Skip to content

Commit 91b596f

Browse files
committed
MDEV-36397 Record change_user command in MTR output
MTR .result files currently do not contain output to indicate if a change_user command has been executed in the corresponding .test files. Record change_user command in MTR output in the following format in MTR output only if enable_connect_log and enable_query_log is set to true: change_user <user>,<password>,<db>; All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
1 parent 4042652 commit 91b596f

31 files changed

+227
-10
lines changed

client/mysqltest.cc

+18
Original file line numberDiff line numberDiff line change
@@ -4662,6 +4662,24 @@ void do_change_user(struct st_command *command)
46624662
dynstr_set(&ds_db, mysql->db);
46634663
}
46644664

4665+
/* Connection logging if enabled */
4666+
if (!disable_query_log)
4667+
{
4668+
DYNAMIC_STRING *ds= &ds_res;
4669+
4670+
dynstr_append_mem(ds, STRING_WITH_LEN("change_user "));
4671+
replace_dynstr_append(ds, ds_user.str);
4672+
dynstr_append_mem(ds, STRING_WITH_LEN(","));
4673+
4674+
if (ds_passwd.length)
4675+
replace_dynstr_append(ds, ds_passwd.str);
4676+
dynstr_append_mem(ds, STRING_WITH_LEN(","));
4677+
4678+
if (ds_db.length)
4679+
replace_dynstr_append(ds, ds_db.str);
4680+
dynstr_append_mem(ds, STRING_WITH_LEN(";\n"));
4681+
}
4682+
46654683
DBUG_PRINT("info",("connection: '%s' user: '%s' password: '%s' database: '%s'",
46664684
cur_con->name, ds_user.str, ds_passwd.str, ds_db.str));
46674685

mysql-test/main/backup_priv.result

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ BACKUP STAGE FLUSH;
1313
SELECT lock_mode FROM information_schema.metadata_lock_info WHERE lock_type='Backup lock';
1414
lock_mode
1515
MDL_BACKUP_FLUSH
16+
change_user user2,,;
1617
SELECT lock_mode FROM information_schema.metadata_lock_info WHERE lock_type='Backup lock';
1718
lock_mode
1819
disconnect con1;

mysql-test/main/change_user.result

+14-5
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,35 @@ grant select on test.* to test_newpw;
1111
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
1212
concat('<', user(), '>') concat('<', current_user(), '>') database()
1313
<root@localhost> <root@localhost> test
14+
change_user test_nopw,,;
1415
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
1516
concat('<', user(), '>') concat('<', current_user(), '>') database()
1617
<test_nopw@localhost> <test_nopw@%> NULL
18+
change_user test_oldpw,oldpw,;
1719
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
1820
concat('<', user(), '>') concat('<', current_user(), '>') database()
1921
<test_oldpw@localhost> <test_oldpw@%> NULL
22+
change_user test_newpw,newpw,;
2023
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
2124
concat('<', user(), '>') concat('<', current_user(), '>') database()
2225
<test_newpw@localhost> <test_newpw@%> NULL
26+
change_user root,,;
2327
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
2428
concat('<', user(), '>') concat('<', current_user(), '>') database()
2529
<root@localhost> <root@localhost> NULL
30+
change_user test_nopw,,test;
2631
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
2732
concat('<', user(), '>') concat('<', current_user(), '>') database()
2833
<test_nopw@localhost> <test_nopw@%> test
34+
change_user test_oldpw,oldpw,test;
2935
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
3036
concat('<', user(), '>') concat('<', current_user(), '>') database()
3137
<test_oldpw@localhost> <test_oldpw@%> test
38+
change_user test_newpw,newpw,test;
3239
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
3340
concat('<', user(), '>') concat('<', current_user(), '>') database()
3441
<test_newpw@localhost> <test_newpw@%> test
42+
change_user root,,test;
3543
select concat('<', user(), '>'), concat('<', current_user(), '>'), database();
3644
concat('<', user(), '>') concat('<', current_user(), '>') database()
3745
<root@localhost> <root@localhost> test
@@ -45,7 +53,7 @@ SELECT @@session.sql_big_selects;
4553
SELECT @@global.max_join_size;
4654
@@global.max_join_size
4755
HA_POS_ERROR
48-
change_user
56+
change_user root,,test;
4957
SELECT @@session.sql_big_selects;
5058
@@session.sql_big_selects
5159
1
@@ -54,13 +62,13 @@ SELECT @@global.max_join_size;
5462
HA_POS_ERROR
5563
SET @@global.max_join_size = 10000;
5664
SET @@session.max_join_size = default;
57-
change_user
65+
change_user root,,test;
5866
SELECT @@session.sql_big_selects;
5967
@@session.sql_big_selects
6068
0
6169
SET @@global.max_join_size = 18446744073709551615;
6270
SET @@session.max_join_size = default;
63-
change_user
71+
change_user root,,test;
6472
SELECT @@session.sql_big_selects;
6573
@@session.sql_big_selects
6674
1
@@ -83,14 +91,15 @@ GET_LOCK('bug31418', 1)
8391
SELECT IS_USED_LOCK('bug31418') = CONNECTION_ID();
8492
IS_USED_LOCK('bug31418') = CONNECTION_ID()
8593
1
86-
change_user
94+
change_user root,,test;
8795
SELECT IS_FREE_LOCK('bug31418');
8896
IS_FREE_LOCK('bug31418')
8997
1
9098
SELECT IS_USED_LOCK('bug31418');
9199
IS_USED_LOCK('bug31418')
92100
NULL
93101
FLUSH STATUS;
102+
change_user root,,test;
94103
Value of com_select did not change
95104
set global secure_auth=default;
96105
Warnings:
@@ -102,7 +111,7 @@ now()
102111
select year(now()) > 2011;
103112
year(now()) > 2011
104113
0
105-
change_user
114+
change_user root,,test;
106115
select year(now()) > 2011;
107116
year(now()) > 2011
108117
1

