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