Skip to content

Commit cd16280

Browse files
committed
- mysql_load_plugin_v supports now the environment variable MARIADB_PLUGIN_DIR
to load plugins from a different destination than PLUGINDIR. - added dialog plugin for authentication (e.g. PAM). If an application provides it's own dialog function, the name must be mariadb_auth_dialog (or for libmysql compatibility mysql_authentication_dialog_ask). Windows-Todo: 1. provide a simple GUI dialog on windows, in case opening the console failed. 2. convert data from console code page to character set of current connection
1 parent 6bfad6e commit cd16280

File tree

12 files changed

+340
-46
lines changed

12 files changed

+340
-46
lines changed

cmake/install.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ SET(BIN_INSTALL_DIR_DEFAULT "bin")
7676
SET(LIB_INSTALL_DIR_DEFAULT "lib")
7777
SET(INCLUDE_INSTALL_DIR_DEFAULT "include")
7878
SET(DOCS_INSTALL_DIR_DEFAULT "docs")
79-
SET(LIB_INSTALL_PLUGIN_DIR_DEFAULT "lib/plugins")
79+
SET(PLUGIN_INSTALL_DIR_DEFAULT "lib/plugin")
8080

8181
#
8282
# RPM layout
@@ -85,15 +85,15 @@ SET(SUFFIX_INSTALL_DIR_RPM "mariadb")
8585
SET(BIN_INSTALL_DIR_RPM "bin")
8686
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
8787
SET(LIB_INSTALL_DIR_RPM "lib64")
88-
SET(LIB_INSTALL_PLUGINDIR_RPM "lib64/plugins")
88+
SET(PLUGIN_INSTALL_DIRDIR_RPM "lib64/plugin")
8989
ELSE()
9090
SET(LIB_INSTALL_DIR_RPM "lib")
91-
SET(LIB_INSTALL_PLUGINDIR_RPM "lib/plugins")
91+
SET(PLUGIN_INSTALL_DIRDIR_RPM "lib/plugin")
9292
ENDIF()
9393

9494
SET(INCLUDE_INSTALL_DIR_RPM "include")
9595
SET(DOCS_INSTALL_DIR_RPM "docs")
96-
SET(LIB_INSTALL_PLUGIN_DIR_RPM "lib/plugins")
96+
SET(PLUGIN_INSTALL_DIR_RPM "lib/plugin")
9797

9898
#
9999
# Overwrite defaults
@@ -102,6 +102,10 @@ IF(LIB_INSTALL_DIR)
102102
SET(LIB_INSTALL_DIR_${INSTALL_LAYOUT} ${LIB_INSTALL_DIR})
103103
ENDIF()
104104

105+
IF(PLUGIN_INSTALL_DIR)
106+
SET(PLUGIN_INSTALL_DIR_${INSTALL_LAYOUT} ${PLUGIN_INSTALL_DIR})
107+
ENDIF()
108+
105109
IF(INCLUDE_INSTALL_DIR)
106110
SET(INCLUDE_INSTALL_DIR_${INSTALL_LAYOUT} ${INCLUDE_INSTALL_DIR})
107111
ENDIF()
@@ -118,7 +122,7 @@ IF(NOT SUFFIX_INSTALL_DIR)
118122
SET(SUFFIX_INSTALL_DIR_${INSTALL_LAYOUT} "mariadb")
119123
ENDIF()
120124

121-
FOREACH(dir "BIN" "LIB" "INCLUDE" "DOCS" "PREFIX" "SUFFIX")
125+
FOREACH(dir "BIN" "LIB" "INCLUDE" "DOCS" "PREFIX" "SUFFIX" "PLUGIN")
122126
SET(${dir}_INSTALL_DIR ${${dir}_INSTALL_DIR_${INSTALL_LAYOUT}})
123127
MARK_AS_ADVANCED(${dir}_INSTALL_DIR)
124128
ENDFOREACH()

include/my_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,5 @@
274274
#cmakedefine HAVE_THREADS 1
275275
#cmakedefine SHAREDIR "@SHAREDIR@"
276276
#cmakedefine DEFAULT_CHARSET_HOME "@DEFAULT_CHARSET_HOME@"
277-
#cmakedefine PLUGINDIR "@PLUGINDIR@"
277+
#cmakedefine PLUGINDIR "@PREFIX_INSTALL_DIR@/@PLUGIN_INSTALL_DIR@"
278278

include/mysql/client_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab
2+
2014 MariaDB Corporation AB
23
34
This library is free software; you can redistribute it and/or
45
modify it under the terms of the GNU Library General Public

include/mysql_com.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ enum enum_server_command
173173
CLIENT_MULTI_STATEMENTS |\
174174
CLIENT_MULTI_RESULTS |\
175175
CLIENT_PROGRESS |\
176-
CLIENT_SSL_VERIFY_SERVER_CERT |\
176+
CLIENT_SSL_VERIFY_SERVER_CERT |\
177177
CLIENT_REMEMBER_OPTIONS |\
178+
CLIENT_PLUGIN_AUTH |\
178179
CLIENT_CONNECT_ATTRS)
179180

