Commit 5e26cd43 authored by unknown's avatar unknown

WL#2050 - CREATE USER and DROP USER and RENAME USER

Added new commands CREATE USER and RENAME USER.
Changed behaviour of DROP USER.
Changed an error messages for the new commands.


Docs/mysqld_error.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
include/mysqld_error.h:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Changed an error code for more general use.
mysql-test/r/grant.result:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Changed test results.
mysql-test/r/grant2.result:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  New test results.
mysql-test/r/ps_1general.result:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Changed test results.
mysql-test/t/grant.test:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Updated old tests for new behaviour of DROP USER.
  It does now implicitly remove all privileges and
  does not fail when privileges are still in place.
  Fixed a typo, which left an user in the database,
  whereby other tests could be confused.
  Added a DROP USER for another test user.
mysql-test/t/grant2.test:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Added new tests for the new features.
sql/share/czech/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/danish/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/dutch/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/english/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/estonian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/french/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/german/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/greek/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/hungarian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/italian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/japanese/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/korean/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/norwegian-ny/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/norwegian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/polish/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/portuguese/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/romanian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/russian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/serbian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/slovak/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/spanish/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/swedish/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/share/ukrainian/errmsg.txt:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Modified an error message for more general use.
sql/sql_acl.cc:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Added a destructor for the GRANT_TABLE object to get
  rid of a hash_column in cases where a nonsense row was
  read from the privilege tables. Added code to delete
  such an object when it is not entered into the 
  column_priv_hash due to a nonsense row.
  Added function comments to two unmodified functions.
  Replaced mysql_drop_user() by the implementation of all
  of the functions as specified in the Low Level Design.
sql/sql_acl.h:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Added prototypes for new functions.
sql/sql_lex.h:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Added new command codes for CREATE USER and
  RENAME USER.
sql/sql_parse.cc:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Added case clauses for the new commands CREATE USER
  and RENAME USER.
sql/sql_yacc.yy:
  WL#2050 - CREATE USER and DROP USER and RENAME USER
  Added syntax for the new commands CREATE USER and 
  RENAME USER, reworked DROP USER, introduced a new
  'user_list' and 'rename_list', renamed the old 
  'user_list' to 'grant_list'. The difference is that
  'grant_list' contains 'grant_user' (with optional
  IDENTIFIED BY), while 'user_list' contains 'user'.
  Concentrated privilege initializazions into a new
  section 'clear_privileges'.
