mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
ACL: implement ACLCreateUser().
This commit is contained in:
parent
e4846b028d
commit
6bb6a6d3a8
20
src/acl.c
20
src/acl.c
@ -85,6 +85,26 @@ int time_independent_strcmp(char *a, char *b) {
|
|||||||
* Low level ACL API
|
* Low level ACL API
|
||||||
* ==========================================================================*/
|
* ==========================================================================*/
|
||||||
|
|
||||||
|
/* 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. */
|
||||||
|
user *ACLcreateUser(const char *name, size_t namelen) {
|
||||||
|
if (raxFind(Users,(unsigned char*)name,namelen) != raxNotFound) return NULL;
|
||||||
|
user *u = zmalloc(sizeof(*u));
|
||||||
|
u->flags = 0;
|
||||||
|
u->allowed_subcommands = NULL;
|
||||||
|
u->passwords = listCreate();
|
||||||
|
u->patterns = NULL; /* Just created users cannot access to any key, however
|
||||||
|
if the "~*" directive was enabled to match all the
|
||||||
|
keys, the user will be flagged with the ALLKEYS
|
||||||
|
flag. */
|
||||||
|
memset(u->allowed_commands,0,sizeof(u->allowed_commands));
|
||||||
|
raxInsert(Users,(unsigned char*)name,namelen,u,NULL);
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialization of the ACL subsystem. */
|
/* Initialization of the ACL subsystem. */
|
||||||
void ACLInit(void) {
|
void ACLInit(void) {
|
||||||
Users = raxNew();
|
Users = raxNew();
|
||||||
|
@ -712,6 +712,7 @@ typedef struct readyList {
|
|||||||
* If there is no associated user, the connection uses the default user. */
|
* If there is no associated user, the connection uses the default user. */
|
||||||
#define USER_MAX_COMMAND_BIT 1024
|
#define USER_MAX_COMMAND_BIT 1024
|
||||||
#define USER_FLAG_ENABLED (1<<0) /* The user is active. */
|
#define USER_FLAG_ENABLED (1<<0) /* The user is active. */
|
||||||
|
#define USER_FLAG_ALLKEYS (1<<1) /* The user can mention any key. */
|
||||||
typedef struct user {
|
typedef struct user {
|
||||||
uint64_t flags; /* See USER_FLAG_* */
|
uint64_t flags; /* See USER_FLAG_* */
|
||||||
|
|
||||||
@ -731,7 +732,9 @@ typedef struct user {
|
|||||||
* set to NULL to avoid allocating USER_MAX_COMMAND_BIT pointers. */
|
* set to NULL to avoid allocating USER_MAX_COMMAND_BIT pointers. */
|
||||||
sds **allowed_subcommands;
|
sds **allowed_subcommands;
|
||||||
list *passwords; /* A list of SDS valid passwords for this user. */
|
list *passwords; /* A list of SDS valid passwords for this user. */
|
||||||
list *patterns; /* A list of allowed key patterns. */
|
list *patterns; /* A list of allowed key patterns. If this field is NULL
|
||||||
|
the user cannot mention any key in a command, unless
|
||||||
|
the flag ALLKEYS is set in the user. */
|
||||||
} user;
|
} user;
|
||||||
|
|
||||||
/* With multiplexing we need to take per-client state.
|
/* With multiplexing we need to take per-client state.
|
||||||
|
Loading…
Reference in New Issue
Block a user