summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <peter@mysql.com>2002-10-03 22:48:53 +0400
committerunknown <peter@mysql.com>2002-10-03 22:48:53 +0400
commit748191fd807d6f380b48b9331a8d8cf333d2bb45 (patch)
treeb9522531a456b10dced6edbc21b35f15c338869c
parente607221a3cd778131cc9250108473819c9b8c8a0 (diff)
parenta370f86622f98fa33e7085878522ff181e7effba (diff)
downloadmariadb-git-748191fd807d6f380b48b9331a8d8cf333d2bb45.tar.gz
Merge mysql.com:/home/pz/mysql/mysql-4.1-root
into mysql.com:/home/pz/mysql/mysql-4.1 BitKeeper/etc/logging_ok: auto-union sql/item_strfunc.cc: Auto merged sql/item_strfunc.h: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged
-rw-r--r--include/mysql_com.h1
-rw-r--r--sql/item_strfunc.cc2
-rw-r--r--sql/item_strfunc.h4
-rw-r--r--sql/mysql_priv.h3
-rw-r--r--sql/mysqld.cc8
-rw-r--r--sql/password.c58
6 files changed, 67 insertions, 9 deletions
diff --git a/include/mysql_com.h b/include/mysql_com.h
index 1edaa99db28..5ed65e993d9 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -275,6 +275,7 @@ void randominit(struct rand_struct *,unsigned long seed1,
unsigned long seed2);
double rnd(struct rand_struct *);
void make_scrambled_password(char *to,const char *password);
+uint get_password_length();
void get_salt_from_password(unsigned long *res,const char *password);
void make_password_from_salt(char *to, unsigned long *hash_res);
char *scramble(char *to,const char *message,const char *password,
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 2ef95bb8746..24320d98576 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1274,7 +1274,7 @@ String *Item_func_password::val_str(String *str)
if (res->length() == 0)
return &empty_string;
make_scrambled_password(tmp_value,res->c_ptr());
- str->set(tmp_value,16,res->charset());
+ str->set(tmp_value,get_password_length(),res->charset());
return str;
}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index b98be7829fb..d416f09d458 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -243,11 +243,11 @@ public:
class Item_func_password :public Item_str_func
{
- char tmp_value[17];
+ char tmp_value[64]; /* This should be enough for new password format */
public:
Item_func_password(Item *a) :Item_str_func(a) {}
String *val_str(String *);
- void fix_length_and_dec() { max_length = 16; }
+ void fix_length_and_dec() { max_length = get_password_length(); }
const char *func_name() const { return "password"; }
};
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index dc58d3cc64e..078343348f6 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -66,7 +66,8 @@ char* query_table_status(THD *thd,const char *db,const char *table_name);
****************************************************************************/
#define ACL_CACHE_SIZE 256
-#define HASH_PASSWORD_LENGTH 16
+/* Password lengh for 4.1 version previous versions had 16 bytes password hash */
+#define HASH_PASSWORD_LENGTH 45
#define HOST_CACHE_SIZE 128
#define MAX_ACCEPT_RETRY 10 // Test accept this many times
#define MAX_FIELDS_BEFORE_HASH 32
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 900d529827e..9be123ce4e0 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -278,7 +278,7 @@ static my_bool opt_noacl=0, opt_bootstrap=0, opt_myisam_log=0;
my_bool opt_safe_user_create = 0, opt_no_mix_types = 0;
my_bool opt_safe_show_db=0, lower_case_table_names, opt_old_rpl_compat;
my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
-my_bool opt_log_slave_updates= 0;
+my_bool opt_log_slave_updates= 0, opt_old_passwords=0;
volatile bool mqh_used = 0;
FILE *bootstrap_file=0;
@@ -395,6 +395,7 @@ const char *myisam_recover_options_str="OFF";
const char *sql_mode_str="OFF";
ulong rpl_recovery_rank=0;
+
my_string mysql_unix_port=NULL, opt_mysql_tmpdir=NULL, mysql_tmpdir=NULL;
ulong my_bind_addr; /* the address we bind to */
char *my_bind_addr_str;
@@ -2903,7 +2904,8 @@ enum options {
OPT_INNODB_FORCE_RECOVERY,
OPT_BDB_CACHE_SIZE,
OPT_BDB_LOG_BUFFER_SIZE,
- OPT_BDB_MAX_LOCK
+ OPT_BDB_MAX_LOCK,
+ OPT_OLD_PASSWORDS
};
@@ -3234,6 +3236,8 @@ struct my_option my_long_options[] =
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"safe-mode", OPT_SAFE, "Skip some optimize stages (for testing).",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"old-passwords", OPT_OLD_PASSWORDS, "Use old password encryption method (needed for old clients)",
+ (gptr*) &opt_old_passwords, (gptr*) &opt_old_passwords, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
#ifndef TO_BE_DELETED
{"safe-show-database", OPT_SAFE_SHOW_DB,
"Deprecated option; One should use GRANT SHOW DATABASES instead...",
diff --git a/sql/password.c b/sql/password.c
index 48181ea18e6..1875bb0ef04 100644
--- a/sql/password.c
+++ b/sql/password.c
@@ -37,9 +37,19 @@
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
+#include <sha1.h>
#include "mysql.h"
+
+/* Character to use as version identifier for version 4.1 */
+#define PVERSION41_CHAR '*'
+
+
+extern my_bool opt_old_passwords; /* If prior 4.1 functions to be used */
+
+
+
void randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2)
{ /* For mysql 3.21.# */
#ifdef HAVE_purify
@@ -84,13 +94,55 @@ void hash_password(ulong *result, const char *password)
return;
}
+
void make_scrambled_password(char *to,const char *password)
+{
+ ulong hash_res[2]; /* Used for pre 4.1 password hashing */
+ static uint salt=0; /* Salt for 4.1 version password */
+ unsigned char* slt=(unsigned char*)&salt;
+ SHA1_CONTEXT context;
+ uint8 digest[SHA1_HASH_SIZE];
+ if (opt_old_passwords) /* Pre 4.1 password encryption */
+ {
+ hash_password(hash_res,password);
+ sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
+ }
+ else /* New password 4.1 password scrambling */
+ {
+ to[0]=PVERSION41_CHAR; /* New passwords have version prefix */
+ /* We do not need too strong salt generation so this should be enough */
+ salt+=getpid()+time(NULL)+0x01010101;
+ /* Use only 2 first bytes from it */
+ sprintf(&(to[1]),"%02x%02x",slt[0],slt[1]);
+ sha1_reset(&context);
+ /* Use Salt for Hash */
+ sha1_input(&context,(uint8*)&salt,2);
+
+ for (; *password ; password++)
+ {
+ if (*password == ' ' || *password == '\t')
+ continue;/* skip space in password */
+ sha1_input(&context,(int8*)&password[0],1);
+ }
+ sha1_result(&context,digest);
+ /* Print resulting hash into the password*/
+ sprintf(&(to[5]),
+ "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+ digest[0],digest[1],digest[2],digest[3],digest[4],digest[5],digest[6],
+ digest[7],digest[8],digest[9],digest[10],digest[11],digest[12],digest[13],
+ digest[14],digest[15],digest[16],digest[17],digest[18],digest[19]);
+
+ }
+}
+
+uint get_password_length()
{
- ulong hash_res[2];
- hash_password(hash_res,password);
- sprintf(to,"%08lx%08lx",hash_res[0],hash_res[1]);
+ if (opt_old_passwords)
+ return 16;
+ else return SHA1_HASH_SIZE*2+4+1;
}
+
inline uint char_val(char X)
{
return (uint) (X >= '0' && X <= '9' ? X-'0' :