List:Internals« Previous MessageNext Message »
From:sanja Date:September 13 2005 2:44pm
Subject:bk commit into 5.0 tree (bell:1.1966)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of bell. When bell does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1966 05/09/13 15:44:48 bell@stripped +23 -0
  part 1 (ver 2, postreview fix) of WL#2787
  view definer information syntax/storage/replication
  fixed SOURCE field of .frm

  sql/table.h
    1.112 05/09/13 15:44:44 bell@stripped +4 -0
    definer information storage

  sql/sql_yacc.yy
    1.420 05/09/13 15:44:43 bell@stripped +67 -7
    definer information sintax support
    getting SOURCE field information for .frm 

  sql/sql_view.cc
    1.62 05/09/13 15:44:43 bell@stripped +88 -15
    check of definer clause
    changes in .frm file
    definer information storage support
    now we store only original SELECT in SOURCE field of .frm

  sql/sql_show.cc
    1.276 05/09/13 15:44:43 bell@stripped +30 -16
    new CREATE VIEW options printed

  sql/sql_parse.cc
    1.484 05/09/13 15:44:43 bell@stripped +55 -1
    send CREATE/ALTER VIEW for replication with full list of options
    set current user as definer procedure

  sql/sql_lex.h
    1.196 05/09/13 15:44:43 bell@stripped +6 -0
    storing definer information

  sql/sql_acl.h
    1.46 05/09/13 15:44:43 bell@stripped +1 -1
    make find_acl_user public to allow to check user

  sql/sql_acl.cc
    1.168 05/09/13 15:44:43 bell@stripped +23 -0
    make find_acl_user public to allow to check user

  sql/share/errmsg.txt
    1.43 05/09/13 15:44:43 bell@stripped +8 -0
    new errors/warnings

  sql/mysql_priv.h
    1.349 05/09/13 15:44:43 bell@stripped +6 -0
    CREATE/ALTER VIEW print support
    set current user as definer procedure

  mysql-test/t/view_grant.test
    1.4 05/09/13 15:44:43 bell@stripped +5 -0
    test of grant check of definer information

  mysql-test/t/view.test
    1.105 05/09/13 15:44:43 bell@stripped +9 -0
    test of storing/restoring definer information

  mysql-test/t/skip_grants.test
    1.4 05/09/13 15:44:43 bell@stripped +1 -2
    --skip-grants do not allow use user information

  mysql-test/t/rpl_view.test
    1.2 05/09/13 15:44:43 bell@stripped +3 -0
    check log of queries

  mysql-test/r/view_grant.result
    1.4 05/09/13 15:44:43 bell@stripped +9 -4
    test of grant check of definer information
    definer information added to CREATE VIEW

  mysql-test/r/view.result
    1.110 05/09/13 15:44:43 bell@stripped +30 -21
    definer information added to CREATE VIEW
    test of storing/restoring definer information

  mysql-test/r/temp_table.result
    1.15 05/09/13 15:44:43 bell@stripped +1 -1
    definer information added to CREATE VIEW

  mysql-test/r/sql_mode.result
    1.26 05/09/13 15:44:43 bell@stripped +2 -2
    definer information added to CREATE VIEW

  mysql-test/r/skip_grants.result
    1.4 05/09/13 15:44:43 bell@stripped +1 -1
    --skip-grants do not allow use user information

  mysql-test/r/rpl_view.result
    1.2 05/09/13 15:44:42 bell@stripped +13 -0
    check log of queries

  mysql-test/r/mysqldump.result
    1.66 05/09/13 15:44:42 bell@stripped +3 -3
    definer information added to CREATE VIEW

  mysql-test/r/lowercase_view.result
    1.9 05/09/13 15:44:42 bell@stripped +3 -3
    definer information added to CREATE VIEW

  mysql-test/r/func_in.result
    1.19 05/09/13 15:44:42 bell@stripped +1 -1
    definer information added to CREATE VIEW

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	bell
# Host:	sanja.is.com.ua
# Root:	/home/bell/mysql/bk/work-owner-5.0

--- 1.348/sql/mysql_priv.h	2005-09-06 20:51:07 +03:00
+++ 1.349/sql/mysql_priv.h	2005-09-13 15:44:43 +03:00
@@ -379,6 +379,10 @@
 #define SHOW_LOG_STATUS_FREE "FREE"
 #define SHOW_LOG_STATUS_INUSE "IN USE"
 
+struct st_table_list;
+class String;
+void view_store_options(THD *thd, st_table_list *table, String *buff);
+
 /* Options to add_table_to_list() */
 #define TL_OPTION_UPDATING	1
 #define TL_OPTION_FORCE_INDEX	2
@@ -511,6 +515,8 @@
 bool insert_precheck(THD *thd, TABLE_LIST *tables);
 bool create_table_precheck(THD *thd, TABLE_LIST *tables,
                            TABLE_LIST *create_table);
+bool default_view_definer(THD *thd, st_lex_user *definer);
+
 
 enum enum_mysql_completiontype {
   ROLLBACK_RELEASE=-2, ROLLBACK=1,  ROLLBACK_AND_CHAIN=7,

--- 1.167/sql/sql_acl.cc	2005-09-02 00:01:25 +03:00
+++ 1.168/sql/sql_acl.cc	2005-09-13 15:44:43 +03:00
@@ -1457,6 +1457,29 @@
 
 
 /*
+  Find user in ACL
+
+  SYNOPSIS
+    is_acl_user()
+    host                 host name
+    user                 user name
+
+  RETURN
+   FALSE  user not fond
+   TRUE   there are such user
+*/
+
+bool is_acl_user(const char *host, const char *user)
+{
+  bool res;
+  VOID(pthread_mutex_lock(&acl_cache->lock));
+  res= find_acl_user(host, user, TRUE);
+  VOID(pthread_mutex_unlock(&acl_cache->lock));
+  return res;
+}
+
+
+/*
   Find first entry that matches the current user
 */
 

--- 1.45/sql/sql_acl.h	2005-09-01 21:25:13 +03:00
+++ 1.46/sql/sql_acl.h	2005-09-13 15:44:43 +03:00
@@ -229,7 +229,7 @@
                          bool is_proc);
 bool check_routine_level_acl(THD *thd, const char *db, const char *name,
                              bool is_proc);
