From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
--- dlls/odbccp32/odbccp32.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c index 46468765b86..6c37c0a5265 100644 --- a/dlls/odbccp32/odbccp32.c +++ b/dlls/odbccp32/odbccp32.c @@ -712,19 +712,31 @@ BOOL WINAPI SQLGetInstalledDrivers(char *buf, WORD size, WORD *sizeout)
static HKEY get_privateprofile_sectionkey(LPCWSTR section, LPCWSTR filename) { - HKEY hkey, hkeyfilename, hkeysection; - LONG ret; + HKEY hkeysection = NULL; + LONG ret = ERROR_FILE_NOT_FOUND; + WCHAR *regpath;
- if (RegOpenKeyW(HKEY_CURRENT_USER, odbcW, &hkey)) + regpath = malloc ( (wcslen(L"Software\ODBC\") + wcslen(filename) + wcslen(L"\") + + wcslen(section) + 1) * sizeof(WCHAR)); + if (!regpath) return NULL;
- ret = RegOpenKeyW(hkey, filename, &hkeyfilename); - RegCloseKey(hkey); - if (ret) - return NULL; + wcscpy(regpath, L"Software\ODBC\"); + wcscat(regpath, filename); + wcscat(regpath, L"\"); + wcscat(regpath, section); + + if (config_mode == ODBC_BOTH_DSN || config_mode == ODBC_USER_DSN) + { + ret = RegOpenKeyW(HKEY_CURRENT_USER, regpath, &hkeysection); + } + + if (!hkeysection && (config_mode == ODBC_BOTH_DSN || config_mode == ODBC_SYSTEM_DSN)) + { + ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, regpath, &hkeysection); + }
- ret = RegOpenKeyW(hkeyfilename, section, &hkeysection); - RegCloseKey(hkeyfilename); + free(regpath);
return ret ? NULL : hkeysection; }