From d4e768b442b8bd83d94e2691fbaea5b0f2e3e4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Sun, 12 Jul 2015 17:50:27 +0200 Subject: [PATCH 2/2] Update _login and _hostname attributes - Remove register storage class (Not useful and removed in recent C++) - Initial Windows code (not tested) --- sql-common/client.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index 5b3904c..2c85b84 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -4025,8 +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; + struct passwd *pw; + uid_t uid; /* Clean up any values set by the client code. We want these options as @@ -4064,16 +4064,35 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len) rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_thread", buff); #endif +#ifdef _WIN32 + WCHAR wbuf[255]; + DWORD wbuf_len= sizeof(wbuf) / sizeof(WCHAR); + size_t len; + uint dummy_errors; + + if (GetUserNameW(wbuf, &wbuf_len)) + { + len= my_convert(buf, sizeof(buf) - 1, charset_info, (char *) wbuf, + wbuf_len * sizeof(WCHAR), &my_charset_utf16le_bin, + &dummy_errors); + buf[len]= 0; + rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_login", buff); + } +#else uid = geteuid(); + +#ifdef HAVE_GETPWUID 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); } +#endif if (gethostname(buff, buf_len) == 0) { rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "_hostname", buff); } +#endif return rc > 0 ? 1 : 0; } -- 2.4.3