/ OEMColumns: Get table column info for an OEM table. */ /
| 67 | /* OEMColumns: Get table column info for an OEM table. */ |
| 68 | /***********************************************************************/ |
| 69 | PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char* tab, char* db, bool info) |
| 70 | { |
| 71 | typedef PQRYRES(__stdcall* XCOLDEF) (PGLOBAL, void*, char*, char*, bool); |
| 72 | const char* module, * subtype; |
| 73 | char c, soname[_MAX_PATH], getname[40] = "Col"; |
| 74 | #if defined(_WIN32) |
| 75 | HANDLE hdll; /* Handle to the external DLL */ |
| 76 | #else // !_WIN32 |
| 77 | void* hdll; /* Handle for the loaded shared library */ |
| 78 | #endif // !_WIN32 |
| 79 | XCOLDEF coldef = NULL; |
| 80 | PQRYRES qrp = NULL; |
| 81 | |
| 82 | module = topt->module; |
| 83 | subtype = topt->subtype; |
| 84 | |
| 85 | if (!module || !subtype) |
| 86 | return NULL; |
| 87 | |
| 88 | /*********************************************************************/ |
| 89 | /* Ensure that the .dll doesn't have a path. */ |
| 90 | /* This is done to ensure that only approved dll from the system */ |
| 91 | /* directories are used (to make this even remotely secure). */ |
| 92 | /*********************************************************************/ |
| 93 | if (check_valid_path(module, strlen(module))) { |
| 94 | safe_strcpy(g->Message, sizeof(g->Message), "Module cannot contain a path"); |
| 95 | return NULL; |
| 96 | } |
| 97 | else if (strlen(subtype)+1+3 >= sizeof(getname)) { |
| 98 | safe_strcpy(g->Message, sizeof(g->Message), "Subtype string too long"); |
| 99 | return NULL; |
| 100 | } |
| 101 | else |
| 102 | PlugSetPath(soname, module, GetPluginDir()); |
| 103 | |
| 104 | // The exported name is always in uppercase |
| 105 | for (int i = 0; ; i++) { |
| 106 | c = subtype[i]; |
| 107 | getname[i + 3] = toupper(c); |
| 108 | if (!c) break; |
| 109 | } // endfor i |
| 110 | |
| 111 | #if defined(_WIN32) |
| 112 | // Load the Dll implementing the table |
| 113 | if (!(hdll = LoadLibrary(soname))) { |
| 114 | char buf[256]; |
| 115 | DWORD rc = GetLastError(); |
| 116 | |
| 117 | snprintf(g->Message, sizeof(g->Message), MSG(DLL_LOAD_ERROR), rc, soname); |
| 118 | FormatMessage(FORMAT_MESSAGE_FLAGS, NULL, rc, 0, |
| 119 | (LPTSTR)buf, sizeof(buf), NULL); |
| 120 | safe_strcat(g->Message, sizeof(g->Message), ": "); |
| 121 | safe_strcat(g->Message, sizeof(g->Message), buf); |
| 122 | return NULL; |
| 123 | } // endif hDll |
| 124 | |
| 125 | // Get the function returning an instance of the external DEF class |
| 126 | if (!(coldef = (XCOLDEF)GetProcAddress((HINSTANCE)hdll, getname))) { |
no test coverage detected