summaryrefslogtreecommitdiff
path: root/libmysqld
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2004-01-07 21:30:15 +0400
committerunknown <hf@deer.(none)>2004-01-07 21:30:15 +0400
commit582886a3e971df2766411cdfe57c8a09f3c2e6b6 (patch)
treed20819ba4aaa9081734e46a63958402010176176 /libmysqld
parent902c361910cdec368c5baec1be6079978a46f1a8 (diff)
downloadmariadb-git-582886a3e971df2766411cdfe57c8a09f3c2e6b6.tar.gz
Fix for 1224 (USER() CURRENT_USER() functions in embedded library)
Now we return user@host for USER() in embedded library CURRENT_USER returns empty string if library compiled with NO_EMBEDDED_ACCESS_CHECKS libmysqld/embedded_priv.h: function's declarations trimmed libmysqld/lib_sql.cc: user/host names handling added libmysqld/libmysqld.c: user/host names handling added sql/sql_class.cc: we shouldn't free user/host names in embedded library
Diffstat (limited to 'libmysqld')
-rw-r--r--libmysqld/embedded_priv.h9
-rw-r--r--libmysqld/lib_sql.cc22
-rw-r--r--libmysqld/libmysqld.c17
3 files changed, 30 insertions, 18 deletions
diff --git a/libmysqld/embedded_priv.h b/libmysqld/embedded_priv.h
index 673531c0c14..1608f4ed4ad 100644
--- a/libmysqld/embedded_priv.h
+++ b/libmysqld/embedded_priv.h
@@ -23,9 +23,10 @@
#include <my_pthread.h>
C_MODE_START
-extern void lib_connection_phase(NET *net, int phase);
-extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
-extern void *create_embedded_thd(int client_flag, char *db);
-extern MYSQL_METHODS embedded_methods;
+void lib_connection_phase(NET *net, int phase);
+void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
+void *create_embedded_thd(int client_flag, char *db);
+int check_embedded_connection(MYSQL *mysql);
void free_old_query(MYSQL *mysql);
+extern MYSQL_METHODS embedded_methods;
C_MODE_END
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 5f478fc8041..2d451d6cecd 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -478,7 +478,17 @@ void *create_embedded_thd(int client_flag, char *db)
return thd;
}
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
+#ifdef NO_EMBEDDED_ACCESS_CHECKS
+int check_embedded_connection(MYSQL *mysql)
+{
+ THD *thd= (THD*)mysql->thd;
+ thd->host= (char*)my_localhost;
+ thd->host_or_ip= thd->host;
+ thd->user= mysql->user;
+ return 0;
+}
+
+#else
int check_embedded_connection(MYSQL *mysql)
{
THD *thd= (THD*)mysql->thd;
@@ -486,9 +496,13 @@ int check_embedded_connection(MYSQL *mysql)
char scramble_buff[SCRAMBLE_LENGTH];
int passwd_len;
- thd->host= mysql->options.client_ip ?
- mysql->options.client_ip : (char*)my_localhost;
- thd->ip= thd->host;
+ if (mysql->options.client_ip)
+ {
+ thd->host= mysql->options.client_ip;
+ thd->ip= thd->host;
+ }
+ else
+ thd->host= (char*)my_localhost;
thd->host_or_ip= thd->host;
if (acl_check_host(thd->host,thd->ip))
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c
index 69fdf14eca4..95f745aef5f 100644
--- a/libmysqld/libmysqld.c
+++ b/libmysqld/libmysqld.c
@@ -124,17 +124,14 @@ static inline int mysql_init_charset(MYSQL *mysql)
return 0;
}
-int check_embedded_connection(MYSQL *mysql);
-
MYSQL * STDCALL
mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db,
uint port, const char *unix_socket,ulong client_flag)
{
char *db_name;
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
char name_buff[USERNAME_LENGTH];
-#endif
+
DBUG_ENTER("mysql_real_connect");
DBUG_PRINT("enter",("host: %s db: %s user: %s",
host ? host : "(Null)",
@@ -165,10 +162,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (!db || !db[0])
db=mysql->options.db;
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!user || !user[0])
user=mysql->options.user;
+#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!passwd)
{
passwd=mysql->options.password;
@@ -177,16 +174,18 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
passwd=getenv("MYSQL_PWD"); /* get it from environment */
#endif
}
+ mysql->passwd= passwd ? my_strdup(passwd,MYF(0)) : NULL;
+#endif /*!NO_EMBEDDED_ACCESS_CHECKS*/
if (!user || !user[0])
{
read_user_name(name_buff);
- if (!name_buff[0])
+ if (name_buff[0])
user= name_buff;
}
+ if (!user)
+ user= "";
mysql->user=my_strdup(user,MYF(0));
- mysql->passwd= passwd ? my_strdup(passwd,MYF(0)) : NULL;
-#endif /*!NO_EMBEDDED_ACCESS_CHECKS*/
port=0;
unix_socket=0;
@@ -196,10 +195,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
init_embedded_mysql(mysql, client_flag, db_name);
-#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (check_embedded_connection(mysql))
goto error;
-#endif
if (mysql_init_charset(mysql))
goto error;