Merge pull request #5076 from 0xtonyxia/add-no-auth-warning-option

Add no auth warning option
This commit is contained in:
Salvatore Sanfilippo 2018-06-29 13:32:58 +02:00 committed by GitHub
commit a4ef94d2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -220,6 +220,7 @@ static struct config {
int last_cmd_type; int last_cmd_type;
int verbose; int verbose;
clusterManagerCommand cluster_manager_command; clusterManagerCommand cluster_manager_command;
int no_auth_warning;
} config; } config;
/* User preferences. */ /* User preferences. */
@ -1235,8 +1236,9 @@ static int parseOptions(int argc, char **argv) {
config.interval = seconds*1000000; config.interval = seconds*1000000;
} else if (!strcmp(argv[i],"-n") && !lastarg) { } else if (!strcmp(argv[i],"-n") && !lastarg) {
config.dbnum = atoi(argv[++i]); 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) { } 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]; config.auth = argv[++i];
} else if (!strcmp(argv[i],"-u") && !lastarg) { } else if (!strcmp(argv[i],"-u") && !lastarg) {
parseRedisUri(argv[++i]); 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]); fprintf(stderr,"Try %s --help for more information.\n", argv[0]);
exit(1); exit(1);
} }
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);
}
return i; return i;
} }
@ -1463,9 +1471,14 @@ static void usage(void) {
" --cluster <command> [args...] [opts...]\n" " --cluster <command> [args...] [opts...]\n"
" Cluster Manager command and arguments (see below).\n" " Cluster Manager command and arguments (see below).\n"
" --verbose Verbose mode.\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" " --help Output this help and exit.\n"
" --version Output version 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" "Cluster Manager Commands:\n"
" Use --cluster help to list all available cluster manager commands.\n" " Use --cluster help to list all available cluster manager commands.\n"
"\n" "\n"
@ -1482,8 +1495,7 @@ static void usage(void) {
"When no command is given, redis-cli starts in interactive mode.\n" "When no command is given, redis-cli starts in interactive mode.\n"
"Type \"help\" in interactive mode for information on available commands\n" "Type \"help\" in interactive mode for information on available commands\n"
"and settings.\n" "and settings.\n"
"\n", "\n");
version, REDIS_CLI_DEFAULT_PIPE_TIMEOUT);
sdsfree(version); sdsfree(version);
exit(1); exit(1);
} }
@ -6551,6 +6563,7 @@ int main(int argc, char **argv) {
config.enable_ldb_on_eval = 0; config.enable_ldb_on_eval = 0;
config.last_cmd_type = -1; config.last_cmd_type = -1;
config.verbose = 0; config.verbose = 0;
config.no_auth_warning = 0;
config.cluster_manager_command.name = NULL; config.cluster_manager_command.name = NULL;
config.cluster_manager_command.argc = 0; config.cluster_manager_command.argc = 0;
config.cluster_manager_command.argv = NULL; config.cluster_manager_command.argv = NULL;