Skip to content

Commit 6ddbc58

Browse files
committed
Bug #20041925: MAKE AUTH_SOCKET MORE FLEXIBLE
Before this fix the unix socket auth plugin returned true only when the OS socket user id matches the mysql user name. The authentication string was ignored. This will still work, but in addition to this (if the comparison fails) the socket user id is compared to the authentication_string too. So effectively this plugin will now return a positive if the socket's user name matches ether the mysql account user name or the mysql account authentication string now. Made the plugin to fill in the @@external_user variable. Fixed a bug in how @@external_user's variable value was formed (it was a copy of @@proxy_user instead of the value returned by the plugin). Tests updated to reflect the proper @@external_user value.
1 parent e9d7463 commit 6ddbc58

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

mysql-test/r/plugin_auth.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ NULL
234234
# in connection plug_con
235235
SELECT @@LOCAL.external_user;
236236
@@LOCAL.external_user
237-
'plug'@'%'
237+
plug_dest
238238
# in connection default
239239
WL#5706 -- show the above got logged/rewritten correctly
240240
SELECT argument FROM mysql.general_log WHERE argument LIKE CONCAT('%IDENTIFIED ','WITH %');

mysql-test/r/plugin_auth_qa_2.result

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ NULL
4646
exec MYSQL PLUGIN_AUTH_OPT -h localhost -P MASTER_MYPORT -u qa_test_2_user --password=qa_test_2_dest test_user_db -e "SELECT current_user(),user(),@@local.proxy_user,@@local.external_user;" 2>&1
4747
mysql: [Warning] Using a password on the command line interface can be insecure.
4848
current_user() user() @@local.proxy_user @@local.external_user
49-
authenticated_as@% user_name@localhost 'qa_test_2_user'@'%' 'qa_test_2_user'@'%'
49+
authenticated_as@% user_name@localhost 'qa_test_2_user'@'%' externaluser
5050
SELECT user,plugin,authentication_string FROM mysql.user WHERE user != 'root';
5151
user plugin authentication_string
5252
authenticated_as mysql_native_password
@@ -63,7 +63,7 @@ GRANT PROXY ON qa_test_3_dest TO qa_test_3_user;
6363
exec MYSQL PLUGIN_AUTH_OPT -h localhost -P MASTER_MYPORT -u qa_test_3_user --password=qa_test_3_dest test_user_db -e "SELECT current_user(),user(),@@local.proxy_user,@@local.external_user;" 2>&1
6464
mysql: [Warning] Using a password on the command line interface can be insecure.
6565
current_user() user() @@local.proxy_user @@local.external_user
66-
qa_test_3_dest@% qa_test_3_user@localhost 'qa_test_3_user'@'%' 'qa_test_3_user'@'%'
66+
qa_test_3_dest@% qa_test_3_user@localhost 'qa_test_3_user'@'%' qa_test_3_dest
6767
DROP USER qa_test_3_user;
6868
DROP USER qa_test_3_dest;
6969
=== Assign too low values for *length, which should have no effect ====
@@ -74,7 +74,7 @@ GRANT PROXY ON qa_test_4_dest TO qa_test_4_user;
7474
exec MYSQL PLUGIN_AUTH_OPT -h localhost -P MASTER_MYPORT -u qa_test_4_user --password=qa_test_4_dest test_user_db -e "SELECT current_user(),user(),@@local.proxy_user,@@local.external_user;" 2>&1
7575
mysql: [Warning] Using a password on the command line interface can be insecure.
7676
current_user() user() @@local.proxy_user @@local.external_user
77-
qa_test_4_dest@% qa_test_4_user@localhost 'qa_test_4_user'@'%' 'qa_test_4_user'@'%'
77+
qa_test_4_dest@% qa_test_4_user@localhost 'qa_test_4_user'@'%' qa_test_4_dest
7878
DROP USER qa_test_4_user;
7979
DROP USER qa_test_4_dest;
8080
=== Assign empty string especially to authenticated_as (in plugin) ====

mysql-test/r/plugin_auth_qa_3.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GRANT PROXY ON qa_test_11_dest TO qa_test_11_user;
55
exec MYSQL PLUGIN_AUTH_OPT --default_auth=qa_auth_client -h localhost -P MASTER_MYPORT -u qa_test_11_user --password=qa_test_11_dest test_user_db -e "SELECT current_user(),user(),@@local.proxy_user,@@local.external_user;" 2>&1
66
mysql: [Warning] Using a password on the command line interface can be insecure.
77
current_user() user() @@local.proxy_user @@local.external_user
8-
qa_test_11_dest@% qa_test_11_user@localhost 'qa_test_11_user'@'%' 'qa_test_11_user'@'%'
8+
qa_test_11_dest@% qa_test_11_user@localhost 'qa_test_11_user'@'%' NULL
99
exec MYSQL PLUGIN_AUTH_OPT --default_auth=qa_auth_client -h localhost -P MASTER_MYPORT -u qa_test_2_user --password=qa_test_11_dest test_user_db -e "SELECT current_user(),user(),@@local.proxy_user,@@local.external_user;" 2>&1
1010
mysql: [Warning] Using a password on the command line interface can be insecure.
1111
ERROR 1045 (28000): Access denied for user 'qa_test_2_user'@'localhost' (using password: YES)

plugin/auth/auth_socket.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ static int socket_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
6161
if (cred_len != sizeof(cred))
6262
return CR_ERROR;
6363

64-
/* and find the username for this uid */
64+
/* and find the socket user name for this uid */
6565
getpwuid_r(cred.uid, &pwd_buf, buf, sizeof(buf), &pwd);
6666
if (pwd == NULL)
6767
return CR_ERROR;
6868

69-
/* now it's simple as that */
70-
return strcmp(pwd->pw_name, info->user_name) ? CR_ERROR : CR_OK;
69+
/* fill in the external user name used */
70+
strncpy(info->external_user, pwd->pw_name, sizeof(info->external_user) - 1);
71+
info->external_user[sizeof(info->external_user) - 1]= 0;
72+
73+
if (!strcmp(pwd->pw_name, info->user_name) ||
74+
!strcmp(pwd->pw_name, info->auth_string))
75+
return CR_OK;
76+
else
77+
return CR_ERROR;
7178
}
7279

7380
static struct st_mysql_auth socket_auth_handler=
@@ -87,7 +94,7 @@ mysql_declare_plugin(socket_auth)
8794
PLUGIN_LICENSE_GPL,
8895
NULL,
8996
NULL,
90-
0x0100,
97+
0x0101,
9198
NULL,
9299
NULL,
93100
NULL,

sql/sys_vars.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,10 @@ class Sys_var_external_user : public Sys_var_proxy_user
595595
protected:
596596
virtual uchar *session_value_ptr(THD *thd, LEX_STRING *base)
597597
{
598-
return thd->security_ctx->proxy_user[0] ?
599-
(uchar *) &(thd->security_ctx->proxy_user[0]) : NULL;
598+
String *external_user= thd->security_ctx->get_external_user();
599+
600+
return external_user && external_user->length() ?
601+
(uchar *) external_user->c_ptr_quick() : NULL;
600602
}
601603
};
602604

0 commit comments

Comments
 (0)