advapi32: LsaQueryInformationPolicy update (REVISED)

Robert Reif reif at earthlink.net
Tue Aug 1 06:19:56 CDT 2006


Robert Reif wrote:

> Update LsaQueryInformationPolicy to use correct computer name and SID.
> Add support for PolicyDnsDomainInformation.
>
> Replaces previous patches.

This is a revised version that does the right thing for both domains and 
accounts.
-------------- next part --------------
diff -p -u -r1.10 lsa.c
--- dlls/advapi32/lsa.c	31 Jul 2006 09:33:02 -0000	1.10
+++ dlls/advapi32/lsa.c	1 Aug 2006 11:15:30 -0000
@@ -374,7 +374,7 @@ NTSTATUS WINAPI LsaQueryInformationPolic
     IN POLICY_INFORMATION_CLASS InformationClass,
     OUT PVOID *Buffer)
 {
-    FIXME("(%p,0x%08x,%p) stub\n", PolicyHandle, InformationClass, Buffer);
+    TRACE("(%p,0x%08x,%p)\n", PolicyHandle, InformationClass, Buffer);
 
     if(!Buffer) return STATUS_INVALID_PARAMETER;
     switch (InformationClass)
@@ -388,17 +388,105 @@ NTSTATUS WINAPI LsaQueryInformationPolic
         }
         break;
         case PolicyPrimaryDomainInformation: /* 3 */
+        {
+            /* Only the domain name is valid for the local computer.
+             * All other fields are zero.
+             */
+            PPOLICY_PRIMARY_DOMAIN_INFO pinfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+                                                          sizeof(POLICY_PRIMARY_DOMAIN_INFO));
+            HKEY key;
+            BOOL useDefault = TRUE;
+            LONG ret;
+
+            if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
+                 "System\\CurrentControlSet\\Services\\VxD\\VNETSUP", 0,
+                 KEY_READ, &key)) == ERROR_SUCCESS)
+            {
+                DWORD size = 0;
+                static const WCHAR wg[] = { 'W','o','r','k','g','r','o','u','p',0 };
+
+                ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
+                if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
+                {
+                    pinfo->Name.Buffer = HeapAlloc(GetProcessHeap(),
+                                                   HEAP_ZERO_MEMORY, size);
+
+                    if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
+                         (LPBYTE)pinfo->Name.Buffer, &size)) == ERROR_SUCCESS)
+                    {
+                        pinfo->Name.Length = (USHORT)(size - sizeof(WCHAR));
+                        pinfo->Name.MaximumLength = (USHORT)size;
+                        useDefault = FALSE;
+                    }
+                    else
+                    {
+                        HeapFree(GetProcessHeap(), 0, pinfo->Name.Buffer);
+                        pinfo->Name.Buffer = NULL;
+                    }
+                }
+                RegCloseKey(key);
+            }
+            if (useDefault)
+                RtlCreateUnicodeStringFromAsciiz(&(pinfo->Name), "DOMAIN");
+
+            TRACE("setting domain to %s\n", debugstr_w(pinfo->Name.Buffer));
+
+            *Buffer = pinfo;
+        }
+        break;
         case PolicyAccountDomainInformation: /* 5 */
         {
             struct di
             {
-                POLICY_PRIMARY_DOMAIN_INFO ppdi;
+                POLICY_ACCOUNT_DOMAIN_INFO info;
                 SID sid;
+                DWORD padding[3];
             };
 
-            SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
-
             struct di * xdi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*xdi));
