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
acd168a7
Commit
acd168a7
authored
Jan 28, 2019
by
antirez
Browse files
ACL: refactoring and fix of adding subcommands to users.
parent
e103fd42
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
acd168a7
...
@@ -259,6 +259,38 @@ void ACLResetSubcommands(user *u) {
...
@@ -259,6 +259,38 @@ void ACLResetSubcommands(user *u) {
u
->
allowed_subcommands
=
NULL
;
u
->
allowed_subcommands
=
NULL
;
}
}
/* Add a subcommand to the list of subcommands for the user 'u' and
* the command id specified. */
void
ACLAddAllowedSubcommand
(
user
*
u
,
unsigned
long
id
,
const
char
*
sub
)
{
/* If this is the first subcommand to be configured for
* this user, we have to allocate the subcommands array. */
if
(
u
->
allowed_subcommands
==
NULL
)
{
u
->
allowed_subcommands
=
zcalloc
(
USER_COMMAND_BITS_COUNT
*
sizeof
(
sds
*
));
}
/* We also need to enlarge the allocation pointing to the
* null terminated SDS array, to make space for this one.
* To start check the current size, and while we are here
* make sure the subcommand is not already specified inside. */
long
items
=
0
;
if
(
u
->
allowed_subcommands
[
id
])
{
while
(
u
->
allowed_subcommands
[
id
][
items
])
{
/* If it's already here do not add it again. */
if
(
!
strcasecmp
(
u
->
allowed_subcommands
[
id
][
items
],
sub
))
return
;
items
++
;
}
}
/* Now we can make space for the new item (and the null term). */
items
+=
2
;
u
->
allowed_subcommands
[
id
]
=
zrealloc
(
u
->
allowed_subcommands
[
id
],
sizeof
(
sds
)
*
items
);
u
->
allowed_subcommands
[
id
][
items
-
2
]
=
sdsnew
(
sub
);
u
->
allowed_subcommands
[
id
][
items
-
1
]
=
NULL
;
}
/* Set user properties according to the string "op". The following
/* Set user properties according to the string "op". The following
* is a description of what different strings will do:
* is a description of what different strings will do:
*
*
...
@@ -403,25 +435,8 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
...
@@ -403,25 +435,8 @@ int ACLSetUser(user *u, const char *op, ssize_t oplen) {
return
C_ERR
;
return
C_ERR
;
}
}
/* If this is the first subcommand to be configured for
/* Add the subcommand to the list of valid ones. */
* this user, we have to allocate the subcommands array. */
ACLAddAllowedSubcommand
(
u
,
id
,
sub
);
if
(
u
->
allowed_subcommands
==
NULL
)
{
u
->
allowed_subcommands
=
zcalloc
(
USER_COMMAND_BITS_COUNT
*
sizeof
(
sds
*
));
}
/* We also need to enlarge the allocation pointing to the
* null terminated SDS array, to make space for this one. */
long
items
=
0
;
if
(
u
->
allowed_subcommands
[
id
])
{
while
(
u
->
allowed_subcommands
[
items
])
items
++
;
}
items
+=
2
;
/* Make space for the new item and the null term. */
u
->
allowed_subcommands
[
id
]
=
zrealloc
(
u
->
allowed_subcommands
[
id
],
sizeof
(
sds
)
*
items
);
u
->
allowed_subcommands
[
id
][
items
-
2
]
=
sdsnew
(
sub
);
u
->
allowed_subcommands
[
id
][
items
-
1
]
=
NULL
;
/* We have to clear the command bit so that we force the
/* We have to clear the command bit so that we force the
* subcommand check. */
* subcommand check. */
...
...
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