summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-03-10 16:51:36 +0100
committerGitHub <noreply@github.com>2020-03-10 16:51:36 +0100
commitbd28dbee0ed53db74b21d702c23c3254cebdbc7f (patch)
tree1d91c914cefe16ec5d9e60b52807dbc0f15fe920 /src
parent2bd360fecaef28e630ff556cb0ae8860a668065d (diff)
parent1b72f4b74951d6abff055e0667f18e9833fd0c72 (diff)
downloadredis-bd28dbee0ed53db74b21d702c23c3254cebdbc7f.tar.gz
Merge pull request #6834 from lifubang/askpassword
add askpass mode
Diffstat (limited to 'src')
-rw-r--r--src/redis-cli.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index 54898f42e..b44db9a1e 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -229,6 +229,7 @@ static struct config {
int hotkeys;
int stdinarg; /* get last arg from stdin. (-x option) */
char *auth;
+ int askpass;
char *user;
int output; /* output mode, see OUTPUT_* defines */
sds mb_delim;
@@ -1450,6 +1451,8 @@ static int parseOptions(int argc, char **argv) {
config.dbnum = atoi(argv[++i]);
} else if (!strcmp(argv[i], "--no-auth-warning")) {
config.no_auth_warning = 1;
+ } else if (!strcmp(argv[i], "--askpass")) {
+ config.askpass = 1;
} else if ((!strcmp(argv[i],"-a") || !strcmp(argv[i],"--pass"))
&& !lastarg)
{
@@ -1690,6 +1693,9 @@ static void usage(void) {
" (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"
+" --askpass Force user to input password with mask from STDIN.\n"
+" If this argument is used, '-a' and " REDIS_CLI_AUTH_ENV "\n"
+" environment variable will be ignored.\n"
" -u <uri> Server URI.\n"
" -r <repeat> Execute specified command N times.\n"
" -i <interval> When -r is used, waits <interval> seconds per command.\n"
@@ -7858,6 +7864,13 @@ static void intrinsicLatencyMode(void) {
}
}
+static sds askPassword() {
+ linenoiseMaskModeEnable();
+ sds auth = linenoise("Please input password: ");
+ linenoiseMaskModeDisable();
+ return auth;
+}
+
/*------------------------------------------------------------------------------
* Program main()
*--------------------------------------------------------------------------- */
@@ -7894,6 +7907,7 @@ int main(int argc, char **argv) {
config.hotkeys = 0;
config.stdinarg = 0;
config.auth = NULL;
+ config.askpass = 0;
config.user = NULL;
config.eval = NULL;
config.eval_ldb = 0;
@@ -7935,6 +7949,10 @@ int main(int argc, char **argv) {
parseEnv();
+ if (config.askpass) {
+ config.auth = askPassword();
+ }
+
#ifdef USE_OPENSSL
if (config.tls) {
ERR_load_crypto_strings();
@@ -8044,4 +8062,4 @@ int main(int argc, char **argv) {
} else {
return noninteractive(argc,convertToSds(argc,argv));
}
-}
+} \ No newline at end of file