List:Commits« Previous MessageNext Message »
From:Georgi Kodinov Date:September 15 2010 3:47pm
Subject:bzr commit into mysql-5.5 branch (Georgi.Kodinov:3083) Bug#56798
View as plain text  
#At file:///home/kgeorge/mysql/work/wl1054-5.5/ based on revid:georgi.kodinov@stripped

 3083 Georgi Kodinov	2010-09-15
      Bug #56798 : Wrong credentials assigned when using a proxy user.
      
      Fixed incorrect handling of user credentials when authenticating
      via proxy user. Now the server will use the proxies user's 
      access mask and host to update the security context runtime 
      structure when logging in.
      
      Fixed a compilation warning with the embedded library.

    modified:
      mysql-test/r/plugin_auth.result
      mysql-test/t/plugin_auth.test
      sql/sql_acl.cc
=== modified file 'mysql-test/r/plugin_auth.result'
--- a/mysql-test/r/plugin_auth.result	2010-08-09 08:32:50 +0000
+++ b/mysql-test/r/plugin_auth.result	2010-09-15 15:47:21 +0000
@@ -210,3 +210,17 @@ SELECT @@LOCAL.external_user;
 DROP USER plug;
 DROP USER plug_dest;
 ## END @@external_user tests
+#
+#  Bug #56798 : Wrong credentials assigned when using a proxy user.
+#
+GRANT ALL PRIVILEGES ON *.* TO power_user;
+GRANT USAGE ON anonymous_db.* TO ''@''
+  IDENTIFIED WITH 'test_plugin_server' AS 'power_user';
+GRANT PROXY ON power_user TO ''@'';
+CREATE DATABASE confidential_db;
+SELECT user(),current_user(),@@proxy_user;
+user()	current_user()	@@proxy_user
+test_login_user@localhost	power_user@%	''@''
+DROP USER power_user;
+DROP USER ''@'';
+DROP DATABASE confidential_db;

=== modified file 'mysql-test/t/plugin_auth.test'
--- a/mysql-test/t/plugin_auth.test	2010-08-09 08:32:50 +0000
+++ b/mysql-test/t/plugin_auth.test	2010-09-15 15:47:21 +0000
@@ -296,3 +296,23 @@ disconnect plug_con;
 DROP USER plug;
 DROP USER plug_dest;
 --echo ## END @@external_user tests
+
+--echo #
+--echo #  Bug #56798 : Wrong credentials assigned when using a proxy user.
+--echo #
+
+GRANT ALL PRIVILEGES ON *.* TO power_user;
+GRANT USAGE ON anonymous_db.* TO ''@''
+  IDENTIFIED WITH 'test_plugin_server' AS 'power_user';
+GRANT PROXY ON power_user TO ''@'';
+CREATE DATABASE confidential_db;
+
+connect(plug_con,localhost, test_login_user, power_user, confidential_db);
+SELECT user(),current_user(),@@proxy_user;
+
+connection default;
+disconnect plug_con;
+
+DROP USER power_user;
+DROP USER ''@'';
+DROP DATABASE confidential_db;

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2010-08-09 08:32:50 +0000
+++ b/sql/sql_acl.cc	2010-09-15 15:47:21 +0000
@@ -318,6 +318,8 @@ public:
   bool get_with_grant() { return with_grant; }
   const char *get_user() { return user; }
   const char *get_host() { return host.hostname; }
