diff options
author | Sergei Golubchik <sergii@pisem.net> | 2012-01-13 15:50:02 +0100 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2012-01-13 15:50:02 +0100 |
commit | 4f435bddfd44d40999f88685c61cc04e319d8d6c (patch) | |
tree | f9d0655a0d901b87f918a736741144b502cba3f6 /plugin/auth_dialog/dialog.c | |
parent | 8c2bcdf85ff753bceeb5b235f3605e348e6f9e1d (diff) | |
parent | 6ca4ca7d37fed3b3da18666768de6a2f8c34bc7b (diff) | |
download | mariadb-git-4f435bddfd44d40999f88685c61cc04e319d8d6c.tar.gz |
5.3 merge
Diffstat (limited to 'plugin/auth_dialog/dialog.c')
-rw-r--r-- | plugin/auth_dialog/dialog.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/plugin/auth_dialog/dialog.c b/plugin/auth_dialog/dialog.c index 9f974f6898f..2026369bc26 100644 --- a/plugin/auth_dialog/dialog.c +++ b/plugin/auth_dialog/dialog.c @@ -43,7 +43,7 @@ To support all this variety, the dialog plugin has a callback function "authentication_dialog_ask". If the client has a function of this name dialog plugin will use it for communication with the user. Otherwise - a default fgets() based implementation will be used. + a default implementation will be used. */ static mysql_authentication_dialog_ask_t ask; @@ -52,13 +52,25 @@ static char *builtin_ask(MYSQL *mysql __attribute__((unused)), const char *prompt, char *buf, int buf_len) { - char *ptr; fputs(prompt, stdout); fputc(' ', stdout); - if (fgets(buf, buf_len, stdin) == NULL) - return NULL; - if ((ptr= strchr(buf, '\n'))) - *ptr= 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; } @@ -84,6 +96,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 { @@ -92,13 +105,13 @@ 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 the first vio->read_packet() does nothing (pkt == 0). - We send the "password", assuming the client knows what it's doing. + We send the "password", assuming the client knows what its doing. (in other words, the dialog plugin should be only set as a default authentication plugin on the client if the first question asks for a password - which will be sent in clear text, by the way) @@ -114,10 +127,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, (const char *) pkt, |