You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
8.7 KiB

23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
23 years ago
  1. #-----------------------------------------------------------------------------
  2. # Copyright (C) 2002 MySQL AB
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; version 2 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. #-----------------------------------------------------------------------------
  17. #-----------------------------------------------------------------------------
  18. # This notice applies to changes, created by or for Novell, Inc.,
  19. # to preexisting works for which notices appear elsewhere in this file.
  20. # Copyright (c) 2003 Novell, Inc. All Rights Reserved.
  21. # This program is free software; you can redistribute it and/or modify
  22. # it under the terms of the GNU General Public License as published by
  23. # the Free Software Foundation; either version 2 of the License, or
  24. # (at your option) any later version.
  25. # This program is distributed in the hope that it will be useful,
  26. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. # GNU General Public License for more details.
  29. # You should have received a copy of the GNU General Public License
  30. # along with this program; if not, write to the Free Software
  31. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32. #-----------------------------------------------------------------------------
  33. #use strict;
  34. use Mysql;
  35. print "MySQL Fix Privilege Tables Script\n\n";
  36. print "NOTE: This script updates your privilege tables to the lastest\n";
  37. print " specifications!\n\n";
  38. #-----------------------------------------------------------------------------
  39. # get the current root password
  40. #-----------------------------------------------------------------------------
  41. print "In order to log into MySQL to update it, we'll need the current\n";
  42. print "password for the root user. If you've just installed MySQL, and\n";
  43. print "you haven't set the root password yet, the password will be blank,\n";
  44. print "so you should just press enter here.\n\n";
  45. print "Enter the current password for root: ";
  46. my $password = <STDIN>;
  47. chomp $password;
  48. print "\n";
  49. my $conn = Mysql->connect("localhost", "mysql", "root", $password)
  50. || die "Unable to connect to MySQL.";
  51. print "OK, successfully used the password, moving on...\n\n";
  52. #-----------------------------------------------------------------------------
  53. # MySQL 4.0.2
  54. #-----------------------------------------------------------------------------
  55. #-- Detect whether or not we had the Grant_priv column
  56. print "Fixing privileges for old tables...\n";
  57. $conn->query("SET \@hadGrantPriv:=0;");
  58. $conn->query("SELECT \@hadGrantPriv:=1 FROM user WHERE Grant_priv LIKE '%';");
  59. #--- Fix privileges for old tables
  60. $conn->query("UPDATE user SET Grant_priv=File_priv,References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE \@hadGrantPriv = 0;");
  61. $conn->query("UPDATE db SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE \@hadGrantPriv = 0;");
  62. $conn->query("UPDATE host SET References_priv=Create_priv,Index_priv=Create_priv,Alter_priv=Create_priv WHERE \@hadGrantPriv = 0;");
  63. # Detect whether we had Show_db_priv
  64. $conn->query("SET \@hadShowDbPriv:=0;");
  65. $conn->query("SELECT \@hadShowDbPriv:=1 FROM user WHERE Show_db_priv LIKE '%';");
  66. print "Adding new fields used by MySQL 4.0.2 to the privilege tables...\n";
  67. print "NOTE: You can ignore any Duplicate column errors.\n";
  68. $conn->query(" \
  69. ALTER TABLE user \
  70. ADD Show_db_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER alter_priv, \
  71. ADD Super_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Show_db_priv, \
  72. ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Super_priv, \
  73. ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Create_tmp_table_priv, \
  74. ADD Execute_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Lock_tables_priv, \
  75. ADD Repl_slave_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Execute_priv, \
  76. ADD Repl_client_priv enum('N','Y') DEFAULT 'N' NOT NULL AFTER Repl_slave_priv; \
  77. ") && $conn->query(" \
  78. UPDATE user SET show_db_priv=select_priv, super_priv=process_priv, execute_priv=process_priv, create_tmp_table_priv='Y', Lock_tables_priv='Y', Repl_slave_priv=file_priv, Repl_client_priv=file_priv where user<>''AND \@hadShowDbPriv = 0; \
  79. ");
  80. #-- The above statement converts privileges so that users have similar privileges as before
  81. #-----------------------------------------------------------------------------
  82. # MySQL 4.0 Limitations
  83. #-----------------------------------------------------------------------------
  84. print "Adding new fields used by MySQL 4.0 security limitations...\n";
  85. $conn->query(" \
  86. ALTER TABLE user \
  87. ADD max_questions int(11) NOT NULL AFTER x509_subject, \
  88. ADD max_updates int(11) unsigned NOT NULL AFTER max_questions, \
  89. ADD max_connections int(11) unsigned NOT NULL AFTER max_updates; \
  90. ");
  91. #-- Change the password column to suite the new password hashing used
  92. #-- in 4.1.1 onward
  93. $conn->query("ALTER TABLE user change Password Password char(41) binary not null;");
  94. #-- The second alter changes ssl_type to new 4.0.2 format
  95. #-- Adding columns needed by GRANT .. REQUIRE (openssl)"
  96. print "Adding new fields to use in ssl authentication...\n";
  97. $conn->query(" \
  98. ALTER TABLE user \
  99. ADD ssl_type enum('','ANY','X509', 'SPECIFIED') NOT NULL, \
  100. ADD ssl_cipher BLOB NOT NULL, \
  101. ADD x509_issuer BLOB NOT NULL, \
  102. ADD x509_subject BLOB NOT NULL; \
  103. ");
  104. #-----------------------------------------------------------------------------
  105. # MySQL 4.0 DB and Host privs
  106. #-----------------------------------------------------------------------------
  107. print "Adding new fields used by MySQL 4.0 locking and temporary table security...\n";
  108. $conn->query(" \
  109. ALTER TABLE db \
  110. ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL, \
  111. ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL; \
  112. ");
  113. $conn->query(" \
  114. ALTER TABLE host \
  115. ADD Create_tmp_table_priv enum('N','Y') DEFAULT 'N' NOT NULL, \
  116. ADD Lock_tables_priv enum('N','Y') DEFAULT 'N' NOT NULL; \
  117. ");
  118. #
  119. # Change the Table_name column to be of char(64) which was char(60) by mistake till now.
  120. #
  121. $conn->query("alter table tables_priv change Table_name Table_name char(64) binary DEFAULT '' NOT NULL;");
  122. #
  123. # Create some possible missing tables
  124. #
  125. print "Adding online help tables...\n";
  126. $conn->query(" \
  127. CREATE TABLE IF NOT EXISTS help_topic ( \
  128. help_topic_id int unsigned not null, \
  129. name varchar(64) not null, \
  130. help_category_id smallint unsigned not null, \
  131. description text not null, \
  132. example text not null, \
  133. url varchar(128) not null, \
  134. primary key (help_topic_id), unique index (name) \
  135. ) comment='help topics'; \
  136. ");
  137. $conn->query(" \
  138. CREATE TABLE IF NOT EXISTS help_category ( \
  139. help_category_id smallint unsigned not null, \
  140. name varchar(64) not null, \
  141. parent_category_id smallint unsigned null, \
  142. url varchar(128) not null, \
  143. primary key (help_category_id), \
  144. unique index (name) \
  145. ) comment='help categories'; \
  146. ");
  147. $conn->query(" \
  148. CREATE TABLE IF NOT EXISTS help_relation ( \
  149. help_topic_id int unsigned not null references help_topic, \
  150. help_keyword_id int unsigned not null references help_keyword, \
  151. primary key (help_keyword_id, help_topic_id) \
  152. ) comment='keyword-topic relation'; \
  153. ");
  154. $conn->query(" \
  155. CREATE TABLE IF NOT EXISTS help_keyword ( \
  156. help_keyword_id int unsigned not null, \
  157. name varchar(64) not null, \
  158. primary key (help_keyword_id), \
  159. unique index (name) \
  160. ) comment='help keywords'; \
  161. ");
  162. #
  163. # Filling the help tables with contents.
  164. #
  165. print "Filling online help tables with contents...\n";
  166. # Generate the path for "fill_help_tables.sql" file which is in different folder.
  167. $fill_help_table=$0;
  168. $fill_help_table =~ s/scripts[\\\/]mysql_fix_privilege_tables.pl/share\\fill_help_tables.sql/;
  169. #read all content from the sql file which contains recordsfor help tables.
  170. open(fileIN,$fill_help_table) or die("Cannot open $fill_help_table: $!");
  171. @logData = <fileIN>;
  172. close(fileIN);
  173. foreach $line (@logData) {
  174. # if the line is not empty, insert a record in the table.
  175. if( ! ($line =~ /^\s*$/) ) {
  176. $conn->query("$line");
  177. }
  178. }
  179. #-----------------------------------------------------------------------------
  180. # done
  181. #-----------------------------------------------------------------------------
  182. print "\n\nAll done!\n\n";
  183. print "Thanks for using MySQL!\n\n";