1
############ suite/funcs_1/datadict/processlist_priv.inc ###############
3
# Testing of privileges around #
4
# SELECT ... PROCESSLIST/SHOW PROCESSLIST #
7
# There is a significant risk to get an unstable test because of #
10
# 1. Disconnect connection X #
11
# 2. Switch to connection Y #
12
# 3. SHOW PROCESSLIST might present a record like #
13
# <ID> <user> <host> <db> Quit 0 cleaning up NULL #
14
# or even a row where connection X is without #
15
# "Quit" or "cleaning up". #
16
# That means our SHOW PROCESSLIST can come too early. #
18
# Close the connections at the end of the test. #
19
# Example2 (2008-08-14 again observed): #
20
# 1. connection X: SHOW PROCESSLIST/GRANT ... etc. #
21
# 2. Switch to connection Y #
22
# 3. SHOW PROCESSLIST might present a record like #
23
# <ID> <user> <host> <db> Query TIME cleaning up <command> #
24
# <ID> <user> <host> <db> Query TIME writing to net <command> #
25
# Problems happens more often in case of slow filesystem! #
27
# Insert a dummy SQL command where the cleanup is most probably #
28
# fast before switching to another connection and running #
29
# SHOW/SELECT PROCESSLIST. #
30
# Suppress writing to protocol by assignment to $variable. #
31
# let $my_var= `SELECT 1`; #
32
# Even the 'SELECT 1' was in some cases in state #
36
# This value was at least on my box sufficient. #
37
# Please inform us if this test fails so that we can adjust #
38
# the sleep time better or switch to poll routines. #
40
# Storage engine variants of this test do not make sense. #
41
# - I_S tables use the MEMORY storage engine whenever possible. #
42
# - There are some I_S table which need column data types which #
43
# are not supported by MEMORY. Example: LONGTEXT/BLOB #
44
# MyISAM will be used for such tables. #
45
# The column PROCESSLIST.INFO is of data type LONGTEXT #
47
# - There is no impact of the GLOBAL(server) or SESSION default #
48
# storage engine setting on the engine used for I_S tables. #
49
# That means we cannot get NDB or InnoDB instead. #
52
# 2007-08 hhunger Implement this test as part of #
53
# WL#3982 Test information_schema.processlist #
56
# 2008-08-14 mleich Bug#38270 Test "processlist_priv_ps" fails on #
57
# varying "processlist" output #
58
# - Replace one sleep by a poll routines #
59
# - Remove or disable superfluous sleeps #
61
########################################################################
63
# The following variables are used in "datadict_priv.inc" and here.
65
# information_schema table to be tested
66
let $table= processlist;
68
# columns of the information_schema table e.g. to use in a select.
69
let $columns= ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO;
71
# Where clause for an update.
72
let $update_where= WHERE id=1 ;
74
# Column to be used in the SET of an update.
75
let $set_column= user='any_user' ;
77
# Where clause of a delete.
78
let $delete_where= WHERE id=1 ;
80
# Column to be dropped.
81
let $drop_column= user;
83
# Column to be indexed
86
USE information_schema;
88
--echo ####################################################################################
89
--echo 1 Prepare test.
90
--echo connection default (user=root)
91
--echo ####################################################################################
92
if (`SELECT COUNT(*) <> 1 FROM processlist`)
94
--echo This test expects one connection to the server.
95
--echo Expectation: USER HOST DB COMMAND STATE INFO
96
--echo Expectation: root localhost information_schema Query executing SELECT USER,HOST,DB,COMMAND,STATE,INFO FROM processlist ORDER BY ID
97
--echo But we found in the moment:
98
SELECT USER,HOST,DB,COMMAND,STATE,INFO FROM processlist ORDER BY ID;
100
--echo - the base configuration (no of parallel auxiliary sessions) of the server has changed
101
--echo - a parallel test intended for another server accidently connected to our current one
102
--echo We cannot proceed in this situation. Abort
106
--echo ####################################################################################
107
--echo 1.1 Create two user
108
--echo ####################################################################################
109
# access to info tables as normal user
110
--error 0, ER_CANNOT_USER
111
DROP USER ddicttestuser1@'localhost';
112
--error 0, ER_CANNOT_USER
113
DROP USER ddicttestuser2@'localhost';
114
CREATE USER ddicttestuser1@'localhost';
115
CREATE USER ddicttestuser2@'localhost';
116
SET PASSWORD FOR ddicttestuser1@'localhost' = PASSWORD('ddictpass');
117
SET PASSWORD FOR ddicttestuser2@'localhost' = PASSWORD('ddictpass');
119
--echo ####################################################################################
120
--echo 1.2 Establish connection con100 (user=ddicttestuser1 with no PROCESS privilege):
121
connect (con100,localhost,ddicttestuser1,ddictpass,information_schema);
122
--echo ####################################################################################
125
--echo ####################################################################################
126
--echo 2 connection default(user=root with default privileges):
127
--echo SHOW/SELECT shows all processes/threads.
128
--echo ####################################################################################
130
# Avoid Bug#38270 Test "processlist_priv_ps" fails on varying "processlist" output
131
# This subtest expects that the connection con100 is in state 'Sleep'.
132
# Poll till the connection con100 is in state COMMAND = 'Sleep'.
133
let $wait_timeout= 10;
135
SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST
136
WHERE DB = 'information_schema' AND COMMAND = 'Sleep' AND USER = 'ddicttestuser1';
137
--source include/wait_condition.inc
138
eval SHOW CREATE TABLE $table;
139
--replace_column 1 ID 3 HOST_NAME 6 TIME
141
--replace_column 1 ID 3 HOST_NAME 6 TIME
142
eval SELECT * FROM $table $select_where ORDER BY id;
143
--replace_column 1 ID 3 HOST_NAME 6 TIME
144
eval SELECT $columns FROM $table $select_where ORDER BY id;
145
--source suite/funcs_1/datadict/datadict_priv.inc
148
--echo ####################################################################################
149
--echo 3 Switch to connection con100 (user=ddicttestuser1 with no PROCESS privilege):
151
--echo SHOW/SELECT shows only the processes (1) of the user.
152
--echo ####################################################################################
153
# No need for poll routine here.
154
# The current state of the default session might depend on load of testing box
155
# but "ddicttestuser1" must not see anything of the root session.
156
eval SHOW CREATE TABLE $table;
157
--replace_column 1 ID 3 HOST_NAME 6 TIME
159
--replace_column 1 ID 3 HOST_NAME 6 TIME
160
eval SELECT * FROM $table $select_where ORDER BY id;
161
--replace_column 1 ID 3 HOST_NAME 6 TIME
162
eval SELECT $columns FROM $table $select_where ORDER BY id;
163
--source suite/funcs_1/datadict/datadict_priv.inc
167
--echo ####################################################################################
168
--echo 4 Grant PROCESS privilege to ddicttestuser1
169
--echo connection default (user=root)
170
--echo ####################################################################################
172
GRANT PROCESS ON *.* TO ddicttestuser1@'localhost' IDENTIFIED BY 'ddictpass';
175
--echo ####################################################################################
176
--echo 4.1 Existing connection con100 (ddicttestuser1)
177
--echo The user ddicttestuser1 has the PROCESS privilege, but the connection was
178
--echo established before PROCESS was granted.
179
--echo SHOW/SELECT shows only the processes (1) of the user.
180
--echo ####################################################################################
183
--replace_column 1 ID 3 HOST_NAME 6 TIME
185
--replace_column 1 ID 3 HOST_NAME 6 TIME
186
SELECT * FROM information_schema.processlist;
189
--echo ####################################################################################
190
--echo 4.2 New connection con101 (ddicttestuser1 with PROCESS privilege)
191
--echo SHOW/SELECT shows all processes/threads.
192
--echo ####################################################################################
193
connect (con101,localhost,ddicttestuser1,ddictpass,information_schema);
195
--replace_column 1 ID 3 HOST_NAME 6 TIME
197
--replace_column 1 ID 3 HOST_NAME 6 TIME
198
SELECT * FROM information_schema.processlist;
202
--echo ####################################################################################
203
--echo 5 Grant PROCESS privilege to anonymous user.
204
--echo connection default (user=root)
205
--echo ####################################################################################
207
GRANT PROCESS ON *.* TO ''@'localhost';
210
--echo ####################################################################################
211
--echo 5.1 Establish connection (anonymous1,localhost,'',,information_schema)
212
--echo anonymous user with PROCESS privilege
213
--echo SHOW/SELECT shows all processes/threads.
214
--echo ####################################################################################
215
connect (anonymous1,localhost,"''",,information_schema);
217
--replace_column 1 ID 3 HOST_NAME 6 TIME
219
--replace_column 1 ID 3 HOST_NAME 6 TIME
220
SELECT * FROM information_schema.processlist;
224
--echo ####################################################################################
225
--echo 6 Revoke PROCESS privilege from ddicttestuser1
226
--echo connection default (user=root)
227
--echo ####################################################################################
229
REVOKE PROCESS ON *.* FROM ddicttestuser1@'localhost' IDENTIFIED BY 'ddictpass';
232
--echo ####################################################################################
233
--echo 6.1 New connection con102 (ddicttestuser1 has no more PROCESS privilege)
234
connect (con102,localhost,ddicttestuser1,ddictpass,information_schema);
235
--echo Again (compared to state before GRANT PROCESS) only the processes of
236
--echo ddicttestuser1 are visible.
237
--echo ####################################################################################
239
--replace_column 1 ID 3 HOST_NAME 6 TIME
241
--replace_column 1 ID 3 HOST_NAME 6 TIME
242
SELECT * FROM information_schema.processlist;
246
--echo ####################################################################################
247
--echo 7 Revoke PROCESS privilege from anonymous user
248
--echo connection default (user=root)
249
--echo ####################################################################################
251
REVOKE PROCESS ON *.* FROM ''@'localhost';
254
--echo ####################################################################################
255
--echo 7.1 New connection (anonymous2,localhost,'',,information_schema)
256
connect (anonymous2,localhost,"''",,information_schema);
257
--echo The anonymous user has no more the PROCESS privilege
258
--echo Again only the processes of the anonymous user are visible.
259
--echo ####################################################################################
260
SHOW GRANTS FOR ''@'localhost';
261
if ($fixed_bug_30395)
263
# Bug#30395 strange results after REVOKE PROCESS ON *.* FROM ...
264
--replace_column 1 ID 3 HOST_NAME 6 TIME
267
--replace_column 1 ID 3 HOST_NAME 6 TIME
268
SELECT * FROM information_schema.processlist;
272
--echo ####################################################################################
273
--echo 8 Grant SUPER (does not imply PROCESS) privilege to ddicttestuser1
274
--echo connection default (user=root)
275
--echo ####################################################################################
277
GRANT SUPER ON *.* TO 'ddicttestuser1'@'localhost';
280
--echo ####################################################################################
281
--echo 8.1 New connection con103 (ddicttestuser1 with SUPER privilege)
282
connect (con103,localhost,ddicttestuser1,ddictpass,information_schema);
283
--echo Only the processes of ddicttestuser1 user are visible.
284
--echo ####################################################################################
285
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
286
--replace_column 1 ID 3 HOST_NAME 6 TIME
288
--replace_column 1 ID 3 HOST_NAME 6 TIME
289
SELECT * FROM information_schema.processlist;
293
--echo ####################################################################################
294
--echo 9 Revoke SUPER privilege from user ddicttestuser1
295
--echo connection default (user=root)
296
--echo ####################################################################################
298
REVOKE SUPER ON *.* FROM 'ddicttestuser1'@'localhost';
301
--echo ####################################################################################
302
--echo 9.1 New connection con104 (ddicttestuser1 without SUPER privilege)
303
connect (con104,localhost,ddicttestuser1,ddictpass,information_schema);
304
--echo ddicttestuser1 has no more the SUPER privilege.
305
--echo Only the processes of ddicttestuser1 are visible.
306
--echo ####################################################################################
307
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
308
--replace_column 1 ID 3 HOST_NAME 6 TIME
310
--replace_column 1 ID 3 HOST_NAME 6 TIME
311
SELECT * FROM information_schema.processlist;
315
--echo ####################################################################################
316
--echo 10 Grant SUPER privilege with grant option to user ddicttestuser1.
317
--echo connection default (user=root)
318
--echo ####################################################################################
320
GRANT SUPER ON *.* TO 'ddicttestuser1'@'localhost' WITH GRANT OPTION;
323
--echo ####################################################################################
324
--echo 10.1 New connection con105 (ddicttestuser1 with SUPER privilege and GRANT OPTION)
325
connect (con105,localhost,ddicttestuser1,ddictpass,information_schema);
326
--echo Try to grant PROCESS privilege to user ddicttestuser2 without having it.
327
--echo ####################################################################################
328
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
329
--error ER_ACCESS_DENIED_ERROR
330
GRANT PROCESS ON *.* TO 'ddicttestuser2'@'localhost';
332
--echo ####################################################################################
333
--echo 10.2 Grant SUPER and PROCESS privilege with grant option to user ddicttestuser1
334
--echo connection default (user=root)
335
--echo ####################################################################################
337
GRANT SUPER,PROCESS ON *.* TO 'ddicttestuser1'@'localhost' WITH GRANT OPTION;
340
--echo ####################################################################################
341
--echo 10.3 New connection con106 (ddicttestuser1 with SUPER,PROCESS WITH GRANT OPTION)
342
connect (con106,localhost,ddicttestuser1,ddictpass,information_schema);
343
--echo Grant PROCESS privilege to user ddicttestuser2
344
--echo ####################################################################################
345
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
346
GRANT PROCESS ON *.* TO 'ddicttestuser2'@'localhost';
349
--echo ####################################################################################
350
--echo 10.4 New connection con200 (ddicttestuser2 with PROCESS privilege)
351
connect (con200,localhost,ddicttestuser2,ddictpass,information_schema);
352
--echo ddicttestuser2 has now the PROCESS privilege and sees all connections
353
--echo ####################################################################################
354
SHOW GRANTS FOR 'ddicttestuser2'@'localhost';
355
--replace_column 1 ID 3 HOST_NAME 6 TIME
357
--replace_column 1 ID 3 HOST_NAME 6 TIME
358
SELECT * FROM information_schema.processlist;
362
--echo ####################################################################################
363
--echo 11 User ddicttestuser1 revokes PROCESS privilege from user ddicttestuser2
364
--echo connection ddicttestuser1;
365
--echo ####################################################################################
367
REVOKE PROCESS ON *.* FROM 'ddicttestuser2'@'localhost';
370
--echo ####################################################################################
371
--echo 11.1 New connection con201 (ddicttestuser2)
372
connect (con201,localhost,ddicttestuser2,ddictpass,information_schema);
373
--echo ddicttestuser2 has no more the PROCESS privilege and can only see own connects
374
--echo ####################################################################################
376
--replace_column 1 ID 3 HOST_NAME 6 TIME
378
--replace_column 1 ID 3 HOST_NAME 6 TIME
379
SELECT * FROM information_schema.processlist;
382
--echo ####################################################################################
383
--echo 11.2 Revoke SUPER,PROCESS,GRANT OPTION privilege from user ddicttestuser1
384
--echo connection default (user=root)
385
--echo ####################################################################################
387
REVOKE SUPER,PROCESS,GRANT OPTION ON *.* FROM 'ddicttestuser1'@'localhost';
390
--echo ####################################################################################
391
--echo 11.3 New connection con107 (ddicttestuser1)
392
connect (con107,localhost,ddicttestuser1,ddictpass,information_schema);
393
--echo ddicttestuser1 has no more the PROCESS privilege and can only see own connects
394
--echo He is also unable to GRANT the PROCESS privilege to ddicttestuser2
395
--echo ####################################################################################
396
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
397
--error ER_ACCESS_DENIED_ERROR
398
GRANT PROCESS ON *.* TO 'ddicttestuser2'@'localhost';
399
--replace_column 1 ID 3 HOST_NAME 6 TIME
401
--replace_column 1 ID 3 HOST_NAME 6 TIME
402
SELECT * FROM information_schema.processlist;
406
--echo ####################################################################################
407
--echo 12 Revoke the SELECT privilege from user ddicttestuser1
408
--echo connection default (user=root)
409
--echo ####################################################################################
411
REVOKE SELECT ON *.* FROM 'ddicttestuser1'@'localhost';
414
--echo ####################################################################################
415
--echo 12.1 New connection con108 (ddicttestuser1)
416
connect (con108,localhost,ddicttestuser1,ddictpass,information_schema);
417
--echo ddicttestuser1 has neither PROCESS nor SELECT privilege
418
--echo Manual says: Each MySQL user has the right to access these tables, but can see
419
--echo only the rows ...
420
--echo Therefore the missing SELECT privilege does not affect SELECTs on PROCESSLIST.
421
--echo ####################################################################################
422
SHOW GRANTS FOR 'ddicttestuser1'@'localhost';
423
--replace_column 1 ID 3 HOST_NAME 6 TIME
425
--replace_column 1 ID 3 HOST_NAME 6 TIME
426
SELECT * FROM information_schema.processlist;
429
--echo ####################################################################################
430
--echo 12.2 Revoke only the SELECT privilege on the information_schema from ddicttestuser1.
431
--echo connection default (user=root)
432
--echo ####################################################################################
434
--error ER_DBACCESS_DENIED_ERROR
435
REVOKE SELECT ON information_schema.* FROM 'ddicttestuser3'@'localhost';
439
--echo ####################################################################################
440
--echo connection default (user=root)
441
--echo Cleanup: close connections, DROP USER etc.
442
--echo ####################################################################################
455
disconnect anonymous1;
456
disconnect anonymous2;
457
DROP USER ddicttestuser1@'localhost';
458
DROP USER ddicttestuser2@'localhost';
459
REVOKE USAGE ON *.* FROM ''@'localhost';
460
DROP USER ''@'localhost';