xref: /reactos/dll/win32/lsasrv/policy.c (revision c2c66aff)
1 /*
2  * PROJECT:     Local Security Authority Server DLL
3  * LICENSE:     GPL - See COPYING in the top level directory
4  * FILE:        dll/win32/lsasrv/policy.c
5  * PURPOSE:     Policy object routines
6  * COPYRIGHT:   Copyright 2011 Eric Kohl
7  */
8 
9 #include "lsasrv.h"
10 
11 /* FUNCTIONS ***************************************************************/
12 
13 NTSTATUS
14 WINAPI
LsaIOpenPolicyTrusted(OUT LSAPR_HANDLE * PolicyHandle)15 LsaIOpenPolicyTrusted(OUT LSAPR_HANDLE *PolicyHandle)
16 {
17     PLSA_DB_OBJECT PolicyObject;
18     NTSTATUS Status;
19 
20     TRACE("(%p)\n", PolicyHandle);
21 
22     Status = LsapOpenDbObject(NULL,
23                               NULL,
24                               L"Policy",
25                               LsaDbPolicyObject,
26                               POLICY_ALL_ACCESS,
27                               TRUE,
28                               &PolicyObject);
29 
30     if (NT_SUCCESS(Status))
31         *PolicyHandle = (LSAPR_HANDLE)PolicyObject;
32 
33     return Status;
34 }
35 
36 
37 NTSTATUS
LsarQueryAuditLog(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)38 LsarQueryAuditLog(PLSA_DB_OBJECT PolicyObject,
39                   PLSAPR_POLICY_INFORMATION *PolicyInformation)
40 {
41     PPOLICY_AUDIT_LOG_INFO AuditLogInfo = NULL;
42     ULONG AttributeSize;
43     NTSTATUS Status;
44 
45     *PolicyInformation = NULL;
46 
47     AttributeSize = sizeof(POLICY_AUDIT_LOG_INFO);
48     AuditLogInfo = MIDL_user_allocate(AttributeSize);
49     if (AuditLogInfo == NULL)
50         return STATUS_INSUFFICIENT_RESOURCES;
51 
52     Status = LsapGetObjectAttribute(PolicyObject,
53                                     L"PolAdtLg",
54                                     AuditLogInfo,
55                                     &AttributeSize);
56     if (!NT_SUCCESS(Status))
57     {
58         MIDL_user_free(AuditLogInfo);
59     }
60     else
61     {
62         *PolicyInformation = (PLSAPR_POLICY_INFORMATION)AuditLogInfo;
63     }
64 
65     return Status;
66 }
67 
68 
69 NTSTATUS
LsarQueryAuditEvents(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)70 LsarQueryAuditEvents(PLSA_DB_OBJECT PolicyObject,
71                      PLSAPR_POLICY_INFORMATION *PolicyInformation)
72 {
73     PLSAP_POLICY_AUDIT_EVENTS_DATA AuditData = NULL;
74     PLSAPR_POLICY_AUDIT_EVENTS_INFO p = NULL;
75     ULONG AttributeSize;
76     NTSTATUS Status = STATUS_SUCCESS;
77 
78     *PolicyInformation = NULL;
79 
80     AttributeSize = 0;
81     Status = LsapGetObjectAttribute(PolicyObject,
82                                     L"PolAdtEv",
83                                     NULL,
84                                     &AttributeSize);
85     if (!NT_SUCCESS(Status))
86         return Status;
87 
88     TRACE("Attribute size: %lu\n", AttributeSize);
89     if (AttributeSize > 0)
90     {
91         AuditData = MIDL_user_allocate(AttributeSize);
92         if (AuditData == NULL)
93             return STATUS_INSUFFICIENT_RESOURCES;
94 
95         Status = LsapGetObjectAttribute(PolicyObject,
96                                         L"PolAdtEv",
97                                         AuditData,
98                                         &AttributeSize);
99         if (!NT_SUCCESS(Status))
100             goto done;
101     }
102 
103     p = MIDL_user_allocate(sizeof(LSAPR_POLICY_AUDIT_EVENTS_INFO));
104     if (p == NULL)
105     {
106         Status = STATUS_INSUFFICIENT_RESOURCES;
107         goto done;
108     }
109 
110     if (AuditData == NULL)
111     {
112         p->AuditingMode = FALSE;
113         p->MaximumAuditEventCount = 0;
114         p->EventAuditingOptions = NULL;
115     }
116     else
117     {
118         p->AuditingMode = AuditData->AuditingMode;
119         p->MaximumAuditEventCount = AuditData->MaximumAuditEventCount;
120 
121         p->EventAuditingOptions = MIDL_user_allocate(AuditData->MaximumAuditEventCount * sizeof(DWORD));
122         if (p->EventAuditingOptions == NULL)
123         {
124             Status = STATUS_INSUFFICIENT_RESOURCES;
125             goto done;
126         }
127 
128         memcpy(p->EventAuditingOptions,
129                &(AuditData->AuditEvents[0]),
130                AuditData->MaximumAuditEventCount * sizeof(DWORD));
131     }
132 
133     *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
134 
135 done:
136     TRACE("Status: 0x%lx\n", Status);
137 
138     if (!NT_SUCCESS(Status))
139     {
140         if (p != NULL)
141         {
142             if (p->EventAuditingOptions != NULL)
143                 MIDL_user_free(p->EventAuditingOptions);
144 
145             MIDL_user_free(p);
146         }
147     }
148 
149     if (AuditData != NULL)
150         MIDL_user_free(AuditData);
151 
152     return Status;
153 }
154 
155 
156 NTSTATUS
LsarQueryPrimaryDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)157 LsarQueryPrimaryDomain(PLSA_DB_OBJECT PolicyObject,
158                        PLSAPR_POLICY_INFORMATION *PolicyInformation)
159 {
160     PLSAPR_POLICY_PRIMARY_DOM_INFO p = NULL;
161     PUNICODE_STRING DomainName;
162     ULONG AttributeSize;
163     NTSTATUS Status;
164 
165     *PolicyInformation = NULL;
166 
167     p = MIDL_user_allocate(sizeof(LSAPR_POLICY_PRIMARY_DOM_INFO));
168     if (p == NULL)
169         return STATUS_INSUFFICIENT_RESOURCES;
170 
171     /* Domain Name */
172     AttributeSize = 0;
173     Status = LsapGetObjectAttribute(PolicyObject,
174                                     L"PolPrDmN",
175                                     NULL,
176                                     &AttributeSize);
177     if (!NT_SUCCESS(Status))
178     {
179         goto Done;
180     }
181 
182     if (AttributeSize > 0)
183     {
184         DomainName = MIDL_user_allocate(AttributeSize);
185         if (DomainName == NULL)
186         {
187             Status = STATUS_INSUFFICIENT_RESOURCES;
188             goto Done;
189         }
190 
191         Status = LsapGetObjectAttribute(PolicyObject,
192                                         L"PolPrDmN",
193                                         DomainName,
194                                         &AttributeSize);
195         if (Status == STATUS_SUCCESS)
196         {
197             DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
198 
199             TRACE("PrimaryDomainName: %wZ\n", DomainName);
200 
201             p->Name.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
202             if (p->Name.Buffer == NULL)
203             {
204                 MIDL_user_free(DomainName);
205                 Status = STATUS_INSUFFICIENT_RESOURCES;
206                 goto Done;
207             }
208 
209             p->Name.Length = DomainName->Length;
210             p->Name.MaximumLength = DomainName->MaximumLength;
211             memcpy(p->Name.Buffer,
212                    DomainName->Buffer,
213                    DomainName->MaximumLength);
214         }
215 
216         MIDL_user_free(DomainName);
217     }
218 
219     /* Domain SID */
220     AttributeSize = 0;
221     Status = LsapGetObjectAttribute(PolicyObject,
222                                     L"PolPrDmS",
223                                     NULL,
224                                     &AttributeSize);
225     if (!NT_SUCCESS(Status))
226     {
227         goto Done;
228     }
229 
230     if (AttributeSize > 0)
231     {
232         p->Sid = MIDL_user_allocate(AttributeSize);
233         if (p->Sid == NULL)
234         {
235             Status = STATUS_INSUFFICIENT_RESOURCES;
236             goto Done;
237         }
238 
239         Status = LsapGetObjectAttribute(PolicyObject,
240                                         L"PolPrDmS",
241                                         p->Sid,
242                                         &AttributeSize);
243     }
244 
245     *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
246 
247 Done:
248     if (!NT_SUCCESS(Status))
249     {
250         if (p != NULL)
251         {
252             if (p->Name.Buffer)
253                 MIDL_user_free(p->Name.Buffer);
254 
255             if (p->Sid)
256                 MIDL_user_free(p->Sid);
257 
258             MIDL_user_free(p);
259         }
260     }
261 
262     return Status;
263 }
264 
265 
266 NTSTATUS
LsarQueryPdAccount(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)267 LsarQueryPdAccount(PLSA_DB_OBJECT PolicyObject,
268                    PLSAPR_POLICY_INFORMATION *PolicyInformation)
269 {
270     PLSAPR_POLICY_PD_ACCOUNT_INFO PdAccountInfo = NULL;
271 
272     *PolicyInformation = NULL;
273 
274     PdAccountInfo = MIDL_user_allocate(sizeof(LSAPR_POLICY_PD_ACCOUNT_INFO));
275     if (PdAccountInfo == NULL)
276         return STATUS_INSUFFICIENT_RESOURCES;
277 
278     PdAccountInfo->Name.Length = 0;
279     PdAccountInfo->Name.MaximumLength = 0;
280     PdAccountInfo->Name.Buffer = NULL;
281 
282     *PolicyInformation = (PLSAPR_POLICY_INFORMATION)PdAccountInfo;
283 
284     return STATUS_SUCCESS;
285 }
286 
287 
288 NTSTATUS
LsarQueryAccountDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)289 LsarQueryAccountDomain(PLSA_DB_OBJECT PolicyObject,
290                        PLSAPR_POLICY_INFORMATION *PolicyInformation)
291 {
292     PLSAPR_POLICY_ACCOUNT_DOM_INFO p = NULL;
293     PUNICODE_STRING DomainName;
294     ULONG AttributeSize = 0;
295     NTSTATUS Status;
296 
297     *PolicyInformation = NULL;
298 
299     p = MIDL_user_allocate(sizeof(LSAPR_POLICY_ACCOUNT_DOM_INFO));
300     if (p == NULL)
301         return STATUS_INSUFFICIENT_RESOURCES;
302 
303     /* Domain Name */
304     Status = LsapGetObjectAttribute(PolicyObject,
305                                     L"PolAcDmN",
306                                     NULL,
307                                     &AttributeSize);
308     if (!NT_SUCCESS(Status))
309     {
310         goto Done;
311     }
312 
313     if (AttributeSize > 0)
314     {
315         DomainName = MIDL_user_allocate(AttributeSize);
316         if (DomainName == NULL)
317         {
318             Status = STATUS_INSUFFICIENT_RESOURCES;
319             goto Done;
320         }
321 
322         Status = LsapGetObjectAttribute(PolicyObject,
323                                         L"PolAcDmN",
324                                         DomainName,
325                                         &AttributeSize);
326         if (Status == STATUS_SUCCESS)
327         {
328             DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
329 
330             TRACE("AccountDomainName: %wZ\n", DomainName);
331 
332             p->DomainName.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
333             if (p->DomainName.Buffer == NULL)
334             {
335                 MIDL_user_free(DomainName);
336                 Status = STATUS_INSUFFICIENT_RESOURCES;
337                 goto Done;
338             }
339 
340             p->DomainName.Length = DomainName->Length;
341             p->DomainName.MaximumLength = DomainName->MaximumLength;
342             memcpy(p->DomainName.Buffer,
343                    DomainName->Buffer,
344                    DomainName->MaximumLength);
345         }
346 
347         MIDL_user_free(DomainName);
348     }
349 
350     /* Domain SID */
351     AttributeSize = 0;
352     Status = LsapGetObjectAttribute(PolicyObject,
353                                     L"PolAcDmS",
354                                     NULL,
355                                     &AttributeSize);
356     if (!NT_SUCCESS(Status))
357     {
358         goto Done;
359     }
360 
361     if (AttributeSize > 0)
362     {
363         p->Sid = MIDL_user_allocate(AttributeSize);
364         if (p->Sid == NULL)
365         {
366             Status = STATUS_INSUFFICIENT_RESOURCES;
367             goto Done;
368         }
369 
370         Status = LsapGetObjectAttribute(PolicyObject,
371                                         L"PolAcDmS",
372                                         p->Sid,
373                                         &AttributeSize);
374     }
375 
376     *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
377 
378 Done:
379     if (!NT_SUCCESS(Status))
380     {
381         if (p)
382         {
383             if (p->DomainName.Buffer)
384                 MIDL_user_free(p->DomainName.Buffer);
385 
386             if (p->Sid)
387                 MIDL_user_free(p->Sid);
388 
389             MIDL_user_free(p);
390         }
391     }
392 
393     return Status;
394 }
395 
396 
397 NTSTATUS
LsarQueryServerRole(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)398 LsarQueryServerRole(PLSA_DB_OBJECT PolicyObject,
399                     PLSAPR_POLICY_INFORMATION *PolicyInformation)
400 {
401     PPOLICY_LSA_SERVER_ROLE_INFO ServerRoleInfo = NULL;
402     ULONG AttributeSize;
403     NTSTATUS Status;
404 
405     *PolicyInformation = NULL;
406 
407     AttributeSize = sizeof(POLICY_LSA_SERVER_ROLE_INFO);
408     ServerRoleInfo = MIDL_user_allocate(AttributeSize);
409     if (ServerRoleInfo == NULL)
410         return STATUS_INSUFFICIENT_RESOURCES;
411 
412     Status = LsapGetObjectAttribute(PolicyObject,
413                                     L"PolSrvRo",
414                                     ServerRoleInfo,
415                                     &AttributeSize);
416     if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
417     {
418         ServerRoleInfo->LsaServerRole = PolicyServerRolePrimary;
419         Status = STATUS_SUCCESS;
420     }
421 
422     if (!NT_SUCCESS(Status))
423     {
424         MIDL_user_free(ServerRoleInfo);
425     }
426     else
427     {
428         *PolicyInformation = (PLSAPR_POLICY_INFORMATION)ServerRoleInfo;
429     }
430 
431     return Status;
432 }
433 
434 
435 NTSTATUS
LsarQueryReplicaSource(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)436 LsarQueryReplicaSource(PLSA_DB_OBJECT PolicyObject,
437                        PLSAPR_POLICY_INFORMATION *PolicyInformation)
438 {
439     FIXME("\n");
440     *PolicyInformation = NULL;
441     return STATUS_NOT_IMPLEMENTED;
442 }
443 
444 
445 NTSTATUS
LsarQueryDefaultQuota(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)446 LsarQueryDefaultQuota(PLSA_DB_OBJECT PolicyObject,
447                       PLSAPR_POLICY_INFORMATION *PolicyInformation)
448 {
449     PPOLICY_DEFAULT_QUOTA_INFO QuotaInfo = NULL;
450     ULONG AttributeSize;
451     NTSTATUS Status;
452 
453     *PolicyInformation = NULL;
454 
455     AttributeSize = sizeof(POLICY_DEFAULT_QUOTA_INFO);
456     QuotaInfo = MIDL_user_allocate(AttributeSize);
457     if (QuotaInfo == NULL)
458         return STATUS_INSUFFICIENT_RESOURCES;
459 
460     Status = LsapGetObjectAttribute(PolicyObject,
461                                     L"DefQuota",
462                                     QuotaInfo,
463                                     &AttributeSize);
464     if (!NT_SUCCESS(Status))
465     {
466         MIDL_user_free(QuotaInfo);
467     }
468     else
469     {
470         *PolicyInformation = (PLSAPR_POLICY_INFORMATION)QuotaInfo;
471     }
472 
473     return Status;
474 }
475 
476 
477 NTSTATUS
LsarQueryModification(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)478 LsarQueryModification(PLSA_DB_OBJECT PolicyObject,
479                       PLSAPR_POLICY_INFORMATION *PolicyInformation)
480 {
481     PPOLICY_MODIFICATION_INFO Info = NULL;
482     ULONG AttributeSize;
483     NTSTATUS Status;
484 
485     *PolicyInformation = NULL;
486 
487     AttributeSize = sizeof(POLICY_MODIFICATION_INFO);
488     Info = MIDL_user_allocate(AttributeSize);
489     if (Info == NULL)
490         return STATUS_INSUFFICIENT_RESOURCES;
491 
492     Status = LsapGetObjectAttribute(PolicyObject,
493                                     L"PolMod",
494                                     Info,
495                                     &AttributeSize);
496     if (!NT_SUCCESS(Status))
497     {
498         MIDL_user_free(Info);
499     }
500     else
501     {
502         *PolicyInformation = (PLSAPR_POLICY_INFORMATION)Info;
503     }
504 
505     return Status;
506 }
507 
508 
509 NTSTATUS
LsarQueryAuditFull(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)510 LsarQueryAuditFull(PLSA_DB_OBJECT PolicyObject,
511                    PLSAPR_POLICY_INFORMATION *PolicyInformation)
512 {
513     PPOLICY_AUDIT_FULL_QUERY_INFO AuditFullInfo = NULL;
514     ULONG AttributeSize;
515     NTSTATUS Status;
516 
517     *PolicyInformation = NULL;
518 
519     AttributeSize = sizeof(POLICY_AUDIT_FULL_QUERY_INFO);
520     AuditFullInfo = MIDL_user_allocate(AttributeSize);
521     if (AuditFullInfo == NULL)
522         return STATUS_INSUFFICIENT_RESOURCES;
523 
524     Status = LsapGetObjectAttribute(PolicyObject,
525                                     L"PolAdtFl",
526                                     AuditFullInfo,
527                                     &AttributeSize);
528     if (!NT_SUCCESS(Status))
529     {
530         MIDL_user_free(AuditFullInfo);
531     }
532     else
533     {
534         *PolicyInformation = (PLSAPR_POLICY_INFORMATION)AuditFullInfo;
535     }
536 
537     return Status;
538 }
539 
540 
541 NTSTATUS
LsarQueryDnsDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)542 LsarQueryDnsDomain(PLSA_DB_OBJECT PolicyObject,
543                    PLSAPR_POLICY_INFORMATION *PolicyInformation)
544 {
545     PLSAPR_POLICY_DNS_DOMAIN_INFO p = NULL;
546     PUNICODE_STRING DomainName;
547     ULONG AttributeSize;
548     NTSTATUS Status;
549 
550     *PolicyInformation = NULL;
551 
552     p = MIDL_user_allocate(sizeof(LSAPR_POLICY_DNS_DOMAIN_INFO));
553     if (p == NULL)
554         return STATUS_INSUFFICIENT_RESOURCES;
555 
556     /* Primary Domain Name */
557     AttributeSize = 0;
558     Status = LsapGetObjectAttribute(PolicyObject,
559                                     L"PolPrDmN",
560                                     NULL,
561                                     &AttributeSize);
562     if (!NT_SUCCESS(Status))
563     {
564         goto done;
565     }
566 
567     if (AttributeSize > 0)
568     {
569         DomainName = MIDL_user_allocate(AttributeSize);
570         if (DomainName == NULL)
571         {
572             Status = STATUS_INSUFFICIENT_RESOURCES;
573             goto done;
574         }
575 
576         Status = LsapGetObjectAttribute(PolicyObject,
577                                         L"PolPrDmN",
578                                         DomainName,
579                                         &AttributeSize);
580         if (Status == STATUS_SUCCESS)
581         {
582             DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
583 
584             TRACE("PrimaryDomainName: %wZ\n", DomainName);
585 
586             p->Name.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
587             if (p->Name.Buffer == NULL)
588             {
589                 MIDL_user_free(DomainName);
590                 Status = STATUS_INSUFFICIENT_RESOURCES;
591                 goto done;
592             }
593 
594             p->Name.Length = DomainName->Length;
595             p->Name.MaximumLength = DomainName->MaximumLength;
596             memcpy(p->Name.Buffer,
597                    DomainName->Buffer,
598                    DomainName->MaximumLength);
599         }
600 
601         MIDL_user_free(DomainName);
602     }
603 
604     /* Primary Domain SID */
605     AttributeSize = 0;
606     Status = LsapGetObjectAttribute(PolicyObject,
607                                     L"PolPrDmS",
608                                     NULL,
609                                     &AttributeSize);
610     if (!NT_SUCCESS(Status))
611     {
612         goto done;
613     }
614 
615     if (AttributeSize > 0)
616     {
617         p->Sid = MIDL_user_allocate(AttributeSize);
618         if (p->Sid == NULL)
619         {
620             Status = STATUS_INSUFFICIENT_RESOURCES;
621             goto done;
622         }
623 
624         Status = LsapGetObjectAttribute(PolicyObject,
625                                         L"PolPrDmS",
626                                         p->Sid,
627                                         &AttributeSize);
628     }
629 
630     /* DNS Domain Name */
631     AttributeSize = 0;
632     Status = LsapGetObjectAttribute(PolicyObject,
633                                     L"PolDnDDN",
634                                     NULL,
635                                     &AttributeSize);
636     if (!NT_SUCCESS(Status))
637         goto done;
638 
639     if (AttributeSize > 0)
640     {
641         DomainName = MIDL_user_allocate(AttributeSize);
642         if (DomainName == NULL)
643         {
644             Status = STATUS_INSUFFICIENT_RESOURCES;
645             goto done;
646         }
647 
648         Status = LsapGetObjectAttribute(PolicyObject,
649                                         L"PolDnDDN",
650                                         DomainName,
651                                         &AttributeSize);
652         if (Status == STATUS_SUCCESS)
653         {
654             DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
655 
656             TRACE("DNS Domain Name: %wZ\n", DomainName);
657 
658             p->DnsDomainName.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
659             if (p->DnsDomainName.Buffer == NULL)
660             {
661                 MIDL_user_free(DomainName);
662                 Status = STATUS_INSUFFICIENT_RESOURCES;
663                 goto done;
664             }
665 
666             p->DnsDomainName.Length = DomainName->Length;
667             p->DnsDomainName.MaximumLength = DomainName->MaximumLength;
668             memcpy(p->DnsDomainName.Buffer,
669                    DomainName->Buffer,
670                    DomainName->MaximumLength);
671         }
672 
673         MIDL_user_free(DomainName);
674     }
675 
676     /* DNS Forest Name */
677     AttributeSize = 0;
678     Status = LsapGetObjectAttribute(PolicyObject,
679                                     L"PolDnTrN",
680                                     NULL,
681                                     &AttributeSize);
682     if (!NT_SUCCESS(Status))
683         goto done;
684 
685     if (AttributeSize > 0)
686     {
687         DomainName = MIDL_user_allocate(AttributeSize);
688         if (DomainName == NULL)
689         {
690             Status = STATUS_INSUFFICIENT_RESOURCES;
691             goto done;
692         }
693 
694         Status = LsapGetObjectAttribute(PolicyObject,
695                                         L"PolDnTrN",
696                                         DomainName,
697                                         &AttributeSize);
698         if (Status == STATUS_SUCCESS)
699         {
700             DomainName->Buffer = (LPWSTR)((ULONG_PTR)DomainName + (ULONG_PTR)DomainName->Buffer);
701 
702             TRACE("DNS Forest Name: %wZ\n", DomainName);
703 
704             p->DnsForestName.Buffer = MIDL_user_allocate(DomainName->MaximumLength);
705             if (p->DnsForestName.Buffer == NULL)
706             {
707                 MIDL_user_free(DomainName);
708                 Status = STATUS_INSUFFICIENT_RESOURCES;
709                 goto done;
710             }
711 
712             p->DnsForestName.Length = DomainName->Length;
713             p->DnsForestName.MaximumLength = DomainName->MaximumLength;
714             memcpy(p->DnsForestName.Buffer,
715                    DomainName->Buffer,
716                    DomainName->MaximumLength);
717         }
718 
719         MIDL_user_free(DomainName);
720     }
721 
722     /* DNS Domain GUID */
723     AttributeSize = sizeof(GUID);
724     Status = LsapGetObjectAttribute(PolicyObject,
725                                     L"PolDnDmG",
726                                     &(p->DomainGuid),
727                                     &AttributeSize);
728     if (!NT_SUCCESS(Status))
729         goto done;
730 
731     *PolicyInformation = (PLSAPR_POLICY_INFORMATION)p;
732 
733 done:
734     if (!NT_SUCCESS(Status))
735     {
736         if (p)
737         {
738             if (p->Name.Buffer)
739                 MIDL_user_free(p->Name.Buffer);
740 
741             if (p->DnsDomainName.Buffer)
742                 MIDL_user_free(p->DnsDomainName.Buffer);
743 
744             if (p->DnsForestName.Buffer)
745                 MIDL_user_free(p->DnsForestName.Buffer);
746 
747             if (p->Sid)
748                 MIDL_user_free(p->Sid);
749 
750             MIDL_user_free(p);
751         }
752     }
753 
754     return Status;
755 }
756 
757 
758 NTSTATUS
LsarQueryDnsDomainInt(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)759 LsarQueryDnsDomainInt(PLSA_DB_OBJECT PolicyObject,
760                       PLSAPR_POLICY_INFORMATION *PolicyInformation)
761 {
762     FIXME("\n");
763     *PolicyInformation = NULL;
764     return STATUS_NOT_IMPLEMENTED;
765 }
766 
767 
768 NTSTATUS
LsarQueryLocalAccountDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_INFORMATION * PolicyInformation)769 LsarQueryLocalAccountDomain(PLSA_DB_OBJECT PolicyObject,
770                             PLSAPR_POLICY_INFORMATION *PolicyInformation)
771 {
772     FIXME("\n");
773     *PolicyInformation = NULL;
774     return STATUS_NOT_IMPLEMENTED;
775 }
776 
777 
778 NTSTATUS
LsarSetAuditLog(PLSA_DB_OBJECT PolicyObject,PPOLICY_AUDIT_LOG_INFO Info)779 LsarSetAuditLog(PLSA_DB_OBJECT PolicyObject,
780                 PPOLICY_AUDIT_LOG_INFO Info)
781 {
782     TRACE("(%p %p)\n", PolicyObject, Info);
783 
784     return LsapSetObjectAttribute(PolicyObject,
785                                   L"PolAdtLg",
786                                   Info,
787                                   sizeof(POLICY_AUDIT_LOG_INFO));
788 }
789 
790 
791 NTSTATUS
LsarSetAuditEvents(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_AUDIT_EVENTS_INFO Info)792 LsarSetAuditEvents(PLSA_DB_OBJECT PolicyObject,
793                    PLSAPR_POLICY_AUDIT_EVENTS_INFO Info)
794 {
795     PLSAP_POLICY_AUDIT_EVENTS_DATA AuditData = NULL;
796     ULONG AttributeSize;
797     NTSTATUS Status = STATUS_SUCCESS;
798 
799     TRACE("(%p %p)\n", PolicyObject, Info);
800 
801     AttributeSize = sizeof(LSAP_POLICY_AUDIT_EVENTS_DATA) +
802                     Info->MaximumAuditEventCount * sizeof(DWORD);
803 
804     AuditData = RtlAllocateHeap(RtlGetProcessHeap(),
805                                 HEAP_ZERO_MEMORY,
806                                 AttributeSize);
807     if (AuditData == NULL)
808         return STATUS_INSUFFICIENT_RESOURCES;
809 
810     AuditData->AuditingMode = Info->AuditingMode;
811     AuditData->MaximumAuditEventCount = Info->MaximumAuditEventCount;
812 
813     memcpy(&(AuditData->AuditEvents[0]),
814            Info->EventAuditingOptions,
815            Info->MaximumAuditEventCount * sizeof(DWORD));
816 
817     Status = LsapSetObjectAttribute(PolicyObject,
818                                     L"PolAdtEv",
819                                     AuditData,
820                                     AttributeSize);
821 
822     RtlFreeHeap(RtlGetProcessHeap(), 0, AuditData);
823 
824     return Status;
825 }
826 
827 
828 NTSTATUS
LsarSetPrimaryDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_PRIMARY_DOM_INFO Info)829 LsarSetPrimaryDomain(PLSA_DB_OBJECT PolicyObject,
830                      PLSAPR_POLICY_PRIMARY_DOM_INFO Info)
831 {
832     PUNICODE_STRING Buffer;
833     ULONG Length = 0;
834     NTSTATUS Status;
835     LPWSTR Ptr;
836 
837     TRACE("(%p %p)\n", PolicyObject, Info);
838 
839     Length = sizeof(UNICODE_STRING) + Info->Name.MaximumLength;
840     Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
841                              0,
842                              Length);
843     if (Buffer == NULL)
844         return STATUS_INSUFFICIENT_RESOURCES;
845 
846     Buffer->Length = Info->Name.Length;
847     Buffer->MaximumLength = Info->Name.MaximumLength;
848     Buffer->Buffer = (LPWSTR)sizeof(UNICODE_STRING);
849     Ptr = (LPWSTR)((ULONG_PTR)Buffer + sizeof(UNICODE_STRING));
850     memcpy(Ptr, Info->Name.Buffer, Info->Name.MaximumLength);
851 
852     Status = LsapSetObjectAttribute(PolicyObject,
853                                     L"PolPrDmN",
854                                     Buffer,
855                                     Length);
856 
857     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
858 
859     if (!NT_SUCCESS(Status))
860         return Status;
861 
862     Length = 0;
863     if (Info->Sid != NULL)
864         Length = RtlLengthSid(Info->Sid);
865 
866     Status = LsapSetObjectAttribute(PolicyObject,
867                                     L"PolPrDmS",
868                                     (LPBYTE)Info->Sid,
869                                     Length);
870 
871     return Status;
872 }
873 
874 
875 NTSTATUS
LsarSetAccountDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_ACCOUNT_DOM_INFO Info)876 LsarSetAccountDomain(PLSA_DB_OBJECT PolicyObject,
877                      PLSAPR_POLICY_ACCOUNT_DOM_INFO Info)
878 {
879     PUNICODE_STRING Buffer;
880     ULONG Length = 0;
881     NTSTATUS Status;
882     LPWSTR Ptr;
883 
884     TRACE("(%p %p)\n", PolicyObject, Info);
885 
886     Length = sizeof(UNICODE_STRING) + Info->DomainName.MaximumLength;
887     Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
888                              0,
889                              Length);
890     if (Buffer == NULL)
891         return STATUS_INSUFFICIENT_RESOURCES;
892 
893     Buffer->Length = Info->DomainName.Length;
894     Buffer->MaximumLength = Info->DomainName.MaximumLength;
895     Buffer->Buffer = (LPWSTR)sizeof(UNICODE_STRING);
896     Ptr = (LPWSTR)((ULONG_PTR)Buffer + sizeof(UNICODE_STRING));
897     memcpy(Ptr, Info->DomainName.Buffer, Info->DomainName.MaximumLength);
898 
899     Status = LsapSetObjectAttribute(PolicyObject,
900                                     L"PolAcDmN",
901                                     Buffer,
902                                     Length);
903 
904     RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
905 
906     if (!NT_SUCCESS(Status))
907         return Status;
908 
909     Length = 0;
910     if (Info->Sid != NULL)
911         Length = RtlLengthSid(Info->Sid);
912 
913     Status = LsapSetObjectAttribute(PolicyObject,
914                                     L"PolAcDmS",
915                                     (LPBYTE)Info->Sid,
916                                     Length);
917 
918     return Status;
919 }
920 
921 
922 NTSTATUS
LsarSetServerRole(PLSA_DB_OBJECT PolicyObject,PPOLICY_LSA_SERVER_ROLE_INFO Info)923 LsarSetServerRole(PLSA_DB_OBJECT PolicyObject,
924                   PPOLICY_LSA_SERVER_ROLE_INFO Info)
925 {
926     TRACE("(%p %p)\n", PolicyObject, Info);
927 
928     return LsapSetObjectAttribute(PolicyObject,
929                                   L"PolSrvRo",
930                                   Info,
931                                   sizeof(POLICY_LSA_SERVER_ROLE_INFO));
932 }
933 
934 
935 NTSTATUS
LsarSetReplicaSource(PLSA_DB_OBJECT PolicyObject,PPOLICY_LSA_REPLICA_SRCE_INFO Info)936 LsarSetReplicaSource(PLSA_DB_OBJECT PolicyObject,
937                      PPOLICY_LSA_REPLICA_SRCE_INFO Info)
938 {
939     FIXME("\n");
940     return STATUS_NOT_IMPLEMENTED;
941 }
942 
943 
944 NTSTATUS
LsarSetDefaultQuota(PLSA_DB_OBJECT PolicyObject,PPOLICY_DEFAULT_QUOTA_INFO Info)945 LsarSetDefaultQuota(PLSA_DB_OBJECT PolicyObject,
946                     PPOLICY_DEFAULT_QUOTA_INFO Info)
947 {
948     TRACE("(%p %p)\n", PolicyObject, Info);
949 
950     return LsapSetObjectAttribute(PolicyObject,
951                                   L"DefQuota",
952                                   Info,
953                                   sizeof(POLICY_DEFAULT_QUOTA_INFO));
954 }
955 
956 
957 NTSTATUS
LsarSetModification(PLSA_DB_OBJECT PolicyObject,PPOLICY_MODIFICATION_INFO Info)958 LsarSetModification(PLSA_DB_OBJECT PolicyObject,
959                     PPOLICY_MODIFICATION_INFO Info)
960 {
961     TRACE("(%p %p)\n", PolicyObject, Info);
962 
963     return LsapSetObjectAttribute(PolicyObject,
964                                   L"PolMod",
965                                   Info,
966                                   sizeof(POLICY_MODIFICATION_INFO));
967 }
968 
969 
970 NTSTATUS
LsarSetAuditFull(PLSA_DB_OBJECT PolicyObject,PPOLICY_AUDIT_FULL_QUERY_INFO Info)971 LsarSetAuditFull(PLSA_DB_OBJECT PolicyObject,
972                  PPOLICY_AUDIT_FULL_QUERY_INFO Info)
973 {
974     PPOLICY_AUDIT_FULL_QUERY_INFO AuditFullInfo = NULL;
975     ULONG AttributeSize;
976     NTSTATUS Status;
977 
978     TRACE("(%p %p)\n", PolicyObject, Info);
979 
980     AttributeSize = sizeof(POLICY_AUDIT_FULL_QUERY_INFO);
981     AuditFullInfo = MIDL_user_allocate(AttributeSize);
982     if (AuditFullInfo == NULL)
983         return STATUS_INSUFFICIENT_RESOURCES;
984 
985     Status = LsapGetObjectAttribute(PolicyObject,
986                                     L"PolAdtFl",
987                                     AuditFullInfo,
988                                     &AttributeSize);
989     if (!NT_SUCCESS(Status))
990         goto done;
991 
992     AuditFullInfo->ShutDownOnFull = Info->ShutDownOnFull;
993 
994     Status = LsapSetObjectAttribute(PolicyObject,
995                                     L"PolAdtFl",
996                                     AuditFullInfo,
997                                     AttributeSize);
998 
999 done:
1000     if (AuditFullInfo != NULL)
1001         MIDL_user_free(AuditFullInfo);
1002 
1003     return Status;
1004 }
1005 
1006 
1007 NTSTATUS
LsarSetDnsDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_DNS_DOMAIN_INFO Info)1008 LsarSetDnsDomain(PLSA_DB_OBJECT PolicyObject,
1009                  PLSAPR_POLICY_DNS_DOMAIN_INFO Info)
1010 {
1011     FIXME("\n");
1012     return STATUS_NOT_IMPLEMENTED;
1013 }
1014 
1015 
1016 NTSTATUS
LsarSetDnsDomainInt(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_DNS_DOMAIN_INFO Info)1017 LsarSetDnsDomainInt(PLSA_DB_OBJECT PolicyObject,
1018                     PLSAPR_POLICY_DNS_DOMAIN_INFO Info)
1019 {
1020     FIXME("\n");
1021     return STATUS_NOT_IMPLEMENTED;
1022 }
1023 
1024 
1025 NTSTATUS
LsarSetLocalAccountDomain(PLSA_DB_OBJECT PolicyObject,PLSAPR_POLICY_ACCOUNT_DOM_INFO Info)1026 LsarSetLocalAccountDomain(PLSA_DB_OBJECT PolicyObject,
1027                           PLSAPR_POLICY_ACCOUNT_DOM_INFO Info)
1028 {
1029     FIXME("\n");
1030     return STATUS_NOT_IMPLEMENTED;
1031 }
1032 
1033 /* EOF */
1034