List:Commits« Previous MessageNext Message »
From:Jim Winstead Date:April 29 2009 10:49pm
Subject:bzr commit into mysql-6.0-falcon branch (jimw:2697) Bug#5724
View as plain text  
#At file:///Users/jimw/my/mysql-6.0/ based on revid:jperkin@stripped

 2697 Jim Winstead	2009-04-29
      Add support for being prompted for new passwords by mysqladmin instead of
      specifying them on the command line. (Bug #5724, patch by Harrison Fisk)
      modified:
        client/mysqladmin.cc

=== modified file 'client/mysqladmin.cc'
--- a/client/mysqladmin.cc	2009-03-17 20:26:16 +0000
+++ b/client/mysqladmin.cc	2009-04-29 22:49:06 +0000
@@ -822,23 +822,38 @@ static int execute_commands(MYSQL *mysql
     {
       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);
+      start_time= time((time_t*) 0);
       my_rnd_init(&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= strlen(pw);
-        if (pw_len > 1 && pw[0] == '\'' && pw[pw_len-1] == '\'')
+        uint 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
@@ -876,9 +891,9 @@ static int execute_commands(MYSQL *mysql
           }
         }
         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 */
@@ -913,6 +928,12 @@ static int execute_commands(MYSQL *mysql
 	  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;
     }
@@ -1004,8 +1025,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\

Thread
bzr commit into mysql-6.0-falcon branch (jimw:2697) Bug#5724Jim Winstead30 Apr