summaryrefslogtreecommitdiff
path: root/storage/connect/mycat.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/connect/mycat.cc')
-rw-r--r--storage/connect/mycat.cc108
1 files changed, 66 insertions, 42 deletions
diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc
index 0ae0537ba6f..9c72e9cd665 100644
--- a/storage/connect/mycat.cc
+++ b/storage/connect/mycat.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) Olivier Bertrand 2004 - 2014
+/* Copyright (C) Olivier Bertrand 2004 - 2015
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
@@ -18,7 +18,7 @@
/* ------------- */
/* Version 1.4 */
/* */
-/* Author: Olivier Bertrand 2012 - 2014 */
+/* Author: Olivier Bertrand 2012 - 2015 */
/* */
/* WHAT THIS PROGRAM DOES: */
/* ----------------------- */
@@ -30,7 +30,7 @@
/***********************************************************************/
#include <my_config.h>
-#if defined(WIN32)
+#if defined(__WIN__)
//#include <windows.h>
//#include <sqlext.h>
#elif defined(UNIX)
@@ -66,21 +66,16 @@
#include "tabfmt.h"
#include "tabvct.h"
#include "tabsys.h"
-#if defined(WIN32)
+#if defined(__WIN__)
#include "tabmac.h"
#include "tabwmi.h"
-#endif // WIN32
+#endif // __WIN__
//#include "tabtbl.h"
#include "tabxcl.h"
#include "tabtbl.h"
#include "taboccur.h"
-#if defined(XML_SUPPORT)
-#include "tabxml.h"
-#endif // XML_SUPPORT
#include "tabmul.h"
-#if defined(MYSQL_SUPPORT)
#include "tabmysql.h"
-#endif // MYSQL_SUPPORT
#if defined(ODBC_SUPPORT)
#define NODBC
#include "tabodbc.h"
@@ -91,18 +86,40 @@
#include "tabvir.h"
#include "tabjson.h"
#include "ha_connect.h"
-#include "mycat.h"
+#if defined(XML_SUPPORT)
+#include "tabxml.h"
+#endif // XML_SUPPORT
/***********************************************************************/
/* Extern static variables. */
/***********************************************************************/
-#if defined(WIN32)
+#if defined(__WIN__)
extern "C" HINSTANCE s_hModule; // Saved module handle
-#endif // !WIN32
+#endif // !__WIN__
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
/***********************************************************************/
+/* Get the plugin directory. */
+/***********************************************************************/
+char *GetPluginDir(void)
+{
+ char *plugin_dir;
+
+#if defined(_WIN64)
+ plugin_dir = (char *)GetProcAddress(GetModuleHandle(NULL),
+ "?opt_plugin_dir@@3PADEA");
+#elif defined(_WIN32)
+ plugin_dir = (char*)GetProcAddress(GetModuleHandle(NULL),
+ "?opt_plugin_dir@@3PADA");
+#else
+ plugin_dir = opt_plugin_dir;
+#endif
+
+ return plugin_dir;
+} // end of GetPluginDir
+
+/***********************************************************************/
/* Get a unique enum table type ID. */
/***********************************************************************/
TABTYPE GetTypeID(const char *type)
@@ -122,12 +139,10 @@ TABTYPE GetTypeID(const char *type)
#ifdef ODBC_SUPPORT
: (!stricmp(type, "ODBC")) ? TAB_ODBC
#endif
-#ifdef MYSQL_SUPPORT
: (!stricmp(type, "MYSQL")) ? TAB_MYSQL
: (!stricmp(type, "MYPRX")) ? TAB_MYSQL
-#endif
: (!stricmp(type, "DIR")) ? TAB_DIR
-#ifdef WIN32
+#ifdef __WIN__
: (!stricmp(type, "MAC")) ? TAB_MAC
: (!stricmp(type, "WMI")) ? TAB_WMI
#endif
@@ -333,12 +348,12 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
{
typedef PQRYRES (__stdcall *XCOLDEF) (PGLOBAL, void*, char*, char*, bool);
const char *module, *subtype;
- char c, getname[40] = "Col";
-#if defined(WIN32)
+ char c, soname[_MAX_PATH], getname[40] = "Col";
+#if defined(__WIN__)
HANDLE hdll; /* Handle to the external DLL */
-#else // !WIN32
+#else // !__WIN__
void *hdll; /* Handle for the loaded shared library */
-#endif // !WIN32
+#endif // !__WIN__
XCOLDEF coldef = NULL;
PQRYRES qrp = NULL;
@@ -348,6 +363,17 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
if (!module || !subtype)
return NULL;
+ /*********************************************************************/
+ /* Ensure that the .dll doesn't have a path. */
+ /* This is done to ensure that only approved dll from the system */
+ /* directories are used (to make this even remotely secure). */
+ /*********************************************************************/
+ if (check_valid_path(module, strlen(module))) {
+ strcpy(g->Message, "Module cannot contain a path");
+ return NULL;
+ } else
+ PlugSetPath(soname, module, GetPluginDir());
+
// The exported name is always in uppercase
for (int i = 0; ; i++) {
c = subtype[i];
@@ -355,13 +381,13 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
if (!c) break;
} // endfor i
-#if defined(WIN32)
+#if defined(__WIN__)
// Load the Dll implementing the table
- if (!(hdll = LoadLibrary(module))) {
+ if (!(hdll = LoadLibrary(soname))) {
char buf[256];
DWORD rc = GetLastError();
- sprintf(g->Message, MSG(DLL_LOAD_ERROR), rc, module);
+ sprintf(g->Message, MSG(DLL_LOAD_ERROR), rc, soname);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0,
(LPTSTR)buf, sizeof(buf), NULL);
@@ -375,13 +401,13 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
FreeLibrary((HMODULE)hdll);
return NULL;
} // endif coldef
-#else // !WIN32
+#else // !__WIN__
const char *error = NULL;
// Load the desired shared library
- if (!(hdll = dlopen(module, RTLD_LAZY))) {
+ if (!(hdll = dlopen(soname, RTLD_LAZY))) {
error = dlerror();
- sprintf(g->Message, MSG(SHARED_LIB_ERR), module, SVP(error));
+ sprintf(g->Message, MSG(SHARED_LIB_ERR), soname, SVP(error));
return NULL;
} // endif Hdll
@@ -392,7 +418,7 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
dlclose(hdll);
return NULL;
} // endif coldef
-#endif // !WIN32
+#endif // !__WIN__
// Just in case the external Get function does not set error messages
sprintf(g->Message, "Error getting column info from %s", subtype);
@@ -400,11 +426,11 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
// Get the table column definition
qrp = coldef(g, topt, tab, db, info);
-#if defined(WIN32)
+#if defined(__WIN__)
FreeLibrary((HMODULE)hdll);
-#else // !WIN32
+#else // !__WIN__
dlclose(hdll);
-#endif // !WIN32
+#endif // !__WIN__
return qrp;
} // end of OEMColumns
@@ -416,11 +442,11 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info)
/***********************************************************************/
CATALOG::CATALOG(void)
{
-#if defined(WIN32)
+#if defined(__WIN__)
//DataPath= ".\\";
-#else // !WIN32
+#else // !__WIN__
//DataPath= "./";
-#endif // !WIN32
+#endif // !__WIN__
memset(&Ctb, 0, sizeof(CURTAB));
Cbuf= NULL;
Cblen= 0;
@@ -463,11 +489,11 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
}
if (*path != '.') {
-#if defined(WIN32)
+#if defined(__WIN__)
char *s= "\\";
-#else // !WIN32
+#else // !__WIN__
char *s= "/";
-#endif // !WIN32
+#endif // !__WIN__
strcat(strcat(strcat(strcpy(buf, "."), s), path), s);
} else
strcpy(buf, path);
@@ -483,7 +509,7 @@ void MYCAT::SetPath(PGLOBAL g, LPCSTR *datapath, const char *path)
/* Look for a table descriptor matching the name and type. */
/***********************************************************************/
PRELDEF MYCAT::GetTableDesc(PGLOBAL g, LPCSTR name,
- LPCSTR type, PRELDEF *prp)
+ LPCSTR type, PRELDEF *)
{
if (trace)
printf("GetTableDesc: name=%s am=%s\n", name, SVP(type));
@@ -528,18 +554,16 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, LPCSTR name, LPCSTR am)
#if defined(ODBC_SUPPORT)
case TAB_ODBC: tdp= new(g) ODBCDEF; break;
#endif // ODBC_SUPPORT
-#if defined(WIN32)
+#if defined(__WIN__)
case TAB_MAC: tdp= new(g) MACDEF; break;
case TAB_WMI: tdp= new(g) WMIDEF; break;
-#endif // WIN32
+#endif // __WIN__
case TAB_OEM: tdp= new(g) OEMDEF; break;
case TAB_TBL: tdp= new(g) TBLDEF; break;
case TAB_XCL: tdp= new(g) XCLDEF; break;
case TAB_PRX: tdp= new(g) PRXDEF; break;
case TAB_OCCUR: tdp= new(g) OCCURDEF; break;
-#if defined(MYSQL_SUPPORT)
case TAB_MYSQL: tdp= new(g) MYSQLDEF; break;
-#endif // MYSQL_SUPPORT
#if defined(PIVOT_SUPPORT)
case TAB_PIVOT: tdp= new(g) PIVOTDEF; break;
#endif // PIVOT_SUPPORT
@@ -596,7 +620,7 @@ PTDB MYCAT::GetTable(PGLOBAL g, PTABLE tablep, MODE mode, LPCSTR type)
/***********************************************************************/
/* ClearDB: Terminates Database usage. */
/***********************************************************************/
-void MYCAT::ClearDB(PGLOBAL g)
+void MYCAT::ClearDB(PGLOBAL)
{
} // end of ClearDB