Commit 4a44e805 authored by unknown's avatar unknown

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
parent 640e97bd
......@@ -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
......@@ -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))
......
......@@ -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;
......
......@@ -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)
......
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