diff options
Diffstat (limited to 'storage/connect/mycat.cc')
-rw-r--r-- | storage/connect/mycat.cc | 95 |
1 files changed, 63 insertions, 32 deletions
diff --git a/storage/connect/mycat.cc b/storage/connect/mycat.cc index b15c8fa2322..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,10 +66,10 @@ #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" @@ -93,13 +93,33 @@ /***********************************************************************/ /* 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,7 +142,7 @@ TABTYPE GetTypeID(const char *type) : (!stricmp(type, "MYSQL")) ? TAB_MYSQL : (!stricmp(type, "MYPRX")) ? TAB_MYSQL : (!stricmp(type, "DIR")) ? TAB_DIR -#ifdef WIN32 +#ifdef __WIN__ : (!stricmp(type, "MAC")) ? TAB_MAC : (!stricmp(type, "WMI")) ? TAB_WMI #endif @@ -328,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; @@ -343,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]; @@ -350,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); @@ -370,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 @@ -387,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); @@ -395,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 @@ -411,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; @@ -458,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); @@ -478,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)); @@ -523,10 +554,10 @@ 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; @@ -589,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 |