Skip to content

Commit

Permalink
cleanup: move all password validation logic into one function
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Jan 25, 2016
1 parent d5b1b1a commit d14c4c7
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,17 @@ static void free_acl_role(ACL_ROLE *role)
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; };

static my_bool do_validate(THD *, plugin_ref plugin, void *arg)
Expand All @@ -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 };
return plugin_foreach(NULL, do_validate,
MariaDB_PASSWORD_VALIDATION_PLUGIN, &data);
}

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);
if (user->pwtext.length || !user->pwhash.length)
{
struct validation_data data= { &user->user, &user->pwtext };
if (plugin_foreach(NULL, do_validate,
MariaDB_PASSWORD_VALIDATION_PLUGIN, &data))
{
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;
}
}
return false;
}

/**
Expand Down Expand Up @@ -1034,22 +1050,8 @@ static bool fix_lex_user(THD *thd, LEX_USER *user)
return true;
}

if (user->pwtext.length || !user->pwhash.length)
{
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 (validate_password(user))
return true;

if (user->pwtext.length && !user->pwhash.length)
{
Expand Down

0 comments on commit d14c4c7

Please sign in to comment.