diff options
author | hf@deer.(none) <> | 2003-09-26 15:40:26 +0500 |
---|---|---|
committer | hf@deer.(none) <> | 2003-09-26 15:40:26 +0500 |
commit | 5f8e7fef2746ece1973116db739c6604cc156b21 (patch) | |
tree | b80c6147c3a9929ec4e00bac55883c6d575ac2a4 /libmysqld/libmysqld.c | |
parent | d5d4923107a2f8d3455debfe6ab8b22b5793f6cf (diff) | |
parent | ba8fa76fa20f400d8adfe2aa14231a682df9ba79 (diff) | |
download | mariadb-git-5f8e7fef2746ece1973116db739c6604cc156b21.tar.gz |
Merge
Diffstat (limited to 'libmysqld/libmysqld.c')
-rw-r--r-- | libmysqld/libmysqld.c | 86 |
1 files changed, 34 insertions, 52 deletions
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c index ddde18c1918..59c18368279 100644 --- a/libmysqld/libmysqld.c +++ b/libmysqld/libmysqld.c @@ -146,12 +146,17 @@ 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; + 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)", @@ -190,6 +195,29 @@ 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; + + if (!passwd) + { + passwd=mysql->options.password; +#if !defined(DONT_USE_MYSQL_PWD) + if (!passwd) + passwd=getenv("MYSQL_PWD"); /* get it from environment */ +#endif + } + if (!user || !user[0]) + { + read_user_name(name_buff); + if (!name_buff[0]) + user= name_buff; + } + + 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; db_name = db ? my_strdup(db,MYF(MY_WME)) : NULL; @@ -198,6 +226,11 @@ 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; @@ -245,54 +278,3 @@ error: DBUG_RETURN(0); } - -/************************************************************************* -** Send a QUIT to the server and close the connection -** If handle is alloced by mysql connect free it. -*************************************************************************/ - -void STDCALL mysql_close(MYSQL *mysql) -{ - DBUG_ENTER("mysql_close"); - if (mysql) /* Some simple safety */ - { - if (mysql->methods != &embedded_methods) - { - cli_mysql_close(mysql); - DBUG_VOID_RETURN; - } - - my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR)); - if (mysql->options.init_commands) - { - DYNAMIC_ARRAY *init_commands= mysql->options.init_commands; - char **ptr= (char**)init_commands->buffer; - char **end= ptr + init_commands->elements; - for (; ptr<end; ptr++) - my_free(*ptr,MYF(MY_WME)); - delete_dynamic(init_commands); - my_free((char*)init_commands,MYF(MY_WME)); - } - /* Clear pointers for better safety */ - bzero((char*) &mysql->options,sizeof(mysql->options)); -#ifdef HAVE_OPENSSL - ((VioConnectorFd*)(mysql->connector_fd))->delete(); - mysql->connector_fd = 0; -#endif /* HAVE_OPENSSL */ - if (mysql->free_me) - my_free((gptr) mysql,MYF(0)); - - free_embedded_thd(mysql); - - } - DBUG_VOID_RETURN; -} - |