-
+bool is_acl_user(const char *host, const char *user);
 #ifdef NO_EMBEDDED_ACCESS_CHECKS
 #define check_grant(A,B,C,D,E,F) 0
 #define check_grant_db(A,B) 0

--- 1.195/sql/sql_lex.h	2005-09-03 02:13:10 +03:00
+++ 1.196/sql/sql_lex.h	2005-09-13 15:44:43 +03:00
@@ -733,6 +733,8 @@
   TABLE_LIST **query_tables_last;
   /* store original leaf_tables for INSERT SELECT and PS/SP */
   TABLE_LIST *leaf_tables_insert;
+  st_lex_user *create_view_definer;
+  char *create_view_select_start;
 
   List<key_part_spec> col_list;
   List<key_part_spec> ref_list;
@@ -853,6 +855,10 @@
     rexecuton
   */
   bool empty_field_list_on_rset;
+  /*
+    view created to be run from definer (standard behaviour)
+  */
+  bool create_view_suid;
   /* Characterstics of trigger being created */
   st_trg_chistics trg_chistics;
   /*

--- 1.483/sql/sql_parse.cc	2005-09-11 02:23:01 +03:00
+++ 1.484/sql/sql_parse.cc	2005-09-13 15:44:43 +03:00
@@ -4451,8 +4451,29 @@
       if (!(res= mysql_create_view(thd, thd->lex->create_view_mode)) &&
           mysql_bin_log.is_open())
       {
+        String buff;
+        LEX_STRING command[3]=
+          {{STRING_WITH_LEN("CREATE ")},
+           {STRING_WITH_LEN("ALTER ")},
+           {STRING_WITH_LEN("CREATE OR REPLACE ")}};
         thd->clear_error();
-        Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
+
+        buff.append(command[thd->lex->create_view_mode].str,
+                    command[thd->lex->create_view_mode].length);
+        view_store_options(thd, first_table, &buff);
+        buff.append("VIEW ", 5);
+        if (!first_table->current_db_used)
+        {
+          append_identifier(thd, &buff, first_table->db,
+                            first_table->db_length);
+          buff.append('.');
+        }
+        append_identifier(thd, &buff, first_table->table_name,
+                          first_table->table_name_length);
+        buff.append(" AS ", 4);
+        buff.append(first_table->source.str, first_table->source.length);
+
+        Query_log_event qinfo(thd, buff.ptr(), buff.length(), 0, FALSE);
         mysql_bin_log.write(&qinfo);
       }
       break;
@@ -6009,12 +6030,14 @@
   {
     ptr->db= thd->db;
     ptr->db_length= thd->db_length;
+    ptr->current_db_used= 1;
   }
   else
   {
     /* The following can't be "" as we may do 'casedn_str()' on it */
     ptr->db= empty_c_string;
     ptr->db_length= 0;
+    ptr->current_db_used= 1;
   }
   if (thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
     ptr->db= thd->strdup(ptr->db);
@@ -7293,4 +7316,35 @@
   if ((negated= expr->neg_transformer(thd)) != 0)
     return negated;
   return new Item_func_not(expr);
+}
+
+
+/*
+  Assign as view definer current user
+
+  SYNOPSIS
+    default_definer()
+    thd                  thread handler
+    definer              structure where it should be assigned
+
+  RETURN
+    FALSE   OK
+    TRUE    Error
+*/
+
+bool default_view_definer(THD *thd, st_lex_user *definer)
+{
+  definer->user.str= thd->priv_user;
+  definer->user.length= strlen(thd->priv_user);
+  if (*thd->priv_host != 0)
+  {
+    definer->host.str= thd->priv_host;
+    definer->host.length= strlen(thd->priv_host);
+  }
+  else
+  {
+    my_error(ER_NO_VIEW_USER, MYF(0));
+    return TRUE;
+  }
+  return FALSE;
 }

--- 1.275/sql/sql_show.cc	2005-09-09 14:52:39 +03:00
+++ 1.276/sql/sql_show.cc	2005-09-13 15:44:43 +03:00
@@ -42,7 +42,7 @@
 static int
 store_create_info(THD *thd, TABLE_LIST *table_list, String *packet);
 static int
-view_store_create_info(THD *thd, TABLE_LIST *table, String *packet);
+view_store_create_info(THD *thd, TABLE_LIST *table, String *buff);
 static bool schema_table_store_record(THD *thd, TABLE *table);
 
 
@@ -1045,6 +1045,34 @@
   DBUG_RETURN(0);
 }
 
+void
+view_store_options(THD *thd, TABLE_LIST *table, String *buff)
+{
+  buff->append("ALGORITHM=", 10);
+  switch ((int8)table->algorithm) {
+  case VIEW_ALGORITHM_UNDEFINED:
+    buff->append("UNDEFINED ", 10);
+    break;
+  case VIEW_ALGORITHM_TMPTABLE:
+    buff->append("TEMPTABLE ", 10);
+    break;
+  case VIEW_ALGORITHM_MERGE:
+    buff->append("MERGE ", 6);
+    break;
+  default:
+    DBUG_ASSERT(0); // never should happen
+  }
+  buff->append("DEFINER=", 8);
+  append_identifier(thd, buff,
+                    table->definer.user.str, table->definer.user.length);
+  buff->append('@');
+  append_identifier(thd, buff,
+                    table->definer.host.str, table->definer.host.length);
+  if (table->view_suid)
+    buff->append(" SQL SECURITY DEFINER ", 22);
+  else
+    buff->append(" SQL SECURITY INVOKER ", 22);
+}
 
 static int
 view_store_create_info(THD *thd, TABLE_LIST *table, String *buff)
