Debian Codegraph @

mysql-test/suite/auth_sec/include/password_require_current_priv_user.inc

raw
1 ###############################################################################
2 # #
3 # This script checks the ALTER USER|SET PASSWORD ... REPLACE ... SQL #
4 # for privileged user. #
5 # #
6 # This script expects, two users have been created already by the caller. #
7 # It grants the update on mysql.* privileges to one user to treat that as #
8 # privileged user, while other user is not granted any privileges. #
9 # It does not drop the users. #
10 # #
11 # Arguments required: #
12 # It needs to know the two users' names through following variables: #
13 # 1. $PRIV_USER : user which will be granted the update privileges #
14 # 2. $NON_PRIV_USER : user which will not be granted the update privileges #
15 # #
16 # It also needs following two password variables: #
17 # 3. $PWRD_1: A password which is used to create $NON_PRIV_USER user. #
18 # 4. $PWRD_2: A password which is used to create $PRIV_USER user. #
19 # #
20 ###############################################################################
21
22 # If required parameters are not set then throw error and exit.
23 --let PARAM_PERL_QUIT=0
24 if ($NON_PRIV_USER == '')
25 {
26 --let VARIABLE_NAME = NON_PRIV_USER
27 --let PARAM_PERL_QUIT=1
28 }
29
30 if ($PRIV_USER == '')
31 {
32 --let VARIABLE_NAME = PRIV_USER
33 --let PARAM_PERL_QUIT=1
34 }
35
36 if ($PWRD_1 == '')
37 {
38 --let VARIABLE_NAME = PWRD_1
39 --let PARAM_PERL_QUIT=1
40 }
41
42 if ($PWRD_2 == '')
43 {
44 --let VARIABLE_NAME = PWRD_2
45 --let PARAM_PERL_QUIT=1
46 }
47
48 --let $WRONG_PWRD = P&(*^_)D
49
50 --echo
51 --echo # Show how the users were created
52 --echo
53 --replace_regex /WITH '(.*)' AS '(.*)' REQUIRE/WITH '<default_auth_plugin>' AS '<password_hash>' REQUIRE/
54 eval SHOW CREATE USER $NON_PRIV_USER;
55 --replace_regex /WITH '(.*)' AS '(.*)' REQUIRE/WITH '<default_auth_plugin>' AS '<password_hash>' REQUIRE/
56 eval SHOW CREATE USER $PRIV_USER;
57 eval SELECT password_require_current from mysql.user
58 where user like '%$PRIV_USER' OR user like '%$NON_PRIV_USER';
59
60 --echo
61 --echo # Grant the update privileges to the user
62 eval GRANT UPDATE ON mysql.* to '$PRIV_USER'@'%' WITH GRANT OPTION;
63
64 --echo
65 --echo #------------------------------------------------------------------------
66 --echo # Priv user changing his own password
67 --echo #------------------------------------------------------------------------
68 connect(con1,localhost,$PRIV_USER,$PWRD_2,);
69
70 --echo
71 --echo # Without REPLACE clause
72 eval SET PASSWORD='$PWRD_1';
73 eval SET PASSWORD for $PRIV_USER='$PWRD_2';
74 eval ALTER USER user() IDENTIFIED BY '$PWRD_1';
75 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_2';
76
77 --echo
78 --echo # With invalid current password in the REPLACE clause
79 --error ER_INCORRECT_CURRENT_PASSWORD
80 eval SET PASSWORD='$PWRD_2' REPLACE '$WRONG_PWRD';
81 --error ER_INCORRECT_CURRENT_PASSWORD
82 eval SET PASSWORD for $PRIV_USER='$PWRD_2' REPLACE '$WRONG_PWRD';
83 --error ER_INCORRECT_CURRENT_PASSWORD
84 eval ALTER USER user() IDENTIFIED BY '$PWRD_2' REPLACE '$WRONG_PWRD';
85 --error ER_INCORRECT_CURRENT_PASSWORD
86 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_2' REPLACE '$WRONG_PWRD';
87
88 --echo
89 --echo # With valid current password in the REPLACE clause
90 eval SET PASSWORD='$PWRD_1' REPLACE '$PWRD_2';
91 eval SET PASSWORD for $PRIV_USER='$PWRD_2' REPLACE '$PWRD_1';
92 eval ALTER USER user() IDENTIFIED BY '$PWRD_1' REPLACE '$PWRD_2';
93 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_2' REPLACE '$PWRD_1';
94
95 --echo
96 --echo #------------------------------------------------------------------------
97 --echo # Priv user changing the password of $NON_PRIV_USER
98 --echo #------------------------------------------------------------------------
99
100 --echo
101 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
102 eval SET PASSWORD for $NON_PRIV_USER='$PWRD_2' REPLACE '$PWRD_1';
103 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
104 eval ALTER USER $NON_PRIV_USER IDENTIFIED BY '$PWRD_2' REPLACE '';
105
106 --echo
107 eval SET PASSWORD for $NON_PRIV_USER='$PWRD_2';
108 eval ALTER USER $NON_PRIV_USER IDENTIFIED BY '$PWRD_2';
109
110 connection default;
111 disconnect con1;
112
113 --echo
114 --echo #------------------------------------------------------------------------
115 --echo # One priv user(root) changing password for other priv user ($PRIV_USER)
116 --echo #------------------------------------------------------------------------
117
118 --echo
119 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
120 eval SET PASSWORD for $PRIV_USER='$PWRD_1' REPLACE '$PWRD_2';
121 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
122 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_1' REPLACE '$WRONG_PWRD';
123
124 --echo
125 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_2';
126 eval SET PASSWORD for $PRIV_USER='$PWRD_1';
127
128 --echo
129 --echo # Now test with Global server variable ON
130 SET @@global.password_require_current=ON;
131
132 --echo
133 --echo #------------------------------------------------------------------------
134 --echo # Priv user changing his own password
135 --echo #------------------------------------------------------------------------
136 connect(con1,localhost,$PRIV_USER,$PWRD_1,);
137
138 --echo
139 --echo # Can change without REPLACE clause
140 eval SET PASSWORD='$PWRD_2';
141 eval SET PASSWORD for $PRIV_USER='$PWRD_1';
142 eval ALTER USER user() IDENTIFIED BY '$PWRD_2';
143 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_1';
144
145 --echo
146 --echo # Incorrect password specified in the REPLACE clause
147 --error ER_INCORRECT_CURRENT_PASSWORD
148 eval SET PASSWORD='$PWRD_2' REPLACE '$WRONG_PWRD';
149 --error ER_INCORRECT_CURRENT_PASSWORD
150 eval SET PASSWORD for $PRIV_USER='$PWRD_2' REPLACE '$WRONG_PWRD';
151 --error ER_INCORRECT_CURRENT_PASSWORD
152 eval ALTER USER user() IDENTIFIED BY '$PWRD_2' REPLACE '$WRONG_PWRD';
153 --error ER_INCORRECT_CURRENT_PASSWORD
154 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_2' REPLACE '$WRONG_PWRD';
155
156 --echo
157 --echo # Correct password specified in the REPLACE clause
158 eval SET PASSWORD='$PWRD_2' REPLACE '$PWRD_1';
159 eval SET PASSWORD for $PRIV_USER='$PWRD_1' REPLACE '$PWRD_2';
160 eval ALTER USER user() IDENTIFIED BY '$PWRD_2' REPLACE '$PWRD_1';
161 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_1' REPLACE '$PWRD_2'
162 WITH MAX_QUERIES_PER_HOUR 100 PASSWORD EXPIRE DEFAULT;
163
164 --echo
165 --echo #------------------------------------------------------------------------
166 --echo # Priv user changing the password of $NON_PRIV_USER
167 --echo #------------------------------------------------------------------------
168
169 --echo
170 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
171 eval SET PASSWORD for $NON_PRIV_USER='$PWRD_2' REPLACE '$WRONG_PWRD';
172 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
173 eval ALTER USER $NON_PRIV_USER IDENTIFIED BY '$PWRD_2' REPLACE '$WRONG_PWRD';
174
175 --echo
176 eval SET PASSWORD for $NON_PRIV_USER='$PWRD_2' ;
177 eval ALTER USER $NON_PRIV_USER IDENTIFIED BY '$PWRD_1';
178
179 connection default;
180 disconnect con1;
181
182 --echo
183 --echo #------------------------------------------------------------------------
184 --echo # One priv user(root) changing password for other priv user ($PRIV_USER)
185 --echo #------------------------------------------------------------------------
186
187 --echo
188 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
189 eval SET PASSWORD for $PRIV_USER='$PWRD_1' REPLACE '';
190 --error ER_CURRENT_PASSWORD_NOT_REQUIRED
191 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_1' REPLACE '$PWRD_2';
192 eval SET PASSWORD for $PRIV_USER='$PWRD_1';
193 eval ALTER USER $PRIV_USER IDENTIFIED BY '$PWRD_2';
194
195 --echo
196 --echo # Reset the privileges and global variable
197 --echo
198 eval REVOKE UPDATE ON mysql.* FROM '$PRIV_USER'@'%';
199 SET @@global.password_require_current=OFF;