0df15ce8f15273f592ac55f66a6707d883e1afc6
[reactos.git] / reactos / dll / win32 / lsasrv / lsarpc.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Local Security Authority (LSA) Server
4 * FILE: reactos/dll/win32/lsasrv/lsarpc.h
5 * PURPOSE: RPC interface functions
6 *
7 * PROGRAMMERS: Eric Kohl
8 */
9
10 #include "lsasrv.h"
11
12 /* GLOBALS *****************************************************************/
13
14 static RTL_CRITICAL_SECTION PolicyHandleTableLock;
15
16
17 /* FUNCTIONS ***************************************************************/
18
19 VOID
20 LsarStartRpcServer(VOID)
21 {
22 RPC_STATUS Status;
23
24 RtlInitializeCriticalSection(&PolicyHandleTableLock);
25
26 TRACE("LsarStartRpcServer() called\n");
27
28 Status = RpcServerUseProtseqEpW(L"ncacn_np",
29 10,
30 L"\\pipe\\lsarpc",
31 NULL);
32 if (Status != RPC_S_OK)
33 {
34 WARN("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
35 return;
36 }
37
38 Status = RpcServerRegisterIf(lsarpc_v0_0_s_ifspec,
39 NULL,
40 NULL);
41 if (Status != RPC_S_OK)
42 {
43 WARN("RpcServerRegisterIf() failed (Status %lx)\n", Status);
44 return;
45 }
46
47 DsSetupInit();
48
49 Status = RpcServerListen(1, 20, TRUE);
50 if (Status != RPC_S_OK)
51 {
52 WARN("RpcServerListen() failed (Status %lx)\n", Status);
53 return;
54 }
55
56 TRACE("LsarStartRpcServer() done\n");
57 }
58
59
60 void __RPC_USER LSAPR_HANDLE_rundown(LSAPR_HANDLE hHandle)
61 {
62
63 }
64
65
66 /* Function 0 */
67 NTSTATUS WINAPI LsarClose(
68 LSAPR_HANDLE *ObjectHandle)
69 {
70 PLSA_DB_OBJECT DbObject;
71 NTSTATUS Status = STATUS_SUCCESS;
72
73 TRACE("0x%p\n", ObjectHandle);
74
75 // RtlEnterCriticalSection(&PolicyHandleTableLock);
76
77 Status = LsapValidateDbObject(*ObjectHandle,
78 LsaDbIgnoreObject,
79 0,
80 &DbObject);
81 if (Status == STATUS_SUCCESS)
82 {
83 Status = LsapCloseDbObject(DbObject);
84 *ObjectHandle = NULL;
85 }
86
87 // RtlLeaveCriticalSection(&PolicyHandleTableLock);
88
89 return Status;
90 }
91
92
93 /* Function 1 */
94 NTSTATUS WINAPI LsarDelete(
95 LSAPR_HANDLE ObjectHandle)
96 {
97 return LsarDeleteObject(&ObjectHandle);
98 }
99
100
101 /* Function 2 */
102 NTSTATUS WINAPI LsarEnumeratePrivileges(
103 LSAPR_HANDLE PolicyHandle,
104 DWORD *EnumerationContext,
105 PLSAPR_PRIVILEGE_ENUM_BUFFER EnumerationBuffer,
106 DWORD PreferedMaximumLength)
107 {
108 PLSA_DB_OBJECT PolicyObject;
109 NTSTATUS Status;
110
111 TRACE("LsarEnumeratePrivileges(%p %p %p %lu)\n",
112 PolicyHandle, EnumerationContext, EnumerationBuffer,
113 PreferedMaximumLength);
114
115 Status = LsapValidateDbObject(PolicyHandle,
116 LsaDbPolicyObject,
117 POLICY_VIEW_LOCAL_INFORMATION,
118 &PolicyObject);
119 if (!NT_SUCCESS(Status))
120 return Status;
121
122 if (EnumerationContext == NULL)
123 return STATUS_INVALID_PARAMETER;
124
125 return LsarpEnumeratePrivileges(EnumerationContext,
126 EnumerationBuffer,
127 PreferedMaximumLength);
128 }
129
130
131 /* Function 3 */
132 NTSTATUS WINAPI LsarQuerySecurityObject(
133 LSAPR_HANDLE ObjectHandle,
134 SECURITY_INFORMATION SecurityInformation,
135 PLSAPR_SR_SECURITY_DESCRIPTOR *SecurityDescriptor)
136 {
137 PLSA_DB_OBJECT DbObject = NULL;
138 PSECURITY_DESCRIPTOR RelativeSd = NULL;
139 PLSAPR_SR_SECURITY_DESCRIPTOR SdData = NULL;
140 ACCESS_MASK DesiredAccess = 0;
141 ULONG RelativeSdSize = 0;
142 NTSTATUS Status;
143
144 if (SecurityDescriptor == NULL)
145 return STATUS_INVALID_PARAMETER;
146
147 if ((SecurityInformation & OWNER_SECURITY_INFORMATION) ||
148 (SecurityInformation & GROUP_SECURITY_INFORMATION) ||
149 (SecurityInformation & DACL_SECURITY_INFORMATION))
150 DesiredAccess |= READ_CONTROL;
151
152 if (SecurityInformation & SACL_SECURITY_INFORMATION)
153 DesiredAccess |= ACCESS_SYSTEM_SECURITY;
154
155 /* Validate the ObjectHandle */
156 Status = LsapValidateDbObject(ObjectHandle,
157 LsaDbIgnoreObject,
158 DesiredAccess,
159 &DbObject);
160 if (!NT_SUCCESS(Status))
161 return Status;
162
163 /* Get the size of the SD */
164 Status = LsapGetObjectAttribute(DbObject,
165 L"SecDesc",
166 NULL,
167 &RelativeSdSize);
168 if (!NT_SUCCESS(Status))
169 return Status;
170
171 /* Allocate a buffer for the SD */
172 RelativeSd = MIDL_user_allocate(RelativeSdSize);
173 if (RelativeSd == NULL)
174 return STATUS_INSUFFICIENT_RESOURCES;
175
176 /* Get the SD */
177 Status = LsapGetObjectAttribute(DbObject,
178 L"SecDesc",
179 RelativeSd,
180 &RelativeSdSize);
181 if (!NT_SUCCESS(Status))
182 goto done;
183
184 /*
185 * FIXME: Invalidate the SD information that was not requested.
186 * (see SecurityInformation)
187 */
188
189 /* Allocate the SD data buffer */
190 SdData = MIDL_user_allocate(sizeof(LSAPR_SR_SECURITY_DESCRIPTOR));
191 if (SdData == NULL)
192 {
193 Status = STATUS_INSUFFICIENT_RESOURCES;
194 goto done;
195 }
196
197 /* Fill the SD data buffer and return it to the caller */
198 SdData->Length = RelativeSdSize;
199 SdData->SecurityDescriptor = (PBYTE)RelativeSd;
200
201 *SecurityDescriptor = SdData;
202
203 done:
204 if (!NT_SUCCESS(Status))
205 {
206 if (RelativeSd != NULL)
207 MIDL_user_free(RelativeSd);
208 }
209
210 return Status;
211 }
212
213
214 /* Function 4 */
215 NTSTATUS WINAPI LsarSetSecurityObject(
216 LSAPR_HANDLE ObjectHandle,
217 SECURITY_INFORMATION SecurityInformation,
218 PLSAPR_SR_SECURITY_DESCRIPTOR SecurityDescriptor)
219 {
220 UNIMPLEMENTED;
221 return STATUS_NOT_IMPLEMENTED;
222 }
223
224
225 /* Function 5 */
226 NTSTATUS WINAPI LsarChangePassword(
227 handle_t IDL_handle,
228 PRPC_UNICODE_STRING String1,
229 PRPC_UNICODE_STRING String2,
230 PRPC_UNICODE_STRING String3,
231 PRPC_UNICODE_STRING String4,
232 PRPC_UNICODE_STRING String5)
233 {
234 /* Deprecated */
235 return STATUS_NOT_IMPLEMENTED;
236 }
237
238
239 /* Function 6 */
240 NTSTATUS WINAPI LsarOpenPolicy(
241 LPWSTR SystemName,
242 PLSAPR_OBJECT_ATTRIBUTES ObjectAttributes,
243 ACCESS_MASK DesiredAccess,
244 LSAPR_HANDLE *PolicyHandle)
245 {
246 PLSA_DB_OBJECT PolicyObject;
247 NTSTATUS Status;
248
249 TRACE("LsarOpenPolicy called!\n");
250
251 RtlEnterCriticalSection(&PolicyHandleTableLock);
252
253 Status = LsapOpenDbObject(NULL,
254 NULL,
255 L"Policy",
256 LsaDbPolicyObject,
257 DesiredAccess,
258 FALSE,
259 &PolicyObject);
260
261 RtlLeaveCriticalSection(&PolicyHandleTableLock);
262
263 if (NT_SUCCESS(Status))
264 *PolicyHandle = (LSAPR_HANDLE)PolicyObject;
265
266 TRACE("LsarOpenPolicy done!\n");
267
268 return Status;
269 }
270
271
272 /* Function 7 */
273 NTSTATUS WINAPI LsarQueryInformationPolicy(
274 LSAPR_HANDLE PolicyHandle,
275 POLICY_INFORMATION_CLASS InformationClass,
276 PLSAPR_POLICY_INFORMATION *PolicyInformation)
277 {
278 PLSA_DB_OBJECT PolicyObject;
279 ACCESS_MASK DesiredAccess = 0;
280 NTSTATUS Status;
281
282 TRACE("LsarQueryInformationPolicy(%p,0x%08x,%p)\n",
283 PolicyHandle, InformationClass, PolicyInformation);
284
285 if (PolicyInformation)
286 {
287 TRACE("*PolicyInformation %p\n", *PolicyInformation);
288 }
289
290 switch (InformationClass)
291 {
292 case PolicyAuditLogInformation:
293 case PolicyAuditEventsInformation:
294 case PolicyAuditFullQueryInformation:
295 DesiredAccess = POLICY_VIEW_AUDIT_INFORMATION;
296 break;
297
298 case PolicyPrimaryDomainInformation:
299 case PolicyAccountDomainInformation:
300 case PolicyLsaServerRoleInformation:
301 case PolicyReplicaSourceInformation:
302 case PolicyDefaultQuotaInformation:
303 case PolicyModificationInformation:
304 case PolicyDnsDomainInformation:
305 case PolicyDnsDomainInformationInt:
306 case PolicyLocalAccountDomainInformation:
307 DesiredAccess = POLICY_VIEW_LOCAL_INFORMATION;
308 break;
309
310 case PolicyPdAccountInformation:
311 DesiredAccess = POLICY_GET_PRIVATE_INFORMATION;
312 break;
313
314 default:
315 ERR("Invalid InformationClass!\n");
316 return STATUS_INVALID_PARAMETER;
317 }
318
319 Status = LsapValidateDbObject(PolicyHandle,
320 LsaDbPolicyObject,
321 DesiredAccess,
322 &PolicyObject);
323 if (!NT_SUCCESS(Status))
324 return Status;
325
326 switch (InformationClass)
327 {
328 case PolicyAuditLogInformation: /* 1 */
329 Status = LsarQueryAuditLog(PolicyObject,
330 PolicyInformation);
331 break;
332
333 case PolicyAuditEventsInformation: /* 2 */
334 Status = LsarQueryAuditEvents(PolicyObject,
335 PolicyInformation);
336 break;
337
338 case PolicyPrimaryDomainInformation: /* 3 */
339 Status = LsarQueryPrimaryDomain(PolicyObject,
340 PolicyInformation);
341 break;
342
343 case PolicyPdAccountInformation: /* 4 */
344 Status = LsarQueryPdAccount(PolicyObject,
345 PolicyInformation);
346 break;
347
348 case PolicyAccountDomainInformation: /* 5 */
349 Status = LsarQueryAccountDomain(PolicyObject,
350 PolicyInformation);
351 break;
352
353 case PolicyLsaServerRoleInformation: /* 6 */
354 Status = LsarQueryServerRole(PolicyObject,
355 PolicyInformation);
356 break;
357
358 case PolicyReplicaSourceInformation: /* 7 */
359 Status = LsarQueryReplicaSource(PolicyObject,
360 PolicyInformation);
361 break;
362
363 case PolicyDefaultQuotaInformation: /* 8 */
364 Status = LsarQueryDefaultQuota(PolicyObject,
365 PolicyInformation);
366 break;
367
368 case PolicyModificationInformation: /* 9 */
369 Status = LsarQueryModification(PolicyObject,
370 PolicyInformation);
371 break;
372
373 case PolicyAuditFullQueryInformation: /* 11 (0xB) */
374 Status = LsarQueryAuditFull(PolicyObject,
375 PolicyInformation);
376 break;
377
378 case PolicyDnsDomainInformation: /* 12 (0xC) */
379 Status = LsarQueryDnsDomain(PolicyObject,
380 PolicyInformation);
381 break;
382
383 case PolicyDnsDomainInformationInt: /* 13 (0xD) */
384 Status = LsarQueryDnsDomainInt(PolicyObject,
385 PolicyInformation);
386 break;
387
388 case PolicyLocalAccountDomainInformation: /* 14 (0xE) */
389 Status = LsarQueryLocalAccountDomain(PolicyObject,
390 PolicyInformation);
391 break;
392
393 default:
394 ERR("Invalid InformationClass!\n");
395 Status = STATUS_INVALID_PARAMETER;
396 }
397
398 return Status;
399 }
400
401
402 /* Function 8 */
403 NTSTATUS WINAPI LsarSetInformationPolicy(
404 LSAPR_HANDLE PolicyHandle,
405 POLICY_INFORMATION_CLASS InformationClass,
406 PLSAPR_POLICY_INFORMATION PolicyInformation)
407 {
408 PLSA_DB_OBJECT PolicyObject;
409 ACCESS_MASK DesiredAccess = 0;
410 NTSTATUS Status;
411
412 TRACE("LsarSetInformationPolicy(%p,0x%08x,%p)\n",
413 PolicyHandle, InformationClass, PolicyInformation);
414
415 if (PolicyInformation)
416 {
417 TRACE("*PolicyInformation %p\n", *PolicyInformation);
418 }
419
420 switch (InformationClass)
421 {
422 case PolicyAuditLogInformation:
423 case PolicyAuditFullSetInformation:
424 DesiredAccess = POLICY_AUDIT_LOG_ADMIN;
425 break;
426
427 case PolicyAuditEventsInformation:
428 DesiredAccess = POLICY_SET_AUDIT_REQUIREMENTS;
429 break;
430
431 case PolicyPrimaryDomainInformation:
432 case PolicyAccountDomainInformation:
433 case PolicyDnsDomainInformation:
434 case PolicyDnsDomainInformationInt:
435 case PolicyLocalAccountDomainInformation:
436 DesiredAccess = POLICY_TRUST_ADMIN;
437 break;
438
439 case PolicyLsaServerRoleInformation:
440 case PolicyReplicaSourceInformation:
441 DesiredAccess = POLICY_SERVER_ADMIN;
442 break;
443
444 case PolicyDefaultQuotaInformation:
445 DesiredAccess = POLICY_SET_DEFAULT_QUOTA_LIMITS;
446 break;
447
448 default:
449 ERR("Invalid InformationClass!\n");
450 return STATUS_INVALID_PARAMETER;
451 }
452
453 Status = LsapValidateDbObject(PolicyHandle,
454 LsaDbPolicyObject,
455 DesiredAccess,
456 &PolicyObject);
457 if (!NT_SUCCESS(Status))
458 return Status;
459
460 switch (InformationClass)
461 {
462 case PolicyAuditLogInformation: /* 1 */
463 Status = LsarSetAuditLog(PolicyObject,
464 (PPOLICY_AUDIT_LOG_INFO)PolicyInformation);
465 break;
466
467 case PolicyAuditEventsInformation: /* 2 */
468 Status = LsarSetAuditEvents(PolicyObject,
469 (PLSAPR_POLICY_AUDIT_EVENTS_INFO)PolicyInformation);
470 break;
471
472 case PolicyPrimaryDomainInformation: /* 3 */
473 Status = LsarSetPrimaryDomain(PolicyObject,
474 (PLSAPR_POLICY_PRIMARY_DOM_INFO)PolicyInformation);
475 break;
476
477 case PolicyAccountDomainInformation: /* 5 */
478 Status = LsarSetAccountDomain(PolicyObject,
479 (PLSAPR_POLICY_ACCOUNT_DOM_INFO)PolicyInformation);
480 break;
481
482 case PolicyLsaServerRoleInformation: /* 6 */
483 Status = LsarSetServerRole(PolicyObject,
484 (PPOLICY_LSA_SERVER_ROLE_INFO)PolicyInformation);
485 break;
486
487 case PolicyReplicaSourceInformation: /* 7 */
488 Status = LsarSetReplicaSource(PolicyObject,
489 (PPOLICY_LSA_REPLICA_SRCE_INFO)PolicyInformation);
490 break;
491
492 case PolicyDefaultQuotaInformation: /* 8 */
493 Status = LsarSetDefaultQuota(PolicyObject,
494 (PPOLICY_DEFAULT_QUOTA_INFO)PolicyInformation);
495 break;
496
497 case PolicyModificationInformation: /* 9 */
498 Status = LsarSetModification(PolicyObject,
499 (PPOLICY_MODIFICATION_INFO)PolicyInformation);
500 break;
501
502 case PolicyAuditFullSetInformation: /* 10 (0xA) */
503 Status = LsarSetAuditFull(PolicyObject,
504 (PPOLICY_AUDIT_FULL_QUERY_INFO)PolicyInformation);
505 break;
506
507 case PolicyDnsDomainInformation: /* 12 (0xC) */
508 Status = LsarSetDnsDomain(PolicyObject,
509 (PLSAPR_POLICY_DNS_DOMAIN_INFO)PolicyInformation);
510 break;
511
512 case PolicyDnsDomainInformationInt: /* 13 (0xD) */
513 Status = LsarSetDnsDomainInt(PolicyObject,
514 (PLSAPR_POLICY_DNS_DOMAIN_INFO)PolicyInformation);
515 break;
516
517 case PolicyLocalAccountDomainInformation: /* 14 (0xE) */
518 Status = LsarSetLocalAccountDomain(PolicyObject,
519 (PLSAPR_POLICY_ACCOUNT_DOM_INFO)PolicyInformation);
520 break;
521
522 default:
523 Status = STATUS_INVALID_PARAMETER;
524 break;
525 }
526
527 return Status;
528 }
529
530
531 /* Function 9 */
532 NTSTATUS WINAPI LsarClearAuditLog(
533 LSAPR_HANDLE ObjectHandle)
534 {
535 /* Deprecated */
536 return STATUS_NOT_IMPLEMENTED;
537 }
538
539
540 /* Function 10 */
541 NTSTATUS WINAPI LsarCreateAccount(
542 LSAPR_HANDLE PolicyHandle,
543 PRPC_SID AccountSid,
544 ACCESS_MASK DesiredAccess,
545 LSAPR_HANDLE *AccountHandle)
546 {
547 PLSA_DB_OBJECT PolicyObject;
548 PLSA_DB_OBJECT AccountObject = NULL;
549 LPWSTR SidString = NULL;
550 PSECURITY_DESCRIPTOR AccountSd = NULL;
551 ULONG AccountSdSize;
552 NTSTATUS Status = STATUS_SUCCESS;
553
554 /* Validate the AccountSid */
555 if (!RtlValidSid(AccountSid))
556 return STATUS_INVALID_PARAMETER;
557
558 /* Validate the PolicyHandle */
559 Status = LsapValidateDbObject(PolicyHandle,
560 LsaDbPolicyObject,
561 POLICY_CREATE_ACCOUNT,
562 &PolicyObject);
563 if (!NT_SUCCESS(Status))
564 {
565 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
566 return Status;
567 }
568
569 /* Create SID string */
570 if (!ConvertSidToStringSid((PSID)AccountSid,
571 &SidString))
572 {
573 ERR("ConvertSidToStringSid failed\n");
574 Status = STATUS_INVALID_PARAMETER;
575 goto done;
576 }
577
578 /* Create a security descriptor for the account */
579 Status = LsapCreateAccountSd(&AccountSd,
580 &AccountSdSize);
581 if (!NT_SUCCESS(Status))
582 {
583 ERR("LsapCreateAccountSd returned 0x%08lx\n", Status);
584 return Status;
585 }
586
587 /* Create the Account object */
588 Status = LsapCreateDbObject(PolicyObject,
589 L"Accounts",
590 SidString,
591 LsaDbAccountObject,
592 DesiredAccess,
593 PolicyObject->Trusted,
594 &AccountObject);
595 if (!NT_SUCCESS(Status))
596 {
597 ERR("LsapCreateDbObject failed (Status 0x%08lx)\n", Status);
598 goto done;
599 }
600
601 /* Set the Sid attribute */
602 Status = LsapSetObjectAttribute(AccountObject,
603 L"Sid",
604 (PVOID)AccountSid,
605 GetLengthSid(AccountSid));
606 if (!NT_SUCCESS(Status))
607 goto done;
608
609 /* Set the SecDesc attribute */
610 Status = LsapSetObjectAttribute(AccountObject,
611 L"SecDesc",
612 AccountSd,
613 AccountSdSize);
614
615 done:
616 if (SidString != NULL)
617 LocalFree(SidString);
618
619 if (AccountSd != NULL)
620 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountSd);
621
622 if (!NT_SUCCESS(Status))
623 {
624 if (AccountObject != NULL)
625 LsapCloseDbObject(AccountObject);
626 }
627 else
628 {
629 *AccountHandle = (LSAPR_HANDLE)AccountObject;
630 }
631
632 return STATUS_SUCCESS;
633 }
634
635
636 /* Function 11 */
637 NTSTATUS WINAPI LsarEnumerateAccounts(
638 LSAPR_HANDLE PolicyHandle,
639 DWORD *EnumerationContext,
640 PLSAPR_ACCOUNT_ENUM_BUFFER EnumerationBuffer,
641 DWORD PreferedMaximumLength)
642 {
643 LSAPR_ACCOUNT_ENUM_BUFFER EnumBuffer = {0, NULL};
644 PLSA_DB_OBJECT PolicyObject = NULL;
645 WCHAR AccountKeyName[64];
646 HANDLE AccountsKeyHandle = NULL;
647 HANDLE AccountKeyHandle;
648 HANDLE SidKeyHandle;
649 ULONG EnumIndex;
650 ULONG EnumCount;
651 ULONG RequiredLength;
652 ULONG DataLength;
653 ULONG i;
654 NTSTATUS Status = STATUS_SUCCESS;
655
656 TRACE("(%p %p %p %lu)\n", PolicyHandle, EnumerationContext,
657 EnumerationBuffer, PreferedMaximumLength);
658
659 if (EnumerationContext == NULL ||
660 EnumerationBuffer == NULL)
661 return STATUS_INVALID_PARAMETER;
662
663 EnumerationBuffer->EntriesRead = 0;
664 EnumerationBuffer->Information = NULL;
665
666 /* Validate the PolicyHandle */
667 Status = LsapValidateDbObject(PolicyHandle,
668 LsaDbPolicyObject,
669 POLICY_VIEW_LOCAL_INFORMATION,
670 &PolicyObject);
671 if (!NT_SUCCESS(Status))
672 {
673 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
674 return Status;
675 }
676
677 Status = LsapRegOpenKey(PolicyObject->KeyHandle,
678 L"Accounts",
679 KEY_READ,
680 &AccountsKeyHandle);
681 if (!NT_SUCCESS(Status))
682 return Status;
683
684 EnumIndex = *EnumerationContext;
685 EnumCount = 0;
686 RequiredLength = 0;
687
688 while (TRUE)
689 {
690 Status = LsapRegEnumerateSubKey(AccountsKeyHandle,
691 EnumIndex,
692 64 * sizeof(WCHAR),
693 AccountKeyName);
694 if (!NT_SUCCESS(Status))
695 break;
696
697 TRACE("EnumIndex: %lu\n", EnumIndex);
698 TRACE("Account key name: %S\n", AccountKeyName);
699
700 Status = LsapRegOpenKey(AccountsKeyHandle,
701 AccountKeyName,
702 KEY_READ,
703 &AccountKeyHandle);
704 TRACE("LsapRegOpenKey returned %08lX\n", Status);
705 if (NT_SUCCESS(Status))
706 {
707 Status = LsapRegOpenKey(AccountKeyHandle,
708 L"Sid",
709 KEY_READ,
710 &SidKeyHandle);
711 TRACE("LsapRegOpenKey returned %08lX\n", Status);
712 if (NT_SUCCESS(Status))
713 {
714 DataLength = 0;
715 Status = LsapRegQueryValue(SidKeyHandle,
716 NULL,
717 NULL,
718 NULL,
719 &DataLength);
720 TRACE("LsapRegQueryValue returned %08lX\n", Status);
721 if (NT_SUCCESS(Status))
722 {
723 TRACE("Data length: %lu\n", DataLength);
724
725 if ((RequiredLength + DataLength + sizeof(LSAPR_ACCOUNT_INFORMATION)) > PreferedMaximumLength)
726 break;
727
728 RequiredLength += (DataLength + sizeof(LSAPR_ACCOUNT_INFORMATION));
729 EnumCount++;
730 }
731
732 LsapRegCloseKey(SidKeyHandle);
733 }
734
735 LsapRegCloseKey(AccountKeyHandle);
736 }
737
738 EnumIndex++;
739 }
740
741 TRACE("EnumCount: %lu\n", EnumCount);
742 TRACE("RequiredLength: %lu\n", RequiredLength);
743
744 EnumBuffer.EntriesRead = EnumCount;
745 EnumBuffer.Information = midl_user_allocate(EnumCount * sizeof(LSAPR_ACCOUNT_INFORMATION));
746 if (EnumBuffer.Information == NULL)
747 {
748 Status = STATUS_INSUFFICIENT_RESOURCES;
749 goto done;
750 }
751
752 EnumIndex = *EnumerationContext;
753 for (i = 0; i < EnumCount; i++, EnumIndex++)
754 {
755 Status = LsapRegEnumerateSubKey(AccountsKeyHandle,
756 EnumIndex,
757 64 * sizeof(WCHAR),
758 AccountKeyName);
759 if (!NT_SUCCESS(Status))
760 break;
761
762 TRACE("EnumIndex: %lu\n", EnumIndex);
763 TRACE("Account key name: %S\n", AccountKeyName);
764
765 Status = LsapRegOpenKey(AccountsKeyHandle,
766 AccountKeyName,
767 KEY_READ,
768 &AccountKeyHandle);
769 TRACE("LsapRegOpenKey returned %08lX\n", Status);
770 if (NT_SUCCESS(Status))
771 {
772 Status = LsapRegOpenKey(AccountKeyHandle,
773 L"Sid",
774 KEY_READ,
775 &SidKeyHandle);
776 TRACE("LsapRegOpenKey returned %08lX\n", Status);
777 if (NT_SUCCESS(Status))
778 {
779 DataLength = 0;
780 Status = LsapRegQueryValue(SidKeyHandle,
781 NULL,
782 NULL,
783 NULL,
784 &DataLength);
785 TRACE("LsapRegQueryValue returned %08lX\n", Status);
786 if (NT_SUCCESS(Status))
787 {
788 EnumBuffer.Information[i].Sid = midl_user_allocate(DataLength);
789 if (EnumBuffer.Information[i].Sid == NULL)
790 {
791 LsapRegCloseKey(AccountKeyHandle);
792 Status = STATUS_INSUFFICIENT_RESOURCES;
793 goto done;
794 }
795
796 Status = LsapRegQueryValue(SidKeyHandle,
797 NULL,
798 NULL,
799 EnumBuffer.Information[i].Sid,
800 &DataLength);
801 TRACE("SampRegQueryValue returned %08lX\n", Status);
802 }
803
804 LsapRegCloseKey(SidKeyHandle);
805 }
806
807 LsapRegCloseKey(AccountKeyHandle);
808
809 if (!NT_SUCCESS(Status))
810 goto done;
811 }
812 }
813
814 if (NT_SUCCESS(Status))
815 {
816 *EnumerationContext += EnumCount;
817 EnumerationBuffer->EntriesRead = EnumBuffer.EntriesRead;
818 EnumerationBuffer->Information = EnumBuffer.Information;
819 }
820
821 done:
822 if (!NT_SUCCESS(Status))
823 {
824 if (EnumBuffer.Information)
825 {
826 for (i = 0; i < EnumBuffer.EntriesRead; i++)
827 {
828 if (EnumBuffer.Information[i].Sid != NULL)
829 midl_user_free(EnumBuffer.Information[i].Sid);
830 }
831
832 midl_user_free(EnumBuffer.Information);
833 }
834 }
835
836 if (AccountsKeyHandle != NULL)
837 LsapRegCloseKey(AccountsKeyHandle);
838
839 return Status;
840 }
841
842
843 /* Function 12 */
844 NTSTATUS WINAPI LsarCreateTrustedDomain(
845 LSAPR_HANDLE PolicyHandle,
846 PLSAPR_TRUST_INFORMATION TrustedDomainInformation,
847 ACCESS_MASK DesiredAccess,
848 LSAPR_HANDLE *TrustedDomainHandle)
849 {
850 UNIMPLEMENTED;
851 return STATUS_NOT_IMPLEMENTED;
852 }
853
854
855 /* Function 13 */
856 NTSTATUS WINAPI LsarEnumerateTrustedDomains(
857 LSAPR_HANDLE PolicyHandle,
858 DWORD *EnumerationContext,
859 PLSAPR_TRUSTED_ENUM_BUFFER EnumerationBuffer,
860 DWORD PreferedMaximumLength)
861 {
862 UNIMPLEMENTED;
863 return STATUS_NOT_IMPLEMENTED;
864 }
865
866
867 /* Function 14 */
868 NTSTATUS WINAPI LsarLookupNames(
869 LSAPR_HANDLE PolicyHandle,
870 DWORD Count,
871 PRPC_UNICODE_STRING Names,
872 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
873 PLSAPR_TRANSLATED_SIDS TranslatedSids,
874 LSAP_LOOKUP_LEVEL LookupLevel,
875 DWORD *MappedCount)
876 {
877 LSAPR_TRANSLATED_SIDS_EX2 TranslatedSidsEx2;
878 ULONG i;
879 NTSTATUS Status;
880
881 TRACE("(%p %lu %p %p %p %d %p)\n",
882 PolicyHandle, Count, Names, ReferencedDomains, TranslatedSids,
883 LookupLevel, MappedCount);
884
885 TranslatedSids->Entries = 0;
886 TranslatedSids->Sids = NULL;
887 *ReferencedDomains = NULL;
888
889 if (Count == 0)
890 return STATUS_NONE_MAPPED;
891
892 TranslatedSidsEx2.Entries = 0;
893 TranslatedSidsEx2.Sids = NULL;
894
895 Status = LsapLookupNames(Count,
896 Names,
897 ReferencedDomains,
898 &TranslatedSidsEx2,
899 LookupLevel,
900 MappedCount,
901 0,
902 0);
903 if (!NT_SUCCESS(Status))
904 return Status;
905
906 TranslatedSids->Entries = TranslatedSidsEx2.Entries;
907 TranslatedSids->Sids = MIDL_user_allocate(TranslatedSids->Entries * sizeof(LSA_TRANSLATED_SID));
908 if (TranslatedSids->Sids == NULL)
909 {
910 MIDL_user_free(TranslatedSidsEx2.Sids);
911 MIDL_user_free(*ReferencedDomains);
912 *ReferencedDomains = NULL;
913 return STATUS_INSUFFICIENT_RESOURCES;
914 }
915
916 for (i = 0; i < TranslatedSidsEx2.Entries; i++)
917 {
918 TranslatedSids->Sids[i].Use = TranslatedSidsEx2.Sids[i].Use;
919 TranslatedSids->Sids[i].RelativeId = LsapGetRelativeIdFromSid(TranslatedSidsEx2.Sids[i].Sid);
920 TranslatedSids->Sids[i].DomainIndex = TranslatedSidsEx2.Sids[i].DomainIndex;
921 }
922
923 MIDL_user_free(TranslatedSidsEx2.Sids);
924
925 return STATUS_SUCCESS;
926 }
927
928
929 /* Function 15 */
930 NTSTATUS WINAPI LsarLookupSids(
931 LSAPR_HANDLE PolicyHandle,
932 PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
933 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
934 PLSAPR_TRANSLATED_NAMES TranslatedNames,
935 LSAP_LOOKUP_LEVEL LookupLevel,
936 DWORD *MappedCount)
937 {
938 LSAPR_TRANSLATED_NAMES_EX TranslatedNamesEx;
939 ULONG i;
940 NTSTATUS Status;
941
942 TRACE("(%p %p %p %p %d %p)\n",
943 PolicyHandle, SidEnumBuffer, ReferencedDomains, TranslatedNames,
944 LookupLevel, MappedCount);
945
946 /* FIXME: Fail, if there is an invalid SID in the SidEnumBuffer */
947
948 TranslatedNames->Entries = SidEnumBuffer->Entries;
949 TranslatedNames->Names = NULL;
950 *ReferencedDomains = NULL;
951
952 TranslatedNamesEx.Entries = SidEnumBuffer->Entries;
953 TranslatedNamesEx.Names = NULL;
954
955 Status = LsapLookupSids(SidEnumBuffer,
956 ReferencedDomains,
957 &TranslatedNamesEx,
958 LookupLevel,
959 MappedCount,
960 0,
961 0);
962 if (!NT_SUCCESS(Status))
963 return Status;
964
965 TranslatedNames->Entries = SidEnumBuffer->Entries;
966 TranslatedNames->Names = MIDL_user_allocate(SidEnumBuffer->Entries * sizeof(LSAPR_TRANSLATED_NAME));
967 if (TranslatedNames->Names == NULL)
968 {
969 MIDL_user_free(TranslatedNamesEx.Names);
970 MIDL_user_free(*ReferencedDomains);
971 *ReferencedDomains = NULL;
972 return STATUS_INSUFFICIENT_RESOURCES;
973 }
974
975 for (i = 0; i < TranslatedNamesEx.Entries; i++)
976 {
977 TranslatedNames->Names[i].Use = TranslatedNamesEx.Names[i].Use;
978 TranslatedNames->Names[i].Name.Length = TranslatedNamesEx.Names[i].Name.Length;
979 TranslatedNames->Names[i].Name.MaximumLength = TranslatedNamesEx.Names[i].Name.MaximumLength;
980 TranslatedNames->Names[i].Name.Buffer = TranslatedNamesEx.Names[i].Name.Buffer;
981 TranslatedNames->Names[i].DomainIndex = TranslatedNamesEx.Names[i].DomainIndex;
982 }
983
984 MIDL_user_free(TranslatedNamesEx.Names);
985
986 return Status;
987 }
988
989
990 /* Function 16 */
991 NTSTATUS WINAPI LsarCreateSecret(
992 LSAPR_HANDLE PolicyHandle,
993 PRPC_UNICODE_STRING SecretName,
994 ACCESS_MASK DesiredAccess,
995 LSAPR_HANDLE *SecretHandle)
996 {
997 PLSA_DB_OBJECT PolicyObject;
998 PLSA_DB_OBJECT SecretObject = NULL;
999 LARGE_INTEGER Time;
1000 PSECURITY_DESCRIPTOR SecretSd = NULL;
1001 ULONG SecretSdSize;
1002 NTSTATUS Status = STATUS_SUCCESS;
1003
1004 /* Validate the PolicyHandle */
1005 Status = LsapValidateDbObject(PolicyHandle,
1006 LsaDbPolicyObject,
1007 POLICY_CREATE_SECRET,
1008 &PolicyObject);
1009 if (!NT_SUCCESS(Status))
1010 {
1011 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1012 return Status;
1013 }
1014
1015 /* Get the current time */
1016 Status = NtQuerySystemTime(&Time);
1017 if (!NT_SUCCESS(Status))
1018 {
1019 ERR("NtQuerySystemTime failed (Status 0x%08lx)\n", Status);
1020 goto done;
1021 }
1022
1023 /* Create a security descriptor for the secret */
1024 Status = LsapCreateSecretSd(&SecretSd,
1025 &SecretSdSize);
1026 if (!NT_SUCCESS(Status))
1027 {
1028 ERR("LsapCreateAccountSd returned 0x%08lx\n", Status);
1029 return Status;
1030 }
1031
1032 /* Create the Secret object */
1033 Status = LsapCreateDbObject(PolicyObject,
1034 L"Secrets",
1035 SecretName->Buffer,
1036 LsaDbSecretObject,
1037 DesiredAccess,
1038 PolicyObject->Trusted,
1039 &SecretObject);
1040 if (!NT_SUCCESS(Status))
1041 {
1042 ERR("LsapCreateDbObject failed (Status 0x%08lx)\n", Status);
1043 goto done;
1044 }
1045
1046 /* Set the CurrentTime attribute */
1047 Status = LsapSetObjectAttribute(SecretObject,
1048 L"CurrentTime",
1049 (PVOID)&Time,
1050 sizeof(LARGE_INTEGER));
1051 if (!NT_SUCCESS(Status))
1052 {
1053 ERR("LsapSetObjectAttribute (CurrentTime) failed (Status 0x%08lx)\n", Status);
1054 goto done;
1055 }
1056
1057 /* Set the OldTime attribute */
1058 Status = LsapSetObjectAttribute(SecretObject,
1059 L"OldTime",
1060 (PVOID)&Time,
1061 sizeof(LARGE_INTEGER));
1062 if (!NT_SUCCESS(Status))
1063 {
1064 ERR("LsapSetObjectAttribute (OldTime) failed (Status 0x%08lx)\n", Status);
1065 goto done;
1066 }
1067
1068 /* Set the SecDesc attribute */
1069 Status = LsapSetObjectAttribute(SecretObject,
1070 L"SecDesc",
1071 SecretSd,
1072 SecretSdSize);
1073
1074 done:
1075 if (SecretSd != NULL)
1076 RtlFreeHeap(RtlGetProcessHeap(), 0, SecretSd);
1077
1078 if (!NT_SUCCESS(Status))
1079 {
1080 if (SecretObject != NULL)
1081 LsapCloseDbObject(SecretObject);
1082 }
1083 else
1084 {
1085 *SecretHandle = (LSAPR_HANDLE)SecretObject;
1086 }
1087
1088 return STATUS_SUCCESS;
1089 }
1090
1091
1092 /* Function 17 */
1093 NTSTATUS WINAPI LsarOpenAccount(
1094 LSAPR_HANDLE PolicyHandle,
1095 PRPC_SID AccountSid,
1096 ACCESS_MASK DesiredAccess,
1097 LSAPR_HANDLE *AccountHandle)
1098 {
1099 PLSA_DB_OBJECT PolicyObject;
1100 PLSA_DB_OBJECT AccountObject = NULL;
1101 LPWSTR SidString = NULL;
1102 NTSTATUS Status = STATUS_SUCCESS;
1103
1104 /* Validate the AccountSid */
1105 if (!RtlValidSid(AccountSid))
1106 return STATUS_INVALID_PARAMETER;
1107
1108 /* Validate the PolicyHandle */
1109 Status = LsapValidateDbObject(PolicyHandle,
1110 LsaDbPolicyObject,
1111 0,
1112 &PolicyObject);
1113 if (!NT_SUCCESS(Status))
1114 {
1115 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1116 return Status;
1117 }
1118
1119 /* Create SID string */
1120 if (!ConvertSidToStringSid((PSID)AccountSid,
1121 &SidString))
1122 {
1123 ERR("ConvertSidToStringSid failed\n");
1124 Status = STATUS_INVALID_PARAMETER;
1125 goto done;
1126 }
1127
1128 /* Create the Account object */
1129 Status = LsapOpenDbObject(PolicyObject,
1130 L"Accounts",
1131 SidString,
1132 LsaDbAccountObject,
1133 DesiredAccess,
1134 PolicyObject->Trusted,
1135 &AccountObject);
1136 if (!NT_SUCCESS(Status))
1137 {
1138 ERR("LsapOpenDbObject failed (Status 0x%08lx)\n", Status);
1139 goto done;
1140 }
1141
1142 /* Set the Sid attribute */
1143 Status = LsapSetObjectAttribute(AccountObject,
1144 L"Sid",
1145 (PVOID)AccountSid,
1146 GetLengthSid(AccountSid));
1147
1148 done:
1149 if (SidString != NULL)
1150 LocalFree(SidString);
1151
1152 if (!NT_SUCCESS(Status))
1153 {
1154 if (AccountObject != NULL)
1155 LsapCloseDbObject(AccountObject);
1156 }
1157 else
1158 {
1159 *AccountHandle = (LSAPR_HANDLE)AccountObject;
1160 }
1161
1162 return Status;
1163 }
1164
1165
1166 /* Function 18 */
1167 NTSTATUS WINAPI LsarEnumeratePrivilegesAccount(
1168 LSAPR_HANDLE AccountHandle,
1169 PLSAPR_PRIVILEGE_SET *Privileges)
1170 {
1171 PLSA_DB_OBJECT AccountObject;
1172 ULONG PrivilegeSetSize = 0;
1173 PLSAPR_PRIVILEGE_SET PrivilegeSet = NULL;
1174 NTSTATUS Status;
1175
1176 *Privileges = NULL;
1177
1178 /* Validate the AccountHandle */
1179 Status = LsapValidateDbObject(AccountHandle,
1180 LsaDbAccountObject,
1181 ACCOUNT_VIEW,
1182 &AccountObject);
1183 if (!NT_SUCCESS(Status))
1184 {
1185 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1186 return Status;
1187 }
1188
1189 /* Get the size of the privilege set */
1190 Status = LsapGetObjectAttribute(AccountObject,
1191 L"Privilgs",
1192 NULL,
1193 &PrivilegeSetSize);
1194 if (!NT_SUCCESS(Status))
1195 return Status;
1196
1197 /* Allocate a buffer for the privilege set */
1198 PrivilegeSet = MIDL_user_allocate(PrivilegeSetSize);
1199 if (PrivilegeSet == NULL)
1200 return STATUS_NO_MEMORY;
1201
1202 /* Get the privilege set */
1203 Status = LsapGetObjectAttribute(AccountObject,
1204 L"Privilgs",
1205 PrivilegeSet,
1206 &PrivilegeSetSize);
1207 if (!NT_SUCCESS(Status))
1208 {
1209 MIDL_user_free(PrivilegeSet);
1210 return Status;
1211 }
1212
1213 /* Return a pointer to the privilege set */
1214 *Privileges = PrivilegeSet;
1215
1216 return STATUS_SUCCESS;
1217 }
1218
1219
1220 /* Function 19 */
1221 NTSTATUS WINAPI LsarAddPrivilegesToAccount(
1222 LSAPR_HANDLE AccountHandle,
1223 PLSAPR_PRIVILEGE_SET Privileges)
1224 {
1225 PLSA_DB_OBJECT AccountObject;
1226 PPRIVILEGE_SET CurrentPrivileges = NULL;
1227 PPRIVILEGE_SET NewPrivileges = NULL;
1228 ULONG PrivilegeSetSize = 0;
1229 ULONG PrivilegeCount;
1230 ULONG i, j;
1231 BOOL bFound;
1232 NTSTATUS Status;
1233
1234 /* Validate the AccountHandle */
1235 Status = LsapValidateDbObject(AccountHandle,
1236 LsaDbAccountObject,
1237 ACCOUNT_ADJUST_PRIVILEGES,
1238 &AccountObject);
1239 if (!NT_SUCCESS(Status))
1240 {
1241 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1242 return Status;
1243 }
1244
1245 /* Get the size of the Privilgs attribute */
1246 Status = LsapGetObjectAttribute(AccountObject,
1247 L"Privilgs",
1248 NULL,
1249 &PrivilegeSetSize);
1250 if (!NT_SUCCESS(Status) || PrivilegeSetSize == 0)
1251 {
1252 /* The Privilgs attribute does not exist */
1253
1254 PrivilegeSetSize = sizeof(PRIVILEGE_SET) +
1255 (Privileges->PrivilegeCount - 1) * sizeof(LUID_AND_ATTRIBUTES);
1256 Status = LsapSetObjectAttribute(AccountObject,
1257 L"Privilgs",
1258 Privileges,
1259 PrivilegeSetSize);
1260 }
1261 else
1262 {
1263 /* The Privilgs attribute exists */
1264
1265 /* Allocate memory for the stored privilege set */
1266 CurrentPrivileges = MIDL_user_allocate(PrivilegeSetSize);
1267 if (CurrentPrivileges == NULL)
1268 return STATUS_NO_MEMORY;
1269
1270 /* Get the current privilege set */
1271 Status = LsapGetObjectAttribute(AccountObject,
1272 L"Privilgs",
1273 CurrentPrivileges,
1274 &PrivilegeSetSize);
1275 if (!NT_SUCCESS(Status))
1276 {
1277 TRACE("LsapGetObjectAttribute() failed (Status 0x%08lx)\n", Status);
1278 goto done;
1279 }
1280
1281 PrivilegeCount = CurrentPrivileges->PrivilegeCount;
1282 TRACE("Current privilege count: %lu\n", PrivilegeCount);
1283
1284 /* Calculate the number privileges in the combined privilege set */
1285 for (i = 0; i < Privileges->PrivilegeCount; i++)
1286 {
1287 bFound = FALSE;
1288 for (j = 0; j < CurrentPrivileges->PrivilegeCount; j++)
1289 {
1290 if (RtlEqualLuid(&(Privileges->Privilege[i].Luid),
1291 &(CurrentPrivileges->Privilege[i].Luid)))
1292 {
1293 bFound = TRUE;
1294 break;
1295 }
1296 }
1297
1298 if (bFound == FALSE)
1299 {
1300 TRACE("Found new privilege\n");
1301 PrivilegeCount++;
1302 }
1303 }
1304 TRACE("New privilege count: %lu\n", PrivilegeCount);
1305
1306 /* Calculate the size of the new privilege set and allocate it */
1307 PrivilegeSetSize = sizeof(PRIVILEGE_SET) +
1308 (PrivilegeCount - 1) * sizeof(LUID_AND_ATTRIBUTES);
1309 NewPrivileges = MIDL_user_allocate(PrivilegeSetSize);
1310 if (NewPrivileges == NULL)
1311 {
1312 Status = STATUS_NO_MEMORY;
1313 goto done;
1314 }
1315
1316 /* Initialize the new privilege set */
1317 NewPrivileges->PrivilegeCount = PrivilegeCount;
1318 NewPrivileges->Control = 0;
1319
1320 /* Copy all privileges from the current privilege set */
1321 RtlCopyLuidAndAttributesArray(CurrentPrivileges->PrivilegeCount,
1322 &(CurrentPrivileges->Privilege[0]),
1323 &(NewPrivileges->Privilege[0]));
1324
1325 /* Add new privileges to the new privilege set */
1326 PrivilegeCount = CurrentPrivileges->PrivilegeCount;
1327 for (i = 0; i < Privileges->PrivilegeCount; i++)
1328 {
1329 bFound = FALSE;
1330 for (j = 0; j < CurrentPrivileges->PrivilegeCount; j++)
1331 {
1332 if (RtlEqualLuid(&(Privileges->Privilege[i].Luid),
1333 &(CurrentPrivileges->Privilege[i].Luid)))
1334 {
1335 /* Overwrite attributes if a matching privilege was found */
1336 NewPrivileges->Privilege[j].Attributes = Privileges->Privilege[i].Attributes;
1337
1338 bFound = TRUE;
1339 break;
1340 }
1341 }
1342
1343 if (bFound == FALSE)
1344 {
1345 /* Copy the new privilege */
1346 RtlCopyLuidAndAttributesArray(1,
1347 (PLUID_AND_ATTRIBUTES)&(Privileges->Privilege[i]),
1348 &(NewPrivileges->Privilege[PrivilegeCount]));
1349 PrivilegeCount++;
1350 }
1351 }
1352
1353 /* Set the new privilege set */
1354 Status = LsapSetObjectAttribute(AccountObject,
1355 L"Privilgs",
1356 NewPrivileges,
1357 PrivilegeSetSize);
1358 }
1359
1360 done:
1361 if (CurrentPrivileges != NULL)
1362 MIDL_user_free(CurrentPrivileges);
1363
1364 if (NewPrivileges != NULL)
1365 MIDL_user_free(NewPrivileges);
1366
1367 return Status;
1368 }
1369
1370
1371 /* Function 20 */
1372 NTSTATUS WINAPI LsarRemovePrivilegesFromAccount(
1373 LSAPR_HANDLE AccountHandle,
1374 BOOL AllPrivileges,
1375 PLSAPR_PRIVILEGE_SET Privileges)
1376 {
1377 PLSA_DB_OBJECT AccountObject;
1378 PPRIVILEGE_SET CurrentPrivileges = NULL;
1379 PPRIVILEGE_SET NewPrivileges = NULL;
1380 ULONG PrivilegeSetSize = 0;
1381 ULONG PrivilegeCount;
1382 ULONG i, j, k;
1383 BOOL bFound;
1384 NTSTATUS Status;
1385
1386 TRACE("(%p %u %p)\n", AccountHandle, AllPrivileges, Privileges);
1387
1388 /* */
1389 if ((AllPrivileges == FALSE && Privileges == NULL) ||
1390 (AllPrivileges == TRUE && Privileges != NULL))
1391 return STATUS_INVALID_PARAMETER;
1392
1393 /* Validate the AccountHandle */
1394 Status = LsapValidateDbObject(AccountHandle,
1395 LsaDbAccountObject,
1396 ACCOUNT_ADJUST_PRIVILEGES,
1397 &AccountObject);
1398 if (!NT_SUCCESS(Status))
1399 {
1400 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1401 return Status;
1402 }
1403
1404 if (AllPrivileges == TRUE)
1405 {
1406 /* Delete the Privilgs attribute */
1407 Status = LsapDeleteObjectAttribute(AccountObject,
1408 L"Privilgs");
1409 if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
1410 Status = STATUS_SUCCESS;
1411 }
1412 else
1413 {
1414 /* Get the size of the Privilgs attribute */
1415 Status = LsapGetObjectAttribute(AccountObject,
1416 L"Privilgs",
1417 NULL,
1418 &PrivilegeSetSize);
1419 if (!NT_SUCCESS(Status))
1420 goto done;
1421
1422 /* Succeed, if there is no privilege set to remove privileges from */
1423 if (PrivilegeSetSize == 0)
1424 {
1425 Status = STATUS_SUCCESS;
1426 goto done;
1427 }
1428
1429 /* Allocate memory for the stored privilege set */
1430 CurrentPrivileges = MIDL_user_allocate(PrivilegeSetSize);
1431 if (CurrentPrivileges == NULL)
1432 return STATUS_NO_MEMORY;
1433
1434 /* Get the current privilege set */
1435 Status = LsapGetObjectAttribute(AccountObject,
1436 L"Privilgs",
1437 CurrentPrivileges,
1438 &PrivilegeSetSize);
1439 if (!NT_SUCCESS(Status))
1440 {
1441 TRACE("LsapGetObjectAttribute() failed (Status 0x%08lx)\n", Status);
1442 goto done;
1443 }
1444
1445 PrivilegeCount = CurrentPrivileges->PrivilegeCount;
1446 TRACE("Current privilege count: %lu\n", PrivilegeCount);
1447
1448 /* Calculate the number of privileges in the new privilege set */
1449 for (i = 0; i < CurrentPrivileges->PrivilegeCount; i++)
1450 {
1451 for (j = 0; j < Privileges->PrivilegeCount; j++)
1452 {
1453 if (RtlEqualLuid(&(CurrentPrivileges->Privilege[i].Luid),
1454 &(Privileges->Privilege[j].Luid)))
1455 {
1456 if (PrivilegeCount > 0)
1457 PrivilegeCount--;
1458 }
1459 }
1460 }
1461 TRACE("New privilege count: %lu\n", PrivilegeCount);
1462
1463 if (PrivilegeCount == 0)
1464 {
1465 /* Delete the Privilgs attribute */
1466 Status = LsapDeleteObjectAttribute(AccountObject,
1467 L"Privilgs");
1468 if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
1469 Status = STATUS_SUCCESS;
1470 }
1471 else
1472 {
1473 /* Calculate the size of the new privilege set and allocate it */
1474 PrivilegeSetSize = sizeof(PRIVILEGE_SET) +
1475 (PrivilegeCount - 1) * sizeof(LUID_AND_ATTRIBUTES);
1476 NewPrivileges = MIDL_user_allocate(PrivilegeSetSize);
1477 if (NewPrivileges == NULL)
1478 {
1479 Status = STATUS_NO_MEMORY;
1480 goto done;
1481 }
1482
1483 /* Initialize the new privilege set */
1484 NewPrivileges->PrivilegeCount = PrivilegeCount;
1485 NewPrivileges->Control = 0;
1486
1487 /* Copy the privileges which are not to be removed */
1488 for (i = 0, k = 0; i < CurrentPrivileges->PrivilegeCount; i++)
1489 {
1490 bFound = FALSE;
1491 for (j = 0; j < Privileges->PrivilegeCount; j++)
1492 {
1493 if (RtlEqualLuid(&(CurrentPrivileges->Privilege[i].Luid),
1494 &(Privileges->Privilege[j].Luid)))
1495 bFound = TRUE;
1496 }
1497
1498 if (bFound == FALSE)
1499 {
1500 /* Copy the privilege */
1501 RtlCopyLuidAndAttributesArray(1,
1502 &(CurrentPrivileges->Privilege[i]),
1503 &(NewPrivileges->Privilege[k]));
1504 k++;
1505 }
1506 }
1507
1508 /* Set the new privilege set */
1509 Status = LsapSetObjectAttribute(AccountObject,
1510 L"Privilgs",
1511 NewPrivileges,
1512 PrivilegeSetSize);
1513 }
1514 }
1515
1516 done:
1517 if (CurrentPrivileges != NULL)
1518 MIDL_user_free(CurrentPrivileges);
1519
1520 if (NewPrivileges != NULL)
1521 MIDL_user_free(NewPrivileges);
1522
1523 return Status;
1524 }
1525
1526
1527 /* Function 21 */
1528 NTSTATUS WINAPI LsarGetQuotasForAccount(
1529 LSAPR_HANDLE AccountHandle,
1530 PQUOTA_LIMITS QuotaLimits)
1531 {
1532 PLSA_DB_OBJECT AccountObject;
1533 ULONG Size;
1534 NTSTATUS Status;
1535
1536 TRACE("(%p %p)\n", AccountHandle, QuotaLimits);
1537
1538 /* Validate the account handle */
1539 Status = LsapValidateDbObject(AccountHandle,
1540 LsaDbAccountObject,
1541 ACCOUNT_VIEW,
1542 &AccountObject);
1543 if (!NT_SUCCESS(Status))
1544 {
1545 ERR("Invalid handle (Status %lx)\n", Status);
1546 return Status;
1547 }
1548
1549 /* Get the quota attribute */
1550 Status = LsapGetObjectAttribute(AccountObject,
1551 L"DefQuota",
1552 QuotaLimits,
1553 &Size);
1554
1555 return Status;
1556 }
1557
1558
1559 /* Function 22 */
1560 NTSTATUS WINAPI LsarSetQuotasForAccount(
1561 LSAPR_HANDLE AccountHandle,
1562 PQUOTA_LIMITS QuotaLimits)
1563 {
1564 PLSA_DB_OBJECT AccountObject;
1565 QUOTA_LIMITS InternalQuotaLimits;
1566 ULONG Size;
1567 NTSTATUS Status;
1568
1569 TRACE("(%p %p)\n", AccountHandle, QuotaLimits);
1570
1571 /* Validate the account handle */
1572 Status = LsapValidateDbObject(AccountHandle,
1573 LsaDbAccountObject,
1574 ACCOUNT_ADJUST_QUOTAS,
1575 &AccountObject);
1576 if (!NT_SUCCESS(Status))
1577 {
1578 ERR("Invalid handle (Status %lx)\n", Status);
1579 return Status;
1580 }
1581
1582 /* Get the quota limits attribute */
1583 Size = sizeof(QUOTA_LIMITS);
1584 Status = LsapGetObjectAttribute(AccountObject,
1585 L"DefQuota",
1586 &InternalQuotaLimits,
1587 &Size);
1588 if (!NT_SUCCESS(Status))
1589 {
1590 TRACE("LsapGetObjectAttribute() failed (Status 0x%08lx)\n", Status);
1591 return Status;
1592 }
1593
1594 /* Update the quota limits */
1595 if (QuotaLimits->PagedPoolLimit != 0)
1596 InternalQuotaLimits.PagedPoolLimit = QuotaLimits->PagedPoolLimit;
1597
1598 if (QuotaLimits->NonPagedPoolLimit != 0)
1599 InternalQuotaLimits.NonPagedPoolLimit = QuotaLimits->NonPagedPoolLimit;
1600
1601 if (QuotaLimits->MinimumWorkingSetSize != 0)
1602 InternalQuotaLimits.MinimumWorkingSetSize = QuotaLimits->MinimumWorkingSetSize;
1603
1604 if (QuotaLimits->MaximumWorkingSetSize != 0)
1605 InternalQuotaLimits.MaximumWorkingSetSize = QuotaLimits->MaximumWorkingSetSize;
1606
1607 if (QuotaLimits->PagefileLimit != 0)
1608 InternalQuotaLimits.PagefileLimit = QuotaLimits->PagefileLimit;
1609
1610 /* Set the quota limits attribute */
1611 Status = LsapSetObjectAttribute(AccountObject,
1612 L"DefQuota",
1613 &InternalQuotaLimits,
1614 sizeof(QUOTA_LIMITS));
1615
1616 return Status;
1617 }
1618
1619
1620 /* Function 23 */
1621 NTSTATUS WINAPI LsarGetSystemAccessAccount(
1622 LSAPR_HANDLE AccountHandle,
1623 ACCESS_MASK *SystemAccess)
1624 {
1625 PLSA_DB_OBJECT AccountObject;
1626 ULONG Size;
1627 NTSTATUS Status;
1628
1629 /* Validate the account handle */
1630 Status = LsapValidateDbObject(AccountHandle,
1631 LsaDbAccountObject,
1632 ACCOUNT_VIEW,
1633 &AccountObject);
1634 if (!NT_SUCCESS(Status))
1635 {
1636 ERR("Invalid handle (Status %lx)\n", Status);
1637 return Status;
1638 }
1639
1640 /* Get the system access flags */
1641 Status = LsapGetObjectAttribute(AccountObject,
1642 L"ActSysAc",
1643 SystemAccess,
1644 &Size);
1645
1646 return Status;
1647 }
1648
1649
1650 /* Function 24 */
1651 NTSTATUS WINAPI LsarSetSystemAccessAccount(
1652 LSAPR_HANDLE AccountHandle,
1653 ACCESS_MASK SystemAccess)
1654 {
1655 PLSA_DB_OBJECT AccountObject;
1656 NTSTATUS Status;
1657
1658 /* Validate the account handle */
1659 Status = LsapValidateDbObject(AccountHandle,
1660 LsaDbAccountObject,
1661 ACCOUNT_ADJUST_SYSTEM_ACCESS,
1662 &AccountObject);
1663 if (!NT_SUCCESS(Status))
1664 {
1665 ERR("Invalid handle (Status %lx)\n", Status);
1666 return Status;
1667 }
1668
1669 /* Set the system access flags */
1670 Status = LsapSetObjectAttribute(AccountObject,
1671 L"ActSysAc",
1672 &SystemAccess,
1673 sizeof(ACCESS_MASK));
1674
1675 return Status;
1676 }
1677
1678
1679 /* Function 25 */
1680 NTSTATUS WINAPI LsarOpenTrustedDomain(
1681 LSAPR_HANDLE PolicyHandle,
1682 PRPC_SID TrustedDomainSid,
1683 ACCESS_MASK DesiredAccess,
1684 LSAPR_HANDLE *TrustedDomainHandle)
1685 {
1686 UNIMPLEMENTED;
1687 return STATUS_NOT_IMPLEMENTED;
1688 }
1689
1690
1691 /* Function 26 */
1692 NTSTATUS WINAPI LsarQueryInfoTrustedDomain(
1693 LSAPR_HANDLE TrustedDomainHandle,
1694 TRUSTED_INFORMATION_CLASS InformationClass,
1695 PLSAPR_TRUSTED_DOMAIN_INFO *TrustedDomainInformation)
1696 {
1697 UNIMPLEMENTED;
1698 return STATUS_NOT_IMPLEMENTED;
1699 }
1700
1701
1702 /* Function 27 */
1703 NTSTATUS WINAPI LsarSetInformationTrustedDomain(
1704 LSAPR_HANDLE TrustedDomainHandle,
1705 TRUSTED_INFORMATION_CLASS InformationClass,
1706 PLSAPR_TRUSTED_DOMAIN_INFO TrustedDomainInformation)
1707 {
1708 UNIMPLEMENTED;
1709 return STATUS_NOT_IMPLEMENTED;
1710 }
1711
1712
1713 /* Function 28 */
1714 NTSTATUS WINAPI LsarOpenSecret(
1715 LSAPR_HANDLE PolicyHandle,
1716 PRPC_UNICODE_STRING SecretName,
1717 ACCESS_MASK DesiredAccess,
1718 LSAPR_HANDLE *SecretHandle)
1719 {
1720 PLSA_DB_OBJECT PolicyObject;
1721 PLSA_DB_OBJECT SecretObject = NULL;
1722 NTSTATUS Status = STATUS_SUCCESS;
1723
1724 /* Validate the PolicyHandle */
1725 Status = LsapValidateDbObject(PolicyHandle,
1726 LsaDbPolicyObject,
1727 0,
1728 &PolicyObject);
1729 if (!NT_SUCCESS(Status))
1730 {
1731 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1732 return Status;
1733 }
1734
1735 /* Create the secret object */
1736 Status = LsapOpenDbObject(PolicyObject,
1737 L"Secrets",
1738 SecretName->Buffer,
1739 LsaDbSecretObject,
1740 DesiredAccess,
1741 PolicyObject->Trusted,
1742 &SecretObject);
1743 if (!NT_SUCCESS(Status))
1744 {
1745 ERR("LsapOpenDbObject failed (Status 0x%08lx)\n", Status);
1746 goto done;
1747 }
1748
1749 done:
1750 if (!NT_SUCCESS(Status))
1751 {
1752 if (SecretObject != NULL)
1753 LsapCloseDbObject(SecretObject);
1754 }
1755 else
1756 {
1757 *SecretHandle = (LSAPR_HANDLE)SecretObject;
1758 }
1759
1760 return Status;
1761 }
1762
1763
1764 /* Function 29 */
1765 NTSTATUS WINAPI LsarSetSecret(
1766 LSAPR_HANDLE SecretHandle,
1767 PLSAPR_CR_CIPHER_VALUE EncryptedCurrentValue,
1768 PLSAPR_CR_CIPHER_VALUE EncryptedOldValue)
1769 {
1770 PLSA_DB_OBJECT SecretObject;
1771 PBYTE CurrentValue = NULL;
1772 PBYTE OldValue = NULL;
1773 ULONG CurrentValueLength = 0;
1774 ULONG OldValueLength = 0;
1775 LARGE_INTEGER Time;
1776 NTSTATUS Status;
1777
1778 TRACE("LsarSetSecret(%p %p %p)\n", SecretHandle,
1779 EncryptedCurrentValue, EncryptedOldValue);
1780
1781 /* Validate the SecretHandle */
1782 Status = LsapValidateDbObject(SecretHandle,
1783 LsaDbSecretObject,
1784 SECRET_SET_VALUE,
1785 &SecretObject);
1786 if (!NT_SUCCESS(Status))
1787 {
1788 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1789 return Status;
1790 }
1791
1792 if (EncryptedCurrentValue != NULL)
1793 {
1794 /* FIXME: Decrypt the current value */
1795 CurrentValue = EncryptedCurrentValue->Buffer;
1796 CurrentValueLength = EncryptedCurrentValue->MaximumLength;
1797 }
1798
1799 /* Set the current value */
1800 Status = LsapSetObjectAttribute(SecretObject,
1801 L"CurrentValue",
1802 CurrentValue,
1803 CurrentValueLength);
1804 if (!NT_SUCCESS(Status))
1805 {
1806 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
1807 goto done;
1808 }
1809
1810 /* Get the current time */
1811 Status = NtQuerySystemTime(&Time);
1812 if (!NT_SUCCESS(Status))
1813 {
1814 ERR("NtQuerySystemTime failed (Status 0x%08lx)\n", Status);
1815 goto done;
1816 }
1817
1818 /* Set the current time */
1819 Status = LsapSetObjectAttribute(SecretObject,
1820 L"CurrentTime",
1821 &Time,
1822 sizeof(LARGE_INTEGER));
1823 if (!NT_SUCCESS(Status))
1824 {
1825 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
1826 goto done;
1827 }
1828
1829 if (EncryptedOldValue != NULL)
1830 {
1831 /* FIXME: Decrypt the old value */
1832 OldValue = EncryptedOldValue->Buffer;
1833 OldValueLength = EncryptedOldValue->MaximumLength;
1834 }
1835
1836 /* Set the old value */
1837 Status = LsapSetObjectAttribute(SecretObject,
1838 L"OldValue",
1839 OldValue,
1840 OldValueLength);
1841 if (!NT_SUCCESS(Status))
1842 {
1843 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
1844 goto done;
1845 }
1846
1847 /* Set the old time */
1848 Status = LsapSetObjectAttribute(SecretObject,
1849 L"OldTime",
1850 &Time,
1851 sizeof(LARGE_INTEGER));
1852 if (!NT_SUCCESS(Status))
1853 {
1854 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
1855 }
1856
1857 done:
1858 return Status;
1859 }
1860
1861
1862 /* Function 30 */
1863 NTSTATUS WINAPI LsarQuerySecret(
1864 LSAPR_HANDLE SecretHandle,
1865 PLSAPR_CR_CIPHER_VALUE *EncryptedCurrentValue,
1866 PLARGE_INTEGER CurrentValueSetTime,
1867 PLSAPR_CR_CIPHER_VALUE *EncryptedOldValue,
1868 PLARGE_INTEGER OldValueSetTime)
1869 {
1870 PLSA_DB_OBJECT SecretObject;
1871 PLSAPR_CR_CIPHER_VALUE EncCurrentValue = NULL;
1872 PLSAPR_CR_CIPHER_VALUE EncOldValue = NULL;
1873 PBYTE CurrentValue = NULL;
1874 PBYTE OldValue = NULL;
1875 ULONG CurrentValueLength = 0;
1876 ULONG OldValueLength = 0;
1877 ULONG BufferSize;
1878 NTSTATUS Status;
1879
1880 TRACE("LsarQuerySecret(%p %p %p %p %p)\n", SecretHandle,
1881 EncryptedCurrentValue, CurrentValueSetTime,
1882 EncryptedOldValue, OldValueSetTime);
1883
1884 /* Validate the SecretHandle */
1885 Status = LsapValidateDbObject(SecretHandle,
1886 LsaDbSecretObject,
1887 SECRET_QUERY_VALUE,
1888 &SecretObject);
1889 if (!NT_SUCCESS(Status))
1890 {
1891 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
1892 return Status;
1893 }
1894
1895 if (EncryptedCurrentValue != NULL)
1896 {
1897 CurrentValueLength = 0;
1898
1899 /* Get the size of the current value */
1900 Status = LsapGetObjectAttribute(SecretObject,
1901 L"CurrentValue",
1902 NULL,
1903 &CurrentValueLength);
1904 if (!NT_SUCCESS(Status))
1905 goto done;
1906
1907 /* Allocate a buffer for the current value */
1908 CurrentValue = midl_user_allocate(CurrentValueLength);
1909 if (CurrentValue == NULL)
1910 {
1911 Status = STATUS_INSUFFICIENT_RESOURCES;
1912 goto done;
1913 }
1914
1915 /* Get the current value */
1916 Status = LsapGetObjectAttribute(SecretObject,
1917 L"CurrentValue",
1918 CurrentValue,
1919 &CurrentValueLength);
1920 if (!NT_SUCCESS(Status))
1921 goto done;
1922
1923 /* Allocate a buffer for the encrypted current value */
1924 EncCurrentValue = midl_user_allocate(sizeof(LSAPR_CR_CIPHER_VALUE));
1925 if (EncCurrentValue == NULL)
1926 {
1927 Status = STATUS_INSUFFICIENT_RESOURCES;
1928 goto done;
1929 }
1930
1931 /* FIXME: Encrypt the current value */
1932 EncCurrentValue->Length = (USHORT)(CurrentValueLength - sizeof(WCHAR));
1933 EncCurrentValue->MaximumLength = (USHORT)CurrentValueLength;
1934 EncCurrentValue->Buffer = (PBYTE)CurrentValue;
1935 }
1936
1937 if (CurrentValueSetTime != NULL)
1938 {
1939 BufferSize = sizeof(LARGE_INTEGER);
1940
1941 /* Get the current value time */
1942 Status = LsapGetObjectAttribute(SecretObject,
1943 L"CurrentTime",
1944 (PBYTE)CurrentValueSetTime,
1945 &BufferSize);
1946 if (!NT_SUCCESS(Status))
1947 goto done;
1948 }
1949
1950 if (EncryptedOldValue != NULL)
1951 {
1952 OldValueLength = 0;
1953
1954 /* Get the size of the old value */
1955 Status = LsapGetObjectAttribute(SecretObject,
1956 L"OldValue",
1957 NULL,
1958 &OldValueLength);
1959 if (!NT_SUCCESS(Status))
1960 goto done;
1961
1962 /* Allocate a buffer for the old value */
1963 OldValue = midl_user_allocate(OldValueLength);
1964 if (OldValue == NULL)
1965 {
1966 Status = STATUS_INSUFFICIENT_RESOURCES;
1967 goto done;
1968 }
1969
1970 /* Get the old value */
1971 Status = LsapGetObjectAttribute(SecretObject,
1972 L"OldValue",
1973 OldValue,
1974 &OldValueLength);
1975 if (!NT_SUCCESS(Status))
1976 goto done;
1977
1978 /* Allocate a buffer for the encrypted old value */
1979 EncOldValue = midl_user_allocate(sizeof(LSAPR_CR_CIPHER_VALUE) + OldValueLength);
1980 if (EncOldValue == NULL)
1981 {
1982 Status = STATUS_INSUFFICIENT_RESOURCES;
1983 goto done;
1984 }
1985
1986 /* FIXME: Encrypt the old value */
1987 EncOldValue->Length = (USHORT)(OldValueLength - sizeof(WCHAR));
1988 EncOldValue->MaximumLength = (USHORT)OldValueLength;
1989 EncOldValue->Buffer = (PBYTE)OldValue;
1990 }
1991
1992 if (OldValueSetTime != NULL)
1993 {
1994 BufferSize = sizeof(LARGE_INTEGER);
1995
1996 /* Get the old value time */
1997 Status = LsapGetObjectAttribute(SecretObject,
1998 L"OldTime",
1999 (PBYTE)OldValueSetTime,
2000 &BufferSize);
2001 if (!NT_SUCCESS(Status))
2002 goto done;
2003 }
2004
2005
2006 done:
2007 if (NT_SUCCESS(Status))
2008 {
2009 if (EncryptedCurrentValue != NULL)
2010 *EncryptedCurrentValue = EncCurrentValue;
2011
2012 if (EncryptedOldValue != NULL)
2013 *EncryptedOldValue = EncOldValue;
2014 }
2015 else
2016 {
2017 if (EncryptedCurrentValue != NULL)
2018 *EncryptedCurrentValue = NULL;
2019
2020 if (EncryptedOldValue != NULL)
2021 *EncryptedOldValue = NULL;
2022
2023 if (EncCurrentValue != NULL)
2024 midl_user_free(EncCurrentValue);
2025
2026 if (EncOldValue != NULL)
2027 midl_user_free(EncOldValue);
2028
2029 if (CurrentValue != NULL)
2030 midl_user_free(CurrentValue);
2031
2032 if (OldValue != NULL)
2033 midl_user_free(OldValue);
2034 }
2035
2036 TRACE("LsarQuerySecret done (Status 0x%08lx)\n", Status);
2037
2038 return Status;
2039 }
2040
2041
2042 /* Function 31 */
2043 NTSTATUS WINAPI LsarLookupPrivilegeValue(
2044 LSAPR_HANDLE PolicyHandle,
2045 PRPC_UNICODE_STRING Name,
2046 PLUID Value)
2047 {
2048 NTSTATUS Status;
2049
2050 TRACE("LsarLookupPrivilegeValue(%p, %wZ, %p)\n",
2051 PolicyHandle, Name, Value);
2052
2053 Status = LsapValidateDbObject(PolicyHandle,
2054 LsaDbPolicyObject,
2055 POLICY_LOOKUP_NAMES,
2056 NULL);
2057 if (!NT_SUCCESS(Status))
2058 {
2059 ERR("Invalid handle (Status %lx)\n", Status);
2060 return Status;
2061 }
2062
2063 TRACE("Privilege: %wZ\n", Name);
2064
2065 Status = LsarpLookupPrivilegeValue(Name,
2066 Value);
2067
2068 return Status;
2069 }
2070
2071
2072 /* Function 32 */
2073 NTSTATUS WINAPI LsarLookupPrivilegeName(
2074 LSAPR_HANDLE PolicyHandle,
2075 PLUID Value,
2076 PRPC_UNICODE_STRING *Name)
2077 {
2078 NTSTATUS Status;
2079
2080 TRACE("LsarLookupPrivilegeName(%p, %p, %p)\n",
2081 PolicyHandle, Value, Name);
2082
2083 Status = LsapValidateDbObject(PolicyHandle,
2084 LsaDbPolicyObject,
2085 POLICY_LOOKUP_NAMES,
2086 NULL);
2087 if (!NT_SUCCESS(Status))
2088 {
2089 ERR("Invalid handle\n");
2090 return Status;
2091 }
2092
2093 Status = LsarpLookupPrivilegeName(Value,
2094 Name);
2095
2096 return Status;
2097 }
2098
2099
2100 /* Function 33 */
2101 NTSTATUS WINAPI LsarLookupPrivilegeDisplayName(
2102 LSAPR_HANDLE PolicyHandle,
2103 PRPC_UNICODE_STRING Name,
2104 USHORT ClientLanguage,
2105 USHORT ClientSystemDefaultLanguage,
2106 PRPC_UNICODE_STRING *DisplayName,
2107 USHORT *LanguageReturned)
2108 {
2109 NTSTATUS Status;
2110
2111 TRACE("LsarLookupPrivilegeDisplayName(%p, %p, %u, %u, %p, %p)\n",
2112 PolicyHandle, Name, ClientLanguage, ClientSystemDefaultLanguage, DisplayName, LanguageReturned);
2113
2114 Status = LsapValidateDbObject(PolicyHandle,
2115 LsaDbPolicyObject,
2116 POLICY_LOOKUP_NAMES,
2117 NULL);
2118 if (!NT_SUCCESS(Status))
2119 {
2120 ERR("Invalid handle\n");
2121 return Status;
2122 }
2123
2124 Status = LsarpLookupPrivilegeDisplayName(Name,
2125 ClientLanguage,
2126 ClientSystemDefaultLanguage,
2127 DisplayName,
2128 LanguageReturned);
2129
2130 return Status;
2131 }
2132
2133
2134 /* Function 34 */
2135 NTSTATUS WINAPI LsarDeleteObject(
2136 LSAPR_HANDLE *ObjectHandle)
2137 {
2138 PLSA_DB_OBJECT DbObject;
2139 NTSTATUS Status;
2140
2141 TRACE("(%p)\n", ObjectHandle);
2142
2143 if (ObjectHandle == NULL)
2144 return STATUS_INVALID_PARAMETER;
2145
2146 /* Validate the ObjectHandle */
2147 Status = LsapValidateDbObject(*ObjectHandle,
2148 LsaDbIgnoreObject,
2149 DELETE,
2150 &DbObject);
2151 if (!NT_SUCCESS(Status))
2152 {
2153 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
2154 return Status;
2155 }
2156
2157 /* You cannot delete the policy object */
2158 if (DbObject->ObjectType == LsaDbPolicyObject)
2159 return STATUS_INVALID_PARAMETER;
2160
2161 /* Delete the database object */
2162 Status = LsapDeleteDbObject(DbObject);
2163 if (!NT_SUCCESS(Status))
2164 {
2165 ERR("LsapDeleteDbObject returned 0x%08lx\n", Status);
2166 return Status;
2167 }
2168
2169 /* Invalidate the object handle */
2170 *ObjectHandle = NULL;
2171
2172 return STATUS_SUCCESS;
2173 }
2174
2175
2176 /* Function 35 */
2177 NTSTATUS WINAPI LsarEnumerateAccountsWithUserRight(
2178 LSAPR_HANDLE PolicyHandle,
2179 PRPC_UNICODE_STRING UserRight,
2180 PLSAPR_ACCOUNT_ENUM_BUFFER EnumerationBuffer)
2181 {
2182 UNIMPLEMENTED;
2183 return STATUS_NOT_IMPLEMENTED;
2184 }
2185
2186
2187 /* Function 36 */
2188 NTSTATUS WINAPI LsarEnumerateAccountRights(
2189 LSAPR_HANDLE PolicyHandle,
2190 PRPC_SID AccountSid,
2191 PLSAPR_USER_RIGHT_SET UserRights)
2192 {
2193 LSAPR_HANDLE AccountHandle;
2194 PLSAPR_PRIVILEGE_SET PrivilegeSet = NULL;
2195 PRPC_UNICODE_STRING RightsBuffer = NULL;
2196 PRPC_UNICODE_STRING PrivilegeString;
2197 ACCESS_MASK SystemAccess;
2198 ULONG RightsCount = 0;
2199 ULONG RightsIndex;
2200 ULONG i;
2201 NTSTATUS Status;
2202
2203 TRACE("LsarEnumerateAccountRights(%p %p %p)\n",
2204 PolicyHandle, AccountSid, UserRights);
2205
2206 /* Open the account */
2207 Status = LsarOpenAccount(PolicyHandle,
2208 AccountSid,
2209 ACCOUNT_VIEW,
2210 &AccountHandle);
2211 if (!NT_SUCCESS(Status))
2212 {
2213 ERR("LsarOpenAccount returned 0x%08lx\n", Status);
2214 return Status;
2215 }
2216
2217 /* Enumerate the privileges */
2218 Status = LsarEnumeratePrivilegesAccount(AccountHandle,
2219 &PrivilegeSet);
2220 if (!NT_SUCCESS(Status))
2221 {
2222 ERR("LsarEnumeratePrivilegesAccount returned 0x%08lx\n", Status);
2223 goto done;
2224 }
2225
2226 /* Get account rights */
2227 Status = LsarGetSystemAccessAccount(AccountHandle,
2228 &SystemAccess);
2229 if (!NT_SUCCESS(Status))
2230 {
2231 ERR("LsarGetSystemAccessAccount returned 0x%08lx\n", Status);
2232 goto done;
2233 }
2234
2235 RightsCount = PrivilegeSet->PrivilegeCount;
2236
2237 /* Count account rights */
2238 for (i = 0; i < sizeof(ACCESS_MASK) * 8; i++)
2239 {
2240 if (SystemAccess & (1 << i))
2241 RightsCount++;
2242 }
2243
2244 /* We are done if there are no rights to be enumerated */
2245 if (RightsCount == 0)
2246 {
2247 UserRights->Entries = 0;
2248 UserRights->UserRights = NULL;
2249 Status = STATUS_SUCCESS;
2250 goto done;
2251 }
2252
2253 /* Allocate a buffer for the account rights */
2254 RightsBuffer = MIDL_user_allocate(RightsCount * sizeof(RPC_UNICODE_STRING));
2255 if (RightsBuffer == NULL)
2256 {
2257 Status = STATUS_INSUFFICIENT_RESOURCES;
2258 goto done;
2259 }
2260
2261 /* Copy the privileges into the buffer */
2262 RightsIndex = 0;
2263 for (i = 0; i < PrivilegeSet->PrivilegeCount; i++)
2264 {
2265 PrivilegeString = NULL;
2266 Status = LsarLookupPrivilegeName(PolicyHandle,
2267 (PLUID)&PrivilegeSet->Privilege[i].Luid,
2268 &PrivilegeString);
2269 if (!NT_SUCCESS(Status))
2270 goto done;
2271
2272 RightsBuffer[i].Length = PrivilegeString->Length;
2273 RightsBuffer[i].MaximumLength = PrivilegeString->MaximumLength;
2274 RightsBuffer[i].Buffer = PrivilegeString->Buffer;
2275
2276 MIDL_user_free(PrivilegeString);
2277 RightsIndex++;
2278 }
2279
2280 /* Copy account rights into the buffer */
2281 for (i = 0; i < sizeof(ACCESS_MASK) * 8; i++)
2282 {
2283 if (SystemAccess & (1 << i))
2284 {
2285 Status = LsapLookupAccountRightName(1 << i,
2286 &PrivilegeString);
2287 if (!NT_SUCCESS(Status))
2288 goto done;
2289
2290 RightsBuffer[i].Length = PrivilegeString->Length;
2291 RightsBuffer[i].MaximumLength = PrivilegeString->MaximumLength;
2292 RightsBuffer[i].Buffer = PrivilegeString->Buffer;
2293
2294 MIDL_user_free(PrivilegeString);
2295 RightsIndex++;
2296 }
2297 }
2298
2299 UserRights->Entries = RightsCount;
2300 UserRights->UserRights = (PRPC_UNICODE_STRING)RightsBuffer;
2301
2302 done:
2303 if (!NT_SUCCESS(Status))
2304 {
2305 if (RightsBuffer != NULL)
2306 {
2307 for (RightsIndex = 0; RightsIndex < RightsCount; RightsIndex++)
2308 {
2309 if (RightsBuffer[RightsIndex].Buffer != NULL)
2310 MIDL_user_free(RightsBuffer[RightsIndex].Buffer);
2311 }
2312
2313 MIDL_user_free(RightsBuffer);
2314 }
2315 }
2316
2317 if (PrivilegeSet != NULL)
2318 MIDL_user_free(PrivilegeSet);
2319
2320 LsarClose(&AccountHandle);
2321
2322 return Status;
2323 }
2324
2325
2326 /* Function 37 */
2327 NTSTATUS WINAPI LsarAddAccountRights(
2328 LSAPR_HANDLE PolicyHandle,
2329 PRPC_SID AccountSid,
2330 PLSAPR_USER_RIGHT_SET UserRights)
2331 {
2332 UNIMPLEMENTED;
2333 return STATUS_NOT_IMPLEMENTED;
2334 }
2335
2336
2337 /* Function 38 */
2338 NTSTATUS WINAPI LsarRemoveAccountRights(
2339 LSAPR_HANDLE PolicyHandle,
2340 PRPC_SID AccountSid,
2341 BOOL AllRights,
2342 PLSAPR_USER_RIGHT_SET UserRights)
2343 {
2344 UNIMPLEMENTED;
2345 return STATUS_NOT_IMPLEMENTED;
2346 }
2347
2348
2349 /* Function 39 */
2350 NTSTATUS WINAPI LsarQueryTrustedDomainInfo(
2351 LSAPR_HANDLE PolicyHandle,
2352 PRPC_SID TrustedDomainSid,
2353 TRUSTED_INFORMATION_CLASS InformationClass,
2354 PLSAPR_TRUSTED_DOMAIN_INFO *TrustedDomainInformation)
2355 {
2356 UNIMPLEMENTED;
2357 return STATUS_NOT_IMPLEMENTED;
2358 }
2359
2360
2361 /* Function 40 */
2362 NTSTATUS WINAPI LsarSetTrustedDomainInfo(
2363 LSAPR_HANDLE PolicyHandle,
2364 PRPC_SID TrustedDomainSid,
2365 TRUSTED_INFORMATION_CLASS InformationClass,
2366 PLSAPR_TRUSTED_DOMAIN_INFO TrustedDomainInformation)
2367 {
2368 UNIMPLEMENTED;
2369 return STATUS_NOT_IMPLEMENTED;
2370 }
2371
2372
2373 /* Function 41 */
2374 NTSTATUS WINAPI LsarDeleteTrustedDomain(
2375 LSAPR_HANDLE PolicyHandle,
2376 PRPC_SID TrustedDomainSid)
2377 {
2378 UNIMPLEMENTED;
2379 return STATUS_NOT_IMPLEMENTED;
2380 }
2381
2382
2383 /* Function 42 */
2384 NTSTATUS WINAPI LsarStorePrivateData(
2385 LSAPR_HANDLE PolicyHandle,
2386 PRPC_UNICODE_STRING KeyName,
2387 PLSAPR_CR_CIPHER_VALUE EncryptedData)
2388 {
2389 PLSA_DB_OBJECT PolicyObject = NULL;
2390 PLSA_DB_OBJECT SecretsObject = NULL;
2391 PLSA_DB_OBJECT SecretObject = NULL;
2392 LARGE_INTEGER Time;
2393 PBYTE Value = NULL;
2394 ULONG ValueLength = 0;
2395 NTSTATUS Status;
2396
2397 TRACE("LsarStorePrivateData(%p %p %p)\n",
2398 PolicyHandle, KeyName, EncryptedData);
2399
2400 /* Validate the SecretHandle */
2401 Status = LsapValidateDbObject(PolicyHandle,
2402 LsaDbPolicyObject,
2403 POLICY_CREATE_SECRET,
2404 &PolicyObject);
2405 if (!NT_SUCCESS(Status))
2406 {
2407 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
2408 return Status;
2409 }
2410
2411 /* Open the 'Secrets' object */
2412 Status = LsapOpenDbObject(PolicyObject,
2413 NULL,
2414 L"Secrets",
2415 LsaDbIgnoreObject,
2416 0,
2417 PolicyObject->Trusted,
2418 &SecretsObject);
2419 if (!NT_SUCCESS(Status))
2420 {
2421 ERR("LsapOpenDbObject failed (Status 0x%08lx)\n", Status);
2422 goto done;
2423 }
2424
2425 if (EncryptedData == NULL)
2426 {
2427 /* Open the Secret object */
2428 Status = LsapOpenDbObject(SecretsObject,
2429 NULL,
2430 KeyName->Buffer,
2431 LsaDbSecretObject,
2432 0,
2433 PolicyObject->Trusted,
2434 &SecretObject);
2435 if (!NT_SUCCESS(Status))
2436 {
2437 ERR("LsapOpenDbObject failed (Status 0x%08lx)\n", Status);
2438 goto done;
2439 }
2440
2441 /* Delete the secret */
2442 Status = LsapDeleteDbObject(SecretObject);
2443 if (NT_SUCCESS(Status))
2444 SecretObject = NULL;
2445 }
2446 else
2447 {
2448 /* Create the Secret object */
2449 Status = LsapCreateDbObject(SecretsObject,
2450 NULL,
2451 KeyName->Buffer,
2452 LsaDbSecretObject,
2453 0,
2454 PolicyObject->Trusted,
2455 &SecretObject);
2456 if (!NT_SUCCESS(Status))
2457 {
2458 ERR("LsapCreateDbObject failed (Status 0x%08lx)\n", Status);
2459 goto done;
2460 }
2461
2462 /* FIXME: Decrypt data */
2463 Value = EncryptedData->Buffer;
2464 ValueLength = EncryptedData->MaximumLength;
2465
2466 /* Get the current time */
2467 Status = NtQuerySystemTime(&Time);
2468 if (!NT_SUCCESS(Status))
2469 {
2470 ERR("NtQuerySystemTime failed (Status 0x%08lx)\n", Status);
2471 goto done;
2472 }
2473
2474 /* Set the current value */
2475 Status = LsapSetObjectAttribute(SecretObject,
2476 L"CurrentValue",
2477 Value,
2478 ValueLength);
2479 if (!NT_SUCCESS(Status))
2480 {
2481 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
2482 goto done;
2483 }
2484
2485 /* Set the current time */
2486 Status = LsapSetObjectAttribute(SecretObject,
2487 L"CurrentTime",
2488 &Time,
2489 sizeof(LARGE_INTEGER));
2490 if (!NT_SUCCESS(Status))
2491 {
2492 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
2493 goto done;
2494 }
2495
2496 /* Get the current time */
2497 Status = NtQuerySystemTime(&Time);
2498 if (!NT_SUCCESS(Status))
2499 {
2500 ERR("NtQuerySystemTime failed (Status 0x%08lx)\n", Status);
2501 goto done;
2502 }
2503
2504 /* Set the old value */
2505 Status = LsapSetObjectAttribute(SecretObject,
2506 L"OldValue",
2507 NULL,
2508 0);
2509 if (!NT_SUCCESS(Status))
2510 {
2511 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
2512 goto done;
2513 }
2514
2515 /* Set the old time */
2516 Status = LsapSetObjectAttribute(SecretObject,
2517 L"OldTime",
2518 &Time,
2519 sizeof(LARGE_INTEGER));
2520 if (!NT_SUCCESS(Status))
2521 {
2522 ERR("LsapSetObjectAttribute failed (Status 0x%08lx)\n", Status);
2523 }
2524 }
2525
2526 done:
2527 if (SecretObject != NULL)
2528 LsapCloseDbObject(SecretObject);
2529
2530 if (SecretsObject != NULL)
2531 LsapCloseDbObject(SecretsObject);
2532
2533 return Status;
2534 }
2535
2536
2537 /* Function 43 */
2538 NTSTATUS WINAPI LsarRetrievePrivateData(
2539 LSAPR_HANDLE PolicyHandle,
2540 PRPC_UNICODE_STRING KeyName,
2541 PLSAPR_CR_CIPHER_VALUE *EncryptedData)
2542 {
2543 PLSA_DB_OBJECT PolicyObject = NULL;
2544 PLSA_DB_OBJECT SecretObject = NULL;
2545 PLSAPR_CR_CIPHER_VALUE EncCurrentValue = NULL;
2546 ULONG CurrentValueLength = 0;
2547 PBYTE CurrentValue = NULL;
2548 NTSTATUS Status;
2549
2550 /* Validate the SecretHandle */
2551 Status = LsapValidateDbObject(PolicyHandle,
2552 LsaDbPolicyObject,
2553 POLICY_CREATE_SECRET,
2554 &PolicyObject);
2555 if (!NT_SUCCESS(Status))
2556 {
2557 ERR("LsapValidateDbObject returned 0x%08lx\n", Status);
2558 return Status;
2559 }
2560
2561 /* Open the secret object */
2562 Status = LsapOpenDbObject(PolicyObject,
2563 L"Secrets",
2564 KeyName->Buffer,
2565 LsaDbSecretObject,
2566 0,
2567 PolicyObject->Trusted,
2568 &SecretObject);
2569 if (!NT_SUCCESS(Status))
2570 {
2571 ERR("LsapOpenDbObject failed (Status 0x%08lx)\n", Status);
2572 goto done;
2573 }
2574
2575 /* Get the size of the current value */
2576 Status = LsapGetObjectAttribute(SecretObject,
2577 L"CurrentValue",
2578 NULL,
2579 &CurrentValueLength);
2580 if (!NT_SUCCESS(Status))
2581 goto done;
2582
2583 /* Allocate a buffer for the current value */
2584 CurrentValue = midl_user_allocate(CurrentValueLength);
2585 if (CurrentValue == NULL)
2586 {
2587 Status = STATUS_INSUFFICIENT_RESOURCES;
2588 goto done;
2589 }
2590
2591 /* Get the current value */
2592 Status = LsapGetObjectAttribute(SecretObject,
2593 L"CurrentValue",
2594 CurrentValue,
2595 &CurrentValueLength);
2596 if (!NT_SUCCESS(Status))
2597 goto done;
2598
2599 /* Allocate a buffer for the encrypted current value */
2600 EncCurrentValue = midl_user_allocate(sizeof(LSAPR_CR_CIPHER_VALUE) + CurrentValueLength);
2601 if (EncCurrentValue == NULL)
2602 {
2603 Status = STATUS_INSUFFICIENT_RESOURCES;
2604 goto done;
2605 }
2606
2607 /* FIXME: Encrypt the current value */
2608 EncCurrentValue->Length = (USHORT)(CurrentValueLength - sizeof(WCHAR));
2609 EncCurrentValue->MaximumLength = (USHORT)CurrentValueLength;
2610 EncCurrentValue->Buffer = (PBYTE)(EncCurrentValue + 1);
2611 RtlCopyMemory(EncCurrentValue->Buffer,
2612 CurrentValue,
2613 CurrentValueLength);
2614
2615 done:
2616 if (NT_SUCCESS(Status))
2617 {
2618 if (EncryptedData != NULL)
2619 *EncryptedData = EncCurrentValue;
2620 }
2621 else
2622 {
2623 if (EncryptedData != NULL)
2624 *EncryptedData = NULL;
2625
2626 if (EncCurrentValue != NULL)
2627 midl_user_free(EncCurrentValue);
2628
2629 if (SecretObject != NULL)
2630 LsapCloseDbObject(SecretObject);
2631 }
2632
2633 return Status;
2634 }
2635
2636
2637 /* Function 44 */
2638 NTSTATUS WINAPI LsarOpenPolicy2(
2639 LPWSTR SystemName,
2640 PLSAPR_OBJECT_ATTRIBUTES ObjectAttributes,
2641 ACCESS_MASK DesiredAccess,
2642 LSAPR_HANDLE *PolicyHandle)
2643 {
2644 return LsarOpenPolicy(SystemName,
2645 ObjectAttributes,
2646 DesiredAccess,
2647 PolicyHandle);
2648 }
2649
2650
2651 /* Function 45 */
2652 NTSTATUS WINAPI LsarGetUserName(
2653 LPWSTR SystemName,
2654 PRPC_UNICODE_STRING *UserName,
2655 PRPC_UNICODE_STRING *DomainName)
2656 {
2657 UNIMPLEMENTED;
2658 return STATUS_NOT_IMPLEMENTED;
2659 }
2660
2661
2662 /* Function 46 */
2663 NTSTATUS WINAPI LsarQueryInformationPolicy2(
2664 LSAPR_HANDLE PolicyHandle,
2665 POLICY_INFORMATION_CLASS InformationClass,
2666 PLSAPR_POLICY_INFORMATION *PolicyInformation)
2667 {
2668 return LsarQueryInformationPolicy(PolicyHandle,
2669 InformationClass,
2670 PolicyInformation);
2671 }
2672
2673
2674 /* Function 47 */
2675 NTSTATUS WINAPI LsarSetInformationPolicy2(
2676 LSAPR_HANDLE PolicyHandle,
2677 POLICY_INFORMATION_CLASS InformationClass,
2678 PLSAPR_POLICY_INFORMATION PolicyInformation)
2679 {
2680 return LsarSetInformationPolicy(PolicyHandle,
2681 InformationClass,
2682 PolicyInformation);
2683 }
2684
2685
2686 /* Function 48 */
2687 NTSTATUS WINAPI LsarQueryTrustedDomainInfoByName(
2688 LSAPR_HANDLE PolicyHandle,
2689 PRPC_UNICODE_STRING TrustedDomainName,
2690 POLICY_INFORMATION_CLASS InformationClass,
2691 PLSAPR_TRUSTED_DOMAIN_INFO *PolicyInformation)
2692 {
2693 UNIMPLEMENTED;
2694 return STATUS_NOT_IMPLEMENTED;
2695 }
2696
2697
2698 /* Function 49 */
2699 NTSTATUS WINAPI LsarSetTrustedDomainInfoByName(
2700 LSAPR_HANDLE PolicyHandle,
2701 PRPC_UNICODE_STRING TrustedDomainName,
2702 POLICY_INFORMATION_CLASS InformationClass,
2703 PLSAPR_TRUSTED_DOMAIN_INFO PolicyInformation)
2704 {
2705 UNIMPLEMENTED;
2706 return STATUS_NOT_IMPLEMENTED;
2707 }
2708
2709
2710 /* Function 50 */
2711 NTSTATUS WINAPI LsarEnumerateTrustedDomainsEx(
2712 LSAPR_HANDLE PolicyHandle,
2713 DWORD *EnumerationContext,
2714 PLSAPR_TRUSTED_ENUM_BUFFER_EX EnumerationBuffer,
2715 DWORD PreferedMaximumLength)
2716 {
2717 UNIMPLEMENTED;
2718 return STATUS_NOT_IMPLEMENTED;
2719 }
2720
2721
2722 /* Function 51 */
2723 NTSTATUS WINAPI LsarCreateTrustedDomainEx(
2724 LSAPR_HANDLE PolicyHandle,
2725 PLSAPR_TRUSTED_DOMAIN_INFORMATION_EX TrustedDomainInformation,
2726 PLSAPR_TRUSTED_DOMAIN_AUTH_INFORMATION AuthentificationInformation,
2727 ACCESS_MASK DesiredAccess,
2728 LSAPR_HANDLE *TrustedDomainHandle)
2729 {
2730 UNIMPLEMENTED;
2731 return STATUS_NOT_IMPLEMENTED;
2732 }
2733
2734
2735 /* Function 52 */
2736 NTSTATUS WINAPI LsarSetPolicyReplicationHandle(
2737 PLSAPR_HANDLE PolicyHandle)
2738 {
2739 /* Deprecated */
2740 return STATUS_NOT_IMPLEMENTED;
2741 }
2742
2743
2744 /* Function 53 */
2745 NTSTATUS WINAPI LsarQueryDomainInformationPolicy(
2746 LSAPR_HANDLE PolicyHandle,
2747 POLICY_INFORMATION_CLASS InformationClass,
2748 PLSAPR_POLICY_DOMAIN_INFORMATION *PolicyInformation)
2749 {
2750 UNIMPLEMENTED;
2751 return STATUS_NOT_IMPLEMENTED;
2752 }
2753
2754
2755 /* Function 54 */
2756 NTSTATUS WINAPI LsarSetDomainInformationPolicy(
2757 LSAPR_HANDLE PolicyHandle,
2758 POLICY_INFORMATION_CLASS InformationClass,
2759 PLSAPR_POLICY_DOMAIN_INFORMATION PolicyInformation)
2760 {
2761 UNIMPLEMENTED;
2762 return STATUS_NOT_IMPLEMENTED;
2763 }
2764
2765
2766 /* Function 55 */
2767 NTSTATUS WINAPI LsarOpenTrustedDomainByName(
2768 LSAPR_HANDLE PolicyHandle,
2769 PRPC_UNICODE_STRING TrustedDomainName,
2770 ACCESS_MASK DesiredAccess,
2771 LSAPR_HANDLE *TrustedDomainHandle)
2772 {
2773 UNIMPLEMENTED;
2774 return STATUS_NOT_IMPLEMENTED;
2775 }
2776
2777
2778 /* Function 56 */
2779 NTSTATUS WINAPI LsarTestCall(
2780 handle_t hBinding)
2781 {
2782 UNIMPLEMENTED;
2783 return STATUS_NOT_IMPLEMENTED;
2784 }
2785
2786
2787 /* Function 57 */
2788 NTSTATUS WINAPI LsarLookupSids2(
2789 LSAPR_HANDLE PolicyHandle,
2790 PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
2791 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
2792 PLSAPR_TRANSLATED_NAMES_EX TranslatedNames,
2793 LSAP_LOOKUP_LEVEL LookupLevel,
2794 DWORD *MappedCount,
2795 DWORD LookupOptions,
2796 DWORD ClientRevision)
2797 {
2798 NTSTATUS Status;
2799
2800 TRACE("(%p %p %p %p %d %p %lu %lu)\n",
2801 PolicyHandle, SidEnumBuffer, ReferencedDomains, TranslatedNames,
2802 LookupLevel, MappedCount, LookupOptions, ClientRevision);
2803
2804 TranslatedNames->Entries = SidEnumBuffer->Entries;
2805 TranslatedNames->Names = NULL;
2806 *ReferencedDomains = NULL;
2807
2808 /* FIXME: Fail, if there is an invalid SID in the SidEnumBuffer */
2809
2810 Status = LsapLookupSids(SidEnumBuffer,
2811 ReferencedDomains,
2812 TranslatedNames,
2813 LookupLevel,
2814 MappedCount,
2815 LookupOptions,
2816 ClientRevision);
2817
2818 return Status;
2819 }
2820
2821
2822 /* Function 58 */
2823 NTSTATUS WINAPI LsarLookupNames2(
2824 LSAPR_HANDLE PolicyHandle,
2825 DWORD Count,
2826 PRPC_UNICODE_STRING Names,
2827 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
2828 PLSAPR_TRANSLATED_SIDS_EX TranslatedSids,
2829 LSAP_LOOKUP_LEVEL LookupLevel,
2830 DWORD *MappedCount,
2831 DWORD LookupOptions,
2832 DWORD ClientRevision)
2833 {
2834 LSAPR_TRANSLATED_SIDS_EX2 TranslatedSidsEx2;
2835 ULONG i;
2836 NTSTATUS Status;
2837
2838 TRACE("(%p %lu %p %p %p %d %p %lu %lu)\n",
2839 PolicyHandle, Count, Names, ReferencedDomains, TranslatedSids,
2840 LookupLevel, MappedCount, LookupOptions, ClientRevision);
2841
2842 TranslatedSids->Entries = 0;
2843 TranslatedSids->Sids = NULL;
2844 *ReferencedDomains = NULL;
2845
2846 if (Count == 0)
2847 return STATUS_NONE_MAPPED;
2848
2849 TranslatedSidsEx2.Entries = 0;
2850 TranslatedSidsEx2.Sids = NULL;
2851
2852 Status = LsapLookupNames(Count,
2853 Names,
2854 ReferencedDomains,
2855 &TranslatedSidsEx2,
2856 LookupLevel,
2857 MappedCount,
2858 LookupOptions,
2859 ClientRevision);
2860 if (!NT_SUCCESS(Status))
2861 return Status;
2862
2863 TranslatedSids->Entries = TranslatedSidsEx2.Entries;
2864 TranslatedSids->Sids = MIDL_user_allocate(TranslatedSids->Entries * sizeof(LSA_TRANSLATED_SID));
2865 if (TranslatedSids->Sids == NULL)
2866 {
2867 MIDL_user_free(TranslatedSidsEx2.Sids);
2868 MIDL_user_free(*ReferencedDomains);
2869 *ReferencedDomains = NULL;
2870 return STATUS_INSUFFICIENT_RESOURCES;
2871 }
2872
2873 for (i = 0; i < TranslatedSidsEx2.Entries; i++)
2874 {
2875 TranslatedSids->Sids[i].Use = TranslatedSidsEx2.Sids[i].Use;
2876 TranslatedSids->Sids[i].RelativeId = LsapGetRelativeIdFromSid(TranslatedSidsEx2.Sids[i].Sid);
2877 TranslatedSids->Sids[i].DomainIndex = TranslatedSidsEx2.Sids[i].DomainIndex;
2878 TranslatedSids->Sids[i].Flags = TranslatedSidsEx2.Sids[i].Flags;
2879 }
2880
2881 MIDL_user_free(TranslatedSidsEx2.Sids);
2882
2883 return STATUS_SUCCESS;
2884 }
2885
2886
2887 /* Function 59 */
2888 NTSTATUS WINAPI LsarCreateTrustedDomainEx2(
2889 LSAPR_HANDLE PolicyHandle,
2890 PLSAPR_TRUSTED_DOMAIN_INFORMATION_EX TrustedDomainInformation,
2891 PLSAPR_TRUSTED_DOMAIN_AUTH_INFORMATION_INTERNAL AuthentificationInformation,
2892 ACCESS_MASK DesiredAccess,
2893 LSAPR_HANDLE *TrustedDomainHandle)
2894 {
2895 UNIMPLEMENTED;
2896 return STATUS_NOT_IMPLEMENTED;
2897 }
2898
2899
2900 /* Function 60 */
2901 NTSTATUS WINAPI CredrWrite(
2902 handle_t hBinding)
2903 {
2904 UNIMPLEMENTED;
2905 return STATUS_NOT_IMPLEMENTED;
2906 }
2907
2908
2909 /* Function 61 */
2910 NTSTATUS WINAPI CredrRead(
2911 handle_t hBinding)
2912 {
2913 UNIMPLEMENTED;
2914 return STATUS_NOT_IMPLEMENTED;
2915 }
2916
2917
2918 /* Function 62 */
2919 NTSTATUS WINAPI CredrEnumerate(
2920 handle_t hBinding)
2921 {
2922 UNIMPLEMENTED;
2923 return STATUS_NOT_IMPLEMENTED;
2924 }
2925
2926
2927 /* Function 63 */
2928 NTSTATUS WINAPI CredrWriteDomainCredentials(
2929 handle_t hBinding)
2930 {
2931 UNIMPLEMENTED;
2932 return STATUS_NOT_IMPLEMENTED;
2933 }
2934
2935
2936 /* Function 64 */
2937 NTSTATUS WINAPI CredrReadDomainCredentials(
2938 handle_t hBinding)
2939 {
2940 UNIMPLEMENTED;
2941 return STATUS_NOT_IMPLEMENTED;
2942 }
2943
2944
2945 /* Function 65 */
2946 NTSTATUS WINAPI CredrDelete(
2947 handle_t hBinding)
2948 {
2949 UNIMPLEMENTED;
2950 return STATUS_NOT_IMPLEMENTED;
2951 }
2952
2953
2954 /* Function 66 */
2955 NTSTATUS WINAPI CredrGetTargetInfo(
2956 handle_t hBinding)
2957 {
2958 UNIMPLEMENTED;
2959 return STATUS_NOT_IMPLEMENTED;
2960 }
2961
2962
2963 /* Function 67 */
2964 NTSTATUS WINAPI CredrProfileLoaded(
2965 handle_t hBinding)
2966 {
2967 UNIMPLEMENTED;
2968 return STATUS_NOT_IMPLEMENTED;
2969 }
2970
2971
2972 /* Function 68 */
2973 NTSTATUS WINAPI LsarLookupNames3(
2974 LSAPR_HANDLE PolicyHandle,
2975 DWORD Count,
2976 PRPC_UNICODE_STRING Names,
2977 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
2978 PLSAPR_TRANSLATED_SIDS_EX2 TranslatedSids,
2979 LSAP_LOOKUP_LEVEL LookupLevel,
2980 DWORD *MappedCount,
2981 DWORD LookupOptions,
2982 DWORD ClientRevision)
2983 {
2984 NTSTATUS Status;
2985
2986 TRACE("(%p %lu %p %p %p %d %p %lu %lu)\n",
2987 PolicyHandle, Count, Names, ReferencedDomains, TranslatedSids,
2988 LookupLevel, MappedCount, LookupOptions, ClientRevision);
2989
2990 TranslatedSids->Entries = 0;
2991 TranslatedSids->Sids = NULL;
2992 *ReferencedDomains = NULL;
2993
2994 if (Count == 0)
2995 return STATUS_NONE_MAPPED;
2996
2997 Status = LsapLookupNames(Count,
2998 Names,
2999 ReferencedDomains,
3000 TranslatedSids,
3001 LookupLevel,
3002 MappedCount,
3003 LookupOptions,
3004 ClientRevision);
3005
3006 return Status;
3007 }
3008
3009
3010 /* Function 69 */
3011 NTSTATUS WINAPI CredrGetSessionTypes(
3012 handle_t hBinding)
3013 {
3014 UNIMPLEMENTED;
3015 return STATUS_NOT_IMPLEMENTED;
3016 }
3017
3018
3019 /* Function 70 */
3020 NTSTATUS WINAPI LsarRegisterAuditEvent(
3021 handle_t hBinding)
3022 {
3023 UNIMPLEMENTED;
3024 return STATUS_NOT_IMPLEMENTED;
3025 }
3026
3027
3028 /* Function 71 */
3029 NTSTATUS WINAPI LsarGenAuditEvent(
3030 handle_t hBinding)
3031 {
3032 UNIMPLEMENTED;
3033 return STATUS_NOT_IMPLEMENTED;
3034 }
3035
3036
3037 /* Function 72 */
3038 NTSTATUS WINAPI LsarUnregisterAuditEvent(
3039 handle_t hBinding)
3040 {
3041 UNIMPLEMENTED;
3042 return STATUS_NOT_IMPLEMENTED;
3043 }
3044
3045
3046 /* Function 73 */
3047 NTSTATUS WINAPI LsarQueryForestTrustInformation(
3048 LSAPR_HANDLE PolicyHandle,
3049 PLSA_UNICODE_STRING TrustedDomainName,
3050 LSA_FOREST_TRUST_RECORD_TYPE HighestRecordType,
3051 PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
3052 {
3053 UNIMPLEMENTED;
3054 return STATUS_NOT_IMPLEMENTED;
3055 }
3056
3057
3058 /* Function 74 */
3059 NTSTATUS WINAPI LsarSetForestTrustInformation(
3060 LSAPR_HANDLE PolicyHandle,
3061 PLSA_UNICODE_STRING TrustedDomainName,
3062 LSA_FOREST_TRUST_RECORD_TYPE HighestRecordType,
3063 PLSA_FOREST_TRUST_INFORMATION ForestTrustInfo,
3064 BOOL CheckOnly,
3065 PLSA_FOREST_TRUST_COLLISION_INFORMATION *CollisionInfo)
3066 {
3067 UNIMPLEMENTED;
3068 return STATUS_NOT_IMPLEMENTED;
3069 }
3070
3071
3072 /* Function 75 */
3073 NTSTATUS WINAPI CredrRename(
3074 handle_t hBinding)
3075 {
3076 UNIMPLEMENTED;
3077 return STATUS_NOT_IMPLEMENTED;
3078 }
3079
3080
3081 /* Function 76 */
3082 NTSTATUS WINAPI LsarLookupSids3(
3083 LSAPR_HANDLE PolicyHandle,
3084 PLSAPR_SID_ENUM_BUFFER SidEnumBuffer,
3085 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
3086 PLSAPR_TRANSLATED_NAMES_EX TranslatedNames,
3087 LSAP_LOOKUP_LEVEL LookupLevel,
3088 DWORD *MappedCount,
3089 DWORD LookupOptions,
3090 DWORD ClientRevision)
3091 {
3092 NTSTATUS Status;
3093
3094 TRACE("(%p %p %p %p %d %p %lu %lu)\n",
3095 PolicyHandle, SidEnumBuffer, ReferencedDomains, TranslatedNames,
3096 LookupLevel, MappedCount, LookupOptions, ClientRevision);
3097
3098 TranslatedNames->Entries = SidEnumBuffer->Entries;
3099 TranslatedNames->Names = NULL;
3100 *ReferencedDomains = NULL;
3101
3102 /* FIXME: Fail, if there is an invalid SID in the SidEnumBuffer */
3103
3104 Status = LsapLookupSids(SidEnumBuffer,
3105 ReferencedDomains,
3106 TranslatedNames,
3107 LookupLevel,
3108 MappedCount,
3109 LookupOptions,
3110 ClientRevision);
3111
3112 return Status;
3113 }
3114
3115
3116 /* Function 77 */
3117 NTSTATUS WINAPI LsarLookupNames4(
3118 handle_t RpcHandle,
3119 DWORD Count,
3120 PRPC_UNICODE_STRING Names,
3121 PLSAPR_REFERENCED_DOMAIN_LIST *ReferencedDomains,
3122 PLSAPR_TRANSLATED_SIDS_EX2 TranslatedSids,
3123 LSAP_LOOKUP_LEVEL LookupLevel,
3124 DWORD *MappedCount,
3125 DWORD LookupOptions,
3126 DWORD ClientRevision)
3127 {
3128 NTSTATUS Status;
3129
3130 TRACE("(%p %lu %p %p %p %d %p %lu %lu)\n",
3131 RpcHandle, Count, Names, ReferencedDomains, TranslatedSids,
3132 LookupLevel, MappedCount, LookupOptions, ClientRevision);
3133
3134 TranslatedSids->Entries = 0;
3135 TranslatedSids->Sids = NULL;
3136 *ReferencedDomains = NULL;
3137
3138 if (Count == 0)
3139 return STATUS_NONE_MAPPED;
3140
3141 Status = LsapLookupNames(Count,
3142 Names,
3143 ReferencedDomains,
3144 TranslatedSids,
3145 LookupLevel,
3146 MappedCount,
3147 LookupOptions,
3148 ClientRevision);
3149
3150 return Status;
3151 }
3152
3153
3154 /* Function 78 */
3155 NTSTATUS WINAPI LsarOpenPolicySce(
3156 LPWSTR SystemName,
3157 PLSAPR_OBJECT_ATTRIBUTES ObjectAttributes,
3158 ACCESS_MASK DesiredAccess,
3159 LSAPR_HANDLE *PolicyHandle)
3160 {
3161 UNIMPLEMENTED;
3162 return STATUS_NOT_IMPLEMENTED;
3163 }
3164
3165
3166 /* Function 79 */
3167 NTSTATUS WINAPI LsarAdtRegisterSecurityEventSource(
3168 handle_t hBinding)
3169 {
3170 UNIMPLEMENTED;
3171 return STATUS_NOT_IMPLEMENTED;
3172 }
3173
3174
3175 /* Function 80 */
3176 NTSTATUS WINAPI LsarAdtUnregisterSecurityEventSource(
3177 handle_t hBinding)
3178 {
3179 UNIMPLEMENTED;
3180 return STATUS_NOT_IMPLEMENTED;
3181 }
3182
3183
3184 /* Function 81 */
3185 NTSTATUS WINAPI LsarAdtReportSecurityEvent(
3186 handle_t hBinding)
3187 {
3188 UNIMPLEMENTED;
3189 return STATUS_NOT_IMPLEMENTED;
3190 }
3191
3192 /* EOF */