List:Internals« Previous MessageNext Message »
From:sanja Date:September 14 2005 11:26am
Subject:bk commit into 5.0 tree (bell:1.1953)
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.1953 05/09/14 12:26:09 bell@stripped +5 -0
  Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0
  into  sanja.is.com.ua:/home/bell/mysql/bk/work-owner2-5.0

  sql/sql_view.cc
    1.63 05/09/14 12:26:02 bell@stripped +0 -0
    Auto merged

  sql/sql_show.cc
    1.280 05/09/14 12:26:02 bell@stripped +0 -0
    Auto merged

  sql/sql_parse.cc
    1.487 05/09/14 12:26:02 bell@stripped +0 -0
    Auto merged

  sql/sql_acl.cc
    1.170 05/09/14 12:26:01 bell@stripped +0 -0
    Auto merged

  sql/mysql_priv.h
    1.350 05/09/14 12:26:01 bell@stripped +0 -0
    Auto merged

# 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-owner2-5.0/RESYNC

--- 1.349/sql/mysql_priv.h	2005-09-13 14:06:27 +03:00
+++ 1.350/sql/mysql_priv.h	2005-09-14 12:26:01 +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.169/sql/sql_acl.cc	2005-09-14 10:11:10 +03:00
+++ 1.170/sql/sql_acl.cc	2005-09-14 12:26:01 +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.486/sql/sql_parse.cc	2005-09-14 10:11:11 +03:00
+++ 1.487/sql/sql_parse.cc	2005-09-14 12:26:02 +03:00
@@ -4463,8 +4463,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;
@@ -6054,12 +6075,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);
@@ -7346,4 +7369,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.279/sql/sql_show.cc	2005-09-14 10:45:56 +03:00
+++ 1.280/sql/sql_show.cc	2005-09-14 12:26:02 +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);
 
 
@@ -1035,6 +1035,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)
@@ -1071,21 +1099,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);
   if (!table->compact_view_format)

--- 1.62/sql/sql_view.cc	2005-09-13 14:06:27 +03:00
+++ 1.63/sql/sql_view.cc	2005-09-14 12:26:02 +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;
       }
     }
Thread
bk commit into 5.0 tree (bell:1.1953)sanja14 Sep