Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
7aea02fa
Commit
7aea02fa
authored
Jan 15, 2019
by
antirez
Browse files
ACL: initial implementation of the ACL command.
parent
a2e376ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
7aea02fa
...
@@ -274,3 +274,39 @@ int ACLCheckCommandPerm(client *c) {
...
@@ -274,3 +274,39 @@ int ACLCheckCommandPerm(client *c) {
/* =============================================================================
/* =============================================================================
* ACL related commands
* ACL related commands
* ==========================================================================*/
* ==========================================================================*/
/* ACL -- show and modify the configuration of ACL users.
* ACL help
* ACL list
* ACL setuser <username> ... user attribs ...
* ACL deluser <username>
* ACL getuser <username>
*/
void
aclCommand
(
client
*
c
)
{
char
*
sub
=
c
->
argv
[
1
]
->
ptr
;
if
(
!
strcasecmp
(
sub
,
"setuser"
)
&&
c
->
argc
>=
3
)
{
sds
username
=
c
->
argv
[
2
]
->
ptr
;
user
*
u
=
ACLGetUserByName
(
username
,
sdslen
(
username
));
if
(
!
u
)
u
=
ACLCreateUser
(
username
,
sdslen
(
username
));
serverAssert
(
u
!=
NULL
);
for
(
int
j
=
3
;
j
<
c
->
argc
;
j
++
)
{
if
(
ACLSetUser
(
u
,
c
->
argv
[
j
]
->
ptr
)
!=
C_OK
)
{
addReplyErrorFormat
(
c
,
"Syntax error in ACL SETUSER modifier '%s'"
,
c
->
argv
[
j
]
->
ptr
);
return
;
}
}
addReply
(
c
,
shared
.
ok
);
}
else
if
(
!
strcasecmp
(
sub
,
"help"
))
{
const
char
*
help
[]
=
{
"LIST -- List all the registered users."
,
"SETUSER <username> [attribs ...] -- Create or modify a user."
,
"DELUSER <username> -- Delete a user."
,
"GETUSER <username> -- Get the user details."
,
NULL
};
addReplyHelp
(
c
,
help
);
}
else
{
addReplySubcommandSyntaxError
(
c
);
}
}
src/server.c
View file @
7aea02fa
...
@@ -115,7 +115,7 @@ volatile unsigned long lru_clock; /* Server global current LRU time. */
...
@@ -115,7 +115,7 @@ volatile unsigned long lru_clock; /* Server global current LRU time. */
* is deterministic.
* is deterministic.
* l: Allow command while loading the database.
* l: Allow command while loading the database.
* t: Allow command while a slave has stale data but is not allowed to
* t: Allow command while a slave has stale data but is not allowed to
* serve
r
this data. Normally no command is accepted in this condition
* serve this data. Normally no command is accepted in this condition
* but just a few.
* but just a few.
* M: Do not automatically propagate the command on MONITOR.
* M: Do not automatically propagate the command on MONITOR.
* k: Perform an implicit ASKING for this command, so the command will be
* k: Perform an implicit ASKING for this command, so the command will be
...
@@ -326,7 +326,8 @@ struct redisCommand redisCommandTable[] = {
...
@@ -326,7 +326,8 @@ struct redisCommand redisCommandTable[] = {
{
"post"
,
securityWarningCommand
,
-
1
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"post"
,
securityWarningCommand
,
-
1
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"host:"
,
securityWarningCommand
,
-
1
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"host:"
,
securityWarningCommand
,
-
1
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"latency"
,
latencyCommand
,
-
2
,
"aslt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"latency"
,
latencyCommand
,
-
2
,
"aslt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"lolwut"
,
lolwutCommand
,
-
1
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
}
{
"lolwut"
,
lolwutCommand
,
-
1
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
},
{
"acl"
,
aclCommand
,
-
2
,
"ast"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
,
0
}
};
};
/*============================ Utility functions ============================ */
/*============================ Utility functions ============================ */
...
...
src/server.h
View file @
7aea02fa
...
@@ -2186,6 +2186,7 @@ void xinfoCommand(client *c);
...
@@ -2186,6 +2186,7 @@ void xinfoCommand(client *c);
void
xdelCommand
(
client
*
c
);
void
xdelCommand
(
client
*
c
);
void
xtrimCommand
(
client
*
c
);
void
xtrimCommand
(
client
*
c
);
void
lolwutCommand
(
client
*
c
);
void
lolwutCommand
(
client
*
c
);
void
aclCommand
(
client
*
c
);
#if defined(__GNUC__)
#if defined(__GNUC__)
void
*
calloc
(
size_t
count
,
size_t
size
)
__attribute__
((
deprecated
));
void
*
calloc
(
size_t
count
,
size_t
size
)
__attribute__
((
deprecated
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment