Skip to content

Commit cf35c9d

Browse files
author
BennyWang
committed
Merge branch 'mysql-trunk' into wl411
2 parents 5d77344 + 8ddbbc8 commit cf35c9d

File tree

565 files changed

+13240
-3189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+13240
-3189
lines changed

client/mysql_install_db.cc

+8-19
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,10 @@ struct Sql_user
273273

274274
void to_sql(string *cmdstr)
275275
{
276-
stringstream set_oldpasscmd,ss;
276+
stringstream set_passcmd,ss, flush_priv;
277277
ss << "INSERT INTO mysql.user VALUES ("
278278
<< "'" << escape_string(host) << "','" << escape_string(user) << "',";
279279

280-
if (plugin == "mysql_native_password")
281-
{
282-
ss << "PASSWORD('" << escape_string(password) << "'),";
283-
}
284-
else if (plugin == "sha256_password")
285-
{
286-
ss << "'',";
287-
}
288280
uint64_t acl= priv.to_int();
289281
for(int i= 0; i< NUM_ACLS; ++i)
290282
{
@@ -302,22 +294,19 @@ struct Sql_user
302294
<< max_connections << ","
303295
<< max_user_connections << ","
304296
<< "'" << plugin << "',";
305-
if (plugin == "sha256_password")
306-
{
307-
set_oldpasscmd << "SET @@old_passwords= 2;\n";
308-
ss << "PASSWORD('" << escape_string(password) << "'),";
309-
}
310-
else
311-
{
312-
ss << "'" << escape_string(authentication_string) << "',";
313-
}
297+
ss << "'',";
314298
if (password_expired)
315299
ss << "'Y',";
316300
else
317301
ss << "'N',";
318302
ss << "now(), NULL);\n";
319303

320-
cmdstr->append(set_oldpasscmd.str()).append(ss.str());
304+
flush_priv << "FLUSH PRIVILEGES;\n";
305+
306+
set_passcmd << "ALTER USER '" << escape_string(user) << "'@'"
307+
<< escape_string(host) << "' IDENTIFIED BY '"
308+
<< escape_string(password) << "';\n";
309+
cmdstr->append(ss.str()).append(flush_priv.str()).append(set_passcmd.str());
321310
}
322311

323312
};

client/mysql_secure_installation.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@ my_bool mysql_set_password(MYSQL *mysql, char *password)
441441
size_t password_len= strlen(password);
442442
char *query, *end;
443443
query= (char *)my_malloc(PSI_NOT_INSTRUMENTED, password_len+50, MYF(MY_WME));
444-
end= my_stpmov(query, "SET PASSWORD= PASSWORD('");
444+
end= my_stpmov(query, "SET PASSWORD=");
445+
*end++ = '\'';
445446
end+= mysql_real_escape_string_quote(mysql, end, password, password_len, '\'');
446447
*end++ = '\'';
447-
*end++ = ')';
448448
if (mysql_real_query(mysql, query, (unsigned int) (end - query)))
449449
{
450450
my_free(query);
@@ -542,18 +542,17 @@ static void set_root_password(int plugin_set)
542542
if ((!plugin_set) || (reply == (int) 'y' || reply == (int) 'Y'))
543543
{
544544
char *query= NULL, *end;
545-
int tmp= sizeof("SET PASSWORD=PASSWORD(") + 3;
545+
int tmp= sizeof("SET PASSWORD=") + 3;
546546
/*
547547
query string needs memory which is atleast the length of initial part
548548
of query plus twice the size of variable being appended.
549549
*/
550550
query= (char *)my_malloc(PSI_NOT_INSTRUMENTED,
551551
(pass_length*2 + tmp)*sizeof(char), MYF(MY_WME));
552-
end= my_stpcpy(query, "SET PASSWORD=PASSWORD(");
552+
end= my_stpcpy(query, "SET PASSWORD=");
553553
*end++ = '\'';
554554
end+= mysql_real_escape_string_quote(&mysql, end, password1, pass_length, '\'');
555555
*end++ = '\'';
556-
*end++ = ')';
557556
my_free(password1);
558557
my_free(password2);
559558
password1= NULL;

client/mysqladmin.cc

+23-7
Original file line numberDiff line numberDiff line change
@@ -1017,10 +1017,12 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
10171017
}
10181018
case ADMIN_PASSWORD:
10191019
{
1020-
char buff[128],crypted_pw[64];
1020+
char buff[128];
10211021
time_t start_time;
1022-
char *typed_password= NULL, *verified= NULL;
1023-
bool log_off= true, err= false;
1022+
char *typed_password= NULL, *verified= NULL, *tmp= NULL;
1023+
bool log_off= true, err= false, ssl_conn= false;
1024+
uint ssl_enforce= 0;
1025+
size_t password_len;
10241026

10251027
/* Do initialization the same way as we do in mysqld */
10261028
start_time=time((time_t*) 0);
@@ -1042,6 +1044,11 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
10421044
err= true;
10431045
goto error;
10441046
}
1047+
/* escape quotes if password has any special characters */
1048+
password_len= strlen(typed_password);
1049+
tmp= (char*) my_malloc(PSI_NOT_INSTRUMENTED, password_len*2+1, MYF(MY_WME));
1050+
mysql_real_escape_string(mysql, tmp, typed_password, password_len);
1051+
typed_password= tmp;
10451052
}
10461053
else
10471054
{
@@ -1074,12 +1081,21 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
10741081
TODO: make sure this always uses SSL and then let the server
10751082
calculate the scramble.
10761083
*/
1077-
make_scrambled_password(crypted_pw, typed_password);
10781084
}
1079-
else
1080-
crypted_pw[0]=0; /* No password */
10811085