mysql-test/main/change_user.test

-5
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,20 @@ SELECT @@session.sql_big_selects;
7474
# The exact value depends on the server build flags
7575
--replace_result 18446744073709551615 HA_POS_ERROR 4294967295 HA_POS_ERROR
7676
SELECT @@global.max_join_size;
77-
--echo change_user
7877
--change_user
7978
SELECT @@session.sql_big_selects;
8079
# The exact value depends on the server build flags
8180
--replace_result 18446744073709551615 HA_POS_ERROR 4294967295 HA_POS_ERROR
8281
SELECT @@global.max_join_size;
8382
SET @@global.max_join_size = 10000;
8483
SET @@session.max_join_size = default;
85-
--echo change_user
8684
--change_user
8785
SELECT @@session.sql_big_selects;
8886
# On some machines the following will result into a warning
8987
--disable_warnings
9088
SET @@global.max_join_size = 18446744073709551615;
9189
--enable_warnings
9290
SET @@session.max_join_size = default;
93-
--echo change_user
9491
--change_user
9592
SELECT @@session.sql_big_selects;
9693
--replace_result 4294967295 18446744073709551615
@@ -107,7 +104,6 @@ SELECT IS_FREE_LOCK('bug31418');
107104
SELECT IS_USED_LOCK('bug31418');
108105
SELECT GET_LOCK('bug31418', 1);
109106
SELECT IS_USED_LOCK('bug31418') = CONNECTION_ID();
110-
--echo change_user
111107
--change_user
112108
SELECT IS_FREE_LOCK('bug31418');
113109
SELECT IS_USED_LOCK('bug31418');
@@ -151,7 +147,6 @@ set global secure_auth=default;
151147
set timestamp=unix_timestamp('2010-10-10 10:10:10');
152148
select now();
153149
select year(now()) > 2011;
154-
--echo change_user
155150
--change_user
156151
select year(now()) > 2011;
157152
--enable_service_connection

mysql-test/main/change_user_notembedded.result

+6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
connect test,localhost,root,,;
22
connection test;
3+
change_user foo,bar,;
34
ERROR 28000: Access denied for user 'foo'@'localhost' (using password: YES)
5+
change_user foo,,;
46
ERROR 28000: Access denied for user 'foo'@'localhost' (using password: NO)
7+
change_user root,,test;
8+
change_user foo,bar,;
59
ERROR 28000: Access denied for user 'foo'@'localhost' (using password: YES)
10+
change_user foo,bar,;
611
ERROR 08S01: Unknown command
12+
change_user root,,test;
713
ERROR 08S01: Unknown command
814
disconnect test;
915
connection default;

