Commit 33485644 authored by hf@deer.(none)'s avatar hf@deer.(none)

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
parent 2e7a5d3e
...@@ -23,9 +23,10 @@ ...@@ -23,9 +23,10 @@
#include <my_pthread.h> #include <my_pthread.h>
C_MODE_START C_MODE_START
extern void lib_connection_phase(NET *net, int phase); void lib_connection_phase(NET *net, int phase);
extern void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db); void init_embedded_mysql(MYSQL *mysql, int client_flag, char *db);
extern void *create_embedded_thd(int client_flag, char *db); void *create_embedded_thd(int client_flag, char *db);
extern MYSQL_METHODS embedded_methods; int check_embedded_connection(MYSQL *mysql);
void free_old_query(MYSQL *mysql); void free_old_query(MYSQL *mysql);
extern MYSQL_METHODS embedded_methods;
C_MODE_END C_MODE_END
...@@ -478,7 +478,17 @@ void *create_embedded_thd(int client_flag, char *db) ...@@ -478,7 +478,17 @@ void *create_embedded_thd(int client_flag, char *db)
return thd; 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) int check_embedded_connection(MYSQL *mysql)
{ {
THD *thd= (THD*)mysql->thd; THD *thd= (THD*)mysql->thd;
...@@ -486,9 +496,13 @@ int check_embedded_connection(MYSQL *mysql) ...@@ -486,9 +496,13 @@ int check_embedded_connection(MYSQL *mysql)
char scramble_buff[SCRAMBLE_LENGTH]; char scramble_buff[SCRAMBLE_LENGTH];
int passwd_len; int passwd_len;
thd->host= mysql->options.client_ip ? if (mysql->options.client_ip)
mysql->options.client_ip : (char*)my_localhost; {
thd->ip= thd->host; thd->host= mysql->options.client_ip;
thd->ip= thd->host;
}
else
thd->host= (char*)my_localhost;
thd->host_or_ip= thd->host; thd->host_or_ip= thd->host;
if (acl_check_host(thd->host,thd->ip)) if (acl_check_host(thd->host,thd->ip))
......
...@@ -124,17 +124,14 @@ static inline int mysql_init_charset(MYSQL *mysql) ...@@ -124,17 +124,14 @@ static inline int mysql_init_charset(MYSQL *mysql)
return 0; return 0;
} }
int check_embedded_connection(MYSQL *mysql);
MYSQL * STDCALL MYSQL * STDCALL
mysql_real_connect(MYSQL *mysql,const char *host, const char *user, mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db, const char *passwd, const char *db,
uint port, const char *unix_socket,ulong client_flag) uint port, const char *unix_socket,ulong client_flag)
{ {
char *db_name; char *db_name;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
char name_buff[USERNAME_LENGTH]; char name_buff[USERNAME_LENGTH];
#endif
DBUG_ENTER("mysql_real_connect"); DBUG_ENTER("mysql_real_connect");
DBUG_PRINT("enter",("host: %s db: %s user: %s", DBUG_PRINT("enter",("host: %s db: %s user: %s",
host ? host : "(Null)", host ? host : "(Null)",
...@@ -165,10 +162,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -165,10 +162,10 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
if (!db || !db[0]) if (!db || !db[0])
db=mysql->options.db; db=mysql->options.db;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!user || !user[0]) if (!user || !user[0])
user=mysql->options.user; user=mysql->options.user;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!passwd) if (!passwd)
{ {
passwd=mysql->options.password; passwd=mysql->options.password;
...@@ -177,16 +174,18 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -177,16 +174,18 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
passwd=getenv("MYSQL_PWD"); /* get it from environment */ passwd=getenv("MYSQL_PWD"); /* get it from environment */
#endif #endif
} }
mysql->passwd= passwd ? my_strdup(passwd,MYF(0)) : NULL;
#endif /*!NO_EMBEDDED_ACCESS_CHECKS*/
if (!user || !user[0]) if (!user || !user[0])
{ {
read_user_name(name_buff); read_user_name(name_buff);
if (!name_buff[0]) if (name_buff[0])
user= name_buff; user= name_buff;
} }
if (!user)
user= "";
mysql->user=my_strdup(user,MYF(0)); mysql->user=my_strdup(user,MYF(0));
mysql->passwd= passwd ? my_strdup(passwd,MYF(0)) : NULL;
#endif /*!NO_EMBEDDED_ACCESS_CHECKS*/
port=0; port=0;
unix_socket=0; unix_socket=0;
...@@ -196,10 +195,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user, ...@@ -196,10 +195,8 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
init_embedded_mysql(mysql, client_flag, db_name); init_embedded_mysql(mysql, client_flag, db_name);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (check_embedded_connection(mysql)) if (check_embedded_connection(mysql))
goto error; goto error;
#endif
if (mysql_init_charset(mysql)) if (mysql_init_charset(mysql))
goto error; goto error;
......
...@@ -323,12 +323,14 @@ THD::~THD() ...@@ -323,12 +323,14 @@ THD::~THD()
#endif #endif
DBUG_PRINT("info", ("freeing host")); DBUG_PRINT("info", ("freeing host"));
#ifndef EMBEDDED_LIBRARY
if (host != my_localhost) // If not pointer to constant if (host != my_localhost) // If not pointer to constant
safeFree(host); safeFree(host);
if (user != delayed_user) if (user != delayed_user)
safeFree(user); safeFree(user);
safeFree(db);
safeFree(ip); safeFree(ip);
#endif
safeFree(db);
free_root(&warn_root,MYF(0)); free_root(&warn_root,MYF(0));
free_root(&transaction.mem_root,MYF(0)); free_root(&transaction.mem_root,MYF(0));
mysys_var=0; // Safety (shouldn't be needed) mysys_var=0; // Safety (shouldn't be needed)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment