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
7fc882c5
Commit
7fc882c5
authored
Jan 09, 2019
by
antirez
Browse files
ACL: use a fixed table for command IDs.
parent
010b24f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
7fc882c5
...
...
@@ -93,3 +93,20 @@ int ACLCheckUserCredentials(robj *username, robj *password) {
return
C_ERR
;
}
}
/* For ACL purposes, every user has a bitmap with the commands that such
* user is allowed to execute. In order to populate the bitmap, every command
* should have an assigned ID (that is used to index the bitmap). This function
* creates such an ID: it uses sequential IDs, reusing the same ID for the same
* command name, so that a command retains the same ID in case of modules that
* are unloaded and later reloaded. */
unsigned
long
ACLGetCommandID
(
const
char
*
cmdname
)
{
static
rax
*
map
=
NULL
;
unsigned
long
nextid
=
0
;
if
(
map
==
NULL
)
map
=
raxNew
();
void
*
id
=
raxFind
(
map
,(
unsigned
char
*
)
cmdname
,
strlen
(
cmdname
));
if
(
id
!=
raxNotFound
)
return
(
unsigned
long
)
id
;
raxInsert
(
map
,(
unsigned
char
*
)
cmdname
,
strlen
(
cmdname
),(
void
*
)
nextid
,
NULL
);
return
nextid
++
;
}
src/server.c
View file @
7fc882c5
...
...
@@ -2224,8 +2224,7 @@ void populateCommandTable(void) {
f
++
;
}
c
->
id
=
j
;
/* Sequential ID for each command. Used for ACLs. */
c
->
id
=
ACLGetCommandID
(
c
->
name
);
/* Assign the ID used for ACL. */
retval1
=
dictAdd
(
server
.
commands
,
sdsnew
(
c
->
name
),
c
);
/* Populate an additional dictionary that will be unaffected
* by rename-command statements in redis.conf. */
...
...
src/server.h
View file @
7fc882c5
...
...
@@ -1352,6 +1352,14 @@ typedef struct {
dictIterator
*
di
;
}
setTypeIterator
;
/* This structure represents a Redis user. This is useful for ACLs, the
* user is associated to the connection after the connection is authenticated.
* If there is no associated user, the connection uses the default user. */
#define USER_MAX_COMMAND_BIT 1024
typedef
struct
user
{
uint64_t
allowed_commands
[
USER_MAX_COMMAND_BIT
/
64
];
}
user
;
/* Structure to hold hash iteration abstraction. Note that iteration over
* hashes involves both fields and values. Because it is possible that
* not both are required, store pointers in the iterator to avoid
...
...
@@ -1655,6 +1663,7 @@ void receiveChildInfo(void);
/* acl.c -- Authentication related prototypes. */
int
ACLCheckUserCredentials
(
robj
*
username
,
robj
*
password
);
unsigned
long
ACLGetCommandID
(
const
char
*
cmdname
);
/* Sorted sets data type */
...
...
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