mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
cleanup: move all password validation logic into one function
This commit is contained in:
@ -874,6 +874,17 @@ static void free_acl_role(ACL_ROLE *role)
|
|||||||
delete_dynamic(&(role->parent_grantee));
|
delete_dynamic(&(role->parent_grantee));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static my_bool check_if_exists(THD *, plugin_ref, void *)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool has_validation_plugins()
|
||||||
|
{
|
||||||
|
return plugin_foreach(NULL, check_if_exists,
|
||||||
|
MariaDB_PASSWORD_VALIDATION_PLUGIN, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
struct validation_data { LEX_STRING *user, *password; };
|
struct validation_data { LEX_STRING *user, *password; };
|
||||||
|
|
||||||
static my_bool do_validate(THD *, plugin_ref plugin, void *arg)
|
static my_bool do_validate(THD *, plugin_ref plugin, void *arg)
|
||||||
@ -885,22 +896,27 @@ static my_bool do_validate(THD *, plugin_ref plugin, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool validate_password(LEX_STRING *user, LEX_STRING *password)
|
static bool validate_password(LEX_USER *user)
|
||||||
{
|
{
|
||||||
struct validation_data data= { user, password };
|
if (user->pwtext.length || !user->pwhash.length)
|
||||||
return plugin_foreach(NULL, do_validate,
|
{
|
||||||
MariaDB_PASSWORD_VALIDATION_PLUGIN, &data);
|
struct validation_data data= { &user->user, &user->pwtext };
|
||||||
}
|
if (plugin_foreach(NULL, do_validate,
|
||||||
|
MariaDB_PASSWORD_VALIDATION_PLUGIN, &data))
|
||||||
static my_bool check_if_exists(THD *, plugin_ref, void *)
|
{
|
||||||
{
|
my_error(ER_NOT_VALID_PASSWORD, MYF(0));
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
static bool has_validation_plugins()
|
else
|
||||||
{
|
{
|
||||||
return plugin_foreach(NULL, check_if_exists,
|
if (strict_password_validation && has_validation_plugins())
|
||||||
MariaDB_PASSWORD_VALIDATION_PLUGIN, NULL);
|
{
|
||||||
|
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--strict-password-validation");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1034,22 +1050,8 @@ static bool fix_lex_user(THD *thd, LEX_USER *user)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user->pwtext.length || !user->pwhash.length)
|
if (validate_password(user))
|
||||||
{
|
return true;
|
||||||
if (validate_password(&user->user, &user->pwtext))
|
|
||||||
{
|
|
||||||
my_error(ER_NOT_VALID_PASSWORD, MYF(0));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (strict_password_validation && has_validation_plugins())
|
|
||||||
{
|
|
||||||
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--strict-password-validation");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user->pwtext.length && !user->pwhash.length)
|
if (user->pwtext.length && !user->pwhash.length)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user