diff options
29 files changed, 202 insertions, 93 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 82ffaa22032..0ce28fa90c6 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -4319,9 +4319,10 @@ char *get_arg(char *line, my_bool get_next_arg) string, and the "dialog" plugin will free() it. */ -extern "C" char *mysql_authentication_dialog_ask(MYSQL *mysql, int type, - const char *prompt, - char *buf, int buf_len) +MYSQL_PLUGIN_EXPORT +char *mysql_authentication_dialog_ask(MYSQL *mysql, int type, + const char *prompt, + char *buf, int buf_len) { char *s=buf; diff --git a/client/mysqltest.cc b/client/mysqltest.cc index cf1b81d6169..45de35ab84b 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -117,6 +117,7 @@ static my_bool disable_connect_log= 1; static my_bool disable_warnings= 0; static my_bool prepare_warnings_enabled= 0; static my_bool disable_info= 1; +static char *opt_plugin_dir= 0, *opt_default_auth; static my_bool abort_on_error= 1; static my_bool server_initialized= 0; static my_bool is_windows= 0; @@ -6235,6 +6236,13 @@ static struct my_option my_long_options[] = {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select.", &view_protocol, &view_protocol, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.", + (uchar**) &opt_plugin_dir, (uchar**) &opt_plugin_dir, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"default_auth", OPT_PLUGIN_DIR, + "Default authentication client-side plugin to use.", + (uchar**) &opt_default_auth, (uchar**) &opt_default_auth, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -8218,6 +8226,12 @@ int main(int argc, char **argv) if (opt_protocol) mysql_options(con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol); + if (opt_plugin_dir && *opt_plugin_dir) + mysql_options(con->mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir); + + if (opt_default_auth && *opt_default_auth) + mysql_options(con->mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); + #ifdef HAVE_OPENSSL if (opt_use_ssl) @@ -10176,3 +10190,33 @@ static int setenv(const char *name, const char *value, int overwrite) return 0; } #endif + +/* + for the purpose of testing (see dialog.test) + we replace default mysql_authentication_dialog_ask function with the one, + that always reads from stdin with explicit echo. + +*/ +MYSQL_PLUGIN_EXPORT +char *mysql_authentication_dialog_ask(MYSQL *mysql, int type, + const char *prompt, + char *buf, int buf_len) +{ + char *s=buf; + + fputs(prompt, stdout); + fputs(" ", stdout); + + if (!fgets(buf, buf_len-1, stdin)) + buf[0]= 0; + else if (buf[0] && (s= strend(buf))[-1] == '\n') + s[-1]= 0; + + for (s= buf; *s; s++) + fputc(type == 2 ? '*' : *s, stdout); + + fputc('\n', stdout); + + return buf; +} + diff --git a/include/my_global.h b/include/my_global.h index 92aa2352621..58147f85ee3 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1520,18 +1520,20 @@ do { doubleget_union _tmp; \ #define NO_EMBEDDED_ACCESS_CHECKS #endif -#ifdef HAVE_DLOPEN -#if defined(__WIN__) +#if defined(_WIN32) #define dlsym(lib, name) GetProcAddress((HMODULE)lib, name) #define dlopen(libname, unused) LoadLibraryEx(libname, NULL, 0) #define dlclose(lib) FreeLibrary((HMODULE)lib) -#elif defined(HAVE_DLFCN_H) +#define HAVE_DLOPEN +#endif + +#ifdef HAVE_DLFCN_H #include <dlfcn.h> #endif + #ifndef HAVE_DLERROR #define dlerror() "" #endif -#endif /* FreeBSD 2.2.2 does not define RTLD_NOW) */ #ifndef RTLD_NOW diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 6e71f886eba..44f07c8a541 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -139,6 +139,7 @@ void get_salt_from_password(unsigned char *res, const char *password); void make_password_from_salt(char *to, const unsigned char *hash_stage2); char *octet2hex(char *to, const char *str, unsigned int len); char *get_tty_password(const char *opt_message); +void get_tty_password_buff(const char *opt_message, char *to, size_t length); const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); my_bool my_thread_init(void); void my_thread_end(void); diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h index 33c63b9df33..f463277c530 100644 --- a/include/mysql/client_plugin.h +++ b/include/mysql/client_plugin.h @@ -28,9 +28,7 @@ #include <stdlib.h> #endif -#ifdef MYSQL_PLUGIN_EXPORT #undef MYSQL_PLUGIN_EXPORT -#endif #if defined(_MSC_VER) #ifdef __cplusplus #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport) @@ -38,7 +36,11 @@ #define MYSQL_PLUGIN_EXPORT __declspec(dllexport) #endif #else /*_MSC_VER */ -#define MYSQL_PLUGIN_EXPORT + #ifdef __cplusplus + #define MYSQL_PLUGIN_EXPORT extern "C" + #else + #define MYSQL_PLUGIN_EXPORT + #endif #endif /* known plugin types */ diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index bacc4bd7bd8..b8f4ad6f3fc 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -25,21 +25,17 @@ for functions. */ #if defined(_MSC_VER) -#if defined(MYSQL_DYNAMIC_PLUGIN) #ifdef __cplusplus #define MYSQL_PLUGIN_EXPORT extern "C" __declspec(dllexport) #else #define MYSQL_PLUGIN_EXPORT __declspec(dllexport) #endif -#else /* MYSQL_DYNAMIC_PLUGIN */ +#else /*_MSC_VER */ #ifdef __cplusplus - #define MYSQL_PLUGIN_EXPORT extern "C" + #define MYSQL_PLUGIN_EXPORT extern "C" #else - #define MYSQL_PLUGIN_EXPORT + #define MYSQL_PLUGIN_EXPORT #endif -#endif /*MYSQL_DYNAMIC_PLUGIN */ -#else /*_MSC_VER */ -#define MYSQL_PLUGIN_EXPORT #endif #ifdef __cplusplus @@ -129,14 +125,20 @@ struct st_maria_plugin DECLS[]= { #else #define __MYSQL_DECLARE_PLUGIN(NAME, VERSION, PSIZE, DECLS) \ -MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \ -MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \ -MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]= { - -#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \ -MYSQL_PLUGIN_EXPORT int _maria_plugin_interface_version_= MARIA_PLUGIN_INTERFACE_VERSION; \ -MYSQL_PLUGIN_EXPORT int _maria_sizeof_struct_st_plugin_= sizeof(struct st_maria_plugin); \ -MYSQL_PLUGIN_EXPORT struct st_maria_plugin _maria_plugin_declarations_[]= { +MYSQL_PLUGIN_EXPORT int _mysql_plugin_interface_version_; \ +int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION; \ +MYSQL_PLUGIN_EXPORT int _mysql_sizeof_struct_st_plugin_; \ +int _mysql_sizeof_struct_st_plugin_= sizeof(struct st_mysql_plugin); \ +MYSQL_PLUGIN_EXPORT struct st_mysql_plugin _mysql_plugin_declarations_[]; \ +struct st_mysql_plugin _mysql_plugin_declarations_[]= { + +#define MARIA_DECLARE_PLUGIN__(NAME, VERSION, PSIZE, DECLS) \ +MYSQL_PLUGIN_EXPORT int _maria_plugin_interface_version_; \ +int _maria_plugin_interface_version_= MARIA_PLUGIN_INTERFACE_VERSION; \ +MYSQL_PLUGIN_EXPORT int _maria_sizeof_struct_st_plugin_; \ +int _maria_sizeof_struct_st_plugin_= sizeof(struct st_maria_plugin); \ +MYSQL_PLUGIN_EXPORT struct st_maria_plugin _maria_plugin_declarations_[]; \ +struct st_maria_plugin _maria_plugin_declarations_[]= { #endif diff --git a/include/mysql_com.h b/include/mysql_com.h index affd24a4636..d7441036a98 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -517,6 +517,7 @@ char *octet2hex(char *to, const char *str, unsigned int len); /* end of password.c */ char *get_tty_password(const char *opt_message); +void get_tty_password_buff(const char *opt_message, char *to, size_t length); const char *mysql_errno_to_sqlstate(unsigned int mysql_errno); /* Some other useful functions */ diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt index 2e99b2a001d..aa6ea8dc851 100755 --- a/libmysql/CMakeLists.txt +++ b/libmysql/CMakeLists.txt @@ -120,7 +120,6 @@ IF(WIN32) ENDIF(WIN32) ADD_DEPENDENCIES(libmysql GenError) TARGET_LINK_LIBRARIES(libmysql mysqlclient ws2_32) -ADD_DEFINITIONS(-DHAVE_DLOPEN) MYSQL_INSTALL_TARGETS(mysqlclient DESTINATION lib COMPONENT Development) MYSQL_INSTALL_TARGETS(libmysql DESTINATION lib COMPONENT SharedLibraries) diff --git a/libmysql/get_password.c b/libmysql/get_password.c index cbe5fce6949..747d598d72a 100644 --- a/libmysql/get_password.c +++ b/libmysql/get_password.c @@ -75,12 +75,10 @@ #define _cputs(A) putstring(A) #endif -char *get_tty_password(const char *opt_message) +void get_tty_password_buff(const char *opt_message, char *to, size_t length) { - char to[80]; - char *pos=to,*end=to+sizeof(to)-1; + char *pos=to,*end=to+length-1; int i=0; - DBUG_ENTER("get_tty_password"); _cputs(opt_message ? opt_message : "Enter password: "); for (;;) { @@ -106,7 +104,6 @@ char *get_tty_password(const char *opt_message) pos--; /* Allow dummy space at end */ *pos=0; _cputs("\n"); - DBUG_RETURN(my_strdup(to,MYF(MY_FAE))); } #else @@ -159,22 +156,19 @@ static void get_password(char *to,uint length,int fd, my_bool echo) #endif /* ! HAVE_GETPASS */ -char *get_tty_password(const char *opt_message) +void get_tty_password_buff(const char *opt_message, char *buff, size_t buflen) { #ifdef HAVE_GETPASS char *passbuff; #else /* ! HAVE_GETPASS */ TERMIO org,tmp; #endif /* HAVE_GETPASS */ - char buff[80]; - - DBUG_ENTER("get_tty_password"); #ifdef HAVE_GETPASS passbuff = getpass(opt_message ? opt_message : "Enter password: "); /* copy the password to buff and clear original (static) buffer */ - strnmov(buff, passbuff, sizeof(buff) - 1); + strnmov(buff, passbuff, buflen - 1); #ifdef _PASSWORD_LEN memset(passbuff, 0, _PASSWORD_LEN); #endif @@ -191,7 +185,7 @@ char *get_tty_password(const char *opt_message) tmp.c_cc[VMIN] = 1; tmp.c_cc[VTIME] = 0; tcsetattr(fileno(stdin), TCSADRAIN, &tmp); - get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stdout))); + get_password(buff, buflen, fileno(stdin), isatty(fileno(stdout))); tcsetattr(fileno(stdin), TCSADRAIN, &org); #elif defined(HAVE_TERMIO_H) ioctl(fileno(stdin), (int) TCGETA, &org); @@ -200,7 +194,7 @@ char *get_tty_password(const char *opt_message) tmp.c_cc[VMIN] = 1; tmp.c_cc[VTIME]= 0; ioctl(fileno(stdin),(int) TCSETA, &tmp); - get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout))); + get_password(buff,buflen-1,fileno(stdin),isatty(fileno(stdout))); ioctl(fileno(stdin),(int) TCSETA, &org); #else gtty(fileno(stdin), &org); @@ -208,13 +202,20 @@ char *get_tty_password(const char *opt_message) tmp.sg_flags &= ~ECHO; tmp.sg_flags |= RAW; stty(fileno(stdin), &tmp); - get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout))); + get_password(buff,buflen-1,fileno(stdin),isatty(fileno(stdout))); stty(fileno(stdin), &org); #endif if (isatty(fileno(stdout))) fputc('\n',stdout); #endif /* HAVE_GETPASS */ - - DBUG_RETURN(my_strdup(buff,MYF(MY_FAE))); } #endif /*__WIN__*/ + +#ifndef MYSQL_DYNAMIC_PLUGIN +char *get_tty_password(const char *opt_message) +{ + char buff[80]; + get_tty_password_buff(opt_message, buff, sizeof(buff)); + return my_strdup(buff, MYF(MY_FAE)); +} +#endif diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index d964def7505..c4ca3d62afe 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -21,7 +21,7 @@ IF(WIN32) ADD_DEFINITIONS(-DUSE_TLS) ENDIF(WIN32) -ADD_DEFINITIONS(-DMYSQL_SERVER -DEMBEDDED_LIBRARY -DHAVE_DLOPEN) +ADD_DEFINITIONS(-DMYSQL_SERVER -DEMBEDDED_LIBRARY) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/libmysqld diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index ddf8d0457f3..b73771391c2 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -110,7 +110,7 @@ TEST_DIRS = t r include std_data std_data/parts collections \ suite/innodb suite/innodb/t suite/innodb/r suite/innodb/include \ suite/innodb_plugin suite/innodb_plugin/t suite/innodb_plugin/r \ suite/innodb_plugin/include \ - suite/percona suite/handler \ + suite/percona suite/handler suite/plugins suite/plugins/t suite/plugins/r \ suite/engines suite/engines/funcs suite/engines/iuds suite/engines/rr_trx \ suite/engines/funcs/r suite/engines/funcs/t suite/engines/iuds/r \ suite/engines/iuds/t suite/engines/rr_trx/include suite/engines/rr_trx/r \ diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index bc3518ed2bc..dc03a6bf5b5 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -160,7 +160,7 @@ my $path_config_file; # The generated config file, var/my.cnf # executables will be used by the test suite. our $opt_vs_config = $ENV{'MTR_VS_CONFIG'}; -my $DEFAULT_SUITES= "main,binlog,federated,rpl,maria,handler,parts,innodb,innodb_plugin,percona,ndb,vcol,oqgraph,sphinx"; +my $DEFAULT_SUITES= "main,binlog,federated,rpl,maria,handler,parts,innodb,innodb_plugin,percona,ndb,vcol,oqgraph,sphinx,plugins"; my $opt_suites; our $opt_verbose= 0; # Verbose output, enable with --verbose diff --git a/mysql-test/suite/plugins/r/dialog.result b/mysql-test/suite/plugins/r/dialog.result new file mode 100644 index 00000000000..da3117fd491 --- /dev/null +++ b/mysql-test/suite/plugins/r/dialog.result @@ -0,0 +1,26 @@ +install plugin three_attempts soname 'dialog.so'; +create user test_dialog identified via three_attempts using 'SECRET'; +# +# -pSECRET is picked up, no questions asked. +# +select user(), current_user(); +user() current_user() +test_dialog@localhost test_dialog@% +# +# without -p. up to three questions are asked on the stdin. +# athentication is successful, the correct pasword is on the third line +# +Password, please: *** +Password, please: **** +Password, please: ****** +select user(), current_user(); +user() current_user() +test_dialog@localhost test_dialog@% +# +# athentication is unsuccessful, first three lines are all wrong +# +Password, please: *** +Password, please: **** +Password, please: ***** +drop user test_dialog; +uninstall plugin three_attempts; diff --git a/mysql-test/r/feedback_plugin_install.result b/mysql-test/suite/plugins/r/feedback_plugin_install.result index b1b35072a08..b1b35072a08 100644 --- a/mysql-test/r/feedback_plugin_install.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_install.result diff --git a/mysql-test/r/feedback_plugin_load.result b/mysql-test/suite/plugins/r/feedback_plugin_load.result index d434d1282c5..d434d1282c5 100644 --- a/mysql-test/r/feedback_plugin_load.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_load.result diff --git a/mysql-test/r/feedback_plugin_send.result b/mysql-test/suite/plugins/r/feedback_plugin_send.result index db622cb3f97..db622cb3f97 100644 --- a/mysql-test/r/feedback_plugin_send.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_send.result diff --git a/mysql-test/r/fulltext_plugin.result b/mysql-test/suite/plugins/r/fulltext_plugin.result index 69ebbe07e9e..69ebbe07e9e 100644 --- a/mysql-test/r/fulltext_plugin.result +++ b/mysql-test/suite/plugins/r/fulltext_plugin.result diff --git a/mysql-test/suite/plugins/t/dialog.test b/mysql-test/suite/plugins/t/dialog.test new file mode 100644 index 00000000000..47452643609 --- /dev/null +++ b/mysql-test/suite/plugins/t/dialog.test @@ -0,0 +1,51 @@ +# +# test for the client "dialog" plugin +# + +--source include/not_embedded.inc + +if (!$DIALOG_SO) { + skip No dialog auth plugin; +} + +--replace_result .dll .so +eval install plugin three_attempts soname '$DIALOG_SO'; +create user test_dialog identified via three_attempts using 'SECRET'; + +let $plugindir=`SELECT @@global.plugin_dir`; + +--write_file $MYSQLTEST_VARDIR/tmp/dialog_good.txt +foo +1234 +SECRET +select user(), current_user(); +EOF + +--write_file $MYSQLTEST_VARDIR/tmp/dialog_bad.txt +foo +1234 +wrong +SECRET +EOF + +--echo # +--echo # -pSECRET is picked up, no questions asked. +--echo # +--exec echo "select user(), current_user();"|$MYSQL_TEST -u test_dialog -pSECRET --plugin-dir=$plugindir + +--echo # +--echo # without -p. up to three questions are asked on the stdin. +--echo # athentication is successful, the correct pasword is on the third line +--echo # +--exec $MYSQL_TEST -u test_dialog --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/dialog_good.txt + +--echo # +--echo # athentication is unsuccessful, first three lines are all wrong +--echo # +--error 1 +--exec $MYSQL_TEST -u test_dialog --plugin-dir=$plugindir < $MYSQLTEST_VARDIR/tmp/dialog_bad.txt + +--remove_file $MYSQLTEST_VARDIR/tmp/dialog_good.txt +--remove_file $MYSQLTEST_VARDIR/tmp/dialog_bad.txt +drop user test_dialog; +uninstall plugin three_attempts; diff --git a/mysql-test/t/feedback_plugin_install.opt b/mysql-test/suite/plugins/t/feedback_plugin_install.opt index a711ae94e69..a711ae94e69 100644 --- a/mysql-test/t/feedback_plugin_install.opt +++ b/mysql-test/suite/plugins/t/feedback_plugin_install.opt diff --git a/mysql-test/t/feedback_plugin_install.test b/mysql-test/suite/plugins/t/feedback_plugin_install.test index 81343c436c3..81343c436c3 100644 --- a/mysql-test/t/feedback_plugin_install.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_install.test diff --git a/mysql-test/t/feedback_plugin_load.opt b/mysql-test/suite/plugins/t/feedback_plugin_load.opt index 5fbb2f83954..5fbb2f83954 100644 --- a/mysql-test/t/feedback_plugin_load.opt +++ b/mysql-test/suite/plugins/t/feedback_plugin_load.opt diff --git a/mysql-test/t/feedback_plugin_load.test b/mysql-test/suite/plugins/t/feedback_plugin_load.test index 5ad301667b4..5ad301667b4 100644 --- a/mysql-test/t/feedback_plugin_load.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_load.test diff --git a/mysql-test/t/feedback_plugin_send.test b/mysql-test/suite/plugins/t/feedback_plugin_send.test index d882539cfea..3324ef469fe 100644 --- a/mysql-test/t/feedback_plugin_send.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_send.test @@ -1,4 +1,4 @@ -source t/feedback_plugin_load.test; +source feedback_plugin_load.test; if (!$MTR_FEEDBACK_PLUGIN) { skip MTR_FEEDBACK_PLUGIN is not set; diff --git a/mysql-test/t/fulltext_plugin.test b/mysql-test/suite/plugins/t/fulltext_plugin.test index 0e2f53d5b15..0e2f53d5b15 100644 --- a/mysql-test/t/fulltext_plugin.test +++ b/mysql-test/suite/plugins/t/fulltext_plugin.test diff --git a/plugin/auth/CMakeLists.txt b/plugin/auth/CMakeLists.txt index 931a47fec5e..2174826b2cd 100644 --- a/plugin/auth/CMakeLists.txt +++ b/plugin/auth/CMakeLists.txt @@ -1,3 +1,3 @@ INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake") -SET(AUTH_SOURCES dialog.c) +SET(AUTH_SOURCES dialog.c ${CMAKE_SOURCE_DIR}/libmysql/get_password.c) MYSQL_PLUGIN(AUTH) diff --git a/plugin/auth/Makefile.am b/plugin/auth/Makefile.am index acca98e26f8..2995d35adf4 100644 --- a/plugin/auth/Makefile.am +++ b/plugin/auth/Makefile.am @@ -4,7 +4,7 @@ AM_LDFLAGS=-module -rpath $(pkgplugindir) AM_CPPFLAGS=-DMYSQL_DYNAMIC_PLUGIN -I$(top_srcdir)/include pkgplugin_LTLIBRARIES= dialog.la -dialog_la_SOURCES= dialog.c +dialog_la_SOURCES= dialog.c $(top_srcdir)/libmysql/get_password.c if HAVE_PEERCRED pkgplugin_LTLIBRARIES+= auth_socket.la diff --git a/plugin/auth/dialog.c b/plugin/auth/dialog.c index 76b2ddae528..24765c17d1c 100644 --- a/plugin/auth/dialog.c +++ b/plugin/auth/dialog.c @@ -142,36 +142,6 @@ static struct st_mysql_auth three_handler= three_attempts }; -mysql_declare_plugin(dialog) -{ - MYSQL_AUTHENTICATION_PLUGIN, - &two_handler, - "two_questions", - "Sergei Golubchik", - "Dialog plugin demo 1", - PLUGIN_LICENSE_GPL, - NULL, - NULL, - 0x0100, - NULL, - NULL, - NULL -}, -{ - MYSQL_AUTHENTICATION_PLUGIN, - &three_handler, - "three_attempts", - "Sergei Golubchik", - "Dialog plugin demo 2", - PLUGIN_LICENSE_GPL, - NULL, - NULL, - 0x0100, - NULL, - NULL, - NULL -} -mysql_declare_plugin_end; maria_declare_plugin(dialog) { MYSQL_AUTHENTICATION_PLUGIN, @@ -186,7 +156,7 @@ maria_declare_plugin(dialog) NULL, NULL, "1.0", - MariaDB_PLUGIN_MATURITY_BETA + MariaDB_PLUGIN_MATURITY_EXPERIMENTAL }, { MYSQL_AUTHENTICATION_PLUGIN, @@ -201,7 +171,7 @@ maria_declare_plugin(dialog) NULL, NULL, "1.0", - MariaDB_PLUGIN_MATURITY_BETA + MariaDB_PLUGIN_MATURITY_EXPERIMENTAL } maria_declare_plugin_end; @@ -224,16 +194,25 @@ static char *builtin_ask(MYSQL *mysql __attribute__((unused)), const char *prompt, char *buf, int buf_len) { - int len; - fputs(prompt, stdout); fputc(' ', stdout); - if (fgets(buf, buf_len, stdin) == 0) - return 0; - len= strlen(buf); - if (len && buf[len-1]=='\n') - buf[len-1]=0; + if (type == 2) /* password */ + { + get_tty_password_buff("", buf, buf_len); + buf[buf_len-1]= 0; + } + else + { + if (!fgets(buf, buf_len-1, stdin)) + buf[0]= 0; + else + { + int len= strlen(buf); + if (len && buf[len-1] == '\n') + buf[len-1]= 0; + } + } return buf; } @@ -261,6 +240,7 @@ static int perform_dialog(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) unsigned char *pkt, cmd= 0; int pkt_len, res; char reply_buf[1024], *reply; + int first = 1; do { @@ -269,7 +249,7 @@ static int perform_dialog(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) if (pkt_len < 0) return CR_ERROR; - if (pkt == 0) + if (pkt == 0 && first) { /* in mysql_change_user() the client sends the first packet, so @@ -291,10 +271,10 @@ static int perform_dialog(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return CR_OK_HANDSHAKE_COMPLETE; /* yes. we're done */ /* - asking for a password with an empty prompt means mysql->password + asking for a password in the first packet mean mysql->password, if it's set otherwise we ask the user and read the reply */ - if ((cmd >> 1) == 2 && *pkt == 0) + if ((cmd >> 1) == 2 && first && mysql->passwd[0]) reply= mysql->passwd; else reply= ask(mysql, cmd >> 1, (char*) pkt, reply_buf, sizeof(reply_buf)); diff --git a/plugin/feedback/feedback.h b/plugin/feedback/feedback.h index df9020fc37e..f9e2cd34231 100644 --- a/plugin/feedback/feedback.h +++ b/plugin/feedback/feedback.h @@ -12,9 +12,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef MYSQL_SERVER -#define MYSQL_SERVER -#endif + +#define MYSQL_SERVER 1 #include <mysql_priv.h> namespace feedback { diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index e281b187149..6255402e3ab 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -36,7 +36,7 @@ SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/sql/sql_yacc.h ${CMAKE_BINARY_DIR}/include/sql_state.h PROPERTIES GENERATED 1) -ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_DLOPEN -DHAVE_EVENT_SCHEDULER) +ADD_DEFINITIONS(-DMYSQL_SERVER -D_CONSOLE -DHAVE_EVENT_SCHEDULER) IF(WITH_FEEDBACK_STORAGE_ENGINE) ADD_DEFINITIONS(-DWITH_FEEDBACK_PLUGIN) ENDIF() |