+  const char *get_proxied_user() { return proxied_user; }
+  const char *get_proxied_host() { return proxied_host.hostname; }
   void set_user(MEM_ROOT *mem, const char *user_arg) 
   { 
     user= user_arg && *user_arg ?  strdup_root (mem, user_arg) : NULL; 
@@ -7044,12 +7046,12 @@ template class List<LEX_USER>;
   @param user              the logged in user (proxy user)
   @param authenticated_as  the effective user a plugin is trying to 
                            impersonate as (proxied user)
-  @return                  status
-    @retval FALSE          OK
-    @retval TRUE           user can't impersonate proxied user
+  @return                  proxy user definition
+    @retval NULL           proxy user definition not found or not applicable
+    @retval non-null       the proxy user data
 */
 
-static bool 
+static ACL_PROXY_USER *
 acl_find_proxy_user(const char *user, const char *host, const char *ip, 
                     const char *authenticated_as, bool *proxy_used)
 {
@@ -7061,7 +7063,7 @@ acl_find_proxy_user(const char *user, co
   if (!strcmp (authenticated_as, user))
   {
     DBUG_PRINT ("info", ("user is the same as authenticated_as"));
-    DBUG_RETURN (FALSE);
+    DBUG_RETURN (NULL);
   }
 
   *proxy_used= TRUE; 
@@ -7070,10 +7072,10 @@ acl_find_proxy_user(const char *user, co
     ACL_PROXY_USER *proxy= dynamic_element (&acl_proxy_users, i, 
                                             ACL_PROXY_USER *);
     if (proxy->matches (host, user, ip, authenticated_as))
-      DBUG_RETURN(FALSE);
+      DBUG_RETURN(proxy);
   }
 
-  DBUG_RETURN (TRUE);
+  DBUG_RETURN (NULL);
 }
 
 
@@ -8676,6 +8678,7 @@ static void server_mpvio_info(MYSQL_PLUG
   mpvio_info(mpvio->net->vio, info);
 }
 
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
 static bool acl_check_ssl(THD *thd, const ACL_USER *acl_user)
 {
 #if defined(HAVE_OPENSSL)
@@ -8780,6 +8783,7 @@ static bool acl_check_ssl(THD *thd, cons
   }
   return 1;
 }
+#endif
 
 
 static int do_auth_once(THD *thd, const LEX_STRING *auth_plugin_name,
@@ -9006,25 +9010,51 @@ acl_authenticate(THD *thd, uint connect_
   {
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
     bool is_proxy_user= FALSE;
-    const char *auth_user = mpvio.acl_user->user ? mpvio.acl_user->user : "";
+    const char *auth_user = acl_user->user ? acl_user->user : "";
+    ACL_PROXY_USER *proxy_user;
     /* check if the user is allowed to proxy as another user */
-    if (acl_find_proxy_user(auth_user, sctx->host, sctx->ip, 
-                            mpvio.auth_info.authenticated_as,
-                            &is_proxy_user))
+    proxy_user= acl_find_proxy_user(auth_user, sctx->host, sctx->ip,
+                                    mpvio.auth_info.authenticated_as,
+                                          &is_proxy_user);
+    if (is_proxy_user)
     {
-      if (!thd->is_error())
-        login_failed_error(&mpvio, mpvio.auth_info.password_used);
-      DBUG_RETURN(1);
-    }
+      ACL_USER *acl_proxy_user;
+
+      /* we need to find the proxy user, but there was none */
+      if (!proxy_user)
+      {
+        if (!thd->is_error())
+          login_failed_error(&mpvio, mpvio.auth_info.password_used);
+        DBUG_RETURN(1);
+      }
 
-    if (is_proxy_user)
       my_snprintf(sctx->proxy_user, sizeof (sctx->proxy_user) - 1,
                   "'%s'@'%s'", auth_user,
                   acl_user->host.hostname ? acl_user->host.hostname : "");
+
+      /* we're proxying : find the proxy user definition */
+      mysql_mutex_lock(&acl_cache->lock);
+      acl_proxy_user= find_acl_user(proxy_user->get_proxied_host() ? 
+                                    proxy_user->get_proxied_host() : "",
+                                    mpvio.auth_info.authenticated_as, TRUE);
+      if (!acl_proxy_user)
+      {
+        if (!thd->is_error())
+          login_failed_error(&mpvio, mpvio.auth_info.password_used);
+        mysql_mutex_unlock(&acl_cache->lock);
+        DBUG_RETURN(1);
+      }
+      acl_user= acl_proxy_user->copy(thd->mem_root);
+      mysql_mutex_unlock(&acl_cache->lock);
+    }
 #endif
 
     sctx->master_access= acl_user->access;
-    strmake(sctx->priv_user, mpvio.auth_info.authenticated_as, USERNAME_LENGTH - 1);
+    if (acl_user->user)
+      strmake(sctx->priv_user, acl_user->user, USERNAME_LENGTH - 1);
+    else
+      *sctx->priv_user= 0;
+
     if (acl_user->host.hostname)
       strmake(sctx->priv_host, acl_user->host.hostname, MAX_HOSTNAME - 1);
     else


Attachment: [text/bzr-bundle] bzr/georgi.kodinov@oracle.com-20100915154721-zqspsphmby13bini.bundle
Thread
bzr commit into mysql-5.5 branch (Georgi.Kodinov:3083) Bug#56798Georgi Kodinov15 Sep