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. */
| 242 | * |
| 243 | * If the user with such name already exists NULL is returned. */ |
| 244 | user *ACLCreateUser(const char *name, size_t namelen) { |
| 245 | if (raxFind(Users,(unsigned char*)name,namelen) != raxNotFound) return NULL; |
| 246 | user *u = zmalloc(sizeof(*u)); |
| 247 | u->name = sdsnewlen(name,namelen); |
| 248 | u->flags = USER_FLAG_DISABLED | server.acl_pubsub_default; |
| 249 | u->allowed_subcommands = NULL; |
| 250 | u->passwords = listCreate(); |
| 251 | u->patterns = listCreate(); |
| 252 | u->channels = listCreate(); |
| 253 | listSetMatchMethod(u->passwords,ACLListMatchSds); |
| 254 | listSetFreeMethod(u->passwords,ACLListFreeSds); |
| 255 | listSetDupMethod(u->passwords,ACLListDupSds); |
| 256 | listSetMatchMethod(u->patterns,ACLListMatchSds); |
| 257 | listSetFreeMethod(u->patterns,ACLListFreeSds); |
| 258 | listSetDupMethod(u->patterns,ACLListDupSds); |
| 259 | listSetMatchMethod(u->channels,ACLListMatchSds); |
| 260 | listSetFreeMethod(u->channels,ACLListFreeSds); |
| 261 | listSetDupMethod(u->channels,ACLListDupSds); |
| 262 | memset(u->allowed_commands,0,sizeof(u->allowed_commands)); |
| 263 | raxInsert(Users,(unsigned char*)name,namelen,u,NULL); |
| 264 | return u; |
| 265 | } |
| 266 | |
| 267 | /* This function should be called when we need an unlinked "fake" user |
| 268 | * we can use in order to validate ACL rules or for other similar reasons. |
no test coverage detected