Commit d4d29edb authored by unknown's avatar unknown
Browse files

Fix for BUG#15110: mysqldump --triggers: does not include DEFINER clause

There are two main idea of this fix:
  - introduce a common function for server and client to split user value
    (<user name>@<host name>) into user name and host name parts;
  - dump DEFINER clause in correct format in mysqldump.


BitKeeper/etc/ignore:
  added client/my_user.c libmysqld/my_user.c sql/my_user.c
client/Makefile.am:
  Use my_user.c in linking of mysqldump executable.
client/mysqldump.c:
  Fix for BUG#15110(mysqldump --triggers: does not include DEFINER clause)
include/Makefile.am:
  Add my_user.c
include/mysql_com.h:
  Introduce a constant for max user length.
libmysqld/Makefile.am:
  Add my_user.c
mysql-test/r/mysqldump.result:
  Update result file.
sql-common/Makefile.am:
  Add my_user.c
sql/Makefile.am:
  Add my_user.c
sql/sp.cc:
  Use constant for max user length.
sql/sp_head.cc:
  Use common function to parse user value.
sql/sql_acl.cc:
  Use constant for max user length.
sql/sql_parse.cc:
  Use constant for max user length.
sql/sql_show.cc:
  Use constant for max user length.
sql/sql_trigger.cc:
  Use constant for max user length.
include/my_user.h:
  A header file for parse_user().
sql-common/my_user.c:
  A new file for parse_user() implementation.
parent ffc206d9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1269,3 +1269,6 @@ vio/viotest.cpp
zlib/*.ds?
zlib/*.vcproj
libmysqld/ha_blackhole.cc
client/my_user.c
libmysqld/my_user.c
sql/my_user.c
+5 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ mysqltestmanager_pwgen_SOURCES = mysqlmanager-pwgen.c
mysqltestmanagerc_SOURCES=      mysqlmanagerc.c $(yassl_dummy_link_fix)
mysqlcheck_SOURCES=             mysqlcheck.c $(yassl_dummy_link_fix)
mysqlshow_SOURCES=              mysqlshow.c $(yassl_dummy_link_fix)
mysqldump_SOURCES=              mysqldump.c $(yassl_dummy_link_fix)
mysqldump_SOURCES=              mysqldump.c my_user.c $(yassl_dummy_link_fix)
mysqlimport_SOURCES=            mysqlimport.c $(yassl_dummy_link_fix)
sql_src=log_event.h mysql_priv.h log_event.cc my_decimal.h my_decimal.cc
strings_src=decimal.c
@@ -62,7 +62,10 @@ link_sources:
        for f in $(strings_src) ; do \
          rm -f $(srcdir)/$$f; \
          @LN_CP_F@ $(top_srcdir)/strings/$$f $$f; \
         done;
         done; \
         rm -f $(srcdir)/my_user.c; \
         @LN_CP_F@ $(top_srcdir)/sql-common/my_user.c my_user.c;
	

# Don't update the files from bitkeeper
%::SCCS/s.%
+32 −3
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@

#include <my_global.h>
#include <my_sys.h>
#include <my_user.h>
#include <m_string.h>
#include <m_ctype.h>
#include <hash.h>
@@ -1840,9 +1841,37 @@ static void dump_triggers_for_table (char *table, char *db)
DELIMITER ;;\n");
  while ((row= mysql_fetch_row(result)))
  {
    fprintf(sql_file, "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n\
/*!50003 CREATE TRIGGER %s %s %s ON %s FOR EACH ROW%s%s */;;\n\n",
            row[6], /* sql_mode */
    fprintf(sql_file,
            "/*!50003 SET SESSION SQL_MODE=\"%s\" */;;\n"
            "/*!50003 CREATE */ ",
            row[6] /* sql_mode */);

    if (mysql_num_fields(result) > 7)
    {
      /*
        mysqldump can be run against the server, that does not support definer
        in triggers (there is no DEFINER column in SHOW TRIGGERS output). So,
        we should check if we have this column before accessing it.
      */

      uint       user_name_len;
      char       user_name_str[USERNAME_LENGTH + 1];
      char       quoted_user_name_str[USERNAME_LENGTH * 2 + 3];
      uint       host_name_len;
      char       host_name_str[HOSTNAME_LENGTH + 1];
      char       quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3];
    
      parse_user(row[7], strlen(row[7]), user_name_str, &user_name_len,
                 host_name_str, &host_name_len);

      fprintf(sql_file,
              "/*!50017 DEFINER=%s@%s */ ",
              quote_name(user_name_str, quoted_user_name_str, FALSE),
              quote_name(host_name_str, quoted_host_name_str, FALSE));
    }

    fprintf(sql_file,
            "/*!50003 TRIGGER %s %s %s ON %s FOR EACH ROW%s%s */;;\n\n",
            quote_name(row[0], name_buff, 0), /* Trigger */
            row[4], /* Timing */
            row[1], /* Event */
+2 −1
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ noinst_HEADERS = config-win.h config-os2.h config-netware.h \
			my_nosys.h my_alarm.h queues.h rijndael.h sha1.h \
			my_aes.h my_tree.h hash.h thr_alarm.h \
			thr_lock.h t_ctype.h violite.h md5.h base64.h \
			mysql_version.h.in my_handler.h my_time.h decimal.h
			mysql_version.h.in my_handler.h my_time.h decimal.h \
			my_user.h

# mysql_version.h are generated
CLEANFILES =            mysql_version.h my_config.h readline openssl

include/my_user.h

0 → 100644
+35 −0
Original line number Diff line number Diff line
/* Copyright (C) 2005 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; either version 2 of the License, or
 (at your option) any later version.

 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 */

/*
  This is a header for libraries containing functions used in both server and
  only some of clients (but not in libmysql)...
*/

#ifndef _my_user_h_
#define _my_user_h_

#include <my_global.h>

C_MODE_START

void parse_user(const char *user_id_str, uint user_id_len,
                char *user_name_str, uint *user_name_len,
                char *host_name_str, uint *host_name_len);

C_MODE_END

#endif /* _my_user_h_ */
Loading