mysql-test/main/cte_nonrecursive.result

+1
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ use test;
16761676
# THD::create_tmp_table_def_key
16771677
#
16781678
connect con1,localhost,root,,;
1679+
change_user root,,;
16791680
CREATE TEMPORARY TABLE test.t (a INT);
16801681
WITH cte AS (SELECT 1) SELECT * FROM cte;
16811682
1

mysql-test/main/failed_auth_3909.result

+3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ ERROR HY000: Server is running in --secure-auth mode, but 'uu2'@'localhost' has
1010
connect(localhost,uu2,password,test,MASTER_PORT,MASTER_SOCKET);
1111
connect fail,localhost,uu2,password;
1212
ERROR HY000: Server is running in --secure-auth mode, but 'uu2'@'localhost' has a password in the old format; please change the password to the new format
13+
change_user u1,,;
1314
ERROR 28000: Access denied for user 'u1'@'localhost' (using password: NO)
15+
change_user uu2,,;
1416
ERROR HY000: Server is running in --secure-auth mode, but 'uu2'@'localhost' has a password in the old format; please change the password to the new format
17+
change_user uu2,password,;
1518
ERROR HY000: Server is running in --secure-auth mode, but 'uu2'@'localhost' has a password in the old format; please change the password to the new format
1619
delete from mysql.user where plugin = 'mysql_old_password';
1720
flush privileges;

mysql-test/main/failed_auth_unixsocket.result

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ delete from mysql.global_priv where user != 'root';
44
flush privileges;
55
connect(localhost,USER,,test,MASTER_PORT,MASTER_SOCKET);
66
ERROR 28000: Access denied for user 'USER'@'localhost'
7+
change_user buildbot,,;
78
ERROR 28000: Access denied for user 'USER'@'localhost'
89
replace mysql.global_priv select * from global_priv_backup;
910
flush privileges;

mysql-test/main/lock_user.result

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ connection default;
129129
# account is locked
130130
#
131131
alter user user1@localhost account lock;
132+
change_user user1,,;
132133
ERROR HY000: Access denied, this account is locked
133134
#
134135
# MDEV-24098 SHOW CREATE USER invalid for both PASSWORD EXPIRE and

mysql-test/main/max_password_errors.result

+3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ connect(localhost,u,bad_pass,test,MASTER_PORT,MASTER_SOCKET);
2525
connect con1, localhost, u, bad_pass;
2626
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
2727
connect con1, localhost, u, good_pass;
28+
change_user u,bad_pass,;
2829
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
30+
change_user u,bad_pass,;
2931
ERROR 28000: Access denied for user 'u'@'localhost' (using password: YES)
32+
change_user u,good_pass,;
3033
ERROR HY000: User is blocked because of too many credential errors; unblock with 'ALTER USER / FLUSH PRIVILEGES'
3134
disconnect con1;
3235
connection default;

mysql-test/main/mysql_upgrade.result

+2
Original file line numberDiff line numberDiff line change
@@ -1159,11 +1159,13 @@ connection default;
11591159
GRANT SELECT ON mysql.* TO very_long_user_name_number_1;
11601160
GRANT SELECT ON mysql.* TO very_long_user_name_number_2;
11611161
GRANT ALL ON *.* TO even_longer_user_name_number_3_to_test_the_grantor_and_definer_field_length@localhost WITH GRANT OPTION;
1162+
change_user even_longer_user_name_number_3_to_test_the_grantor_and_definer_field_length,,;
11621163
GRANT INSERT ON mysql.user TO very_long_user_name_number_1;
11631164
GRANT INSERT ON mysql.user TO very_long_user_name_number_2;
11641165
GRANT UPDATE (User) ON mysql.db TO very_long_user_name_number_1;
11651166
GRANT UPDATE (User) ON mysql.db TO very_long_user_name_number_2;
11661167
CREATE PROCEDURE test.pr() BEGIN END;
1168+
change_user root,,;
11671169
Phase 1/8: Checking and upgrading mysql database
11681170
Processing databases
11691171
mysql

mysql-test/main/mysqltest.result

