[SAL]
[reactos.git] / reactos / dll / win32 / samlib / samlib.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS system libraries
22 * PURPOSE: SAM interface library
23 * FILE: lib/samlib/samlib.c
24 * PROGRAMER: Eric Kohl
25 */
26
27 /* INCLUDES *****************************************************************/
28
29 #include "precomp.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(samlib);
32
33 NTSTATUS
34 WINAPI
35 SystemFunction006(LPCSTR password,
36 LPSTR hash);
37
38 NTSTATUS
39 WINAPI
40 SystemFunction007(PUNICODE_STRING string,
41 LPBYTE hash);
42
43 /* GLOBALS *******************************************************************/
44
45
46 /* FUNCTIONS *****************************************************************/
47
48 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
49 {
50 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
51 }
52
53
54 void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
55 {
56 HeapFree(GetProcessHeap(), 0, ptr);
57 }
58
59
60 handle_t __RPC_USER
61 PSAMPR_SERVER_NAME_bind(PSAMPR_SERVER_NAME pszSystemName)
62 {
63 handle_t hBinding = NULL;
64 LPWSTR pszStringBinding;
65 RPC_STATUS status;
66
67 TRACE("PSAMPR_SERVER_NAME_bind() called\n");
68
69 status = RpcStringBindingComposeW(NULL,
70 L"ncacn_np",
71 pszSystemName,
72 L"\\pipe\\samr",
73 NULL,
74 &pszStringBinding);
75 if (status)
76 {
77 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
78 return NULL;
79 }
80
81 /* Set the binding handle that will be used to bind to the server. */
82 status = RpcBindingFromStringBindingW(pszStringBinding,
83 &hBinding);
84 if (status)
85 {
86 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
87 }
88
89 status = RpcStringFreeW(&pszStringBinding);
90 if (status)
91 {
92 // TRACE("RpcStringFree returned 0x%x\n", status);
93 }
94
95 return hBinding;
96 }
97
98
99 void __RPC_USER
100 PSAMPR_SERVER_NAME_unbind(PSAMPR_SERVER_NAME pszSystemName,
101 handle_t hBinding)
102 {
103 RPC_STATUS status;
104
105 TRACE("PSAMPR_SERVER_NAME_unbind() called\n");
106
107 status = RpcBindingFree(&hBinding);
108 if (status)
109 {
110 TRACE("RpcBindingFree returned 0x%x\n", status);
111 }
112 }
113
114
115 NTSTATUS
116 NTAPI
117 SamAddMemberToAlias(IN SAM_HANDLE AliasHandle,
118 IN PSID MemberId)
119 {
120 NTSTATUS Status;
121
122 TRACE("SamAddMemberToAlias(%p %p)\n",
123 AliasHandle, MemberId);
124
125 RpcTryExcept
126 {
127 Status = SamrAddMemberToAlias((SAMPR_HANDLE)AliasHandle,
128 (PRPC_SID)MemberId);
129 }
130 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
131 {
132 Status = I_RpcMapWin32Status(RpcExceptionCode());
133 }
134 RpcEndExcept;
135
136 return Status;
137 }
138
139
140 NTSTATUS
141 NTAPI
142 SamAddMemberToGroup(IN SAM_HANDLE GroupHandle,
143 IN ULONG MemberId,
144 IN ULONG Attributes)
145 {
146 NTSTATUS Status;
147
148 TRACE("SamAddMemberToGroup(%p %lu %lx)\n",
149 GroupHandle, MemberId, Attributes);
150
151 RpcTryExcept
152 {
153 Status = SamrAddMemberToGroup((SAMPR_HANDLE)GroupHandle,
154 MemberId,
155 Attributes);
156 }
157 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
158 {
159 Status = I_RpcMapWin32Status(RpcExceptionCode());
160 }
161 RpcEndExcept;
162
163 return Status;
164 }
165
166
167 NTSTATUS
168 NTAPI
169 SamAddMultipleMembersToAlias(IN SAM_HANDLE AliasHandle,
170 IN PSID *MemberIds,
171 IN ULONG MemberCount)
172 {
173 SAMPR_PSID_ARRAY Buffer;
174 NTSTATUS Status;
175
176 TRACE("SamAddMultipleMembersToAlias(%p %p %lu)\n",
177 AliasHandle, MemberIds, MemberCount);
178
179 if (MemberIds == NULL)
180 return STATUS_INVALID_PARAMETER_2;
181
182 Buffer.Count = MemberCount;
183 Buffer.Sids = (PSAMPR_SID_INFORMATION)MemberIds;
184
185 RpcTryExcept
186 {
187 Status = SamrAddMultipleMembersToAlias((SAMPR_HANDLE)AliasHandle,
188 &Buffer);
189 }
190 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
191 {
192 Status = I_RpcMapWin32Status(RpcExceptionCode());
193 }
194 RpcEndExcept;
195
196 return Status;
197 }
198
199
200 NTSTATUS
201 NTAPI
202 SamChangePasswordUser(IN SAM_HANDLE UserHandle,
203 IN PUNICODE_STRING OldPassword,
204 IN PUNICODE_STRING NewPassword)
205 {
206 ENCRYPTED_NT_OWF_PASSWORD OldNtPassword;
207 ENCRYPTED_NT_OWF_PASSWORD NewNtPassword;
208 ENCRYPTED_LM_OWF_PASSWORD OldLmPassword;
209 ENCRYPTED_LM_OWF_PASSWORD NewLmPassword;
210 OEM_STRING LmPwdString;
211 CHAR LmPwdBuffer[15];
212 BOOLEAN OldLmPasswordPresent = FALSE;
213 BOOLEAN NewLmPasswordPresent = FALSE;
214 NTSTATUS Status;
215
216 /* Calculate the NT hash for the old password */
217 Status = SystemFunction007(OldPassword,
218 (LPBYTE)&OldNtPassword);
219 if (!NT_SUCCESS(Status))
220 {
221 TRACE("SystemFunction007 failed (Status 0x%08lx)\n", Status);
222 return Status;
223 }
224
225 /* Calculate the NT hash for the new password */
226 Status = SystemFunction007(NewPassword,
227 (LPBYTE)&NewNtPassword);
228 if (!NT_SUCCESS(Status))
229 {
230 TRACE("SystemFunction007 failed (Status 0x%08lx)\n", Status);
231 return Status;
232 }
233
234 /* Calculate the LM password and hash for the old password */
235 LmPwdString.Length = 15;
236 LmPwdString.MaximumLength = 15;
237 LmPwdString.Buffer = LmPwdBuffer;
238 ZeroMemory(LmPwdString.Buffer, LmPwdString.MaximumLength);
239
240 Status = RtlUpcaseUnicodeStringToOemString(&LmPwdString,
241 OldPassword,
242 FALSE);
243 if (NT_SUCCESS(Status))
244 {
245 /* Calculate the LM hash value of the password */
246 Status = SystemFunction006(LmPwdString.Buffer,
247 (LPSTR)&OldLmPassword);
248 if (NT_SUCCESS(Status))
249 {
250 OldLmPasswordPresent = TRUE;
251 }
252 }
253
254 /* Calculate the LM password and hash for the new password */
255 LmPwdString.Length = 15;
256 LmPwdString.MaximumLength = 15;
257 LmPwdString.Buffer = LmPwdBuffer;
258 ZeroMemory(LmPwdString.Buffer, LmPwdString.MaximumLength);
259
260 Status = RtlUpcaseUnicodeStringToOemString(&LmPwdString,
261 NewPassword,
262 FALSE);
263 if (NT_SUCCESS(Status))
264 {
265 /* Calculate the LM hash value of the password */
266 Status = SystemFunction006(LmPwdString.Buffer,
267 (LPSTR)&NewLmPassword);
268 if (NT_SUCCESS(Status))
269 {
270 NewLmPasswordPresent = TRUE;
271 }
272 }
273
274 RpcTryExcept
275 {
276 Status = SamrChangePasswordUser((SAMPR_HANDLE)UserHandle,
277 OldLmPasswordPresent && NewLmPasswordPresent,
278 &OldLmPassword,
279 &NewLmPassword,
280 TRUE,
281 &OldNtPassword,
282 &NewNtPassword,
283 FALSE,
284 NULL,
285 FALSE,
286 NULL);
287 }
288 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
289 {
290 Status = I_RpcMapWin32Status(RpcExceptionCode());
291 }
292 RpcEndExcept;
293
294 return Status;
295 }
296
297
298 NTSTATUS
299 NTAPI
300 SamChangePasswordUser2(IN PUNICODE_STRING ServerName,
301 IN PUNICODE_STRING UserName,
302 IN PUNICODE_STRING OldPassword,
303 IN PUNICODE_STRING NewPassword)
304 {
305 UNIMPLEMENTED;
306 return STATUS_NOT_IMPLEMENTED;
307 }
308
309
310 NTSTATUS
311 NTAPI
312 SamChangePasswordUser3(IN PUNICODE_STRING ServerName,
313 IN PUNICODE_STRING UserName,
314 IN PUNICODE_STRING OldPassword,
315 IN PUNICODE_STRING NewPassword,
316 OUT PDOMAIN_PASSWORD_INFORMATION *EffectivePasswordPolicy,
317 OUT PUSER_PWD_CHANGE_FAILURE_INFORMATION *PasswordChangeFailureInfo)
318 {
319 UNIMPLEMENTED;
320 return STATUS_NOT_IMPLEMENTED;
321 }
322
323
324 NTSTATUS
325 NTAPI
326 SamCloseHandle(IN SAM_HANDLE SamHandle)
327 {
328 NTSTATUS Status;
329
330 TRACE("SamCloseHandle(%p)\n", SamHandle);
331
332 RpcTryExcept
333 {
334 Status = SamrCloseHandle((SAMPR_HANDLE *)&SamHandle);
335 }
336 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
337 {
338 Status = I_RpcMapWin32Status(RpcExceptionCode());
339 }
340 RpcEndExcept;
341
342 return Status;
343 }
344
345
346 NTSTATUS
347 NTAPI
348 SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL,
349 OUT PSAM_HANDLE ServerHandle,
350 IN ACCESS_MASK DesiredAccess,
351 IN POBJECT_ATTRIBUTES ObjectAttributes)
352 {
353 NTSTATUS Status;
354
355 TRACE("SamConnect(%p %p 0x%08x %p)\n",
356 ServerName, ServerHandle, DesiredAccess, ObjectAttributes);
357
358 RpcTryExcept
359 {
360 Status = SamrConnect((PSAMPR_SERVER_NAME)ServerName,
361 (SAMPR_HANDLE *)ServerHandle,
362 DesiredAccess);
363 }
364 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
365 {
366 Status = I_RpcMapWin32Status(RpcExceptionCode());
367 }
368 RpcEndExcept;
369
370 return Status;
371 }
372
373
374 NTSTATUS
375 NTAPI
376 SamCreateAliasInDomain(IN SAM_HANDLE DomainHandle,
377 IN PUNICODE_STRING AccountName,
378 IN ACCESS_MASK DesiredAccess,
379 OUT PSAM_HANDLE AliasHandle,
380 OUT PULONG RelativeId)
381 {
382 NTSTATUS Status;
383
384 TRACE("SamCreateAliasInDomain(%p %p 0x%08x %p %p)\n",
385 DomainHandle, AccountName, DesiredAccess, AliasHandle, RelativeId);
386
387 *AliasHandle = NULL;
388 *RelativeId = 0;
389
390 RpcTryExcept
391 {
392 Status = SamrCreateAliasInDomain((SAMPR_HANDLE)DomainHandle,
393 (PRPC_UNICODE_STRING)AccountName,
394 DesiredAccess,
395 (SAMPR_HANDLE *)AliasHandle,
396 RelativeId);
397 }
398 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
399 {
400 Status = I_RpcMapWin32Status(RpcExceptionCode());
401 }
402 RpcEndExcept;
403
404 return Status;
405 }
406
407
408 NTSTATUS
409 NTAPI
410 SamCreateGroupInDomain(IN SAM_HANDLE DomainHandle,
411 IN PUNICODE_STRING AccountName,
412 IN ACCESS_MASK DesiredAccess,
413 OUT PSAM_HANDLE GroupHandle,
414 OUT PULONG RelativeId)
415 {
416 NTSTATUS Status;
417
418 TRACE("SamCreateGroupInDomain(%p %p 0x%08x %p %p)\n",
419 DomainHandle, AccountName, DesiredAccess, GroupHandle, RelativeId);
420
421 *GroupHandle = NULL;
422 *RelativeId = 0;
423
424 RpcTryExcept
425 {
426 Status = SamrCreateGroupInDomain((SAMPR_HANDLE)DomainHandle,
427 (PRPC_UNICODE_STRING)AccountName,
428 DesiredAccess,
429 (SAMPR_HANDLE *)GroupHandle,
430 RelativeId);
431 }
432 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
433 {
434 Status = I_RpcMapWin32Status(RpcExceptionCode());
435 }
436 RpcEndExcept;
437
438 return Status;
439 }
440
441
442 NTSTATUS
443 NTAPI
444 SamCreateUser2InDomain(IN SAM_HANDLE DomainHandle,
445 IN PUNICODE_STRING AccountName,
446 IN ULONG AccountType,
447 IN ACCESS_MASK DesiredAccess,
448 OUT PSAM_HANDLE UserHandle,
449 OUT PULONG GrantedAccess,
450 OUT PULONG RelativeId)
451 {
452 NTSTATUS Status;
453
454 TRACE("SamCreateUser2InDomain(%p %p %lu 0x%08x %p %p %p)\n",
455 DomainHandle, AccountName, AccountType, DesiredAccess,
456 UserHandle, GrantedAccess, RelativeId);
457
458 *UserHandle = NULL;
459 *RelativeId = 0;
460
461 RpcTryExcept
462 {
463 Status = SamrCreateUser2InDomain((SAMPR_HANDLE)DomainHandle,
464 (PRPC_UNICODE_STRING)AccountName,
465 AccountType,
466 DesiredAccess,
467 (SAMPR_HANDLE *)UserHandle,
468 GrantedAccess,
469 RelativeId);
470
471 }
472 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
473 {
474 Status = I_RpcMapWin32Status(RpcExceptionCode());
475 }
476 RpcEndExcept;
477
478 return Status;
479 }
480
481
482 NTSTATUS
483 NTAPI
484 SamCreateUserInDomain(IN SAM_HANDLE DomainHandle,
485 IN PUNICODE_STRING AccountName,
486 IN ACCESS_MASK DesiredAccess,
487 OUT PSAM_HANDLE UserHandle,
488 OUT PULONG RelativeId)
489 {
490 NTSTATUS Status;
491
492 TRACE("SamCreateUserInDomain(%p %p 0x%08x %p %p)\n",
493 DomainHandle, AccountName, DesiredAccess, UserHandle, RelativeId);
494
495 *UserHandle = NULL;
496 *RelativeId = 0;
497
498 RpcTryExcept
499 {
500 Status = SamrCreateUserInDomain((SAMPR_HANDLE)DomainHandle,
501 (PRPC_UNICODE_STRING)AccountName,
502 DesiredAccess,
503 (SAMPR_HANDLE *)UserHandle,
504 RelativeId);
505 }
506 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
507 {
508 Status = I_RpcMapWin32Status(RpcExceptionCode());
509 }
510 RpcEndExcept;
511
512 return Status;
513 }
514
515
516 NTSTATUS
517 NTAPI
518 SamDeleteAlias(IN SAM_HANDLE AliasHandle)
519 {
520 SAMPR_HANDLE LocalAliasHandle;
521 NTSTATUS Status;
522
523 TRACE("SamDeleteAlias(%p)\n", AliasHandle);
524
525 LocalAliasHandle = (SAMPR_HANDLE)AliasHandle;
526
527 if (LocalAliasHandle == NULL)
528 return STATUS_INVALID_HANDLE;
529
530 RpcTryExcept
531 {
532 Status = SamrDeleteAlias(&LocalAliasHandle);
533 }
534 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
535 {
536 Status = I_RpcMapWin32Status(RpcExceptionCode());
537 }
538 RpcEndExcept;
539
540 return Status;
541 }
542
543
544 NTSTATUS
545 NTAPI
546 SamDeleteGroup(IN SAM_HANDLE GroupHandle)
547 {
548 SAMPR_HANDLE LocalGroupHandle;
549 NTSTATUS Status;
550
551 TRACE("SamDeleteGroup(%p)\n", GroupHandle);
552
553 LocalGroupHandle = (SAMPR_HANDLE)GroupHandle;
554
555 if (LocalGroupHandle == NULL)
556 return STATUS_INVALID_HANDLE;
557
558 RpcTryExcept
559 {
560 Status = SamrDeleteGroup(&LocalGroupHandle);
561 }
562 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
563 {
564 Status = I_RpcMapWin32Status(RpcExceptionCode());
565 }
566 RpcEndExcept;
567
568 return Status;
569 }
570
571
572 NTSTATUS
573 NTAPI
574 SamDeleteUser(IN SAM_HANDLE UserHandle)
575 {
576 SAMPR_HANDLE LocalUserHandle;
577 NTSTATUS Status;
578
579 TRACE("SamDeleteUser(%p)\n", UserHandle);
580
581 LocalUserHandle = (SAMPR_HANDLE)UserHandle;
582
583 if (LocalUserHandle == NULL)
584 return STATUS_INVALID_HANDLE;
585
586 RpcTryExcept
587 {
588 Status = SamrDeleteUser(&LocalUserHandle);
589 }
590 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
591 {
592 Status = I_RpcMapWin32Status(RpcExceptionCode());
593 }
594 RpcEndExcept;
595
596 return Status;
597 }
598
599
600 NTSTATUS
601 NTAPI
602 SamEnumerateAliasesInDomain(IN SAM_HANDLE DomainHandle,
603 IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext,
604 OUT PVOID *Buffer,
605 IN ULONG PreferedMaximumLength,
606 OUT PULONG CountReturned)
607 {
608 PSAMPR_ENUMERATION_BUFFER EnumBuffer = NULL;
609 NTSTATUS Status;
610
611 TRACE("SamEnumerateAliasesInDomain(%p %p %p %lu %p)\n",
612 DomainHandle, EnumerationContext, Buffer, PreferedMaximumLength,
613 CountReturned);
614
615 if ((EnumerationContext == NULL) ||
616 (Buffer == NULL) ||
617 (CountReturned == NULL))
618 return STATUS_INVALID_PARAMETER;
619
620 *Buffer = NULL;
621
622 RpcTryExcept
623 {
624 Status = SamrEnumerateAliasesInDomain((SAMPR_HANDLE)DomainHandle,
625 EnumerationContext,
626 &EnumBuffer,
627 PreferedMaximumLength,
628 CountReturned);
629
630 if (EnumBuffer != NULL)
631 {
632 if (EnumBuffer->Buffer != NULL)
633 {
634 *Buffer = EnumBuffer->Buffer;
635 }
636
637 midl_user_free(EnumBuffer);
638 }
639 }
640 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
641 {
642 Status = I_RpcMapWin32Status(RpcExceptionCode());
643 }
644 RpcEndExcept;
645
646 return Status;
647 }
648
649
650 NTSTATUS
651 NTAPI
652 SamEnumerateDomainsInSamServer(IN SAM_HANDLE ServerHandle,
653 IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext,
654 OUT PVOID *Buffer,
655 IN ULONG PreferedMaximumLength,
656 OUT PULONG CountReturned)
657 {
658 PSAMPR_ENUMERATION_BUFFER EnumBuffer = NULL;
659 NTSTATUS Status;
660
661 TRACE("SamEnumerateDomainsInSamServer(%p %p %p %lu %p)\n",
662 ServerHandle, EnumerationContext, Buffer, PreferedMaximumLength,
663 CountReturned);
664
665 if ((EnumerationContext == NULL) ||
666 (Buffer == NULL) ||
667 (CountReturned == NULL))
668 return STATUS_INVALID_PARAMETER;
669
670 *Buffer = NULL;
671
672 RpcTryExcept
673 {
674 Status = SamrEnumerateDomainsInSamServer((SAMPR_HANDLE)ServerHandle,
675 EnumerationContext,
676 &EnumBuffer,
677 PreferedMaximumLength,
678 CountReturned);
679
680 if (EnumBuffer != NULL)
681 {
682 if (EnumBuffer->Buffer != NULL)
683 {
684 *Buffer = EnumBuffer->Buffer;
685 }
686
687 midl_user_free(EnumBuffer);
688 }
689 }
690 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
691 {
692 Status = I_RpcMapWin32Status(RpcExceptionCode());
693 }
694 RpcEndExcept;
695
696 return Status;
697 }
698
699
700 NTSTATUS
701 NTAPI
702 SamEnumerateGroupsInDomain(IN SAM_HANDLE DomainHandle,
703 IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext,
704 IN PVOID *Buffer,
705 IN ULONG PreferedMaximumLength,
706 OUT PULONG CountReturned)
707 {
708 PSAMPR_ENUMERATION_BUFFER EnumBuffer = NULL;
709 NTSTATUS Status;
710
711 TRACE("SamEnumerateGroupsInDomain(%p %p %p %lu %p)\n",
712 DomainHandle, EnumerationContext, Buffer,
713 PreferedMaximumLength, CountReturned);
714
715 if (EnumerationContext == NULL || Buffer == NULL || CountReturned == NULL)
716 return STATUS_INVALID_PARAMETER;
717
718 *Buffer = NULL;
719
720 RpcTryExcept
721 {
722 Status = SamrEnumerateGroupsInDomain((SAMPR_HANDLE)DomainHandle,
723 EnumerationContext,
724 &EnumBuffer,
725 PreferedMaximumLength,
726 CountReturned);
727 if (EnumBuffer != NULL)
728 {
729 if (EnumBuffer->Buffer != NULL)
730 *Buffer = EnumBuffer->Buffer;
731
732 midl_user_free(EnumBuffer);
733 }
734 }
735 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
736 {
737 Status = I_RpcMapWin32Status(RpcExceptionCode());
738 }
739 RpcEndExcept;
740
741 return Status;
742 }
743
744
745 NTSTATUS
746 NTAPI
747 SamEnumerateUsersInDomain(IN SAM_HANDLE DomainHandle,
748 IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext,
749 IN ULONG UserAccountControl,
750 OUT PVOID *Buffer,
751 IN ULONG PreferedMaximumLength,
752 OUT PULONG CountReturned)
753 {
754 PSAMPR_ENUMERATION_BUFFER EnumBuffer = NULL;
755 NTSTATUS Status;
756
757 TRACE("SamEnumerateUsersInDomain(%p %p %lx %p %lu %p)\n",
758 DomainHandle, EnumerationContext, UserAccountControl, Buffer,
759 PreferedMaximumLength, CountReturned);
760
761 if (EnumerationContext == NULL || Buffer == NULL || CountReturned == NULL)
762 return STATUS_INVALID_PARAMETER;
763
764 *Buffer = NULL;
765
766 RpcTryExcept
767 {
768 Status = SamrEnumerateUsersInDomain((SAMPR_HANDLE)DomainHandle,
769 EnumerationContext,
770 UserAccountControl,
771 &EnumBuffer,
772 PreferedMaximumLength,
773 CountReturned);
774 if (EnumBuffer != NULL)
775 {
776 if (EnumBuffer->Buffer != NULL)
777 {
778 *Buffer = EnumBuffer->Buffer;
779 }
780
781 midl_user_free(EnumBuffer);
782 }
783
784 }
785 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
786 {
787 Status = I_RpcMapWin32Status(RpcExceptionCode());
788 }
789 RpcEndExcept;
790
791 return Status;
792 }
793
794
795 NTSTATUS
796 NTAPI
797 SamFreeMemory(IN PVOID Buffer)
798 {
799 if (Buffer != NULL)
800 midl_user_free(Buffer);
801
802 return STATUS_SUCCESS;
803 }
804
805
806 NTSTATUS
807 NTAPI
808 SamGetAliasMembership(IN SAM_HANDLE DomainHandle,
809 IN ULONG PassedCount,
810 IN PSID *Sids,
811 OUT PULONG MembershipCount,
812 OUT PULONG *Aliases)
813 {
814 SAMPR_PSID_ARRAY SidArray;
815 SAMPR_ULONG_ARRAY Membership;
816 NTSTATUS Status;
817
818 TRACE("SamAliasMembership(%p %lu %p %p %p)\n",
819 DomainHandle, PassedCount, Sids, MembershipCount, Aliases);
820
821 if (Sids == NULL ||
822 MembershipCount == NULL ||
823 Aliases == NULL)
824 return STATUS_INVALID_PARAMETER;
825
826 Membership.Element = NULL;
827
828 RpcTryExcept
829 {
830 SidArray.Count = PassedCount;
831 SidArray.Sids = (PSAMPR_SID_INFORMATION)Sids;
832
833 Status = SamrGetAliasMembership((SAMPR_HANDLE)DomainHandle,
834 &SidArray,
835 &Membership);
836 if (NT_SUCCESS(Status))
837 {
838 *MembershipCount = Membership.Count;
839 *Aliases = Membership.Element;
840 }
841 else
842 {
843 if (Membership.Element != NULL)
844 midl_user_free(Membership.Element);
845 }
846 }
847 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
848 {
849 Status = I_RpcMapWin32Status(RpcExceptionCode());
850 }
851 RpcEndExcept;
852
853 return Status;
854 }
855
856
857 NTSTATUS
858 NTAPI
859 SamGetCompatibilityMode(IN SAM_HANDLE ObjectHandle,
860 OUT PULONG Mode)
861 {
862 TRACE("(%p %p)\n", ObjectHandle, Mode);
863
864 if (Mode == NULL)
865 return STATUS_INVALID_PARAMETER;
866
867 *Mode = SAM_SID_COMPATIBILITY_ALL;
868
869 return STATUS_SUCCESS;
870 }
871
872
873 NTSTATUS
874 NTAPI
875 SamGetDisplayEnumerationIndex(IN SAM_HANDLE DomainHandle,
876 IN DOMAIN_DISPLAY_INFORMATION DisplayInformation,
877 IN PUNICODE_STRING Prefix,
878 OUT PULONG Index)
879 {
880 NTSTATUS Status;
881
882 TRACE("(%p %lu %wZ %p)\n",
883 DomainHandle, DisplayInformation, Prefix, Index);
884
885 if ((Prefix == NULL) ||
886 (Index == NULL))
887 return STATUS_INVALID_PARAMETER;
888
889 RpcTryExcept
890 {
891 Status = SamrGetDisplayEnumerationIndex2((SAMPR_HANDLE)DomainHandle,
892 DisplayInformation,
893 (PRPC_UNICODE_STRING)Prefix,
894 Index);
895 }
896 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
897 {
898 Status = I_RpcMapWin32Status(RpcExceptionCode());
899 }
900 RpcEndExcept;
901
902 return Status;
903 }
904
905
906 NTSTATUS
907 NTAPI
908 SamGetGroupsForUser(IN SAM_HANDLE UserHandle,
909 OUT PGROUP_MEMBERSHIP *Groups,
910 OUT PULONG MembershipCount)
911 {
912 PSAMPR_GET_GROUPS_BUFFER GroupsBuffer = NULL;
913 NTSTATUS Status;
914
915 TRACE("SamGetGroupsForUser(%p %p %p)\n",
916 UserHandle, Groups, MembershipCount);
917
918 RpcTryExcept
919 {
920 Status = SamrGetGroupsForUser((SAMPR_HANDLE)UserHandle,
921 &GroupsBuffer);
922 if (NT_SUCCESS(Status))
923 {
924 *Groups = GroupsBuffer->Groups;
925 *MembershipCount = GroupsBuffer->MembershipCount;
926
927 MIDL_user_free(GroupsBuffer);
928 }
929 else
930 {
931 if (GroupsBuffer != NULL)
932 {
933 if (GroupsBuffer->Groups != NULL)
934 MIDL_user_free(GroupsBuffer->Groups);
935
936 MIDL_user_free(GroupsBuffer);
937 }
938 }
939 }
940 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
941 {
942 Status = I_RpcMapWin32Status(RpcExceptionCode());
943 }
944 RpcEndExcept;
945
946 return Status;
947 }
948
949
950 NTSTATUS
951 NTAPI
952 SamGetMembersInAlias(IN SAM_HANDLE AliasHandle,
953 OUT PSID **MemberIds,
954 OUT PULONG MemberCount)
955 {
956 SAMPR_PSID_ARRAY_OUT SidArray;
957 NTSTATUS Status;
958
959 TRACE("SamGetMembersInAlias(%p %p %p)\n",
960 AliasHandle, MemberIds, MemberCount);
961
962 if ((MemberIds == NULL) ||
963 (MemberCount == NULL))
964 return STATUS_INVALID_PARAMETER;
965
966 *MemberIds = NULL;
967 *MemberCount = 0;
968
969 SidArray.Sids = NULL;
970
971 RpcTryExcept
972 {
973 Status = SamrGetMembersInAlias((SAMPR_HANDLE)AliasHandle,
974 &SidArray);
975 if (NT_SUCCESS(Status))
976 {
977 *MemberCount = SidArray.Count;
978 *MemberIds = (PSID *)SidArray.Sids;
979 }
980
981 }
982 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
983 {
984 Status = I_RpcMapWin32Status(RpcExceptionCode());
985 }
986 RpcEndExcept;
987
988 return Status;
989 }
990
991
992 NTSTATUS
993 NTAPI
994 SamGetMembersInGroup(IN SAM_HANDLE GroupHandle,
995 OUT PULONG *MemberIds,
996 OUT PULONG *Attributes,
997 OUT PULONG MemberCount)
998 {
999 PSAMPR_GET_MEMBERS_BUFFER MembersBuffer = NULL;
1000 NTSTATUS Status;
1001
1002 TRACE("SamGetMembersInGroup(%p %p %p %p)\n",
1003 GroupHandle, MemberIds, Attributes, MemberCount);
1004
1005 RpcTryExcept
1006 {
1007 Status = SamrGetMembersInGroup((SAMPR_HANDLE)GroupHandle,
1008 &MembersBuffer);
1009 if (NT_SUCCESS(Status))
1010 {
1011 *MemberIds = MembersBuffer->Members;
1012 *Attributes = MembersBuffer->Attributes;
1013 *MemberCount = MembersBuffer->MemberCount;
1014
1015 MIDL_user_free(MembersBuffer);
1016 }
1017 else
1018 {
1019 if (MembersBuffer != NULL)
1020 {
1021 if (MembersBuffer->Members != NULL)
1022 MIDL_user_free(MembersBuffer->Members);
1023
1024 if (MembersBuffer->Attributes != NULL)
1025 MIDL_user_free(MembersBuffer->Attributes);
1026
1027 MIDL_user_free(MembersBuffer);
1028 }
1029 }
1030 }
1031 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1032 {
1033 Status = I_RpcMapWin32Status(RpcExceptionCode());
1034 }
1035 RpcEndExcept;
1036
1037 return Status;
1038 }
1039
1040
1041 NTSTATUS
1042 NTAPI
1043 SamLookupDomainInSamServer(IN SAM_HANDLE ServerHandle,
1044 IN PUNICODE_STRING Name,
1045 OUT PSID *DomainId)
1046 {
1047 NTSTATUS Status;
1048
1049 TRACE("SamLookupDomainInSamServer(%p %p %p)\n",
1050 ServerHandle, Name, DomainId);
1051
1052 RpcTryExcept
1053 {
1054 Status = SamrLookupDomainInSamServer((SAMPR_HANDLE)ServerHandle,
1055 (PRPC_UNICODE_STRING)Name,
1056 (PRPC_SID *)DomainId);
1057 }
1058 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1059 {
1060 Status = I_RpcMapWin32Status(RpcExceptionCode());
1061 }
1062 RpcEndExcept;
1063
1064 return Status;
1065 }
1066
1067
1068 NTSTATUS
1069 NTAPI
1070 SamLookupIdsInDomain(IN SAM_HANDLE DomainHandle,
1071 IN ULONG Count,
1072 IN PULONG RelativeIds,
1073 OUT PUNICODE_STRING *Names,
1074 OUT PSID_NAME_USE *Use OPTIONAL)
1075 {
1076 SAMPR_RETURNED_USTRING_ARRAY NamesBuffer = {0, NULL};
1077 SAMPR_ULONG_ARRAY UseBuffer = {0, NULL};
1078 ULONG i;
1079 NTSTATUS Status;
1080
1081 TRACE("SamLookupIdsInDomain(%p %lu %p %p %p)\n",
1082 DomainHandle, Count, RelativeIds, Names, Use);
1083
1084 *Names = NULL;
1085
1086 if (Use != NULL)
1087 *Use = NULL;
1088
1089 RpcTryExcept
1090 {
1091 Status = SamrLookupIdsInDomain((SAMPR_HANDLE)DomainHandle,
1092 Count,
1093 RelativeIds,
1094 &NamesBuffer,
1095 &UseBuffer);
1096 }
1097 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1098 {
1099 Status = I_RpcMapWin32Status(RpcExceptionCode());
1100 }
1101 RpcEndExcept;
1102
1103 if (NT_SUCCESS(Status))
1104 {
1105 *Names = midl_user_allocate(Count * sizeof(RPC_UNICODE_STRING));
1106 if (*Names == NULL)
1107 {
1108 Status = STATUS_INSUFFICIENT_RESOURCES;
1109 goto done;
1110 }
1111
1112 for (i = 0; i < Count; i++)
1113 {
1114 (*Names)[i].Buffer = midl_user_allocate(NamesBuffer.Element[i].MaximumLength);
1115 if ((*Names)[i].Buffer == NULL)
1116 {
1117 Status = STATUS_INSUFFICIENT_RESOURCES;
1118 goto done;
1119 }
1120 }
1121
1122 for (i = 0; i < Count; i++)
1123 {
1124 (*Names)[i].Length = NamesBuffer.Element[i].Length;
1125 (*Names)[i].MaximumLength = NamesBuffer.Element[i].MaximumLength;
1126
1127 RtlCopyMemory((*Names)[i].Buffer,
1128 NamesBuffer.Element[i].Buffer,
1129 NamesBuffer.Element[i].Length);
1130 }
1131
1132 if (Use != NULL)
1133 {
1134 *Use = midl_user_allocate(Count * sizeof(SID_NAME_USE));
1135 if (*Use == NULL)
1136 {
1137 Status = STATUS_INSUFFICIENT_RESOURCES;
1138 goto done;
1139 }
1140
1141 RtlCopyMemory(*Use,
1142 UseBuffer.Element,
1143 Count * sizeof(SID_NAME_USE));
1144 }
1145 }
1146
1147 done:
1148 if (!NT_SUCCESS(Status))
1149 {
1150 if (*Names != NULL)
1151 {
1152 for (i = 0; i < Count; i++)
1153 {
1154 if ((*Names)[i].Buffer != NULL)
1155 midl_user_free((*Names)[i].Buffer);
1156 }
1157
1158 midl_user_free(*Names);
1159 }
1160
1161 if (Use != NULL && *Use != NULL)
1162 midl_user_free(*Use);
1163 }
1164
1165 if (NamesBuffer.Element != NULL)
1166 {
1167 for (i = 0; i < NamesBuffer.Count; i++)
1168 {
1169 if (NamesBuffer.Element[i].Buffer != NULL)
1170 midl_user_free(NamesBuffer.Element[i].Buffer);
1171 }
1172
1173 midl_user_free(NamesBuffer.Element);
1174 }
1175
1176 if (UseBuffer.Element != NULL)
1177 midl_user_free(UseBuffer.Element);
1178
1179 return 0;
1180 }
1181
1182
1183 NTSTATUS
1184 NTAPI
1185 SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle,
1186 IN ULONG Count,
1187 IN PUNICODE_STRING Names,
1188 OUT PULONG *RelativeIds,
1189 OUT PSID_NAME_USE *Use)
1190 {
1191 SAMPR_ULONG_ARRAY RidBuffer = {0, NULL};
1192 SAMPR_ULONG_ARRAY UseBuffer = {0, NULL};
1193 NTSTATUS Status;
1194
1195 TRACE("SamLookupNamesInDomain(%p %lu %p %p %p)\n",
1196 DomainHandle, Count, Names, RelativeIds, Use);
1197
1198 *RelativeIds = NULL;
1199 *Use = NULL;
1200
1201 RpcTryExcept
1202 {
1203 Status = SamrLookupNamesInDomain((SAMPR_HANDLE)DomainHandle,
1204 Count,
1205 (PRPC_UNICODE_STRING)Names,
1206 &RidBuffer,
1207 &UseBuffer);
1208 }
1209 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1210 {
1211 Status = I_RpcMapWin32Status(RpcExceptionCode());
1212 }
1213 RpcEndExcept;
1214
1215 if (NT_SUCCESS(Status))
1216 {
1217 *RelativeIds = midl_user_allocate(Count * sizeof(ULONG));
1218 if (*RelativeIds == NULL)
1219 {
1220 Status = STATUS_INSUFFICIENT_RESOURCES;
1221 goto done;
1222 }
1223
1224 *Use = midl_user_allocate(Count * sizeof(SID_NAME_USE));
1225 if (*Use == NULL)
1226 {
1227 Status = STATUS_INSUFFICIENT_RESOURCES;
1228 goto done;
1229 }
1230
1231 RtlCopyMemory(*RelativeIds,
1232 RidBuffer.Element,
1233 Count * sizeof(ULONG));
1234
1235 RtlCopyMemory(*Use,
1236 UseBuffer.Element,
1237 Count * sizeof(SID_NAME_USE));
1238 }
1239
1240 done:
1241 if (!NT_SUCCESS(Status))
1242 {
1243 if (*RelativeIds != NULL)
1244 midl_user_free(*RelativeIds);
1245
1246 if (*Use != NULL)
1247 midl_user_free(*Use);
1248 }
1249
1250 if (RidBuffer.Element != NULL)
1251 midl_user_free(RidBuffer.Element);
1252
1253 if (UseBuffer.Element != NULL)
1254 midl_user_free(UseBuffer.Element);
1255
1256 return Status;
1257 }
1258
1259
1260 NTSTATUS
1261 NTAPI
1262 SamOpenAlias(IN SAM_HANDLE DomainHandle,
1263 IN ACCESS_MASK DesiredAccess,
1264 IN ULONG AliasId,
1265 OUT PSAM_HANDLE AliasHandle)
1266 {
1267 NTSTATUS Status;
1268
1269 TRACE("SamOpenAlias(%p 0x%08x %lx %p)\n",
1270 DomainHandle, DesiredAccess, AliasId, AliasHandle);
1271
1272 RpcTryExcept
1273 {
1274 Status = SamrOpenAlias((SAMPR_HANDLE)DomainHandle,
1275 DesiredAccess,
1276 AliasId,
1277 (SAMPR_HANDLE *)AliasHandle);
1278 }
1279 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1280 {
1281 Status = I_RpcMapWin32Status(RpcExceptionCode());
1282 }
1283 RpcEndExcept;
1284
1285 return Status;
1286 }
1287
1288
1289 NTSTATUS
1290 NTAPI
1291 SamOpenDomain(IN SAM_HANDLE ServerHandle,
1292 IN ACCESS_MASK DesiredAccess,
1293 IN PSID DomainId,
1294 OUT PSAM_HANDLE DomainHandle)
1295 {
1296 NTSTATUS Status;
1297
1298 TRACE("SamOpenDomain(%p 0x%08x %p %p)\n",
1299 ServerHandle, DesiredAccess, DomainId, DomainHandle);
1300
1301 RpcTryExcept
1302 {
1303 Status = SamrOpenDomain((SAMPR_HANDLE)ServerHandle,
1304 DesiredAccess,
1305 (PRPC_SID)DomainId,
1306 (SAMPR_HANDLE *)DomainHandle);
1307 }
1308 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1309 {
1310 Status = I_RpcMapWin32Status(RpcExceptionCode());
1311 }
1312 RpcEndExcept;
1313
1314 return Status;
1315 }
1316
1317
1318 NTSTATUS
1319 NTAPI
1320 SamOpenGroup(IN SAM_HANDLE DomainHandle,
1321 IN ACCESS_MASK DesiredAccess,
1322 IN ULONG GroupId,
1323 OUT PSAM_HANDLE GroupHandle)
1324 {
1325 NTSTATUS Status;
1326
1327 TRACE("SamOpenGroup(%p 0x%08x %p %p)\n",
1328 DomainHandle, DesiredAccess, GroupId, GroupHandle);
1329
1330 RpcTryExcept
1331 {
1332 Status = SamrOpenGroup((SAMPR_HANDLE)DomainHandle,
1333 DesiredAccess,
1334 GroupId,
1335 (SAMPR_HANDLE *)GroupHandle);
1336 }
1337 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1338 {
1339 Status = I_RpcMapWin32Status(RpcExceptionCode());
1340 }
1341 RpcEndExcept;
1342
1343 return Status;
1344 }
1345
1346
1347 NTSTATUS
1348 NTAPI
1349 SamOpenUser(IN SAM_HANDLE DomainHandle,
1350 IN ACCESS_MASK DesiredAccess,
1351 IN ULONG UserId,
1352 OUT PSAM_HANDLE UserHandle)
1353 {
1354 NTSTATUS Status;
1355
1356 TRACE("SamOpenUser(%p 0x%08x %lx %p)\n",
1357 DomainHandle, DesiredAccess, UserId, UserHandle);
1358
1359 RpcTryExcept
1360 {
1361 Status = SamrOpenUser((SAMPR_HANDLE)DomainHandle,
1362 DesiredAccess,
1363 UserId,
1364 (SAMPR_HANDLE *)UserHandle);
1365 }
1366 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1367 {
1368 Status = I_RpcMapWin32Status(RpcExceptionCode());
1369 }
1370 RpcEndExcept;
1371
1372 return Status;
1373 }
1374
1375
1376 NTSTATUS
1377 NTAPI
1378 SamQueryInformationAlias(IN SAM_HANDLE AliasHandle,
1379 IN ALIAS_INFORMATION_CLASS AliasInformationClass,
1380 OUT PVOID *Buffer)
1381 {
1382 NTSTATUS Status;
1383
1384 TRACE("SamQueryInformationAlias(%p %lu %p)\n",
1385 AliasHandle, AliasInformationClass, Buffer);
1386
1387 RpcTryExcept
1388 {
1389 Status = SamrQueryInformationAlias((SAMPR_HANDLE)AliasHandle,
1390 AliasInformationClass,
1391 (PSAMPR_ALIAS_INFO_BUFFER *)Buffer);
1392 }
1393 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1394 {
1395 Status = I_RpcMapWin32Status(RpcExceptionCode());
1396 }
1397 RpcEndExcept;
1398
1399 return Status;
1400 }
1401
1402
1403 NTSTATUS
1404 NTAPI
1405 SamQueryInformationDomain(IN SAM_HANDLE DomainHandle,
1406 IN DOMAIN_INFORMATION_CLASS DomainInformationClass,
1407 OUT PVOID *Buffer)
1408 {
1409 NTSTATUS Status;
1410
1411 TRACE("SamQueryInformationDomain(%p %lu %p)\n",
1412 DomainHandle, DomainInformationClass, Buffer);
1413
1414 RpcTryExcept
1415 {
1416 Status = SamrQueryInformationDomain((SAMPR_HANDLE)DomainHandle,
1417 DomainInformationClass,
1418 (PSAMPR_DOMAIN_INFO_BUFFER *)Buffer);
1419 }
1420 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1421 {
1422 Status = I_RpcMapWin32Status(RpcExceptionCode());
1423 }
1424 RpcEndExcept;
1425
1426 return Status;
1427 }
1428
1429
1430 NTSTATUS
1431 NTAPI
1432 SamQueryInformationGroup(IN SAM_HANDLE GroupHandle,
1433 IN GROUP_INFORMATION_CLASS GroupInformationClass,
1434 OUT PVOID *Buffer)
1435 {
1436 NTSTATUS Status;
1437
1438 TRACE("SamQueryInformationGroup(%p %lu %p)\n",
1439 GroupHandle, GroupInformationClass, Buffer);
1440
1441 RpcTryExcept
1442 {
1443 Status = SamrQueryInformationGroup((SAMPR_HANDLE)GroupHandle,
1444 GroupInformationClass,
1445 (PSAMPR_GROUP_INFO_BUFFER *)Buffer);
1446 }
1447 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1448 {
1449 Status = I_RpcMapWin32Status(RpcExceptionCode());
1450 }
1451 RpcEndExcept;
1452
1453 return Status;
1454 }
1455
1456
1457 NTSTATUS
1458 NTAPI
1459 SamQueryInformationUser(IN SAM_HANDLE UserHandle,
1460 IN USER_INFORMATION_CLASS UserInformationClass,
1461 OUT PVOID *Buffer)
1462 {
1463 NTSTATUS Status;
1464
1465 TRACE("SamQueryInformationUser(%p %lu %p)\n",
1466 UserHandle, UserInformationClass, Buffer);
1467
1468 RpcTryExcept
1469 {
1470 Status = SamrQueryInformationUser((SAMPR_HANDLE)UserHandle,
1471 UserInformationClass,
1472 (PSAMPR_USER_INFO_BUFFER *)Buffer);
1473 }
1474 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1475 {
1476 Status = I_RpcMapWin32Status(RpcExceptionCode());
1477 }
1478 RpcEndExcept;
1479
1480 return Status;
1481 }
1482
1483
1484 NTSTATUS
1485 NTAPI
1486 SamQuerySecurityObject(IN SAM_HANDLE ObjectHandle,
1487 IN SECURITY_INFORMATION SecurityInformation,
1488 OUT PSECURITY_DESCRIPTOR *SecurityDescriptor)
1489 {
1490 SAMPR_SR_SECURITY_DESCRIPTOR LocalSecurityDescriptor;
1491 PSAMPR_SR_SECURITY_DESCRIPTOR pLocalSecurityDescriptor;
1492 NTSTATUS Status;
1493
1494 TRACE("SamQuerySecurityObject(%p %lu %p)\n",
1495 ObjectHandle, SecurityInformation, SecurityDescriptor);
1496
1497 LocalSecurityDescriptor.Length = 0;
1498 LocalSecurityDescriptor.SecurityDescriptor = NULL;
1499
1500 RpcTryExcept
1501 {
1502 pLocalSecurityDescriptor = &LocalSecurityDescriptor;
1503
1504 Status = SamrQuerySecurityObject((SAMPR_HANDLE)ObjectHandle,
1505 SecurityInformation,
1506 &pLocalSecurityDescriptor);
1507 }
1508 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1509 {
1510 Status = I_RpcMapWin32Status(RpcExceptionCode());
1511 }
1512 RpcEndExcept;
1513
1514 *SecurityDescriptor = LocalSecurityDescriptor.SecurityDescriptor;
1515
1516 return Status;
1517 }
1518
1519
1520 NTSTATUS
1521 NTAPI
1522 SamRemoveMemberFromAlias(IN SAM_HANDLE AliasHandle,
1523 IN PSID MemberId)
1524 {
1525 NTSTATUS Status;
1526
1527 TRACE("SamRemoveMemberFromAlias(%p %ul)\n",
1528 AliasHandle, MemberId);
1529
1530 RpcTryExcept
1531 {
1532 Status = SamrRemoveMemberFromAlias((SAMPR_HANDLE)AliasHandle,
1533 MemberId);
1534 }
1535 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1536 {
1537 Status = I_RpcMapWin32Status(RpcExceptionCode());
1538 }
1539 RpcEndExcept;
1540
1541 return Status;
1542 }
1543
1544
1545 NTSTATUS
1546 NTAPI
1547 SamRemoveMemberFromForeignDomain(IN SAM_HANDLE DomainHandle,
1548 IN PSID MemberId)
1549 {
1550 NTSTATUS Status;
1551
1552 TRACE("SamRemoveMemberFromForeignDomain(%p %ul)\n",
1553 DomainHandle, MemberId);
1554
1555 RpcTryExcept
1556 {
1557 Status = SamrRemoveMemberFromForeignDomain((SAMPR_HANDLE)DomainHandle,
1558 MemberId);
1559 }
1560 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1561 {
1562 Status = I_RpcMapWin32Status(RpcExceptionCode());
1563 }
1564 RpcEndExcept;
1565
1566 return Status;
1567 }
1568
1569
1570 NTSTATUS
1571 NTAPI
1572 SamRemoveMemberFromGroup(IN SAM_HANDLE GroupHandle,
1573 IN ULONG MemberId)
1574 {
1575 NTSTATUS Status;
1576
1577 TRACE("SamRemoveMemberFromGroup(%p %ul)\n",
1578 GroupHandle, MemberId);
1579
1580 RpcTryExcept
1581 {
1582 Status = SamrRemoveMemberFromGroup((SAMPR_HANDLE)GroupHandle,
1583 MemberId);
1584 }
1585 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1586 {
1587 Status = I_RpcMapWin32Status(RpcExceptionCode());
1588 }
1589 RpcEndExcept;
1590
1591 return Status;
1592 }
1593
1594
1595 NTSTATUS
1596 NTAPI
1597 SamRemoveMultipleMembersFromAlias(IN SAM_HANDLE AliasHandle,
1598 IN PSID *MemberIds,
1599 IN ULONG MemberCount)
1600 {
1601 SAMPR_PSID_ARRAY Buffer;
1602 NTSTATUS Status;
1603
1604 TRACE("SamRemoveMultipleMembersFromAlias(%p %p %lu)\n",
1605 AliasHandle, MemberIds, MemberCount);
1606
1607 if (MemberIds == NULL)
1608 return STATUS_INVALID_PARAMETER_2;
1609
1610 Buffer.Count = MemberCount;
1611 Buffer.Sids = (PSAMPR_SID_INFORMATION)MemberIds;
1612
1613 RpcTryExcept
1614 {
1615 Status = SamrRemoveMultipleMembersFromAlias((SAMPR_HANDLE)AliasHandle,
1616 &Buffer);
1617 }
1618 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1619 {
1620 Status = I_RpcMapWin32Status(RpcExceptionCode());
1621 }
1622 RpcEndExcept;
1623
1624 return Status;
1625 }
1626
1627
1628 NTSTATUS
1629 NTAPI
1630 SamRidToSid(IN SAM_HANDLE ObjectHandle,
1631 IN ULONG Rid,
1632 OUT PSID *Sid)
1633 {
1634 UNIMPLEMENTED;
1635 return STATUS_NOT_IMPLEMENTED;
1636 }
1637
1638
1639 NTSTATUS
1640 NTAPI
1641 SamSetInformationAlias(IN SAM_HANDLE AliasHandle,
1642 IN ALIAS_INFORMATION_CLASS AliasInformationClass,
1643 IN PVOID Buffer)
1644 {
1645 NTSTATUS Status;
1646
1647 TRACE("SamSetInformationAlias(%p %lu %p)\n",
1648 AliasHandle, AliasInformationClass, Buffer);
1649
1650 RpcTryExcept
1651 {
1652 Status = SamrSetInformationAlias((SAMPR_HANDLE)AliasHandle,
1653 AliasInformationClass,
1654 Buffer);
1655 }
1656 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1657 {
1658 Status = I_RpcMapWin32Status(RpcExceptionCode());
1659 }
1660 RpcEndExcept;
1661
1662 return Status;
1663 }
1664
1665
1666 NTSTATUS
1667 NTAPI
1668 SamSetInformationDomain(IN SAM_HANDLE DomainHandle,
1669 IN DOMAIN_INFORMATION_CLASS DomainInformationClass,
1670 IN PVOID Buffer)
1671 {
1672 NTSTATUS Status;
1673
1674 TRACE("SamSetInformationDomain(%p %lu %p)\n",
1675 DomainHandle, DomainInformationClass, Buffer);
1676
1677 RpcTryExcept
1678 {
1679 Status = SamrSetInformationDomain((SAMPR_HANDLE)DomainHandle,
1680 DomainInformationClass,
1681 Buffer);
1682 }
1683 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1684 {
1685 Status = I_RpcMapWin32Status(RpcExceptionCode());
1686 }
1687 RpcEndExcept;
1688
1689 return Status;
1690 }
1691
1692
1693 NTSTATUS
1694 NTAPI
1695 SamSetInformationGroup(IN SAM_HANDLE GroupHandle,
1696 IN GROUP_INFORMATION_CLASS GroupInformationClass,
1697 IN PVOID Buffer)
1698 {
1699 NTSTATUS Status;
1700
1701 TRACE("SamSetInformationGroup(%p %lu %p)\n",
1702 GroupHandle, GroupInformationClass, Buffer);
1703
1704 RpcTryExcept
1705 {
1706 Status = SamrSetInformationGroup((SAMPR_HANDLE)GroupHandle,
1707 GroupInformationClass,
1708 Buffer);
1709 }
1710 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1711 {
1712 Status = I_RpcMapWin32Status(RpcExceptionCode());
1713 }
1714 RpcEndExcept;
1715
1716 return Status;
1717 }
1718
1719
1720 NTSTATUS
1721 NTAPI
1722 SamSetInformationUser(IN SAM_HANDLE UserHandle,
1723 IN USER_INFORMATION_CLASS UserInformationClass,
1724 IN PVOID Buffer)
1725 {
1726 PSAMPR_USER_SET_PASSWORD_INFORMATION PasswordBuffer;
1727 SAMPR_USER_INTERNAL1_INFORMATION Internal1Buffer;
1728 OEM_STRING LmPwdString;
1729 CHAR LmPwdBuffer[15];
1730 NTSTATUS Status;
1731
1732 TRACE("SamSetInformationUser(%p %lu %p)\n",
1733 UserHandle, UserInformationClass, Buffer);
1734
1735 if (UserInformationClass == UserSetPasswordInformation)
1736 {
1737 PasswordBuffer = (PSAMPR_USER_SET_PASSWORD_INFORMATION)Buffer;
1738
1739 /* Calculate the NT hash value of the passord */
1740 Status = SystemFunction007((PUNICODE_STRING)&PasswordBuffer->Password,
1741 (LPBYTE)&Internal1Buffer.EncryptedNtOwfPassword);
1742 if (!NT_SUCCESS(Status))
1743 {
1744 TRACE("SystemFunction007 failed (Status 0x%08lx)\n", Status);
1745 return Status;
1746 }
1747
1748 Internal1Buffer.NtPasswordPresent = TRUE;
1749 Internal1Buffer.LmPasswordPresent = FALSE;
1750
1751 /* Build the LM password */
1752 LmPwdString.Length = 15;
1753 LmPwdString.MaximumLength = 15;
1754 LmPwdString.Buffer = LmPwdBuffer;
1755 ZeroMemory(LmPwdString.Buffer, LmPwdString.MaximumLength);
1756
1757 Status = RtlUpcaseUnicodeStringToOemString(&LmPwdString,
1758 (PUNICODE_STRING)&PasswordBuffer->Password,
1759 FALSE);
1760 if (NT_SUCCESS(Status))
1761 {
1762 /* Calculate the LM hash value of the password */
1763 Status = SystemFunction006(LmPwdString.Buffer,
1764 (LPSTR)&Internal1Buffer.EncryptedLmOwfPassword);
1765 if (NT_SUCCESS(Status))
1766 Internal1Buffer.LmPasswordPresent = TRUE;
1767 }
1768
1769 Internal1Buffer.PasswordExpired = PasswordBuffer->PasswordExpired;
1770
1771 RpcTryExcept
1772 {
1773 Status = SamrSetInformationUser((SAMPR_HANDLE)UserHandle,
1774 UserInternal1Information,
1775 (PVOID)&Internal1Buffer);
1776 }
1777 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1778 {
1779 Status = I_RpcMapWin32Status(RpcExceptionCode());
1780 }
1781 RpcEndExcept;
1782
1783 if (!NT_SUCCESS(Status))
1784 {
1785 TRACE("SamrSetInformation() failed (Status 0x%08lx)\n", Status);
1786 return Status;
1787 }
1788 }
1789
1790 RpcTryExcept
1791 {
1792 Status = SamrSetInformationUser((SAMPR_HANDLE)UserHandle,
1793 UserInformationClass,
1794 Buffer);
1795 }
1796 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1797 {
1798 Status = I_RpcMapWin32Status(RpcExceptionCode());
1799 }
1800 RpcEndExcept;
1801
1802 return Status;
1803 }
1804
1805
1806 NTSTATUS
1807 NTAPI
1808 SamSetMemberAttributesOfGroup(IN SAM_HANDLE GroupHandle,
1809 IN ULONG MemberId,
1810 IN ULONG Attributes)
1811 {
1812 NTSTATUS Status;
1813
1814 TRACE("SamSetMemberAttributesOfGroup(%p %lu 0x%lx)\n",
1815 GroupHandle, MemberId, Attributes);
1816
1817 RpcTryExcept
1818 {
1819 Status = SamrSetMemberAttributesOfGroup((SAMPR_HANDLE)GroupHandle,
1820 MemberId,
1821 Attributes);
1822 }
1823 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1824 {
1825 Status = I_RpcMapWin32Status(RpcExceptionCode());
1826 }
1827 RpcEndExcept;
1828
1829 return Status;
1830 }
1831
1832
1833 NTSTATUS
1834 NTAPI
1835 SamSetSecurityObject(IN SAM_HANDLE ObjectHandle,
1836 IN SECURITY_INFORMATION SecurityInformation,
1837 IN PSECURITY_DESCRIPTOR SecurityDescriptor)
1838 {
1839 SAMPR_SR_SECURITY_DESCRIPTOR DescriptorToPass;
1840 ULONG Length;
1841 NTSTATUS Status;
1842
1843 TRACE("SamSetSecurityObject(%p %lu %p)\n",
1844 ObjectHandle, SecurityInformation, SecurityDescriptor);
1845
1846 /* Retrieve the length of the relative security descriptor */
1847 Length = 0;
1848 Status = RtlMakeSelfRelativeSD(SecurityDescriptor,
1849 NULL,
1850 &Length);
1851 if (Status != STATUS_BUFFER_TOO_SMALL)
1852 return STATUS_INVALID_PARAMETER;
1853
1854
1855 /* Allocate a buffer for the security descriptor */
1856 DescriptorToPass.Length = Length;
1857 DescriptorToPass.SecurityDescriptor = MIDL_user_allocate(Length);
1858 if (DescriptorToPass.SecurityDescriptor == NULL)
1859 return STATUS_INSUFFICIENT_RESOURCES;
1860
1861 /* Convert the given security descriptor to a relative security descriptor */
1862 Status = RtlMakeSelfRelativeSD(SecurityDescriptor,
1863 (PSECURITY_DESCRIPTOR)DescriptorToPass.SecurityDescriptor,
1864 &Length);
1865 if (!NT_SUCCESS(Status))
1866 goto done;
1867
1868 RpcTryExcept
1869 {
1870 Status = SamrSetSecurityObject((SAMPR_HANDLE)ObjectHandle,
1871 SecurityInformation,
1872 &DescriptorToPass);
1873 }
1874 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1875 {
1876 Status = I_RpcMapWin32Status(RpcExceptionCode());
1877 }
1878 RpcEndExcept;
1879
1880 done:
1881 if (DescriptorToPass.SecurityDescriptor != NULL)
1882 MIDL_user_free(DescriptorToPass.SecurityDescriptor);
1883
1884 return Status;
1885 }
1886
1887
1888 NTSTATUS
1889 NTAPI
1890 SamShutdownSamServer(IN SAM_HANDLE ServerHandle)
1891 {
1892 NTSTATUS Status;
1893
1894 TRACE("(%p)\n", ServerHandle);
1895
1896 RpcTryExcept
1897 {
1898 Status = SamrShutdownSamServer((SAMPR_HANDLE)ServerHandle);
1899 }
1900 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1901 {
1902 Status = I_RpcMapWin32Status(RpcExceptionCode());
1903 }
1904 RpcEndExcept;
1905
1906 return Status;
1907 }
1908
1909 /* EOF */