180181
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD |\
@@ -384,7 +385,6 @@ char *scramble_323(char *to,const char *message,const char *password);
384385
void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password);
385386
my_bool check_scramble(const char *, const char *message,
386387
unsigned long *salt,my_bool old_ver);
387-
char *get_tty_password(char *opt_message);
388388
void hash_password(unsigned long *result, const char *password, size_t len);
389389

390390
/* Some other useful functions */

libmariadb/client_plugin.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
346346
char dlpath[FN_REFLEN+1];
347347
void *sym, *dlhandle;
348348
struct st_mysql_client_plugin *plugin;
349+
char *env_plugin_dir= getenv("MARIADB_PLUGIN_DIR");
349350

350351
if (is_not_initialized(mysql, name))
351352
return NULL;
@@ -362,7 +363,8 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type,
362363
/* Compile dll path */
363364
strxnmov(dlpath, sizeof(dlpath) - 1,
364365
mysql->options.extension && mysql->options.extension->plugin_dir ?
365-
mysql->options.extension->plugin_dir : PLUGINDIR, "/",
366+
mysql->options.extension->plugin_dir : (env_plugin_dir) ? env_plugin_dir :
367+
PLUGINDIR, "/",
366368
name, SO_EXT, NullS);
367369

368370
/* Open new dll handle */

libmariadb/get_password.c

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,83 @@
6363
#endif
6464

6565
#if defined( _WIN32) || defined(OS2)
66-
/* were just going to fake it here and get input from the keyboard */
66+
/* {{{ statuc char* get_password */
67+
/*
68+
reads password from tty/console
69+
70+
SYNOPSIS
71+
get_password()
72+
buffer input buffer
73+
length length of input buffer
6774
68-
char *get_tty_password(char *opt_message)
75+
DESCRIPTION
76+
reads a password from console (Windows) or tty without echoing
77+
it's characters. Input buffer must be allocated by calling function.
78+
79+
RETURNS
80+
buffer pointer to input buffer
81+
*/
82+
char* get_tty_password(char *prompt, char *buffer, int length)
6983
{
70-
char to[80];
71-
char *pos=to,*end=to+sizeof(to)-1;
72-
int i=0;
73-
DBUG_ENTER("get_tty_password");
74-
fprintf(stdout,opt_message ? opt_message : "Enter password: ");
75-
for (;;)
84+
#ifdef _WIN32
85+
DWORD SaveState;
86+
HANDLE Hdl;
87+
int Offset= 0;
88+
DWORD CharsProcessed= 0;
89+
char inChar;
90+
91+
ZeroMemory(buffer, length);
92+
93+
if (!(Hdl= CreateFile("CONIN$",
94+
GENERIC_READ | GENERIC_WRITE,
95+
FILE_SHARE_READ,
96+
NULL,
97+
OPEN_EXISTING, 0, NULL)))
7698
{
77-
char tmp;
78-
tmp=_getch();
79-
if (tmp == '\b' || (int) tmp == 127)
80-
{
81-
if (pos != to)
99+
/* todo: provide a graphical dialog */
100+
return buffer;
101+
}
102+
/* Save ConsoleMode and set ENABLE_PROCESSED_INPUT:
103+
CTRL+C is processed by the system and is not placed in the input buffer */
104+
GetConsoleMode(Hdl, &SaveState);
105+
SetConsoleMode(Hdl, ENABLE_PROCESSED_INPUT);
106+
107+
do
108+
{
109+
if (!ReadConsole(Hdl, &inChar, 1, &CharsProcessed, NULL) ||
110+
!CharsProcessed)
111+
break;
112+
113+
switch(inChar) {
114+
case '\b': /* backslash */
115+
if (Offset)
82116
{
83-
_cputs("\b \b");
84-
pos--;
85-
continue;
117+
/* cursor is always at the end */
118+
Offset--;
119+
buffer[Offset]= 0;
120+
_cputs("\b \b");
86121
}
87-
}
88-
if (tmp == '\n' || tmp == '\r' || tmp == 3)
89122
break;
90-
if (iscntrl(tmp) || pos == end)
91-
continue;
92-
_cputs("*");
93-
*(pos++) = tmp;
94-
}
95-
while (pos != to && isspace(pos[-1]) == ' ')
96-
pos--; /* Allow dummy space at end */
97-
*pos=0;
98-
_cputs("\n");
99-
DBUG_RETURN(my_strdup(to,MYF(MY_FAE)));
100-
}
123+
case '\n':
124+
case '\r':
125+
break;
126+
default:
127+
buffer[Offset]= inChar;
128+
if (Offset < length - 2)
129+
Offset++;
130+
_cputs("*");
131+
break;
132+
}
133+
} while (CharsProcessed && inChar != '\n' && inChar != '\r');
134+
SetConsoleMode(Hdl, SaveState);
135+
CloseHandle(Hdl);
136+
return buffer;
101137

102138
#else
139+
#endif
140+
}
141+
/* }}} */
142+
#else
103143

104144

105145
#ifndef HAVE_GETPASS
@@ -150,22 +190,21 @@ static void get_password(char *to,uint length,int fd,bool echo)
150190
#endif /* ! HAVE_GETPASS */
151191

