mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-7015: SET STATEMENT old_passwords has no effect
Decision about algorihtm moved on prepare phase. Made possible to add mpore password algorithms.
This commit is contained in:
@ -1070,8 +1070,6 @@ set statement character_set_filesystem=default for select 1;
|
||||
ERROR 42000: The system variable character_set_filesystem cannot be set in SET STATEMENT.
|
||||
set statement collation_connection=default for select 1;
|
||||
ERROR 42000: The system variable collation_connection cannot be set in SET STATEMENT.
|
||||
set statement old_passwords=default for select 1;
|
||||
ERROR 42000: The system variable old_passwords cannot be set in SET STATEMENT.
|
||||
set statement query_cache_type=default for select 1;
|
||||
ERROR 42000: The system variable query_cache_type cannot be set in SET STATEMENT.
|
||||
set statement wait_timeout=default for select 1;
|
||||
@ -1105,3 +1103,38 @@ week(a)
|
||||
deallocate prepare stmt1;
|
||||
drop table t1;
|
||||
set @@default_week_format=@save_week_format;
|
||||
set @save_old_passwords=@@old_passwords;
|
||||
set @@old_passwords=0;
|
||||
set statement OLD_PASSWORDS = 0 for select password('test');
|
||||
password('test')
|
||||
*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
|
||||
set statement OLD_PASSWORDS = 1 for select password('test');
|
||||
password('test')
|
||||
378b243e220ca493
|
||||
set statement OLD_PASSWORDS = 0 for explain extended select password('test');
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
Warnings:
|
||||
Note 1003 select password('test') AS `password('test')`
|
||||
set statement OLD_PASSWORDS = 1 for explain extended select password('test');
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
Warnings:
|
||||
Note 1003 select password('test') AS `password('test')`
|
||||
create table t1 (a char(10));
|
||||
insert t1 values ('qwertyuiop');
|
||||
prepare stmt1 from "select password(a) from t1";
|
||||
execute stmt1;
|
||||
password(a)
|
||||
*6063C78456BB048BAF36BE1104D12D547834DFEA
|
||||
set old_passwords=1;
|
||||
execute stmt1;
|
||||
password(a)
|
||||
2013610f6aac2950
|
||||
alter table t1 engine=myisam;
|
||||
execute stmt1;
|
||||
password(a)
|
||||
2013610f6aac2950
|
||||
deallocate prepare stmt1;
|
||||
drop table t1;
|
||||
set @@old_passwords=@save_old_passwords;
|
||||
|
@ -1025,8 +1025,6 @@ set statement character_set_filesystem=default for select 1;
|
||||
--error ER_SET_STATEMENT_NOT_SUPPORTED
|
||||
set statement collation_connection=default for select 1;
|
||||
--error ER_SET_STATEMENT_NOT_SUPPORTED
|
||||
set statement old_passwords=default for select 1;
|
||||
--error ER_SET_STATEMENT_NOT_SUPPORTED
|
||||
set statement query_cache_type=default for select 1;
|
||||
--error ER_SET_STATEMENT_NOT_SUPPORTED
|
||||
set statement wait_timeout=default for select 1;
|
||||
@ -1050,3 +1048,21 @@ deallocate prepare stmt1;
|
||||
drop table t1;
|
||||
set @@default_week_format=@save_week_format;
|
||||
|
||||
# MDEV-7015: SET STATEMENT old_passwords has no effect
|
||||
set @save_old_passwords=@@old_passwords;
|
||||
set @@old_passwords=0;
|
||||
set statement OLD_PASSWORDS = 0 for select password('test');
|
||||
set statement OLD_PASSWORDS = 1 for select password('test');
|
||||
set statement OLD_PASSWORDS = 0 for explain extended select password('test');
|
||||
set statement OLD_PASSWORDS = 1 for explain extended select password('test');
|
||||
create table t1 (a char(10));
|
||||
insert t1 values ('qwertyuiop');
|
||||
prepare stmt1 from "select password(a) from t1";
|
||||
execute stmt1;
|
||||
set old_passwords=1;
|
||||
execute stmt1;
|
||||
alter table t1 engine=myisam;
|
||||
execute stmt1;
|
||||
deallocate prepare stmt1;
|
||||
drop table t1;
|
||||
set @@old_passwords=@save_old_passwords;
|
||||
|
@ -2168,56 +2168,67 @@ void Item_func_trim::print(String *str, enum_query_type query_type)
|
||||
|
||||
/* Item_func_password */
|
||||
|
||||
bool Item_func_password::fix_fields(THD *thd, Item **ref)
|
||||
{
|
||||
if (deflt)
|
||||
alg= (thd->variables.old_passwords ? OLD : NEW);
|
||||
return Item_str_ascii_func::fix_fields(thd, ref);
|
||||
}
|
||||
|
||||
String *Item_func_password::val_str_ascii(String *str)
|
||||
{
|
||||
DBUG_ASSERT(fixed == 1);
|
||||
String *res= args[0]->val_str(str);
|
||||
check_password_policy(res);
|
||||
if (args[0]->null_value || res->length() == 0)
|
||||
return make_empty_result();
|
||||
my_make_scrambled_password(tmp_value, res->ptr(), res->length());
|
||||
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, &my_charset_latin1);
|
||||
switch (alg){
|
||||
case NEW:
|
||||
check_password_policy(res);
|
||||
if (args[0]->null_value || res->length() == 0)
|
||||
return make_empty_result();
|
||||
my_make_scrambled_password(tmp_value, res->ptr(), res->length());
|
||||
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH, &my_charset_latin1);
|
||||
break;
|
||||
case OLD:
|
||||
if ((null_value=args[0]->null_value))
|
||||
return 0;
|
||||
if (res->length() == 0)
|
||||
return make_empty_result();
|
||||
my_make_scrambled_password_323(tmp_value, res->ptr(), res->length());
|
||||
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, &my_charset_latin1);
|
||||
break;
|
||||
default:
|
||||
DBUG_ASSERT(0);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
char *Item_func_password::alloc(THD *thd, const char *password, size_t pass_len)
|
||||
char *Item_func_password::alloc(THD *thd, const char *password,
|
||||
size_t pass_len, enum PW_Alg al)
|
||||
{
|
||||
char *buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH+1);
|
||||
if (buff)
|
||||
{
|
||||
String *password_str= new (thd->mem_root)String(password, thd->variables.
|
||||
character_set_client);
|
||||
check_password_policy(password_str);
|
||||
my_make_scrambled_password(buff, password, pass_len);
|
||||
char *buff= (char *) thd->alloc((al==NEW)?
|
||||
SCRAMBLED_PASSWORD_CHAR_LENGTH + 1:
|
||||
SCRAMBLED_PASSWORD_CHAR_LENGTH_323 + 1);
|
||||
if (!buff)
|
||||
return NULL;
|
||||
|
||||
switch (al) {
|
||||
case NEW:
|
||||
{
|
||||
String *password_str= new (thd->mem_root)String(password, thd->variables.
|
||||
character_set_client);
|
||||
check_password_policy(password_str);
|
||||
my_make_scrambled_password(buff, password, pass_len);
|
||||
break;
|
||||
}
|
||||
case OLD:
|
||||
my_make_scrambled_password_323(buff, password, pass_len);
|
||||
break;
|
||||
default:
|
||||
DBUG_ASSERT(0);
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
/* Item_func_old_password */
|
||||
|
||||
String *Item_func_old_password::val_str_ascii(String *str)
|
||||
{
|
||||
DBUG_ASSERT(fixed == 1);
|
||||
String *res= args[0]->val_str(str);
|
||||
if ((null_value=args[0]->null_value))
|
||||
return 0;
|
||||
if (res->length() == 0)
|
||||
return make_empty_result();
|
||||
my_make_scrambled_password_323(tmp_value, res->ptr(), res->length());
|
||||
str->set(tmp_value, SCRAMBLED_PASSWORD_CHAR_LENGTH_323, &my_charset_latin1);
|
||||
return str;
|
||||
}
|
||||
|
||||
char *Item_func_old_password::alloc(THD *thd, const char *password,
|
||||
size_t pass_len)
|
||||
{
|
||||
char *buff= (char *) thd->alloc(SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1);
|
||||
if (buff)
|
||||
my_make_scrambled_password_323(buff, password, pass_len);
|
||||
return buff;
|
||||
}
|
||||
|
||||
|
||||
#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
|
||||
|
||||
|
@ -407,40 +407,32 @@ public:
|
||||
|
||||
class Item_func_password :public Item_str_ascii_func
|
||||
{
|
||||
public:
|
||||
enum PW_Alg {OLD, NEW};
|
||||
private:
|
||||
char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH+1];
|
||||
enum PW_Alg alg;
|
||||
bool deflt;
|
||||
public:
|
||||
Item_func_password(Item *a) :Item_str_ascii_func(a) {}
|
||||
Item_func_password(Item *a) :Item_str_ascii_func(a), alg(NEW), deflt(1) {}
|
||||
Item_func_password(Item *a, PW_Alg al) :Item_str_ascii_func(a),
|
||||
alg(al), deflt(0) {}
|
||||
String *val_str_ascii(String *str);
|
||||
bool fix_fields(THD *thd, Item **ref);
|
||||
void fix_length_and_dec()
|
||||
{
|
||||
fix_length_and_charset(SCRAMBLED_PASSWORD_CHAR_LENGTH, default_charset());
|
||||
fix_length_and_charset((alg == 1 ?
|
||||
SCRAMBLED_PASSWORD_CHAR_LENGTH :
|
||||
SCRAMBLED_PASSWORD_CHAR_LENGTH_323),
|
||||
default_charset());
|
||||
}
|
||||
const char *func_name() const { return "password"; }
|
||||
static char *alloc(THD *thd, const char *password, size_t pass_len);
|
||||
const char *func_name() const { return ((deflt || alg == 1) ?
|
||||
"password" : "old_password"); }
|
||||
static char *alloc(THD *thd, const char *password, size_t pass_len,
|
||||
enum PW_Alg al);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Item_func_old_password -- PASSWORD() implementation used in MySQL 3.21 - 4.0
|
||||
compatibility mode. This item is created in sql_yacc.yy when
|
||||
'old_passwords' session variable is set, and to handle OLD_PASSWORD()
|
||||
function.
|
||||
*/
|
||||
|
||||
class Item_func_old_password :public Item_str_ascii_func
|
||||
{
|
||||
char tmp_value[SCRAMBLED_PASSWORD_CHAR_LENGTH_323+1];
|
||||
public:
|
||||
Item_func_old_password(Item *a) :Item_str_ascii_func(a) {}
|
||||
String *val_str_ascii(String *str);
|
||||
void fix_length_and_dec()
|
||||
{
|
||||
fix_length_and_charset(SCRAMBLED_PASSWORD_CHAR_LENGTH_323, default_charset());
|
||||
}
|
||||
const char *func_name() const { return "old_password"; }
|
||||
static char *alloc(THD *thd, const char *password, size_t pass_len);
|
||||
};
|
||||
|
||||
|
||||
class Item_func_des_encrypt :public Item_str_func
|
||||
{
|
||||
|
@ -9771,17 +9771,15 @@ function_call_conflict:
|
||||
}
|
||||
| OLD_PASSWORD '(' expr ')'
|
||||
{
|
||||
$$= new (thd->mem_root) Item_func_old_password($3);
|
||||
$$= new (thd->mem_root)
|
||||
Item_func_password($3, Item_func_password::OLD);
|
||||
if ($$ == NULL)
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
| PASSWORD '(' expr ')'
|
||||
{
|
||||
Item* i1;
|
||||
if (thd->variables.old_passwords)
|
||||
i1= new (thd->mem_root) Item_func_old_password($3);
|
||||
else
|
||||
i1= new (thd->mem_root) Item_func_password($3);
|
||||
i1= new (thd->mem_root) Item_func_password($3);
|
||||
if (i1 == NULL)
|
||||
MYSQL_YYABORT;
|
||||
$$= i1;
|
||||
@ -14898,17 +14896,19 @@ text_or_password:
|
||||
TEXT_STRING { $$=$1.str;}
|
||||
| PASSWORD '(' TEXT_STRING ')'
|
||||
{
|
||||
$$= $3.length ? thd->variables.old_passwords ?
|
||||
Item_func_old_password::alloc(thd, $3.str, $3.length) :
|
||||
Item_func_password::alloc(thd, $3.str, $3.length) :
|
||||
$$= $3.length ?
|
||||
Item_func_password::alloc(thd, $3.str, $3.length,
|
||||
thd->variables.old_passwords ?
|
||||
Item_func_password::OLD :
|
||||
Item_func_password::NEW) :
|
||||
$3.str;
|
||||
if ($$ == NULL)
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
| OLD_PASSWORD '(' TEXT_STRING ')'
|
||||
{
|
||||
$$= $3.length ? Item_func_old_password::
|
||||
alloc(thd, $3.str, $3.length) :
|
||||
$$= $3.length ? Item_func_password::
|
||||
alloc(thd, $3.str, $3.length, Item_func_password::OLD) :
|
||||
$3.str;
|
||||
if ($$ == NULL)
|
||||
MYSQL_YYABORT;
|
||||
|
@ -2130,7 +2130,7 @@ static bool check_old_passwords(sys_var *self, THD *thd, set_var *var)
|
||||
static Sys_var_mybool Sys_old_passwords(
|
||||
"old_passwords",
|
||||
"Use old password encryption method (needed for 4.0 and older clients)",
|
||||
NO_SET_STMT SESSION_VAR(old_passwords), CMD_LINE(OPT_ARG),
|
||||
SESSION_VAR(old_passwords), CMD_LINE(OPT_ARG),
|
||||
DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
|
||||
ON_CHECK(check_old_passwords));
|
||||
export sys_var *Sys_old_passwords_ptr= &Sys_old_passwords; // for sql_acl.cc
|
||||
|
Reference in New Issue
Block a user