Skip to content

Commit 56f4c21

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 cbd6755 commit 56f4c21

30 files changed

+230
-4
lines changed

client/mysqltest.cc

+17
Original file line numberDiff line numberDiff line change
@@ -4655,6 +4655,23 @@ void do_change_user(struct st_command *command)
46554655
dynstr_set(&ds_db, mysql->db);
46564656
}
46574657

4658+
/* Connection logging if enabled */
4659+
if (!disable_connect_log && !disable_query_log)
4660+
{
4661+
DYNAMIC_STRING *ds= &ds_res;
4662+
4663+
dynstr_append_mem(ds, "change_user ", 12);
4664+
replace_dynstr_append(ds, ds_user.str);
4665+
dynstr_append_mem(ds, ",", 1);
4666+
4667+
if (ds_passwd.length)
4668+
replace_dynstr_append(ds, ds_passwd.str);
4669+
dynstr_append_mem(ds, ",", 1);
4670+
4671+
replace_dynstr_append(ds, ds_db.str);
4672+
dynstr_append_mem(ds, ";\n", 2);
4673+
}
4674+
46584675
DBUG_PRINT("info",("connection: '%s' user: '%s' password: '%s' database: '%s'",
46594676
cur_con->name, ds_user.str, ds_passwd.str, ds_db.str));
46604677

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
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
@@ -46,6 +54,7 @@ SELECT @@global.max_join_size;
4654
@@global.max_join_size
4755
HA_POS_ERROR
4856
change_user
57+
change_user root,,test;
4958
SELECT @@session.sql_big_selects;
5059
@@session.sql_big_selects
5160
1
@@ -55,12 +64,14 @@ HA_POS_ERROR
5564
SET @@global.max_join_size = 10000;
5665
SET @@session.max_join_size = default;
5766
change_user
67+
change_user root,,test;
5868
SELECT @@session.sql_big_selects;
5969
@@session.sql_big_selects
6070
0
6171
SET @@global.max_join_size = 18446744073709551615;
6272
SET @@session.max_join_size = default;
6373
change_user
74+
change_user root,,test;
6475
SELECT @@session.sql_big_selects;
6576
@@session.sql_big_selects
6677
1
@@ -84,13 +95,15 @@ SELECT IS_USED_LOCK('bug31418') = CONNECTION_ID();
8495
IS_USED_LOCK('bug31418') = CONNECTION_ID()
8596
1
8697
change_user
98+
change_user root,,test;
8799
SELECT IS_FREE_LOCK('bug31418');
88100
IS_FREE_LOCK('bug31418')
89101
1
90102
SELECT IS_USED_LOCK('bug31418');
91103
IS_USED_LOCK('bug31418')
92104
NULL
93105
FLUSH STATUS;
106+
change_user root,,test;
94107
Value of com_select did not change
95108
set global secure_auth=default;
96109
Warnings:
@@ -103,6 +116,7 @@ select year(now()) > 2011;
103116
year(now()) > 2011
104117
0
105118
change_user
119+
change_user root,,test;
106120
select year(now()) > 2011;
107121
year(now()) > 2011
108122
1

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,9 @@ INSERT INTO t1 SELECT f1 - 256 FROM t1;
883883
INSERT INTO t1 SELECT f1 - 512 FROM t1;
884884
SELECT * FROM t1;
885885
DROP TABLE t1;
886-
select "500g bl�b�rsyltet�y" as "will be lower cased";
886+
select "500g bl�b�rsyltet�y" as "will be lower cased";
887887
will be lower cased
888-
500g bl�b�rsyltet�y
888+
500g bl�b�rsyltet�y
889889
SELECT "UPPER" AS "WILL NOT BE lower cased";
890890
WILL NOT BE lower cased
891891
UPPER
@@ -903,8 +903,8 @@ xyz
903903
select 1 as "some new text";
904904
some new text
905905
1
906-
select 0 as "will not lower case ���";
907-
will not lower case ���
906+
select 0 as "will not lower case ���";
907+
will not lower case ���
908908
0
909909
CREATE TABLE t1(
910910
a int, b varchar(255), c datetime
@@ -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)