Description:
Description of Patch
================================================================================
The purpose of this patch is to allow variable username-length setting at
compile time by using --with-username-length=X. The mysql default of
16 characters is sometimes not enough as shown in the following example.
Example: Hosting Scenario
To keep usernames as simple as possible, usernames are equal to the domain
names of the users. I.e mydomain.tld will have a mysql login of mydomain.tld
There are various users with domain names longer than 16 bytes, leading
to problems when trying to create mysql users with >16 byte usernames:
mysql> GRANT ALL ON *.* TO 'thisUsernameIsReallyReallyLong.com'@'localhost'
ERROR 1145 (42000): The host or user argument to GRANT is too long
With this patch, people willing to change the default value of 16 bytes, can
easily do so.
Patch Notes (with-username-length.patch)
================================================================================
Top Directory
--------------------------------------------------------------------------------
Added MYSQL_CHECK_USERNAME_LENGTH macro call to configure.in
config Directory
--------------------------------------------------------------------------------
Added M4 Macro MYSQL_CHECK_USERNAME_LENGTH to config/ac-macros/misc.m4 including
an AC_SUBST(USERNAME_LENGTH) to propagate to subdirectories where needed. This
creates the constant USERNAME_LENGTH in config.h
scripts Directory
--------------------------------------------------------------------------------
Added target %.sql: %.sql.sh to scripts/Makefile.am and fixed old style: .sh:
target to %: %.sh plus addition of sed USERNAME_LENGTH substitution
Replaced all occurences of User char(16) with User Char(@USERNAME_LENGTH@) in
scripts/mysql_create_system_tables.sh (remember, these get substituted by the
additional -e 's!@''USERNAME_LENGTH''@!@USERNAME_LENGTH@!' in the %: %.sh
target)
Replaced all occurences of User char(16) with User Char(@USERNAME_LENGTH@) in
scripts/mysql_fix_privilege_tables.sql and renamed file to
scripts/mysql_fix_privilege_tables.sql.sh (gets processed by the new
%.sql: %.sql.sh target of scripts/Makefile.am)
include Directory
--------------------------------------------------------------------------------
Removed the USERNAME_LENGTH constant definition from include/mysql.com.h
since we now get USERNAME_LENGTH directly from config.h
netware Directory
--------------------------------------------------------------------------------
Added target %.sql: %.sql.sh to netware/Makefile.am
Replaced all occurences of User char(16) with User Char(@USERNAME_LENGTH@) in
netware/init_db.sql and renamed file to
netware/init_db.sql.sh (gets processed by the new %.sql: %.sql.sh target of
netware/Makefile.am)
Replaced all occurences of User char(16) with User Char(@USERNAME_LENGTH@) in
netware/static_init_db.sql and renamed file to
netware/static_init_db.sql.sh (gets processed by the new %.sql: %.sql.sh target of
netware/Makefile.am)
Replaced all occurences of User char(16) with User Char(@USERNAME_LENGTH@) in
netware/test_db.sql and renamed file to
netware/test_db.sql.sh (gets processed by the new %.sql: %.sql.sh target of
netware/Makefile.am)
Testing
================================================================================
with-username-length.patch applied to BK 5.1 source as follows:
sh> cp with-username-length.patch mysql-5.1/
sh> cd mysql-5.1/
sh> patch -p1 < with-username-length.patch
compiled source after running autotools:
sh> ./configure --with-username-length=37 --prefix=/root/mysql-bin
sh> make
sh> make install
first let's see if the mysql database was created correctly by mysql_install_db:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.1.6-alpha
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> DESCRIBE user;
+-----------------------+-----------------------------------+------+-----+..
| Field | Type | Null | Key |
+-----------------------+-----------------------------------+------+-----+..
| .... | ........ | .. | ... |
| User | char(37) | NO | PRI |
| .... | ........ | .. | ... |
+-----------------------+-----------------------------------+------+-----+..
now let us add a new user with a 37 byte username:
mysql> GRANT ALL ON *.* TO 'areallyreallyreallyreallylongusername'@'localhost';
Query OK, 0 rows affected (0.00 sec)
Note 'areallyreallyreallyreallylongusername' is exactly 37 bytes.
let us add a new user with a 38 byte username:
mysql> GRANT ALL ON *.* TO 'areallyreallyreallyreallylongusername2'@'localhost';
ERROR 1145 (42000): The host or user argument to GRANT is too long
so far so good.
let us now try to login with this user to check client/server functionality:
sh> /root/mysql-bin/bin/mysql -u areallyreallyreallyreallylongusername \
-S /tmp/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4 to server version: 5.1.6-alpha
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
Seems to be ok. let us check some other things:
mysql> SHOW PROCESSLIST;
+----+---------------------------------------+-----------+------+---------+..
| Id | User | Host | db | Command |..
+----+---------------------------------------+-----------+------+---------+
| 4 | areallyreallyreallyreallylongusername | localhost | NULL | Query |
+----+---------------------------------------+-----------+------+---------+..
mysql> SELECT CURRENT_USER();
+-------------------------------------------------+
| CURRENT_USER() |
+-------------------------------------------------+
| areallyreallyreallyreallylongusername@localhost |
+-------------------------------------------------+
Now let us login as root again, and try to revoke all of the user's rights:
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'areallyreallyreallyreallylongusername'@'localhost';
Query OK, 0 rows affected (0.00 sec)
Now let us drop the user:
mysql> DROP USER 'areallyreallyreallyreallylongusername'@'localhost';
Query OK, 0 rows affected (0.00 sec)
Everything seems to be ok.
How to repeat:
Try to add a user longer than 16 Bytes, like:
mysql> GRANT ALL ON *.* TO 'thisUsernameIsReallyReallyLong.com'@'localhost'
ERROR 1145 (42000): The host or user argument to GRANT is too long
Suggested fix:
See attached patch