+            DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
+            LPWSTR buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
+
+            xdi->info.DomainName.MaximumLength = dwSize * sizeof(WCHAR);
+
+            if (GetComputerNameW(buf, &dwSize))
+            {
+                xdi->info.DomainName.Buffer = buf;
+                xdi->info.DomainName.Length = dwSize * sizeof(WCHAR);
+            }
+
+            TRACE("setting name to %s\n", debugstr_w(xdi->info.DomainName.Buffer));
+
+            xdi->info.DomainSid = &(xdi->sid);
+
+            /* read the computer SID from the registry */
+            if (!ADVAPI_GetComputerSid(&(xdi->sid)))
+            {
+                SID_IDENTIFIER_AUTHORITY localSidAuthority = {SECURITY_NT_AUTHORITY};
+
+                xdi->sid.Revision = SID_REVISION;
+                xdi->sid.SubAuthorityCount = 4;
+                xdi->sid.IdentifierAuthority = localSidAuthority;
+                xdi->sid.SubAuthority[0] = SECURITY_NT_NON_UNIQUE;
+                xdi->sid.SubAuthority[1] = 0;
+                xdi->sid.SubAuthority[2] = 0;
+                xdi->sid.SubAuthority[3] = 0;
+
+                WARN("Computer SID not found in registry\n");
+            }
+
+            TRACE("setting SID to %s\n", debugstr_sid(&xdi->sid));
+
+            *Buffer = xdi;
+        }
+        break;
+        case  PolicyDnsDomainInformation:	/* 12 (0xc) */
+        {
+            /* Only the domain name is valid for the local computer.
+             * All other fields are zero.
+             */
+            PPOLICY_DNS_DOMAIN_INFO pinfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
+                                                      sizeof(POLICY_DNS_DOMAIN_INFO));
             HKEY key;
             BOOL useDefault = TRUE;
             LONG ret;
@@ -413,34 +501,30 @@ NTSTATUS WINAPI LsaQueryInformationPolic
                 ret = RegQueryValueExW(key, wg, NULL, NULL, NULL, &size);
                 if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
                 {
-                    xdi->ppdi.Name.Buffer = HeapAlloc(GetProcessHeap(),
-                                                      HEAP_ZERO_MEMORY, size);
+                    pinfo->Name.Buffer = HeapAlloc(GetProcessHeap(),
+                                                   HEAP_ZERO_MEMORY, size);
 
                     if ((ret = RegQueryValueExW(key, wg, NULL, NULL,
-                         (LPBYTE)xdi->ppdi.Name.Buffer, &size)) == ERROR_SUCCESS)
+                         (LPBYTE)pinfo->Name.Buffer, &size)) == ERROR_SUCCESS)
                     {
-                        xdi->ppdi.Name.Length = (USHORT)size;
+                        pinfo->Name.Length = (USHORT)(size - sizeof(WCHAR));
+                        pinfo->Name.MaximumLength = (USHORT)size;
                         useDefault = FALSE;
                     }
                     else
                     {
-                        HeapFree(GetProcessHeap(), 0, xdi->ppdi.Name.Buffer);
-                        xdi->ppdi.Name.Buffer = NULL;
+                        HeapFree(GetProcessHeap(), 0, pinfo->Name.Buffer);
+                        pinfo->Name.Buffer = NULL;
                     }
                 }
                 RegCloseKey(key);
             }
             if (useDefault)
-                RtlCreateUnicodeStringFromAsciiz(&(xdi->ppdi.Name), "DOMAIN");
+                RtlCreateUnicodeStringFromAsciiz(&(pinfo->Name), "DOMAIN");
 
-            TRACE("setting domain to %s\n", debugstr_w(xdi->ppdi.Name.Buffer));
+            TRACE("setting domain to %s\n", debugstr_w(pinfo->Name.Buffer));
 
-            xdi->ppdi.Sid = &(xdi->sid);
-            xdi->sid.Revision = SID_REVISION;
-            xdi->sid.SubAuthorityCount = 1;
-            xdi->sid.IdentifierAuthority = localSidAuthority;
-            xdi->sid.SubAuthority[0] = SECURITY_LOCAL_SYSTEM_RID;
-            *Buffer = xdi;
+            *Buffer = pinfo;
         }
         break;
         case  PolicyAuditLogInformation:
@@ -451,7 +535,6 @@ NTSTATUS WINAPI LsaQueryInformationPolic
         case  PolicyModificationInformation:
         case  PolicyAuditFullSetInformation:
         case  PolicyAuditFullQueryInformation:
-        case  PolicyDnsDomainInformation:
         {
             FIXME("category not implemented\n");
             return STATUS_UNSUCCESSFUL;


More information about the wine-patches mailing list