summaryrefslogtreecommitdiff
path: root/client/mysqladmin.cc
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2009-11-20 17:18:37 +0300
committerKonstantin Osipov <kostja@sun.com>2009-11-20 17:18:37 +0300
commitd51a4fae328044f6b796ad8405dbb0dc3c653762 (patch)
tree126efa7bce0c3c70a1d3c3cb0099c6615f951e39 /client/mysqladmin.cc
parentca595821498d6a547fa1780df86cdf127b0019b3 (diff)
parentecb6228c623cc2b239bf297e107225eaa4455d19 (diff)
downloadmariadb-git-d51a4fae328044f6b796ad8405dbb0dc3c653762.tar.gz
Merge with next-mr
Diffstat (limited to 'client/mysqladmin.cc')
-rw-r--r--client/mysqladmin.cc39
1 files changed, 30 insertions, 9 deletions
diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc
index c8cbafe72d9..3484cf08713 100644
--- a/client/mysqladmin.cc
+++ b/client/mysqladmin.cc
@@ -901,23 +901,38 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
{
char buff[128],crypted_pw[64];
time_t start_time;
+ char *typed_password= NULL, *verified= NULL;
/* Do initialization the same way as we do in mysqld */
start_time=time((time_t*) 0);
randominit(&rand_st,(ulong) start_time,(ulong) start_time/2);
- if (argc < 2)
+ if (argc < 1)
{
my_printf_error(0, "Too few arguments to change password", error_flags);
return 1;
}
- if (argv[1][0])
+ else if (argc == 1)
+ {
+ /* prompt for password */
+ typed_password= get_tty_password("New password: ");
+ verified= get_tty_password("Confirm new password: ");
+ if (strcmp(typed_password, verified) != 0)
+ {
+ my_printf_error(0,"Passwords don't match",MYF(ME_BELL));
+ return -1;
+ }
+ }
+ else
+ typed_password= argv[1];
+
+ if (typed_password[0])
{
- char *pw= argv[1];
bool old= (find_type(argv[0], &command_typelib, 2) ==
ADMIN_OLD_PASSWORD);
#ifdef __WIN__
- uint pw_len= (uint) strlen(pw);
- if (pw_len > 1 && pw[0] == '\'' && pw[pw_len-1] == '\'')
+ size_t pw_len= strlen(typed_password);
+ if (pw_len > 1 && typed_password[0] == '\'' &&
+ typed_password[pw_len-1] == '\'')
printf("Warning: single quotes were not trimmed from the password by"
" your command\nline client, as you might have expected.\n");
#endif
@@ -955,9 +970,9 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
}
}
if (old)
- make_scrambled_password_323(crypted_pw, pw);
+ make_scrambled_password_323(crypted_pw, typed_password);
else
- make_scrambled_password(crypted_pw, pw);
+ make_scrambled_password(crypted_pw, typed_password);
}
else
crypted_pw[0]=0; /* No password */
@@ -992,6 +1007,12 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
return -1;
}
}
+ /* free up memory from prompted password */
+ if (typed_password != argv[1])
+ {
+ my_free(typed_password,MYF(MY_ALLOW_ZERO_PTR));
+ my_free(verified,MYF(MY_ALLOW_ZERO_PTR));
+ }
argc--; argv++;
break;
}
@@ -1083,8 +1104,8 @@ static void usage(void)
kill id,id,... Kill mysql threads");
#if MYSQL_VERSION_ID >= 32200
puts("\
- password new-password Change old password to new-password, MySQL 4.1 hashing.\n\
- old-password new-password Change old password to new-password in old format.\n");
+ password [new-password] Change old password to new-password in current format\n\
+ old-password [new-password] Change old password to new-password in old format");
#endif
puts("\
ping Check if mysqld is alive\n\