Skip to content

Commit 116be67

Browse files
author
V S Murthy Sidagam
committed
Bug #27619667 MYSQL_SECURE_INSTALLATION TO LOAD THE VALIDATE_PASSWORD
COMPONENT AND NOT PLUGIN As part of wl#6667 task, mysql_secure_installation has to load the validate_password component instead of validate_password plugin. Modified below files to reflect the changes related to validate_password component. client/mysql_secure_installation.cc man/mysql_secure_installation.1
1 parent 0dacffc commit 116be67

8 files changed

+60
-71
lines changed

client/mysql_secure_installation.cc

Lines changed: 38 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -273,17 +273,19 @@ static bool execute_query(const char **query, size_t length) {
273273
}
274274

275275
/**
276-
Checks if the validate_password plugin is installed and returns true if it is.
276+
Checks if the validate_password component is installed and returns true
277+
if it is.
277278
*/
278279
static bool validate_password_exists() {
279280
MYSQL_ROW row;
280281
bool res = true;
281282
const char *query =
282-
"SELECT NAME FROM mysql.plugin WHERE NAME "
283-
"= \'validate_password\'";
283+
"SELECT component_urn FROM mysql.component WHERE component_urn "
284+
"= \'file://component_validate_password\'";
284285
if (!execute_query(&query, strlen(query)))
285286
DBUG_PRINT("info", ("query success!"));
286287
MYSQL_RES *result = mysql_store_result(&mysql);
288+
if (!result) return false;
287289
row = mysql_fetch_row(result);
288290
if (!row) res = false;
289291

@@ -292,40 +294,29 @@ static bool validate_password_exists() {
292294
}
293295

294296
/**
295-
Installs validate_password plugin and sets the password validation policy.
297+
Installs validate_password component and sets the password validation policy.
296298
297-
@return Returns 1 on successfully setting the plugin and 0 in case of
299+
@return Returns 1 on successfully setting the component and 0 in case of
298300
of any error.
299301
*/
300-
static int install_password_validation_plugin() {
302+
static int install_password_validation_component() {
301303
int reply;
302-
int plugin_set = 0;
304+
int component_set = 0;
303305
char *strength = NULL;
304306
bool option_read = false;
305-
reply= get_response((const char *) "\nVALIDATE PASSWORD PLUGIN can be used "
306-
"to test passwords\nand improve security. "
307-
"It checks the strength of password\nand "
308-
"allows the users to set only those "
309-
"passwords which are\nsecure enough. "
310-
"Would you like to setup VALIDATE "
311-
"PASSWORD plugin?\n\nPress y|Y for Yes, "
312-
"any other key for No: ", 'y');
307+
reply= get_response((const char *) "\nVALIDATE PASSWORD COMPONENT can be "
308+
"used to test passwords\nand improve "
309+
"security. It checks the strength of "
310+
"password\nand allows the users to set "
311+
"only those passwords which are\nsecure "
312+
"enough. Would you like to setup VALIDATE "
313+
"PASSWORD component?\n\nPress y|Y for Yes,"
314+
" any other key for No: ", 'y');
313315
if (reply == (int)'y' || reply == (int)'Y') {
314-
#ifdef _WIN32
315-
const char *query_tmp;
316-
query_tmp =
317-
"INSTALL PLUGIN validate_password SONAME "
318-
"'validate_password.dll'";
319-
if (!execute_query(&query_tmp, strlen(query_tmp)))
320-
#else
321316
const char *query_tmp;
322-
query_tmp =
323-
"INSTALL PLUGIN validate_password SONAME "
324-
"'validate_password.so'";
325-
if (!execute_query(&query_tmp, strlen(query_tmp)))
326-
#endif
327-
{
328-
plugin_set = 1;
317+
query_tmp = "INSTALL COMPONENT 'file://component_validate_password'";
318+
if (!execute_query(&query_tmp, strlen(query_tmp))) {
319+
component_set = 1;
329320
while (!option_read) {
330321
reply= get_response((const char *) "\nThere are three levels of "
331322
"password validation policy:\n\n"
@@ -352,7 +343,7 @@ static int install_password_validation_plugin() {
352343
}
353344
}
354345
char *query, *end;
355-
int tmp = sizeof("SET GLOBAL validate_password_policy = ") + 3;
346+
int tmp = sizeof("SET GLOBAL validate_password.policy = ") + 3;
356347
size_t strength_length = strlen(strength);
357348
/*
358349
query string needs memory which is atleast the length of initial part
@@ -361,7 +352,7 @@ static int install_password_validation_plugin() {
361352
query = (char *)my_malloc(PSI_NOT_INSTRUMENTED,
362353
(strength_length * 2 + tmp) * sizeof(char),
363354
MYF(MY_WME));
364-
end = my_stpcpy(query, "SET GLOBAL validate_password_policy = ");
355+
end = my_stpcpy(query, "SET GLOBAL validate_password.policy = ");
365356
*end++ = '\'';
366357
end += mysql_real_escape_string_quote(&mysql, end, strength,
367358
(ulong)strength_length, '\'');
@@ -371,10 +362,10 @@ static int install_password_validation_plugin() {
371362
my_free(query);
372363
} else
373364
fprintf(stdout,
374-
"The password validation plugin is not available. "
375-
"Proceeding with the further steps without the plugin.\n");
365+
"The password validation component is not available. "
366+
"Proceeding with the further steps without the component.\n");
376367
}
377-
return (plugin_set);
368+
return (component_set);
378369
}
379370

380371
/**
@@ -474,11 +465,11 @@ static bool mysql_expire_password(MYSQL *mysql) {
474465
if he wants to continue with the password, or provide a new one,
475466
depending on the strength displayed.
476467
477-
@param plugin_set 1 if validate_password plugin is set and
468+
@param component_set 1 if validate_password component is set and
478469
0 if it is not.
479470
*/
480471

481-
static void set_opt_user_password(int plugin_set) {
472+
static void set_opt_user_password(int component_set) {
482473
char *password1 = 0, *password2 = 0;
483474
int reply = 0;
484475

@@ -506,7 +497,7 @@ static void set_opt_user_password(int plugin_set) {
506497
continue;
507498
}
508499

509-
if (plugin_set == 1) {
500+
if (component_set == 1) {
510501
estimate_password_strength(password1);
511502
reply = get_response((
512503
const char *)"Do you wish to continue with the "
@@ -516,7 +507,7 @@ static void set_opt_user_password(int plugin_set) {
516507

517508
size_t pass_length = strlen(password1);
518509

519-
if ((!plugin_set) || (reply == (int)'y' || reply == (int)'Y')) {
510+
if ((!component_set) || (reply == (int)'y' || reply == (int)'Y')) {
520511
char *query = NULL, *end;
521512
int tmp = sizeof("SET PASSWORD=") + 3;
522513
/*
@@ -834,7 +825,7 @@ bool find_temporary_password(char **p) {
834825
int main(int argc, char *argv[]) {
835826
int reply;
836827
int rc;
837-
int hadpass, plugin_set = 0;
828+
int hadpass, component_set = 0;
838829

839830
MY_INIT(argv[0]);
840831
DBUG_ENTER("main");
@@ -870,23 +861,23 @@ int main(int argc, char *argv[]) {
870861
hadpass = get_opt_user_password();
871862

872863
if (!validate_password_exists())
873-
plugin_set = install_password_validation_plugin();
864+
component_set = install_password_validation_component();
874865
else {
875866
fprintf(stdout,
876-
"The 'validate_password' plugin is installed on the server.\n"
867+
"The 'validate_password' component is installed on the server.\n"
877868
"The subsequent steps will run with the existing "
878-
"configuration\nof the plugin.\n");
879-
plugin_set = 1;
869+
"configuration\nof the component.\n");
870+
component_set = 1;
880871
}
881872

882873
if (!hadpass) {
883874
fprintf(stdout, "Please set the password for %s here.\n", opt_user);
884-
set_opt_user_password(plugin_set);
875+
set_opt_user_password(component_set);
885876
} else if (opt_use_default == false) {
886877
char prompt[256];
887878
fprintf(stdout, "Using existing password for %s.\n", opt_user);
888879

889-
if (plugin_set == 1) estimate_password_strength(password);
880+
if (component_set == 1) estimate_password_strength(password);
890881

891882
snprintf(prompt, sizeof(prompt) - 1,
892883
"Change the password for %s ? ((Press y|Y "
@@ -895,7 +886,7 @@ int main(int argc, char *argv[]) {
895886
reply = get_response(prompt, 'n');
896887

897888
if (reply == (int)'y' || reply == (int)'Y')
898-
set_opt_user_password(plugin_set);
889+
set_opt_user_password(component_set);
899890
else
900891
fprintf(stdout, "\n ... skipping.\n");
901892
}

man/mysql_secure_installation.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ prompts you to determine which actions to perform\&.
111111
.PP
112112
The
113113
validate_password
114-
plugin can be used for password strength checking\&. If the plugin is not installed,
114+
component can be used for password strength checking\&. If the component is not installed,
115115
\fBmysql_secure_installation\fR
116-
prompts the user whether to install it\&. Any passwords entered later are checked using the plugin if it is enabled\&.
116+
prompts the user whether to install it\&. Any passwords entered later are checked using the component if it is enabled\&.
117117
.PP
118118
Most of the usual MySQL client options such as
119119
\fB\-\-host\fR

mysql-test/suite/interactive_utilities/r/mysql_secure_installation.result

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ Securing the MySQL server deployment.
1111

1212
Connecting to MySQL using a blank password.
1313

14-
VALIDATE PASSWORD PLUGIN can be used to test passwords
14+
VALIDATE PASSWORD COMPONENT can be used to test passwords
1515
and improve security. It checks the strength of password
1616
and allows the users to set only those passwords which are
17-
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
17+
secure enough. Would you like to setup VALIDATE PASSWORD component?
1818

1919
Press y|Y for Yes, any other key for No: Please set the password for root here.
2020

@@ -55,10 +55,10 @@ Enter password:
5555
Securing the MySQL server deployment.
5656

5757

58-
VALIDATE PASSWORD PLUGIN can be used to test passwords
58+
VALIDATE PASSWORD COMPONENT can be used to test passwords
5959
and improve security. It checks the strength of password
6060
and allows the users to set only those passwords which are
61-
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
61+
secure enough. Would you like to setup VALIDATE PASSWORD component?
6262

6363
Press y|Y for Yes, any other key for No: Using existing password for root.
6464
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
@@ -102,10 +102,10 @@ Enter password:
102102
Securing the MySQL server deployment.
103103

104104

105-
VALIDATE PASSWORD PLUGIN can be used to test passwords
105+
VALIDATE PASSWORD COMPONENT can be used to test passwords
106106
and improve security. It checks the strength of password
107107
and allows the users to set only those passwords which are
108-
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
108+
secure enough. Would you like to setup VALIDATE PASSWORD component?
109109

110110
Press y|Y for Yes, any other key for No:
111111
There are three levels of password validation policy:
@@ -159,9 +159,9 @@ Enter password:
159159

160160
Securing the MySQL server deployment.
161161

162-
The 'validate_password' plugin is installed on the server.
162+
The 'validate_password' component is installed on the server.
163163
The subsequent steps will run with the existing configuration
164-
of the plugin.
164+
of the component.
165165
Using existing password for root.
166166

167167
Estimated strength of the password: 100
@@ -211,9 +211,7 @@ made so far will take effect immediately.
211211

212212
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Execution number 4 was successful
213213
Enter password: Execution 5 was successful
214-
UNINSTALL PLUGIN validate_password;
215-
Warnings:
216-
Warning 1287 'validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead
214+
UNINSTALL COMPONENT "file://component_validate_password";
217215
SET PASSWORD for root@localhost = '';
218216
CREATE DATABASE test;
219217
REPLACE INTO mysql.user VALUES ('localhost','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N',NULL,NULL,'N','Y','Y', NULL, NULL);

mysql-test/suite/interactive_utilities/r/mysql_secure_installation_ssl.result

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ mysql_secure_installation: [Warning] Using a password on the command line interf
1313
Securing the MySQL server deployment.
1414

1515

16-
VALIDATE PASSWORD PLUGIN can be used to test passwords
16+
VALIDATE PASSWORD COMPONENT can be used to test passwords
1717
and improve security. It checks the strength of password
1818
and allows the users to set only those passwords which are
19-
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
19+
secure enough. Would you like to setup VALIDATE PASSWORD component?
2020

2121
Press y|Y for Yes, any other key for No: Using existing password for root.
2222
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
@@ -55,10 +55,10 @@ mysql_secure_installation: [Warning] Using a password on the command line interf
5555
Securing the MySQL server deployment.
5656

5757

58-
VALIDATE PASSWORD PLUGIN can be used to test passwords
58+
VALIDATE PASSWORD COMPONENT can be used to test passwords
5959
and improve security. It checks the strength of password
6060
and allows the users to set only those passwords which are
61-
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
61+
secure enough. Would you like to setup VALIDATE PASSWORD component?
6262

6363
Press y|Y for Yes, any other key for No:
6464
There are three levels of password validation policy:
@@ -114,9 +114,7 @@ CREATE DATABASE test;
114114
REPLACE INTO mysql.user VALUES ('localhost','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N',NULL,NULL,'N','Y','Y', NULL, NULL);
115115
REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',NULL,NULL,'Y','N','N', NULL, NULL);
116116
INSERT INTO mysql.db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N','Y','Y');
117-
UNINSTALL PLUGIN validate_password;
118-
Warnings:
119-
Warning 1287 'validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead
117+
UNINSTALL COMPONENT "file://component_validate_password";
120118
UPDATE mysql.user SET password_last_changed=@plc, authentication_string=@auth_str, plugin= @plugin where user='root';
121119
UPDATE mysql.user SET password_last_changed=@sys_plc, authentication_string=@sys_auth_str, plugin= @sys_plugin where user='mysql.sys';
122120
FLUSH PRIVILEGES;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
$VALIDATE_PASSWORD_OPT
1+
$VALIDATE_PASSWORD_COMPONENT_OPT

mysql-test/suite/interactive_utilities/t/mysql_secure_installation.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# If not, the test will be skipped.
33
--source include/have_expect.inc
44
--source include/not_windows.inc
5+
--source include/have_validate_password_component.inc
56

67
SELECT plugin into @plugin from mysql.user where user= 'root' and host='localhost';
78
SELECT password_last_changed into @plc from mysql.user where user= 'root' and host='localhost';
@@ -144,7 +145,7 @@ $i++;
144145
EOF
145146

146147
# Uninstalling validate_password plugin
147-
UNINSTALL PLUGIN validate_password;
148+
UNINSTALL COMPONENT "file://component_validate_password";
148149

149150
# Restoring the server to the state prior to this test.
150151
SET PASSWORD for root@localhost = '';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
$VALIDATE_PASSWORD_OPT
1+
$VALIDATE_PASSWORD_COMPONENT_OPT
22
--ssl-ca=$MYSQL_TEST_DIR/std_data/ca-sha512.pem
33
--ssl-key=$MYSQL_TEST_DIR/std_data/server-key-sha512.pem
44
--ssl-cert=$MYSQL_TEST_DIR/std_data/server-cert-sha512.pem

mysql-test/suite/interactive_utilities/t/mysql_secure_installation_ssl.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
--source include/have_ssl.inc
22
--source include/have_expect.inc
33
--source include/not_windows.inc
4+
--source include/have_validate_password_component.inc
45

56
SELECT plugin into @plugin from mysql.user where user= 'root' and host='localhost';
67
SELECT password_last_changed into @plc from mysql.user where user= 'root' and host='localhost';
@@ -90,7 +91,7 @@ CREATE DATABASE test;
9091
REPLACE INTO mysql.user VALUES ('localhost','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','','N',NULL,NULL,'N','Y','Y', NULL, NULL);
9192
REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',NULL,NULL,'Y','N','N', NULL, NULL);
9293
INSERT INTO mysql.db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','N','N','Y','Y');
93-
UNINSTALL PLUGIN validate_password;
94+
UNINSTALL COMPONENT "file://component_validate_password";
9495
UPDATE mysql.user SET password_last_changed=@plc, authentication_string=@auth_str, plugin= @plugin where user='root';
9596
UPDATE mysql.user SET password_last_changed=@sys_plc, authentication_string=@sys_auth_str, plugin= @sys_plugin where user='mysql.sys';
9697
FLUSH PRIVILEGES;

0 commit comments

Comments
 (0)