summaryrefslogtreecommitdiff
path: root/libmysqld/libmysqld.c
diff options
context:
space:
mode:
authorunknown <hf@deer.(none)>2003-09-26 15:33:13 +0500
committerunknown <hf@deer.(none)>2003-09-26 15:33:13 +0500
commit1705369809aaa17407ce0bd25fdd15607cdf32b0 (patch)
treef4b60e9394c6d88f0bd04731d87ae6203e987e3b /libmysqld/libmysqld.c
parent4535f6897f5ee132d086e0bd98bbc3a1fdaea54a (diff)
downloadmariadb-git-1705369809aaa17407ce0bd25fdd15607cdf32b0.tar.gz
SCRUM:
WL#604 Privileges in embedded library code added to check privileges in embedded library NO_EMBEDDED_ACCESS_CHECKS macros inserted in code so we can exclude access-checking parts. Actually we now can exclude these parts from standalone server as well. Do we need it? Access checks are disabled in embedded server by default. One should edit libmysqld/Makefile manually to get this working. We definitely need the separate configure for embedded server include/mysql.h: options added so user of embedded library can set the client host it will work as if the usual client connects from this host libmysqld/Makefile.am: Usually one doesn't need access checking in embedded library we definitely should separate configure for embedded server libmysqld/lib_sql.cc: necessary code for getting passwords and access checks added libmysqld/libmysqld.c: code #ifdef-ed - we use this only when we check permissions sql-common/client.c: one mysql_close left now sql/item_strfunc.cc: #ifndef-s added sql/log.cc: #ifndef-s added sql/mysql_priv.h: #ifndef-s added also i removed default parameters from check_access and check_table_access definitions to set definitions working sql/mysqld.cc: #ifndef-s added localhost renamed to my_localhost sql/repl_failsafe.cc: parameters added sql/set_var.cc: #ifndef-s added sql/sql_acl.cc: #ifndef-s added sql/sql_acl.h: #ifndef-s added sql/sql_base.cc: #ifndef-s added sql/sql_cache.cc: #ifndef-s added sql/sql_class.cc: #ifndef-s added sql/sql_db.cc: #ifndef-s added sql/sql_derived.cc: #ifndef-s added sql/sql_insert.cc: #ifndef-s added sql/sql_parse.cc: a horde of #ifndef-s added sql/sql_prepare.cc: #ifndef-s added sql/sql_repl.cc: parameters added sql/sql_show.cc: #ifndef-s added sql/sql_update.cc: #ifndef-s added
Diffstat (limited to 'libmysqld/libmysqld.c')
-rw-r--r--libmysqld/libmysqld.c83
1 files changed, 34 insertions, 49 deletions
diff --git a/libmysqld/libmysqld.c b/libmysqld/libmysqld.c
index 67dc00e4c1b..e3a46733288 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,51 +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));
- }
- DBUG_VOID_RETURN;
-}
-