- 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.
This commit is contained in:
Rein Klazes 2005-09-15 09:31:05 +00:00 committed by Alexandre Julliard
parent d64172dc5e
commit c16e70587a
3 changed files with 36 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -1000,6 +1000,7 @@ SC_HANDLE WINAPI OpenSCManagerW( LPCWSTR lpMachineName, LPCWSTR lpDatabaseName,
error:
sc_handle_free( &manager->hdr );
SetLastError( r);
return NULL;
}

View File

@ -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();
}