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
eda703ab
Commit
eda703ab
authored
Sep 23, 2019
by
antirez
Browse files
redis-cli: support for ACL style user/pass AUTH.
parent
b21dd082
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
eda703ab
...
@@ -218,6 +218,7 @@ static struct config {
...
@@ -218,6 +218,7 @@ static struct config {
int
hotkeys
;
int
hotkeys
;
int
stdinarg
;
/* get last arg from stdin. (-x option) */
int
stdinarg
;
/* get last arg from stdin. (-x option) */
char
*
auth
;
char
*
auth
;
char
*
user
;
int
output
;
/* output mode, see OUTPUT_* defines */
int
output
;
/* output mode, see OUTPUT_* defines */
sds
mb_delim
;
sds
mb_delim
;
char
prompt
[
128
];
char
prompt
[
128
];
...
@@ -729,8 +730,13 @@ static int cliAuth(void) {
...
@@ -729,8 +730,13 @@ static int cliAuth(void) {
redisReply
*
reply
;
redisReply
*
reply
;
if
(
config
.
auth
==
NULL
)
return
REDIS_OK
;
if
(
config
.
auth
==
NULL
)
return
REDIS_OK
;
reply
=
redisCommand
(
context
,
"AUTH %s"
,
config
.
auth
);
if
(
config
.
user
==
NULL
)
reply
=
redisCommand
(
context
,
"AUTH %s"
,
config
.
auth
);
else
reply
=
redisCommand
(
context
,
"AUTH %s %s"
,
config
.
user
,
config
.
auth
);
if
(
reply
!=
NULL
)
{
if
(
reply
!=
NULL
)
{
if
(
reply
->
type
==
REDIS_REPLY_ERROR
)
fprintf
(
stderr
,
"Warning: AUTH failed
\n
"
);
freeReplyObject
(
reply
);
freeReplyObject
(
reply
);
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
@@ -1350,8 +1356,12 @@ static int parseOptions(int argc, char **argv) {
...
@@ -1350,8 +1356,12 @@ static int parseOptions(int argc, char **argv) {
config
.
dbnum
=
atoi
(
argv
[
++
i
]);
config
.
dbnum
=
atoi
(
argv
[
++
i
]);
}
else
if
(
!
strcmp
(
argv
[
i
],
"--no-auth-warning"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"--no-auth-warning"
))
{
config
.
no_auth_warning
=
1
;
config
.
no_auth_warning
=
1
;
}
else
if
(
!
strcmp
(
argv
[
i
],
"-a"
)
&&
!
lastarg
)
{
}
else
if
((
!
strcmp
(
argv
[
i
],
"-a"
)
||
!
strcmp
(
argv
[
i
],
"--pass"
))
&&
!
lastarg
)
{
config
.
auth
=
argv
[
++
i
];
config
.
auth
=
argv
[
++
i
];
}
else
if
(
!
strcmp
(
argv
[
i
],
"--user"
)
&&
!
lastarg
)
{
config
.
user
=
argv
[
++
i
];
}
else
if
(
!
strcmp
(
argv
[
i
],
"-u"
)
&&
!
lastarg
)
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"-u"
)
&&
!
lastarg
)
{
parseRedisUri
(
argv
[
++
i
]);
parseRedisUri
(
argv
[
++
i
]);
}
else
if
(
!
strcmp
(
argv
[
i
],
"--raw"
))
{
}
else
if
(
!
strcmp
(
argv
[
i
],
"--raw"
))
{
...
@@ -1570,6 +1580,8 @@ static void usage(void) {
...
@@ -1570,6 +1580,8 @@ static void usage(void) {
" You can also use the "
REDIS_CLI_AUTH_ENV
" environment
\n
"
" You can also use the "
REDIS_CLI_AUTH_ENV
" environment
\n
"
" variable to pass this password more safely
\n
"
" variable to pass this password more safely
\n
"
" (if both are used, this argument takes predecence).
\n
"
" (if both are used, this argument takes predecence).
\n
"
" -user <username> Used to send ACL style 'AUTH username pass'. Needs -a.
\n
"
" -pass <password> Alias of -a for consistency with the new --user option.
\n
"
" -u <uri> Server URI.
\n
"
" -u <uri> Server URI.
\n
"
" -r <repeat> Execute specified command N times.
\n
"
" -r <repeat> Execute specified command N times.
\n
"
" -i <interval> When -r is used, waits <interval> seconds per command.
\n
"
" -i <interval> When -r is used, waits <interval> seconds per command.
\n
"
...
@@ -2409,7 +2421,12 @@ static int clusterManagerNodeConnect(clusterManagerNode *node) {
...
@@ -2409,7 +2421,12 @@ static int clusterManagerNodeConnect(clusterManagerNode *node) {
* errors. */
* errors. */
anetKeepAlive
(
NULL
,
node
->
context
->
fd
,
REDIS_CLI_KEEPALIVE_INTERVAL
);
anetKeepAlive
(
NULL
,
node
->
context
->
fd
,
REDIS_CLI_KEEPALIVE_INTERVAL
);
if
(
config
.
auth
)
{
if
(
config
.
auth
)
{
redisReply
*
reply
=
redisCommand
(
node
->
context
,
"AUTH %s"
,
config
.
auth
);
redisReply
*
reply
;
if
(
config
.
user
==
NULL
)
reply
=
redisCommand
(
node
->
context
,
"AUTH %s"
,
config
.
auth
);
else
reply
=
redisCommand
(
node
->
context
,
"AUTH %s %s"
,
config
.
user
,
config
.
auth
);
int
ok
=
clusterManagerCheckRedisReply
(
node
,
reply
,
NULL
);
int
ok
=
clusterManagerCheckRedisReply
(
node
,
reply
,
NULL
);
if
(
reply
!=
NULL
)
freeReplyObject
(
reply
);
if
(
reply
!=
NULL
)
freeReplyObject
(
reply
);
if
(
!
ok
)
return
0
;
if
(
!
ok
)
return
0
;
...
@@ -7737,6 +7754,7 @@ int main(int argc, char **argv) {
...
@@ -7737,6 +7754,7 @@ int main(int argc, char **argv) {
config
.
hotkeys
=
0
;
config
.
hotkeys
=
0
;
config
.
stdinarg
=
0
;
config
.
stdinarg
=
0
;
config
.
auth
=
NULL
;
config
.
auth
=
NULL
;
config
.
user
=
NULL
;
config
.
eval
=
NULL
;
config
.
eval
=
NULL
;
config
.
eval_ldb
=
0
;
config
.
eval_ldb
=
0
;
config
.
eval_ldb_end
=
0
;
config
.
eval_ldb_end
=
0
;
...
...
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