advapi32: small fixes for OpenSCManager

Rein Klazes wijn at wanadoo.nl
Wed Sep 14 12:48:39 CDT 2005


Hi,

Changelog:
dlls/advapi32		: service.c, registry.c
dlls/advapi32/tests	: registry.c

- 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.

Rein. 
-------------- next part --------------
--- wine/dlls/advapi32/service.c	2005-08-30 10:05:39.000000000 +0200
+++ mywine/dlls/advapi32/service.c	2005-09-10 17:43:22.000000000 +0200
@@ -1000,6 +1000,7 @@ SC_HANDLE WINAPI OpenSCManagerW( LPCWSTR
 
 error:
     sc_handle_free( &manager->hdr );
+    SetLastError( r);
     return NULL;
 }
 
--- wine/dlls/advapi32/registry.c	2005-08-30 10:05:39.000000000 +0200
+++ mywine/dlls/advapi32/registry.c	2005-09-11 10:08:58.000000000 +0200
@@ -2223,20 +2223,20 @@ LONG WINAPI RegConnectRegistryW( LPCWSTR
         /* 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;
             }
         }
--- wine/dlls/advapi32/tests/registry.c	2005-07-19 09:37:52.000000000 +0200
+++ mywine/dlls/advapi32/tests/registry.c	2005-09-14 19:03:34.000000000 +0200
@@ -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 privil
     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( (int) schnd, "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();
 }


More information about the wine-patches mailing list