@@ -1058,21 +1086,7 @@
   buff->append("CREATE ", 7);
   if (!foreign_db_mode)
   {
-    buff->append("ALGORITHM=", 10);
-    switch((int8)table->algorithm)
-    {
-    case VIEW_ALGORITHM_UNDEFINED:
-      buff->append("UNDEFINED ", 10);
-      break;
-    case VIEW_ALGORITHM_TMPTABLE:
-      buff->append("TEMPTABLE ", 10);
-      break;
-    case VIEW_ALGORITHM_MERGE:
-      buff->append("MERGE ", 6);
-      break;
-    default:
-	DBUG_ASSERT(0); // never should happen
-    }
+    view_store_options(thd, table, buff);
   }
   buff->append("VIEW ", 5);
   append_identifier(thd, buff, table->view_db.str, table->view_db.length);

--- 1.419/sql/sql_yacc.yy	2005-09-07 22:44:12 +03:00
+++ 1.420/sql/sql_yacc.yy	2005-09-13 15:44:43 +03:00
@@ -823,10 +823,11 @@
 	precision subselect_start opt_and charset
 	subselect_end select_var_list select_var_list_init help opt_len
 	opt_extended_describe
-        prepare prepare_src execute deallocate 
+        prepare prepare_src execute deallocate
 	statement sp_suid opt_view_list view_list or_replace algorithm
 	sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic xa
         load_data opt_field_or_var_spec fields_or_vars opt_load_data_set_spec
+        view_user view_suid
 END_OF_INPUT
 
 %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt
@@ -1254,16 +1255,16 @@
 	      YYTHD->client_capabilities |= CLIENT_MULTI_QUERIES;
 	    sp->restore_thd_mem_root(YYTHD);
 	  }
-	| CREATE or_replace algorithm VIEW_SYM table_ident
+	| CREATE or_replace algorithm view_user view_suid VIEW_SYM table_ident
 	  {
 	    THD *thd= YYTHD;
 	    LEX *lex= thd->lex;
 	    lex->sql_command= SQLCOM_CREATE_VIEW;
 	    /* first table in list is target VIEW name */
-	    if (!lex->select_lex.add_table_to_list(thd, $5, NULL, 0))
+	    if (!lex->select_lex.add_table_to_list(thd, $7, NULL, 0))
               YYABORT;
 	  }
-	  opt_view_list AS select_init check_option
+	  opt_view_list AS select_view_init check_option
 	  {}
         | CREATE TRIGGER_SYM sp_name trg_action_time trg_event 
           ON table_ident FOR_SYM EACH_SYM ROW_SYM
@@ -3418,16 +3419,16 @@
 	    lex->sql_command= SQLCOM_ALTER_FUNCTION;
 	    lex->spname= $3;
 	  }
-	| ALTER algorithm VIEW_SYM table_ident
+	| ALTER algorithm view_user view_suid VIEW_SYM table_ident
 	  {
 	    THD *thd= YYTHD;
 	    LEX *lex= thd->lex;
 	    lex->sql_command= SQLCOM_CREATE_VIEW;
 	    lex->create_view_mode= VIEW_ALTER;
 	    /* first table in list is target VIEW name */
-	    lex->select_lex.add_table_to_list(thd, $4, NULL, 0);
+	    lex->select_lex.add_table_to_list(thd, $6, NULL, 0);
 	  }
-	  opt_view_list AS select_init check_option
+	  opt_view_list AS select_view_init check_option
 	  {}
 	;
 
@@ -3995,6 +3996,18 @@
 	|
 	'(' select_paren ')' union_opt;
 
