Author: ekohl
Date: Sun May 13 21:45:59 2012
New Revision: 56581

URL: http://svn.reactos.org/svn/reactos?rev=56581&view=rev
Log:
[ADVAPI32]
Use LSA functions to query the account domain SID.

Modified:
    trunk/reactos/dll/win32/advapi32/misc/logon.c

Modified: trunk/reactos/dll/win32/advapi32/misc/logon.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/misc/logon.c?rev=56581&r1=56580&r2=56581&view=diff
==============================================================================
--- trunk/reactos/dll/win32/advapi32/misc/logon.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/misc/logon.c [iso-8859-1] Sun May 13 
21:45:59 2012
@@ -307,75 +307,59 @@
 
 
 static BOOL WINAPI
-SamGetDomainSid(PSID *Sid)
-{
+GetDomainSid(PSID *Sid)
+{
+    PPOLICY_ACCOUNT_DOMAIN_INFO Info = NULL;
+    LSA_OBJECT_ATTRIBUTES ObjectAttributes;
+    LSA_HANDLE PolicyHandle;
     PSID lpSid;
-    DWORD dwLength;
-    HKEY hDomainKey;
-
-    TRACE("SamGetDomainSid() called\n");
-
-    if (Sid != NULL)
-        *Sid = NULL;
-
-    /* Open the account domain key */
-    if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
-                      L"SAM\\SAM\\Domains\\Account",
-                      0,
-                      KEY_READ,
-                      &hDomainKey))
-    {
-        ERR("Failed to open the account domain key! (Error %lu)\n", 
GetLastError());
-        return FALSE;
-    }
-
-    /* Get SID size */
-    dwLength = 0;
-    if (RegQueryValueExW(hDomainKey,
-                         L"Sid",
-                         NULL,
-                         NULL,
-                         NULL,
-                         &dwLength))
-    {
-        ERR("Failed to read the SID size! (Error %lu)\n", GetLastError());
-        RegCloseKey(hDomainKey);
-        return FALSE;
-    }
-
-    /* Allocate sid buffer */
-    TRACE("Required SID buffer size: %lu\n", dwLength);
-    lpSid = (PSID)RtlAllocateHeap(RtlGetProcessHeap(),
-                                  0,
-                                  dwLength);
+    ULONG Length;
+    NTSTATUS Status;
+
+    *Sid = NULL;
+
+    memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
+    ObjectAttributes.Length = sizeof(LSA_OBJECT_ATTRIBUTES);
+
+    Status = LsaOpenPolicy(NULL,
+                           &ObjectAttributes,
+                           POLICY_TRUST_ADMIN,
+                           &PolicyHandle);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("LsaOpenPolicy failed (Status: 0x%08lx)\n", Status);
+        return FALSE;
+    }
+
+    Status = LsaQueryInformationPolicy(PolicyHandle,
+                                       PolicyAccountDomainInformation,
+                                       (PVOID *)&Info);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("LsaQueryInformationPolicy failed (Status: 0x%08lx)\n", Status);
+        LsaClose(PolicyHandle);
+        return FALSE;
+    }
+
+    Length = RtlLengthSid(Info->DomainSid);
+
+    lpSid = RtlAllocateHeap(RtlGetProcessHeap(),
+                            0,
+                            Length);
     if (lpSid == NULL)
     {
         ERR("Failed to allocate SID buffer!\n");
-        RegCloseKey(hDomainKey);
-        return FALSE;
-    }
-
-    /* Read sid */
-    if (RegQueryValueExW(hDomainKey,
-                         L"Sid",
-                         NULL,
-                         NULL,
-                         (LPBYTE)lpSid,
-                         &dwLength))
-    {
-        ERR("Failed to read the SID! (Error %lu)\n", GetLastError());
-        RtlFreeHeap(RtlGetProcessHeap(),
-                    0,
-                    lpSid);
-        RegCloseKey(hDomainKey);
-        return FALSE;
-    }
-
-    RegCloseKey(hDomainKey);
+        LsaFreeMemory(Info);
+        LsaClose(PolicyHandle);
+        return FALSE;
+    }
+
+    memcpy(lpSid, Info->DomainSid, Length);
 
     *Sid = lpSid;
 
-    TRACE("SamGetDomainSid() done\n");
+    LsaFreeMemory(Info);
+    LsaClose(PolicyHandle);
 
     return TRUE;
 }
@@ -435,7 +419,7 @@
     if (!NT_SUCCESS(Status))
         return NULL;
 
-    if (!SamGetDomainSid(&DomainSid))
+    if (!GetDomainSid(&DomainSid))
         return NULL;
 
     TokenGroups = RtlAllocateHeap(


Reply via email to