From c16e70587af398152fabe59fcdc6c09f66776d1c Mon Sep 17 00:00:00 2001 From: Rein Klazes Date: Thu, 15 Sep 2005 09:31:05 +0000 Subject: [PATCH] - Set the LastError in OpenSCManager in case of errors; - Accept machine names without a '\\' prefix in OpenSCManager and RegConnectRegistry. - Add a regression test for that. --- dlls/advapi32/registry.c | 12 ++++++------ dlls/advapi32/service.c | 1 + dlls/advapi32/tests/registry.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index 3ab02697cf..4667147061 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -2223,20 +2223,20 @@ LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey, /* Use the local machine name */ ret = RegOpenKeyW( hKey, NULL, phkResult ); } - else if (lpMachineName[0] != '\\' || lpMachineName[1] != '\\') - ret = ERROR_BAD_NETPATH; - else - { + else { WCHAR compName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD len = sizeof(compName) / sizeof(WCHAR); + /* MSDN says lpMachineName must start with \\ : not so */ + if( lpMachineName[0] == '\\' && lpMachineName[1] == '\\') + lpMachineName += 2; if (GetComputerNameW(compName, &len)) { - if (!strcmpiW(lpMachineName + 2, compName)) + if (!strcmpiW(lpMachineName, compName)) ret = RegOpenKeyW(hKey, NULL, phkResult); else { - FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName)); + FIXME("Connect to %s is not supported.\n",debugstr_w(lpMachineName)); ret = ERROR_BAD_NETPATH; } } diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c index bcd3e78400..7721238156 100644 --- a/dlls/advapi32/service.c +++ b/dlls/advapi32/service.c @@ -1000,6 +1000,7 @@ SC_HANDLE WINAPI OpenSCManagerW( LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, error: sc_handle_free( &manager->hdr ); + SetLastError( r); return NULL; } diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index b79750661d..2581181996 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -24,6 +24,7 @@ #include "windef.h" #include "winbase.h" #include "winreg.h" +#include "winsvc.h" #include "winerror.h" static HKEY hkey_main; @@ -593,6 +594,32 @@ static BOOL set_privileges(LPCSTR privilege, BOOL set) return TRUE; } +/* tests that show that RegConnectRegistry and + OpenSCManager accept computer names without the + \\ prefix (what MSDN says). */ +static void test_regconnectregistry( void) +{ + CHAR compName[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD len = sizeof(compName) ; + BOOL ret; + LONG retl; + HKEY hkey; + SC_HANDLE schnd; + + ret = GetComputerNameA(compName, &len); + ok( ret, "GetComputerName failed err = %ld\n", GetLastError()); + if( !ret) return; + + retl = RegConnectRegistryA( compName, HKEY_LOCAL_MACHINE, &hkey); + ok( !retl, "RegConnectRegistryA failed err = %ld\n", retl); + if( !retl) RegCloseKey( hkey); + + schnd = OpenSCManagerA( compName, NULL, GENERIC_READ); + ok( schnd != NULL, "OpenSCManagerA failed err = %ld\n", GetLastError()); + CloseServiceHandle( schnd); + +} + START_TEST(registry) { setup_main_key(); @@ -619,4 +646,6 @@ START_TEST(registry) /* cleanup */ delete_key( hkey_main ); + + test_regconnectregistry(); } -- 2.32.0.93.g670b81a890