From 0b74fd6766b29c2a132828477f4e0f12af85efad Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Thu, 28 Jun 2018 18:17:04 +0800 Subject: [PATCH 1/6] Add --no-auth-warning help message. --- src/redis-cli.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/redis-cli.c b/src/redis-cli.c index b1ece6250..51080d08d 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1463,6 +1463,8 @@ static void usage(void) { " --cluster [args...] [opts...]\n" " Cluster Manager command and arguments (see below).\n" " --verbose Verbose mode.\n" +" --no-auth-warning Don't show warning message when using password on command\n" +" line interface.\n" " --help Output this help and exit.\n" " --version Output version and exit.\n" "\n" From bde05e9c327bf80debcbbfc047f247f1944c4ff6 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Thu, 28 Jun 2018 18:22:06 +0800 Subject: [PATCH 2/6] Avoid -Woverlength-strings compile warning. Using another fprintf call to output the rest help message. --- src/redis-cli.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 51080d08d..3b992f40b 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1467,7 +1467,10 @@ static void usage(void) { " line interface.\n" " --help Output this help and exit.\n" " --version Output version and exit.\n" -"\n" +"\n", + version, REDIS_CLI_DEFAULT_PIPE_TIMEOUT); + /* Using another fprintf call to avoid -Woverlength-strings compile warning */ + fprintf(stderr, "Cluster Manager Commands:\n" " Use --cluster help to list all available cluster manager commands.\n" "\n" @@ -1484,8 +1487,7 @@ static void usage(void) { "When no command is given, redis-cli starts in interactive mode.\n" "Type \"help\" in interactive mode for information on available commands\n" "and settings.\n" -"\n", - version, REDIS_CLI_DEFAULT_PIPE_TIMEOUT); +"\n"); sdsfree(version); exit(1); } From 7becf54e51ee226bf9cb3a4d5a297d0381f4b571 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Thu, 28 Jun 2018 18:38:24 +0800 Subject: [PATCH 3/6] Don't output password warning message when --no-auth-warning is used. --- src/redis-cli.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 3b992f40b..cf03161fb 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -220,6 +220,7 @@ static struct config { int last_cmd_type; int verbose; clusterManagerCommand cluster_manager_command; + int no_auth_warning; } config; /* User preferences. */ @@ -1235,8 +1236,9 @@ static int parseOptions(int argc, char **argv) { config.interval = seconds*1000000; } else if (!strcmp(argv[i],"-n") && !lastarg) { config.dbnum = atoi(argv[++i]); + } else if (!strcmp(argv[i], "--no-auth-warning")) { + config.no_auth_warning = 1; } else if (!strcmp(argv[i],"-a") && !lastarg) { - fputs("Warning: Using a password with '-a' option on the command line interface may not be safe.\n", stderr); config.auth = argv[++i]; } else if (!strcmp(argv[i],"-u") && !lastarg) { parseRedisUri(argv[++i]); @@ -1387,6 +1389,12 @@ static int parseOptions(int argc, char **argv) { fprintf(stderr,"Try %s --help for more information.\n", argv[0]); exit(1); } + + if (!config.no_auth_warning) { + fputs("Warning: Using a password with '-a' or '-u' option on the command" + " line interface may not be safe.\n", stderr); + } + return i; } @@ -6555,6 +6563,7 @@ int main(int argc, char **argv) { config.enable_ldb_on_eval = 0; config.last_cmd_type = -1; config.verbose = 0; + config.no_auth_warning = 0; config.cluster_manager_command.name = NULL; config.cluster_manager_command.argc = 0; config.cluster_manager_command.argv = NULL; From bbd0ca952292979f54b5479d9397d1510f8bb84c Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Thu, 28 Jun 2018 18:39:42 +0800 Subject: [PATCH 4/6] Fix code format issue. --- src/redis-cli.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index cf03161fb..7926ab81f 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -4867,7 +4867,7 @@ static int clusterManagerCommandRebalance(int argc, char **argv) { } /* Calculate the slots balance for each node. It's the number of * slots the node should lose (if positive) or gain (if negative) - * in order to be balanced. */ + * in order to be balanced. */ int threshold_reached = 0, total_balance = 0; float threshold = config.cluster_manager_command.threshold; i = 0; @@ -4879,9 +4879,9 @@ static int clusterManagerCommandRebalance(int argc, char **argv) { n->weight); n->balance = n->slots_count - expected; total_balance += n->balance; - /* Compute the percentage of difference between the - * expected number of slots and the real one, to see - * if it's over the threshold specified by the user. */ + /* Compute the percentage of difference between the + * expected number of slots and the real one, to see + * if it's over the threshold specified by the user. */ int over_threshold = 0; if (threshold > 0) { if (n->slots_count > 0) { From 1139070a0ffd4fcf79a1420241746b9c626625ce Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Thu, 28 Jun 2018 18:47:28 +0800 Subject: [PATCH 5/6] Fix trailing white space. --- src/redis-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 7926ab81f..b6acfefc9 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -4867,7 +4867,7 @@ static int clusterManagerCommandRebalance(int argc, char **argv) { } /* Calculate the slots balance for each node. It's the number of * slots the node should lose (if positive) or gain (if negative) - * in order to be balanced. */ + * in order to be balanced. */ int threshold_reached = 0, total_balance = 0; float threshold = config.cluster_manager_command.threshold; i = 0; From 9f1856268c9dfb8ef56f1778aa4ef99f9d504bff Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Thu, 28 Jun 2018 19:09:22 +0800 Subject: [PATCH 6/6] Check if password is used on command line interface. --- src/redis-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index b6acfefc9..3e44d2c7c 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -1390,7 +1390,7 @@ static int parseOptions(int argc, char **argv) { exit(1); } - if (!config.no_auth_warning) { + if (!config.no_auth_warning && config.auth != NULL) { fputs("Warning: Using a password with '-a' or '-u' option on the command" " line interface may not be safe.\n", stderr); }