ReactOS 0.4.16-dev-289-g096a551
msv1_0.c
Go to the documentation of this file.
1/*
2 * PROJECT: Authentication Package DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/msv1_0/msv1_0.c
5 * PURPOSE: Main file
6 * COPYRIGHT: Copyright 2013 Eric Kohl
7 */
8
9/* INCLUDES ****************************************************************/
10
11#include "precomp.h"
12
14
15typedef struct _LOGON_LIST_ENTRY
16{
21
22/* GLOBALS *****************************************************************/
23
27
28/* FUNCTIONS ***************************************************************/
29
30static
34 IN PWSTR ComputerName,
37{
39 PVOID ClientBaseAddress = NULL;
40 LPWSTR Ptr;
42 USHORT ComputerNameLength;
44
47
48 if (UIntPtrToUShort(wcslen(ComputerName), &ComputerNameLength) != S_OK)
49 {
51 }
52
54 UserInfo->All.FullName.Length + sizeof(WCHAR) +
55 UserInfo->All.HomeDirectory.Length + sizeof(WCHAR) +
56 UserInfo->All.HomeDirectoryDrive.Length + sizeof(WCHAR) +
57 UserInfo->All.ScriptPath.Length + sizeof(WCHAR) +
58 UserInfo->All.ProfilePath.Length + sizeof(WCHAR) +
59 ((ComputerNameLength + 3) * sizeof(WCHAR));
60
61 LocalBuffer = DispatchTable.AllocateLsaHeap(BufferLength);
62 if (LocalBuffer == NULL)
63 {
64 TRACE("Failed to allocate the local buffer!\n");
66 goto done;
67 }
68
69 Status = DispatchTable.AllocateClientBuffer(ClientRequest,
71 &ClientBaseAddress);
72 if (!NT_SUCCESS(Status))
73 {
74 TRACE("DispatchTable.AllocateClientBuffer failed (Status 0x%08lx)\n", Status);
75 goto done;
76 }
77
78 TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
79
80 Ptr = (LPWSTR)((ULONG_PTR)LocalBuffer + sizeof(MSV1_0_INTERACTIVE_PROFILE));
81
83 LocalBuffer->LogonCount = UserInfo->All.LogonCount;
84 LocalBuffer->BadPasswordCount = UserInfo->All.BadPasswordCount;
85
86 LocalBuffer->LogonTime.LowPart = UserInfo->All.LastLogon.LowPart;
87 LocalBuffer->LogonTime.HighPart = UserInfo->All.LastLogon.HighPart;
88
89 LocalBuffer->LogoffTime.LowPart = UserInfo->All.AccountExpires.LowPart;
90 LocalBuffer->LogoffTime.HighPart = UserInfo->All.AccountExpires.HighPart;
91
92 LocalBuffer->KickOffTime.LowPart = UserInfo->All.AccountExpires.LowPart;
93 LocalBuffer->KickOffTime.HighPart = UserInfo->All.AccountExpires.HighPart;
94
95 LocalBuffer->PasswordLastSet.LowPart = UserInfo->All.PasswordLastSet.LowPart;
96 LocalBuffer->PasswordLastSet.HighPart = UserInfo->All.PasswordLastSet.HighPart;
97
98 LocalBuffer->PasswordCanChange.LowPart = UserInfo->All.PasswordCanChange.LowPart;
99 LocalBuffer->PasswordCanChange.HighPart = UserInfo->All.PasswordCanChange.HighPart;
100
101 LocalBuffer->PasswordMustChange.LowPart = UserInfo->All.PasswordMustChange.LowPart;
102 LocalBuffer->PasswordMustChange.HighPart = UserInfo->All.PasswordMustChange.HighPart;
103
104 LocalBuffer->LogonScript.Length = UserInfo->All.ScriptPath.Length;
105 LocalBuffer->LogonScript.MaximumLength = UserInfo->All.ScriptPath.Length + sizeof(WCHAR);
106 LocalBuffer->LogonScript.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
107 memcpy(Ptr,
108 UserInfo->All.ScriptPath.Buffer,
109 UserInfo->All.ScriptPath.Length);
110
111 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LocalBuffer->LogonScript.MaximumLength);
112
113 LocalBuffer->HomeDirectory.Length = UserInfo->All.HomeDirectory.Length;
114 LocalBuffer->HomeDirectory.MaximumLength = UserInfo->All.HomeDirectory.Length + sizeof(WCHAR);
115 LocalBuffer->HomeDirectory.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
116 memcpy(Ptr,
117 UserInfo->All.HomeDirectory.Buffer,
118 UserInfo->All.HomeDirectory.Length);
119
120 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LocalBuffer->HomeDirectory.MaximumLength);
121
122 LocalBuffer->FullName.Length = UserInfo->All.FullName.Length;
123 LocalBuffer->FullName.MaximumLength = UserInfo->All.FullName.Length + sizeof(WCHAR);
124 LocalBuffer->FullName.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
125 memcpy(Ptr,
126 UserInfo->All.FullName.Buffer,
127 UserInfo->All.FullName.Length);
128 TRACE("FullName.Buffer: %p\n", LocalBuffer->FullName.Buffer);
129
130 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LocalBuffer->FullName.MaximumLength);
131
132 LocalBuffer->ProfilePath.Length = UserInfo->All.ProfilePath.Length;
133 LocalBuffer->ProfilePath.MaximumLength = UserInfo->All.ProfilePath.Length + sizeof(WCHAR);
134 LocalBuffer->ProfilePath.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
135 memcpy(Ptr,
136 UserInfo->All.ProfilePath.Buffer,
137 UserInfo->All.ProfilePath.Length);
138
139 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LocalBuffer->ProfilePath.MaximumLength);
140
141 LocalBuffer->HomeDirectoryDrive.Length = UserInfo->All.HomeDirectoryDrive.Length;
142 LocalBuffer->HomeDirectoryDrive.MaximumLength = UserInfo->All.HomeDirectoryDrive.Length + sizeof(WCHAR);
143 LocalBuffer->HomeDirectoryDrive.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
144 memcpy(Ptr,
145 UserInfo->All.HomeDirectoryDrive.Buffer,
146 UserInfo->All.HomeDirectoryDrive.Length);
147
149
150 LocalBuffer->LogonServer.Length = (ComputerNameLength + 2) * sizeof(WCHAR);
151 LocalBuffer->LogonServer.MaximumLength = LocalBuffer->LogonServer.Length + sizeof(WCHAR);
152 LocalBuffer->LogonServer.Buffer = (LPWSTR)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)Ptr - (ULONG_PTR)LocalBuffer);
153 wcscpy(Ptr, L"\\");
154 wcscat(Ptr, ComputerName);
155
156 LocalBuffer->UserFlags = 0;
157
158 Status = DispatchTable.CopyToClientBuffer(ClientRequest,
160 ClientBaseAddress,
161 LocalBuffer);
162 if (!NT_SUCCESS(Status))
163 {
164 TRACE("DispatchTable.CopyToClientBuffer failed (Status 0x%08lx)\n", Status);
165 goto done;
166 }
167
168 *ProfileBuffer = (PMSV1_0_INTERACTIVE_PROFILE)ClientBaseAddress;
170
171done:
172 if (LocalBuffer != NULL)
173 DispatchTable.FreeLsaHeap(LocalBuffer);
174
175 if (!NT_SUCCESS(Status))
176 {
177 if (ClientBaseAddress != NULL)
178 DispatchTable.FreeClientBuffer(ClientRequest,
179 ClientBaseAddress);
180 }
181
182 return Status;
183}
184
185
186static
189 _In_ PLSA_CLIENT_REQUEST ClientRequest,
191 _In_ PLSA_SAM_PWD_DATA LogonPwdData,
194{
195 PMSV1_0_LM20_LOGON_PROFILE LocalBuffer;
200 UNICODE_STRING ComputerNameUCS;
201
204
205 if (!NtlmUStrAlloc(&ComputerNameUCS, LogonPwdData->ComputerName->Length + sizeof(WCHAR) * 3, 0))
206 {
208 goto done;
209 }
210 Status = RtlAppendUnicodeToString(&ComputerNameUCS, L"\\\\");
211 if (!NT_SUCCESS(Status))
212 {
213 ERR("RtlAppendUnicodeToString failed 0x%lx\n", Status);
214 goto done;
215 }
216 Status = RtlAppendUnicodeStringToString(&ComputerNameUCS, LogonPwdData->ComputerName);
217 if (!NT_SUCCESS(Status))
218 {
219 ERR("RtlAppendUnicodeStringToString failed 0x%lx\n", Status);
220 goto done;
221 }
222
223 BufferLength = sizeof(MSV1_0_LM20_LOGON_PROFILE) + ComputerNameUCS.Length + sizeof(WCHAR);
224
226 if (!NT_SUCCESS(Status))
227 {
228 TRACE("DispatchTable.AllocateClientBuffer failed (Status 0x%08lx)\n", Status);
229 goto done;
230 }
231
232 TRACE("ClientBaseAddress: %p\n", Buffer.ClientBaseAddress);
233
234 LocalBuffer = (PMSV1_0_LM20_LOGON_PROFILE)Buffer.LocalBuffer;
235 PtrOffset = (PBYTE)(LocalBuffer + 1);
236
237 LocalBuffer->MessageType = MsV1_0Lm20LogonProfile;
238 LocalBuffer->KickOffTime.LowPart = UserInfo->All.AccountExpires.LowPart;
239 LocalBuffer->KickOffTime.HighPart = UserInfo->All.AccountExpires.HighPart;
240 LocalBuffer->LogoffTime.LowPart = UserInfo->All.AccountExpires.LowPart;
241 LocalBuffer->LogoffTime.HighPart = UserInfo->All.AccountExpires.HighPart;
242
243 memcpy(LocalBuffer->UserSessionKey,
244 &LogonPwdData->UserSessionKey,
246
247 //FIXME: Set Domainname if we domain joined
248 // what to do if not? WORKGROUP
250
251 memcpy(LocalBuffer->LanmanSessionKey,
252 &LogonPwdData->LanmanSessionKey,
254
255 if (!NtlmUStrWriteToStruct(LocalBuffer,
257 &LocalBuffer->LogonServer,
258 &ComputerNameUCS,
259 &PtrOffset,
260 TRUE))
261 {
262 ERR("NtlmStructWriteUCS failed.\n");
264 goto done;
265 }
266 /* not supported */
268 /* Build user flags */
269 LocalBuffer->UserFlags = 0x0;
270 if (LogonPwdData->LogonType == NetLogonLmKey)
271 LocalBuffer->UserFlags |= LOGON_USED_LM_PASSWORD;
272
273 /* copy data to client buffer */
275 if (!NT_SUCCESS(Status))
276 {
277 TRACE("DispatchTable.CopyToClientBuffer failed (Status 0x%08lx)\n", Status);
278 goto done;
279 }
280
281 *ProfileBuffer = (PMSV1_0_LM20_LOGON_PROFILE)Buffer.ClientBaseAddress;
283done:
284 /* On success Buffer.ClientBaseAddress will not be free */
285 NtlmFreeClientBuffer(ClientRequest, !NT_SUCCESS(Status), &Buffer);
286 NtlmUStrFree(&ComputerNameUCS);
287 return Status;
288}
289
290static
291PSID
293 ULONG Rid)
294{
295 PSID DstSid = NULL;
296 UCHAR RidCount;
297
298 RidCount = *RtlSubAuthorityCountSid(SrcSid);
299 if (RidCount >= 8)
300 return NULL;
301
302 DstSid = DispatchTable.AllocateLsaHeap(RtlLengthRequiredSid(RidCount + 1));
303 if (DstSid == NULL)
304 return NULL;
305
306 RtlCopyMemory(DstSid,
307 SrcSid,
308 RtlLengthRequiredSid(RidCount));
309
310 *RtlSubAuthorityCountSid(DstSid) = RidCount + 1;
311 *RtlSubAuthoritySid(DstSid, RidCount) = Rid;
312
313 return DstSid;
314}
315
316
317static
321 IN ULONG RelativeId)
322{
323 User->User.Sid = AppendRidToSid(AccountDomainSid,
324 RelativeId);
325 if (User->User.Sid == NULL)
326 {
327 ERR("Could not create the user SID\n");
329 }
330
331 User->User.Attributes = 0;
332
333 return STATUS_SUCCESS;
334}
335
336
337static
341 IN ULONG RelativeId)
342{
344 RelativeId);
345 if (PrimaryGroup->PrimaryGroup == NULL)
346 {
347 ERR("Could not create the primary group SID\n");
349 }
350
351 return STATUS_SUCCESS;
352}
353
354
355static
359 IN ULONG RelativeId,
360 IN BOOL SpecialAccount)
361{
364 DWORD GroupCount = 0;
365 DWORD MaxGroups = 2;
366 PSID Sid;
368
369 if (SpecialAccount)
370 MaxGroups++;
371
372 TokenGroups = DispatchTable.AllocateLsaHeap(sizeof(TOKEN_GROUPS) +
373 MaxGroups * sizeof(SID_AND_ATTRIBUTES));
374 if (TokenGroups == NULL)
375 {
377 }
378
379 if (SpecialAccount)
380 {
381 /* Self */
382 Sid = AppendRidToSid(AccountDomainSid, RelativeId);
383 if (Sid == NULL)
384 {
385
386 }
387
388 TokenGroups->Groups[GroupCount].Sid = Sid;
389 TokenGroups->Groups[GroupCount].Attributes =
391 GroupCount++;
392
393 /* Member of 'Users' alias */
395 2,
404 &Sid);
405 TokenGroups->Groups[GroupCount].Sid = Sid;
406 TokenGroups->Groups[GroupCount].Attributes =
408 GroupCount++;
409 }
410 else
411 {
412 /* Member of the domains users group */
414 if (Sid == NULL)
415 {
416
417 }
418
419 TokenGroups->Groups[GroupCount].Sid = Sid;
420 TokenGroups->Groups[GroupCount].Attributes =
422 GroupCount++;
423 }
424
425 /* Member of 'Authenticated users' */
427 1,
436 &Sid);
437 TokenGroups->Groups[GroupCount].Sid = Sid;
438 TokenGroups->Groups[GroupCount].Attributes =
440 GroupCount++;
441
442 TokenGroups->GroupCount = GroupCount;
443 ASSERT(TokenGroups->GroupCount <= MaxGroups);
444
445 *Groups = TokenGroups;
446
447 return Status;
448}
449
450
451static
456 BOOL SpecialAccount)
457{
459 ULONG i;
461
462 Buffer = DispatchTable.AllocateLsaHeap(sizeof(LSA_TOKEN_INFORMATION_V1));
463 if (Buffer == NULL)
464 {
465 WARN("Failed to allocate the local buffer!\n");
467 goto done;
468 }
469
470 Buffer->ExpirationTime.LowPart = UserInfo->All.AccountExpires.LowPart;
471 Buffer->ExpirationTime.HighPart = UserInfo->All.AccountExpires.HighPart;
472
475 UserInfo->All.UserId);
476 if (!NT_SUCCESS(Status))
477 {
478 WARN("BuildTokenUser() failed (Status 0x%08lx)\n", Status);
479 goto done;
480 }
481
482 Status = BuildTokenPrimaryGroup(&Buffer->PrimaryGroup,
484 UserInfo->All.PrimaryGroupId);
485 if (!NT_SUCCESS(Status))
486 {
487 WARN("BuildTokenPrimaryGroup() failed (Status 0x%08lx)\n", Status);
488 goto done;
489 }
490
491 Status = BuildTokenGroups(&Buffer->Groups,
493 UserInfo->All.UserId,
494 SpecialAccount);
495 if (!NT_SUCCESS(Status))
496 {
497 WARN("BuildTokenGroups() failed (Status 0x%08lx)\n", Status);
498 goto done;
499 }
500
501 *TokenInformation = Buffer;
502
503done:
504 if (!NT_SUCCESS(Status))
505 {
506 if (Buffer != NULL)
507 {
508 if (Buffer->User.User.Sid != NULL)
509 DispatchTable.FreeLsaHeap(Buffer->User.User.Sid);
510
511 if (Buffer->Groups != NULL)
512 {
513 for (i = 0; i < Buffer->Groups->GroupCount; i++)
514 {
515 if (Buffer->Groups->Groups[i].Sid != NULL)
516 DispatchTable.FreeLsaHeap(Buffer->Groups->Groups[i].Sid);
517 }
518
519 DispatchTable.FreeLsaHeap(Buffer->Groups);
520 }
521
522 if (Buffer->PrimaryGroup.PrimaryGroup != NULL)
523 DispatchTable.FreeLsaHeap(Buffer->PrimaryGroup.PrimaryGroup);
524
525 if (Buffer->DefaultDacl.DefaultDacl != NULL)
526 DispatchTable.FreeLsaHeap(Buffer->DefaultDacl.DefaultDacl);
527
528 DispatchTable.FreeLsaHeap(Buffer);
529 }
530 }
531
532 return Status;
533}
534
535
536static
539 IN PVOID ProtocolSubmitBuffer,
540 IN PVOID ClientBufferBase,
541 IN ULONG SubmitBufferLength,
542 OUT PVOID *ProtocolReturnBuffer,
543 OUT PULONG ReturnBufferLength,
545{
547 PMSV1_0_CHANGEPASSWORD_REQUEST RequestBuffer;
549
550 SAMPR_HANDLE ServerHandle = NULL;
551 SAMPR_HANDLE DomainHandle = NULL;
552 SAMPR_HANDLE UserHandle = NULL;
553 PRPC_SID DomainSid = NULL;
555 SAMPR_ULONG_ARRAY RelativeIds = {0, NULL};
556 SAMPR_ULONG_ARRAY Use = {0, NULL};
557
558 ENCRYPTED_NT_OWF_PASSWORD OldNtPassword;
559 ENCRYPTED_NT_OWF_PASSWORD NewNtPassword;
560 ENCRYPTED_LM_OWF_PASSWORD OldLmPassword;
561 ENCRYPTED_LM_OWF_PASSWORD NewLmPassword;
562 OEM_STRING LmPwdString;
563 CHAR LmPwdBuffer[15];
564 BOOLEAN OldLmPasswordPresent = FALSE;
565 BOOLEAN NewLmPasswordPresent = FALSE;
566
567 ENCRYPTED_LM_OWF_PASSWORD OldLmEncryptedWithNewLm;
568 ENCRYPTED_LM_OWF_PASSWORD NewLmEncryptedWithOldLm;
569 ENCRYPTED_LM_OWF_PASSWORD OldNtEncryptedWithNewNt;
570 ENCRYPTED_LM_OWF_PASSWORD NewNtEncryptedWithOldNt;
571 PENCRYPTED_LM_OWF_PASSWORD pOldLmEncryptedWithNewLm = NULL;
572 PENCRYPTED_LM_OWF_PASSWORD pNewLmEncryptedWithOldLm = NULL;
573
574 TRACE("MsvpChangePassword()\n");
575
576 /* Parameters validation */
577
578 if (SubmitBufferLength < sizeof(MSV1_0_CHANGEPASSWORD_REQUEST))
579 {
580 ERR("Invalid SubmitBufferLength %lu\n", SubmitBufferLength);
582 }
583
584 RequestBuffer = (PMSV1_0_CHANGEPASSWORD_REQUEST)ProtocolSubmitBuffer;
585
586 /* Fix-up pointers in the request buffer info */
587 PtrOffset = (ULONG_PTR)ProtocolSubmitBuffer - (ULONG_PTR)ClientBufferBase;
588
589 Status = RtlValidateUnicodeString(0, &RequestBuffer->DomainName);
590 if (!NT_SUCCESS(Status))
592 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
593 RequestBuffer->DomainName.Buffer = FIXUP_POINTER(RequestBuffer->DomainName.Buffer, PtrOffset);
594 RequestBuffer->DomainName.MaximumLength = RequestBuffer->DomainName.Length;
595
596 Status = RtlValidateUnicodeString(0, &RequestBuffer->AccountName);
597 if (!NT_SUCCESS(Status))
599 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
600 RequestBuffer->AccountName.Buffer = FIXUP_POINTER(RequestBuffer->AccountName.Buffer, PtrOffset);
601 RequestBuffer->AccountName.MaximumLength = RequestBuffer->AccountName.Length;
602
603 Status = RtlValidateUnicodeString(0, &RequestBuffer->OldPassword);
604 if (!NT_SUCCESS(Status))
606 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
607 RequestBuffer->OldPassword.Buffer = FIXUP_POINTER(RequestBuffer->OldPassword.Buffer, PtrOffset);
608 RequestBuffer->OldPassword.MaximumLength = RequestBuffer->OldPassword.Length;
609
610 Status = RtlValidateUnicodeString(0, &RequestBuffer->NewPassword);
611 if (!NT_SUCCESS(Status))
613 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
614 RequestBuffer->NewPassword.Buffer = FIXUP_POINTER(RequestBuffer->NewPassword.Buffer, PtrOffset);
615 RequestBuffer->NewPassword.MaximumLength = RequestBuffer->NewPassword.Length;
616
617 TRACE("Domain: %S\n", RequestBuffer->DomainName.Buffer);
618 TRACE("Account: %S\n", RequestBuffer->AccountName.Buffer);
619 TRACE("Old Password: %S\n", RequestBuffer->OldPassword.Buffer);
620 TRACE("New Password: %S\n", RequestBuffer->NewPassword.Buffer);
621
622 /* Connect to the SAM server */
624 &ServerHandle,
626 TRUE);
627 if (!NT_SUCCESS(Status))
628 {
629 TRACE("SamIConnect() failed (Status 0x%08lx)\n", Status);
630 goto done;
631 }
632
633 /* Get the domain SID */
634 Status = SamrLookupDomainInSamServer(ServerHandle,
635 (PRPC_UNICODE_STRING)&RequestBuffer->DomainName,
636 &DomainSid);
637 if (!NT_SUCCESS(Status))
638 {
639 TRACE("SamrLookupDomainInSamServer failed (Status %08lx)\n", Status);
640 goto done;
641 }
642
643 /* Open the domain */
644 Status = SamrOpenDomain(ServerHandle,
646 DomainSid,
647 &DomainHandle);
648 if (!NT_SUCCESS(Status))
649 {
650 TRACE("SamrOpenDomain failed (Status %08lx)\n", Status);
651 goto done;
652 }
653
654 Names[0].Length = RequestBuffer->AccountName.Length;
655 Names[0].MaximumLength = RequestBuffer->AccountName.MaximumLength;
656 Names[0].Buffer = RequestBuffer->AccountName.Buffer;
657
658 /* Try to get the RID for the user name */
659 Status = SamrLookupNamesInDomain(DomainHandle,
660 1,
661 Names,
662 &RelativeIds,
663 &Use);
664 if (!NT_SUCCESS(Status))
665 {
666 TRACE("SamrLookupNamesInDomain failed (Status %08lx)\n", Status);
668 goto done;
669 }
670
671 /* Fail, if it is not a user account */
672 if (Use.Element[0] != SidTypeUser)
673 {
674 TRACE("Account is not a user account!\n");
676 goto done;
677 }
678
679 /* Open the user object */
680 Status = SamrOpenUser(DomainHandle,
682 RelativeIds.Element[0],
683 &UserHandle);
684 if (!NT_SUCCESS(Status))
685 {
686 TRACE("SamrOpenUser failed (Status %08lx)\n", Status);
687 goto done;
688 }
689
690
691 /* Calculate the NT hash for the old password */
692 Status = SystemFunction007(&RequestBuffer->OldPassword,
693 (LPBYTE)&OldNtPassword);
694 if (!NT_SUCCESS(Status))
695 {
696 TRACE("SystemFunction007 failed (Status 0x%08lx)\n", Status);
697 goto done;
698 }
699
700 /* Calculate the NT hash for the new password */
701 Status = SystemFunction007(&RequestBuffer->NewPassword,
702 (LPBYTE)&NewNtPassword);
703 if (!NT_SUCCESS(Status))
704 {
705 TRACE("SystemFunction007 failed (Status 0x%08lx)\n", Status);
706 goto done;
707 }
708
709 /* Calculate the LM password and hash for the old password */
710 LmPwdString.Length = 15;
711 LmPwdString.MaximumLength = 15;
712 LmPwdString.Buffer = LmPwdBuffer;
713 ZeroMemory(LmPwdString.Buffer, LmPwdString.MaximumLength);
714
716 &RequestBuffer->OldPassword,
717 FALSE);
718 if (NT_SUCCESS(Status))
719 {
720 /* Calculate the LM hash value of the password */
721 Status = SystemFunction006(LmPwdString.Buffer,
722 (LPSTR)&OldLmPassword);
723 if (NT_SUCCESS(Status))
724 {
725 OldLmPasswordPresent = TRUE;
726 }
727 }
728
729 /* Calculate the LM password and hash for the new password */
730 LmPwdString.Length = 15;
731 LmPwdString.MaximumLength = 15;
732 LmPwdString.Buffer = LmPwdBuffer;
733 ZeroMemory(LmPwdString.Buffer, LmPwdString.MaximumLength);
734
736 &RequestBuffer->NewPassword,
737 FALSE);
738 if (NT_SUCCESS(Status))
739 {
740 /* Calculate the LM hash value of the password */
741 Status = SystemFunction006(LmPwdString.Buffer,
742 (LPSTR)&NewLmPassword);
743 if (NT_SUCCESS(Status))
744 {
745 NewLmPasswordPresent = TRUE;
746 }
747 }
748
749 /* Encrypt the old and new LM passwords, if they exist */
750 if (OldLmPasswordPresent && NewLmPasswordPresent)
751 {
752 /* Encrypt the old LM password */
753 Status = SystemFunction012((const BYTE *)&OldLmPassword,
754 (const BYTE *)&NewLmPassword,
755 (LPBYTE)&OldLmEncryptedWithNewLm);
756 if (!NT_SUCCESS(Status))
757 {
758 TRACE("SystemFunction012 failed (Status 0x%08lx)\n", Status);
759 goto done;
760 }
761
762 /* Encrypt the new LM password */
763 Status = SystemFunction012((const BYTE *)&NewLmPassword,
764 (const BYTE *)&OldLmPassword,
765 (LPBYTE)&NewLmEncryptedWithOldLm);
766 if (!NT_SUCCESS(Status))
767 {
768 TRACE("SystemFunction012 failed (Status 0x%08lx)\n", Status);
769 goto done;
770 }
771
772 pOldLmEncryptedWithNewLm = &OldLmEncryptedWithNewLm;
773 pNewLmEncryptedWithOldLm = &NewLmEncryptedWithOldLm;
774 }
775
776 /* Encrypt the old NT password */
777 Status = SystemFunction012((const BYTE *)&OldNtPassword,
778 (const BYTE *)&NewNtPassword,
779 (LPBYTE)&OldNtEncryptedWithNewNt);
780 if (!NT_SUCCESS(Status))
781 {
782 TRACE("SystemFunction012 failed (Status 0x%08lx)\n", Status);
783 goto done;
784 }
785
786 /* Encrypt the new NT password */
787 Status = SystemFunction012((const BYTE *)&NewNtPassword,
788 (const BYTE *)&OldNtPassword,
789 (LPBYTE)&NewNtEncryptedWithOldNt);
790 if (!NT_SUCCESS(Status))
791 {
792 TRACE("SystemFunction012 failed (Status 0x%08lx)\n", Status);
793 goto done;
794 }
795
796 /* Change the password */
797 Status = SamrChangePasswordUser(UserHandle,
798 OldLmPasswordPresent && NewLmPasswordPresent,
799 pOldLmEncryptedWithNewLm,
800 pNewLmEncryptedWithOldLm,
801 TRUE,
802 &OldNtEncryptedWithNewNt,
803 &NewNtEncryptedWithOldNt,
804 FALSE,
805 NULL,
806 FALSE,
807 NULL);
808 if (!NT_SUCCESS(Status))
809 {
810 TRACE("SamrChangePasswordUser failed (Status %08lx)\n", Status);
811 goto done;
812 }
813
814done:
815 if (UserHandle != NULL)
816 SamrCloseHandle(&UserHandle);
817
818 SamIFree_SAMPR_ULONG_ARRAY(&RelativeIds);
820
821 if (DomainHandle != NULL)
822 SamrCloseHandle(&DomainHandle);
823
824 if (DomainSid != NULL)
825 SamIFreeVoid(DomainSid);
826
827 if (ServerHandle != NULL)
828 SamrCloseHandle(&ServerHandle);
829
830 return Status;
831}
832
833
834static
837 _In_ PLSA_CLIENT_REQUEST ClientRequest,
838 _In_ PVOID ProtocolSubmitBuffer,
839 _In_ PVOID ClientBufferBase,
840 _In_ ULONG SubmitBufferLength,
841 _Out_ PVOID *ProtocolReturnBuffer,
842 _Out_ PULONG ReturnBufferLength,
844{
845 PMSV1_0_ENUMUSERS_RESPONSE LocalBuffer = NULL;
846 PVOID ClientBaseAddress = NULL;
848 PLIST_ENTRY CurrentEntry;
849 PLOGON_LIST_ENTRY LogonEntry;
850 ULONG LogonCount = 0;
851 PLUID LuidPtr;
852 PULONG EnumPtr;
854
855 TRACE("MsvpEnumerateUsers()\n");
856
857 /* Count the currently logged-on users */
858 CurrentEntry = LogonListHead.Flink;
859 while (CurrentEntry != &LogonListHead)
860 {
861 LogonEntry = CONTAINING_RECORD(CurrentEntry,
863 ListEntry);
864
865 TRACE("Logon %lu: 0x%08lx\n", LogonCount, LogonEntry->LogonId.LowPart);
866 LogonCount++;
867
868 CurrentEntry = CurrentEntry->Flink;
869 }
870
871 TRACE("LogonCount %lu\n", LogonCount);
872
874 (LogonCount * sizeof(LUID)) +
875 (LogonCount * sizeof(ULONG));
876
877 LocalBuffer = DispatchTable.AllocateLsaHeap(BufferLength);
878 if (LocalBuffer == NULL)
879 {
880 ERR("Failed to allocate the local buffer!\n");
882 goto done;
883 }
884
885 Status = DispatchTable.AllocateClientBuffer(ClientRequest,
887 &ClientBaseAddress);
888 if (!NT_SUCCESS(Status))
889 {
890 ERR("DispatchTable.AllocateClientBuffer failed (Status 0x%08lx)\n", Status);
891 goto done;
892 }
893
894 TRACE("ClientBaseAddress: %p\n", ClientBaseAddress);
895
896 /* Fill the local buffer */
897 LocalBuffer->MessageType = MsV1_0EnumerateUsers;
898 LocalBuffer->NumberOfLoggedOnUsers = LogonCount;
899
900 LuidPtr = (PLUID)((ULONG_PTR)LocalBuffer + sizeof(MSV1_0_ENUMUSERS_RESPONSE));
901 EnumPtr = (PULONG)((ULONG_PTR)LuidPtr + LogonCount * sizeof(LUID));
902
903 LocalBuffer->LogonIds = (PLUID)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)LuidPtr - (ULONG_PTR)LocalBuffer);
904 LocalBuffer->EnumHandles = (PULONG)((ULONG_PTR)ClientBaseAddress + (ULONG_PTR)EnumPtr - (ULONG_PTR)LocalBuffer);
905
906 /* Copy the LogonIds and EnumHandles into the local buffer */
907 CurrentEntry = LogonListHead.Flink;
908 while (CurrentEntry != &LogonListHead)
909 {
910 LogonEntry = CONTAINING_RECORD(CurrentEntry,
912 ListEntry);
913
914 TRACE("Logon: 0x%08lx %lu\n", LogonEntry->LogonId.LowPart, LogonEntry->EnumHandle);
915 RtlCopyMemory(LuidPtr, &LogonEntry->LogonId, sizeof(LUID));
916 LuidPtr++;
917
918 *EnumPtr = LogonEntry->EnumHandle;
919 EnumPtr++;
920
921 CurrentEntry = CurrentEntry->Flink;
922 }
923
924 Status = DispatchTable.CopyToClientBuffer(ClientRequest,
926 ClientBaseAddress,
927 LocalBuffer);
928 if (!NT_SUCCESS(Status))
929 {
930 ERR("DispatchTable.CopyToClientBuffer failed (Status 0x%08lx)\n", Status);
931 goto done;
932 }
933
934 *ProtocolReturnBuffer = (PMSV1_0_INTERACTIVE_PROFILE)ClientBaseAddress;
935 *ReturnBufferLength = BufferLength;
937
938done:
939 if (LocalBuffer != NULL)
940 DispatchTable.FreeLsaHeap(LocalBuffer);
941
942 if (!NT_SUCCESS(Status))
943 {
944 if (ClientBaseAddress != NULL)
945 DispatchTable.FreeClientBuffer(ClientRequest,
946 ClientBaseAddress);
947 }
948
949 return STATUS_SUCCESS;
950}
951
952
953/*
954 * @unimplemented
955 */
957NTAPI
959 IN PVOID ProtocolSubmitBuffer,
960 IN PVOID ClientBufferBase,
961 IN ULONG SubmitBufferLength,
962 OUT PVOID *ProtocolReturnBuffer,
963 OUT PULONG ReturnBufferLength,
965{
968
969 TRACE("LsaApCallPackage()\n");
970
971 if (SubmitBufferLength < sizeof(MSV1_0_PROTOCOL_MESSAGE_TYPE))
973
974 MessageType = *((PMSV1_0_PROTOCOL_MESSAGE_TYPE)ProtocolSubmitBuffer);
975
976 *ProtocolReturnBuffer = NULL;
977 *ReturnBufferLength = 0;
978
979 switch (MessageType)
980 {
984 break;
985
987 Status = MsvpEnumerateUsers(ClientRequest,
988 ProtocolSubmitBuffer,
989 ClientBufferBase,
990 SubmitBufferLength,
991 ProtocolReturnBuffer,
992 ReturnBufferLength,
994 break;
995
999 break;
1000
1002 Status = MsvpChangePassword(ClientRequest,
1003 ProtocolSubmitBuffer,
1004 ClientBufferBase,
1005 SubmitBufferLength,
1006 ProtocolReturnBuffer,
1007 ReturnBufferLength,
1009 break;
1010
1013 case MsV1_0CacheLogon:
1014 case MsV1_0SubAuth:
1016 case MsV1_0CacheLookup:
1018 break;
1019
1020 default:
1022 }
1023
1024 return Status;
1025}
1026
1027
1028/*
1029 * @unimplemented
1030 */
1032NTAPI
1034 IN PVOID ProtocolSubmitBuffer,
1035 IN PVOID ClientBufferBase,
1036 IN ULONG SubmitBufferLength,
1037 OUT PVOID *ProtocolReturnBuffer,
1038 OUT PULONG ReturnBufferLength,
1040{
1041 TRACE("LsaApCallPackagePassthrough()\n");
1043}
1044
1045
1046/*
1047 * @implemented
1048 */
1050NTAPI
1052 IN PVOID ProtocolSubmitBuffer,
1053 IN PVOID ClientBufferBase,
1054 IN ULONG SubmitBufferLength,
1055 OUT PVOID *ProtocolReturnBuffer,
1056 OUT PULONG ReturnBufferLength,
1058{
1059 ULONG MessageType;
1061
1062 TRACE("LsaApCallPackageUntrusted()\n");
1063
1064 if (SubmitBufferLength < sizeof(MSV1_0_PROTOCOL_MESSAGE_TYPE))
1066
1067 MessageType = (ULONG)*((PMSV1_0_PROTOCOL_MESSAGE_TYPE)ProtocolSubmitBuffer);
1068
1069 *ProtocolReturnBuffer = NULL;
1070 *ReturnBufferLength = 0;
1071
1072 if (MessageType == MsV1_0ChangePassword)
1073 Status = MsvpChangePassword(ClientRequest,
1074 ProtocolSubmitBuffer,
1075 ClientBufferBase,
1076 SubmitBufferLength,
1077 ProtocolReturnBuffer,
1078 ReturnBufferLength,
1080 else
1082
1083 return Status;
1084}
1085
1086
1087/*
1088 * @implemented
1089 */
1091NTAPI
1092LsaApInitializePackage(IN ULONG AuthenticationPackageId,
1093 IN PLSA_DISPATCH_TABLE LsaDispatchTable,
1095 IN PLSA_STRING Confidentiality OPTIONAL,
1096 OUT PLSA_STRING *AuthenticationPackageName)
1097{
1098 PANSI_STRING NameString;
1099 PCHAR NameBuffer;
1100
1101 TRACE("LsaApInitializePackage(%lu %p %p %p %p)\n",
1102 AuthenticationPackageId, LsaDispatchTable, Database,
1103 Confidentiality, AuthenticationPackageName);
1104
1105 if (!PackageInitialized)
1106 {
1108 EnumCounter = 0;
1110 }
1111
1112 /* Get the dispatch table entries */
1113 DispatchTable.CreateLogonSession = LsaDispatchTable->CreateLogonSession;
1114 DispatchTable.DeleteLogonSession = LsaDispatchTable->DeleteLogonSession;
1115 DispatchTable.AddCredential = LsaDispatchTable->AddCredential;
1116 DispatchTable.GetCredentials = LsaDispatchTable->GetCredentials;
1117 DispatchTable.DeleteCredential = LsaDispatchTable->DeleteCredential;
1118 DispatchTable.AllocateLsaHeap = LsaDispatchTable->AllocateLsaHeap;
1119 DispatchTable.FreeLsaHeap = LsaDispatchTable->FreeLsaHeap;
1120 DispatchTable.AllocateClientBuffer = LsaDispatchTable->AllocateClientBuffer;
1121 DispatchTable.FreeClientBuffer = LsaDispatchTable->FreeClientBuffer;
1122 DispatchTable.CopyToClientBuffer = LsaDispatchTable->CopyToClientBuffer;
1123 DispatchTable.CopyFromClientBuffer = LsaDispatchTable->CopyFromClientBuffer;
1124
1125 /* Return the package name */
1126 NameString = DispatchTable.AllocateLsaHeap(sizeof(LSA_STRING));
1127 if (NameString == NULL)
1129
1130 NameBuffer = DispatchTable.AllocateLsaHeap(sizeof(MSV1_0_PACKAGE_NAME));
1131 if (NameBuffer == NULL)
1132 {
1133 DispatchTable.FreeLsaHeap(NameString);
1135 }
1136
1137 strcpy(NameBuffer, MSV1_0_PACKAGE_NAME);
1138
1139 RtlInitAnsiString(NameString, NameBuffer);
1140
1141 *AuthenticationPackageName = (PLSA_STRING)NameString;
1142
1143 return STATUS_SUCCESS;
1144}
1145
1146
1147/*
1148 * @unimplemented
1149 */
1150VOID
1151NTAPI
1153{
1154 TRACE("LsaApLogonTerminated()\n");
1155}
1156
1157
1158/*
1159 * Handle Network logon
1160 */
1161static
1164 _In_ PLSA_CLIENT_REQUEST ClientRequest,
1165 _In_ PVOID ProtocolSubmitBuffer,
1166 _In_ PVOID ClientBufferBase,
1167 _In_ ULONG SubmitBufferSize,
1168 _In_ PUNICODE_STRING ComputerName,
1169 _Out_ PUNICODE_STRING* LogonUserRef,
1170 _Out_ PUNICODE_STRING* LogonDomainRef,
1171 _Inout_ PLSA_SAM_PWD_DATA LogonPwdData,
1172 _Out_ SAMPR_HANDLE* UserHandlePtr,
1173 _Out_ PSAMPR_USER_INFO_BUFFER* UserInfoPtr,
1174 _Out_ PRPC_SID* AccountDomainSidPtr,
1175 _Out_ PBOOL SpecialAccount,
1176 _Out_ PMSV1_0_LM20_LOGON_PROFILE *LogonProfile,
1177 _Out_ PULONG LogonProfileSize,
1179{
1181 PMSV1_0_LM20_LOGON LogonInfo;
1183
1184 *LogonProfile = NULL;
1185 *LogonProfileSize = 0;
1186 *UserInfoPtr = NULL;
1187 *AccountDomainSidPtr = NULL;
1188 *SpecialAccount = FALSE;
1189 LogonInfo = ProtocolSubmitBuffer;
1190
1191 if (SubmitBufferSize < sizeof(MSV1_0_LM20_LOGON))
1192 {
1193 ERR("Invalid SubmitBufferSize %lu\n", SubmitBufferSize);
1195 }
1196
1197 /* Fix-up pointers in the authentication info */
1198 PtrOffset = (ULONG_PTR)ProtocolSubmitBuffer - (ULONG_PTR)ClientBufferBase;
1199
1200 if ((!NtlmFixupAndValidateUStr(&LogonInfo->LogonDomainName, PtrOffset)) ||
1201 (!NtlmFixupAndValidateUStr(&LogonInfo->UserName, PtrOffset)) ||
1205 {
1207 }
1208
1209 LogonPwdData->IsNetwork = TRUE;
1210 LogonPwdData->LogonInfo = LogonInfo;
1211 LogonPwdData->ComputerName = ComputerName;
1213 &LogonInfo->UserName,
1214 &LogonInfo->LogonDomainName,
1215 LogonPwdData,
1216 ComputerName,
1217 SpecialAccount,
1218 AccountDomainSidPtr,
1219 UserHandlePtr,
1220 UserInfoPtr,
1221 SubStatus);
1222 if (!NT_SUCCESS(Status))
1223 {
1224 ERR("SamValidateUser failed with 0x%lx\n", Status);
1225 return Status;
1226 }
1227
1229 {
1230 Status = BuildLm20LogonProfileBuffer(ClientRequest,
1231 *UserInfoPtr,
1232 LogonPwdData,
1233 LogonProfile,
1234 LogonProfileSize);
1235 if (!NT_SUCCESS(Status))
1236 {
1237 ERR("BuildLm20LogonProfileBuffer failed with 0x%lx\n", Status);
1238 return Status;
1239 }
1240 }
1241
1242 *LogonUserRef = &LogonInfo->UserName;
1243 *LogonDomainRef = &LogonInfo->LogonDomainName;
1244
1245 return Status;
1246}
1247
1248/*
1249 * @implemented
1250 */
1252NTAPI
1255 IN PVOID ProtocolSubmitBuffer,
1256 IN PVOID ClientBufferBase,
1257 IN ULONG SubmitBufferSize,
1259 OUT PULONG ProfileBufferSize,
1262 OUT PLSA_TOKEN_INFORMATION_TYPE TokenInformationType,
1263 OUT PVOID *TokenInformation,
1264 OUT PUNICODE_STRING *AccountName,
1265 OUT PUNICODE_STRING *AuthenticatingAuthority,
1267 OUT PSECPKG_PRIMARY_CRED PrimaryCredentials, /* Not supported yet */
1268 OUT PSECPKG_SUPPLEMENTAL_CRED_ARRAY *SupplementalCredentials) /* Not supported yet */
1269{
1271 UNICODE_STRING ComputerName;
1272 WCHAR ComputerNameData[MAX_COMPUTERNAME_LENGTH + 1];
1273 PUNICODE_STRING LogonUserName = NULL;
1274 LSA_SAM_PWD_DATA LogonPwdData = { FALSE, NULL };
1275 PUNICODE_STRING LogonDomain = NULL;
1276 SAMPR_HANDLE UserHandle = NULL;
1278 PSAMPR_USER_INFO_BUFFER UserInfo = NULL;
1279 BOOLEAN SessionCreated = FALSE;
1280 DWORD ComputerNameSize;
1281 BOOL SpecialAccount = FALSE;
1282 UCHAR LogonPassHash;
1283 PUNICODE_STRING ErasePassword = NULL;
1284 PLOGON_LIST_ENTRY LogonEntry = NULL;
1285
1286 TRACE("LsaApLogonUserEx2()\n");
1287
1288 TRACE("LogonType: %lu\n", LogonType);
1289 TRACE("ProtocolSubmitBuffer: %p\n", ProtocolSubmitBuffer);
1290 TRACE("SubmitBufferSize: %lu\n", SubmitBufferSize);
1291
1293 *ProfileBufferSize = 0;
1295 *AccountName = NULL;
1296 *AuthenticatingAuthority = NULL;
1297
1298 /* Get the computer name */
1299 ComputerNameSize = ARRAYSIZE(ComputerNameData);
1300 if (!GetComputerNameW(ComputerNameData, &ComputerNameSize))
1301 {
1302 ERR("Failed to get Computername.\n");
1303 return STATUS_INTERNAL_ERROR;
1304 }
1305 RtlInitUnicodeString(&ComputerName, ComputerNameData);
1306
1307 /* Parameters validation */
1308 if (LogonType == Interactive ||
1309 LogonType == Batch ||
1310 LogonType == Service)
1311 {
1312 PMSV1_0_INTERACTIVE_LOGON LogonInfo;
1314
1315 if (SubmitBufferSize < sizeof(MSV1_0_INTERACTIVE_LOGON))
1316 {
1317 ERR("Invalid SubmitBufferSize %lu\n", SubmitBufferSize);
1319 }
1320
1321 LogonInfo = (PMSV1_0_INTERACTIVE_LOGON)ProtocolSubmitBuffer;
1322
1323 if (LogonInfo->MessageType != MsV1_0InteractiveLogon &&
1325 {
1326 ERR("Invalid MessageType %lu\n", LogonInfo->MessageType);
1328 }
1329
1330#if 0 // FIXME: These checks happen to be done on Windows. We however keep them general on ReactOS for now...
1331 if (LogonInfo->UserName.Length > 512) // CRED_MAX_STRING_LENGTH * sizeof(WCHAR) or (CREDUI_MAX_USERNAME_LENGTH (== CRED_MAX_USERNAME_LENGTH) - 1) * sizeof(WCHAR)
1332 {
1333 ERR("UserName too long (%lu, maximum 512)\n", LogonInfo->UserName.Length);
1334 return STATUS_NAME_TOO_LONG;
1335 }
1336 if (LogonInfo->Password.Length > 512) // CREDUI_MAX_PASSWORD_LENGTH * sizeof(WCHAR)
1337 {
1338 ERR("Password too long (%lu, maximum 512)\n", LogonInfo->Password.Length);
1339 return STATUS_NAME_TOO_LONG;
1340 }
1341#endif
1342
1343 /* Fix-up pointers in the authentication info */
1344 PtrOffset = (ULONG_PTR)ProtocolSubmitBuffer - (ULONG_PTR)ClientBufferBase;
1345
1346 /* LogonDomainName is optional and can be an empty string */
1347 if (LogonInfo->LogonDomainName.Length)
1348 {
1349 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
1351 LogonInfo->LogonDomainName.MaximumLength = LogonInfo->LogonDomainName.Length;
1352 }
1353 else
1354 {
1355 LogonInfo->LogonDomainName.Buffer = NULL;
1356 LogonInfo->LogonDomainName.MaximumLength = 0;
1357 }
1359 if (!NT_SUCCESS(Status))
1361
1362 /* UserName is mandatory and cannot be an empty string */
1363 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
1364 LogonInfo->UserName.Buffer = FIXUP_POINTER(LogonInfo->UserName.Buffer, PtrOffset);
1365 LogonInfo->UserName.MaximumLength = LogonInfo->UserName.Length;
1366
1367 Status = RtlValidateUnicodeString(0, &LogonInfo->UserName);
1368 if (!NT_SUCCESS(Status))
1370
1371 /* MS docs says max length is 0xFF bytes. But thats not the full story:
1372 *
1373 * A Quote from https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.kernel/eFGcCo_ZObk:
1374 * "... At least on my WinXP SP2. Domain and UserName are passed
1375 * in clear text, but the Password is NOT. ..."
1376 *
1377 * If the higher byte of length != 0 we have to use RtlRunDecodeUnicodeString.
1378 */
1379 LogonPassHash = (LogonInfo->Password.Length >> 8) & 0xFF;
1380 LogonInfo->Password.Length = LogonInfo->Password.Length & 0xFF;
1381
1382 /* Password is optional and can be an empty string */
1383 if (LogonInfo->Password.Length)
1384 {
1385 // TODO: Check for Buffer limits wrt. ClientBufferBase and alignment.
1386 LogonInfo->Password.Buffer = FIXUP_POINTER(LogonInfo->Password.Buffer, PtrOffset);
1387 LogonInfo->Password.MaximumLength = LogonInfo->Password.Length;
1388 }
1389 else
1390 {
1391 LogonInfo->Password.Buffer = NULL;
1392 LogonInfo->Password.MaximumLength = 0;
1393 }
1394
1395 /* Decode password */
1396 if (LogonPassHash > 0)
1397 {
1398 RtlRunDecodeUnicodeString(LogonPassHash, &LogonInfo->Password);
1399 }
1400
1401 /* ErasePassword will be "erased" before we return */
1402 ErasePassword = &LogonInfo->Password;
1403
1404 Status = RtlValidateUnicodeString(0, &LogonInfo->Password);
1405 if (!NT_SUCCESS(Status))
1407
1408 LogonUserName = &LogonInfo->UserName;
1409 LogonDomain = &LogonInfo->LogonDomainName;
1410 LogonPwdData.IsNetwork = FALSE;
1411 LogonPwdData.PlainPwd = &LogonInfo->Password;
1412 LogonPwdData.ComputerName = &ComputerName;
1413
1414 TRACE("Domain: %wZ\n", &LogonInfo->LogonDomainName);
1415 TRACE("User: %wZ\n", &LogonInfo->UserName);
1416 TRACE("Password: %wZ\n", &LogonInfo->Password);
1417
1418 // TODO: If LogonType == Service, do some extra work using LogonInfo->Password.
1419 }
1420 else if (LogonType == Network)
1421 {
1422 Status = LsaApLogonUserEx2_Network(ClientRequest,
1423 ProtocolSubmitBuffer,
1424 ClientBufferBase,
1425 SubmitBufferSize,
1426 &ComputerName,
1427 &LogonUserName,
1428 &LogonDomain,
1429 &LogonPwdData,
1430 &UserHandle,
1431 &UserInfo,
1433 &SpecialAccount,
1435 ProfileBufferSize,
1436 SubStatus);
1437 if (!NT_SUCCESS(Status))
1438 goto done;
1439 }
1440 else
1441 {
1442 FIXME("LogonType %lu is not supported yet!\n", LogonType);
1444 }
1445 // TODO: Add other LogonType validity checks.
1446
1448 LogonUserName,
1449 LogonDomain,
1450 &LogonPwdData,
1451 &ComputerName,
1452 &SpecialAccount,
1454 &UserHandle,
1455 &UserInfo,
1456 SubStatus);
1457 if (!NT_SUCCESS(Status))
1458 goto done;
1459
1460 /* Return logon information */
1461
1462 /* Create and return a new logon id */
1464 if (!NT_SUCCESS(Status))
1465 {
1466 TRACE("NtAllocateLocallyUniqueId failed (Status %08lx)\n", Status);
1467 goto done;
1468 }
1469
1470 /* Create the logon session */
1471 Status = DispatchTable.CreateLogonSession(LogonId);
1472 if (!NT_SUCCESS(Status))
1473 {
1474 TRACE("CreateLogonSession failed (Status %08lx)\n", Status);
1475 goto done;
1476 }
1477
1478 SessionCreated = TRUE;
1479
1480 LogonEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LOGON_LIST_ENTRY));
1481 if (LogonEntry)
1482 {
1483 RtlCopyMemory(&LogonEntry->LogonId, LogonId, sizeof(LUID));
1484 LogonEntry->EnumHandle = EnumCounter;
1485 EnumCounter++;
1486
1487 InsertTailList(&LogonListHead, &LogonEntry->ListEntry);
1488 }
1489
1491 {
1492 /* Build and fill the interactive profile buffer */
1493 Status = BuildInteractiveProfileBuffer(ClientRequest,
1494 UserInfo,
1495 ComputerName.Buffer,
1497 ProfileBufferSize);
1498 if (!NT_SUCCESS(Status))
1499 {
1500 TRACE("BuildInteractiveProfileBuffer failed (Status %08lx)\n", Status);
1501 goto done;
1502 }
1503 }
1504 else if (LogonType == Network)
1505 {
1506 //FIXME: no need to do anything, its already done ...
1507 }
1508
1509 /* Return the token information type */
1510 *TokenInformationType = LsaTokenInformationV1;
1511
1512 /* Build and fill the token information buffer */
1515 UserInfo,
1516 SpecialAccount);
1517 if (!NT_SUCCESS(Status))
1518 {
1519 TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status);
1520 goto done;
1521 }
1522
1523done:
1524 /* Erase password */
1525 if (ErasePassword)
1526 {
1527 RtlEraseUnicodeString(ErasePassword);
1528 }
1529
1530 /* Update the logon time/count or the bad password time/count */
1531 if ((UserHandle != NULL) &&
1533 {
1534 SAMPR_USER_INFO_BUFFER InternalInfo;
1535
1536 RtlZeroMemory(&InternalInfo, sizeof(InternalInfo));
1537
1538 if (Status == STATUS_SUCCESS)
1539 InternalInfo.Internal2.Flags = USER_LOGON_SUCCESS;
1540 else
1542
1543 SamrSetInformationUser(UserHandle,
1545 &InternalInfo);
1546 }
1547
1548 if (NT_SUCCESS(Status))
1549 {
1550 /* Return the account name */
1551 *AccountName = DispatchTable.AllocateLsaHeap(sizeof(UNICODE_STRING));
1552 if ((LogonUserName != NULL) &&
1553 (*AccountName != NULL))
1554 {
1555 (*AccountName)->Buffer = DispatchTable.AllocateLsaHeap(LogonUserName->Length +
1556 sizeof(UNICODE_NULL));
1557 if ((*AccountName)->Buffer != NULL)
1558 {
1559 (*AccountName)->MaximumLength = LogonUserName->Length +
1560 sizeof(UNICODE_NULL);
1561 RtlCopyUnicodeString(*AccountName, LogonUserName);
1562 }
1563 }
1564
1565 /* Return the authenticating authority */
1566 *AuthenticatingAuthority = DispatchTable.AllocateLsaHeap(sizeof(UNICODE_STRING));
1567 if ((LogonDomain != NULL) &&
1568 (*AuthenticatingAuthority != NULL))
1569 {
1570 (*AuthenticatingAuthority)->Buffer = DispatchTable.AllocateLsaHeap(LogonDomain->Length +
1571 sizeof(UNICODE_NULL));
1572 if ((*AuthenticatingAuthority)->Buffer != NULL)
1573 {
1574 (*AuthenticatingAuthority)->MaximumLength = LogonDomain->Length +
1575 sizeof(UNICODE_NULL);
1576 RtlCopyUnicodeString(*AuthenticatingAuthority, LogonDomain);
1577 }
1578 }
1579
1580 /* Return the machine name */
1581 *MachineName = DispatchTable.AllocateLsaHeap(sizeof(UNICODE_STRING));
1582 if (*MachineName != NULL)
1583 {
1584 (*MachineName)->Buffer = DispatchTable.AllocateLsaHeap(ComputerName.MaximumLength);
1585 if ((*MachineName)->Buffer != NULL)
1586 {
1587 (*MachineName)->MaximumLength = ComputerName.MaximumLength;
1588 (*MachineName)->Length = ComputerName.Length;
1589 RtlCopyMemory((*MachineName)->Buffer,
1590 ComputerName.Buffer,
1591 ComputerName.MaximumLength);
1592 }
1593 }
1594 }
1595
1596 if (!NT_SUCCESS(Status))
1597 {
1598 if (SessionCreated != FALSE)
1599 DispatchTable.DeleteLogonSession(LogonId);
1600
1601 if (*ProfileBuffer != NULL)
1602 {
1603 DispatchTable.FreeClientBuffer(ClientRequest,
1604 *ProfileBuffer);
1606 }
1607 }
1608
1609 if (UserHandle != NULL)
1610 SamrCloseHandle(&UserHandle);
1611
1614
1615 if (AccountDomainSid != NULL)
1616 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
1617
1618 if (Status == STATUS_NO_SUCH_USER ||
1620 {
1621 *SubStatus = Status;
1623 }
1624
1625 TRACE("LsaApLogonUserEx2 done (Status 0x%08lx, SubStatus 0x%08lx)\n", Status, *SubStatus);
1626
1627 return Status;
1628}
1629
1630
1631/*
1632 * @unimplemented
1633 */
1635NTAPI
1637 _In_ ULONG LsaVersion,
1638 _Out_ PULONG PackageVersion,
1639 _Out_ PSECPKG_FUNCTION_TABLE *ppTables,
1640 _Out_ PULONG pcTables)
1641{
1642 TRACE("SpLsaModeInitialize(0x%lx %p %p %p)\n",
1643 LsaVersion, PackageVersion, ppTables, pcTables);
1644
1645 if (LsaVersion != SECPKG_INTERFACE_VERSION)
1647
1648 *PackageVersion = SECPKG_INTERFACE_VERSION;
1649
1650 *ppTables = NtlmLsaFn;
1651 *pcTables = 1;
1652
1653 return STATUS_SUCCESS;
1654}
1655
1656/*
1657 * @unimplemented
1658 */
1660WINAPI
1662 _In_ ULONG LsaVersion,
1663 _Out_ PULONG PackageVersion,
1665 _Out_ PULONG pcTables)
1666{
1667 TRACE("SpUserModeInitialize(0x%lx %p %p %p)\n",
1668 LsaVersion, PackageVersion, ppTables, pcTables);
1669
1670 if (LsaVersion != SECPKG_INTERFACE_VERSION)
1672
1673 *PackageVersion = SECPKG_INTERFACE_VERSION;
1674
1675 *ppTables = NtlmUsrFn;
1676 *pcTables = 1;
1677
1678 return STATUS_SUCCESS;
1679}
1680
1681/* EOF */
unsigned char BOOLEAN
PWSTR Names[]
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
NTSTATUS __stdcall SamrOpenDomain(SAMPR_HANDLE ServerHandle, ACCESS_MASK DesiredAccess, PRPC_SID DomainId, SAMPR_HANDLE *DomainHandle)
VOID NTAPI SamIFree_SAMPR_ULONG_ARRAY(PSAMPR_ULONG_ARRAY Ptr)
Definition: samsrv.c:524
@ LsaTokenInformationV1
Definition: authpackage.c:17
NTSTATUS __stdcall SamrCloseHandle(SAMPR_HANDLE *SamHandle)
enum _LSA_TOKEN_INFORMATION_TYPE * PLSA_TOKEN_INFORMATION_TYPE
NTSTATUS NTAPI SamIConnect(PSAMPR_SERVER_NAME ServerName, SAMPR_HANDLE *ServerHandle, ACCESS_MASK DesiredAccess, BOOLEAN Trusted)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define PtrOffset(BASE, OFFSET)
Definition: cdprocs.h:1547
Definition: bufpool.h:45
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
@ Network
struct _LUID * PLUID
struct _LUID LUID
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NTSTATUS WINAPI SystemFunction006(LPCSTR password, LPSTR hash)
Definition: crypt_lmhash.c:53
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
PSID AccountDomainSid
Definition: database.c:24
NTSTATUS NTAPI SamrLookupNamesInDomain(IN SAMPR_HANDLE DomainHandle, IN ULONG Count, IN RPC_UNICODE_STRING Names[], OUT PSAMPR_ULONG_ARRAY RelativeIds, OUT PSAMPR_ULONG_ARRAY Use)
Definition: samrpc.c:3464
bool NtlmUStrWriteToStruct(_In_ PVOID DataStart, _In_ ULONG DataSize, _Out_ PUNICODE_STRING DstData, _In_ const PUNICODE_STRING SrcData, _Inout_ PBYTE *AbsoluteOffsetPtr, _In_ bool TerminateWith0)
Definition: util.c:197
VOID NtlmUStrFree(_In_ PUNICODE_STRING String)
Definition: util.c:115
bool NtlmFixupAndValidateUStr(_Inout_ PUNICODE_STRING String, _In_ ULONG_PTR FixupOffset)
Definition: util.c:223
NTSTATUS NtlmCopyToClientBuffer(_In_ PLSA_CLIENT_REQUEST ClientRequest, _In_ ULONG BufferLength, _Inout_ PNTLM_CLIENT_BUFFER Buffer)
Definition: util.c:301
bool NtlmFixupAStr(_Inout_ PSTRING String, _In_ ULONG_PTR FixupOffset)
Definition: util.c:245
bool NtlmUStrAlloc(_Inout_ PUNICODE_STRING Dst, _In_ UINT16 SizeInBytes, _In_ UINT16 InitLength)
Definition: util.c:103
NTSTATUS NtlmAllocateClientBuffer(_In_ PLSA_CLIENT_REQUEST ClientRequest, _In_ ULONG BufferLength, _Inout_ PNTLM_CLIENT_BUFFER Buffer)
Definition: util.c:264
VOID NtlmFreeClientBuffer(_In_ PLSA_CLIENT_REQUEST ClientRequest, _In_ bool FreeClientBuffer, _Inout_ PNTLM_CLIENT_BUFFER Buffer)
Definition: util.c:335
#define ULONG_PTR
Definition: config.h:101
#define InsertTailList(ListHead, Entry)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define S_OK
Definition: intsafe.h:52
VOID NTAPI ProtocolStatus(NDIS_HANDLE BindingContext, NDIS_STATUS GenerelStatus, PVOID StatusBuffer, UINT StatusBufferSize)
Called by NDIS when the underlying driver has changed state.
Definition: lan.c:461
@ SidTypeUser
Definition: lsa.idl:118
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ASSERT(a)
Definition: mode.c:44
* PNTSTATUS
Definition: strlen.c:14
static SID_IDENTIFIER_AUTHORITY SystemAuthority
Definition: msgina.c:38
SECPKG_USER_FUNCTION_TABLE NtlmUsrFn[1]
Definition: global.c:57
SECPKG_FUNCTION_TABLE NtlmLsaFn[1]
Definition: global.c:23
static NTSTATUS BuildTokenGroups(OUT PTOKEN_GROUPS *Groups, IN PSID AccountDomainSid, IN ULONG RelativeId, IN BOOL SpecialAccount)
Definition: msv1_0.c:357
NTSTATUS WINAPI SpUserModeInitialize(_In_ ULONG LsaVersion, _Out_ PULONG PackageVersion, _Out_ PSECPKG_USER_FUNCTION_TABLE *ppTables, _Out_ PULONG pcTables)
Definition: msv1_0.c:1661
NTSTATUS NTAPI LsaApLogonUserEx2(IN PLSA_CLIENT_REQUEST ClientRequest, IN SECURITY_LOGON_TYPE LogonType, IN PVOID ProtocolSubmitBuffer, IN PVOID ClientBufferBase, IN ULONG SubmitBufferSize, OUT PVOID *ProfileBuffer, OUT PULONG ProfileBufferSize, OUT PLUID LogonId, OUT PNTSTATUS SubStatus, OUT PLSA_TOKEN_INFORMATION_TYPE TokenInformationType, OUT PVOID *TokenInformation, OUT PUNICODE_STRING *AccountName, OUT PUNICODE_STRING *AuthenticatingAuthority, OUT PUNICODE_STRING *MachineName, OUT PSECPKG_PRIMARY_CRED PrimaryCredentials, OUT PSECPKG_SUPPLEMENTAL_CRED_ARRAY *SupplementalCredentials)
Definition: msv1_0.c:1253
static NTSTATUS BuildTokenPrimaryGroup(OUT PTOKEN_PRIMARY_GROUP PrimaryGroup, IN PSID AccountDomainSid, IN ULONG RelativeId)
Definition: msv1_0.c:339
ULONG EnumCounter
Definition: msv1_0.c:26
static NTSTATUS BuildLm20LogonProfileBuffer(_In_ PLSA_CLIENT_REQUEST ClientRequest, _In_ PSAMPR_USER_INFO_BUFFER UserInfo, _In_ PLSA_SAM_PWD_DATA LogonPwdData, _Out_ PMSV1_0_LM20_LOGON_PROFILE *ProfileBuffer, _Out_ PULONG ProfileBufferLength)
Definition: msv1_0.c:188
struct _LOGON_LIST_ENTRY * PLOGON_LIST_ENTRY
BOOL PackageInitialized
Definition: msv1_0.c:24
NTSTATUS NTAPI LsaApInitializePackage(IN ULONG AuthenticationPackageId, IN PLSA_DISPATCH_TABLE LsaDispatchTable, IN PLSA_STRING Database OPTIONAL, IN PLSA_STRING Confidentiality OPTIONAL, OUT PLSA_STRING *AuthenticationPackageName)
Definition: msv1_0.c:1092
struct _LOGON_LIST_ENTRY LOGON_LIST_ENTRY
NTSTATUS NTAPI LsaApCallPackagePassthrough(IN PLSA_CLIENT_REQUEST ClientRequest, IN PVOID ProtocolSubmitBuffer, IN PVOID ClientBufferBase, IN ULONG SubmitBufferLength, OUT PVOID *ProtocolReturnBuffer, OUT PULONG ReturnBufferLength, OUT PNTSTATUS ProtocolStatus)
Definition: msv1_0.c:1033
LIST_ENTRY LogonListHead
Definition: msv1_0.c:25
NTSTATUS NTAPI SpLsaModeInitialize(_In_ ULONG LsaVersion, _Out_ PULONG PackageVersion, _Out_ PSECPKG_FUNCTION_TABLE *ppTables, _Out_ PULONG pcTables)
Definition: msv1_0.c:1636
NTSTATUS NTAPI LsaApCallPackage(IN PLSA_CLIENT_REQUEST ClientRequest, IN PVOID ProtocolSubmitBuffer, IN PVOID ClientBufferBase, IN ULONG SubmitBufferLength, OUT PVOID *ProtocolReturnBuffer, OUT PULONG ReturnBufferLength, OUT PNTSTATUS ProtocolStatus)
Definition: msv1_0.c:958
static PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: msv1_0.c:292
static NTSTATUS MsvpEnumerateUsers(_In_ PLSA_CLIENT_REQUEST ClientRequest, _In_ PVOID ProtocolSubmitBuffer, _In_ PVOID ClientBufferBase, _In_ ULONG SubmitBufferLength, _Out_ PVOID *ProtocolReturnBuffer, _Out_ PULONG ReturnBufferLength, _Out_ PNTSTATUS ProtocolStatus)
Definition: msv1_0.c:836
static NTSTATUS LsaApLogonUserEx2_Network(_In_ PLSA_CLIENT_REQUEST ClientRequest, _In_ PVOID ProtocolSubmitBuffer, _In_ PVOID ClientBufferBase, _In_ ULONG SubmitBufferSize, _In_ PUNICODE_STRING ComputerName, _Out_ PUNICODE_STRING *LogonUserRef, _Out_ PUNICODE_STRING *LogonDomainRef, _Inout_ PLSA_SAM_PWD_DATA LogonPwdData, _Out_ SAMPR_HANDLE *UserHandlePtr, _Out_ PSAMPR_USER_INFO_BUFFER *UserInfoPtr, _Out_ PRPC_SID *AccountDomainSidPtr, _Out_ PBOOL SpecialAccount, _Out_ PMSV1_0_LM20_LOGON_PROFILE *LogonProfile, _Out_ PULONG LogonProfileSize, _Out_ PNTSTATUS SubStatus)
Definition: msv1_0.c:1163
static NTSTATUS BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation, PRPC_SID AccountDomainSid, PSAMPR_USER_INFO_BUFFER UserInfo, BOOL SpecialAccount)
Definition: msv1_0.c:453
static NTSTATUS MsvpChangePassword(IN PLSA_CLIENT_REQUEST ClientRequest, IN PVOID ProtocolSubmitBuffer, IN PVOID ClientBufferBase, IN ULONG SubmitBufferLength, OUT PVOID *ProtocolReturnBuffer, OUT PULONG ReturnBufferLength, OUT PNTSTATUS ProtocolStatus)
Definition: msv1_0.c:538
static NTSTATUS BuildInteractiveProfileBuffer(IN PLSA_CLIENT_REQUEST ClientRequest, IN PSAMPR_USER_INFO_BUFFER UserInfo, IN PWSTR ComputerName, OUT PMSV1_0_INTERACTIVE_PROFILE *ProfileBuffer, OUT PULONG ProfileBufferLength)
Definition: msv1_0.c:32
NTSTATUS NTAPI LsaApCallPackageUntrusted(IN PLSA_CLIENT_REQUEST ClientRequest, IN PVOID ProtocolSubmitBuffer, IN PVOID ClientBufferBase, IN ULONG SubmitBufferLength, OUT PVOID *ProtocolReturnBuffer, OUT PULONG ReturnBufferLength, OUT PNTSTATUS ProtocolStatus)
Definition: msv1_0.c:1051
static NTSTATUS BuildTokenUser(OUT PTOKEN_USER User, IN PSID AccountDomainSid, IN ULONG RelativeId)
Definition: msv1_0.c:319
VOID NTAPI LsaApLogonTerminated(IN PLUID LogonId)
Definition: msv1_0.c:1152
VOID NTAPI SamIFree_SAMPR_USER_INFO_BUFFER(PSAMPR_USER_INFO_BUFFER Ptr, USER_INFORMATION_CLASS InformationClass)
Definition: samsrv.c:540
NTSTATUS NTAPI SamrSetInformationUser(IN SAMPR_HANDLE UserHandle, IN USER_INFORMATION_CLASS UserInformationClass, IN PSAMPR_USER_INFO_BUFFER Buffer)
Definition: samrpc.c:7848
NTSTATUS NTAPI SamrChangePasswordUser(IN SAMPR_HANDLE UserHandle, IN unsigned char LmPresent, IN PENCRYPTED_LM_OWF_PASSWORD OldLmEncryptedWithNewLm, IN PENCRYPTED_LM_OWF_PASSWORD NewLmEncryptedWithOldLm, IN unsigned char NtPresent, IN PENCRYPTED_NT_OWF_PASSWORD OldNtEncryptedWithNewNt, IN PENCRYPTED_NT_OWF_PASSWORD NewNtEncryptedWithOldNt, IN unsigned char NtCrossEncryptionPresent, IN PENCRYPTED_NT_OWF_PASSWORD NewNtEncryptedWithNewLm, IN unsigned char LmCrossEncryptionPresent, IN PENCRYPTED_LM_OWF_PASSWORD NewLmEncryptedWithNewNt)
Definition: samrpc.c:7864
NTSTATUS NTAPI SamrLookupDomainInSamServer(IN SAMPR_HANDLE ServerHandle, IN PRPC_UNICODE_STRING Name, OUT PRPC_SID *DomainId)
Definition: samrpc.c:504
NTSTATUS NTAPI SamrOpenUser(IN SAMPR_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG UserId, OUT SAMPR_HANDLE *UserHandle)
#define USER_LOGON_SUCCESS
Definition: sam.idl:649
VOID NTAPI SamIFreeVoid(PVOID Ptr)
Definition: samsrv.c:155
#define FIXUP_POINTER(Pointer, Offset)
Definition: msv1_0.h:9
#define USER_LOGON_BAD_PASSWORD
Definition: sam.idl:648
struct _MSV1_0_ENUMUSERS_RESPONSE MSV1_0_ENUMUSERS_RESPONSE
NTSYSAPI NTSTATUS NTAPI RtlUpcaseUnicodeStringToOemString(POEM_STRING DestinationString, PCUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI PULONG NTAPI RtlSubAuthoritySid(_In_ PSID Sid, _In_ ULONG SubAuthority)
NTSYSAPI ULONG NTAPI RtlLengthRequiredSid(IN ULONG SubAuthorityCount)
Definition: sid.c:54
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ OwnerSize PSID _Inout_ PULONG _Out_writes_bytes_to_opt_ PrimaryGroupSize PSID PrimaryGroup
Definition: rtlfuncs.h:1611
NTSYSAPI VOID NTAPI RtlEraseUnicodeString(_Inout_ PUNICODE_STRING String)
NTSYSAPI NTSTATUS NTAPI RtlValidateUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING String)
Definition: unicode.c:2605
_In_ ULONG _In_ ACCESS_MASK _In_ PSID Sid
Definition: rtlfuncs.h:1145
#define SE_GROUP_MANDATORY
Definition: setypes.h:90
#define SE_GROUP_ENABLED_BY_DEFAULT
Definition: setypes.h:91
#define SE_GROUP_ENABLED
Definition: setypes.h:92
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define UNICODE_NULL
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE LogonType
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID _Out_ PHANDLE _Out_ PQUOTA_LIMITS _Out_ PNTSTATUS SubStatus
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID * ProfileBuffer
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG ProfileBufferLength
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID _Out_ PULONG _Inout_ PLUID LogonId
NTSYSAPI NTSTATUS NTAPI RtlAllocateAndInitializeSid(IN PSID_IDENTIFIER_AUTHORITY IdentifierAuthority, IN UCHAR SubAuthorityCount, IN ULONG SubAuthority0, IN ULONG SubAuthority1, IN ULONG SubAuthority2, IN ULONG SubAuthority3, IN ULONG SubAuthority4, IN ULONG SubAuthority5, IN ULONG SubAuthority6, IN ULONG SubAuthority7, OUT PSID *Sid)
Definition: sid.c:290
NTSYSAPI PUCHAR NTAPI RtlSubAuthorityCountSid(IN PSID Sid)
Definition: sid.c:104
NTSTATUS NTAPI NtAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
Definition: uuid.c:348
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
@ UserInternal2Information
Definition: ntsam.h:532
@ UserAllInformation
Definition: ntsam.h:534
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
#define USER_CHANGE_PASSWORD
Definition: ntsam.h:132
struct _MSV1_0_CHANGEPASSWORD_REQUEST * PMSV1_0_CHANGEPASSWORD_REQUEST
struct _MSV1_0_INTERACTIVE_PROFILE * PMSV1_0_INTERACTIVE_PROFILE
@ MsV1_0ChangeCachedPassword
Definition: ntsecapi.h:224
@ MsV1_0GenericPassthrough
Definition: ntsecapi.h:225
@ MsV1_0Lm20GetChallengeResponse
Definition: ntsecapi.h:219
@ MsV1_0CacheLookup
Definition: ntsecapi.h:229
@ MsV1_0DeriveCredential
Definition: ntsecapi.h:228
@ MsV1_0ReLogonUsers
Definition: ntsecapi.h:222
@ MsV1_0ChangePassword
Definition: ntsecapi.h:223
@ MsV1_0Lm20ChallengeRequest
Definition: ntsecapi.h:218
@ MsV1_0EnumerateUsers
Definition: ntsecapi.h:220
@ MsV1_0CacheLogon
Definition: ntsecapi.h:226
@ MsV1_0GetUserInfo
Definition: ntsecapi.h:221
@ MsV1_0SubAuth
Definition: ntsecapi.h:227
#define MSV1_0_USER_SESSION_KEY_LENGTH
Definition: ntsecapi.h:60
#define MSV1_0_RETURN_PROFILE_PATH
Definition: ntsecapi.h:47
@ Interactive
Definition: ntsecapi.h:289
@ Service
Definition: ntsecapi.h:292
@ Batch
Definition: ntsecapi.h:291
struct _MSV1_0_LM20_LOGON_PROFILE MSV1_0_LM20_LOGON_PROFILE
struct _LSA_STRING * PLSA_STRING
struct _MSV1_0_INTERACTIVE_PROFILE MSV1_0_INTERACTIVE_PROFILE
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
enum _SECURITY_LOGON_TYPE SECURITY_LOGON_TYPE
enum _MSV1_0_PROTOCOL_MESSAGE_TYPE * PMSV1_0_PROTOCOL_MESSAGE_TYPE
@ MsV1_0InteractiveProfile
Definition: ntsecapi.h:206
@ MsV1_0Lm20LogonProfile
Definition: ntsecapi.h:207
struct _MSV1_0_LM20_LOGON_PROFILE * PMSV1_0_LM20_LOGON_PROFILE
#define MSV1_0_LANMAN_SESSION_KEY_LENGTH
Definition: ntsecapi.h:34
struct _MSV1_0_INTERACTIVE_LOGON * PMSV1_0_INTERACTIVE_LOGON
enum _MSV1_0_PROTOCOL_MESSAGE_TYPE MSV1_0_PROTOCOL_MESSAGE_TYPE
#define LOGON_USED_LM_PASSWORD
Definition: ntsecapi.h:11
@ MsV1_0WorkstationUnlockLogon
Definition: ntsecapi.h:203
@ MsV1_0InteractiveLogon
Definition: ntsecapi.h:199
#define SECPKG_INTERFACE_VERSION
Definition: ntsecpkg.h:34
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define STATUS_WRONG_PASSWORD
Definition: ntstatus.h:342
#define STATUS_BAD_VALIDATION_CLASS
Definition: ntstatus.h:403
#define STATUS_NO_SUCH_USER
Definition: ntstatus.h:336
#define STATUS_LOGON_FAILURE
Definition: ntstatus.h:345
#define STATUS_NAME_TOO_LONG
Definition: ntstatus.h:498
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS SamValidateUser(_In_ SECURITY_LOGON_TYPE LogonType, _In_ PUNICODE_STRING LogonUserName, _In_ PUNICODE_STRING LogonDomain, _In_ PLSA_SAM_PWD_DATA LogonPwdData, _In_ PUNICODE_STRING ComputerName, _Out_ PBOOL SpecialAccount, _Out_ PRPC_SID *AccountDomainSidPtr, _Out_ SAMPR_HANDLE *UserHandlePtr, _Out_ PSAMPR_USER_INFO_BUFFER *UserInfoPtr, _Out_ PNTSTATUS SubStatus)
Validates a user by checking if it exists in the sam database. Some other checks are done further.
Definition: sam.c:460
@ NetLogonLmKey
Definition: sam.h:13
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
VOID NTAPI RtlRunDecodeUnicodeString(IN UCHAR Hash, IN OUT PUNICODE_STRING String)
Definition: encode.c:20
_In_ DWORD _Out_ PDWORD _In_opt_ PCSTR MachineName
Definition: setupapi.h:1293
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: msv1_0.c:16
LUID LogonId
Definition: msv1_0.c:18
LIST_ENTRY ListEntry
Definition: msv1_0.c:17
ULONG EnumHandle
Definition: msv1_0.c:19
PUNICODE_STRING PlainPwd
Definition: sam.h:22
PUNICODE_STRING ComputerName
Definition: sam.h:26
BOOL IsNetwork
Definition: sam.h:21
USHORT MaximumLength
Definition: ntsecapi.h:164
DWORD LowPart
UNICODE_STRING AccountName
Definition: ntsecapi.h:513
UNICODE_STRING NewPassword
Definition: ntsecapi.h:515
UNICODE_STRING OldPassword
Definition: ntsecapi.h:514
MSV1_0_PROTOCOL_MESSAGE_TYPE MessageType
Definition: msv1_0p.h:11
UNICODE_STRING Password
Definition: ntsecapi.h:437
UNICODE_STRING UserName
Definition: ntsecapi.h:436
MSV1_0_LOGON_SUBMIT_TYPE MessageType
Definition: ntsecapi.h:434
UNICODE_STRING LogonDomainName
Definition: ntsecapi.h:435
LARGE_INTEGER LogonTime
Definition: ntsecapi.h:443
MSV1_0_PROFILE_BUFFER_TYPE MessageType
Definition: ntsecapi.h:440
LARGE_INTEGER KickOffTime
Definition: ntsecapi.h:445
LARGE_INTEGER PasswordMustChange
Definition: ntsecapi.h:448
UNICODE_STRING LogonScript
Definition: ntsecapi.h:449
LARGE_INTEGER PasswordCanChange
Definition: ntsecapi.h:447
LARGE_INTEGER LogoffTime
Definition: ntsecapi.h:444
UNICODE_STRING FullName
Definition: ntsecapi.h:451
LARGE_INTEGER PasswordLastSet
Definition: ntsecapi.h:446
UNICODE_STRING ProfilePath
Definition: ntsecapi.h:452
UNICODE_STRING LogonServer
Definition: ntsecapi.h:454
UNICODE_STRING HomeDirectory
Definition: ntsecapi.h:450
UNICODE_STRING HomeDirectoryDrive
Definition: ntsecapi.h:453
MSV1_0_PROFILE_BUFFER_TYPE MessageType
Definition: ntsecapi.h:479
UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH]
Definition: ntsecapi.h:483
UNICODE_STRING LogonServer
Definition: ntsecapi.h:486
UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH]
Definition: ntsecapi.h:485
UNICODE_STRING LogonDomainName
Definition: ntsecapi.h:484
LARGE_INTEGER LogoffTime
Definition: ntsecapi.h:481
UNICODE_STRING UserParameters
Definition: ntsecapi.h:487
LARGE_INTEGER KickOffTime
Definition: ntsecapi.h:480
UNICODE_STRING UserName
Definition: ntsecapi.h:460
STRING CaseInsensitiveChallengeResponse
Definition: ntsecapi.h:464
UNICODE_STRING LogonDomainName
Definition: ntsecapi.h:459
UNICODE_STRING Workstation
Definition: ntsecapi.h:461
ULONG ParameterControl
Definition: ntsecapi.h:465
STRING CaseSensitiveChallengeResponse
Definition: ntsecapi.h:463
unsigned long LowPart
Definition: msv1_0.h:32
unsigned long * Element
Definition: lsasrv.h:88
unsigned long PrimaryGroupId
Definition: msv1_0.h:101
unsigned long UserId
Definition: msv1_0.h:100
OLD_LARGE_INTEGER AccountExpires
Definition: msv1_0.h:83
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSTATUS WINAPI SystemFunction012(const BYTE *in, const BYTE *key, LPBYTE out)
Definition: sysfunc.c:353
NTSTATUS WINAPI SystemFunction007(const UNICODE_STRING *string, LPBYTE hash)
Definition: sysfunc.c:245
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * LPBYTE
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
STRING OEM_STRING
Definition: umtypes.h:203
ULONG LowPart
Definition: typedefs.h:106
SAMPR_USER_ALL_INFORMATION All
Definition: msv1_0.h:141
SAMPR_USER_INTERNAL2_INFORMATION Internal2
Definition: msv1_0.h:137
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:248
#define ZeroMemory
Definition: winbase.h:1737
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:269
BOOL * PBOOL
Definition: windef.h:161
#define WINAPI
Definition: msvc.h:6
#define ERROR_INTERNAL_ERROR
Definition: winerror.h:840
#define DOMAIN_ALIAS_RID_USERS
Definition: setypes.h:653
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:568
#define SECURITY_NULL_RID
Definition: setypes.h:540
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
@ TokenGroups
Definition: setypes.h:967
#define DOMAIN_GROUP_RID_USERS
Definition: setypes.h:640
char * LPSTR
Definition: xmlstorage.h:182
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char CHAR
Definition: xmlstorage.h:175
unsigned char BYTE
Definition: xxhash.c:193