1082-
sprintf(buff, "set password='%s'", crypted_pw);
1086+
/* Warn about password being set in non ssl connection */
1087+
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
1088+
mysql_get_option(mysql, MYSQL_OPT_SSL_ENFORCE, &ssl_enforce);
1089+
if (opt_use_ssl && ssl_enforce)
1090+
ssl_conn= true;
1091+
if (!ssl_conn)
1092+
{
1093+
fprintf(stderr, "Warning: Since password will be sent to server in "
1094+
"plain text, use ssl connection to ensure password safety.\n");
1095+
}
1096+
#endif
1097+
memset(buff, 0, sizeof(buff));
1098+
sprintf(buff, "ALTER USER USER() IDENTIFIED BY '%s'", typed_password);
10831099

10841100
if (mysql_query(mysql,buff))
10851101
{

include/mysql/plugin_auth.h

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#ifndef MYSQL_PLUGIN_AUTH_INCLUDED
2-
/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2+
/* Copyright (c) 2010, 2015 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 as published by
@@ -26,7 +26,7 @@
2626

2727
#include <mysql/plugin.h>
2828

29-
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0100
29+
#define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0101
3030

3131
#include <mysql/plugin_auth_common.h>
3232

@@ -120,6 +120,51 @@ struct st_mysql_auth
120120
used for authorization.
121121
*/
122122
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
123+
/**
124+
New plugin API to generate password digest out of authentication string.
125+
This function will first invoke a service to check for validity of the
126+
password based on the policies defined and then generate encrypted hash
127+
128+
@param[OUT] outbuf A buffer provided by server which will hold the
129+
authentication string generated by plugin.
130+
@param[INOUT] outbuflen Length of server provided buffer as IN param and
131+
length of plugin generated string as OUT param.
132+
@param[IN] inbuf auth string provided by user.
133+
@param[IN] inbuflen auth string length.
134+
135+
@retval 0 OK
136+
1 ERROR
137+
138+
*/
139+
int (*generate_authentication_string)(char *outbuf,
140+
unsigned int *outbuflen, const char *inbuf, unsigned int inbuflen);
141+
/**
142+
Plugin API to validate password digest.
143+
144+
@param[IN] inbuf hash string to be validated.
145+
@param[IN] buflen hash string length.
146+
147+
@retval 0 OK
148+
1 ERROR
149+
150+
*/
151+
int (*validate_authentication_string)(char* const inbuf, unsigned int buflen);
152+
/**
153+
Plugin API to convert scrambled password to binary form
154+
based on scramble type.
155+
156+
@param[IN] password The password hash containing the salt.
157+
@param[IN] password_len The length of the password hash.
158+
@param[INOUT] salt Used as password hash based on the
159+
authentication plugin.
160+
@param[INOUT] salt_len The length of salt.
161+
162+
@retval 0 OK
163+
1 ERROR
164+
165+
*/
166+
int (*set_salt)(const char *password, unsigned int password_len,
167+
unsigned char* salt, unsigned char *salt_len);
123168
};
124169
#endif
125170

