If a DSN is System wide, we need to write to the HKEY_LOCAL_MACHINE part of the registry not HKEY_CURRENT_USER which it's currently doing.
-- v6: odbccp32: SQLWritePrivateProfileStringW simplify creating registry keys. odbccp32: SQLWritePrivateProfileStringW check for existing DSN first.
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; }
From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
Use ConfigMode to determine where to look for the key. --- dlls/odbccp32/odbccp32.c | 42 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c index 6c37c0a5265..dbcc7ae5383 100644 --- a/dlls/odbccp32/odbccp32.c +++ b/dlls/odbccp32/odbccp32.c @@ -1813,8 +1813,9 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry LPCWSTR lpszString, LPCWSTR lpszFilename) { static const WCHAR empty[] = {0}; - LONG ret; - HKEY hkey; + LONG ret = ERROR_FILE_NOT_FOUND; + HKEY hkey = NULL, hrootkey; + WCHAR *regpath;
clear_errors(); TRACE("%s %s %s %s\n", debugstr_w(lpszSection), debugstr_w(lpszEntry), @@ -1826,7 +1827,42 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry return FALSE; }
- if ((ret = RegCreateKeyW(HKEY_CURRENT_USER, odbcW, &hkey)) == ERROR_SUCCESS) + regpath = malloc ( (wcslen(L"Software\ODBC\") + wcslen(lpszFilename) + wcslen(L"\") + + wcslen(lpszSection) + 1) * sizeof(WCHAR)); + if (!regpath) + { + push_error(ODBC_ERROR_OUT_OF_MEM, odbc_error_out_of_mem); + return FALSE; + } + wcscpy(regpath, L"Software\ODBC\"); + wcscat(regpath, lpszFilename); + wcscat(regpath, L"\"); + wcscat(regpath, lpszSection); + + /* Check for an existing key first before writing a new one */ + if (config_mode == ODBC_BOTH_DSN || config_mode == ODBC_USER_DSN) + { + ret = RegOpenKeyW(HKEY_CURRENT_USER, regpath, &hkey); + } + + if (!hkey && (config_mode == ODBC_BOTH_DSN || config_mode == ODBC_SYSTEM_DSN)) + { + ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, regpath, &hkey); + } + + hrootkey = config_mode == ODBC_SYSTEM_DSN ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + + free(regpath); + + if (ret == ERROR_SUCCESS) + { + if(lpszString) + ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR)); + else + ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)empty, sizeof(empty)); + RegCloseKey(hkey); + } + else if ((ret = RegCreateKeyW(hrootkey, odbcW, &hkey)) == ERROR_SUCCESS) { HKEY hkeyfilename;
From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
--- dlls/odbccp32/odbccp32.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-)
diff --git a/dlls/odbccp32/odbccp32.c b/dlls/odbccp32/odbccp32.c index dbcc7ae5383..5b38ba471cf 100644 --- a/dlls/odbccp32/odbccp32.c +++ b/dlls/odbccp32/odbccp32.c @@ -38,7 +38,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(odbc);
/* Registry key names */ static const WCHAR drivers_key[] = {'S','o','f','t','w','a','r','e','\','O','D','B','C','\','O','D','B','C','I','N','S','T','.','I','N','I','\','O','D','B','C',' ','D','r','i','v','e','r','s',0}; -static const WCHAR odbcW[] = {'S','o','f','t','w','a','r','e','\','O','D','B','C',0}; static const WCHAR odbcini[] = {'S','o','f','t','w','a','r','e','\','O','D','B','C','\','O','D','B','C','I','N','S','T','.','I','N','I','\',0}; static const WCHAR odbcdrivers[] = {'O','D','B','C',' ','D','r','i','v','e','r','s',0}; static const WCHAR odbctranslators[] = {'O','D','B','C',' ','T','r','a','n','s','l','a','t','o','r','s',0}; @@ -1814,7 +1813,7 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry { static const WCHAR empty[] = {0}; LONG ret = ERROR_FILE_NOT_FOUND; - HKEY hkey = NULL, hrootkey; + HKEY hkey = NULL; WCHAR *regpath;
clear_errors(); @@ -1850,7 +1849,13 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry ret = RegOpenKeyW(HKEY_LOCAL_MACHINE, regpath, &hkey); }
- hrootkey = config_mode == ODBC_SYSTEM_DSN ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + /* Only create the key if it doesn't exist. */ + if (!hkey) + { + HKEY hrootkey = config_mode == ODBC_SYSTEM_DSN ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; + + ret = RegCreateKeyW(hrootkey, regpath, &hkey); + }
free(regpath);
@@ -1862,28 +1867,6 @@ BOOL WINAPI SQLWritePrivateProfileStringW(LPCWSTR lpszSection, LPCWSTR lpszEntry ret = RegSetValueExW(hkey, lpszEntry, 0, REG_SZ, (BYTE*)empty, sizeof(empty)); RegCloseKey(hkey); } - else if ((ret = RegCreateKeyW(hrootkey, odbcW, &hkey)) == ERROR_SUCCESS) - { - HKEY hkeyfilename; - - if ((ret = RegCreateKeyW(hkey, lpszFilename, &hkeyfilename)) == ERROR_SUCCESS) - { - HKEY hkey_section; - - if ((ret = RegCreateKeyW(hkeyfilename, lpszSection, &hkey_section)) == ERROR_SUCCESS) - { - if(lpszString) - ret = RegSetValueExW(hkey_section, lpszEntry, 0, REG_SZ, (BYTE*)lpszString, (lstrlenW(lpszString)+1)*sizeof(WCHAR)); - else - ret = RegSetValueExW(hkey_section, lpszEntry, 0, REG_SZ, (BYTE*)empty, sizeof(empty)); - RegCloseKey(hkey_section); - } - - RegCloseKey(hkeyfilename); - } - - RegCloseKey(hkey); - }
return ret == ERROR_SUCCESS; }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=147269
Your paranoid android.
=== debian11b (64 bit WoW report) ===
user32: input.c:4305: Test succeeded inside todo block: button_down_hwnd_todo 1: got MSG_TEST_WIN hwnd 00000000005000EE, msg WM_LBUTTONDOWN, wparam 0x1, lparam 0x320032