diff options
author | unknown <hf@deer.(none)> | 2003-09-26 15:40:26 +0500 |
---|---|---|
committer | unknown <hf@deer.(none)> | 2003-09-26 15:40:26 +0500 |
commit | 2796f5193781946406d1fa9fbc41e7550dad267f (patch) | |
tree | b80c6147c3a9929ec4e00bac55883c6d575ac2a4 /libmysqld | |
parent | 7998699260c9466206d13b72b18752a547df316b (diff) | |
parent | e206bcf0670031d1ea028d561eca0fcc214313fb (diff) | |
download | mariadb-git-2796f5193781946406d1fa9fbc41e7550dad267f.tar.gz |
Merge
include/mysql.h:
Auto merged
sql/item_strfunc.cc:
Auto merged
sql/log.cc:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/repl_failsafe.cc:
Auto merged
sql/set_var.cc:
Auto merged
sql/sql_acl.cc:
Auto merged
sql/sql_base.cc:
Auto merged
sql/sql_cache.cc:
Auto merged
sql/sql_class.cc:
Auto merged
sql/sql_derived.cc:
Auto merged
sql/sql_insert.cc:
Auto merged
sql-common/client.c:
Auto merged
sql/sql_prepare.cc:
Auto merged
sql/sql_repl.cc:
Auto merged
sql/sql_show.cc:
Auto merged
libmysqld/lib_sql.cc:
SCCS merged
libmysqld/libmysqld.c:
SCCS merged
sql/sql_parse.cc:
SCCS merged
Diffstat (limited to 'libmysqld')
-rw-r--r-- | libmysqld/Makefile.am | 1 | ||||
-rw-r--r-- | libmysqld/lib_sql.cc | 93 | ||||
-rw-r--r-- | libmysqld/libmysqld.c | 86 |
3 files changed, 91 insertions, 89 deletions
diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index b22ff9e5001..09b03bce79a 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -22,6 +22,7 @@ MYSQLSHAREdir = $(pkgdatadir) MYSQLBASEdir= $(prefix) DEFS = -DEMBEDDED_LIBRARY -DMYSQL_SERVER \ + -DNO_EMBEDDED_ACCESS_CHECKS \ -DDEFAULT_MYSQL_HOME="\"$(MYSQLBASEdir)\"" \ -DDATADIR="\"$(MYSQLDATAdir)\"" \ -DSHAREDIR="\"$(MYSQLSHAREdir)\"" diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index df1e5b8f36c..38fc3cce9ee 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -33,6 +33,9 @@ static const char *fake_groups[] = { "server", "embedded", 0 }; #include "../sql/mysqld.cc" #endif +int check_user(THD *thd, enum enum_server_command command, + const char *passwd, uint passwd_len, const char *db, + bool check_count); C_MODE_START #include <mysql.h> #undef ER @@ -42,14 +45,6 @@ C_MODE_START static my_bool org_my_init_done; my_bool server_inited; -static int check_connections1(THD * thd); -static int check_connections2(THD * thd); -static bool check_user(THD *thd, enum_server_command command, - const char *user, const char *passwd, const char *db, - bool check_count); -char * get_mysql_home(){ return mysql_home;}; -char * get_mysql_real_data_home(){ return mysql_real_data_home;}; - static my_bool STDCALL emb_advanced_command(MYSQL *mysql, enum enum_server_command command, const char *header, ulong header_length, @@ -238,34 +233,6 @@ void THD::clear_error() net.report_error= 0; } -static bool check_user(THD *thd,enum_server_command command, const char *user, - const char *passwd, const char *db, bool check_count) -{ - thd->db=0; - - if (!(thd->user = my_strdup(user, MYF(0)))) - { - send_error(thd,ER_OUT_OF_RESOURCES); - return 1; - } - thd->master_access= ~0L; // No user checking - thd->priv_user= thd->user; - mysql_log.write(thd,command, - (thd->priv_user == thd->user ? - (char*) "%s@%s on %s" : - (char*) "%s@%s as anonymous on %s"), - user, - thd->host_or_ip, - db ? db : (char*) ""); - thd->db_access=0; - if (db && db[0]) - return test(mysql_change_db(thd,db)); - else - send_ok(thd); // Ready to handle questions - return 0; // ok -} - - /* Make a copy of array and the strings array points to */ @@ -360,7 +327,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) error_handler_hook = my_message_sql; - opt_noacl = 1; // No permissions +#ifndef NO_EMBEDDED_ACCESS_CHECKS if (acl_init((THD *)0, opt_noacl)) { mysql_server_end(); @@ -368,11 +335,16 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) } if (!opt_noacl) (void) grant_init((THD *)0); + +#endif + init_max_user_conn(); init_update_queries(); #ifdef HAVE_DLOPEN +#ifndef NO_EMBEDDED_ACCESS_CHECKS if (!opt_noacl) +#endif udf_init(); #endif @@ -465,8 +437,10 @@ void *create_embedded_thd(int client_flag, char *db) thd->db= db; thd->db_length= db ? strip_sp(db) : 0; +#ifndef NO_EMBEDDED_ACCESS_CHECKS thd->db_access= DB_ACLS; thd->master_access= ~NO_ACCESS; +#endif thd->net.query_cache_query= 0; thd->data= 0; @@ -474,6 +448,51 @@ void *create_embedded_thd(int client_flag, char *db) return thd; } +#ifndef NO_EMBEDDED_ACCESS_CHECKS +int check_embedded_connection(MYSQL *mysql) +{ + THD *thd= (THD*)mysql->thd; + int result; + 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; + thd->host_or_ip= thd->host; + + if (acl_check_host(thd->host,thd->ip)) + { + result= ER_HOST_NOT_PRIVILEGED; + goto err; + } + + thd->user= mysql->user; + if (mysql->passwd && mysql->passwd[0]) + { + memset(thd->scramble, 55, SCRAMBLE_LENGTH); // dummy scramble + thd->scramble[SCRAMBLE_LENGTH]= 0; + scramble(scramble_buff, thd->scramble, mysql->passwd); + passwd_len= SCRAMBLE_LENGTH; + } + else + passwd_len= 0; + + if((result= check_user(thd, COM_CONNECT, + scramble_buff, passwd_len, thd->db, true))) + goto err; + + return 0; +err: + { + NET *net= &mysql->net; + memcpy(net->last_error, thd->net.last_error, sizeof(net->last_error)); + memcpy(net->sqlstate, thd->net.sqlstate, sizeof(net->sqlstate)); + } + return result; +} +#endif + void free_embedded_thd(MYSQL *mysql) { THD *thd= (THD*)mysql->thd; 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; -} - |