From 6c8024fc70736d15e3d07c986b2bcea4ce66f274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Mon, 1 Jun 2015 12:38:30 +0200 Subject: [PATCH] Add _login and _hostname as connection attribute. https://bugs.mysql.com/bug.php?id=77190 --- sql-common/client.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sql-common/client.c b/sql-common/client.c index 3bbd87b..5b3904c 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -4025,6 +4025,8 @@ static int set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) { int rc= 0; + register struct passwd *pw; + register uid_t uid; /* Clean up any values set by the client code. We want these options as @@ -4036,6 +4038,8 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_pid"); rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_thread"); rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_version"); + rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_login"); + rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_hostname"); /* Now let's set up some values @@ -4060,6 +4064,17 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buff); #endif + uid = geteuid(); + pw = getpwuid(uid); + if (pw) { + my_snprintf(buff, buf_len, "%s", pw->pw_name); + rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_login", buff); + } + + if (gethostname(buff, buf_len) == 0) { + rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_hostname", buff); + } + return rc > 0 ? 1 : 0; }