Bug#25452 mysql_upgrade access denied

 - Improve mysql_upgrade and add comments describing it's logic
 - Don't look for mysql and mysqlcheck randomly, use dir where mysql_upgrade
  was started from
 - Don't look for mysql_fix_privilege_tables.sql randomly, compile
  in the mysql_fix_privilege_tables.sql file and use that to upgrade
  the system tables of MySQL
 - Check for any unexpected error returned from runnning the mysql_fix_privilege_tables SQL
 - Fix bug#26639, bug#24248 and bug#25405
parent 1c5c12ac
......@@ -1337,3 +1337,5 @@ win/vs71cache.txt
win/vs8cache.txt
zlib/*.ds?
zlib/*.vcproj
scripts/comp_sql
scripts/mysql_fix_privilege_tables_sql.c
......@@ -128,6 +128,7 @@ ADD_SUBDIRECTORY(dbug)
ADD_SUBDIRECTORY(strings)
ADD_SUBDIRECTORY(regex)
ADD_SUBDIRECTORY(mysys)
ADD_SUBDIRECTORY(scripts)
ADD_SUBDIRECTORY(extra/yassl)
ADD_SUBDIRECTORY(extra/yassl/taocrypt)
ADD_SUBDIRECTORY(extra)
......
......@@ -21,9 +21,9 @@ AUTOMAKE_OPTIONS = foreign
EXTRA_DIST = INSTALL-SOURCE INSTALL-WIN-SOURCE \
README COPYING EXCEPTIONS-CLIENT CMakeLists.txt
SUBDIRS = . include @docs_dirs@ @zlib_dir@ @yassl_dir@ \
@readline_topdir@ sql-common \
@readline_topdir@ sql-common scripts \
@thread_dirs@ pstack \
@sql_union_dirs@ scripts @man_dirs@ tests \
@sql_union_dirs@ @man_dirs@ tests \
netware @libmysqld_dirs@ \
@bench_dirs@ support-files @tools_dirs@
......
This diff is collapsed.
......@@ -86,6 +86,14 @@
#endif
#endif /* _WIN32... */
/* Make it easier to add conditionl code for windows */
#ifdef __WIN__
#define IF_WIN(A,B) (A)
#else
#define IF_WIN(A,B) (B)
#endif
/* Some defines to avoid ifdefs in the code */
#ifndef NETWARE_YIELD
#define NETWARE_YIELD
......
set autocommit=1;
reset master;
create table bug16206 (a int);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
show binlog events;
Log_name Pos Event_type Server_id End_log_pos Info
f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4
f n Query 1 n use `test`; create table bug16206 (a int)
f n Query 1 n use `test`; insert into bug16206 values(1)
f n Query 1 n use `test`; insert into bug16206 values(2)
drop table bug16206;
reset master;
create table bug16206 (a int) engine= bdb;
insert into bug16206 values(0);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
insert into bug16206 values(3);
show binlog events;
Log_name Pos Event_type Server_id End_log_pos Info
f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4
f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb
f n Query 1 n use `test`; insert into bug16206 values(0)
f n Query 1 n use `test`; insert into bug16206 values(1)
f n Query 1 n use `test`; BEGIN
f n Query 1 n use `test`; insert into bug16206 values(2)
f n Query 1 n use `test`; COMMIT
f n Query 1 n use `test`; insert into bug16206 values(3)
drop table bug16206;
set autocommit=0;
End of 5.0 tests
......@@ -16,48 +16,9 @@ mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
@hadGrantPriv:=1
1
1
1
@hadShowDbPriv:=1
1
1
1
@hadCreateViewPriv:=1
1
1
1
@hadCreateRoutinePriv:=1
1
1
1
@hadCreateUserPriv:=1
1
1
1
Run it again - should say already completed
@hadGrantPriv:=1
1
1
1
@hadShowDbPriv:=1
1
1
1
@hadCreateViewPriv:=1
1
1
1
@hadCreateRoutinePriv:=1
1
1
1
@hadCreateUserPriv:=1
1
1
1
Force should run it regardless of wheter it's been run before
This installation of MySQL is already upgraded to VERSION, use --force if you still need to run mysql_upgrade
Force should run it regardless of wether it's been run before
mysql.columns_priv OK
mysql.db OK
mysql.func OK
......@@ -75,23 +36,27 @@ mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
@hadGrantPriv:=1
1
1
1
@hadShowDbPriv:=1
1
1
1
@hadCreateViewPriv:=1
1
1
1
@hadCreateRoutinePriv:=1
1
1
1
@hadCreateUserPriv:=1
1
1
1
CREATE USER mysqltest1@'%' IDENTIFIED by 'sakila';
GRANT ALL ON *.* TO mysqltest1@'%';
Run mysql_upgrade with password protected account
mysql.columns_priv OK
mysql.db OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.proc OK
mysql.procs_priv OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
DROP USER mysqltest1@'%';
Run mysql_upgrade with a non existing server socket
mysqlcheck: Got error: 2002: Can't connect to local MySQL server through socket 'var/tmp/no_sock_here' (2) when trying to connect
FATAL ERROR: Upgrade failed
-- source include/not_embedded.inc
-- source include/have_bdb.inc
#
# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode
#
set autocommit=1;
let $VERSION=`select version()`;
reset master;
create table bug16206 (a int);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
--replace_result $VERSION VERSION
--replace_column 1 f 2 n 5 n
show binlog events;
drop table bug16206;
reset master;
create table bug16206 (a int) engine= bdb;
insert into bug16206 values(0);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
insert into bug16206 values(3);
--replace_result $VERSION VERSION
--replace_column 1 f 2 n 5 n
show binlog events;
drop table bug16206;
set autocommit=0;
--echo End of 5.0 tests
......@@ -7,17 +7,55 @@
select LENGTH("$MYSQL_UPGRADE")>0 as have_mysql_upgrade;
--enable_query_log
# Get version of the server so it can be masked out in the
# error messages from mysql_upgrade
let $VERSION=`select LEFT(version(), 6)`;
#
# Basic test thta we can run mysql_upgrde and that it finds the
# Basic test that we can run mysql_upgrde and that it finds the
# expected binaries it uses.
#
--echo Run mysql_upgrade once
--exec $MYSQL_UPGRADE 2> $MYSQLTEST_VARDIR/log/mysql_upgrade.err
--exec $MYSQL_UPGRADE --skip-verbose 2>&1
# It should have created a file in the MySQL Servers datadir
file_exists $MYSQLTEST_VARDIR/master-data/mysql_upgrade_info;
--echo Run it again - should say already completed
--exec $MYSQL_UPGRADE 2> $MYSQLTEST_VARDIR/log/mysql_upgrade.err
--replace_result $VERSION VERSION
--error 1
--exec $MYSQL_UPGRADE --skip-verbose 2>&1
# It should have created a file in the MySQL Servers datadir
file_exists $MYSQLTEST_VARDIR/master-data/mysql_upgrade_info;
--echo Force should run it regardless of wether it's been run before
--exec $MYSQL_UPGRADE --skip-verbose --force 2>&1
# It should have created a file in the MySQL Servers datadir
file_exists $MYSQLTEST_VARDIR/master-data/mysql_upgrade_info;
#
# Bug #25452 mysql_upgrade access denied.
#
# Password protect a root account and run mysql_upgrade
CREATE USER mysqltest1@'%' IDENTIFIED by 'sakila';
GRANT ALL ON *.* TO mysqltest1@'%';
--echo Run mysql_upgrade with password protected account
--exec $MYSQL_UPGRADE --skip-verbose --force --user=mysqltest1 --password=sakila 2>&1
--echo Force should run it regardless of wheter it's been run before
--exec $MYSQL_UPGRADE --force 2> $MYSQLTEST_VARDIR/log/mysql_upgrade.err
DROP USER mysqltest1@'%';
#
# Bug #26639 mysql_upgrade exits successfully even if external command failed
#
--echo Run mysql_upgrade with a non existing server socket
--replace_result $MYSQLTEST_VARDIR var
--replace_regex /.*mysqlcheck.*: Got/mysqlcheck: Got/
--error 1
--exec $MYSQL_UPGRADE --skip-verbose --force --socket=$MYSQLTEST_VARDIR/tmp/no_sock_here 2>&1
# Copyright (C) 2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
ADD_EXECUTABLE(comp_sql comp_sql.c)
TARGET_LINK_LIBRARIES(comp_sql dbug mysys strings)
# Build comp_sql - used for embedding SQL in C or C++ programs
GET_TARGET_PROPERTY(COMP_SQL_EXE comp_sql LOCATION)
ADD_CUSTOM_COMMAND(OUTPUT ${PROJECT_SOURCE_DIR}/client/mysql_fix_privilege_tables_sql.c
COMMAND ${COMP_SQL_EXE}
${PROJECT_SOURCE_DIR}/scripts/mysql_fix_privilege_tables.sql
${PROJECT_SOURCE_DIR}/client/mysql_fix_privilege_tables_sql.c
DEPENDS comp_sql ${PROJECT_SOURCE_DIR}/scripts/mysql_fix_privilege_tables.sql)
......@@ -165,5 +165,19 @@ SUFFIXES = .sh
@CHMOD@ +x $@-t
@MV@ $@-t $@
BUILT_SOURCES = mysql_fix_privilege_tables_sql.c
noinst_PROGRAMS = comp_sql
#
# Build mysql_fix_privilege_tables_sql.c from
# mysql_fix_privileges_tables.sql using comp_sql
#
mysql_fix_privilege_tables_sql.c: comp_sql.c mysql_fix_privilege_tables.sql
$(MAKE) $(AM_MAKEFLAGS) comp_sql$(EXEEXT)
$(top_builddir)/scripts/comp_sql$(EXEEXT) \
mysql_fix_privilege_tables.sql $@
# Don't update the files from bitkeeper
%::SCCS/s.%
/* Copyright (C) 2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Written by Magnus Svensson
*/
/*
Converts a SQL file into a C file that can be compiled and linked
into other programs
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
FILE *in, *out;
static void die(const char *fmt, ...)
{
va_list args;
/* Print the error message */
fprintf(stderr, "FATAL ERROR: ");
if (fmt)
{
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
else
fprintf(stderr, "unknown error");
fprintf(stderr, "\n");
fflush(stderr);
/* Close any open files */
if (in)
fclose(in);
if (out)
fclose(out);
exit(1);
}
int main(int argc, char *argv[])
{
char buff[512];
char* infile_name= argv[1];
char* outfile_name= argv[2];
char* end= infile_name;
if (argc != 3)
die("Usage: comp_sql <sql_filename> <c_filename>");
/* Open input and output file */
if (!(in= fopen(infile_name, "r")))
die("Failed to open SQL file '%s'", infile_name);
if (!(out= fopen(outfile_name, "w")))
die("Failed to open output file '%s'", outfile_name);
while(*end && *end != '.')
end++;
*end= 0;
fprintf(out, "const char* %s={\"\\\n", infile_name);
while (fgets(buff, sizeof(buff), in))
{
char *curr= buff;
while (*curr)
{
if (*curr == '\n')
{
/*
Reached end of line, add escaped newline, escaped
backslash and a newline to outfile
*/
fprintf(out, "\\n\\\n");
curr++;
}
else if (*curr == '\r')
{
curr++; /* Skip */
}
else
{
if (*curr == '"')
{
/* Needs escape */
fputc('\\', out);
}
fputc(*curr, out);
curr++;
}
}
}
fprintf(out, "\\\n\"};\n");
fclose(in);
fclose(out);
exit(0);
}
......@@ -268,7 +268,6 @@ MY_LOCALE *my_locale_by_number(uint number);
#endif
#if defined(__WIN__) || defined(OS2)
#define IF_WIN(A,B) (A)
#undef FLUSH_TIME
#define FLUSH_TIME 1800 /* Flush every half hour */
......@@ -277,7 +276,6 @@ MY_LOCALE *my_locale_by_number(uint number);
#define WAIT_PRIOR 0
#define QUERY_PRIOR 2
#else
#define IF_WIN(A,B) (B)
#define INTERRUPT_PRIOR 10
#define CONNECT_PRIOR 9
#define WAIT_PRIOR 8
......
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