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
479f7f7a
Commit
479f7f7a
authored
Jan 30, 2019
by
antirez
Browse files
ACL: add function to return ACLSetUser() string errors.
parent
09602598
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
479f7f7a
...
@@ -625,6 +625,26 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
...
@@ -625,6 +625,26 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
return
C_OK
;
return
C_OK
;
}
}
/* Return a description of the error that occurred in ACLSetUser() according to
* the errno value set by the function on error. */
char
*
ACLSetUserStringError
(
void
)
{
char
*
errmsg
=
"Wrong format"
;
if
(
errno
==
ENOENT
)
errmsg
=
"Unknown command or category name in ACL"
;
else
if
(
errno
==
EINVAL
)
errmsg
=
"Syntax error"
;
else
if
(
errno
==
EBUSY
)
errmsg
=
"Adding a subcommand of a command already fully "
"added is not allowed. Remove the command to start. "
"Example: -DEBUG +DEBUG|DIGEST"
;
else
if
(
errno
==
EEXIST
)
errmsg
=
"Adding a pattern after the * pattern (or the "
"'allkeys' flag) is not valid and does not have any "
"effect. Try 'resetkeys' to start with an empty "
"list of patterns"
;
return
errmsg
;
}
/* Return the first password of the default user or NULL.
/* Return the first password of the default user or NULL.
* This function is needed for backward compatibility with the old
* This function is needed for backward compatibility with the old
* directive "requirepass" when Redis supported a single global
* directive "requirepass" when Redis supported a single global
...
@@ -827,20 +847,7 @@ void aclCommand(client *c) {
...
@@ -827,20 +847,7 @@ void aclCommand(client *c) {
serverAssert
(
u
!=
NULL
);
serverAssert
(
u
!=
NULL
);
for
(
int
j
=
3
;
j
<
c
->
argc
;
j
++
)
{
for
(
int
j
=
3
;
j
<
c
->
argc
;
j
++
)
{
if
(
ACLSetUser
(
u
,
c
->
argv
[
j
]
->
ptr
,
sdslen
(
c
->
argv
[
j
]
->
ptr
))
!=
C_OK
)
{
if
(
ACLSetUser
(
u
,
c
->
argv
[
j
]
->
ptr
,
sdslen
(
c
->
argv
[
j
]
->
ptr
))
!=
C_OK
)
{
char
*
errmsg
=
"wrong format"
;
char
*
errmsg
=
ACLSetUserStringError
();
if
(
errno
==
ENOENT
)
errmsg
=
"unknown command or category name in ACL"
;
else
if
(
errno
==
EINVAL
)
errmsg
=
"syntax error"
;
else
if
(
errno
==
EBUSY
)
errmsg
=
"adding a subcommand of a command already fully "
"added is not allowed. Remove the command to start. "
"Example: -DEBUG +DEBUG|DIGEST"
;
else
if
(
errno
==
EEXIST
)
errmsg
=
"adding a pattern after the * pattern (or the "
"'allkeys' flag) is not valid and does not have any "
"effect. Try 'resetkeys' to start with an empty "
"list of patterns"
;
addReplyErrorFormat
(
c
,
addReplyErrorFormat
(
c
,
"Error in ACL SETUSER modifier '%s': %s"
,
"Error in ACL SETUSER modifier '%s': %s"
,
(
char
*
)
c
->
argv
[
j
]
->
ptr
,
errmsg
);
(
char
*
)
c
->
argv
[
j
]
->
ptr
,
errmsg
);
...
...
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