Huw Davies : advapi32: Fix ADVAPI_GetComputerSid to work correctly if a sid doesn' t exist in the registry.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Sep 25 14:45:26 CDT 2006


Module: wine
Branch: master
Commit: 38d33e33aebdcc64ae95efe0318b547a9481cdb1
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=38d33e33aebdcc64ae95efe0318b547a9481cdb1

Author: Huw Davies <huw at codeweavers.com>
Date:   Thu Sep 21 12:59:52 2006 +0100

advapi32: Fix ADVAPI_GetComputerSid to work correctly if a sid doesn't exist in the registry.

This makes the tests run correctly on first invocation.

---

 dlls/advapi32/security.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 51a28d8..3aa99b6 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -386,6 +386,7 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
 {
     HKEY key;
     LONG ret;
+    BOOL retval = FALSE;
     static const WCHAR Account[] = { 'S','E','C','U','R','I','T','Y','\\','S','A','M','\\','D','o','m','a','i','n','s','\\','A','c','c','o','u','n','t',0 };
     static const WCHAR V[] = { 'V',0 };
 
@@ -404,9 +405,7 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
                 {
                     /* the SID is in the last 24 bytes of the binary data */
                     CopyMemory(sid, &data[size-24], 24);
-                    HeapFree(GetProcessHeap(), 0, data);
-                    RegCloseKey(key);
-                    return TRUE;
+                    retval = TRUE;
                 }
                 HeapFree(GetProcessHeap(), 0, data);
             }
@@ -414,6 +413,8 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
         RegCloseKey(key);
     }
 
+    if(retval == TRUE) return retval;
+
     /* create a new random SID */
     if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, Account,
         0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
@@ -427,18 +428,15 @@ BOOL ADVAPI_GetComputerSid(PSID sid)
             if (AllocateAndInitializeSid(&identifierAuthority, 4, SECURITY_NT_NON_UNIQUE, id[0], id[1], id[2], 0, 0, 0, 0, &new_sid))
             {
                 if (RegSetValueExW(key, V, 0, REG_BINARY, new_sid, GetLengthSid(new_sid)) == ERROR_SUCCESS)
-                {
-                    FreeSid(new_sid);
-                    RegCloseKey(key);
-                    return CopySid(GetLengthSid(new_sid), sid, &new_sid);
-                }
+                    retval = CopySid(GetLengthSid(new_sid), sid, new_sid);
+
                 FreeSid(new_sid);
             }
         }
         RegCloseKey(key);
     }
 
-    return FALSE;
+    return retval;
 }
 
 /*	##############################




More information about the wine-cvs mailing list