diff options
Diffstat (limited to 'storage/connect/reldef.cpp')
-rw-r--r-- | storage/connect/reldef.cpp | 126 |
1 files changed, 85 insertions, 41 deletions
diff --git a/storage/connect/reldef.cpp b/storage/connect/reldef.cpp index 47f825e965d..60d515a61ca 100644 --- a/storage/connect/reldef.cpp +++ b/storage/connect/reldef.cpp @@ -17,7 +17,7 @@ /* Include relevant MariaDB header file. */ /***********************************************************************/ #include "my_global.h" -#if defined(WIN32) +#if defined(__WIN__) #include <sqlext.h> #else #include <dlfcn.h> // dlopen(), dlclose(), dlsym() ... @@ -48,14 +48,15 @@ #include "tabmul.h" #include "ha_connect.h" -#if !defined(WIN32) +#if !defined(__WIN__) extern handlerton *connect_hton; -#endif // !WIN32 +#endif // !__WIN__ /***********************************************************************/ /* External function. */ /***********************************************************************/ USETEMP UseTemp(void); +char *GetPluginDir(void); /* --------------------------- Class RELDEF -------------------------- */ @@ -246,7 +247,7 @@ bool TABDEF::Define(PGLOBAL g, PCATLG cat, LPCSTR name, LPCSTR am) /***********************************************************************/ PSZ TABDEF::GetPath(void) { - return (Database) ? (PSZ)Database : Hc->GetDataPath(); + return (Database) ? (PSZ)Database : (Hc) ? Hc->GetDataPath() : NULL; } // end of GetPath /***********************************************************************/ @@ -255,7 +256,8 @@ PSZ TABDEF::GetPath(void) int TABDEF::GetColCatInfo(PGLOBAL g) { char *type= GetStringCatInfo(g, "Type", "*"); - int i, loff, poff, nof, nlg; + char c, fty, eds; + int i, n, loff, poff, nof, nlg; void *field= NULL; TABTYPE tc; PCOLDEF cdp, lcdp= NULL, tocols= NULL; @@ -322,7 +324,7 @@ int TABDEF::GetColCatInfo(PGLOBAL g) if ((nof= cdp->Define(g, NULL, pcf, poff)) < 0) return -1; // Error, probably unhandled type - else if (nof) + else loff= cdp->GetOffset(); switch (tc) { @@ -330,20 +332,52 @@ int TABDEF::GetColCatInfo(PGLOBAL g) cdp->SetOffset(0); // Not to have shift case TAB_BIN: // BIN/VEC are packed by default - if (nof) + if (nof) { // Field width is the internal representation width // that can also depend on the column format - switch (cdp->Fmt ? *cdp->Fmt : 'X') { - case 'C': break; + fty = cdp->Decode ? 'C' : 'X'; + eds = 0; + n = 0; + + if (cdp->Fmt && !cdp->Decode) { + for (i = 0; cdp->Fmt[i]; i++) { + c = toupper(cdp->Fmt[i]); + + if (isdigit(c)) + n = (n * 10 + (c - '0')); + else if (c == 'L' || c == 'B' || c == 'H') + eds = c; + else + fty = c; + + } // endfor i + + } // endif Fmt + + if (n) + nof = n; + else switch (fty) { + case 'X': + if (eds && IsTypeChar(cdp->Buf_Type)) + nof = sizeof(longlong); + else + nof= cdp->Clen; + + break; + case 'C': break; case 'R': - case 'F': - case 'L': - case 'I': nof= 4; break; - case 'D': nof= 8; break; - case 'S': nof= 2; break; - case 'T': nof= 1; break; - default: nof= cdp->Clen; - } // endswitch Fmt + case 'F': nof = sizeof(float); break; + case 'I': nof = sizeof(int); break; + case 'D': nof = sizeof(double); break; + case 'S': nof = sizeof(short); break; + case 'T': nof = sizeof(char); break; + case 'G': nof = sizeof(longlong); break; + default: /* Wrong format */ + sprintf(g->Message, "Invalid format %c", fty); + return -1; + } // endswitch fty + + } // endif nof default: break; @@ -369,20 +403,16 @@ int TABDEF::GetColCatInfo(PGLOBAL g) // not specified (for instance if quoted is specified) // if ((ending= Hc->GetIntegerOption("Ending")) < 0) { if ((ending= Hc->GetIntegerOption("Ending")) <= 0) { -#if defined(WIN32) - ending= 2; -#else - ending= 1; -#endif + ending= (tc == TAB_BIN || tc == TAB_VEC) ? 0 : CRLF; Hc->SetIntegerOption("Ending", ending); } // endif ending // Calculate the default record size switch (tc) { case TAB_FIX: + case TAB_BIN: recln= nlg + ending; // + length of line ending break; - case TAB_BIN: case TAB_VEC: recln= nlg; @@ -433,20 +463,31 @@ void TABDEF::SetIndexInfo(void) PTABDEF OEMDEF::GetXdef(PGLOBAL g) { typedef PTABDEF (__stdcall *XGETDEF) (PGLOBAL, void *); - char c, getname[40] = "Get"; + char c, soname[_MAX_PATH], getname[40] = "Get"; PTABDEF xdefp; XGETDEF getdef = NULL; PCATLG cat = Cat; -#if defined(WIN32) + /*********************************************************************/ + /* 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()); + +#if defined(__WIN__) // Is the DLL already loaded? - if (!Hdll && !(Hdll = GetModuleHandle(Module))) + if (!Hdll && !(Hdll = GetModuleHandle(soname))) // No, load the Dll implementing the function - 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); @@ -467,10 +508,11 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) FreeLibrary((HMODULE)Hdll); return NULL; } // endif getdef -#else // !WIN32 +#else // !__WIN__ const char *error = NULL; Dl_info dl_info; - + +#if 0 // Don't know what all this stuff does // The OEM lib must retrieve exported CONNECT variables if (dladdr(&connect_hton, &dl_info)) { if (dlopen(dl_info.dli_fname, RTLD_NOLOAD | RTLD_NOW | RTLD_GLOBAL) == 0) { @@ -484,15 +526,16 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) sprintf(g->Message, "dladdr failed: %s, OEM not supported", SVP(error)); return NULL; } // endif dladdr +#endif // 0 // Is the library already loaded? -// if (!Hdll && !(Hdll = ???)) - // Load the desired shared library - if (!(Hdll = dlopen(Module, RTLD_LAZY))) { - error = dlerror(); - sprintf(g->Message, MSG(SHARED_LIB_ERR), Module, SVP(error)); - return NULL; - } // endif Hdll + if (!Hdll && !(Hdll = dlopen(soname, RTLD_NOLOAD))) + // Load the desired shared library + if (!(Hdll = dlopen(soname, RTLD_LAZY))) { + error = dlerror(); + sprintf(g->Message, MSG(SHARED_LIB_ERR), soname, SVP(error)); + return NULL; + } // endif Hdll // The exported name is always in uppercase for (int i = 0; ; i++) { @@ -508,7 +551,7 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) dlclose(Hdll); return NULL; } // endif getdef -#endif // !WIN32 +#endif // !__WIN__ // Just in case the external Get function does not set error messages sprintf(g->Message, MSG(DEF_ALLOC_ERROR), Subtype); @@ -548,7 +591,7 @@ bool OEMDEF::DeleteTableFile(PGLOBAL g) /***********************************************************************/ /* Define: initialize the table definition block from XDB file. */ /***********************************************************************/ -bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) +bool OEMDEF::DefineAM(PGLOBAL g, LPCSTR, int) { Module = GetStringCatInfo(g, "Module", ""); Subtype = GetStringCatInfo(g, "Subtype", Module); @@ -715,7 +758,7 @@ COLDEF::COLDEF(void) : COLCRT() /***********************************************************************/ /* Define: initialize a column definition from a COLINFO structure. */ /***********************************************************************/ -int COLDEF::Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff) +int COLDEF::Define(PGLOBAL g, void *, PCOLINFO cfp, int poff) { Name = (PSZ)PlugDup(g, cfp->Name); @@ -745,7 +788,8 @@ int COLDEF::Define(PGLOBAL g, void *memp, PCOLINFO cfp, int poff) if (cfp->Datefmt) Decode = (PSZ)PlugDup(g, cfp->Datefmt); - } // endif special + } else + Offset = poff; if (cfp->Fieldfmt) Fmt = (PSZ)PlugDup(g, cfp->Fieldfmt); |