summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-09-04 13:35:14 +0200
committerSergei Golubchik <serg@mariadb.org>2016-09-12 17:51:49 +0200
commited0b84a0270bd99b001dd00654875d26e29b9432 (patch)
treeecdff364c7f3e6816bcdeae3e32d325b0681c01e /sql-common
parent4ba198c6e3c7ccf4da2a87c14043bb3be08915f7 (diff)
downloadmariadb-git-ed0b84a0270bd99b001dd00654875d26e29b9432.tar.gz
remove libmysql/
also disable server's client plugins when C/C has the same
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/conf_to_src.c144
-rw-r--r--sql-common/errmsg.c129
-rw-r--r--sql-common/get_password.c227
3 files changed, 500 insertions, 0 deletions
diff --git a/sql-common/conf_to_src.c b/sql-common/conf_to_src.c
new file mode 100644
index 00000000000..0e92388c93c
--- /dev/null
+++ b/sql-common/conf_to_src.c
@@ -0,0 +1,144 @@
+/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
+
+/* can't use -lmysys because this prog is used to create -lstrings */
+
+
+#include <my_global.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+
+#define CHARSETS_SUBDIR "sql/share/charsets"
+#define CTYPE_TABLE_SIZE 257
+#define TO_LOWER_TABLE_SIZE 256
+#define TO_UPPER_TABLE_SIZE 256
+#define SORT_ORDER_TABLE_SIZE 256
+#define ROW_LEN 16
+
+void print_arrays_for(char *set);
+
+char *prog;
+char buf[1024], *p, *endptr;
+
+int
+main(int argc, char **argv)
+{
+ prog = *argv;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog);
+ exit(EXIT_FAILURE);
+ }
+
+ --argc; ++argv; /* skip program name */
+
+ if (chdir(*argv) != 0) {
+ fprintf(stderr, "%s: can't cd to %s\n", prog, *argv);
+ exit(EXIT_FAILURE);
+ }
+ --argc; ++argv;
+
+ if (chdir(CHARSETS_SUBDIR) != 0) {
+ fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR);
+ exit(EXIT_FAILURE);
+ }
+
+ while (argc--)
+ print_arrays_for(*argv++);
+
+ exit(EXIT_SUCCESS);
+}
+
+void
+print_array(FILE *f, const char *set, const char *name, int n)
+{
+ int i;
+ char val[100];
+
+ printf("uchar %s_%s[] = {\n", name, set);
+
+ p = buf;
+ *buf = '\0';
+ for (i = 0; i < n; ++i)
+ {
+ /* get a word from f */
+ endptr = p;
+ for (;;)
+ {
+ while (isspace(*endptr))
+ ++endptr;
+ if (*endptr && *endptr != '#') /* not comment */
+ break;
+ if ((fgets(buf, sizeof(buf), f)) == NULL)
+ return; /* XXX: break silently */
+ endptr = buf;
+ }
+
+ p = val;
+ while (!isspace(*endptr))
+ *p++ = *endptr++;
+ *p = '\0';
+ p = endptr;
+
+ /* write the value out */
+
+ if (i == 0 || i % ROW_LEN == n % ROW_LEN)
+ printf(" ");
+
+ printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16));
+
+ if (i < n - 1)
+ printf(",");
+
+ if ((i+1) % ROW_LEN == n % ROW_LEN)
+ printf("\n");
+ }
+
+ printf("};\n\n");
+}
+
+void
+print_arrays_for(char *set)
+{
+ FILE *f;
+
+ snprintf(buf, sizeof(buf), "%s.conf", set);
+
+ if ((f = fopen(buf, "r")) == NULL) {
+ fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("\
+/* The %s character set. Generated automatically by configure and\n\
+ * the %s program\n\
+ */\n\n",
+ set, prog);
+
+ /* it would be nice if this used the code in mysys/charset.c, but... */
+ print_array(f, set, "ctype", CTYPE_TABLE_SIZE);
+ print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE);
+ print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE);
+ print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE);
+ printf("\n");
+
+ fclose(f);
+
+ return;
+}
diff --git a/sql-common/errmsg.c b/sql-common/errmsg.c
new file mode 100644
index 00000000000..fc5a6a07e11
--- /dev/null
+++ b/sql-common/errmsg.c
@@ -0,0 +1,129 @@
+/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+/* Error messages for MySQL clients */
+/* (Error messages for the daemon are in share/language/errmsg.sys) */
+
+#include <my_global.h>
+#include <my_sys.h>
+#include "errmsg.h"
+
+const char *client_errors[]=
+{
+ "Unknown MySQL error",
+ "Can't create UNIX socket (%d)",
+ "Can't connect to local MySQL server through socket '%-.100s' (%M)",
+ "Can't connect to MySQL server on '%-.100s' (%M)",
+ "Can't create TCP/IP socket (%M)",
+ "Unknown MySQL server host '%-.100s' (%d)",
+ "MySQL server has gone away",
+ "Protocol mismatch; server version = %d, client version = %d",
+ "MySQL client ran out of memory",
+ "Wrong host info",
+ "Localhost via UNIX socket",
+ "%-.100s via TCP/IP",
+ "Error in server handshake",
+ "Lost connection to MySQL server during query",
+ "Commands out of sync; you can't run this command now",
+ "Named pipe: %-.32s",
+ "Can't wait for named pipe to host: %-.64s pipe: %-.32s (%lu)",
+ "Can't open named pipe to host: %-.64s pipe: %-.32s (%lu)",
+ "Can't set state of named pipe to host: %-.64s pipe: %-.32s (%lu)",
+ "Can't initialize character set %-.32s (path: %-.100s)",
+ "Got packet bigger than 'max_allowed_packet' bytes",
+ "Embedded server",
+ "Error on SHOW SLAVE STATUS:",
+ "Error on SHOW SLAVE HOSTS:",
+ "Error connecting to slave:",
+ "Error connecting to master:",
+ "SSL connection error: %-.100s",
+ "Malformed packet",
+ "This client library is licensed only for use with MySQL servers having '%s' license",
+ "Invalid use of null pointer",
+ "Statement not prepared",
+ "No data supplied for parameters in prepared statement",
+ "Data truncated",
+ "No parameters exist in the statement",
+ "Invalid parameter number",
+ "Can't send long data for non-string/non-binary data types (parameter: %d)",
+ "Using unsupported buffer type: %d (parameter: %d)",
+ "Shared memory: %-.100s",
+ "Can't open shared memory; client could not create request event (%lu)",
+ "Can't open shared memory; no answer event received from server (%lu)",
+ "Can't open shared memory; server could not allocate file mapping (%lu)",
+ "Can't open shared memory; server could not get pointer to file mapping (%lu)",
+ "Can't open shared memory; client could not allocate file mapping (%lu)",
+ "Can't open shared memory; client could not get pointer to file mapping (%lu)",
+ "Can't open shared memory; client could not create %s event (%lu)",
+ "Can't open shared memory; no answer from server (%lu)",
+ "Can't open shared memory; cannot send request event to server (%lu)",
+ "Wrong or unknown protocol",
+ "Invalid connection handle",
+ "Connection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)",
+ "Row retrieval was canceled by mysql_stmt_close() call",
+ "Attempt to read column without prior row fetch",
+ "Prepared statement contains no metadata",
+ "Attempt to read a row while there is no result set associated with the statement",
+ "This feature is not implemented yet",
+ "Lost connection to MySQL server at '%s', system error: %M",
+ "Statement closed indirectly because of a preceding %s() call",
+ "The number of columns in the result set differs from the number of bound buffers. You must reset the statement, rebind the result set columns, and execute the statement again",
+ "This handle is already connected. Use a separate handle for each connection.",
+ "Authentication plugin '%s' cannot be loaded: %s",
+ "There is an attribute with the same name already",
+ "Authentication plugin '%s' reported error: %s",
+ ""
+};
+
+const char** get_client_errmsgs(int nr __attribute__((unused)))
+{
+ return client_errors;
+}
+
+/*
+ Register client error messages for use with my_error().
+
+ SYNOPSIS
+ init_client_errs()
+
+ RETURN
+ void
+*/
+
+void init_client_errs(void)
+{
+ compile_time_assert(array_elements(client_errors) ==
+ (CR_ERROR_LAST - CR_ERROR_FIRST + 2));
+ (void) my_error_register(get_client_errmsgs, CR_ERROR_FIRST, CR_ERROR_LAST);
+}
+
+
+/*
+ Unregister client error messages.
+
+ SYNOPSIS
+ finish_client_errs()
+
+ RETURN
+ void
+*/
+
+void finish_client_errs(void)
+{
+ (void) my_error_unregister(CR_ERROR_FIRST, CR_ERROR_LAST);
+}
diff --git a/sql-common/get_password.c b/sql-common/get_password.c
new file mode 100644
index 00000000000..a113306ed57
--- /dev/null
+++ b/sql-common/get_password.c
@@ -0,0 +1,227 @@
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+/*
+** Ask for a password from tty
+** This is an own file to avoid conflicts with curses
+*/
+#include <my_global.h>
+#include <my_sys.h>
+#include "mysql.h"
+#include <m_string.h>
+#include <m_ctype.h>
+
+#ifdef HAVE_GETPASS
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif /* HAVE_PWD_H */
+#else /* ! HAVE_GETPASS */
+#if !defined(__WIN__)
+#include <sys/ioctl.h>
+#ifdef HAVE_TERMIOS_H /* For tty-password */
+#include <termios.h>
+#define TERMIO struct termios
+#else
+#ifdef HAVE_TERMIO_H /* For tty-password */
+#include <termio.h>
+#define TERMIO struct termio
+#else
+#include <sgtty.h>
+#define TERMIO struct sgttyb
+#endif
+#endif
+#ifdef alpha_linux_port
+#include <asm/ioctls.h>
+#include <asm/termiobits.h>
+#endif
+#else
+#include <conio.h>
+#endif /* __WIN__ */
+#endif /* HAVE_GETPASS */
+
+#ifdef HAVE_GETPASSPHRASE /* For Solaris */
+#define getpass(A) getpassphrase(A)
+#endif
+
+#if defined(__WIN__)
+/* were just going to fake it here and get input from the keyboard */
+void get_tty_password_buff(const char *opt_message, char *to, size_t length)
+{
+ HANDLE consoleinput;
+ DWORD oldstate;
+ char *pos=to,*end=to+length-1;
+ int i=0;
+
+ consoleinput= CreateFile("CONIN$", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ ,
+ NULL, OPEN_EXISTING, 0, NULL);
+ if (consoleinput == NULL || consoleinput == INVALID_HANDLE_VALUE)
+ {
+ /* This is a GUI application or service without console input, bail out. */
+ *to= 0;
+ return;
+ }
+ _cputs(opt_message ? opt_message : "Enter password: ");
+
+ /*
+ Switch to raw mode (no line input, no echo input).
+ Allow Ctrl-C handler with ENABLE_PROCESSED_INPUT.
+ */
+ GetConsoleMode(consoleinput, &oldstate);
+ SetConsoleMode(consoleinput, ENABLE_PROCESSED_INPUT);
+ for (;;)
+ {
+ char tmp;
+ DWORD chars_read;
+ if (!ReadConsole(consoleinput, &tmp, 1, &chars_read, NULL))
+ break;
+ if (chars_read == 0)
+ break;
+ if (tmp == '\b' || tmp == 127)
+ {
+ if (pos != to)
+ {
+ _cputs("\b \b");
+ pos--;
+ continue;
+ }
+ }
+ if (tmp == '\n' || tmp == '\r')
+ break;
+ if (iscntrl(tmp) || pos == end)
+ continue;
+ _cputs("*");
+ *(pos++) = tmp;
+ }
+ /* Reset console mode after password input. */
+ SetConsoleMode(consoleinput, oldstate);
+ CloseHandle(consoleinput);
+ *pos=0;
+ _cputs("\n");
+}
+
+#else
+
+#ifndef HAVE_GETPASS
+/*
+ Can't use fgets, because readline will get confused
+ length is max number of chars in to, not counting \0
+ to will not include the eol characters.
+*/
+
+static void get_password(char *to,uint length,int fd, my_bool echo)
+{
+ char *pos=to,*end=to+length;
+
+ for (;;)
+ {
+ char tmp;
+ if (my_read(fd,&tmp,1,MYF(0)) != 1)
+ break;
+ if (tmp == '\b' || (int) tmp == 127)
+ {
+ if (pos != to)
+ {
+ if (echo)
+ {
+ fputs("\b \b",stdout);
+ fflush(stdout);
+ }
+ pos--;
+ continue;
+ }
+ }
+ if (tmp == '\n' || tmp == '\r' || tmp == 3)
+ break;
+ if (iscntrl(tmp) || pos == end)
+ continue;
+ if (echo)
+ {
+ fputc('*',stdout);
+ fflush(stdout);
+ }
+ *(pos++) = tmp;
+ }
+ *pos=0;
+ return;
+}
+#endif /* ! HAVE_GETPASS */
+
+
+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 */
+
+#ifdef HAVE_GETPASS
+ passbuff = getpass(opt_message ? opt_message : "Enter password: ");
+
+ /* copy the password to buff and clear original (static) buffer */
+ strncpy(buff, passbuff, buflen - 1);
+#ifdef _PASSWORD_LEN
+ memset(passbuff, 0, _PASSWORD_LEN);
+#endif
+#else
+ if (isatty(fileno(stdout)))
+ {
+ fputs(opt_message ? opt_message : "Enter password: ",stdout);
+ fflush(stdout);
+ }
+#if defined(HAVE_TERMIOS_H)
+ tcgetattr(fileno(stdin), &org);
+ tmp = org;
+ tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
+ tmp.c_cc[VMIN] = 1;
+ tmp.c_cc[VTIME] = 0;
+ tcsetattr(fileno(stdin), TCSADRAIN, &tmp);
+ 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);
+ tmp=org;
+ tmp.c_lflag &= ~(ECHO | ISIG | ICANON);
+ tmp.c_cc[VMIN] = 1;
+ tmp.c_cc[VTIME]= 0;
+ ioctl(fileno(stdin),(int) TCSETA, &tmp);
+ get_password(buff,buflen-1,fileno(stdin),isatty(fileno(stdout)));
+ ioctl(fileno(stdin),(int) TCSETA, &org);
+#else
+ gtty(fileno(stdin), &org);
+ tmp=org;
+ tmp.sg_flags &= ~ECHO;
+ tmp.sg_flags |= RAW;
+ stty(fileno(stdin), &tmp);
+ 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 */
+}
+#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