+select_view_init:
+        SELECT_SYM remember_name select_init2
+          {
+            Lex->create_view_select_start= $2;
+          }
+        |
+        '(' remember_name select_paren ')' union_opt
+          {
+            Lex->create_view_select_start= $2;
+          }
+        ;
+
 select_paren:
 	SELECT_SYM select_part2
 	  {
@@ -8885,6 +8898,53 @@
 	| ALGORITHM_SYM EQ TEMPTABLE_SYM
 	  { Lex->create_view_algorithm= VIEW_ALGORITHM_TMPTABLE; }
 	;
+
+view_user:
+        /* empty */
+          {
+            THD *thd= YYTHD;
+            if (!(thd->lex->create_view_definer=
+                  (LEX_USER*) thd->alloc(sizeof(st_lex_user))))
+              YYABORT;
+            if (default_view_definer(thd, thd->lex->create_view_definer))
+              YYABORT;
+          }
+        | CURRENT_USER optional_braces
+          {
+            THD *thd= YYTHD;
+            if (!(thd->lex->create_view_definer=
+                  (LEX_USER*) thd->alloc(sizeof(st_lex_user))))
+              YYABORT;
+            if (default_view_definer(thd, thd->lex->create_view_definer))
+              YYABORT;
+          }
+	| DEFINER_SYM EQ ident_or_text '@' ident_or_text
+	  {
+	    THD *thd= YYTHD;
+            st_lex_user *view_user;
+	    if (!(thd->lex->create_view_definer= view_user=
+                  (LEX_USER*) thd->alloc(sizeof(st_lex_user))))
+	      YYABORT;
+	    view_user->user = $3; view_user->host=$5;
+            if (strchr(view_user->host.str, wild_many) ||
+                strchr(view_user->host.str, wild_one))
+            {
+              my_error(ER_NO_VIEW_USER, MYF(0));
+              YYABORT;
+            }
+	  }
+        ;
+
+view_suid:
+        /* empty */
+	  { Lex->create_view_suid= TRUE; }
+        |
+	  SQL_SYM SECURITY_SYM DEFINER_SYM
+	  { Lex->create_view_suid= TRUE; }
+	| SQL_SYM SECURITY_SYM INVOKER_SYM
+	  { Lex->create_view_suid= FALSE; }
+	;
+
 check_option:
         /* empty */
           { Lex->create_view_check= VIEW_CHECK_NONE; }

--- 1.111/sql/table.h	2005-09-01 22:42:22 +03:00
+++ 1.112/sql/table.h	2005-09-13 15:44:44 +03:00
@@ -539,10 +539,12 @@
   LEX_STRING	view_db;		/* saved view database */
   LEX_STRING	view_name;		/* saved view name */
   LEX_STRING	timestamp;		/* GMT time stamp of last operation */
+  st_lex_user   definer;                /* definer of view */
   ulonglong	file_version;		/* version of file's field set */
   ulonglong     updatable_view;         /* VIEW can be updated */
   ulonglong	revision;		/* revision control number */
   ulonglong	algorithm;		/* 0 any, 1 tmp tables , 2 merging */
+  ulonglong     view_suid;              /* view is suid (TRUE dy default) */
   ulonglong     with_check;             /* WITH CHECK OPTION */
   /*
     effective value of WITH CHECK OPTION (differ for temporary table
@@ -578,6 +580,8 @@
   bool          multitable_view;        /* TRUE iff this is multitable view */
   /* view where processed */
   bool          where_processed;
+  /* db part was not defined in table definition */
+  bool          current_db_used;
   /* FRMTYPE_ERROR if any type is acceptable */
   enum frm_type_enum required_type;
   char		timestamp_buffer[20];	/* buffer for timestamp (19+1) */

--- 1.42/sql/share/errmsg.txt	2005-09-03 02:25:41 +03:00
+++ 1.43/sql/share/errmsg.txt	2005-09-13 15:44:43 +03:00
@@ -5403,3 +5403,11 @@
         eng "The definition of table '%-.64s' prevents operation %s on table '%-.64s'."
 ER_PS_NO_RECURSION
         eng "The prepared statement contains a stored routine call that refers to that
same statement. It's not allowed to execute a prepared statement in such a recursive
manner"
+ER_NO_VIEW_USER
+        eng "View definer is not fully qualified"
+ER_VIEW_FRM_NO_USER
+        eng "View %-.64s.%-.64s has not definer information (old table format). Current
user is used as definer. Please recreate view!"
+ER_VIEW_OTHER_USER
+        eng "You need the SUPER privilege for creation view with %-.64s@%-.64s definer"
+ER_NO_SUCH_USER
+        eng "there are not %-.64s@%-.64s registered"

--- 1.8/mysql-test/r/lowercase_view.result	2005-08-02 22:54:44 +03:00
+++ 1.9/mysql-test/r/lowercase_view.result	2005-09-13 15:44:42 +03:00
@@ -7,7 +7,7 @@
 create view ViE as select * from TAb;
 show create table VIe;
 View	Create View
-vie	CREATE ALGORITHM=UNDEFINED VIEW `mysqltest`.`vie` AS select `mysqltest`.`tab`.`Field`
AS `Field` from `mysqltest`.`tab`
+vie	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`mysqltest`.`vie` AS select `mysqltest`.`tab`.`Field` AS `Field` from `mysqltest`.`tab`
 drop database MySQLTest;
 use test;
 create table t1Aa (col1 int);
@@ -119,7 +119,7 @@
 create view v1Aa as select col1 from t1Aa as AaA;
 show create view v1AA;
 View	Create View
-v1aa	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1aa` AS select `aaa`.`col1` AS `col1` from
`test`.`t1aa` `AaA`
+v1aa	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1aa` AS select `aaa`.`col1` AS `col1` from `test`.`t1aa` `AaA`
 drop view v1AA;
 select Aaa.col1 from t1Aa as AaA;
 col1
@@ -128,6 +128,6 @@
 create view v1Aa as select AaA.col1 from t1Aa as AaA;
 show create view v1AA;
 View	Create View
-v1aa	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1aa` AS select `aaa`.`col1` AS `col1` from
`test`.`t1aa` `AaA`
+v1aa	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1aa` AS select `aaa`.`col1` AS `col1` from `test`.`t1aa` `AaA`
 drop view v1AA;
 drop table t1Aa;

--- 1.1/mysql-test/r/rpl_view.result	2005-01-17 01:17:11 +02:00
+++ 1.2/mysql-test/r/rpl_view.result	2005-09-13 15:44:42 +03:00
@@ -6,6 +6,7 @@
 start slave;
 drop table if exists t1,v1;
 drop view if exists t1,v1;
+reset master;
 create table t1 (a int);
 insert into t1 values (1);
 create view v1 as select a from t1;
@@ -42,3 +43,15 @@
 select * from v1 order by a;
 ERROR 42S02: Table 'test.v1' doesn't exist
 drop table t1;
+show binlog events;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Format_desc	2	#	Server ver: 5.0.13-beta-debug-log, Binlog ver: 4
+slave-bin.000001	#	Query	1	#	use `test`; create table t1 (a int)
+slave-bin.000001	#	Query	1	#	use `test`; insert into t1 values (1)
+slave-bin.000001	#	Query	1	#	use `test`; CREATE ALGORITHM=UNDEFINED
DEFINER=root@localhost SQL SECURITY DEFINER VIEW v1 AS select a from t1
+slave-bin.000001	#	Query	1	#	use `test`; insert into v1 values (2)
+slave-bin.000001	#	Query	1	#	use `test`; update v1 set a=3 where a=1
+slave-bin.000001	#	Query	1	#	use `test`; delete from v1 where a=2
+slave-bin.000001	#	Query	1	#	use `test`; ALTER ALGORITHM=UNDEFINED DEFINER=root@localhost
SQL SECURITY DEFINER VIEW v1 AS select a as b from t1
+slave-bin.000001	#	Query	1	#	use `test`; drop view v1
+slave-bin.000001	#	Query	1	#	use `test`; drop table t1

--- 1.109/mysql-test/r/view.result	2005-09-07 21:55:47 +03:00
+++ 1.110/mysql-test/r/view.result	2005-09-13 15:44:43 +03:00
@@ -32,10 +32,10 @@
 11
 show create table v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c`
from `test`.`t1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1`
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c`
from `test`.`t1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1`
 show create view t1;
 ERROR HY000: 'test.t1' is not VIEW
 drop table t1;
@@ -55,7 +55,7 @@
 create algorithm=temptable view v2 (c) as select b+1 from t1;
 show create view v2;
 View	Create View
-v2	CREATE ALGORITHM=TEMPTABLE VIEW `test`.`v2` AS select (`test`.`t1`.`b` + 1) AS `c`
from `test`.`t1`
+v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v2` AS select (`test`.`t1`.`b` + 1) AS `c` from `test`.`t1`
 select c from v2;
 c
 3
@@ -657,7 +657,7 @@
 CREATE VIEW v1 (f1,f2,f3,f4) AS SELECT connection_id(), pi(), current_user(), version();
 SHOW CREATE VIEW v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache connection_id() AS
`f1`,pi() AS `f2`,current_user() AS `f3`,version() AS `f4`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select sql_no_cache connection_id() AS `f1`,pi() AS `f2`,current_user() AS
`f3`,version() AS `f4`
 drop view v1;
 create table t1 (s1 int);
 create table t2 (s2 int);
@@ -691,13 +691,13 @@
 create view v2 as select a from t2 where a in (select a from v1);
 show create view v2;
 View	Create View
-v2	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v2` AS select `test`.`t2`.`a` AS `a` from
`test`.`t2` where `a` in (select `v1`.`a` AS `a` from `test`.`v1`)
+v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v2` AS select `test`.`t2`.`a` AS `a` from `test`.`t2` where `a` in (select
`v1`.`a` AS `a` from `test`.`v1`)
 drop view v2, v1;
 drop table t1, t2;
 CREATE VIEW `v 1` AS select 5 AS `5`;
 show create view `v 1`;
 View	Create View
-v 1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v 1` AS select 5 AS `5`
+v 1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v 1` AS select 5 AS `5`
 drop view `v 1`;
 create database mysqltest;
 create table mysqltest.t1 (a int, b int);
@@ -765,14 +765,14 @@
 1	1
 show create view v3;
 View	Create View
-v3	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v3` AS select `v1`.`col1` AS `a`,`v2`.`col1`
AS `b` from (`test`.`v1` join `test`.`v2`) where (`v1`.`col1` = `v2`.`col1`)
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from (`test`.`v1` join
`test`.`v2`) where (`v1`.`col1` = `v2`.`col1`)
 drop view v3, v2, v1;
 drop table t2, t1;
 create function `f``1` () returns int return 5;
 create view v1 as select test.`f``1` ();
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`f``1`() AS
`test.``f````1`` ()`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select sql_no_cache `test`.`f``1`() AS `test.``f````1`` ()`
 select * from v1;
 test.`f``1` ()
 5
@@ -789,10 +789,10 @@
 create view v2 as select col1 collate latin1_german1_ci from t2;
 show create view v2;
 View	Create View
-v2	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate
latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
+v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate
latin1_german1_ci` from `test`.`t2`
 show create view v2;
 View	Create View
-v2	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v2` AS select (`test`.`t2`.`col1` collate
latin1_german1_ci) AS `col1 collate latin1_german1_ci` from `test`.`t2`
+v2	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v2` AS select (`test`.`t2`.`col1` collate latin1_german1_ci) AS `col1 collate
latin1_german1_ci` from `test`.`t2`
 drop view v2;
 drop table t2;
 create table t1 (a int);
@@ -819,7 +819,7 @@
 create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select
99999999999999999999999999999999999999999999999999999 AS `col1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select 99999999999999999999999999999999999999999999999999999 AS `col1`
 drop view v1;
 create table tü (cü char);
 create view vü as select cü from tü;
@@ -840,7 +840,7 @@
 create view v1 as select cast(1 as char(3));
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select cast(1 as char(3) charset
latin1) AS `cast(1 as char(3))`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select cast(1 as char(3) charset latin1) AS `cast(1 as char(3))`
 select * from v1;
 cast(1 as char(3))
 1
@@ -1157,19 +1157,19 @@
 create view v1 as select * from t1;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`
 alter algorithm=undefined view v1 as select * from t1 with check option;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1` WITH CASCADED CHECK OPTION
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` WITH CASCADED CHECK OPTION
 alter algorithm=merge view v1 as select * from t1 with cascaded check option;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=MERGE VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1` WITH CASCADED CHECK OPTION
+v1	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` WITH CASCADED CHECK OPTION
 alter algorithm=temptable view v1 as select * from t1;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=TEMPTABLE VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1`
+v1	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`
 drop view v1;
 drop table t1;
 create table t1 (s1 int);
@@ -1841,24 +1841,24 @@
 create view v1 as select a,b,t1.a < now() from t1,t2 where t1.a < now();
 SHOW CREATE VIEW v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS
`a`,`test`.`t2`.`b` AS `b`,(`test`.`t1`.`a` < now()) AS `t1.a < now()` from
(`test`.`t1` join `test`.`t2`) where (`test`.`t1`.`a` < now())
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a`,`test`.`t2`.`b` AS
`b`,(`test`.`t1`.`a` < now()) AS `t1.a < now()` from (`test`.`t1` join `test`.`t2`)
where (`test`.`t1`.`a` < now())
 drop view v1;
 drop table t1, t2;
 CREATE TABLE t1 ( a varchar(50) );
 CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = CURRENT_USER();
 SHOW CREATE VIEW v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS
`a` from `test`.`t1` where (`test`.`t1`.`a` = current_user())
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a` from `test`.`t1` where
(`test`.`t1`.`a` = current_user())
 DROP VIEW v1;
 CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = VERSION();
 SHOW CREATE VIEW v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1` where (`test`.`t1`.`a` = version())
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` =
version())
 DROP VIEW v1;
 CREATE VIEW v1 AS SELECT * FROM t1 WHERE a = DATABASE();
 SHOW CREATE VIEW v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS
`a` from `test`.`t1` where (`test`.`t1`.`a` = database())
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select sql_no_cache `test`.`t1`.`a` AS `a` from `test`.`t1` where
(`test`.`t1`.`a` = database())
 DROP VIEW v1;
 DROP TABLE t1;
 CREATE TABLE t1 (col1 time);
@@ -1949,7 +1949,7 @@
 create view v1 as select var_samp(s1) from t1;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select var_samp(`test`.`t1`.`s1`) AS
`var_samp(s1)` from `test`.`t1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select var_samp(`test`.`t1`.`s1`) AS `var_samp(s1)` from `test`.`t1`
 drop view v1;
 drop table t1;
 set sql_mode='strict_all_tables';
@@ -2186,3 +2186,12 @@
 120001a080000542	guser02
 drop view v1, v2;
 drop table t1, t2;
+create definer=some_user@__% sql security invoker view v1 as select 1;
+ERROR HY000: View definer is not fully qualified
+create definer=some_user@localhost sql security invoker view v1 as select 1;
+Warnings:
+Note	1448	there are not some_user@localhost registered
+show create view v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`some_user`@`localhost` SQL SECURITY INVOKER VIEW
`test`.`v1` AS select 1 AS `1`
+drop view v1;

--- 1.3/mysql-test/r/skip_grants.result	2005-05-26 17:44:42 +03:00
+++ 1.4/mysql-test/r/skip_grants.result	2005-09-13 15:44:43 +03:00
@@ -4,7 +4,7 @@
 use test;
 create table t1 (field1 INT);
 CREATE VIEW v1 AS SELECT field1 FROM t1;
-drop view v1;
+ERROR HY000: View definer is not fully qualified
 drop table t1;
 create procedure f1() select 1;
 drop procedure f1;

--- 1.1/mysql-test/t/rpl_view.test	2005-01-17 01:17:11 +02:00
+++ 1.2/mysql-test/t/rpl_view.test	2005-09-13 15:44:43 +03:00
@@ -3,6 +3,7 @@
 drop table if exists t1,v1;
 drop view if exists t1,v1;
 sync_slave_with_master;
+reset master;
 --enable_warnings
 
 #
@@ -42,3 +43,5 @@
 connection master;
 drop table t1;
 sync_slave_with_master;
+--replace_column 2 # 5 #
+show binlog events;

--- 1.104/mysql-test/t/view.test	2005-09-07 21:55:47 +03:00
+++ 1.105/mysql-test/t/view.test	2005-09-13 15:44:43 +03:00
@@ -2059,3 +2059,12 @@
 
 drop view v1, v2;
 drop table t1, t2;
+
+#
+# DEFINER information check
+#
+-- error ER_NO_VIEW_USER
+create definer=some_user@__% sql security invoker view v1 as select 1;
+create definer=some_user@localhost sql security invoker view v1 as select 1;
+show create view v1;
+drop view v1;

--- 1.3/mysql-test/t/skip_grants.test	2005-05-26 17:44:42 +03:00
+++ 1.4/mysql-test/t/skip_grants.test	2005-09-13 15:44:43 +03:00
@@ -9,9 +9,8 @@
 # test that we can create VIEW if privileges check switched off
 #
 create table t1 (field1 INT);
+-- error ER_NO_VIEW_USER
 CREATE VIEW v1 AS SELECT field1 FROM t1;
-
-drop view v1;
 drop table t1;
 
 #

--- 1.61/sql/sql_view.cc	2005-09-02 17:06:10 +03:00
+++ 1.62/sql/sql_view.cc	2005-09-13 15:44:43 +03:00
@@ -210,6 +210,36 @@
 
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   /*
+    check definer of view:
+      - same as current user
+      - current user has SUPER_ACL
+  */
+  if (strcmp(lex->create_view_definer->user.str, thd->priv_user) != 0 ||
+      my_strcasecmp(system_charset_info,
+                    lex->create_view_definer->host.str,
+                    thd->priv_host) != 0)
+  {
+    if (!(thd->master_access & SUPER_ACL))
+    {
+      my_error(ER_VIEW_OTHER_USER, MYF(0), lex->create_view_definer->user.str,
+               lex->create_view_definer->host.str);
+      res= TRUE;
+      goto err;
+    }
+    else
+    {
+      if (!is_acl_user(lex->create_view_definer->host.str,
+                       lex->create_view_definer->user.str))
+      {
+        push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+                            ER_NO_SUCH_USER,
+                            ER(ER_NO_SUCH_USER),
+                            lex->create_view_definer->user.str,
+                            lex->create_view_definer->host.str);
+      }
+    }
+  }
+  /*
     Privilege check for view creation:
     - user has CREATE VIEW privilege on view table
     - user has DROP privilege in case of ALTER VIEW or CREATE OR REPLACE
@@ -369,6 +399,7 @@
     if (lex->view_list.elements != select_lex->item_list.elements)
     {
       my_message(ER_VIEW_WRONG_LIST, ER(ER_VIEW_WRONG_LIST), MYF(0));
+      res= TRUE;
       goto err;
     }
     while ((item= it++, name= nm++))
@@ -447,9 +478,9 @@
 
 
 /* index of revision number in following table */
