From 190f7a6f451f01b4b336b8825178ec3e38d24a9c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 5 Jan 2005 21:56:18 +0100 Subject: Fix "mysqladmin password" to use correct password scrambling function when talking to pre-4.1 servers or 4.1 and later servers where the old_passwords option is enabled. "mysqladmin old-password" is unchanged. (Bug #7451) client/mysqladmin.cc: Check old_passwords from server, and use that to determine which scramble function to use (except in the case of the old-password command, which always use the old scramble function). --- client/mysqladmin.cc | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'client/mysqladmin.cc') diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 2e8b3cd588a..6916b4ea808 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -826,13 +826,39 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) if (argv[1][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] == '\'') printf("Warning: single quotes were not trimmed from the password by" " your command\nline client, as you might have expected.\n"); #endif - if (find_type(argv[0], &command_typelib, 2) == ADMIN_OLD_PASSWORD) + /* + If we don't already know to use an old-style password, see what + the server is using + */ + if (!old) { + if (mysql_query(mysql, "SHOW VARIABLES LIKE 'old_passwords'")) { + my_printf_error(0, "Could not determine old_passwords setting from server; error: '%s'", + MYF(ME_BELL),mysql_error(mysql)); + return -1; + } else { + MYSQL_RES *res= mysql_store_result(mysql); + if (!res) { + my_printf_error(0, "Could not get old_passwords setting from server; error: '%s'", + MYF(ME_BELL),mysql_error(mysql)); + return -1; + } + if (!mysql_num_rows(res)) { + old= 1; + } else { + MYSQL_ROW row= mysql_fetch_row(res); + old= !strncmp(row[1], "ON", 2); + } + mysql_free_result(res); + } + } + if (old) make_scrambled_password_323(crypted_pw, pw); else make_scrambled_password(crypted_pw, pw); -- cgit v1.2.1