include/mysql/plugin_auth.h.pp

+5
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,9 @@
134134
int interface_version;
135135
const char *client_auth_plugin;
136136
int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
137+
int (*generate_authentication_string)(char *outbuf,
138+
unsigned int *outbuflen, const char *inbuf, unsigned int inbuflen);
139+
int (*validate_authentication_string)(char* const inbuf, unsigned int buflen);
140+
int (*set_salt)(const char *password, unsigned int password_len,
141+
unsigned char* salt, unsigned char *salt_len);
137142
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Copyright (c) 2014, 2015 Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
#ifndef MYSQL_SERVICE_MYSQL_PLUGIN_AUTH_INCLUDED
17+
#define MYSQL_SERVICE_MYSQL_PLUGIN_AUTH_INCLUDED
18+
19+
/**
20+
@file include/mysql/service_mysql_plugin_auth.h
21+
This service provides functions to validatete password, check for strength
22+
of password based on common policy.
23+
24+
SYNOPSIS
25+
my_validate_password_policy() - function to validate password
26+
based on defined policy
27+
const char* buffer holding the password value
28+
29+
my_calculate_password_strength() - function to calculate strength
30+
of the password based on the policies defined.
31+
const char* buffer holding the password value
32+
33+
Both the service function returns 0 on SUCCESS and 1 incase input password does not
34+
match against the policy rules defined.
35+
*/
36+
37+
#ifdef __cplusplus
38+
extern "C" {
39+
#endif
40+
41+
extern struct mysql_password_policy_service_st {
42+
int (*my_validate_password_policy_func)(const char *);
43+
int (*my_calculate_password_strength_func)(const char *);
44+
} *mysql_password_policy_service;
45+
46+
#ifdef MYSQL_DYNAMIC_PLUGIN
47+
48+
#define my_validate_password_policy(buffer) \
49+
mysql_password_policy_service->my_validate_password_policy_func(buffer)
50+
#define my_calculate_password_strength(buffer) \
51+
mysql_password_policy_service->my_calculate_password_strength_func(buffer)
52+
53+
#else
54+
55+
int my_validate_password_policy(const char *);
56+
int my_calculate_password_strength(const char *);
57+
58+
#endif
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
64+
#endif

include/mysql/services.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#include <mysql/service_my_plugin_log.h>
2626
#include <mysql/service_mysql_string.h>
2727
#include <mysql/service_mysql_alloc.h>
28+
#include <mysql/service_mysql_password_policy.h>
2829
#include <mysql/service_parser.h>
2930
#include <mysql/service_rpl_transaction_ctx.h>
3031
#include <mysql/service_rpl_transaction_write_set.h>

include/mysql/services.h.pp

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@
130130
extern void * my_memdup(PSI_memory_key key, const void *from, size_t length, myf_t flags);
131131
extern char * my_strdup(PSI_memory_key key, const char *from, myf_t flags);
132132
extern char * my_strndup(PSI_memory_key key, const char *from, size_t length, myf_t flags);
133+
#include <mysql/service_mysql_password_policy.h>
134+
extern struct mysql_password_policy_service_st {
135+
int (*my_validate_password_policy_func)(const char *);
136+
int (*my_calculate_password_strength_func)(const char *);
137+
} *mysql_password_policy_service;
138+
int my_validate_password_policy(const char *);
139+
int my_calculate_password_strength(const char *);
133140
#include <mysql/service_parser.h>
134141
#include "my_md5_size.h"
135142
#include <mysql/mysql_lex_string.h>

include/service_versions.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define VERSION_my_plugin_log 0x0100
2727
#define VERSION_mysql_string 0x0100
2828
#define VERSION_mysql_malloc 0x0100
29+
#define VERSION_mysql_password_policy 0x0100
2930
#define VERSION_parser 0x0100
3031
#define VERSION_rpl_transaction_ctx_service 0x0100
3132
#define VERSION_transaction_write_set_service 0x0100

libservices/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SET(MYSQLSERVICES_SOURCES
2323
my_thread_scheduler_service.c
2424
mysql_string_service.c
2525
mysql_malloc_service.c
26+
mysql_password_policy_service.c
2627
parser_service.c
2728
rpl_transaction_ctx_service.c
2829
rpl_transaction_write_set_service.c)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or
4+
modify it under the terms of the GNU General Public License as
5+
published by the Free Software Foundation; version 2 of the
6+
License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16+
17+
#include <service_versions.h>
18+
SERVICE_VERSION *mysql_password_policy_service= (void*)VERSION_mysql_password_policy;
19+

mysql-test/extra/binlog_tests/binlog.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ create table if not exists t3 like tt1;
227227

228228
--disable_warnings
229229
USE mysql;
230-
INSERT IGNORE INTO user SET host='localhost', user='@#@', password=password('Just a test');
231-
UPDATE user SET password=password('Another password') WHERE host='localhost' AND user='@#@';
230+
INSERT IGNORE INTO user SET host='localhost', user='@#@', authentication_string=password('Just a test');
231+
UPDATE user SET authentication_string=password('Another password') WHERE host='localhost' AND user='@#@';
232232
DELETE FROM user WHERE host='localhost' AND user='@#@';
233233
--enable_warnings
234234

mysql-test/extra/rpl_tests/rpl_implicit_commit_binlog.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ while ($ddl_cases >= 1)
220220
}
221221
if ($ddl_cases == 31)
222222
{
223-
let $cmd= SET PASSWORD FOR 'user'@'localhost' = PASSWORD('newpass');
223+
let $cmd= SET PASSWORD FOR 'user'@'localhost' = 'newpass';
224224
#
225225
# In NDB (RBR mode), the commit event is the 14th event
226226
# in the binary log:

mysql-test/extra/rpl_tests/rpl_row_001.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ connection slave;
2020
sync_with_master;
2121
STOP SLAVE;
2222
connection master;
23-
SET PASSWORD FOR root@"localhost" = PASSWORD('foo');
23+
SET PASSWORD FOR root@"localhost" = 'foo';
2424
connection slave;
2525
START SLAVE;
2626
connection master;
2727
#
2828
# Give slave time to do at last one failed connect retry
2929
# This one must be short so that the slave will not stop retrying
3030
real_sleep 2;
31-
SET PASSWORD FOR root@"localhost" = PASSWORD('');
31+
SET PASSWORD FOR root@"localhost" = '';
3232
# Give slave time to connect (will retry every second)
3333
sleep 2;
3434

mysql-test/include/concurrent.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let $keep_locks= `SELECT NOT @@global.innodb_locks_unsafe_for_binlog`;
4949
#
5050
# Set up privileges and remove user level locks, if exist.
5151
#
52-
GRANT USAGE ON test.* TO mysqltest@localhost;
52+
CREATE USER mysqltest@localhost;
5353

5454
#
5555
# Preparatory cleanup.

mysql-test/include/ipv6.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ connection default;
1313
disconnect con1;
1414
eval REVOKE ALL ON test.* FROM testuser@'$IPv6';
1515
eval RENAME USER testuser@'$IPv6' to testuser1@'$IPv6';
16-
eval SET PASSWORD FOR testuser1@'$IPv6' = PASSWORD ('9876');
16+
eval SET PASSWORD FOR testuser1@'$IPv6' = '9876';
1717
--replace_result ::1 localhost
1818
SELECT USER();
1919
eval DROP USER testuser1@'$IPv6';

0 commit comments

Comments
 (0)