summaryrefslogtreecommitdiff
path: root/mysql-test/suite/rpl/r/rpl_current_user.result
blob: ba5269bef2269d3dedaee0b822dce2286ac93220 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
include/rpl_init.inc [topology=1->2->3]
include/rpl_connect.inc [creating master]
include/rpl_connect.inc [creating slave]
connection master;
CREATE TABLE t1(c1 char(100));
CREATE VIEW test.v_user AS SELECT * FROM mysql.user WHERE User LIKE 'bug48321%';
CREATE VIEW test.v_tables_priv AS SELECT * FROM mysql.tables_priv WHERE User LIKE 'bug48321%';
CREATE VIEW test.v_procs_priv AS SELECT * FROM mysql.procs_priv WHERE User LIKE 'bug48321%';
CREATE VIEW test.v_event AS SELECT definer FROM mysql.event WHERE name = 'e1';
CREATE PROCEDURE p1() SELECT 1;
# bug48321_1-01234 has the max length(16) of user.
CREATE USER 'bug48321_1-01234'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'bug48321_1-01234'@'localhost' WITH GRANT OPTION;

# Test the max lengths of user and host names
# the user name is too long
GRANT CREATE USER ON *.* TO '012345678901234567890123456789012345678901234567890123456789012345678901234567890'@'fakehost';
ERROR HY000: String '0123456789012345678901234567890123456789012345678901234567890123456789' is too long for user name (should be no longer than 80)
# the host name is too long
GRANT CREATE USER ON *.* TO 'fakename'@'0123456789012345678901234567890123456789012345678901234567890';
ERROR HY000: String '0123456789012345678901234567890123456789012345678901234567890' is too long for host name (should be no longer than 60)

# User 'bug48321_1-01234' connects to master by conn1
connect  conn1, 127.0.0.1, 'bug48321_1-01234'@'localhost',,;
connection conn1;
# Verify 'REVOKE ALL' statement
REVOKE ALL PRIVILEGES, GRANT OPTION FROM CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_user, server_2:v_user, server_3:v_user]

# Verify 'GRANT ... ON TABLE ...' statement
GRANT CREATE, INSERT, SELECT ON TABLE test.t1 TO CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_tables_priv, server_2:v_tables_priv, server_3:v_tables_priv]

# Verify 'GRANT ... ON PROCEDURE...' statement
GRANT ALTER ROUTINE, EXECUTE ON PROCEDURE p1 TO CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_procs_priv, server_2:v_procs_priv, server_3:v_procs_priv]

# Verify 'GRANT ... ON *.* ...' statement
GRANT ALL PRIVILEGES ON *.* TO CURRENT_USER() WITH GRANT OPTION;
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_procs_priv, server_2:v_procs_priv, server_3:v_procs_priv]

# Verify 'REVOKE ... ON TABLE ...' statement
REVOKE CREATE, INSERT, SELECT ON TABLE t1 FROM CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_tables_priv, server_2:v_tables_priv, server_3:v_tables_priv]

# Verify 'REVOKE ... ON PROCEDURE...' statement
REVOKE ALTER ROUTINE, EXECUTE ON PROCEDURE p1 FROM CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_procs_priv, server_2:v_procs_priv, server_3:v_procs_priv]

# Verify 'REVOKE ... ON *.* ...' statement
REVOKE ALL PRIVILEGES ON *.* FROM CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_user, server_2:v_user, server_3:v_user]

# Verify 'GRANT ...' statement in the procedure
CREATE PROCEDURE my_grant()
GRANT CREATE, INSERT, SELECT ON TABLE test.t1 TO CURRENT_USER();
call my_grant;
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_tables_priv, server_2:v_tables_priv, server_3:v_tables_priv]

# Verify 'REVOKE ... ON TABLE ...' statement in the procedure
CREATE PROCEDURE my_revoke()
REVOKE CREATE, INSERT, SELECT ON TABLE t1 FROM CURRENT_USER();
call my_revoke;
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_tables_priv, server_2:v_tables_priv, server_3:v_tables_priv]

# Verify 'RENAME USER ...' statement
RENAME USER CURRENT_USER TO 'bug48321_2'@'localhost';
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_user, server_2:v_user, server_3:v_user]
disconnect conn1;

# Verify 'DROP USER ...' statement
connection master;
GRANT CREATE USER ON *.* TO 'bug48321_2'@'localhost';
connect  conn1, 127.0.0.1, 'bug48321_2'@'localhost',,;
connection conn1;
DROP USER CURRENT_USER();
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_user, server_2:v_user, server_3:v_user]

# Verify 'ALTER EVENT...' statement
connection master;
CREATE EVENT e1 ON SCHEDULE EVERY 1 DAY DO SELECT * FROM t1;
# Explicitly assign CURRENT_USER() to definer
ALTER DEFINER=CURRENT_USER() EVENT e1 ENABLE;
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_event, server_2:v_event, server_3:v_event]

# Session user will be set as definer, if the statement does not assign
# a definer
ALTER EVENT e1 ENABLE;
include/rpl_sync.inc
include/diff_tables.inc [server_1:v_event, server_2:v_event, server_3:v_event]

# Verify that this patch does not affect the calling of CURRENT_USER() 
# in the other statements
connection master;
INSERT INTO t1 VALUES(CURRENT_USER()), ('1234');
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave
SELECT * FROM t1;
c1
root@localhost
1234
connection slave;
SELECT * FROM t1;
c1
@
1234
connection server_3;
SELECT * FROM t1;
c1
@
1234
connection master;
UPDATE t1 SET c1=CURRENT_USER() WHERE c1='1234';
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave
SELECT * FROM t1;
c1
root@localhost
root@localhost
connection slave;
SELECT * FROM t1;
c1
@
@
connection server_3;
SELECT * FROM t1;
c1
@
@
connection master;
DELETE FROM t1 WHERE c1=CURRENT_USER();
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave
SELECT * FROM t1;
c1
connection slave;
SELECT * FROM t1;
c1
connection server_3;
SELECT * FROM t1;
c1
connection master;
CREATE TABLE t2(c1 char(100));
CREATE FUNCTION my_user() RETURNS VARCHAR(64) 
SQL SECURITY INVOKER 
BEGIN
INSERT INTO t2 VALUES(CURRENT_USER());
RETURN CURRENT_USER();
END |
INSERT INTO t1 VALUES(my_user());
Warnings:
Note	1592	Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave
SELECT * FROM t1;
c1
root@localhost
SELECT * FROM t2;
c1
root@localhost
connection slave;
SELECT * FROM t1;
c1
@
SELECT * FROM t2;
c1
@
connection server_3;
SELECT * FROM t1;
c1
@
SELECT * FROM t2;
c1
@

# END
connection master;
DROP TABLE t1, t2;
DROP VIEW v_user, v_tables_priv, v_procs_priv, v_event;
DROP PROCEDURE p1;
DROP PROCEDURE my_grant;
DROP PROCEDURE my_revoke;
DROP FUNCTION my_user;
DROP EVENT e1;
include/rpl_end.inc