+4
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,10 @@ drop table t1;
949949
mysqltest: At line 1: query 'change_user root,,inexistent' failed: ER_BAD_DB_ERROR (1049): Unknown database 'inexistent'
950950
mysqltest: At line 1: query 'change_user inexistent,,test' failed: ER_ACCESS_DENIED_ERROR (1045): Access denied for user 'inexistent'@'localhost' (using password: NO)
951951
mysqltest: At line 1: query 'change_user root,inexistent,test' failed: ER_ACCESS_DENIED_ERROR (1045): Access denied for user 'root'@'localhost' (using password: YES)
952+
change_user root,,test;
953+
change_user root,,;
954+
change_user root,,;
955+
change_user root,,test;
952956
REPLACED_FILE1.txt
953957
file1.txt
954958
file2.txt

mysql-test/main/opt_trace_security.result

+13
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ BEGIN
1111
insert into t2 select * from t1;
1212
return a+1;
1313
END|
14+
change_user foo,,;
1415
set optimizer_trace="enabled=on";
1516
select * from db1.t1;
1617
ERROR 42000: SELECT command denied to user 'foo'@'localhost' for table `db1`.`t1`
1718
select * from information_schema.OPTIMIZER_TRACE;
1819
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
1920
0 1
2021
set optimizer_trace="enabled=off";
22+
change_user root,,;
2123
grant select(a) on db1.t1 to 'foo'@'%';
24+
change_user foo,,;
2225
set optimizer_trace="enabled=on";
2326
select * from db1.t1;
2427
a
@@ -32,10 +35,12 @@ select * from information_schema.OPTIMIZER_TRACE;
3235
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
3336
0 1
3437
set optimizer_trace="enabled=off";
38+
change_user root,,;
3539
select * from information_schema.OPTIMIZER_TRACE;
3640
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
3741
grant select on db1.t1 to 'foo'@'%';
3842
grant select on db1.t2 to 'foo'@'%';
43+
change_user foo,,;
3944
set optimizer_trace="enabled=on";
4045
#
4146
# SELECT privilege on the table db1.t1
@@ -158,10 +163,12 @@ select * from db1.t1 {
158163
]
159164
} 0 0
160165
set optimizer_trace="enabled=off";
166+
change_user root,,;
161167
grant select on db1.v1 to 'foo'@'%';
162168
grant show view on db1.v1 to 'foo'@'%';
163169
grant select on db1.v1 to 'bar'@'%';
164170
grant show view on db1.v1 to 'bar'@'%';
171+
change_user foo,,;
165172
select current_user();
166173
current_user()
167174
foo@%
@@ -300,6 +307,7 @@ select * from db1.v1 {
300307
]
301308
} 0 0
302309
set optimizer_trace="enabled=off";
310+
change_user bar,,;
303311
select current_user();
304312
current_user()
305313
bar@%
@@ -319,10 +327,12 @@ select * from information_schema.OPTIMIZER_TRACE;
319327
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
320328
0 1
321329
set optimizer_trace="enabled=off";
330+
change_user root,,;
322331
grant execute on function db1.f1 to 'foo'@'%';
323332
grant execute on function db1.f1 to 'bar'@'%';
324333
grant select on db1.t1 to 'bar'@'%';
325334
grant insert on db1.t2 to 'foo'@'%';
335+
change_user foo,,;
326336
select current_user();
327337
current_user()
328338
foo@%
@@ -336,6 +346,7 @@ select INSUFFICIENT_PRIVILEGES from information_schema.OPTIMIZER_TRACE;
336346
INSUFFICIENT_PRIVILEGES
337347
0
338348
set optimizer_trace="enabled=off";
349+
change_user bar,,;
339350
select current_user();
340351
current_user()
341352
bar@%
@@ -354,10 +365,12 @@ select * from information_schema.OPTIMIZER_TRACE;
354365
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
355366
0 1
356367
set optimizer_trace="enabled=off";
368+
change_user root,,;
357369
select current_user();
358370
current_user()
359371
root@localhost
360372
REVOKE ALL PRIVILEGES, GRANT OPTION FROM foo;
373+
change_user root,,;
361374
drop user if exists foo;
362375
drop user if exists bar;
363376
drop table db1.t1, db1.t2;

0 commit comments

Comments
 (0)