[LSASRV]
authorEric Kohl <eric.kohl@reactos.org>
Fri, 23 Sep 2011 10:01:22 +0000 (10:01 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Fri, 23 Sep 2011 10:01:22 +0000 (10:01 +0000)
Implement the PolicyPrimaryDomainInformation and PolicyAccountDomainInformation cases of LsarQueryInformationPolicy.

svn path=/trunk/; revision=53808

reactos/dll/win32/lsasrv/lsarpc.c
reactos/dll/win32/lsasrv/lsasrv.h
reactos/dll/win32/lsasrv/policy.c

index 1881e30..7bb7714 100644 (file)
@@ -200,113 +200,25 @@ NTSTATUS WINAPI LsarQueryInformationPolicy(
 
     switch (InformationClass)
     {
-        case PolicyAuditEventsInformation: /* 2 */
-        {
-            PLSAPR_POLICY_AUDIT_EVENTS_INFO p = MIDL_user_allocate(sizeof(LSAPR_POLICY_AUDIT_EVENTS_INFO));
-            if (p == NULL)
-                return STATUS_INSUFFICIENT_RESOURCES;
-
-            p->AuditingMode = FALSE; /* no auditing */
-            p->EventAuditingOptions = NULL;
-            p->MaximumAuditEventCount = 0;
-
-            *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
-        }
-        break;
+        case PolicyAuditEventsInformation:   /* 2 */
+            Status = LsarQueryAuditEvents(PolicyHandle,
+                                          PolicyInformation);
+            break;
 
         case PolicyPrimaryDomainInformation: /* 3 */
-        {
-            PLSAPR_POLICY_PRIMARY_DOM_INFO p = MIDL_user_allocate(sizeof(LSAPR_POLICY_PRIMARY_DOM_INFO));
-            if (p == NULL)
-                return STATUS_INSUFFICIENT_RESOURCES;
-
-            p->Name.Length = 0;
-            p->Name.MaximumLength = 0;
-            p->Name.Buffer = NULL;
-#if 0
-            p->Name.Length = wcslen(L"COMPUTERNAME");
-            p->Name.MaximumLength = p->Name.Length + sizeof(WCHAR);
-            p->Name.Buffer = MIDL_user_allocate(p->Name.MaximumLength);
-            if (p->Name.Buffer == NULL)
-            {
-                MIDL_user_free(p);
-                return STATUS_INSUFFICIENT_RESOURCES;
-            }
-
-            wcscpy(p->Name.Buffer, L"COMPUTERNAME");
-#endif
-
-            p->Sid = NULL; /* no domain, no workgroup */
-
-            *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
-        }
-        break;
+            Status = LsarQueryPrimaryDomain(PolicyHandle,
+                                            PolicyInformation);
+            break;
 
         case PolicyAccountDomainInformation: /* 5 */
-        {
-            PLSAPR_POLICY_ACCOUNT_DOM_INFO p = MIDL_user_allocate(sizeof(LSAPR_POLICY_ACCOUNT_DOM_INFO));
-            if (p == NULL)
-                return STATUS_INSUFFICIENT_RESOURCES;
-
-            p->DomainName.Length = 0;
-            p->DomainName.MaximumLength = 0;
-            p->DomainName.Buffer = NULL;
-#if 0
-            p->DomainName.Length = wcslen(L"COMPUTERNAME");
-            p->DomainName.MaximumLength = p->DomainName.Length + sizeof(WCHAR);
-            p->DomainName.Buffer = MIDL_user_allocate(p->DomainName.MaximumLength);
-            if (p->DomainName.Buffer == NULL)
-            {
-                MIDL_user_free(p);
-                return STATUS_INSUFFICIENT_RESOURCES;
-            }
-
-            wcscpy(p->DomainName.Buffer, L"COMPUTERNAME");
-#endif
-
-            p->Sid = NULL; /* no domain, no workgroup */
-
-            *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
-        }
-        break;
-
-        case  PolicyDnsDomainInformation:      /* 12 (0xc) */
-        {
-            PLSAPR_POLICY_DNS_DOMAIN_INFO p = MIDL_user_allocate(sizeof(LSAPR_POLICY_DNS_DOMAIN_INFO));
-            if (p == NULL)
-                return STATUS_INSUFFICIENT_RESOURCES;
-
-            p->Name.Length = 0;
-            p->Name.MaximumLength = 0;
-            p->Name.Buffer = NULL;
-#if 0
-            p->Name.Length = wcslen(L"COMPUTERNAME");
-            p->Name.MaximumLength = p->Name.Length + sizeof(WCHAR);
-            p->Name.Buffer = MIDL_user_allocate(p->Name.MaximumLength);
-            if (p->Name.Buffer == NULL)
-            {
-                MIDL_user_free(p);
-                return STATUS_INSUFFICIENT_RESOURCES;
-            }
-
-            wcscpy(p->Name.Buffer, L"COMPUTERNAME");
-#endif
-
-            p->DnsDomainName.Length = 0;
-            p->DnsDomainName.MaximumLength = 0;
-            p->DnsDomainName.Buffer = NULL;
-
-            p->DnsForestName.Length = 0;
-            p->DnsForestName.MaximumLength = 0;
-            p->DnsForestName.Buffer = 0;
-
-            memset(&p->DomainGuid, 0, sizeof(GUID));
-
-            p->Sid = NULL; /* no domain, no workgroup */
-
-            *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
-        }
-        break;
+            Status = LsarQueryAccountDomain(PolicyHandle,
+                                            PolicyInformation);
+            break;
+
+        case PolicyDnsDomainInformation:     /* 12 (0xc) */
+            Status = LsarQueryDnsDomain(PolicyHandle,
+                                        PolicyInformation);
+            break;
 
         case PolicyAuditLogInformation:
         case PolicyPdAccountInformation:
@@ -317,13 +229,12 @@ NTSTATUS WINAPI LsarQueryInformationPolicy(
         case PolicyAuditFullSetInformation:
         case PolicyAuditFullQueryInformation:
         case PolicyEfsInformation:
-        {
             FIXME("category not implemented\n");
-            return STATUS_UNSUCCESSFUL;
-        }
+            Status = STATUS_UNSUCCESSFUL;
+            break;
     }
 
-    return STATUS_SUCCESS;
+    return Status;
 }
 
 
index 1686ca6..769436d 100644 (file)
@@ -91,6 +91,22 @@ VOID
 LsarStartRpcServer(VOID);
 
 /* policy.c */
+NTSTATUS
+LsarQueryAuditEvents(LSAPR_HANDLE PolicyHandle,
+                     PLSAPR_POLICY_INFORMATION *PolicyInformation);
+
+NTSTATUS
+LsarQueryPrimaryDomain(LSAPR_HANDLE PolicyHandle,
+                       PLSAPR_POLICY_INFORMATION *PolicyInformation);
+
+NTSTATUS
+LsarQueryAccountDomain(LSAPR_HANDLE PolicyHandle,
+                       PLSAPR_POLICY_INFORMATION *PolicyInformation);
+
+NTSTATUS
+LsarQueryDnsDomain(LSAPR_HANDLE PolicyHandle,
+                   PLSAPR_POLICY_INFORMATION *PolicyInformation);
+
 NTSTATUS
 LsarSetPrimaryDomain(LSAPR_HANDLE PolicyObject,
                      PLSAPR_POLICY_PRIMARY_DOM_INFO Info);
index 66f20d1..6239acb 100644 (file)
@@ -115,4 +115,286 @@ LsarSetDnsDomain(LSAPR_HANDLE PolicyHandle,
     return STATUS_NOT_IMPLEMENTED;
 }
 
+
+NTSTATUS
+LsarQueryAuditEvents(LSAPR_HANDLE PolicyHandle,
+                     PLSAPR_POLICY_INFORMATION *PolicyInformation)
+{
+    PLSAPR_POLICY_AUDIT_EVENTS_INFO p = NULL;
+
+    p = MIDL_user_allocate(sizeof(LSAPR_POLICY_AUDIT_EVENTS_INFO));
+    if (p == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    p->AuditingMode = FALSE; /* no auditing */
+    p->EventAuditingOptions = NULL;
+    p->MaximumAuditEventCount = 0;
+
+    *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
+
+    return STATUS_SUCCESS;
+}
+
+
+NTSTATUS
+LsarQueryPrimaryDomain(LSAPR_HANDLE PolicyHandle,
+                       PLSAPR_POLICY_INFORMATION *PolicyInformation)
+{
+    PLSAPR_POLICY_PRIMARY_DOM_INFO p = NULL;
+    PUNICODE_STRING DomainName;
+    ULONG AttributeSize;
+    NTSTATUS Status;
+
+    *PolicyInformation = NULL;
+
+    p = MIDL_user_allocate(sizeof(LSAPR_POLICY_PRIMARY_DOM_INFO));
+    if (p == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    /* Domain Name */
+    Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                    L"PolPrDmN",
+                                    NULL,
+                                    &AttributeSize);
+    if (!NT_SUCCESS(Status))
+    {
+        goto Done;
+    }
+
+    if (AttributeSize > 0)
+    {
+        DomainName = MIDL_user_allocate(AttributeSize);
+        if (DomainName == NULL)
+        {
+            Status = STATUS_INSUFFICIENT_RESOURCES;
+            goto Done;
+        }
+
+        Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                        L"PolPrDmN",
+                                        DomainName,
+                                        &AttributeSize);
+        if (Status == STATUS_SUCCESS)
+        {
+            DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
+
+            TRACE("PrimaryDomainName: %wZ\n", DomainName);
+
+            p->Name.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
+            if (p->Name.Buffer == NULL)
+            {
+                MIDL_user_free(DomainName);
+                Status = STATUS_INSUFFICIENT_RESOURCES;
+                goto Done;
+            }
+
+            p->Name.Length = DomainName->Length;
+            p->Name.MaximumLength = DomainName->MaximumLength;
+            memcpy(p->Name.Buffer,
+                   DomainName->Buffer,
+                   DomainName->MaximumLength);
+        }
+
+        MIDL_user_free(DomainName);
+    }
+
+    /* Domain SID */
+    AttributeSize = 0;
+    Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                    L"PolPrDmS",
+                                    NULL,
+                                    &AttributeSize);
+    if (!NT_SUCCESS(Status))
+    {
+        goto Done;
+    }
+
+    if (AttributeSize > 0)
+    {
+        p->Sid = MIDL_user_allocate(AttributeSize);
+        if (p->Sid == NULL)
+        {
+            Status = STATUS_INSUFFICIENT_RESOURCES;
+            goto Done;
+        }
+
+        Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                        L"PolPrDmS",
+                                        p->Sid,
+                                        &AttributeSize);
+    }
+
+    *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
+
+Done:
+    if (!NT_SUCCESS(Status))
+    {
+        if (p)
+        {
+            if (p->Name.Buffer)
+                MIDL_user_free(p->Name.Buffer);
+
+            if (p->Sid)
+                MIDL_user_free(p->Sid);
+
+            MIDL_user_free(p);
+        }
+    }
+
+    return STATUS_SUCCESS;
+}
+
+
+NTSTATUS
+LsarQueryAccountDomain(LSAPR_HANDLE PolicyHandle,
+                       PLSAPR_POLICY_INFORMATION *PolicyInformation)
+{
+    PLSAPR_POLICY_ACCOUNT_DOM_INFO p = NULL;
+    PUNICODE_STRING DomainName;
+    ULONG AttributeSize;
+    NTSTATUS Status;
+
+    *PolicyInformation = NULL;
+
+    p = MIDL_user_allocate(sizeof(LSAPR_POLICY_ACCOUNT_DOM_INFO));
+    if (p == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    /* Domain Name */
+    Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                    L"PolAcDmN",
+                                    NULL,
+                                    &AttributeSize);
+    if (!NT_SUCCESS(Status))
+    {
+        goto Done;
+    }
+
+    if (AttributeSize > 0)
+    {
+        DomainName = MIDL_user_allocate(AttributeSize);
+        if (DomainName == NULL)
+        {
+            Status = STATUS_INSUFFICIENT_RESOURCES;
+            goto Done;
+        }
+
+        Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                        L"PolAcDmN",
+                                        DomainName,
+                                        &AttributeSize);
+        if (Status == STATUS_SUCCESS)
+        {
+            DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
+
+            TRACE("AccountDomainName: %wZ\n", DomainName);
+
+            p->DomainName.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
+            if (p->DomainName.Buffer == NULL)
+            {
+                MIDL_user_free(DomainName);
+                Status = STATUS_INSUFFICIENT_RESOURCES;
+                goto Done;
+            }
+
+            p->DomainName.Length = DomainName->Length;
+            p->DomainName.MaximumLength = DomainName->MaximumLength;
+            memcpy(p->DomainName.Buffer,
+                   DomainName->Buffer,
+                   DomainName->MaximumLength);
+        }
+
+        MIDL_user_free(DomainName);
+    }
+
+    /* Domain SID */
+    AttributeSize = 0;
+    Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                    L"PolAcDmS",
+                                    NULL,
+                                    &AttributeSize);
+    if (!NT_SUCCESS(Status))
+    {
+        goto Done;
+    }
+
+    if (AttributeSize > 0)
+    {
+        p->Sid = MIDL_user_allocate(AttributeSize);
+        if (p->Sid == NULL)
+        {
+            Status = STATUS_INSUFFICIENT_RESOURCES;
+            goto Done;
+        }
+
+        Status = LsapGetObjectAttribute((PLSA_DB_OBJECT)PolicyHandle,
+                                        L"PolAcDmS",
+                                        p->Sid,
+                                        &AttributeSize);
+    }
+
+    *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
+
+Done:
+    if (!NT_SUCCESS(Status))
+    {
+        if (p)
+        {
+            if (p->DomainName.Buffer)
+                MIDL_user_free(p->DomainName.Buffer);
+
+            if (p->Sid)
+                MIDL_user_free(p->Sid);
+
+            MIDL_user_free(p);
+        }
+    }
+
+    return STATUS_SUCCESS;
+}
+
+
+NTSTATUS
+LsarQueryDnsDomain(LSAPR_HANDLE PolicyHandle,
+                   PLSAPR_POLICY_INFORMATION *PolicyInformation)
+{
+    PLSAPR_POLICY_DNS_DOMAIN_INFO p = NULL;
+
+    p = MIDL_user_allocate(sizeof(LSAPR_POLICY_DNS_DOMAIN_INFO));
+    if (p == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    p->Name.Length = 0;
+    p->Name.MaximumLength = 0;
+    p->Name.Buffer = NULL;
+#if 0
+            p->Name.Length = wcslen(L"COMPUTERNAME");
+            p->Name.MaximumLength = p->Name.Length + sizeof(WCHAR);
+            p->Name.Buffer = MIDL_user_allocate(p->Name.MaximumLength);
+            if (p->Name.Buffer == NULL)
+            {
+                MIDL_user_free(p);
+                return STATUS_INSUFFICIENT_RESOURCES;
+            }
+
+            wcscpy(p->Name.Buffer, L"COMPUTERNAME");
+#endif
+
+    p->DnsDomainName.Length = 0;
+    p->DnsDomainName.MaximumLength = 0;
+    p->DnsDomainName.Buffer = NULL;
+
+    p->DnsForestName.Length = 0;
+    p->DnsForestName.MaximumLength = 0;
+    p->DnsForestName.Buffer = 0;
+
+    memset(&p->DomainGuid, 0, sizeof(GUID));
+
+    p->Sid = NULL; /* no domain, no workgroup */
+
+    *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
+
+    return STATUS_SUCCESS;
+}
+
 /* EOF */