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. */
| 251 | * |
| 252 | * If the user with such name already exists NULL is returned. */ |
| 253 | user *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. |
no test coverage detected