From 582886a3e971df2766411cdfe57c8a09f3c2e6b6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 7 Jan 2004 21:30:15 +0400 Subject: 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 --- libmysqld/embedded_priv.h | 9 +++++---- libmysqld/lib_sql.cc | 22 ++++++++++++++++++---- libmysqld/libmysqld.c | 17 +++++++---------- sql/sql_class.cc | 4 +++- 4 files changed, 33 insertions(+), 19 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 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; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 60220ffc889..89b812eb205 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -323,12 +323,14 @@ THD::~THD() #endif DBUG_PRINT("info", ("freeing host")); +#ifndef EMBEDDED_LIBRARY if (host != my_localhost) // If not pointer to constant safeFree(host); if (user != delayed_user) safeFree(user); - safeFree(db); safeFree(ip); +#endif + safeFree(db); free_root(&warn_root,MYF(0)); free_root(&transaction.mem_root,MYF(0)); mysys_var=0; // Safety (shouldn't be needed) -- cgit v1.2.1