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
9c2e42dd
Commit
9c2e42dd
authored
Mar 16, 2020
by
antirez
Browse files
ACL: Make Redis 6 more backward compatible with requirepass.
Note that this as a side effect fixes Sentinel "requirepass" mode.
parent
d387f67d
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/acl.c
View file @
9c2e42dd
...
...
@@ -899,16 +899,6 @@ char *ACLSetUserStringError(void) {
return
errmsg
;
}
/* Return the first password of the default user or NULL.
* This function is needed for backward compatibility with the old
* directive "requirepass" when Redis supported a single global
* password. */
sds
ACLDefaultUserFirstPassword
(
void
)
{
if
(
listLength
(
DefaultUser
->
passwords
)
==
0
)
return
NULL
;
listNode
*
first
=
listFirst
(
DefaultUser
->
passwords
);
return
listNodeValue
(
first
);
}
/* Initialize the default user, that will always exist for all the process
* lifetime. */
void
ACLInitDefaultUser
(
void
)
{
...
...
@@ -925,6 +915,7 @@ void ACLInit(void) {
UsersToLoad
=
listCreate
();
ACLLog
=
listCreate
();
ACLInitDefaultUser
();
server
.
requirepass
=
NULL
;
/* Only used for backward compatibility. */
}
/* Check the username and password pair and return C_OK if they are valid,
...
...
src/config.c
View file @
9c2e42dd
...
...
@@ -411,11 +411,15 @@ void loadServerConfigFromString(char *config) {
goto
loaderr
;
}
/* The old "requirepass" directive just translates to setting
* a password to the default user. */
* a password to the default user. The only thing we do
* additionally is to remember the cleartext password in this
* case, for backward compatibility with Redis <= 5. */
ACLSetUser
(
DefaultUser
,
"resetpass"
,
-
1
);
sds
aclop
=
sdscatprintf
(
sdsempty
(),
">%s"
,
argv
[
1
]);
ACLSetUser
(
DefaultUser
,
aclop
,
sdslen
(
aclop
));
sdsfree
(
aclop
);
sdsfree
(
server
.
requirepass
);
server
.
requirepass
=
sdsnew
(
argv
[
1
]);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"list-max-ziplist-entries"
)
&&
argc
==
2
){
/* DEAD OPTION */
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"list-max-ziplist-value"
)
&&
argc
==
2
)
{
...
...
@@ -623,11 +627,15 @@ void configSetCommand(client *c) {
config_set_special_field
(
"requirepass"
)
{
if
(
sdslen
(
o
->
ptr
)
>
CONFIG_AUTHPASS_MAX_LEN
)
goto
badfmt
;
/* The old "requirepass" directive just translates to setting
* a password to the default user. */
* a password to the default user. The only thing we do
* additionally is to remember the cleartext password in this
* case, for backward compatibility with Redis <= 5. */
ACLSetUser
(
DefaultUser
,
"resetpass"
,
-
1
);
sds
aclop
=
sdscatprintf
(
sdsempty
(),
">%s"
,(
char
*
)
o
->
ptr
);
ACLSetUser
(
DefaultUser
,
aclop
,
sdslen
(
aclop
));
sdsfree
(
aclop
);
sdsfree
(
server
.
requirepass
);
server
.
requirepass
=
sdsnew
(
o
->
ptr
);
}
config_set_special_field
(
"save"
)
{
int
vlen
,
j
;
sds
*
v
=
sdssplitlen
(
o
->
ptr
,
sdslen
(
o
->
ptr
),
" "
,
1
,
&
vlen
);
...
...
@@ -899,7 +907,7 @@ void configGetCommand(client *c) {
}
if
(
stringmatch
(
pattern
,
"requirepass"
,
1
))
{
addReplyBulkCString
(
c
,
"requirepass"
);
sds
password
=
ACLDefaultUserFirstPassword
()
;
sds
password
=
server
.
requirepass
;
if
(
password
)
{
addReplyBulkCBuffer
(
c
,
password
,
sdslen
(
password
));
}
else
{
...
...
@@ -1341,7 +1349,7 @@ void rewriteConfigBindOption(struct rewriteConfigState *state) {
void
rewriteConfigRequirepassOption
(
struct
rewriteConfigState
*
state
,
char
*
option
)
{
int
force
=
1
;
sds
line
;
sds
password
=
ACLDefaultUserFirstPassword
()
;
sds
password
=
server
.
requirepass
;
/* If there is no password set, we don't want the requirepass option
* to be present in the configuration at all. */
...
...
src/sentinel.c
View file @
9c2e42dd
...
...
@@ -1992,7 +1992,7 @@ void sentinelSendAuthIfNeeded(sentinelRedisInstance *ri, redisAsyncContext *c) {
auth_pass
=
ri
->
master
->
auth_pass
;
auth_user
=
ri
->
master
->
auth_user
;
}
else
if
(
ri
->
flags
&
SRI_SENTINEL
)
{
auth_pass
=
ACLDefaultUserFirstPassword
()
;
auth_pass
=
server
.
requirepass
;
auth_user
=
NULL
;
}
...
...
src/server.h
View file @
9c2e42dd
...
...
@@ -1395,6 +1395,9 @@ struct redisServer {
/* ACLs */
char
*
acl_filename
;
/* ACL Users file. NULL if not configured. */
unsigned
long
acllog_max_len
;
/* Maximum length of the ACL LOG list. */
sds
requirepass
;
/* Remember the cleartext password set with the
old "requirepass" directive for backward
compatibility with Redis <= 5. */
/* Assert & bug reporting */
const
char
*
assert_failed
;
const
char
*
assert_file
;
...
...
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