parent e24375fd
......@@ -539,8 +539,8 @@ character-set=latin1
"Using storage engine %s for table '%s'",
#define ER_CANT_AGGREGATE_2COLLATIONS 1267
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
#define ER_DROP_USER 1268
"Can't drop one or more of the requested users",
#define ER_HANDLE_USER 1268
"Operation %s failed for %d of the requested users",
#define ER_REVOKE_GRANTS 1269
"Can't revoke all privileges, grant for one or more of the requested users",
#define ER_CANT_AGGREGATE_3COLLATIONS 1270
......
......@@ -284,7 +284,7 @@
#define ER_WARN_DATA_TRUNCATED 1265
#define ER_WARN_USING_OTHER_HANDLER 1266
#define ER_CANT_AGGREGATE_2COLLATIONS 1267
#define ER_DROP_USER 1268
#define ER_HANDLE_USER 1268
#define ER_REVOKE_GRANTS 1269
#define ER_CANT_AGGREGATE_3COLLATIONS 1270
#define ER_CANT_AGGREGATE_NCOLLATIONS 1271
......
......@@ -218,17 +218,19 @@ grant select on test.* to drop_user3@localhost;
grant select on *.* to drop_user4@localhost;
drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost,
drop_user4@localhost;
ERROR HY000: Can't drop one or more of the requested users
revoke all privileges, grant option from drop_user1@localhost, drop_user2@localhost,
drop_user3@localhost, drop_user4@localhost;
ERROR HY000: Can't revoke all privileges, grant for one or more of the requested users
drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost,
drop_user4@localhost;
ERROR HY000: Operation DROP USER failed for 4 of the requested users
drop table t1;
grant usage on *.* to mysqltest_1@localhost identified by "password";
grant select, update, insert on test.* to mysqltest@localhost;
grant select, update, insert on test.* to mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
Grants for mysqltest_1@localhost
GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19'
GRANT SELECT, INSERT, UPDATE ON `test`.* TO 'mysqltest_1'@'localhost'
drop user mysqltest_1@localhost;
SET NAMES koi8r;
CREATE DATABASE ;
......@@ -252,6 +254,7 @@ Grants for
GRANT USAGE ON *.* TO ''@'localhost'
GRANT SELECT () ON ``.`` TO ''@'localhost'
REVOKE SELECT () ON . FROM @localhost;
DROP USER @localhost;
DROP DATABASE ;
SET NAMES latin1;
USE test;
......
......@@ -60,3 +60,166 @@ use test;
delete from mysql.user where user like 'mysqltest\_%';
delete from mysql.db where user like 'mysqltest\_%';
flush privileges;
set sql_mode='maxdb';
drop table if exists t1, t2;
create table t1(c1 int);
create table t2(c1 int, c2 int);
create user 'mysqltest_1';
create user 'mysqltest_1';
ERROR HY000: Operation CREATE USER failed for 1 of the requested users
create user 'mysqltest_2' identified by 'Mysqltest-2';
create user 'mysqltest_3' identified by password 'fffffffffffffffffffffffffffffffffffffffff';
grant select on *.* to 'mysqltest_2';
grant insert on test.* to 'mysqltest_2';
grant update on test.t1 to 'mysqltest_2';
grant update (c2) on test.t2 to 'mysqltest_2';
select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;
host user password
% mysqltest_1
% mysqltest_2 *BD447CBA355AF58578D3AE33BA2E2CD388BA08D1
% mysqltest_3 fffffffffffffffffffffffffffffffffffffffff
select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user;
host db user
% test mysqltest_2
select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name;
host db user table_name
% test mysqltest_2 t1
% test mysqltest_2 t2
select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name;
host db user table_name column_name
% test mysqltest_2 t2 c2
show grants for 'mysqltest_1';
Grants for mysqltest_1@%
GRANT USAGE ON *.* TO 'mysqltest_1'@'%'
show grants for 'mysqltest_2';
Grants for mysqltest_2@%
GRANT SELECT ON *.* TO 'mysqltest_2'@'%' IDENTIFIED BY PASSWORD '*BD447CBA355AF58578D3AE33BA2E2CD388BA08D1'
GRANT INSERT ON "test".* TO 'mysqltest_2'@'%'
GRANT UPDATE (c2) ON "test"."t2" TO 'mysqltest_2'@'%'
GRANT UPDATE ON "test"."t1" TO 'mysqltest_2'@'%'
drop user 'mysqltest_1';
select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;
host user password
% mysqltest_2 *BD447CBA355AF58578D3AE33BA2E2CD388BA08D1
% mysqltest_3 fffffffffffffffffffffffffffffffffffffffff
select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user;
host db user
% test mysqltest_2
select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name;
host db user table_name
% test mysqltest_2 t1
% test mysqltest_2 t2
select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name;
host db user table_name column_name
% test mysqltest_2 t2 c2
show grants for 'mysqltest_1';
ERROR 42000: There is no such grant defined for user 'mysqltest_1' on host '%'
rename user 'mysqltest_2' to 'mysqltest_1';
select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;
host user password
% mysqltest_1 *BD447CBA355AF58578D3AE33BA2E2CD388BA08D1
% mysqltest_3 fffffffffffffffffffffffffffffffffffffffff
select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user;
host db user
% test mysqltest_1
select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name;
host db user table_name
% test mysqltest_1 t1
% test mysqltest_1 t2
select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name;
host db user table_name column_name
% test mysqltest_1 t2 c2
show grants for 'mysqltest_1';
Grants for mysqltest_1@%
GRANT SELECT ON *.* TO 'mysqltest_1'@'%' IDENTIFIED BY PASSWORD '*BD447CBA355AF58578D3AE33BA2E2CD388BA08D1'
GRANT INSERT ON "test".* TO 'mysqltest_1'@'%'
GRANT UPDATE (c2) ON "test"."t2" TO 'mysqltest_1'@'%'
GRANT UPDATE ON "test"."t1" TO 'mysqltest_1'@'%'
drop user 'mysqltest_1', 'mysqltest_3';
drop table t1, t2;
insert into mysql.db set user='mysqltest_1', db='%', host='%';
flush privileges;
show grants for 'mysqltest_1';
ERROR 42000: There is no such grant defined for user 'mysqltest_1' on host '%'
revoke all privileges, grant option from 'mysqltest_1';
ERROR HY000: Can't revoke all privileges, grant for one or more of the requested users
drop user 'mysqltest_1';
select host,db,user from mysql.db where user = 'mysqltest_1' order by host,db,user;
host db user
insert into mysql.tables_priv set host='%', db='test', user='mysqltest_1', table_name='t1';
flush privileges;
show grants for 'mysqltest_1';
ERROR 42000: There is no such grant defined for user 'mysqltest_1' on host '%'
drop user 'mysqltest_1';
select host,db,user,table_name from mysql.tables_priv where user = 'mysqltest_1' order by host,db,user,table_name;
host db user table_name
insert into mysql.columns_priv set host='%', db='test', user='mysqltest_1', table_name='t1', column_name='c1';
flush privileges;
show grants for 'mysqltest_1';
ERROR 42000: There is no such grant defined for user 'mysqltest_1' on host '%'
drop user 'mysqltest_1';
select host,db,user,table_name,column_name from mysql.columns_priv where user = 'mysqltest_1' order by host,db,user,table_name,column_name;
host db user table_name column_name
create user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
create user 'mysqltest_1', 'mysqltest_2' identified by 'Mysqltest-2', 'mysqltest_3' identified by password 'fffffffffffffffffffffffffffffffffffffffff';
rename user 'mysqltest_1' to 'mysqltest_1a', 'mysqltest_2' TO 'mysqltest_2a', 'mysqltest_3' TO 'mysqltest_3a';
drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
ERROR HY000: Operation DROP USER failed for 3 of the requested users
drop user 'mysqltest_1a', 'mysqltest_2a', 'mysqltest_3a';
create user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
create user 'mysqltest_1a', 'mysqltest_2', 'mysqltest_3a';
ERROR HY000: Operation CREATE USER failed for 1 of the requested users
rename user 'mysqltest_1a' to 'mysqltest_1b', 'mysqltest_2a' TO 'mysqltest_2b', 'mysqltest_3a' TO 'mysqltest_3b';
ERROR HY000: Operation RENAME USER failed for 1 of the requested users
drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
drop user 'mysqltest_1b', 'mysqltest_2b', 'mysqltest_3b';
ERROR HY000: Operation DROP USER failed for 1 of the requested users
create user 'mysqltest_2' identified by 'Mysqltest-2';
drop user 'mysqltest_2' identified by 'Mysqltest-2';
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'Mysqltest-2'' at line 1
create user '%@b'@'b';
show grants for '%@b'@'b';
Grants for %@b@b
GRANT USAGE ON *.* TO '%@b'@'b'
grant select on mysql.* to '%@b'@'b';
show grants for '%@b'@'b';
Grants for %@b@b
GRANT USAGE ON *.* TO '%@b'@'b'
GRANT SELECT ON "mysql".* TO '%@b'@'b'
rename user '%@b'@'b' to '%@a'@'a';
show grants for '%@b'@'b';
ERROR 42000: There is no such grant defined for user '%@b' on host 'b'
show grants for '%@a'@'a';
Grants for %@a@a
GRANT USAGE ON *.* TO '%@a'@'a'
GRANT SELECT ON "mysql".* TO '%@a'@'a'
drop user '%@a'@'a';
create user mysqltest_2@localhost;
grant usage on *.* to mysqltest_2@localhost with grant option;
select host,user,password from mysql.user order by host,user,password;
ERROR 42000: Access denied for user 'mysqltest_2'@'localhost' to database 'mysql'
create user mysqltest_A@'%';
rename user mysqltest_A@'%' to mysqltest_B@'%';
drop user mysqltest_B@'%';
drop user mysqltest_2@localhost;
create user mysqltest_3@localhost;
grant all privileges on mysql.* to mysqltest_3@localhost;
select host,user,password from mysql.user order by host,user,password;
host user password
% mysqltest_2 *BD447CBA355AF58578D3AE33BA2E2CD388BA08D1
127.0.0.1 root
chilla%
chilla% root
localhost
localhost mysqltest_3
localhost root
insert into mysql.user set host='%', user='mysqltest_B';
create user mysqltest_A@'%';
ERROR 42000: Access denied for user 'mysqltest_3'@'localhost' to database 'mysql'
rename user mysqltest_B@'%' to mysqltest_C@'%';
ERROR 42000: Access denied for user 'mysqltest_3'@'localhost' to database 'mysql'
drop user mysqltest_B@'%';
ERROR 42000: Access denied for user 'mysqltest_3'@'localhost' to database 'mysql'
drop user mysqltest_B@'%';
drop user mysqltest_3@localhost;
......@@ -835,19 +835,19 @@ identified by 'looser' ;
show grants for second_user@localhost ;
Grants for second_user@localhost
GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3'
GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost'
GRANT SELECT ON `mysqltest`.`t1` TO 'second_user'@'localhost'
GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost'
drop table mysqltest.t9 ;
show grants for second_user@localhost ;
Grants for second_user@localhost
GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3'
GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost'
GRANT SELECT ON `mysqltest`.`t1` TO 'second_user'@'localhost'
GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost'
show grants for second_user@localhost ;
Grants for second_user@localhost
GRANT USAGE ON *.* TO 'second_user'@'localhost' IDENTIFIED BY PASSWORD '*13843FE600B19A81E32AF50D4A6FED25875FF1F3'
GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost'
GRANT SELECT ON `mysqltest`.`t1` TO 'second_user'@'localhost'
GRANT SELECT ON `mysqltest`.`t9` TO 'second_user'@'localhost'
prepare s_t1 from 'select a as my_col from t1' ;
execute s_t1 ;
my_col
......
......@@ -162,16 +162,18 @@ grant select(a) on test.t1 to drop_user1@localhost;
grant select on test.t1 to drop_user2@localhost;
grant select on test.* to drop_user3@localhost;
grant select on *.* to drop_user4@localhost;
--error 1268
# Drop user now implicitly revokes all privileges.
drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost,
drop_user4@localhost;
--error 1269
revoke all privileges, grant option from drop_user1@localhost, drop_user2@localhost,
drop_user3@localhost, drop_user4@localhost;
--error 1268
drop user drop_user1@localhost, drop_user2@localhost, drop_user3@localhost,
drop_user4@localhost;
drop table t1;
grant usage on *.* to mysqltest_1@localhost identified by "password";
grant select, update, insert on test.* to mysqltest@localhost;
grant select, update, insert on test.* to mysqltest_1@localhost;
show grants for mysqltest_1@localhost;
drop user mysqltest_1@localhost;
......@@ -195,6 +197,9 @@ GRANT SELECT (
SHOW GRANTS FOR @localhost;
REVOKE SELECT () ON . FROM @localhost;
# Revoke does not drop user. Leave a clean user table for the next tests.
DROP USER @localhost;
DROP DATABASE ;
SET NAMES latin1;
......
......@@ -78,3 +78,150 @@ use test;
delete from mysql.user where user like 'mysqltest\_%';
delete from mysql.db where user like 'mysqltest\_%';
flush privileges;
#
# Create and drop user
#
set sql_mode='maxdb';
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
create table t1(c1 int);
create table t2(c1 int, c2 int);
#
# Three forms of CREATE USER
create user 'mysqltest_1';
--error 1268
create user 'mysqltest_1';
create user 'mysqltest_2' identified by 'Mysqltest-2';
create user 'mysqltest_3' identified by password 'fffffffffffffffffffffffffffffffffffffffff';
grant select on *.* to 'mysqltest_2';
grant insert on test.* to 'mysqltest_2';
grant update on test.t1 to 'mysqltest_2';
grant update (c2) on test.t2 to 'mysqltest_2';
select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;
select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user;
select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name;
select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name;
show grants for 'mysqltest_1';
show grants for 'mysqltest_2';
#
# Drop
drop user 'mysqltest_1';
select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;
select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user;
select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name;
select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name;
--error 1141
show grants for 'mysqltest_1';
#
# Rename
rename user 'mysqltest_2' to 'mysqltest_1';
select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password;
select host,db,user from mysql.db where user like 'mysqltest_%' order by host,db,user;
select host,db,user,table_name from mysql.tables_priv where user like 'mysqltest_%' order by host,db,user,table_name;
select host,db,user,table_name,column_name from mysql.columns_priv where user like 'mysqltest_%' order by host,db,user,table_name,column_name;
show grants for 'mysqltest_1';
drop user 'mysqltest_1', 'mysqltest_3';
#
# Grant must not create user
#grant all on test.t1 to 'mysqltest_1';
#drop user 'mysqltest_1';
#
# Cleanup
drop table t1, t2;
#
# Add a stray record
insert into mysql.db set user='mysqltest_1', db='%', host='%';
flush privileges;
--error 1141
show grants for 'mysqltest_1';
--error 1269
revoke all privileges, grant option from 'mysqltest_1';
drop user 'mysqltest_1';
select host,db,user from mysql.db where user = 'mysqltest_1' order by host,db,user;
#
# Add a stray record
insert into mysql.tables_priv set host='%', db='test', user='mysqltest_1', table_name='t1';
flush privileges;
--error 1141
show grants for 'mysqltest_1';
drop user 'mysqltest_1';
select host,db,user,table_name from mysql.tables_priv where user = 'mysqltest_1' order by host,db,user,table_name;
#
# Add a stray record
insert into mysql.columns_priv set host='%', db='test', user='mysqltest_1', table_name='t1', column_name='c1';
flush privileges;
--error 1141
show grants for 'mysqltest_1';
drop user 'mysqltest_1';
select host,db,user,table_name,column_name from mysql.columns_priv where user = 'mysqltest_1' order by host,db,user,table_name,column_name;
#
# Handle multi user lists
create user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
create user 'mysqltest_1', 'mysqltest_2' identified by 'Mysqltest-2', 'mysqltest_3' identified by password 'fffffffffffffffffffffffffffffffffffffffff';
rename user 'mysqltest_1' to 'mysqltest_1a', 'mysqltest_2' TO 'mysqltest_2a', 'mysqltest_3' TO 'mysqltest_3a';
--error 1268
drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
drop user 'mysqltest_1a', 'mysqltest_2a', 'mysqltest_3a';
#
# Let one of multiple users fail
create user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
--error 1268
create user 'mysqltest_1a', 'mysqltest_2', 'mysqltest_3a';
--error 1268
rename user 'mysqltest_1a' to 'mysqltest_1b', 'mysqltest_2a' TO 'mysqltest_2b', 'mysqltest_3a' TO 'mysqltest_3b';
drop user 'mysqltest_1', 'mysqltest_2', 'mysqltest_3';
--error 1268
drop user 'mysqltest_1b', 'mysqltest_2b', 'mysqltest_3b';
#
# Obsolete syntax has been dropped
create user 'mysqltest_2' identified by 'Mysqltest-2';
--error 1064
drop user 'mysqltest_2' identified by 'Mysqltest-2';
#
# Strange user names
create user '%@b'@'b';
show grants for '%@b'@'b';
grant select on mysql.* to '%@b'@'b';
show grants for '%@b'@'b';
rename user '%@b'@'b' to '%@a'@'a';
--error 1141
show grants for '%@b'@'b';
show grants for '%@a'@'a';
drop user '%@a'@'a';
#
# USAGE WITH GRANT OPTION is sufficient.
create user mysqltest_2@localhost;
grant usage on *.* to mysqltest_2@localhost with grant option;
connect (user2,localhost,mysqltest_2,,);
connection user2;
--error 1044
select host,user,password from mysql.user order by host,user,password;
create user mysqltest_A@'%';
rename user mysqltest_A@'%' to mysqltest_B@'%';
drop user mysqltest_B@'%';
disconnect user2;
connection default;
drop user mysqltest_2@localhost;
#
# ALL PRIVILEGES without GRANT OPTION is not sufficient.
create user mysqltest_3@localhost;
grant all privileges on mysql.* to mysqltest_3@localhost;
connect (user3,localhost,mysqltest_3,,);
connection user3;
select host,user,password from mysql.user order by host,user,password;
insert into mysql.user set host='%', user='mysqltest_B';
--error 1044
create user mysqltest_A@'%';
--error 1044
rename user mysqltest_B@'%' to mysqltest_C@'%';
--error 1044
drop user mysqltest_B@'%';
disconnect user3;
connection default;
drop user mysqltest_B@'%';
drop user mysqltest_3@localhost;
#
......@@ -296,7 +296,7 @@ character-set=latin2
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -287,7 +287,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -296,7 +296,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -284,7 +284,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -289,7 +289,7 @@ character-set=latin7
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -284,7 +284,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -297,7 +297,7 @@ character-set=latin1
"Daten abgeschnitten für Spalte '%s' in Zeile %ld",
"Für Tabelle '%s' wird Speicher-Engine %s benutzt",
"Unerlaubte Vermischung der Kollationen (%s,%s) und (%s,%s) für die Operation '%s'",
"Kann einen oder mehrere der angegebenen Benutzer nicht löschen",
"Das Kommando %s scheiterte für %d von den betroffenen Benutzern",
"Kann nicht alle Berechtigungen widerrufen, grant for one or more of the requested users",
"Unerlaubte Vermischung der Kollationen (%s,%s), (%s,%s), (%s,%s) für die Operation '%s'",
"Unerlaubte Vermischung der Kollationen für die Operation '%s'",
......
......@@ -284,7 +284,7 @@ character-set=greek
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -289,7 +289,7 @@ character-set=latin2
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -284,7 +284,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -288,7 +288,7 @@ character-set=ujis
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -284,7 +284,7 @@ character-set=euckr
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -286,7 +286,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -286,7 +286,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -289,7 +289,7 @@ character-set=latin2
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -286,7 +286,7 @@ character-set=latin1
"Dado truncado para coluna '%s' na linha %ld",
"Usando engine de armazenamento %s para tabela '%s'",
"Combinação ilegal de collations (%s,%s) e (%s,%s) para operação '%s'",
"Não pode remover um ou mais dos usuários pedidos",
"Operation %s failed for %d of the requested users",
"Não pode revocar todos os privilégios, grant para um ou mais dos usuários pedidos",
"Ilegal combinação de collations (%s,%s), (%s,%s), (%s,%s) para operação '%s'",
"Ilegal combinação de collations para operação '%s'",
......
......@@ -289,7 +289,7 @@ character-set=latin2
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -289,7 +289,7 @@ character-set=koi8r
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -277,7 +277,7 @@ character-set=cp1250
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -292,7 +292,7 @@ character-set=latin2
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -288,7 +288,7 @@ character-set=latin1
"Datos truncados para columna '%s' en la línea %ld",
"Usando motor de almacenamiento %s para tabla '%s'",
"Ilegal mezcla de collations (%s,%s) y (%s,%s) para operación '%s'",
"No puede remover uno o mas de los usuarios solicitados",
"Operation %s failed for %d of the requested users",
"No puede revocar todos los privilegios, derecho para uno o mas de los usuarios solicitados",
"Ilegal mezcla de collations (%s,%s), (%s,%s), (%s,%s) para operación '%s'",
"Ilegal mezcla de collations para operación '%s'",
......
......@@ -284,7 +284,7 @@ character-set=latin1
"Data truncated for column '%s' at row %ld",
"Använder handler %s för tabell '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
......@@ -290,7 +290,7 @@ character-set=koi8u
"Data truncated for column '%s' at row %ld",
"Using storage engine %s for table '%s'",
"Illegal mix of collations (%s,%s) and (%s,%s) for operation '%s'",
"Can't drop one or more of the requested users",
"Operation %s failed for %d of the requested users",
"Can't revoke all privileges, grant for one or more of the requested users",
"Illegal mix of collations (%s,%s), (%s,%s), (%s,%s) for operation '%s'",
"Illegal mix of collations for operation '%s'",
......
This diff is collapsed.
......@@ -182,7 +182,9 @@ ulong get_column_grant(THD *thd, GRANT_INFO *grant,
bool mysql_show_grants(THD *thd, LEX_USER *user);
void get_privilege_desc(char *to, uint max_length, ulong access);
void get_mqh(const char *user, const char *host, USER_CONN *uc);
bool mysql_create_user(THD *thd, List <LEX_USER> &list);
bool mysql_drop_user(THD *thd, List <LEX_USER> &list);
bool mysql_rename_user(THD *thd, List <LEX_USER> &list);
bool mysql_revoke_all(THD *thd, List <LEX_USER> &list);
void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant,
const char *db, const char *table);
......
......@@ -78,7 +78,8 @@ enum enum_sql_command {
SQLCOM_SHOW_BINLOG_EVENTS, SQLCOM_SHOW_NEW_MASTER, SQLCOM_DO,
SQLCOM_SHOW_WARNS, SQLCOM_EMPTY_QUERY, SQLCOM_SHOW_ERRORS,
SQLCOM_SHOW_COLUMN_TYPES, SQLCOM_SHOW_STORAGE_ENGINES, SQLCOM_SHOW_PRIVILEGES,
SQLCOM_HELP, SQLCOM_DROP_USER, SQLCOM_REVOKE_ALL, SQLCOM_CHECKSUM,
SQLCOM_HELP, SQLCOM_CREATE_USER, SQLCOM_DROP_USER, SQLCOM_RENAME_USER,
SQLCOM_REVOKE_ALL, SQLCOM_CHECKSUM,
SQLCOM_CREATE_PROCEDURE, SQLCOM_CREATE_SPFUNCTION, SQLCOM_CALL,
SQLCOM_DROP_PROCEDURE, SQLCOM_ALTER_PROCEDURE,SQLCOM_ALTER_FUNCTION,
SQLCOM_SHOW_CREATE_PROC, SQLCOM_SHOW_CREATE_FUNC,
......
......@@ -3370,6 +3370,21 @@ mysql_execute_command(THD *thd)
break;
}
#ifndef NO_EMBEDDED_ACCESS_CHECKS
case SQLCOM_CREATE_USER:
{
if (check_access(thd, GRANT_ACL,"mysql",0,1,0))
break;
if (!(res= mysql_create_user(thd, lex->users_list)))
{
if (mysql_bin_log.is_open())
{
Query_log_event qinfo(thd, thd->query, thd->query_length, 0);
mysql_bin_log.write(&qinfo);
}
send_ok(thd);
}
break;
}
case SQLCOM_DROP_USER:
{
if (check_access(thd, GRANT_ACL,"mysql",0,1,0))
......@@ -3385,6 +3400,21 @@ mysql_execute_command(THD *thd)
}
break;
}
case SQLCOM_RENAME_USER:
{
if (check_access(thd, GRANT_ACL,"mysql",0,1,0))
break;
if (!(res= mysql_rename_user(thd, lex->users_list)))
{
if (mysql_bin_log.is_open())
{
Query_log_event qinfo(thd, thd->query, thd->query_length, 0);
mysql_bin_log.write(&qinfo);
}
send_ok(thd);
}
break;
}
case SQLCOM_REVOKE_ALL:
{
if (check_access(thd, GRANT_ACL ,"mysql",0,1,0))
......
......@@ -788,9 +788,9 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
opt_delete_options opt_delete_option varchar nchar nvarchar
opt_outer table_list table_name opt_option opt_place
opt_attribute opt_attribute_list attribute column_list column_list_id
opt_column_list grant_privileges opt_table user_list grant_option
grant_privilege grant_privilege_list
flush_options flush_option
opt_column_list grant_privileges opt_table grant_list grant_option
grant_privilege grant_privilege_list user_list rename_list
clear_privileges flush_options flush_option
equal optional_braces opt_key_definition key_usage_list2
opt_mi_check_type opt_to mi_check_types normal_join
table_to_table_list table_to_table opt_table_list opt_as
......@@ -1287,6 +1287,24 @@ create:
TL_WRITE))
YYABORT;
}
| CREATE USER clear_privileges grant_list
{
Lex->sql_command = SQLCOM_CREATE_USER;
}
;
clear_privileges:
/* Nothing */
{
LEX *lex=Lex;
lex->users_list.empty();
lex->columns.empty();
lex->grant= lex->grant_tot_col= 0;
lex->select_lex.db= 0;
lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
bzero((char *)&(lex->mqh),sizeof(lex->mqh));
}
;
sp_name:
......@@ -3671,6 +3689,23 @@ rename:
}
table_to_table_list
{}
| RENAME USER clear_privileges rename_list
{
Lex->sql_command = SQLCOM_RENAME_USER;
}
;
rename_list:
user TO_SYM user
{
if (Lex->users_list.push_back($1) || Lex->users_list.push_back($3))
YYABORT;
}
| rename_list ',' user TO_SYM user
{
if (Lex->users_list.push_back($3) || Lex->users_list.push_back($5))
YYABORT;
}
;
table_to_table_list:
......@@ -5479,14 +5514,10 @@ drop:
lex->drop_if_exists= $3;
lex->spname= $4;
}
| DROP USER
| DROP USER clear_privileges user_list
{
LEX *lex=Lex;
lex->sql_command = SQLCOM_DROP_USER;
lex->users_list.empty();
Lex->sql_command = SQLCOM_DROP_USER;
}
user_list
{}
| DROP VIEW_SYM if_exists table_list opt_restrict
{
THD *thd= YYTHD;
......@@ -7478,48 +7509,28 @@ handler_rkey_mode:
/* GRANT / REVOKE */
revoke:
REVOKE
{
LEX *lex=Lex;
lex->sql_command = SQLCOM_REVOKE;
lex->users_list.empty();
lex->columns.empty();
lex->grant= lex->grant_tot_col=0;
lex->select_lex.db=0;
lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
bzero((char*) &lex->mqh, sizeof(lex->mqh));
}
revoke_command
REVOKE clear_privileges revoke_command
{}
;
revoke_command:
grant_privileges ON opt_table FROM user_list
{}
grant_privileges ON opt_table FROM grant_list
{
Lex->sql_command = SQLCOM_REVOKE;
}
|
ALL opt_privileges ',' GRANT OPTION FROM user_list
ALL opt_privileges ',' GRANT OPTION FROM grant_list
{
Lex->sql_command = SQLCOM_REVOKE_ALL;
}
;
grant:
GRANT
GRANT clear_privileges grant_privileges ON opt_table TO_SYM grant_list
require_clause grant_options
{
LEX *lex=Lex;
lex->users_list.empty();
lex->columns.empty();
lex->sql_command = SQLCOM_GRANT;
lex->grant= lex->grant_tot_col= 0;
lex->select_lex.db= 0;
lex->ssl_type= SSL_TYPE_NOT_SPECIFIED;
lex->ssl_cipher= lex->x509_subject= lex->x509_issuer= 0;
bzero((char *)&(lex->mqh),sizeof(lex->mqh));
Lex->sql_command = SQLCOM_GRANT;
}
grant_privileges ON opt_table TO_SYM user_list
require_clause grant_options
{}
;
grant_privileges:
......@@ -7659,8 +7670,18 @@ opt_table:
user_list:
user { if (Lex->users_list.push_back($1)) YYABORT;}
| user_list ',' user
{
if (Lex->users_list.push_back($3))
YYABORT;
}
;
grant_list:
grant_user { if (Lex->users_list.push_back($1)) YYABORT;}
| user_list ',' grant_user
| grant_list ',' grant_user
{
if (Lex->users_list.push_back($3))
YYABORT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment