MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ACLCreateUser

Function ACLCreateUser

src/acl.cpp:253–274  ·  view source on GitHub ↗

Create a new user with the specified name, store it in the list * of users (the Users global radix tree), and returns a reference to * the structure representing the user. * * If the user with such name already exists NULL is returned. */

Source from the content-addressed store, hash-verified

251 *
252 * If the user with such name already exists NULL is returned. */
253user *ACLCreateUser(const char *name, size_t namelen) {
254 if (raxFind(Users,(unsigned char*)name,namelen) != raxNotFound) return NULL;
255 user *u = (user*)zmalloc(sizeof(*u), MALLOC_LOCAL);
256 u->name = sdsnewlen(name,namelen);
257 u->flags = USER_FLAG_DISABLED | g_pserver->acl_pubsub_default;
258 u->allowed_subcommands = NULL;
259 u->passwords = listCreate();
260 u->patterns = listCreate();
261 u->channels = listCreate();
262 listSetMatchMethod(u->passwords,ACLListMatchSdsSecure);
263 listSetFreeMethod(u->passwords,ACLListFreeSds);
264 listSetDupMethod(u->passwords,ACLListDupSds);
265 listSetMatchMethod(u->patterns,ACLListMatchSds);
266 listSetFreeMethod(u->patterns,ACLListFreeSds);
267 listSetDupMethod(u->patterns,ACLListDupSds);
268 listSetMatchMethod(u->channels,ACLListMatchSds);
269 listSetFreeMethod(u->channels,ACLListFreeSds);
270 listSetDupMethod(u->channels,ACLListDupSds);
271 memset(u->allowed_commands,0,sizeof(u->allowed_commands));
272 raxInsert(Users,(unsigned char*)name,namelen,u,NULL);
273 return u;
274}
275
276/* This function should be called when we need an unlinked "fake" user
277 * we can use in order to validate ACL rules or for other similar reasons.

Callers 5

ACLCreateUnlinkedUserFunction · 0.85
ACLInitDefaultUserFunction · 0.85
ACLLoadConfiguredUsersFunction · 0.85
ACLLoadFromFileFunction · 0.85
aclCommandFunction · 0.85

Calls 5

raxFindFunction · 0.85
zmallocFunction · 0.85
sdsnewlenFunction · 0.85
listCreateFunction · 0.85
raxInsertFunction · 0.85

Tested by

no test coverage detected