-static const int revision_number_position= 5;
+static const int revision_number_position= 8;
 /* index of last required parameter for making view */
-static const int required_view_parameters= 7;
+static const int required_view_parameters= 10;
 
 /*
   table of VIEW .frm field descriptors
@@ -458,23 +489,41 @@
   parse()
 */
 static File_option view_parameters[]=
-{{{(char*) "query", 5},		offsetof(TABLE_LIST, query),
+{{{(char*) STRING_WITH_LEN("query")},
+  offsetof(TABLE_LIST, query),
+  FILE_OPTIONS_STRING},
+ {{(char*) STRING_WITH_LEN("md5")},
+  offsetof(TABLE_LIST, md5),
+  FILE_OPTIONS_STRING},
+ {{(char*) STRING_WITH_LEN("updatable")},
+  offsetof(TABLE_LIST, updatable_view),
+  FILE_OPTIONS_ULONGLONG},
+ {{(char*) STRING_WITH_LEN("algorithm")},
+  offsetof(TABLE_LIST, algorithm),
+  FILE_OPTIONS_ULONGLONG},
+ {{(char*) STRING_WITH_LEN("definer_user")},
+  offsetof(TABLE_LIST, definer.user),
   FILE_OPTIONS_STRING},
- {{(char*) "md5", 3},		offsetof(TABLE_LIST, md5),
+ {{(char*) STRING_WITH_LEN("definer_host")},
+  offsetof(TABLE_LIST, definer.host),
   FILE_OPTIONS_STRING},
- {{(char*) "updatable", 9},	offsetof(TABLE_LIST, updatable_view),
+ {{(char*) STRING_WITH_LEN("suid")},
+  offsetof(TABLE_LIST, view_suid),
   FILE_OPTIONS_ULONGLONG},
- {{(char*) "algorithm", 9},	offsetof(TABLE_LIST, algorithm),
+ {{(char*) STRING_WITH_LEN("with_check_option")},
+  offsetof(TABLE_LIST, with_check),
   FILE_OPTIONS_ULONGLONG},
- {{(char*) "with_check_option", 17}, offsetof(TABLE_LIST, with_check),
-   FILE_OPTIONS_ULONGLONG},
- {{(char*) "revision", 8},	offsetof(TABLE_LIST, revision),
+ {{(char*) STRING_WITH_LEN("revision")},
+  offsetof(TABLE_LIST, revision),
   FILE_OPTIONS_REV},
- {{(char*) "timestamp", 9},	offsetof(TABLE_LIST, timestamp),
+ {{(char*) STRING_WITH_LEN("timestamp")},
+  offsetof(TABLE_LIST, timestamp),
   FILE_OPTIONS_TIMESTAMP},
- {{(char*)"create-version", 14},offsetof(TABLE_LIST, file_version),
+ {{(char*)STRING_WITH_LEN("create-version")},
+  offsetof(TABLE_LIST, file_version),
   FILE_OPTIONS_ULONGLONG},
- {{(char*) "source", 6},	offsetof(TABLE_LIST, source),
+ {{(char*) STRING_WITH_LEN("source")},
+  offsetof(TABLE_LIST, source),
   FILE_OPTIONS_ESTRING},
  {{NullS, 0},			0,
   FILE_OPTIONS_STRING}
@@ -587,8 +636,9 @@
   /* fill structure */
   view->query.str= (char*)str.ptr();
   view->query.length= str.length()-1; // we do not need last \0
-  view->source.str= thd->query;
-  view->source.length= thd->query_length;
+  view->source.str= thd->lex->create_view_select_start;
+  view->source.length= (thd->query_length -
+                        (thd->lex->create_view_select_start - thd->query));
   view->file_version= 1;
   view->calc_md5(md5);
   view->md5.str= md5;
@@ -602,6 +652,9 @@
     lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED;
   }
   view->algorithm= lex->create_view_algorithm;
+  view->definer.user= lex->create_view_definer->user;
+  view->definer.host= lex->create_view_definer->host;
+  view->view_suid= lex->create_view_suid;
   view->with_check= lex->create_view_check;
   if ((view->updatable_view= (can_be_merged &&
                               view->algorithm != VIEW_ALGORITHM_TMPTABLE)))
@@ -709,6 +762,11 @@
   /* init timestamp */
   if (!table->timestamp.str)
     table->timestamp.str= table->timestamp_buffer;
+  /* prepare default values for old format */
+  table->view_suid= 1;
+  table->definer.user.str= table->definer.host.str= 0;
+  table->definer.user.length= table->definer.host.length= 0;
+
   /*
     TODO: when VIEWs will be stored in cache, table mem_root should
     be used here
@@ -718,6 +776,21 @@
     goto err;
 
   /*
+    check old format view .frm
+  */
+  if (!table->definer.user.str)
+  {
+    DBUG_ASSERT(!table->definer.host.str &&
+                !table->definer.user.length &&
+                !table->definer.host.length);
+    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                        ER_VIEW_FRM_NO_USER, ER(ER_VIEW_FRM_NO_USER),
+                        table->db, table->table_name);
+    if (default_view_definer(thd, &table->definer))
+      goto err;
+  }
+
+  /*
     Save VIEW parameters, which will be wiped out by derived table
     processing
   */
@@ -1162,7 +1235,7 @@
     {
       if (!fld->item->fixed && fld->item->fix_fields(thd,
&fld->item))
       {
-        thd->set_query_id= save_set_query_id;        
+        thd->set_query_id= save_set_query_id;
         return TRUE;
       }
     }

--- 1.25/mysql-test/r/sql_mode.result	2005-08-27 13:29:29 +03:00
+++ 1.26/mysql-test/r/sql_mode.result	2005-09-13 15:44:43 +03:00
@@ -449,11 +449,11 @@
 create view v1 as select a from t1;
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`
 SET @@SQL_MODE='ANSI_QUOTES';
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW "test"."v1" AS select "test"."t1"."a" AS "a" from
"test"."t1"
+v1	CREATE ALGORITHM=UNDEFINED DEFINER="root"@"localhost" SQL SECURITY DEFINER VIEW
"test"."v1" AS select "test"."t1"."a" AS "a" from "test"."t1"
 create view v2 as select a from t2 where a in (select a from v1);
 drop view v2, v1;
 drop table t1, t2;

--- 1.3/mysql-test/r/view_grant.result	2005-07-30 04:25:54 +03:00
+++ 1.4/mysql-test/r/view_grant.result	2005-09-13 15:44:43 +03:00
@@ -12,6 +12,8 @@
 create table mysqltest.t2 (a int, b int);
 grant select on mysqltest.t1 to mysqltest_1@localhost;
 grant create view,select on test.* to mysqltest_1@localhost;
+create definer=root@localhost view v1 as select * from mysqltest.t1;
+ERROR HY000: You need the SUPER privilege for creation view with root@localhost definer
 create view v1 as select * from mysqltest.t1;
 alter view v1 as select * from mysqltest.t1;
 ERROR 42000: DROP command denied to user 'mysqltest_1'@'localhost' for table 'v1'
@@ -21,6 +23,9 @@
 ERROR 42000: CREATE VIEW command denied to user 'mysqltest_1'@'localhost' for table 'v2'
 create view v2 as select * from mysqltest.t2;
 ERROR 42000: ANY command denied to user 'mysqltest_1'@'localhost' for table 't2'
+show create view v1;
+View	Create View
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`mysqltest_1`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `mysqltest`.`t1`.`a` AS `a`,`mysqltest`.`t1`.`b` AS `b` from
`mysqltest`.`t1`
 grant create view,drop,select on test.* to mysqltest_1@localhost;
 use test;
 alter view v1 as select * from mysqltest.t1;
@@ -120,27 +125,27 @@
 1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	0	const row not found
 show create view mysqltest.v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1)
AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`mysqltest`.`v1` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1)
AS `d` from `mysqltest`.`t1`
 explain select c from mysqltest.v2;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	0	const row not found
 2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
 show create view mysqltest.v2;
 View	Create View
-v2	CREATE ALGORITHM=TEMPTABLE VIEW `mysqltest`.`v2` AS select (`mysqltest`.`t1`.`a` + 1)
AS `c`,(`mysqltest`.`t1`.`b` + 1) AS `d` from `mysqltest`.`t1`
+v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`mysqltest`.`v2` AS select (`mysqltest`.`t1`.`a` + 1) AS `c`,(`mysqltest`.`t1`.`b` + 1)
AS `d` from `mysqltest`.`t1`
 explain select c from mysqltest.v3;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	t2	system	NULL	NULL	NULL	NULL	0	const row not found
 show create view mysqltest.v3;
 View	Create View
-v3	CREATE ALGORITHM=UNDEFINED VIEW `mysqltest`.`v3` AS select (`mysqltest`.`t2`.`a` + 1)
AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2`
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`mysqltest`.`v3` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1)
AS `d` from `mysqltest`.`t2`
 explain select c from mysqltest.v4;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	0	const row not found
 2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
 show create view mysqltest.v4;
 View	Create View
-v4	CREATE ALGORITHM=TEMPTABLE VIEW `mysqltest`.`v4` AS select (`mysqltest`.`t2`.`a` + 1)
AS `c`,(`mysqltest`.`t2`.`b` + 1) AS `d` from `mysqltest`.`t2`
+v4	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`mysqltest`.`v4` AS select (`mysqltest`.`t2`.`a` + 1) AS `c`,(`mysqltest`.`t2`.`b` + 1)
AS `d` from `mysqltest`.`t2`
 revoke all privileges on mysqltest.* from mysqltest_1@localhost;
 delete from mysql.user where user='mysqltest_1';
 drop database mysqltest;

--- 1.3/mysql-test/t/view_grant.test	2005-07-05 13:36:31 +03:00
+++ 1.4/mysql-test/t/view_grant.test	2005-09-13 15:44:43 +03:00
@@ -24,6 +24,8 @@
 connect (user1,localhost,mysqltest_1,,test);
 connection user1;
 
+-- error ER_VIEW_OTHER_USER
+create definer=root@localhost view v1 as select * from mysqltest.t1;
 create view v1 as select * from mysqltest.t1;
 # try to modify view without DROP privilege on it
 -- error 1142
@@ -38,6 +40,9 @@
 create view v2 as select * from mysqltest.t2;
 
 connection root;
+# check view definer information
+show create view v1;
+
 grant create view,drop,select on test.* to mysqltest_1@localhost;
 
 connection user1;

--- 1.18/mysql-test/r/func_in.result	2005-07-17 04:04:30 +03:00
+++ 1.19/mysql-test/r/func_in.result	2005-09-13 15:44:42 +03:00
@@ -209,7 +209,7 @@
 CREATE VIEW v1 AS SELECT * FROM t1 WHERE a NOT IN (45);
 SHOW CREATE VIEW v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a` from
`test`.`t1` where (`test`.`t1`.`a` <> 45)
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a`
<> 45)
 SELECT * FROM v1;
 a
 44

--- 1.14/mysql-test/r/temp_table.result	2005-05-07 15:00:58 +03:00
+++ 1.15/mysql-test/r/temp_table.result	2005-09-13 15:44:43 +03:00
@@ -109,7 +109,7 @@
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 show create view t1;
 View	Create View
-t1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`t1` AS select _latin1'This is view' AS `A`
+t1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`t1` AS select _latin1'This is view' AS `A`
 drop view t1;
 select * from t1;
 A

--- 1.65/mysql-test/r/mysqldump.result	2005-09-10 01:47:58 +03:00
+++ 1.66/mysql-test/r/mysqldump.result	2005-09-13 15:44:42 +03:00
@@ -1549,7 +1549,7 @@
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1*/;
 /*!50001 DROP TABLE IF EXISTS `v1`*/;
 /*!50001 DROP VIEW IF EXISTS `v1`*/;
-/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `test`.`t1`.`a` AS `a`
from `test`.`t1`*/;
+/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `test`.`t1`.`a` AS `a` from `test`.`t1`*/;
 
 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
@@ -1601,7 +1601,7 @@
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1*/;
 /*!50001 DROP TABLE IF EXISTS `v2`*/;
 /*!50001 DROP VIEW IF EXISTS `v2`*/;
-/*!50001 CREATE ALGORITHM=UNDEFINED VIEW `mysqldump_test_db`.`v2` AS select
`mysqldump_test_db`.`t2`.`a` AS `a` from `mysqldump_test_db`.`t2` where
(`mysqldump_test_db`.`t2`.`a` like _latin1'a%') WITH CASCADED CHECK OPTION*/;
+/*!50001 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`mysqldump_test_db`.`v2` AS select `mysqldump_test_db`.`t2`.`a` AS `a` from
`mysqldump_test_db`.`t2` where (`mysqldump_test_db`.`t2`.`a` like _latin1'a%') WITH
CASCADED CHECK OPTION*/;
 
 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
@@ -1665,7 +1665,7 @@
 v3	VIEW
 show create view v1;
 View	Create View
-v1	CREATE ALGORITHM=UNDEFINED VIEW `test`.`v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS
`b`,`v3`.`c` AS `c` from `test`.`v3` where (`v3`.`b` in (1,2,3,4,5,6,7))
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
`test`.`v1` AS select `v3`.`a` AS `a`,`v3`.`b` AS `b`,`v3`.`c` AS `c` from `test`.`v3`
where (`v3`.`b` in (1,2,3,4,5,6,7))
 select * from v1;
 a	b	c
 1	2	one
Thread
bk commit into 5.0 tree (bell:1.1966)sanja13 Sep