From 5f715b52d0443c1d3cd456692faba81ceb9a9f69 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Mon, 21 Mar 2005 21:51:31 +0100 Subject: [PATCH 1/6] Fix test_libmysqld link problem on Windows. --- VC++Files/libmysqld/examples/test_libmysqld.dsp | 6 +----- libmysqld/libmysqld.def | 6 ++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/VC++Files/libmysqld/examples/test_libmysqld.dsp b/VC++Files/libmysqld/examples/test_libmysqld.dsp index 6707b8cd8ee..013bc41409d 100644 --- a/VC++Files/libmysqld/examples/test_libmysqld.dsp +++ b/VC++Files/libmysqld/examples/test_libmysqld.dsp @@ -47,7 +47,7 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=xilink6.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"LIBCMTD" /out:"Release/mysql-server.exe" +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib Wsock32.lib /nologo /subsystem:console /machine:I386 /nodefaultlib:"LIBCMTD" /out:"..\test_libmysqld.exe" # Begin Target # Name "test_libmysqld - Win32 Release" @@ -71,9 +71,5 @@ SOURCE=..\..\client\readline.cpp SOURCE=..\..\client\sql_string.cpp # End Source File # End Group -# Begin Source File - -SOURCE=..\..\lib_release\libmysqld.lib -# End Source File # End Target # End Project diff --git a/libmysqld/libmysqld.def b/libmysqld/libmysqld.def index ea3133594f5..0612141a60d 100644 --- a/libmysqld/libmysqld.def +++ b/libmysqld/libmysqld.def @@ -1,6 +1,6 @@ LIBRARY LIBMYSQLD -DESCRIPTION 'MySQL 4.1 Embedded Server Library' -VERSION 4.1 +DESCRIPTION 'MySQL 5.0 Embedded Server Library' +VERSION 5.0 EXPORTS _dig_vec_upper _dig_vec_lower @@ -158,3 +158,5 @@ EXPORTS mysql_stmt_attr_set mysql_stmt_field_count get_defaults_files + my_charset_bin + my_charset_same From 7b985df2a0eb55e5c9efe571bb967b1bf53dcc26 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Mon, 21 Mar 2005 23:32:27 +0100 Subject: [PATCH 2/6] Remove references to no-longer-used MySqlManager project files --- VC++Files/mysql.dsw | 18 -- VC++Files/mysql_ia64.dsw | 3 - VC++Files/mysqlmanager/MySqlManager_ia64.dsp | 276 ------------------- 3 files changed, 297 deletions(-) delete mode 100644 VC++Files/mysqlmanager/MySqlManager_ia64.dsp diff --git a/VC++Files/mysql.dsw b/VC++Files/mysql.dsw index 43cfab4b915..73db9d095cb 100644 --- a/VC++Files/mysql.dsw +++ b/VC++Files/mysql.dsw @@ -3,21 +3,6 @@ Microsoft Developer Studio Workspace File, Format Version 6.00 ############################################################################### -Project: "MySqlManager"=".\mysqlmanager\MySqlManager.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name mysqlclient - End Project Dependency -}}} - -############################################################################### - Project: "bdb"=".\bdb\bdb.dsp" - Package Owner=<4> Package=<5> @@ -420,9 +405,6 @@ Package=<4> Project_Dep_Name mysqlimport End Project Dependency Begin Project Dependency - Project_Dep_Name MySqlManager - End Project Dependency - Begin Project Dependency Project_Dep_Name mysqlshow End Project Dependency Begin Project Dependency diff --git a/VC++Files/mysql_ia64.dsw b/VC++Files/mysql_ia64.dsw index 8af4a7e5c42..dd86d498afe 100644 --- a/VC++Files/mysql_ia64.dsw +++ b/VC++Files/mysql_ia64.dsw @@ -508,9 +508,6 @@ Package=<4> Project_Dep_Name mysqlimport End Project Dependency Begin Project Dependency - Project_Dep_Name MySqlManager - End Project Dependency - Begin Project Dependency Project_Dep_Name mysqlshow End Project Dependency Begin Project Dependency diff --git a/VC++Files/mysqlmanager/MySqlManager_ia64.dsp b/VC++Files/mysqlmanager/MySqlManager_ia64.dsp deleted file mode 100644 index b0ffc9e48c6..00000000000 --- a/VC++Files/mysqlmanager/MySqlManager_ia64.dsp +++ /dev/null @@ -1,276 +0,0 @@ -# Microsoft Developer Studio Project File - Name="MySqlManager" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Application" 0x0101 - -CFG=MYSQLMANAGER - WinIA64 DEBUG -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "MySqlManager.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "MySqlManager.mak" CFG="MYSQLMANAGER - WinIA64 DEBUG" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "MySqlManager - WinIA64 Release" (based on "Win32 (x86) Application") -!MESSAGE "MySqlManager - WinIA64 Debug" (based on "Win32 (x86) Application") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "MySqlManager - WinIA64 Release" - -# PROP BASE Use_MFC 6 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 6 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "release" -# PROP Intermediate_Dir "release" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN64" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MT /W3 /Zi /O2 /I "../include" /D "NDEBUG" /D "DBUG_OFF" /D "_WINDOWS" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c -# SUBTRACT CPP /WX /Fr /YX /Yc /Yu -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win64 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o "NUL" /win64 -# ADD BASE RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "NDEBUG" /d "_AFXDLL" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /machine:IA64 -# ADD LINK32 /nologo /subsystem:windows /out:"../client_release/MySqlManager.exe" /machine:IA64 -# SUBTRACT LINK32 /nodefaultlib - -!ELSEIF "$(CFG)" == "MySqlManager - WinIA64 Debug" - -# PROP BASE Use_MFC 6 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 6 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "debug" -# PROP Intermediate_Dir "debug" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /D "WIN64" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c -# ADD CPP /nologo /MTd /W3 /GR /Zi /Od /I "../include" /D "_DEBUG" /D "_WINDOWS" /D "_IA64_" /D "WIN64" /D "WIN32" /D "_AFX_NO_DAO_SUPPORT" /FD /G2 /EHsc /Wp64 /Zm600 /c -# SUBTRACT CPP /Fr /YX /Yc /Yu -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o "NUL" /win64 -# ADD MTL /nologo /D "_DEBUG" /o "NUL" /win64 -# SUBTRACT MTL /mktyplib203 -# ADD BASE RSC /l 0x409 /d "_DEBUG" /d "_AFXDLL" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:IA64 -# ADD LINK32 wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib uuid.lib /nologo /subsystem:windows /incremental:no /debug /out:"../client_debug/MySqlManager.exe" /libpath:"..\lib_debug\\" /machine:IA64 - -!ENDIF - -# Begin Target - -# Name "MySqlManager - WinIA64 Release" -# Name "MySqlManager - WinIA64 Debug" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\ChildFrm.cpp -# End Source File -# Begin Source File - -SOURCE="..\strings\ctype-extra.c" -# End Source File -# Begin Source File - -SOURCE="..\strings\ctype-latin1.c" -# End Source File -# Begin Source File - -SOURCE="..\strings\ctype-mb.c" -# End Source File -# Begin Source File - -SOURCE=..\strings\is_prefix.c -# End Source File -# Begin Source File - -SOURCE=.\MainFrm.cpp -# End Source File -# Begin Source File - -SOURCE=..\mysys\my_sleep.c -# End Source File -# Begin Source File - -SOURCE=..\strings\my_vsnprintf.c -# End Source File -# Begin Source File - -SOURCE=.\MySqlManager.cpp -# End Source File -# Begin Source File - -SOURCE=.\MySqlManager.rc -# End Source File -# Begin Source File - -SOURCE=.\MySqlManagerDoc.cpp -# End Source File -# Begin Source File - -SOURCE=.\MySqlManagerView.cpp -# End Source File -# Begin Source File - -SOURCE=.\RegisterServer.cpp -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"stdafx.h" -# End Source File -# Begin Source File - -SOURCE=.\ToolSql.cpp -# End Source File -# Begin Source File - -SOURCE=.\ToolSqlQuery.cpp -# End Source File -# Begin Source File - -SOURCE=.\ToolSqlResults.cpp -# End Source File -# Begin Source File - -SOURCE=.\ToolSqlStatus.cpp -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\ChildFrm.h -# End Source File -# Begin Source File - -SOURCE=.\MainFrm.h -# End Source File -# Begin Source File - -SOURCE=.\MySqlManager.h -# End Source File -# Begin Source File - -SOURCE=.\MySqlManagerDoc.h -# End Source File -# Begin Source File - -SOURCE=.\MySqlManagerView.h -# End Source File -# Begin Source File - -SOURCE=.\RegisterServer.h -# End Source File -# Begin Source File - -SOURCE=.\Resource.h -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# Begin Source File - -SOURCE=.\ToolSqlQuery.h -# End Source File -# Begin Source File - -SOURCE=.\ToolSqlResults.h -# End Source File -# Begin Source File - -SOURCE=.\ToolSqlStatus.h -# End Source File -# End Group -# Begin Group "Resource Files" - -# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" -# Begin Source File - -SOURCE=.\res\bitmap1.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\bitmap3.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\bmp00001.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\bmp00002.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\database.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\fontd.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\fontu.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\MySqlManager.ico -# End Source File -# Begin Source File - -SOURCE=.\res\MySqlManager.rc2 -# End Source File -# Begin Source File - -SOURCE=.\res\MySqlManagerDoc.ico -# End Source File -# Begin Source File - -SOURCE=.\res\query_ex.bmp -# End Source File -# Begin Source File - -SOURCE=.\res\Toolbar.bmp -# End Source File -# End Group -# Begin Source File - -SOURCE=.\ReadMe.txt -# End Source File -# End Target -# End Project From 4c67678f1506c668726d411cdeb2ccc0087540ad Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Tue, 22 Mar 2005 00:00:24 +0100 Subject: [PATCH 3/6] Fix Windows compile warnings, declarations of walk functions --- sql/handler.cc | 4 ++-- sql/item_func.cc | 1 - sql/item_sum.cc | 6 +++++- sql/item_sum.h | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 36c14660a95..620477680ee 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -836,9 +836,9 @@ int ha_recover(HASH *commit_list) /* commit_list and tc_heuristic_recover cannot be set both */ DBUG_ASSERT(commit_list==0 || tc_heuristic_recover==0); /* if either is set, total_ha_2pc must be set too */ - DBUG_ASSERT(dry_run || total_ha_2pc>opt_bin_log); + DBUG_ASSERT(dry_run || total_ha_2pc>(ulong)opt_bin_log); - if (total_ha_2pc <= opt_bin_log) + if (total_ha_2pc <= (ulong)opt_bin_log) DBUG_RETURN(0); if (commit_list) diff --git a/sql/item_func.cc b/sql/item_func.cc index 53c0cf4c05a..3be99479e67 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4683,7 +4683,6 @@ Field * Item_func_sp::tmp_table_field(TABLE *t_arg) { Field *res= 0; - enum_field_types ftype; DBUG_ENTER("Item_func_sp::tmp_table_field"); if (m_sp) diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 8ee9dc0859b..11d42389ca1 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2158,12 +2158,16 @@ int composite_key_cmp(void* arg, byte* key1, byte* key2) } +C_MODE_START + static int count_distinct_walk(void *elem, element_count count, void *arg) { (*((ulonglong*)arg))++; return 0; } +C_MODE_END + void Item_sum_count_distinct::cleanup() { @@ -2658,7 +2662,7 @@ int group_concat_key_cmp_with_distinct_and_order(void* arg,byte* key1, Append data from current leaf to item->result */ -int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), +int dump_leaf_key(byte* key, element_count count __attribute__((unused)), Item_func_group_concat *item) { char buff[MAX_FIELD_WIDTH]; diff --git a/sql/item_sum.h b/sql/item_sum.h index f6650f9c3d2..07f23a3d400 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -851,7 +851,8 @@ class Item_func_group_concat : public Item_sum friend int group_concat_key_cmp_with_distinct_and_order(void* arg, byte* key1, byte* key2); - friend int dump_leaf_key(byte* key, uint32 count __attribute__((unused)), + friend int dump_leaf_key(byte* key, + element_count count __attribute__((unused)), Item_func_group_concat *group_concat_item); public: From ad26a667e69b964c60d1a30916dea3c7fbefaf4a Mon Sep 17 00:00:00 2001 From: "mysqldev@mysql.com" <> Date: Tue, 22 Mar 2005 15:54:18 +0100 Subject: [PATCH 4/6] sql_acl.cc, sql_acl.h, sql_parse.cc New privilege CREATE USER (CREATE_USER_ACL, Create_user_priv) added grant2.test: new tests (mostly backported from jani's patch) system_mysql_db.result, sp.result, grant2.result, grant.result: results updated --- BitKeeper/etc/logging_ok | 1 + mysql-test/r/grant.result | 13 +++--- mysql-test/r/grant2.result | 39 +++++++++++------ mysql-test/r/sp.result | 2 + mysql-test/r/system_mysql_db.result | 1 + mysql-test/t/grant2.test | 50 ++++++++++++++++----- scripts/mysql_create_system_tables.sh | 13 +++--- scripts/mysql_fix_privilege_tables.sql | 12 ++++++ sql/sql_acl.cc | 36 ++++++++++++---- sql/sql_acl.h | 37 ++++++++-------- sql/sql_parse.cc | 60 ++++++++++++++------------ sql/sql_show.cc | 1 + sql/sql_yacc.yy | 1 + 13 files changed, 176 insertions(+), 90 deletions(-) diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index eff53f4a789..6c6065277fe 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -225,6 +225,7 @@ salle@vafla.online.bg sasha@mysql.sashanet.com serg@build.mysql.com serg@build.mysql2.com +serg@mysql.com serg@serg.mylan serg@serg.mysql.com serg@sergbook.mylan diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index e5f7f535ae2..ecd2758fd1c 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -10,8 +10,8 @@ GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' REQUIRE CIPHER 'EDH-RSA-DES-CBC3 GRANT SELECT ON `mysqltest`.* TO 'mysqltest_1'@'localhost' grant delete on mysqltest.* to mysqltest_1@localhost; select * from mysql.user where user="mysqltest_1"; -Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections -localhost mysqltest_1 N N N N N N N N N N N N N N N N N N N N N N N N N SPECIFIED EDH-RSA-DES-CBC3-SHA 0 0 0 0 +Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Create_user_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections +localhost mysqltest_1 N N N N N N N N N N N N N N N N N N N N N N N N N N SPECIFIED EDH-RSA-DES-CBC3-SHA 0 0 0 0 show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' REQUIRE CIPHER 'EDH-RSA-DES-CBC3-SHA' @@ -41,15 +41,15 @@ delete from mysql.user where user='mysqltest_1'; flush privileges; grant usage on *.* to mysqltest_1@localhost with max_queries_per_hour 10; select * from mysql.user where user="mysqltest_1"; -Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections -localhost mysqltest_1 N N N N N N N N N N N N N N N N N N N N N N N N N 10 0 0 0 +Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Create_user_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections +localhost mysqltest_1 N N N N N N N N N N N N N N N N N N N N N N N N N N 10 0 0 0 show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' WITH MAX_QUERIES_PER_HOUR 10 grant usage on *.* to mysqltest_1@localhost with max_updates_per_hour 20 max_connections_per_hour 30; select * from mysql.user where user="mysqltest_1"; -Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections -localhost mysqltest_1 N N N N N N N N N N N N N N N N N N N N N N N N N 10 20 30 0 +Host User Password Select_priv Insert_priv Update_priv Delete_priv Create_priv Drop_priv Reload_priv Shutdown_priv Process_priv File_priv Grant_priv References_priv Index_priv Alter_priv Show_db_priv Super_priv Create_tmp_table_priv Lock_tables_priv Execute_priv Repl_slave_priv Repl_client_priv Create_view_priv Show_view_priv Create_routine_priv Alter_routine_priv Create_user_priv ssl_type ssl_cipher x509_issuer x509_subject max_questions max_updates max_connections max_user_connections +localhost mysqltest_1 N N N N N N N N N N N N N N N N N N N N N N N N N N 10 20 30 0 show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' WITH MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 20 MAX_CONNECTIONS_PER_HOUR 30 @@ -440,6 +440,7 @@ Create Databases,Tables,Indexes To create new databases and tables Create routine Functions,Procedures To use CREATE FUNCTION/PROCEDURE Create temporary tables Databases To use CREATE TEMPORARY TABLE Create view Tables To create new views +Create user Server Admin To create new users Delete Tables To delete existing rows Drop Databases,Tables To drop databases, tables, and views Execute Functions,Procedures To execute stored routines diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result index e6c78fdfdd4..7b3598ab4d9 100644 --- a/mysql-test/r/grant2.result +++ b/mysql-test/r/grant2.result @@ -5,7 +5,25 @@ delete from mysql.db where user like 'mysqltest\_%'; delete from mysql.tables_priv where user like 'mysqltest\_%'; delete from mysql.columns_priv where user like 'mysqltest\_%'; flush privileges; +grant all privileges on `my\_1`.* to mysqltest_1@localhost with grant option; +grant create user on *.* to mysqltest_1@localhost; +create user mysqltest_2@localhost; +grant select on `my\_1`.* to mysqltest_2@localhost; +grant select on `my\_1`.* to mysqltest_2@localhost identified by 'pass'; +ERROR 42000: You must have privileges to update tables in the mysql database to be able to change passwords for others +grant update on mysql.* to mysqltest_1@localhost; +grant select on `my\_1`.* to mysqltest_2@localhost identified by 'pass'; +grant select on `my\_1`.* to mysqltest_3@localhost; +grant insert on mysql.* to mysqltest_1@localhost; +grant select on `my\_1`.* to mysqltest_3@localhost; +grant select on `my\_1`.* to mysqltest_4@localhost identified by 'pass'; +delete from mysql.user where user like 'mysqltest\_%'; +delete from mysql.db where user like 'mysqltest\_%'; +delete from mysql.tables_priv where user like 'mysqltest\_%'; +delete from mysql.columns_priv where user like 'mysqltest\_%'; +flush privileges; grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option; +grant create user on *.* to mysqltest_1@localhost; select current_user(); current_user() mysqltest_1@localhost @@ -23,10 +41,9 @@ grant select on `my\_1`.* to mysqltest_4@localhost with grant option; ERROR 42000: 'mysqltest_1'@'localhost' is not allowed to create new users grant select on `my\_1`.* to mysqltest_4@localhost identified by 'mypass' with grant option; -ERROR 42000: Access denied for user 'mysqltest_1'@'localhost' to database 'mysql' show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost -GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' +GRANT CREATE USER ON *.* TO 'mysqltest_1'@'localhost' GRANT ALL PRIVILEGES ON `my\_%`.* TO 'mysqltest_1'@'localhost' WITH GRANT OPTION show grants for mysqltest_2@localhost; Grants for mysqltest_2@localhost @@ -212,7 +229,7 @@ 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; +grant create user on *.* to mysqltest_2@localhost; select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; ERROR 42000: SELECT command denied to user 'mysqltest_2'@'localhost' for table 'user' create user mysqltest_A@'%'; @@ -220,19 +237,17 @@ 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; +grant INSERT,DELETE,UPDATE on mysql.* to mysqltest_3@localhost; +show grants; +Grants for mysqltest_3@localhost +GRANT USAGE ON *.* TO 'mysqltest_3'@'localhost' +GRANT INSERT, UPDATE, DELETE ON `mysql`.* TO 'mysqltest_3'@'localhost' select host,user,password from mysql.user where user like 'mysqltest_%' order by host,user,password; -host user password -% mysqltest_2 *BD447CBA355AF58578D3AE33BA2E2CD388BA08D1 -localhost mysqltest_3 +ERROR 42000: SELECT command denied to user 'mysqltest_3'@'localhost' for table 'user' 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_C@'%'; drop user mysqltest_3@localhost; set @@sql_mode=''; create database mysqltest_1; diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 5366ecb2be3..93884bf4cf4 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -2185,6 +2185,7 @@ Create Databases,Tables,Indexes To create new databases and tables Create routine Functions,Procedures To use CREATE FUNCTION/PROCEDURE Create temporary tables Databases To use CREATE TEMPORARY TABLE Create view Tables To create new views +Create user Server Admin To create new users Delete Tables To delete existing rows Drop Databases,Tables To drop databases, tables, and views Execute Functions,Procedures To execute stored routines @@ -2238,6 +2239,7 @@ Create Databases,Tables,Indexes To create new databases and tables Create routine Functions,Procedures To use CREATE FUNCTION/PROCEDURE Create temporary tables Databases To use CREATE TEMPORARY TABLE Create view Tables To create new views +Create user Server Admin To create new users Delete Tables To delete existing rows Drop Databases,Tables To drop databases, tables, and views Execute Functions,Procedures To execute stored routines diff --git a/mysql-test/r/system_mysql_db.result b/mysql-test/r/system_mysql_db.result index 532f0eca014..40a9c3b9af5 100644 --- a/mysql-test/r/system_mysql_db.result +++ b/mysql-test/r/system_mysql_db.result @@ -96,6 +96,7 @@ user CREATE TABLE `user` ( `Show_view_priv` enum('N','Y') character set utf8 NOT NULL default 'N', `Create_routine_priv` enum('N','Y') character set utf8 NOT NULL default 'N', `Alter_routine_priv` enum('N','Y') character set utf8 NOT NULL default 'N', + `Create_user_priv` enum('N','Y') character set utf8 NOT NULL default 'N', `ssl_type` enum('','ANY','X509','SPECIFIED') character set utf8 NOT NULL default '', `ssl_cipher` blob NOT NULL, `x509_issuer` blob NOT NULL, diff --git a/mysql-test/t/grant2.test b/mysql-test/t/grant2.test index 58f91fddcc2..e480cfc4f5b 100644 --- a/mysql-test/t/grant2.test +++ b/mysql-test/t/grant2.test @@ -17,11 +17,42 @@ delete from mysql.columns_priv where user like 'mysqltest\_%'; flush privileges; +grant all privileges on `my\_1`.* to mysqltest_1@localhost with grant option; +grant create user on *.* to mysqltest_1@localhost; +create user mysqltest_2@localhost; +connect (user_a,localhost,mysqltest_1,,); +connection user_a; +grant select on `my\_1`.* to mysqltest_2@localhost; +--error 1132 +grant select on `my\_1`.* to mysqltest_2@localhost identified by 'pass'; +disconnect user_a; +connection default; +grant update on mysql.* to mysqltest_1@localhost; +connect (user_b,localhost,mysqltest_1,,); +connection user_b; +grant select on `my\_1`.* to mysqltest_2@localhost identified by 'pass'; +grant select on `my\_1`.* to mysqltest_3@localhost; +disconnect user_b; +connection default; +grant insert on mysql.* to mysqltest_1@localhost; +connect (user_c,localhost,mysqltest_1,,); +connection user_c; +grant select on `my\_1`.* to mysqltest_3@localhost; +grant select on `my\_1`.* to mysqltest_4@localhost identified by 'pass'; +disconnect user_c; +connection default; +delete from mysql.user where user like 'mysqltest\_%'; +delete from mysql.db where user like 'mysqltest\_%'; +delete from mysql.tables_priv where user like 'mysqltest\_%'; +delete from mysql.columns_priv where user like 'mysqltest\_%'; +flush privileges; + # # wild_compare fun # grant all privileges on `my\_%`.* to mysqltest_1@localhost with grant option; +grant create user on *.* to mysqltest_1@localhost; connect (user1,localhost,mysqltest_1,,); connection user1; select current_user(); @@ -29,6 +60,7 @@ select current_user; grant all privileges on `my\_1`.* to mysqltest_2@localhost with grant option; --error 1044 grant all privileges on `my_%`.* to mysqltest_3@localhost with grant option; + # # NO_AUTO_CREATE_USER mode # @@ -36,7 +68,6 @@ set @@sql_mode='NO_AUTO_CREATE_USER'; select @@sql_mode; --error 1211 grant select on `my\_1`.* to mysqltest_4@localhost with grant option; ---error 1044 grant select on `my\_1`.* to mysqltest_4@localhost identified by 'mypass' with grant option; disconnect user1; @@ -215,9 +246,10 @@ show grants for '%@b'@'b'; show grants for '%@a'@'a'; drop user '%@a'@'a'; # -# USAGE WITH GRANT OPTION is sufficient. +# CREATE USER privilege is enough +# create user mysqltest_2@localhost; -grant usage on *.* to mysqltest_2@localhost with grant option; +grant create user on *.* to mysqltest_2@localhost; connect (user2,localhost,mysqltest_2,,); connection user2; --error 1142 @@ -229,22 +261,20 @@ disconnect user2; connection default; drop user mysqltest_2@localhost; # -# ALL PRIVILEGES without GRANT OPTION is not sufficient. +# INSERT/UPDATE/DELETE is ok too create user mysqltest_3@localhost; -grant all privileges on mysql.* to mysqltest_3@localhost; +grant INSERT,DELETE,UPDATE on mysql.* to mysqltest_3@localhost; connect (user3,localhost,mysqltest_3,,); connection user3; +show grants; +--error 1142 select host,user,password from mysql.user where user like 'mysqltest_%' 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@'%'; +drop user mysqltest_C@'%'; disconnect user3; connection default; -drop user mysqltest_B@'%'; drop user mysqltest_3@localhost; # # Bug #3309: Test IP addresses with netmask diff --git a/scripts/mysql_create_system_tables.sh b/scripts/mysql_create_system_tables.sh index d87113d3656..29f6f7b41e1 100644 --- a/scripts/mysql_create_system_tables.sh +++ b/scripts/mysql_create_system_tables.sh @@ -146,6 +146,7 @@ then c_u="$c_u Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," c_u="$c_u Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," c_u="$c_u Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," + c_u="$c_u Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL," c_u="$c_u ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL," c_u="$c_u ssl_cipher BLOB NOT NULL," c_u="$c_u x509_issuer BLOB NOT NULL," @@ -161,22 +162,22 @@ then if test "$1" = "test" then - i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); - INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); - REPLACE INTO user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); + i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); + INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); + REPLACE INTO user VALUES ('127.0.0.1','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); INSERT INTO user (host,user) values ('localhost',''); INSERT INTO user (host,user) values ('$hostname','');" else - i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);" + i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0);" if test "$windows" = "0" then i_u="$i_u - INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); + INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0); INSERT INTO user (host,user) values ('$hostname',''); INSERT INTO user (host,user) values ('localhost','');" else i_u="$i_u - INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);" + INSERT INTO user VALUES ('localhost','','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0);" fi fi fi diff --git a/scripts/mysql_fix_privilege_tables.sql b/scripts/mysql_fix_privilege_tables.sql index 2310e8d0bef..628b034362d 100644 --- a/scripts/mysql_fix_privilege_tables.sql +++ b/scripts/mysql_fix_privilege_tables.sql @@ -290,6 +290,18 @@ UPDATE db SET Create_routine_priv=Create_priv, Alter_routine_priv=Alter_priv, Ex # ALTER TABLE user ADD max_user_connections int(11) unsigned DEFAULT '0' NOT NULL AFTER max_connections; +# +# user.Create_user_priv +# + +SET @hadCreateUserPriv:=0; +SELECT @hadCreateUserPriv:=1 FROM user WHERE Create_user_priv LIKE '%'; + +ALTER TABLE user ADD Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL AFTER Alter_routine_priv; +UPDATE user LEFT JOIN db USING (Host,User) SET Create_user_priv='Y' + WHERE @hadCreateUserPriv = 0 AND + (user.Grant_priv = 'Y' OR db.Grant_priv = 'Y'); + # # Create some possible missing tables # diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index c51e5e00aa1..582fd4cf425 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -239,7 +239,7 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables) DBUG_PRINT("info",("user table fields: %d, password length: %d", table->s->fields, table->field[2]->field_length)); - + pthread_mutex_lock(&LOCK_global_system_variables); if (table->field[2]->field_length < SCRAMBLED_PASSWORD_CHAR_LENGTH) { @@ -323,6 +323,12 @@ my_bool acl_init(THD *org_thd, bool dont_read_acl_tables) if (table->s->fields <= 33 && (user.access & ALTER_ACL)) user.access|= ALTER_PROC_ACL; + /* + pre 5.0.3 did not have CREATE_USER_ACL + */ + if (table->s->fields <= 36 && (user.access & GRANT_ACL)) + user.access|= CREATE_USER_ACL; + user.sort= get_sort(2,user.host.hostname,user.user); user.hostname_length= (user.host.hostname ? (uint) strlen(user.host.hostname) : 0); @@ -1541,18 +1547,26 @@ end: } -/* Return 1 if we are allowed to create new users */ +/* + Return 1 if we are allowed to create new users + the logic here is: INSERT_ACL is sufficient. + It's also a requirement in opt_safe_user_create, + otherwise CREATE_USER_ACL is enough. +*/ static bool test_if_create_new_users(THD *thd) { - bool create_new_users=1; // Assume that we are allowed to create new users - if (opt_safe_user_create && !(thd->master_access & INSERT_ACL)) + bool create_new_users= test(thd->master_access & INSERT_ACL) || + (!opt_safe_user_create && + test(thd->master_access & CREATE_USER_ACL)); + if (!create_new_users) { TABLE_LIST tl; ulong db_access; bzero((char*) &tl,sizeof(tl)); tl.db= (char*) "mysql"; tl.table_name= (char*) "user"; + create_new_users= 1; db_access=acl_get(thd->host, thd->ip, thd->priv_user, tl.db, 0); @@ -1614,8 +1628,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, goto end; } /* - There are four options which affect the process of creation of - a new user(mysqld option --safe-create-user, 'insert' privilege + There are four options which affect the process of creation of + a new user (mysqld option --safe-create-user, 'insert' privilege on 'mysql.user' table, using 'GRANT' with 'IDENTIFIED BY' and SQL_MODE flag NO_AUTO_CREATE_USER). Below is the simplified rule how it should work. @@ -1623,6 +1637,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, else if (identified_by) => create else if (no_auto_create_user) => reject else create + + see also test_if_create_new_users() */ else if (((thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER) && !password_len) || !create_user) @@ -2925,7 +2941,7 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list, table_name= table_list->table_name; grant_name= proc_hash_search(Str->host.str, NullS, db_name, - Str->user.str, table_name, 1); + Str->user.str, table_name, 1); if (!grant_name) { if (revoke_grant) @@ -2946,7 +2962,7 @@ bool mysql_procedure_grant(THD *thd, TABLE_LIST *table_list, } my_hash_insert(&proc_priv_hash,(byte*) grant_name); } - + if (replace_proc_table(thd, grant_name, tables[1].table, *Str, db_name, table_name, rights, revoke_grant)) { @@ -3688,11 +3704,13 @@ static const char *command_array[]= "ALTER", "SHOW DATABASES", "SUPER", "CREATE TEMPORARY TABLES", "LOCK TABLES", "EXECUTE", "REPLICATION SLAVE", "REPLICATION CLIENT", "CREATE VIEW", "SHOW VIEW", "CREATE ROUTINE", "ALTER ROUTINE", + "CREATE USER" }; static uint command_lengths[]= { - 6, 6, 6, 6, 6, 4, 6, 8, 7, 4, 5, 10, 5, 5, 14, 5, 23, 11, 7, 17, 18, 11, 9, 14, 13 + 6, 6, 6, 6, 6, 4, 6, 8, 7, 4, 5, 10, 5, 5, 14, 5, 23, 11, 7, 17, 18, 11, 9, + 14, 13, 11 }; diff --git a/sql/sql_acl.h b/sql/sql_acl.h index 24916fd4385..18eb123d402 100644 --- a/sql/sql_acl.h +++ b/sql/sql_acl.h @@ -39,12 +39,17 @@ #define SHOW_VIEW_ACL (1L << 22) #define CREATE_PROC_ACL (1L << 23) #define ALTER_PROC_ACL (1L << 24) +#define CREATE_USER_ACL (1L << 25) /* don't forget to update - static struct show_privileges_st sys_privileges[] - in sql_show.cc when adding new privileges! + 1. static struct show_privileges_st sys_privileges[] + 2. static const char *command_array[] and static uint command_lengths[] + 3. mysql_create_system_tables.sh, mysql_fix_privilege_tables.sql + 4. acl_init() or whatever - to define behaviour for old privilege tables + 5. sql_yacc.yy - for GRANT/REVOKE to work */ - +#define EXTRA_ACL (1L << 29) +#define NO_ACCESS (1L << 30) #define DB_ACLS \ (UPDATE_ACL | SELECT_ACL | INSERT_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL | \ @@ -72,10 +77,7 @@ REFERENCES_ACL | INDEX_ACL | ALTER_ACL | SHOW_DB_ACL | SUPER_ACL | \ CREATE_TMP_ACL | LOCK_TABLES_ACL | REPL_SLAVE_ACL | REPL_CLIENT_ACL | \ EXECUTE_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL | CREATE_PROC_ACL | \ - ALTER_PROC_ACL ) - -#define EXTRA_ACL (1L << 29) -#define NO_ACCESS (1L << 30) + ALTER_PROC_ACL | CREATE_USER_ACL) #define DEFAULT_CREATE_PROC_ACLS \ (ALTER_PROC_ACL | EXECUTE_ACL) @@ -85,25 +87,21 @@ This is needed as the 'host' and 'db' table is missing a few privileges */ -/* Continius bit-segments that needs to be shifted */ -#define DB_REL1 ((1L << 6) | (1L << 7) | (1L << 8) | (1L << 9)) -#define DB_REL2 ((1L << 10) | (1L << 11)) -#define DB_REL3 ((1L << 12) | (1L << 13) | (1L << 14) | (1L << 15)) -#define DB_REL4 ((1L << 16)) - /* Privileges that needs to be reallocated (in continous chunks) */ +#define DB_CHUNK0 (SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL | \ + CREATE_ACL | DROP_ACL) #define DB_CHUNK1 (GRANT_ACL | REFERENCES_ACL | INDEX_ACL | ALTER_ACL) #define DB_CHUNK2 (CREATE_TMP_ACL | LOCK_TABLES_ACL) #define DB_CHUNK3 (CREATE_VIEW_ACL | SHOW_VIEW_ACL | \ CREATE_PROC_ACL | ALTER_PROC_ACL ) #define DB_CHUNK4 (EXECUTE_ACL) -#define fix_rights_for_db(A) (((A) & 63) | \ - (((A) & DB_REL1) << 4) | \ - (((A) & DB_REL2) << 6) | \ - (((A) & DB_REL3) << 9) | \ - (((A) & DB_REL4) << 2)) -#define get_rights_for_db(A) (((A) & 63) | \ +#define fix_rights_for_db(A) (((A) & DB_CHUNK0) | \ + (((A) << 4) & DB_CHUNK1) | \ + (((A) << 6) & DB_CHUNK2) | \ + (((A) << 9) & DB_CHUNK3) | \ + (((A) << 2) & DB_CHUNK4)) +#define get_rights_for_db(A) (((A) & DB_CHUNK0) | \ (((A) & DB_CHUNK1) >> 4) | \ (((A) & DB_CHUNK2) >> 6) | \ (((A) & DB_CHUNK3) >> 9) | \ @@ -190,6 +188,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table, List &user_list, bool mysql_procedure_grant(THD *thd, TABLE_LIST *table, List &user_list, ulong rights, bool revoke, bool no_error); +ACL_USER *check_acl_user(LEX_USER *user_name, uint *acl_acl_userdx); my_bool grant_init(THD *thd); void grant_free(void); void grant_reload(THD *thd); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index cc5bd90e4f2..dc5c644d9a1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3559,7 +3559,8 @@ unsent_create_error: #ifndef NO_EMBEDDED_ACCESS_CHECKS case SQLCOM_CREATE_USER: { - if (check_access(thd, GRANT_ACL,"mysql",0,1,0)) + if (check_access(thd, INSERT_ACL, "mysql", 0, 1, 1) && + check_global_access(thd,CREATE_USER_ACL)) break; if (!(res= mysql_create_user(thd, lex->users_list))) { @@ -3574,7 +3575,8 @@ unsent_create_error: } case SQLCOM_DROP_USER: { - if (check_access(thd, GRANT_ACL,"mysql",0,1,0)) + if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 1) && + check_global_access(thd,CREATE_USER_ACL)) break; if (!(res= mysql_drop_user(thd, lex->users_list))) { @@ -3589,7 +3591,8 @@ unsent_create_error: } case SQLCOM_RENAME_USER: { - if (check_access(thd, GRANT_ACL,"mysql",0,1,0)) + if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1) && + check_global_access(thd,CREATE_USER_ACL)) break; if (!(res= mysql_rename_user(thd, lex->users_list))) { @@ -3604,7 +3607,8 @@ unsent_create_error: } case SQLCOM_REVOKE_ALL: { - if (check_access(thd, GRANT_ACL ,"mysql",0,1,0)) + if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1) && + check_global_access(thd,CREATE_USER_ACL)) break; if (!(res = mysql_revoke_all(thd, lex->users_list))) { @@ -3629,32 +3633,32 @@ unsent_create_error: if (thd->user) // If not replication { LEX_USER *user; + uint counter; + List_iterator user_list(lex->users_list); - while ((user=user_list++)) + while ((user= user_list++)) { - if (user->password.str && - (strcmp(thd->user, user->user.str) || - user->host.str && - my_strcasecmp(system_charset_info, - user->host.str, thd->host_or_ip))) - { - if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 0)) - goto error; - break; // We are allowed to do changes - } - } - } - if (specialflag & SPECIAL_NO_RESOLVE) - { - LEX_USER *user; - List_iterator user_list(lex->users_list); - while ((user=user_list++)) - { - if (hostname_requires_resolving(user->host.str)) - push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_WARN_HOSTNAME_WONT_WORK, - ER(ER_WARN_HOSTNAME_WONT_WORK), - user->host.str); + if (specialflag & SPECIAL_NO_RESOLVE && + hostname_requires_resolving(user->host.str)) + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_WARN_HOSTNAME_WONT_WORK, + ER(ER_WARN_HOSTNAME_WONT_WORK), + user->host.str); + // Are we trying to change a password of another user + DBUG_ASSERT(user->host.str != 0); + if (strcmp(thd->user, user->user.str) || + my_strcasecmp(system_charset_info, + user->host.str, thd->host_or_ip)) + { + // TODO: use check_change_password() + if (check_acl_user(user, &counter) && user->password.str && + check_access(thd, UPDATE_ACL,"mysql",0,1,1)) + { + my_message(ER_PASSWORD_NOT_ALLOWED, + ER(ER_PASSWORD_NOT_ALLOWED), MYF(0)); + goto error; + } + } } } if (first_table) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 124ce1805db..fadc445e85d 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -102,6 +102,7 @@ static struct show_privileges_st sys_privileges[]= {"Create routine","Functions,Procedures","To use CREATE FUNCTION/PROCEDURE"}, {"Create temporary tables","Databases","To use CREATE TEMPORARY TABLE"}, {"Create view", "Tables", "To create new views"}, + {"Create user", "Server Admin", "To create new users"}, {"Delete", "Tables", "To delete existing rows"}, {"Drop", "Databases,Tables", "To drop databases, tables, and views"}, {"Execute", "Functions,Procedures", "To execute stored routines"}, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index cc6eadf5fd5..8141de31275 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7903,6 +7903,7 @@ object_privilege: | SHOW VIEW_SYM { Lex->grant |= SHOW_VIEW_ACL; } | CREATE ROUTINE_SYM { Lex->grant |= CREATE_PROC_ACL; } | ALTER ROUTINE_SYM { Lex->grant |= ALTER_PROC_ACL; } + | CREATE USER { Lex->grant |= CREATE_USER_ACL; } ; From f7cbe9a2cc973d73967c1628f7716487f2f174f1 Mon Sep 17 00:00:00 2001 From: "serg@mysql.com" <> Date: Tue, 22 Mar 2005 20:13:49 +0100 Subject: [PATCH 5/6] BUG#9339 - Updating a column does not work if the table has a UTF-8 VARCHAR primary key fixed my_charpos() call in Field_varstring::get_key_image --- mysql-test/r/type_varchar.result | 7 +++++++ mysql-test/t/type_varchar.test | 9 +++++++++ sql/field.cc | 6 +++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/type_varchar.result b/mysql-test/r/type_varchar.result index 1c2653bd225..d2fe843a68b 100644 --- a/mysql-test/r/type_varchar.result +++ b/mysql-test/r/type_varchar.result @@ -376,3 +376,10 @@ explain select * from t1 where v like 'S%' order by v; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range v v 13 NULL 2 Using where; Using filesort drop table t1; +create table t1 (pkcol varchar(16), othercol varchar(16), primary key (pkcol)); +insert into t1 values ('test', 'something'); +update t1 set othercol='somethingelse' where pkcol='test'; +select * from t1; +pkcol othercol +test somethingelse +drop table t1; diff --git a/mysql-test/t/type_varchar.test b/mysql-test/t/type_varchar.test index 0168128d513..9867cf4c057 100644 --- a/mysql-test/t/type_varchar.test +++ b/mysql-test/t/type_varchar.test @@ -97,3 +97,12 @@ explain select * from t1 where v like 'This is a test' order by v; explain select * from t1 where v='This is a test' order by v; explain select * from t1 where v like 'S%' order by v; drop table t1; + +# +# bug#9339 - meaningless Field_varstring::get_key_image +# +create table t1 (pkcol varchar(16), othercol varchar(16), primary key (pkcol)); +insert into t1 values ('test', 'something'); +update t1 set othercol='somethingelse' where pkcol='test'; +select * from t1; +drop table t1; diff --git a/sql/field.cc b/sql/field.cc index 84024a63266..b96a2cbdf4d 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -5725,12 +5725,12 @@ void Field_varstring::get_key_image(char *buff, uint length, imagetype type) { uint f_length= length_bytes == 1 ? (uint) (uchar) *ptr : uint2korr(ptr); uint char_length= length / field_charset->mbmaxlen; - char_length= my_charpos(field_charset, ptr, ptr + length_bytes, - char_length); + char *pos= ptr+length_bytes; + char_length= my_charpos(field_charset, pos, pos + f_length, char_length); set_if_smaller(f_length, char_length); /* Key is always stored with 2 bytes */ int2store(buff,f_length); - memcpy(buff+HA_KEY_BLOB_LENGTH, ptr+length_bytes, f_length); + memcpy(buff+HA_KEY_BLOB_LENGTH, pos, f_length); if (f_length < length) { /* From 3ef3c59ed0682f8c892efbe3ec612517cd5f8c72 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Tue, 22 Mar 2005 21:52:01 +0100 Subject: [PATCH 6/6] Hack to ensure that CHAR's created in 5.0 are not converted to VARCHAR even if the row type is dynamic (For 4.1 tables old 'VARCHAR' fields are converted to true VARCHAR in the next ALTER TABLE) This ensures that one can use MySQL 5.0 privilege tables with MySQL 4.1. (Fix imported from main 5.0 tree to 5.0.3 build tree.) --- mysql-test/r/information_schema.result | 5 ++- mysql-test/r/ndb_autodiscover.result | 4 +-- mysql-test/r/ps_1general.result | 2 +- mysql-test/r/show_check.result | 42 +++++++++++++------------- mysql-test/r/view.result | 4 +-- scripts/fill_func_tables.sh | 8 ++--- scripts/mysql_create_system_tables.sh | 10 +++--- scripts/mysql_fix_privilege_tables.sh | 2 +- scripts/mysql_fix_privilege_tables.sql | 42 +++++++++++++++++++++++--- sql/sql_table.cc | 9 ++---- sql/table.cc | 10 ++++++ 11 files changed, 87 insertions(+), 51 deletions(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index dc456e80e63..1c3525c1508 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -118,8 +118,8 @@ t2 t3 show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t2 MyISAM 9 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL -t3 MyISAM 9 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL +t2 MyISAM 10 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL +t3 MyISAM 10 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL v1 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # NULL NULL NULL NULL view show full columns from t3 like "a%"; Field Type Collation Null Key Default Extra Privileges Comment @@ -432,7 +432,6 @@ information_schema.tables) union select version from information_schema.tables; s1 0 -9 10 drop table t1; SHOW CREATE TABLE INFORMATION_SCHEMA.character_sets; diff --git a/mysql-test/r/ndb_autodiscover.result b/mysql-test/r/ndb_autodiscover.result index 38b34579f03..27ebda36669 100644 --- a/mysql-test/r/ndb_autodiscover.result +++ b/mysql-test/r/ndb_autodiscover.result @@ -144,8 +144,8 @@ Handler_discover 1 flush tables; show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t6 MyISAM 9 Fixed 1 260 # # # 0 NULL # # NULL # NULL # -t7 ndbcluster 9 Fixed 1 276 # # # 0 NULL # # NULL # NULL # +t6 MyISAM 10 Fixed 1 260 # # # 0 NULL # # NULL # NULL # +t7 ndbcluster 10 Fixed 1 276 # # # 0 NULL # # NULL # NULL # show status like 'handler_discover%'; Variable_name Value Handler_discover 2 diff --git a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result index cd3c8e162f7..342b3e3ef06 100644 --- a/mysql-test/r/ps_1general.result +++ b/mysql-test/r/ps_1general.result @@ -290,7 +290,7 @@ t2 1 t2_idx 1 b A NULL NULL NULL YES BTREE prepare stmt4 from ' show table status from test like ''t2%'' '; execute stmt4; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t2 MyISAM 9 Fixed 0 0 0 64424509439 1024 0 NULL # # # latin1_swedish_ci NULL +t2 MyISAM 10 Fixed 0 0 0 64424509439 1024 0 NULL # # # latin1_swedish_ci NULL prepare stmt4 from ' show table status from test like ''t9%'' '; execute stmt4; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index 15cae7646f9..7c34481b519 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -315,57 +315,57 @@ insert into t2 values (1),(2); insert into t3 values (1,1),(2,2); show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 2 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 2 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 2 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 2 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 2 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 2 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL insert into t1 values (3),(4); insert into t2 values (3),(4); insert into t3 values (3,3),(4,4); show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 4 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 4 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 4 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 4 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 4 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 4 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL insert into t1 values (5); insert into t2 values (5); insert into t3 values (5,5); show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 5 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 5 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 5 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 5 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 5 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 5 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL delete from t1 where a=3; delete from t2 where b=3; delete from t3 where a=3; show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 4 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 4 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 4 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 4 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 4 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 4 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL delete from t1; delete from t2; delete from t3; show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 0 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 0 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 0 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 0 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 0 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 0 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL insert into t1 values (5); insert into t2 values (5); insert into t3 values (5,5); show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 1 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 1 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 1 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 1 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 1 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 1 # # # # 0 NULL NULL NULL NULL latin1_swedish_ci NULL delete from t1 where a=5; delete from t2 where b=5; delete from t3 where a=5; show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MEMORY 9 Fixed 0 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL -t2 MEMORY 9 Fixed 0 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL -t3 MEMORY 9 Fixed 0 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL +t1 MEMORY 10 Fixed 0 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 0 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL +t3 MEMORY 10 Fixed 0 # # # # # NULL NULL NULL NULL latin1_swedish_ci NULL drop table t1, t2, t3; create database mysqltest; show create database mysqltest; diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 75459bd960b..ae1bb42cc29 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -149,7 +149,7 @@ v5 VIEW v6 VIEW show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 9 Fixed 5 9 45 38654705663 1024 0 NULL # # NULL latin1_swedish_ci NULL +t1 MyISAM 10 Fixed 5 9 45 38654705663 1024 0 NULL # # NULL latin1_swedish_ci NULL v1 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL view v2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL view v3 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL # # NULL NULL NULL NULL view @@ -1115,7 +1115,7 @@ select * from v1; ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) show table status; Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment -t1 MyISAM 9 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL +t1 MyISAM 10 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL v1 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # NULL NULL NULL NULL View 'test.v1' references invalid table(s) or column(s) or function(s) drop view v1; drop table t1; diff --git a/scripts/fill_func_tables.sh b/scripts/fill_func_tables.sh index 459afee2fe1..203c730dd9a 100644 --- a/scripts/fill_func_tables.sh +++ b/scripts/fill_func_tables.sh @@ -131,8 +131,8 @@ print "USE mysql_help;\n"; print "DROP TABLE IF EXISTS function;\n"; print "CREATE TABLE function ("; print " func_id int unsigned not null auto_increment,"; -print " name varchar(64) not null,"; -print " url varchar(128) not null,"; +print " name char(64) not null,"; +print " url char(128) not null,"; print " description text not null,"; print " example text not null,"; print " min_args tinyint not null,"; @@ -145,8 +145,8 @@ print ") type=myisam;\n\n"; print "DROP TABLE IF EXISTS function_category_name;\n"; print "CREATE TABLE function_category_name ("; print " cat_id smallint unsigned not null auto_increment,"; -print " name varchar(64) not null,"; -print " url varchar(128) not null,"; +print " name char(64) not null,"; +print " url char(128) not null,"; print " date_created datetime not null,"; print " last_modified timestamp not null,"; print " primary key (cat_id)"; diff --git a/scripts/mysql_create_system_tables.sh b/scripts/mysql_create_system_tables.sh index 29f6f7b41e1..bb4c2f08193 100644 --- a/scripts/mysql_create_system_tables.sh +++ b/scripts/mysql_create_system_tables.sh @@ -270,11 +270,11 @@ then c_ht="$c_ht CREATE TABLE help_topic (" c_ht="$c_ht help_topic_id int unsigned not null," - c_ht="$c_ht name varchar(64) not null," + c_ht="$c_ht name char(64) not null," c_ht="$c_ht help_category_id smallint unsigned not null," c_ht="$c_ht description text not null," c_ht="$c_ht example text not null," - c_ht="$c_ht url varchar(128) not null," + c_ht="$c_ht url char(128) not null," c_ht="$c_ht primary key (help_topic_id)," c_ht="$c_ht unique index (name)" c_ht="$c_ht ) engine=MyISAM" @@ -292,9 +292,9 @@ then c_hc="$c_hc CREATE TABLE help_category (" c_hc="$c_hc help_category_id smallint unsigned not null," - c_hc="$c_hc name varchar(64) not null," + c_hc="$c_hc name char(64) not null," c_hc="$c_hc parent_category_id smallint unsigned null," - c_hc="$c_hc url varchar(128) not null," + c_hc="$c_hc url char(128) not null," c_hc="$c_hc primary key (help_category_id)," c_hc="$c_hc unique index (name)" c_hc="$c_hc ) engine=MyISAM" @@ -310,7 +310,7 @@ then c_hk="$c_hk CREATE TABLE help_keyword (" c_hk="$c_hk help_keyword_id int unsigned not null," - c_hk="$c_hk name varchar(64) not null," + c_hk="$c_hk name char(64) not null," c_hk="$c_hk primary key (help_keyword_id)," c_hk="$c_hk unique index (name)" c_hk="$c_hk ) engine=MyISAM" diff --git a/scripts/mysql_fix_privilege_tables.sh b/scripts/mysql_fix_privilege_tables.sh index d5c96532782..d080b68b268 100644 --- a/scripts/mysql_fix_privilege_tables.sh +++ b/scripts/mysql_fix_privilege_tables.sh @@ -13,7 +13,7 @@ args="" port="" socket="" database="mysql" -bindir="." +bindir="" pkgdatadir="@pkgdatadir@" print_defaults_bindir="." diff --git a/scripts/mysql_fix_privilege_tables.sql b/scripts/mysql_fix_privilege_tables.sql index 628b034362d..dee4ebd3d2f 100644 --- a/scripts/mysql_fix_privilege_tables.sql +++ b/scripts/mysql_fix_privilege_tables.sql @@ -319,19 +319,19 @@ KEY Grantor (Grantor) CREATE TABLE IF NOT EXISTS help_topic ( help_topic_id int unsigned not null, -name varchar(64) not null, +name char(64) not null, help_category_id smallint unsigned not null, description text not null, example text not null, -url varchar(128) not null, +url char(128) not null, primary key (help_topic_id), unique index (name) ) CHARACTER SET utf8 comment='help topics'; CREATE TABLE IF NOT EXISTS help_category ( help_category_id smallint unsigned not null, -name varchar(64) not null, +name char(64) not null, parent_category_id smallint unsigned null, -url varchar(128) not null, +url char(128) not null, primary key (help_category_id), unique index (name) ) CHARACTER SET utf8 comment='help categories'; @@ -344,7 +344,7 @@ primary key (help_keyword_id, help_topic_id) CREATE TABLE IF NOT EXISTS help_keyword ( help_keyword_id int unsigned not null, -name varchar(64) not null, +name char(64) not null, primary key (help_keyword_id), unique index (name) ) CHARACTER SET utf8 comment='help keywords'; @@ -491,3 +491,35 @@ ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL, 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE' ) DEFAULT 0 NOT NULL; + +# +# Change all varchar fields in privilege tables to CHAR, to ensure that +# we can use the privilege tables in MySQL 4.1 +# Note that for this hack to work, we must change all CHAR() columns at +# the same time +# + +ALTER TABLE mysql.user +modify Host char(60) binary DEFAULT '' NOT NULL, +modify User char(16) binary DEFAULT '' NOT NULL, +modify Password char(41) binary DEFAULT '' NOT NULL; + +ALTER TABLE mysql.db +modify Host char(60) binary DEFAULT '' NOT NULL, +modify Db char(64) binary DEFAULT '' NOT NULL, +modify User char(16) binary DEFAULT '' NOT NULL; + +ALTER TABLE mysql.host +modify Host char(60) binary DEFAULT '' NOT NULL, +modify Db char(64) binary DEFAULT '' NOT NULL; + +ALTER TABLE help_topic +modify name char(64) not null, +modify url char(128) not null; + +ALTER TABLE help_category +modify name char(64) not null, +modify url char(128) not null; + +ALTER TABLE help_keyword +modify name char(64) not null; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 82d887891cf..b125eeaf03a 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -613,7 +613,7 @@ int prepare_create_field(create_field *sql_field, Prepares the table and key structures for table creation. NOTES - sets create_info->varchar if the table has a varchar or blob. + sets create_info->varchar if the table has a varchar RETURN VALUES 0 ok @@ -862,12 +862,7 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, ×tamps, ×tamps_with_niladic, file->table_flags())) DBUG_RETURN(-1); - if (sql_field->sql_type == FIELD_TYPE_BLOB || - sql_field->sql_type == FIELD_TYPE_MEDIUM_BLOB || - sql_field->sql_type == FIELD_TYPE_TINY_BLOB || - sql_field->sql_type == FIELD_TYPE_LONG_BLOB || - sql_field->sql_type == FIELD_TYPE_GEOMETRY || - sql_field->sql_type == MYSQL_TYPE_VARCHAR) + if (sql_field->sql_type == MYSQL_TYPE_VARCHAR) create_info->varchar= 1; sql_field->offset= pos; if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER) diff --git a/sql/table.cc b/sql/table.cc index 939690395d4..9238d8aa68e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -149,6 +149,15 @@ int openfrm(THD *thd, const char *name, const char *alias, uint db_stat, *fn_ext(index_file)='\0'; // Remove .frm extension share->frm_version= head[2]; + /* + Check if .frm file created by MySQL 5.0. In this case we want to + display CHAR fields as CHAR and not as VARCHAR. + We do it this way as we want to keep the old frm version to enable + MySQL 4.1 to read these files. + */ + if (share->frm_version == FRM_VER_TRUE_VARCHAR -1 && head[33] == 5) + share->frm_version= FRM_VER_TRUE_VARCHAR; + share->db_type= ha_checktype((enum db_type) (uint) *(head+3)); share->db_create_options= db_create_options=uint2korr(head+30); share->db_options_in_use= share->db_create_options; @@ -1317,6 +1326,7 @@ File create_frm(register my_string name, uint reclength, uchar *fileinfo, create_info->table_options|=HA_OPTION_LONG_BLOB_PTR; // Use portable blob pointers int2store(fileinfo+30,create_info->table_options); fileinfo[32]=0; // No filename anymore + fileinfo[33]=5; // Mark for 5.0 frm file int4store(fileinfo+34,create_info->avg_row_length); fileinfo[38]= (create_info->default_table_charset ? create_info->default_table_charset->number : 0);