mirror of
https://github.com/fluencelabs/redis
synced 2025-04-26 02:52:15 +00:00
ACL: implement LOAD subcommand plus some minor rafactoring.
This commit is contained in:
parent
72e8a080c2
commit
0f0240b526
29
src/acl.c
29
src/acl.c
@ -758,10 +758,9 @@ sds ACLDefaultUserFirstPassword(void) {
|
|||||||
return listNodeValue(first);
|
return listNodeValue(first);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialization of the ACL subsystem. */
|
/* Initialize the default user, that will always exist for all the process
|
||||||
void ACLInit(void) {
|
* lifetime. */
|
||||||
Users = raxNew();
|
void ACLInitDefaultUser(void) {
|
||||||
UsersToLoad = listCreate();
|
|
||||||
DefaultUser = ACLCreateUser("default",7);
|
DefaultUser = ACLCreateUser("default",7);
|
||||||
ACLSetUser(DefaultUser,"+@all",-1);
|
ACLSetUser(DefaultUser,"+@all",-1);
|
||||||
ACLSetUser(DefaultUser,"~*",-1);
|
ACLSetUser(DefaultUser,"~*",-1);
|
||||||
@ -769,6 +768,13 @@ void ACLInit(void) {
|
|||||||
ACLSetUser(DefaultUser,"nopass",-1);
|
ACLSetUser(DefaultUser,"nopass",-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialization of the ACL subsystem. */
|
||||||
|
void ACLInit(void) {
|
||||||
|
Users = raxNew();
|
||||||
|
UsersToLoad = listCreate();
|
||||||
|
ACLInitDefaultUser();
|
||||||
|
}
|
||||||
|
|
||||||
/* Check the username and password pair and return C_OK if they are valid,
|
/* Check the username and password pair and return C_OK if they are valid,
|
||||||
* otherwise C_ERR is returned and errno is set to:
|
* otherwise C_ERR is returned and errno is set to:
|
||||||
*
|
*
|
||||||
@ -1134,7 +1140,7 @@ sds ACLLoadFromFile(const char *filename) {
|
|||||||
/* Note that the same rules already applied to the fake user, so
|
/* Note that the same rules already applied to the fake user, so
|
||||||
* we just assert that everything goess well: it should. */
|
* we just assert that everything goess well: it should. */
|
||||||
for (j = 2; j < argc; j++)
|
for (j = 2; j < argc; j++)
|
||||||
serverAssert(ACLSetUser(fakeuser,argv[j],sdslen(argv[j]) == C_OK);
|
serverAssert(ACLSetUser(fakeuser,argv[j],sdslen(argv[j])) == C_OK);
|
||||||
|
|
||||||
sdsfreesplitres(argv,argc);
|
sdsfreesplitres(argv,argc);
|
||||||
}
|
}
|
||||||
@ -1297,6 +1303,19 @@ void aclCommand(client *c) {
|
|||||||
} else {
|
} else {
|
||||||
addReplyNull(c);
|
addReplyNull(c);
|
||||||
}
|
}
|
||||||
|
} else if (!strcasecmp(sub,"load")) {
|
||||||
|
if (server.acl_filename[0] == '\0') {
|
||||||
|
addReplyError(c,"This Redis instance is not configured to use an ACL file. You may want to specify users via the ACL SETUSER command and then issue a CONFIG REWRITE (assuming you have a Redis configuration file set) in order to store users in the Redis configuration.");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
sds errors = ACLLoadFromFile(server.acl_filename);
|
||||||
|
if (errors == NULL) {
|
||||||
|
addReply(c,shared.ok);
|
||||||
|
} else {
|
||||||
|
addReplyError(c,errors);
|
||||||
|
sdsfree(errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (!strcasecmp(sub,"help")) {
|
} else if (!strcasecmp(sub,"help")) {
|
||||||
const char *help[] = {
|
const char *help[] = {
|
||||||
"LIST -- Show user details in config file format.",
|
"LIST -- Show user details in config file format.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user