[INCLUDE]
[reactos.git] / reactos / dll / win32 / advapi32 / sec / lsa.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/advapi32/sec/lsa.c
5 * PURPOSE: Local security authority functions
6 * PROGRAMMER: Emanuele Aliberti
7 * UPDATE HISTORY:
8 * 19990322 EA created
9 * 19990515 EA stubs
10 * 20030202 KJK compressed stubs
11 *
12 */
13
14 #include <advapi32.h>
15
16 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
17
18
19 static
20 BOOL
21 LsapIsLocalComputer(PLSA_UNICODE_STRING ServerName)
22 {
23 DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
24 BOOL Result;
25 LPWSTR buf;
26
27 if (ServerName == NULL || ServerName->Length == 0 || ServerName->Buffer == NULL)
28 return TRUE;
29
30 buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
31 Result = GetComputerNameW(buf, &dwSize);
32 if (Result && (ServerName->Buffer[0] == '\\') && (ServerName->Buffer[1] == '\\'))
33 ServerName += 2;
34 Result = Result && !lstrcmpW(ServerName->Buffer, buf);
35 HeapFree(GetProcessHeap(), 0, buf);
36
37 return Result;
38 }
39
40
41 handle_t
42 __RPC_USER
43 PLSAPR_SERVER_NAME_bind(PLSAPR_SERVER_NAME pszSystemName)
44 {
45 handle_t hBinding = NULL;
46 LPWSTR pszStringBinding;
47 RPC_STATUS status;
48
49 TRACE("PLSAPR_SERVER_NAME_bind() called\n");
50
51 status = RpcStringBindingComposeW(NULL,
52 L"ncacn_np",
53 pszSystemName,
54 L"\\pipe\\lsarpc",
55 NULL,
56 &pszStringBinding);
57 if (status)
58 {
59 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
60 return NULL;
61 }
62
63 /* Set the binding handle that will be used to bind to the server. */
64 status = RpcBindingFromStringBindingW(pszStringBinding,
65 &hBinding);
66 if (status)
67 {
68 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
69 }
70
71 status = RpcStringFreeW(&pszStringBinding);
72 if (status)
73 {
74 TRACE("RpcStringFree returned 0x%x\n", status);
75 }
76
77 return hBinding;
78 }
79
80
81 void
82 __RPC_USER
83 PLSAPR_SERVER_NAME_unbind(PLSAPR_SERVER_NAME pszSystemName,
84 handle_t hBinding)
85 {
86 RPC_STATUS status;
87
88 TRACE("PLSAPR_SERVER_NAME_unbind() called\n");
89
90 status = RpcBindingFree(&hBinding);
91 if (status)
92 {
93 TRACE("RpcBindingFree returned 0x%x\n", status);
94 }
95 }
96
97
98 /*
99 * @implemented
100 */
101 NTSTATUS
102 WINAPI
103 LsaAddAccountRights(IN LSA_HANDLE PolicyHandle,
104 IN PSID AccountSid,
105 IN PLSA_UNICODE_STRING UserRights,
106 IN ULONG CountOfRights)
107 {
108 LSAPR_USER_RIGHT_SET UserRightSet;
109 NTSTATUS Status;
110
111 TRACE("LsaAddAccountRights(%p %p %p 0x%08x)\n",
112 PolicyHandle, AccountSid, UserRights, CountOfRights);
113
114 UserRightSet.Entries = CountOfRights;
115 UserRightSet.UserRights = (PRPC_UNICODE_STRING)UserRights;
116
117 RpcTryExcept
118 {
119 Status = LsarAddAccountRights((LSAPR_HANDLE)PolicyHandle,
120 (PRPC_SID)AccountSid,
121 &UserRightSet);
122
123 }
124 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
125 {
126 Status = I_RpcMapWin32Status(RpcExceptionCode());
127 }
128 RpcEndExcept;
129
130 return Status;
131 }
132
133
134 /*
135 * @implemented
136 */
137 NTSTATUS
138 WINAPI
139 LsaAddPrivilegesToAccount(IN LSA_HANDLE AccountHandle,
140 IN PPRIVILEGE_SET PrivilegeSet)
141 {
142 NTSTATUS Status;
143
144 TRACE("LsaAddPrivilegesToAccount(%p %p)\n",
145 AccountHandle, PrivilegeSet);
146
147 RpcTryExcept
148 {
149 Status = LsarAddPrivilegesToAccount((LSAPR_HANDLE)AccountHandle,
150 (PLSAPR_PRIVILEGE_SET)PrivilegeSet);
151 }
152 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
153 {
154 Status = I_RpcMapWin32Status(RpcExceptionCode());
155 }
156 RpcEndExcept;
157
158 return Status;
159 }
160
161
162 /*
163 * @implemented
164 */
165 NTSTATUS
166 WINAPI
167 LsaClearAuditLog(IN LSA_HANDLE PolicyHandle)
168 {
169 NTSTATUS Status;
170
171 TRACE("LsaClearAuditLog(%p)\n", PolicyHandle);
172
173 RpcTryExcept
174 {
175 Status = LsarClearAuditLog((LSAPR_HANDLE)PolicyHandle);
176 }
177 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
178 {
179 Status = I_RpcMapWin32Status(RpcExceptionCode());
180 }
181 RpcEndExcept;
182
183 return Status;
184 }
185
186
187 /*
188 * @implemented
189 */
190 NTSTATUS
191 WINAPI
192 LsaClose(IN LSA_HANDLE ObjectHandle)
193 {
194 NTSTATUS Status;
195
196 TRACE("LsaClose(%p) called\n", ObjectHandle);
197
198 RpcTryExcept
199 {
200 Status = LsarClose((PLSAPR_HANDLE)&ObjectHandle);
201 }
202 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
203 {
204 Status = I_RpcMapWin32Status(RpcExceptionCode());
205 }
206 RpcEndExcept;
207
208 return Status;
209 }
210
211
212 /*
213 * @implemented
214 */
215 NTSTATUS
216 WINAPI
217 LsaCreateAccount(IN LSA_HANDLE PolicyHandle,
218 IN PSID AccountSid,
219 IN ACCESS_MASK DesiredAccess,
220 OUT PLSA_HANDLE AccountHandle)
221 {
222 NTSTATUS Status;
223
224 TRACE("LsaCreateAccount(%p %p 0x%08lx %p)\n",
225 PolicyHandle, AccountSid, DesiredAccess, AccountHandle);
226
227 RpcTryExcept
228 {
229 Status = LsarCreateAccount((LSAPR_HANDLE)PolicyHandle,
230 AccountSid,
231 DesiredAccess,
232 AccountHandle);
233 }
234 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
235 {
236 Status = I_RpcMapWin32Status(RpcExceptionCode());
237 }
238 RpcEndExcept;
239
240 return Status;
241 }
242
243
244 /*
245 * @implemented
246 */
247 NTSTATUS
248 WINAPI
249 LsaCreateSecret(IN LSA_HANDLE PolicyHandle,
250 IN PLSA_UNICODE_STRING SecretName,
251 IN ACCESS_MASK DesiredAccess,
252 OUT PLSA_HANDLE SecretHandle)
253 {
254 NTSTATUS Status;
255
256 TRACE("LsaCreateSecret(%p %p 0x%08lx %p)\n",
257 PolicyHandle, SecretName, DesiredAccess, SecretHandle);
258
259 RpcTryExcept
260 {
261 Status = LsarCreateSecret((LSAPR_HANDLE)PolicyHandle,
262 (PRPC_UNICODE_STRING)SecretName,
263 DesiredAccess,
264 SecretHandle);
265 }
266 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
267 {
268 Status = I_RpcMapWin32Status(RpcExceptionCode());
269 }
270 RpcEndExcept;
271
272 return Status;
273 }
274
275
276 /*
277 * @implemented
278 */
279 NTSTATUS
280 WINAPI
281 LsaCreateTrustedDomain(IN LSA_HANDLE PolicyHandle,
282 IN PLSA_TRUST_INFORMATION TrustedDomainInformation,
283 IN ACCESS_MASK DesiredAccess,
284 OUT PLSA_HANDLE TrustedDomainHandle)
285 {
286 NTSTATUS Status;
287
288 TRACE("LsaCreateTrustedDomain(%p %p 0x%08lx %p)\n",
289 PolicyHandle, TrustedDomainInformation, DesiredAccess, TrustedDomainHandle);
290
291 RpcTryExcept
292 {
293 Status = LsarCreateTrustedDomain((LSAPR_HANDLE)PolicyHandle,
294 (PLSAPR_TRUST_INFORMATION)TrustedDomainInformation,
295 DesiredAccess,
296 (PLSAPR_HANDLE)TrustedDomainHandle);
297 }
298 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
299 {
300 Status = I_RpcMapWin32Status(RpcExceptionCode());
301 }
302 RpcEndExcept;
303
304 return Status;
305 }
306
307
308 /*
309 * @unimplemented
310 */
311 NTSTATUS
312 WINAPI
313 LsaCreateTrustedDomainEx(IN LSA_HANDLE PolicyHandle,
314 IN PTRUSTED_DOMAIN_INFORMATION_EX TrustedDomainInformation,
315 IN PTRUSTED_DOMAIN_AUTH_INFORMATION AuthenticationInformation,
316 IN ACCESS_MASK DesiredAccess,
317 OUT PLSA_HANDLE TrustedDomainHandle)
318 {
319 PLSAPR_TRUSTED_DOMAIN_AUTH_INFORMATION_INTERNAL EncryptedAuthInfo = NULL;
320 NTSTATUS Status;
321
322 TRACE("LsaCreateTrustedDomainEx(%p %p %p 0x%08lx %p) stub\n",
323 PolicyHandle, TrustedDomainInformation, AuthenticationInformation,
324 DesiredAccess, TrustedDomainHandle);
325
326 RpcTryExcept
327 {
328 /* FIXME: Encrypt AuthenticationInformation */
329
330 Status = LsarCreateTrustedDomainEx2((LSAPR_HANDLE)PolicyHandle,
331 (PLSAPR_TRUSTED_DOMAIN_INFORMATION_EX)TrustedDomainInformation,
332 EncryptedAuthInfo,
333 DesiredAccess,
334 (PLSAPR_HANDLE)TrustedDomainHandle);
335 }
336 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
337 {
338 Status = I_RpcMapWin32Status(RpcExceptionCode());
339 }
340 RpcEndExcept;
341
342 return Status;
343 }
344
345
346 /*
347 * @implemented
348 */
349 NTSTATUS
350 WINAPI
351 LsaDelete(IN LSA_HANDLE ObjectHandle)
352 {
353 NTSTATUS Status;
354
355 TRACE("LsaDelete(%p)\n", ObjectHandle);
356
357 RpcTryExcept
358 {
359 Status = LsarDelete((LSAPR_HANDLE)ObjectHandle);
360 }
361 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
362 {
363 Status = I_RpcMapWin32Status(RpcExceptionCode());
364 }
365 RpcEndExcept;
366
367 return Status;
368 }
369
370
371 /*
372 * @implemented
373 */
374 NTSTATUS
375 WINAPI
376 LsaDeleteTrustedDomain(IN LSA_HANDLE PolicyHandle,
377 IN PSID TrustedDomainSid)
378 {
379 NTSTATUS Status;
380
381 TRACE("LsaDeleteTrustedDomain(%p %p)\n",
382 PolicyHandle, TrustedDomainSid);
383
384 RpcTryExcept
385 {
386 Status = LsarDeleteTrustedDomain((LSAPR_HANDLE)PolicyHandle,
387 TrustedDomainSid);
388 }
389 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
390 {
391 Status = I_RpcMapWin32Status(RpcExceptionCode());
392 }
393 RpcEndExcept;
394
395 return Status;
396 }
397
398
399 /*
400 * @implemented
401 */
402 NTSTATUS
403 WINAPI
404 LsaEnumerateAccountRights(IN LSA_HANDLE PolicyHandle,
405 IN PSID AccountSid,
406 OUT PLSA_UNICODE_STRING *UserRights,
407 OUT PULONG CountOfRights)
408 {
409 LSAPR_USER_RIGHT_SET UserRightsSet;
410 NTSTATUS Status;
411
412 TRACE("LsaEnumerateAccountRights(%p %p %p %p)\n",
413 PolicyHandle, AccountSid, UserRights, CountOfRights);
414
415 UserRightsSet.Entries = 0;
416 UserRightsSet.UserRights = NULL;
417
418 RpcTryExcept
419 {
420 Status = LsarEnmuerateAccountRights((LSAPR_HANDLE)PolicyHandle,
421 AccountSid,
422 &UserRightsSet);
423
424 *UserRights = (PUNICODE_STRING)UserRightsSet.UserRights;
425 *CountOfRights = UserRightsSet.Entries;
426 }
427 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
428 {
429 Status = I_RpcMapWin32Status(RpcExceptionCode());
430
431 if (UserRightsSet.UserRights != NULL)
432 MIDL_user_free(UserRightsSet.UserRights);
433 }
434 RpcEndExcept;
435
436 return Status;
437 }
438
439
440 /*
441 * @implemented
442 */
443 NTSTATUS
444 WINAPI
445 LsaEnumerateAccounts(IN LSA_HANDLE PolicyHandle,
446 IN OUT PLSA_ENUMERATION_HANDLE EnumerationContext,
447 OUT PVOID *Buffer,
448 IN ULONG PreferedMaximumLength,
449 OUT PULONG CountReturned)
450 {
451 LSAPR_ACCOUNT_ENUM_BUFFER AccountEnumBuffer;
452 NTSTATUS Status;
453
454 TRACE("LsaEnumerateAccounts(%p %p %p %lu %p)\n",
455 PolicyHandle, EnumerationContext, Buffer,
456 PreferedMaximumLength, CountReturned);
457
458 AccountEnumBuffer.EntriesRead = 0;
459 AccountEnumBuffer.Information = NULL;
460
461 RpcTryExcept
462 {
463 Status = LsarEnumerateAccounts((LSAPR_HANDLE)PolicyHandle,
464 EnumerationContext,
465 &AccountEnumBuffer,
466 PreferedMaximumLength);
467
468 *Buffer = AccountEnumBuffer.Information;
469 *CountReturned = AccountEnumBuffer.EntriesRead;
470 }
471 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
472 {
473 if (AccountEnumBuffer.Information != NULL)
474 MIDL_user_free(AccountEnumBuffer.Information);
475
476 Status = I_RpcMapWin32Status(RpcExceptionCode());
477 }
478 RpcEndExcept;
479
480 return Status;
481 }
482
483
484 /*
485 * @implemented
486 */
487 NTSTATUS
488 WINAPI
489 LsaEnumerateAccountsWithUserRight(IN LSA_HANDLE PolicyHandle,
490 IN PLSA_UNICODE_STRING UserRight OPTIONAL,
491 OUT PVOID *Buffer,
492 OUT PULONG CountReturned)
493 {
494 LSAPR_ACCOUNT_ENUM_BUFFER AccountEnumBuffer;
495 NTSTATUS Status;
496
497 TRACE("LsaEnumerateAccountsWithUserRight(%p %p %p %p) stub\n",
498 PolicyHandle, UserRight, Buffer, CountReturned);
499
500 AccountEnumBuffer.EntriesRead = 0;
501 AccountEnumBuffer.Information = NULL;
502
503 RpcTryExcept
504 {
505 Status = LsarEnumerateAccountsWithUserRight((LSAPR_HANDLE)PolicyHandle,
506 (PRPC_UNICODE_STRING)UserRight,
507 &AccountEnumBuffer);
508
509 *Buffer = AccountEnumBuffer.Information;
510 *CountReturned = AccountEnumBuffer.EntriesRead;
511 }
512 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
513 {
514 if (AccountEnumBuffer.Information != NULL)
515 MIDL_user_free(AccountEnumBuffer.Information);
516
517 Status = I_RpcMapWin32Status(RpcExceptionCode());
518 }
519 RpcEndExcept;
520
521 return Status;
522 }
523
524
525 /*
526 * @implemented
527 */
528 NTSTATUS
529 WINAPI
530 LsaEnumeratePrivileges(IN LSA_HANDLE PolicyHandle,
531 IN OUT PLSA_ENUMERATION_HANDLE EnumerationContext,
532 OUT PVOID *Buffer,
533 IN ULONG PreferedMaximumLength,
534 OUT PULONG CountReturned)
535 {
536 LSAPR_PRIVILEGE_ENUM_BUFFER PrivilegeEnumBuffer;
537 NTSTATUS Status;
538
539 TRACE("LsaEnumeratePrivileges(%p %p %p %lu %p)\n",
540 PolicyHandle, EnumerationContext, Buffer,
541 PreferedMaximumLength, CountReturned);
542
543 PrivilegeEnumBuffer.Entries = 0;
544 PrivilegeEnumBuffer.Privileges = NULL;
545
546 RpcTryExcept
547 {
548 Status = LsarEnumeratePrivileges((LSAPR_HANDLE)PolicyHandle,
549 EnumerationContext,
550 &PrivilegeEnumBuffer,
551 PreferedMaximumLength);
552
553 *Buffer = PrivilegeEnumBuffer.Privileges;
554 *CountReturned = PrivilegeEnumBuffer.Entries;
555
556 }
557 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
558 {
559 if (PrivilegeEnumBuffer.Privileges != NULL)
560 MIDL_user_free(PrivilegeEnumBuffer.Privileges);
561
562 Status = I_RpcMapWin32Status(RpcExceptionCode());
563 }
564 RpcEndExcept;
565
566 return Status;
567 }
568
569
570 /*
571 * @implemented
572 */
573 NTSTATUS
574 WINAPI
575 LsaEnumeratePrivilegesOfAccount(IN LSA_HANDLE AccountHandle,
576 OUT PPRIVILEGE_SET *Privileges)
577 {
578 NTSTATUS Status;
579
580 TRACE("LsaEnumeratePrivilegesOfAccount(%p %p)\n",
581 AccountHandle, Privileges);
582
583 RpcTryExcept
584 {
585 Status = LsarEnumeratePrivilegesAccount((LSAPR_HANDLE)AccountHandle,
586 (LSAPR_PRIVILEGE_SET **)Privileges);
587 }
588 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
589 {
590 Status = I_RpcMapWin32Status(RpcExceptionCode());
591 }
592 RpcEndExcept;
593
594 return Status;
595 }
596
597
598 /*
599 * @unimplemented
600 */
601 NTSTATUS
602 WINAPI
603 LsaEnumerateTrustedDomains(IN LSA_HANDLE PolicyHandle,
604 IN OUT PLSA_ENUMERATION_HANDLE EnumerationContext,
605 OUT PVOID *Buffer,
606 IN ULONG PreferedMaximumLength,
607 OUT PULONG CountReturned)
608 {
609 FIXME("LsaEnumerateTrustedDomains(%p %p %p %lu %p) stub\n",
610 PolicyHandle, EnumerationContext, Buffer,
611 PreferedMaximumLength, CountReturned);
612
613 if (CountReturned)
614 *CountReturned = 0;
615
616 return STATUS_SUCCESS;
617 }
618
619
620 /*
621 * @unimplemented
622 */
623 NTSTATUS
624 WINAPI
625 LsaEnumerateTrustedDomainsEx(IN LSA_HANDLE PolicyHandle,
626 IN OUT PLSA_ENUMERATION_HANDLE EnumerationContext,
627 OUT PVOID *Buffer,
628 IN ULONG PreferedMaximumLength,
629 OUT PULONG CountReturned)
630 {
631 FIXME("LsaEnumerateTrustedDomainsEx(%p %p %p %lu %p) stub\n",
632 PolicyHandle, EnumerationContext, Buffer,
633 PreferedMaximumLength, CountReturned);
634
635 if (CountReturned)
636 *CountReturned = 0;
637
638 return STATUS_SUCCESS;
639 }
640
641
642 /*
643 * @implemented
644 */
645 NTSTATUS
646 WINAPI
647 LsaFreeMemory(IN PVOID Buffer)
648 {
649 TRACE("LsaFreeMemory(%p)\n", Buffer);
650 return RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
651 }
652
653
654 /*
655 * @implemented
656 */
657 NTSTATUS
658 WINAPI
659 LsaGetQuotasForAccount(IN LSA_HANDLE AccountHandle,
660 OUT PQUOTA_LIMITS QuotaLimits)
661 {
662 NTSTATUS Status;
663
664 TRACE("LsaGetQuotasForAccount(%p %p)\n",
665 AccountHandle, QuotaLimits);
666
667 RpcTryExcept
668 {
669 Status = LsarGetQuotasForAccount((LSAPR_HANDLE)AccountHandle,
670 QuotaLimits);
671 }
672 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
673 {
674 Status = I_RpcMapWin32Status(RpcExceptionCode());
675 }
676 RpcEndExcept;
677
678 return Status;
679 }
680
681
682 /*
683 * @unimplemented
684 */
685 NTSTATUS
686 WINAPI
687 LsaGetRemoteUserName(IN PLSA_UNICODE_STRING SystemName OPTIONAL,
688 OUT PLSA_UNICODE_STRING *UserName,
689 OUT PLSA_UNICODE_STRING *DomainName OPTIONAL)
690 {
691 PRPC_UNICODE_STRING UserNameString = NULL;
692 PRPC_UNICODE_STRING DomainNameString = NULL;
693 NTSTATUS Status;
694
695 TRACE("LsaGetRemoteUserName(%s %p %p)\n",
696 SystemName ? debugstr_w(SystemName->Buffer) : "(null)",
697 UserName, DomainName);
698
699 RpcTryExcept
700 {
701 Status = LsarGetUserName((PLSAPR_SERVER_NAME)SystemName,
702 &UserNameString,
703 (DomainName != NULL) ? &DomainNameString : NULL);
704
705 *UserName = (PLSA_UNICODE_STRING)UserNameString;
706
707 if (DomainName != NULL)
708 *DomainName = (PLSA_UNICODE_STRING)DomainNameString;
709 }
710 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
711 {
712 if (UserNameString != NULL)
713 MIDL_user_free(UserNameString);
714
715 if (DomainNameString != NULL)
716 MIDL_user_free(DomainNameString);
717
718 Status = I_RpcMapWin32Status(RpcExceptionCode());
719 }
720 RpcEndExcept;
721
722 return Status;
723 }
724
725
726 /*
727 * @implemented
728 */
729 NTSTATUS
730 WINAPI
731 LsaGetSystemAccessAccount(IN LSA_HANDLE AccountHandle,
732 OUT PULONG SystemAccess)
733 {
734 NTSTATUS Status;
735
736 TRACE("LsaGetSystemAccessAccount(%p %p)\n",
737 AccountHandle, SystemAccess);
738
739 RpcTryExcept
740 {
741 Status = LsarGetSystemAccessAccount((LSAPR_HANDLE)AccountHandle,
742 (ACCESS_MASK *)SystemAccess);
743 }
744 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
745 {
746 Status = I_RpcMapWin32Status(RpcExceptionCode());
747 }
748 RpcEndExcept;
749
750 return Status;
751 }
752
753
754 /*
755 * @implemented
756 */
757 NTSTATUS
758 WINAPI
759 LsaGetUserName(OUT PUNICODE_STRING *UserName,
760 OUT PUNICODE_STRING *DomainName OPTIONAL)
761 {
762 PRPC_UNICODE_STRING UserNameString = NULL;
763 PRPC_UNICODE_STRING DomainNameString = NULL;
764 NTSTATUS Status;
765
766 TRACE("LsaGetUserName(%p %p)\n",
767 UserName, DomainName);
768
769 RpcTryExcept
770 {
771 Status = LsarGetUserName(NULL,
772 &UserNameString,
773 (DomainName != NULL) ? &DomainNameString : NULL);
774
775 *UserName = (PUNICODE_STRING)UserNameString;
776
777 if (DomainName != NULL)
778 *DomainName = (PUNICODE_STRING)DomainNameString;
779 }
780 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
781 {
782 if (UserNameString != NULL)
783 MIDL_user_free(UserNameString);
784
785 if (DomainNameString != NULL)
786 MIDL_user_free(DomainNameString);
787
788 Status = I_RpcMapWin32Status(RpcExceptionCode());
789 }
790 RpcEndExcept;
791
792 return Status;
793 }
794
795
796 /*
797 * @implemented
798 */
799 NTSTATUS
800 WINAPI
801 LsaLookupNames(IN LSA_HANDLE PolicyHandle,
802 IN ULONG Count,
803 IN PLSA_UNICODE_STRING Names,
804 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
805 OUT PLSA_TRANSLATED_SID *Sids)
806 {
807 LSAPR_TRANSLATED_SIDS TranslatedSids = {0, NULL};
808 ULONG MappedCount = 0;
809 NTSTATUS Status;
810
811 TRACE("LsaLookupNames(%p %lu %p %p %p)\n",
812 PolicyHandle, Count, Names, ReferencedDomains, Sids);
813
814 if (ReferencedDomains == NULL || Sids == NULL)
815 return STATUS_INVALID_PARAMETER;
816
817 RpcTryExcept
818 {
819 *ReferencedDomains = NULL;
820 *Sids = NULL;
821
822 TranslatedSids.Entries = Count;
823
824 Status = LsarLookupNames((LSAPR_HANDLE)PolicyHandle,
825 Count,
826 (PRPC_UNICODE_STRING)Names,
827 (PLSAPR_REFERENCED_DOMAIN_LIST *)ReferencedDomains,
828 &TranslatedSids,
829 LsapLookupWksta,
830 &MappedCount);
831
832 *Sids = (PLSA_TRANSLATED_SID)TranslatedSids.Sids;
833 }
834 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
835 {
836 if (TranslatedSids.Sids != NULL)
837 MIDL_user_free(TranslatedSids.Sids);
838
839 Status = I_RpcMapWin32Status(RpcExceptionCode());
840 }
841 RpcEndExcept;
842
843 return Status;
844 }
845
846
847 /*
848 * @implemented
849 */
850 NTSTATUS
851 WINAPI
852 LsaLookupNames2(IN LSA_HANDLE PolicyHandle,
853 IN ULONG Flags,
854 IN ULONG Count,
855 IN PLSA_UNICODE_STRING Names,
856 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
857 OUT PLSA_TRANSLATED_SID2 *Sids)
858 {
859 LSAPR_TRANSLATED_SIDS_EX2 TranslatedSids = {0, NULL};
860 ULONG MappedCount = 0;
861 NTSTATUS Status;
862
863 TRACE("LsaLookupNames2(%p 0x%08x %lu %p %p %p)\n",
864 PolicyHandle, Flags, Count, Names, ReferencedDomains, Sids);
865
866 if (ReferencedDomains == NULL || Sids == NULL)
867 return STATUS_INVALID_PARAMETER;
868
869 RpcTryExcept
870 {
871 *ReferencedDomains = NULL;
872 *Sids = NULL;
873
874 TranslatedSids.Entries = Count;
875
876 Status = LsarLookupNames3((LSAPR_HANDLE)PolicyHandle,
877 Count,
878 (PRPC_UNICODE_STRING)Names,
879 (PLSAPR_REFERENCED_DOMAIN_LIST *)ReferencedDomains,
880 &TranslatedSids,
881 LsapLookupWksta,
882 &MappedCount,
883 Flags,
884 2);
885
886 *Sids = (PLSA_TRANSLATED_SID2)TranslatedSids.Sids;
887 }
888 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
889 {
890 if (TranslatedSids.Sids != NULL)
891 MIDL_user_free(TranslatedSids.Sids);
892
893 Status = I_RpcMapWin32Status(RpcExceptionCode());
894 }
895 RpcEndExcept;
896
897 return Status;
898 }
899
900
901 /*
902 * @unimplemented
903 */
904 NTSTATUS
905 WINAPI
906 LsaLookupPrivilegeDisplayName(IN LSA_HANDLE PolicyHandle,
907 IN PLSA_UNICODE_STRING Name,
908 OUT PLSA_UNICODE_STRING *DisplayName,
909 OUT PSHORT LanguageReturned)
910 {
911 FIXME("LsaLookupPrivilegeDisplayName(%p %p %p %p)\n",
912 PolicyHandle, Name, DisplayName, LanguageReturned);
913 return STATUS_NOT_IMPLEMENTED;
914 }
915
916
917 /*
918 * @implemented
919 */
920 NTSTATUS
921 WINAPI
922 LsaLookupPrivilegeName(IN LSA_HANDLE PolicyHandle,
923 IN PLUID Value,
924 OUT PUNICODE_STRING *Name)
925 {
926 PRPC_UNICODE_STRING NameBuffer = NULL;
927 NTSTATUS Status;
928
929 TRACE("LsaLookupPrivilegeName(%p %p %p)\n",
930 PolicyHandle, Value, Name);
931
932 RpcTryExcept
933 {
934 Status = LsarLookupPrivilegeName(PolicyHandle,
935 Value,
936 &NameBuffer);
937
938 *Name = (PUNICODE_STRING)NameBuffer;
939 }
940 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
941 {
942 if (NameBuffer != NULL)
943 MIDL_user_free(NameBuffer);
944
945 Status = I_RpcMapWin32Status(RpcExceptionCode());
946 }
947 RpcEndExcept;
948
949 return Status;
950 }
951
952
953 /*
954 * @implemented
955 */
956 NTSTATUS
957 WINAPI
958 LsaLookupPrivilegeValue(IN LSA_HANDLE PolicyHandle,
959 IN PLSA_UNICODE_STRING Name,
960 OUT PLUID Value)
961 {
962 LUID Luid;
963 NTSTATUS Status;
964
965 TRACE("LsaLookupPrivilegeValue(%p %p %p)\n",
966 PolicyHandle, Name, Value);
967
968 RpcTryExcept
969 {
970 Status = LsarLookupPrivilegeValue(PolicyHandle,
971 (PRPC_UNICODE_STRING)Name,
972 &Luid);
973 if (Status == STATUS_SUCCESS)
974 *Value = Luid;
975 }
976 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
977 {
978 Status = I_RpcMapWin32Status(RpcExceptionCode());
979 }
980 RpcEndExcept;
981
982 return Status;
983 }
984
985
986 /*
987 * @implemented
988 */
989 NTSTATUS
990 WINAPI
991 LsaLookupSids(IN LSA_HANDLE PolicyHandle,
992 IN ULONG Count,
993 IN PSID *Sids,
994 OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains,
995 OUT PLSA_TRANSLATED_NAME *Names)
996 {
997 LSAPR_SID_ENUM_BUFFER SidEnumBuffer;
998 LSAPR_TRANSLATED_NAMES TranslatedNames;
999 ULONG MappedCount = 0;
1000 NTSTATUS Status;
1001
1002 TRACE("LsaLookupSids(%p %lu %p %p %p)\n",
1003 PolicyHandle, Count, Sids, ReferencedDomains, Names);
1004
1005 if (Count == 0)
1006 return STATUS_INVALID_PARAMETER;
1007
1008 SidEnumBuffer.Entries = Count;
1009 SidEnumBuffer.SidInfo = (PLSAPR_SID_INFORMATION)Sids;
1010
1011 RpcTryExcept
1012 {
1013 *ReferencedDomains = NULL;
1014 *Names = NULL;
1015
1016 TranslatedNames.Entries = 0;
1017 TranslatedNames.Names = NULL;
1018
1019 Status = LsarLookupSids((LSAPR_HANDLE)PolicyHandle,
1020 &SidEnumBuffer,
1021 (PLSAPR_REFERENCED_DOMAIN_LIST *)ReferencedDomains,
1022 &TranslatedNames,
1023 LsapLookupWksta,
1024 &MappedCount);
1025
1026 *Names = (PLSA_TRANSLATED_NAME)TranslatedNames.Names;
1027 }
1028 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1029 {
1030 if (TranslatedNames.Names != NULL)
1031 {
1032 MIDL_user_free(TranslatedNames.Names);
1033 }
1034
1035 Status = I_RpcMapWin32Status(RpcExceptionCode());
1036 }
1037 RpcEndExcept;
1038
1039 return Status;
1040 }
1041
1042
1043 /******************************************************************************
1044 * LsaNtStatusToWinError
1045 *
1046 * PARAMS
1047 * Status [I]
1048 *
1049 * @implemented
1050 */
1051 ULONG
1052 WINAPI
1053 LsaNtStatusToWinError(IN NTSTATUS Status)
1054 {
1055 TRACE("LsaNtStatusToWinError(0x%lx)\n", Status);
1056 return RtlNtStatusToDosError(Status);
1057 }
1058
1059
1060 /*
1061 * @implemented
1062 */
1063 NTSTATUS
1064 WINAPI
1065 LsaOpenAccount(IN LSA_HANDLE PolicyHandle,
1066 IN PSID AccountSid,
1067 IN ACCESS_MASK DesiredAccess,
1068 OUT PLSA_HANDLE AccountHandle)
1069 {
1070 NTSTATUS Status;
1071
1072 TRACE("LsaOpenAccount(%p %p 0x%08lx %p)\n",
1073 PolicyHandle, AccountSid, DesiredAccess, AccountHandle);
1074
1075 RpcTryExcept
1076 {
1077 Status = LsarOpenAccount((LSAPR_HANDLE)PolicyHandle,
1078 AccountSid,
1079 DesiredAccess,
1080 AccountHandle);
1081 }
1082 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1083 {
1084 Status = I_RpcMapWin32Status(RpcExceptionCode());
1085 }
1086 RpcEndExcept;
1087
1088 return Status;
1089 }
1090
1091
1092 /******************************************************************************
1093 * LsaOpenPolicy
1094 *
1095 * PARAMS
1096 * x1 []
1097 * x2 []
1098 * x3 []
1099 * x4 []
1100 *
1101 * @implemented
1102 */
1103 NTSTATUS
1104 WINAPI
1105 LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL,
1106 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1107 IN ACCESS_MASK DesiredAccess,
1108 OUT PLSA_HANDLE PolicyHandle)
1109 {
1110 NTSTATUS Status;
1111
1112 TRACE("LsaOpenPolicy(%s %p 0x%08lx %p)\n",
1113 SystemName ? debugstr_w(SystemName->Buffer) : "(null)",
1114 ObjectAttributes, DesiredAccess, PolicyHandle);
1115
1116 /* FIXME: RPC should take care of this */
1117 if (!LsapIsLocalComputer(SystemName))
1118 return RPC_NT_SERVER_UNAVAILABLE;
1119
1120 RpcTryExcept
1121 {
1122 *PolicyHandle = NULL;
1123
1124 Status = LsarOpenPolicy(SystemName ? SystemName->Buffer : NULL,
1125 (PLSAPR_OBJECT_ATTRIBUTES)ObjectAttributes,
1126 DesiredAccess,
1127 PolicyHandle);
1128 }
1129 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1130 {
1131 Status = I_RpcMapWin32Status(RpcExceptionCode());
1132 }
1133 RpcEndExcept;
1134
1135 TRACE("LsaOpenPolicy() done (Status: 0x%08lx)\n", Status);
1136
1137 return Status;
1138 }
1139
1140
1141 /*
1142 * @unimplemented
1143 */
1144 NTSTATUS
1145 WINAPI
1146 LsaOpenPolicySce(IN PLSA_UNICODE_STRING SystemName OPTIONAL,
1147 IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes,
1148 IN ACCESS_MASK DesiredAccess,
1149 OUT PLSA_HANDLE PolicyHandle)
1150 {
1151 FIXME("LsaOpenPolicySce(%s %p 0x%08lx %p)\n",
1152 SystemName ? debugstr_w(SystemName->Buffer) : "(null)",
1153 ObjectAttributes, DesiredAccess, PolicyHandle);
1154 return STATUS_NOT_IMPLEMENTED;
1155 }
1156
1157
1158 /*
1159 * @implemented
1160 */
1161 NTSTATUS
1162 WINAPI
1163 LsaOpenSecret(IN LSA_HANDLE PolicyHandle,
1164 IN PLSA_UNICODE_STRING SecretName,
1165 IN ACCESS_MASK DesiredAccess,
1166 OUT PLSA_HANDLE SecretHandle)
1167 {
1168 NTSTATUS Status;
1169
1170 TRACE("LsaOpenSecret(%p %p 0x%08lx %p)\n",
1171 PolicyHandle, SecretName, DesiredAccess, SecretHandle);
1172
1173 RpcTryExcept
1174 {
1175 *SecretHandle = NULL;
1176
1177 Status = LsarOpenSecret((LSAPR_HANDLE)PolicyHandle,
1178 (PRPC_UNICODE_STRING)SecretName,
1179 DesiredAccess,
1180 SecretHandle);
1181 }
1182 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1183 {
1184 Status = I_RpcMapWin32Status(RpcExceptionCode());
1185 }
1186 RpcEndExcept;
1187
1188 TRACE("LsaOpenSecret() done (Status: 0x%08lx)\n", Status);
1189
1190 return Status;
1191 }
1192
1193
1194 /*
1195 * @implemented
1196 */
1197 NTSTATUS
1198 WINAPI
1199 LsaOpenTrustedDomain(IN LSA_HANDLE PolicyHandle,
1200 IN PSID TrustedDomainSid,
1201 IN ACCESS_MASK DesiredAccess,
1202 OUT PLSA_HANDLE TrustedDomainHandle)
1203 {
1204 NTSTATUS Status;
1205
1206 TRACE("LsaOpenTrustedDomain(%p %p 0x%08lx %p)\n",
1207 PolicyHandle, TrustedDomainSid, DesiredAccess, TrustedDomainHandle);
1208
1209 RpcTryExcept
1210 {
1211 Status = LsarOpenTrustedDomain((LSAPR_HANDLE)PolicyHandle,
1212 (PRPC_SID)TrustedDomainSid,
1213 DesiredAccess,
1214 (PLSAPR_HANDLE)TrustedDomainHandle);
1215 }
1216 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1217 {
1218 Status = I_RpcMapWin32Status(RpcExceptionCode());
1219 }
1220 RpcEndExcept;
1221
1222 return Status;
1223 }
1224
1225
1226 /*
1227 * @implemented
1228 */
1229 NTSTATUS
1230 WINAPI
1231 LsaOpenTrustedDomainByName(IN LSA_HANDLE PolicyHandle,
1232 IN PLSA_UNICODE_STRING TrustedDomainName,
1233 IN ACCESS_MASK DesiredAccess,
1234 OUT PLSA_HANDLE TrustedDomainHandle)
1235 {
1236 NTSTATUS Status;
1237
1238 TRACE("LsaOpenTrustedDomainByName(%p %p 0x%08lx %p)\n",
1239 PolicyHandle, TrustedDomainName, DesiredAccess, TrustedDomainHandle);
1240
1241 RpcTryExcept
1242 {
1243 Status = LsarOpenTrustedDomainByName((LSAPR_HANDLE)PolicyHandle,
1244 (PRPC_UNICODE_STRING)TrustedDomainName,
1245 DesiredAccess,
1246 TrustedDomainHandle);
1247 }
1248 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1249 {
1250 Status = I_RpcMapWin32Status(RpcExceptionCode());
1251 }
1252 RpcEndExcept;
1253
1254 return Status;
1255 }
1256
1257
1258 /*
1259 * @implemented
1260 */
1261 NTSTATUS
1262 WINAPI
1263 LsaQueryDomainInformationPolicy(IN LSA_HANDLE PolicyHandle,
1264 IN POLICY_DOMAIN_INFORMATION_CLASS InformationClass,
1265 OUT PVOID *Buffer)
1266 {
1267 PLSAPR_POLICY_DOMAIN_INFORMATION PolicyInformation = NULL;
1268 NTSTATUS Status;
1269
1270 TRACE("LsaQueryDomainInformationPolicy(%p %lu %p)\n",
1271 PolicyHandle, InformationClass, Buffer);
1272
1273 RpcTryExcept
1274 {
1275 Status = LsarQueryDomainInformationPolicy((LSAPR_HANDLE)PolicyHandle,
1276 InformationClass,
1277 &PolicyInformation);
1278
1279 *Buffer = PolicyInformation;
1280 }
1281 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1282 {
1283 if (PolicyInformation != NULL)
1284 MIDL_user_free(PolicyInformation);
1285
1286 Status = I_RpcMapWin32Status(RpcExceptionCode());
1287 }
1288 RpcEndExcept;
1289
1290 return Status;
1291 }
1292
1293
1294 /*
1295 * @unimplemented
1296 */
1297 NTSTATUS
1298 WINAPI
1299 LsaQueryForestTrustInformation(IN LSA_HANDLE PolicyHandle,
1300 IN PLSA_UNICODE_STRING TrustedDomainName,
1301 OUT PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
1302 {
1303 FIXME("LsaQueryForestTrustInformation(%p %p %p) stub\n",
1304 PolicyHandle, TrustedDomainName, ForestTrustInfo);
1305 return STATUS_NOT_IMPLEMENTED;
1306 }
1307
1308
1309 /*
1310 * @unimplemented
1311 */
1312 NTSTATUS
1313 WINAPI
1314 LsaQueryInfoTrustedDomain(IN LSA_HANDLE TrustedDomainHandle,
1315 IN TRUSTED_INFORMATION_CLASS InformationClass,
1316 OUT PVOID *Buffer)
1317 {
1318 FIXME("LsaQueryInfoTrustedDomain(%p %d %p) stub\n",
1319 TrustedDomainHandle, InformationClass, Buffer);
1320 return STATUS_NOT_IMPLEMENTED;
1321 }
1322
1323
1324 /*
1325 * @implemented
1326 */
1327 NTSTATUS
1328 WINAPI
1329 LsaQueryInformationPolicy(IN LSA_HANDLE PolicyHandle,
1330 IN POLICY_INFORMATION_CLASS InformationClass,
1331 OUT PVOID *Buffer)
1332 {
1333 PLSAPR_POLICY_INFORMATION PolicyInformation = NULL;
1334 NTSTATUS Status;
1335
1336 TRACE("LsaQueryInformationPolicy(%p %d %p)\n",
1337 PolicyHandle, InformationClass, Buffer);
1338
1339 RpcTryExcept
1340 {
1341 Status = LsarQueryInformationPolicy((LSAPR_HANDLE)PolicyHandle,
1342 InformationClass,
1343 &PolicyInformation);
1344 *Buffer = PolicyInformation;
1345 }
1346 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1347 {
1348 if (PolicyInformation != NULL)
1349 MIDL_user_free(PolicyInformation);
1350
1351 Status = I_RpcMapWin32Status(RpcExceptionCode());
1352 }
1353 RpcEndExcept;
1354
1355 TRACE("Done (Status: 0x%08x)\n", Status);
1356
1357 return Status;
1358 }
1359
1360
1361 /*
1362 * @unimplemented
1363 */
1364 NTSTATUS
1365 WINAPI
1366 LsaQuerySecret(IN LSA_HANDLE SecretHandle,
1367 OUT PLSA_UNICODE_STRING *CurrentValue OPTIONAL,
1368 OUT PLARGE_INTEGER CurrentValueSetTime OPTIONAL,
1369 OUT PLSA_UNICODE_STRING *OldValue OPTIONAL,
1370 OUT PLARGE_INTEGER OldValueSetTime OPTIONAL)
1371 {
1372 PLSAPR_CR_CIPHER_VALUE EncryptedCurrentValue = NULL;
1373 PLSAPR_CR_CIPHER_VALUE EncryptedOldValue = NULL;
1374 PLSA_UNICODE_STRING DecryptedCurrentValue = NULL;
1375 PLSA_UNICODE_STRING DecryptedOldValue = NULL;
1376 SIZE_T BufferSize;
1377 NTSTATUS Status;
1378
1379 TRACE("LsaQuerySecret(%p %p %p %p %p)\n",
1380 SecretHandle, CurrentValue, CurrentValueSetTime,
1381 OldValue, OldValueSetTime);
1382
1383 RpcTryExcept
1384 {
1385 Status = LsarQuerySecret((PLSAPR_HANDLE)SecretHandle,
1386 &EncryptedCurrentValue,
1387 CurrentValueSetTime,
1388 &EncryptedOldValue,
1389 OldValueSetTime);
1390 }
1391 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1392 {
1393 Status = I_RpcMapWin32Status(RpcExceptionCode());
1394 }
1395 RpcEndExcept;
1396
1397 if (!NT_SUCCESS(Status))
1398 goto done;
1399
1400 /* Decrypt the current value */
1401 if (CurrentValue != NULL)
1402 {
1403 if (EncryptedCurrentValue == NULL)
1404 {
1405 *CurrentValue = NULL;
1406 }
1407 else
1408 {
1409 /* FIXME: Decrypt the current value */
1410 BufferSize = sizeof(LSA_UNICODE_STRING) + EncryptedCurrentValue->MaximumLength;
1411 DecryptedCurrentValue = midl_user_allocate(BufferSize);
1412 if (DecryptedCurrentValue == NULL)
1413 {
1414 Status = STATUS_INSUFFICIENT_RESOURCES;
1415 goto done;
1416 }
1417
1418 DecryptedCurrentValue->Length = (USHORT)EncryptedCurrentValue->Length;
1419 DecryptedCurrentValue->MaximumLength = (USHORT)EncryptedCurrentValue->MaximumLength;
1420 DecryptedCurrentValue->Buffer = (PWSTR)(DecryptedCurrentValue + 1);
1421 RtlCopyMemory(DecryptedCurrentValue->Buffer,
1422 EncryptedCurrentValue->Buffer,
1423 EncryptedCurrentValue->Length);
1424
1425 *CurrentValue = DecryptedCurrentValue;
1426 }
1427 }
1428
1429 /* Decrypt the old value */
1430 if (OldValue != NULL)
1431 {
1432 if (EncryptedOldValue == NULL)
1433 {
1434 *OldValue = NULL;
1435 }
1436 else
1437 {
1438 /* FIXME: Decrypt the old value */
1439 BufferSize = sizeof(LSA_UNICODE_STRING) + EncryptedOldValue->MaximumLength;
1440 DecryptedOldValue = midl_user_allocate(BufferSize);
1441 if (DecryptedOldValue == NULL)
1442 {
1443 Status = STATUS_INSUFFICIENT_RESOURCES;
1444 goto done;
1445 }
1446
1447 DecryptedOldValue->Length = (USHORT)EncryptedOldValue->Length;
1448 DecryptedOldValue->MaximumLength = (USHORT)EncryptedOldValue->MaximumLength;
1449 DecryptedOldValue->Buffer = (PWSTR)(DecryptedOldValue + 1);
1450 RtlCopyMemory(DecryptedOldValue->Buffer,
1451 EncryptedOldValue->Buffer,
1452 EncryptedOldValue->Length);
1453
1454 *OldValue = DecryptedOldValue;
1455 }
1456 }
1457
1458 done:
1459 if (!NT_SUCCESS(Status))
1460 {
1461 if (DecryptedCurrentValue != NULL)
1462 midl_user_free(DecryptedCurrentValue);
1463
1464 if (DecryptedOldValue != NULL)
1465 midl_user_free(DecryptedOldValue);
1466
1467 if (CurrentValue != NULL)
1468 *CurrentValue = NULL;
1469
1470 if (OldValue != NULL)
1471 *OldValue = NULL;
1472 }
1473
1474 if (EncryptedCurrentValue != NULL)
1475 midl_user_free(EncryptedCurrentValue);
1476
1477 if (EncryptedOldValue != NULL)
1478 midl_user_free(EncryptedOldValue);
1479
1480 return Status;
1481 }
1482
1483
1484 /*
1485 * @implemented
1486 */
1487 NTSTATUS
1488 WINAPI
1489 LsaQuerySecurityObject(IN LSA_HANDLE ObjectHandle,
1490 IN SECURITY_INFORMATION SecurityInformation,
1491 OUT PSECURITY_DESCRIPTOR *SecurityDescriptor)
1492 {
1493 LSAPR_SR_SECURITY_DESCRIPTOR SdBuffer;
1494 PLSAPR_SR_SECURITY_DESCRIPTOR SdPointer;
1495 NTSTATUS Status;
1496
1497 TRACE("LsaQuerySecurityObject(%p %lx %p)\n",
1498 ObjectHandle, SecurityInformation, SecurityDescriptor);
1499
1500 SdBuffer.Length = 0;
1501 SdBuffer.SecurityDescriptor = NULL;
1502
1503 SdPointer = &SdBuffer;
1504
1505 RpcTryExcept
1506 {
1507 Status = LsarQuerySecurityObject((LSAPR_HANDLE)ObjectHandle,
1508 SecurityInformation,
1509 &SdPointer);
1510 if (NT_SUCCESS(Status))
1511 {
1512 *SecurityDescriptor = SdBuffer.SecurityDescriptor;
1513 }
1514 else
1515 {
1516 *SecurityDescriptor = NULL;
1517 }
1518 }
1519 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1520 {
1521 Status = I_RpcMapWin32Status(RpcExceptionCode());
1522 }
1523 RpcEndExcept;
1524
1525 return Status;
1526 }
1527
1528
1529 /*
1530 * @unimplemented
1531 */
1532 NTSTATUS
1533 WINAPI
1534 LsaQueryTrustedDomainInfo(IN LSA_HANDLE PolicyHandle,
1535 IN PSID TrustedDomainSid,
1536 IN TRUSTED_INFORMATION_CLASS InformationClass,
1537 OUT PVOID *Buffer)
1538 {
1539 FIXME("LsaQueryTrustedDomainInfo(%p %p %d %p) stub\n",
1540 PolicyHandle, TrustedDomainSid, InformationClass, Buffer);
1541 return STATUS_OBJECT_NAME_NOT_FOUND;
1542 }
1543
1544
1545 /*
1546 * @implemented
1547 */
1548 NTSTATUS
1549 WINAPI
1550 LsaQueryTrustedDomainInfoByName(IN LSA_HANDLE PolicyHandle,
1551 IN PLSA_UNICODE_STRING TrustedDomainName,
1552 IN TRUSTED_INFORMATION_CLASS InformationClass,
1553 OUT PVOID *Buffer)
1554 {
1555 NTSTATUS Status;
1556
1557 TRACE("LsaQueryTrustedDomainInfoByName(%p %p %d %p)\n",
1558 PolicyHandle, TrustedDomainName, InformationClass, Buffer);
1559
1560 if (InformationClass == TrustedDomainAuthInformationInternal ||
1561 InformationClass == TrustedDomainFullInformationInternal)
1562 return STATUS_INVALID_INFO_CLASS;
1563
1564 RpcTryExcept
1565 {
1566 Status = LsarQueryTrustedDomainInfoByName((LSAPR_HANDLE)PolicyHandle,
1567 (PRPC_UNICODE_STRING)TrustedDomainName,
1568 InformationClass,
1569 (PLSAPR_TRUSTED_DOMAIN_INFO *)Buffer);
1570 }
1571 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1572 {
1573 Status = I_RpcMapWin32Status(RpcExceptionCode());
1574 }
1575 RpcEndExcept;
1576
1577 return Status;
1578 }
1579
1580
1581 /*
1582 * @unimplemented
1583 */
1584 NTSTATUS
1585 WINAPI
1586 LsaRegisterPolicyChangeNotification(IN POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
1587 IN HANDLE NotificationEventHandle)
1588 {
1589 FIXME("LsaRegisterPolicyChangeNotification(%d %p) stub\n",
1590 InformationClass, NotificationEventHandle);
1591 return STATUS_UNSUCCESSFUL;
1592 }
1593
1594
1595 /*
1596 * @implemented
1597 */
1598 NTSTATUS
1599 WINAPI
1600 LsaRemoveAccountRights(IN LSA_HANDLE PolicyHandle,
1601 IN PSID AccountSid,
1602 IN BOOLEAN AllRights,
1603 IN PLSA_UNICODE_STRING UserRights,
1604 IN ULONG CountOfRights)
1605 {
1606 LSAPR_USER_RIGHT_SET UserRightSet;
1607
1608 TRACE("LsaRemoveAccountRights(%p %p %d %p %lu)\n",
1609 PolicyHandle, AccountSid, AllRights, UserRights, CountOfRights);
1610
1611 UserRightSet.Entries = CountOfRights;
1612 UserRightSet.UserRights = (PRPC_UNICODE_STRING)UserRights;
1613
1614 RpcTryExcept
1615 {
1616 LsarRemoveAccountRights((LSAPR_HANDLE)PolicyHandle,
1617 (PRPC_SID)AccountSid,
1618 AllRights,
1619 &UserRightSet);
1620 }
1621 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1622 {
1623 I_RpcMapWin32Status(RpcExceptionCode());
1624 }
1625 RpcEndExcept;
1626
1627 return STATUS_SUCCESS;
1628 }
1629
1630
1631 /*
1632 * @implemented
1633 */
1634 NTSTATUS
1635 WINAPI
1636 LsaRemovePrivilegesFromAccount(IN LSA_HANDLE AccountHandle,
1637 IN BOOLEAN AllPrivileges,
1638 IN PPRIVILEGE_SET Privileges OPTIONAL)
1639 {
1640 NTSTATUS Status;
1641
1642 RpcTryExcept
1643 {
1644 Status = LsarRemovePrivilegesFromAccount((LSAPR_HANDLE)AccountHandle,
1645 AllPrivileges,
1646 (PLSAPR_PRIVILEGE_SET)Privileges);
1647 }
1648 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1649 {
1650 Status = I_RpcMapWin32Status(RpcExceptionCode());
1651 }
1652 RpcEndExcept;
1653
1654 return Status;
1655 }
1656
1657
1658 /*
1659 * @unimplemented
1660 */
1661 NTSTATUS
1662 WINAPI
1663 LsaRetrievePrivateData(IN LSA_HANDLE PolicyHandle,
1664 IN PLSA_UNICODE_STRING KeyName,
1665 OUT PLSA_UNICODE_STRING *PrivateData)
1666 {
1667 FIXME("LsaRetrievePrivateData(%p %p %p) stub\n",
1668 PolicyHandle, KeyName, PrivateData);
1669 return STATUS_OBJECT_NAME_NOT_FOUND;
1670 }
1671
1672
1673 /*
1674 * @implemented
1675 */
1676 NTSTATUS
1677 WINAPI
1678 LsaSetDomainInformationPolicy(IN LSA_HANDLE PolicyHandle,
1679 IN POLICY_DOMAIN_INFORMATION_CLASS InformationClass,
1680 IN PVOID Buffer OPTIONAL)
1681 {
1682 NTSTATUS Status;
1683
1684 TRACE("LsaSetDomainInformationPolicy(%p %d %p)\n",
1685 PolicyHandle, InformationClass, Buffer);
1686
1687 RpcTryExcept
1688 {
1689 Status = LsarSetDomainInformationPolicy((LSAPR_HANDLE)PolicyHandle,
1690 InformationClass,
1691 (PLSAPR_POLICY_DOMAIN_INFORMATION)Buffer);
1692 }
1693 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1694 {
1695 Status = I_RpcMapWin32Status(RpcExceptionCode());
1696 }
1697 RpcEndExcept;
1698
1699 return Status;
1700 }
1701
1702
1703 /*
1704 * @unimplemented
1705 */
1706 NTSTATUS
1707 WINAPI
1708 LsaSetForestTrustInformation(IN LSA_HANDLE PolicyHandle,
1709 IN PLSA_UNICODE_STRING TrustedDomainName,
1710 IN PLSA_FOREST_TRUST_INFORMATION ForestTrustInfo,
1711 IN BOOL CheckOnly,
1712 OUT PLSA_FOREST_TRUST_COLLISION_INFORMATION *CollisionInfo)
1713 {
1714 FIXME("LsaSetForestTrustInformation(%p %p %p %d %p) stub\n",
1715 PolicyHandle, TrustedDomainName, ForestTrustInfo, CheckOnly, CollisionInfo);
1716 return STATUS_NOT_IMPLEMENTED;
1717 }
1718
1719
1720 /*
1721 * @implemented
1722 */
1723 NTSTATUS
1724 WINAPI
1725 LsaSetInformationPolicy(IN LSA_HANDLE PolicyHandle,
1726 IN POLICY_INFORMATION_CLASS InformationClass,
1727 IN PVOID Buffer)
1728 {
1729 NTSTATUS Status;
1730
1731 TRACE("LsaSetInformationPolicy(%p %d %p)\n",
1732 PolicyHandle, InformationClass, Buffer);
1733
1734 RpcTryExcept
1735 {
1736 Status = LsarSetInformationPolicy((LSAPR_HANDLE)PolicyHandle,
1737 InformationClass,
1738 (PLSAPR_POLICY_INFORMATION)Buffer);
1739 }
1740 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1741 {
1742 Status = I_RpcMapWin32Status(RpcExceptionCode());
1743 }
1744 RpcEndExcept;
1745
1746 return Status;
1747 }
1748
1749
1750 /*
1751 * @unimplemented
1752 */
1753 NTSTATUS
1754 WINAPI
1755 LsaSetInformationTrustedDomain(IN LSA_HANDLE TrustedDomainHandle,
1756 IN TRUSTED_INFORMATION_CLASS InformationClass,
1757 IN PVOID Buffer)
1758 {
1759 FIXME("LsaSetInformationTrustedDomain(%p %d %p)\n",
1760 TrustedDomainHandle, InformationClass, Buffer);
1761 return STATUS_NOT_IMPLEMENTED;
1762 }
1763
1764
1765 /*
1766 * @implemented
1767 */
1768 NTSTATUS
1769 WINAPI
1770 LsaSetQuotasForAccount(IN LSA_HANDLE AccountHandle,
1771 IN PQUOTA_LIMITS QuotaLimits)
1772 {
1773 NTSTATUS Status;
1774
1775 TRACE("LsaSetQuotasForAccount(%p %p)\n",
1776 AccountHandle, QuotaLimits);
1777
1778 RpcTryExcept
1779 {
1780 Status = LsarSetQuotasForAccount((LSAPR_HANDLE)AccountHandle,
1781 QuotaLimits);
1782 }
1783 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1784 {
1785 Status = I_RpcMapWin32Status(RpcExceptionCode());
1786 }
1787 RpcEndExcept;
1788
1789 return Status;
1790 }
1791
1792
1793 /*
1794 * @implemented
1795 */
1796 NTSTATUS
1797 WINAPI
1798 LsaSetSecret(IN LSA_HANDLE SecretHandle,
1799 IN PLSA_UNICODE_STRING CurrentValue OPTIONAL,
1800 IN PLSA_UNICODE_STRING OldValue OPTIONAL)
1801 {
1802 PLSAPR_CR_CIPHER_VALUE EncryptedCurrentValue = NULL;
1803 PLSAPR_CR_CIPHER_VALUE EncryptedOldValue = NULL;
1804 SIZE_T BufferSize;
1805 NTSTATUS Status;
1806
1807 TRACE("LsaSetSecret(%p %p %p)\n",
1808 SecretHandle, EncryptedCurrentValue, EncryptedOldValue);
1809
1810 if (CurrentValue != NULL)
1811 {
1812 BufferSize = sizeof(LSAPR_CR_CIPHER_VALUE) + CurrentValue->MaximumLength;
1813 EncryptedCurrentValue = midl_user_allocate(BufferSize);
1814 if (EncryptedCurrentValue == NULL)
1815 {
1816 Status = STATUS_INSUFFICIENT_RESOURCES;
1817 goto done;
1818 }
1819
1820 EncryptedCurrentValue->Length = CurrentValue->Length;
1821 EncryptedCurrentValue->MaximumLength = CurrentValue->MaximumLength;
1822 EncryptedCurrentValue->Buffer = (BYTE *)(EncryptedCurrentValue + 1);
1823 if (EncryptedCurrentValue->Buffer != NULL)
1824 memcpy(EncryptedCurrentValue->Buffer, CurrentValue->Buffer, CurrentValue->Length);
1825 }
1826
1827 if (OldValue != NULL)
1828 {
1829 BufferSize = sizeof(LSAPR_CR_CIPHER_VALUE) + OldValue->MaximumLength;
1830 EncryptedOldValue = midl_user_allocate(BufferSize);
1831 if (EncryptedOldValue == NULL)
1832 {
1833 Status = STATUS_INSUFFICIENT_RESOURCES;
1834 goto done;
1835 }
1836
1837 EncryptedOldValue->Length = OldValue->Length;
1838 EncryptedOldValue->MaximumLength = OldValue->MaximumLength;
1839 EncryptedOldValue->Buffer = (BYTE*)(EncryptedOldValue + 1);
1840 if (EncryptedOldValue->Buffer != NULL)
1841 memcpy(EncryptedOldValue->Buffer, OldValue->Buffer, OldValue->Length);
1842 }
1843
1844 RpcTryExcept
1845 {
1846 Status = LsarSetSecret((LSAPR_HANDLE)SecretHandle,
1847 EncryptedCurrentValue,
1848 EncryptedOldValue);
1849 }
1850 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1851 {
1852 Status = I_RpcMapWin32Status(RpcExceptionCode());
1853 }
1854 RpcEndExcept;
1855
1856 done:
1857 if (EncryptedCurrentValue != NULL)
1858 midl_user_free(EncryptedCurrentValue);
1859
1860 if (EncryptedOldValue != NULL)
1861 midl_user_free(EncryptedOldValue);
1862
1863 return Status;
1864 }
1865
1866
1867 /*
1868 * @implemented
1869 */
1870 NTSTATUS
1871 WINAPI
1872 LsaSetSecurityObject(IN LSA_HANDLE ObjectHandle,
1873 IN SECURITY_INFORMATION SecurityInformation,
1874 IN PSECURITY_DESCRIPTOR SecurityDescriptor)
1875 {
1876 LSAPR_SR_SECURITY_DESCRIPTOR SdBuffer = {0, NULL};
1877 ULONG SdLength = 0;
1878 NTSTATUS Status;
1879
1880 TRACE("LsaSetSecurityObject(%p %lx %p)\n",
1881 ObjectHandle, SecurityInformation, SecurityDescriptor);
1882
1883 Status = RtlMakeSelfRelativeSD(SecurityDescriptor,
1884 NULL,
1885 &SdLength);
1886 if (Status != STATUS_BUFFER_TOO_SMALL)
1887 return STATUS_INVALID_PARAMETER;
1888
1889 SdBuffer.SecurityDescriptor = MIDL_user_allocate(SdLength);
1890 if (SdBuffer.SecurityDescriptor == NULL)
1891 return STATUS_INSUFFICIENT_RESOURCES;
1892
1893 Status = RtlMakeSelfRelativeSD(SecurityDescriptor,
1894 (PSECURITY_DESCRIPTOR)SdBuffer.SecurityDescriptor,
1895 &SdLength);
1896 if (!NT_SUCCESS(Status))
1897 goto done;
1898
1899 SdBuffer.Length = SdLength;
1900
1901 RpcTryExcept
1902 {
1903 Status = LsarSetSecurityObject((LSAPR_HANDLE)ObjectHandle,
1904 SecurityInformation,
1905 &SdBuffer);
1906 }
1907 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1908 {
1909 Status = I_RpcMapWin32Status(RpcExceptionCode());
1910 }
1911 RpcEndExcept;
1912
1913 done:
1914 if (SdBuffer.SecurityDescriptor != NULL)
1915 MIDL_user_free(SdBuffer.SecurityDescriptor);
1916
1917 return Status;
1918 }
1919
1920
1921 /*
1922 * @implemented
1923 */
1924 NTSTATUS
1925 WINAPI
1926 LsaSetSystemAccessAccount(IN LSA_HANDLE AccountHandle,
1927 IN ULONG SystemAccess)
1928 {
1929 NTSTATUS Status;
1930
1931 TRACE("LsaSetSystemAccessAccount(%p 0x%lx)\n",
1932 AccountHandle, SystemAccess);
1933
1934 RpcTryExcept
1935 {
1936 Status = LsarSetSystemAccessAccount((LSAPR_HANDLE)AccountHandle,
1937 SystemAccess);
1938 }
1939 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1940 {
1941 Status = I_RpcMapWin32Status(RpcExceptionCode());
1942 }
1943 RpcEndExcept;
1944
1945 return Status;
1946 }
1947
1948
1949 /*
1950 * @unimplemented
1951 */
1952 NTSTATUS
1953 WINAPI
1954 LsaSetTrustedDomainInfoByName(IN LSA_HANDLE PolicyHandle,
1955 IN PLSA_UNICODE_STRING TrustedDomainName,
1956 IN TRUSTED_INFORMATION_CLASS InformationClass,
1957 IN PVOID Buffer)
1958 {
1959 FIXME("LsaSetTrustedDomainInfoByName(%p %p %d %p) stub\n",
1960 PolicyHandle, TrustedDomainName, InformationClass, Buffer);
1961 return STATUS_SUCCESS;
1962 }
1963
1964
1965 /*
1966 * @unimplemented
1967 */
1968 NTSTATUS
1969 WINAPI
1970 LsaSetTrustedDomainInformation(IN LSA_HANDLE PolicyHandle,
1971 IN PSID TrustedDomainSid,
1972 IN TRUSTED_INFORMATION_CLASS InformationClass,
1973 IN PVOID Buffer)
1974 {
1975 FIXME("LsaSetTrustedDomainInformation(%p %p %d %p) stub\n",
1976 PolicyHandle, TrustedDomainSid, InformationClass, Buffer);
1977 return STATUS_SUCCESS;
1978 }
1979
1980
1981 /*
1982 * @unimplemented
1983 */
1984 NTSTATUS
1985 WINAPI
1986 LsaStorePrivateData(IN LSA_HANDLE PolicyHandle,
1987 IN PLSA_UNICODE_STRING KeyName,
1988 IN PLSA_UNICODE_STRING PrivateData OPTIONAL)
1989 {
1990 FIXME("LsaStorePrivateData(%p %p %p) stub\n",
1991 PolicyHandle, KeyName, PrivateData);
1992 return STATUS_OBJECT_NAME_NOT_FOUND;
1993 }
1994
1995
1996 /*
1997 * @unimplemented
1998 */
1999 NTSTATUS
2000 WINAPI
2001 LsaUnregisterPolicyChangeNotification(IN POLICY_NOTIFICATION_INFORMATION_CLASS InformationClass,
2002 IN HANDLE NotificationEventHandle)
2003 {
2004 FIXME("(%d %p) stub\n",
2005 InformationClass, NotificationEventHandle);
2006 return STATUS_SUCCESS;
2007 }
2008
2009 /* EOF */