152192

153-
char *get_tty_password(char *opt_message)
193+
char *get_tty_password(char *opt_message, char *buff, int bufflen)
154194
{
155195
#ifdef HAVE_GETPASS
156196
char *passbuff;
157197
#else /* ! HAVE_GETPASS */
158198
TERMIO org,tmp;
159199
#endif /* HAVE_GETPASS */
160-
char buff[80];
161200

162201
DBUG_ENTER("get_tty_password");
163202

164203
#ifdef HAVE_GETPASS
165204
passbuff = getpass(opt_message ? opt_message : "Enter password: ");
166205

167206
/* copy the password to buff and clear original (static) buffer */
168-
strnmov(buff, passbuff, sizeof(buff) - 1);
207+
strnmov(buff, passbuff, bufflen - 1);
169208
#ifdef _PASSWORD_LEN
170209
memset(passbuff, 0, _PASSWORD_LEN);
171210
#endif
@@ -182,7 +221,7 @@ char *get_tty_password(char *opt_message)
182221
tmp.c_cc[VMIN] = 1;
183222
tmp.c_cc[VTIME] = 0;
184223
tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
185-
get_password(buff, sizeof(buff)-1, fileno(stdin), isatty(fileno(stdout)));
224+
get_password(buff, bufflen-1, fileno(stdin), isatty(fileno(stdout)));
186225
tcsetattr(fileno(stdin), TCSADRAIN, &org);
187226
#elif defined(HAVE_TERMIO_H)
188227
ioctl(fileno(stdin), (int) TCGETA, &org);
@@ -191,21 +230,21 @@ char *get_tty_password(char *opt_message)
191230
tmp.c_cc[VMIN] = 1;
192231
tmp.c_cc[VTIME]= 0;
193232
ioctl(fileno(stdin),(int) TCSETA, &tmp);
194-
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
233+
get_password(buff,bufflen-1,fileno(stdin),isatty(fileno(stdout)));
195234
ioctl(fileno(stdin),(int) TCSETA, &org);
196235
#else
197236
gtty(fileno(stdin), &org);
198237
tmp=org;
199238
tmp.sg_flags &= ~ECHO;
200239
tmp.sg_flags |= RAW;
201240
stty(fileno(stdin), &tmp);
202-
get_password(buff,sizeof(buff)-1,fileno(stdin),isatty(fileno(stdout)));
241+
get_password(buff,bufflen-1,fileno(stdin),isatty(fileno(stdout)));
203242
stty(fileno(stdin), &org);
204243
#endif
205244
if (isatty(fileno(stdout)))
206245
fputc('\n',stdout);
207246
#endif /* HAVE_GETPASS */
208247

209-
DBUG_RETURN(my_strdup(buff,MYF(MY_FAE)));
248+
DBUG_RETURN(buff);
210249
}
211250
#endif /*_WIN32*/

mariadb_config/mariadb_config.c.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@extra_dynamic_LDFLAGS@"
99
#define CFLAGS INCLUDE " @CMAKE_C_FLAGS@"
1010
#define VERSION "@MYSQL_CLIENT_VERSION@"
11+
#define PLUGIN_DIR "@PREFIX_INSTALL_DIR@/@PLUGIN_INSTALL_DIR@"
1112
#define SOCKET "@MYSQL_UNIX_ADDR@"
1213
#define PORT "@MYSQL_PORT@"
1314

@@ -21,6 +22,7 @@ static struct option long_options[]=
2122
{"version", no_argument, 0, 'f'},
2223
{"socket", no_argument, 0, 'g'},
2324
{"port", no_argument, 0, 'h'},
25+
{"plugindir", no_argument, 0, 'p'},
2426
{NULL, 0, 0, 0}
2527
};
2628

@@ -33,7 +35,8 @@ static char *values[]=
3335
LIBS,
3436
VERSION,
3537
SOCKET,
36-
PORT
38+
PORT,
39+
PLUGIN_DIR
3740
};
3841

3942
void usage(void)
@@ -90,6 +93,9 @@ int main(int argc, char **argv)
9093
case 'h':
9194
puts(PORT);
9295
break;
96+
case 'p':
97+
puts(PLUGINDIR);
98+
break;
9399
default:
94100
exit(0);
95101
}

plugins/auth/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Dialog plugin
2+
SET(DIALOG_SOURCES dialog.c ${CMAKE_SOURCE_DIR}/libmariadb/get_password.c)
3+
IF(WIN32)
4+
SET(DIALOG_SOURCES ${DIALOG_SOURCES} ${CMAKE_SOURCE_DIR}/plugins/plugin.def)
5+
ENDIF()
6+
ADD_LIBRARY(dialog SHARED ${DIALOG_SOURCES})
7+
SET_TARGET_PROPERTIES(dialog PROPERTIES PREFIX "")
8+
9+
INSTALL(TARGETS
10+
dialog
11+
RUNTIME DESTINATION "${PLUGIN_INSTALL_DIR}"
12+
LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}"
13+
ARCHIVE DESTINATION "${PLUGIN_INSTALL_DIR}")

0 commit comments

Comments
 (0)