ReactOS  0.4.15-dev-439-g292f67a
lsa.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS msgina.dll
3  * FILE: dll/win32/msgina/gui.c
4  * PURPOSE: ReactOS Logon GINA DLL
5  * PROGRAMMER: Eric Kohl
6  */
7 
8 #include "msgina.h"
9 
12  PGINA_CONTEXT pgContext)
13 {
14  LSA_STRING LogonProcessName;
15  LSA_STRING PackageName;
18 
19  /* We are already connected to the LSA */
20  if (pgContext->LsaHandle != NULL)
21  return STATUS_SUCCESS;
22 
23  /* Connect to the LSA server */
24  RtlInitAnsiString((PANSI_STRING)&LogonProcessName,
25  "MSGINA");
26 
27  Status = LsaRegisterLogonProcess(&LogonProcessName,
28  &pgContext->LsaHandle,
29  &SecurityMode);
30  if (!NT_SUCCESS(Status))
31  {
32  ERR("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status);
33  return Status;
34  }
35 
36  /* Get the authentication package */
37  RtlInitAnsiString((PANSI_STRING)&PackageName,
39 
41  &PackageName,
42  &pgContext->AuthenticationPackage);
43  if (!NT_SUCCESS(Status))
44  {
45  ERR("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status);
46  }
47 
48  return Status;
49 }
50 
51 static const CHAR User32TokenSourceName[] = "User32 ";
53 
58  LPWSTR lpszUsername,
63 {
66  PSID LogonSid = NULL;
67  PSID LocalSid = NULL;
69  UNICODE_STRING DomainName;
70  UNICODE_STRING UserName;
73  ULONG AuthInfoLength;
74  ULONG_PTR Ptr;
79  LUID Luid = {0, 0};
80  LUID LogonId = {0, 0};
82  QUOTA_LIMITS QuotaLimits;
84 
85  *phToken = NULL;
86 
88  "MSGINA Logon");
89 
90  RtlInitUnicodeString(&DomainName,
91  lpszDomain);
92 
93  RtlInitUnicodeString(&UserName,
94  lpszUsername);
95 
97  lpszPassword);
98 
99  AuthInfoLength = sizeof(MSV1_0_INTERACTIVE_LOGON)+
100  DomainName.MaximumLength +
101  UserName.MaximumLength +
102  Password.MaximumLength;
103 
104  AuthInfo = RtlAllocateHeap(RtlGetProcessHeap(),
106  AuthInfoLength);
107  if (AuthInfo == NULL)
108  {
110  goto done;
111  }
112 
114 
115  Ptr = (ULONG_PTR)AuthInfo + sizeof(MSV1_0_INTERACTIVE_LOGON);
116 
117  AuthInfo->LogonDomainName.Length = DomainName.Length;
118  AuthInfo->LogonDomainName.MaximumLength = DomainName.MaximumLength;
119  AuthInfo->LogonDomainName.Buffer = (DomainName.Buffer == NULL) ? NULL : (PWCHAR)Ptr;
120  if (DomainName.MaximumLength > 0)
121  {
123  DomainName.Buffer,
124  DomainName.MaximumLength);
125 
126  Ptr += DomainName.MaximumLength;
127  }
128 
129  AuthInfo->UserName.Length = UserName.Length;
130  AuthInfo->UserName.MaximumLength = UserName.MaximumLength;
131  AuthInfo->UserName.Buffer = (PWCHAR)Ptr;
132  if (UserName.MaximumLength > 0)
133  RtlCopyMemory(AuthInfo->UserName.Buffer,
134  UserName.Buffer,
135  UserName.MaximumLength);
136 
137  Ptr += UserName.MaximumLength;
138 
139  AuthInfo->Password.Length = Password.Length;
140  AuthInfo->Password.MaximumLength = Password.MaximumLength;
141  AuthInfo->Password.Buffer = (PWCHAR)Ptr;
142  if (Password.MaximumLength > 0)
143  RtlCopyMemory(AuthInfo->Password.Buffer,
144  Password.Buffer,
145  Password.MaximumLength);
146 
147  /* Create the Logon SID*/
152  LogonId.HighPart,
153  LogonId.LowPart,
159  &LogonSid);
160  if (!NT_SUCCESS(Status))
161  goto done;
162 
163  /* Create the Local SID*/
164  Status = RtlAllocateAndInitializeSid(&LocalAuthority,
165  1,
174  &LocalSid);
175  if (!NT_SUCCESS(Status))
176  goto done;
177 
178  /* Allocate and set the token groups */
179  TokenGroups = RtlAllocateHeap(RtlGetProcessHeap(),
181  sizeof(TOKEN_GROUPS) + ((2 - ANYSIZE_ARRAY) * sizeof(SID_AND_ATTRIBUTES)));
182  if (TokenGroups == NULL)
183  {
185  goto done;
186  }
187 
188  TokenGroups->GroupCount = 2;
189  TokenGroups->Groups[0].Sid = LogonSid;
190  TokenGroups->Groups[0].Attributes = SE_GROUP_MANDATORY | SE_GROUP_ENABLED |
192  TokenGroups->Groups[1].Sid = LocalSid;
193  TokenGroups->Groups[1].Attributes = SE_GROUP_MANDATORY | SE_GROUP_ENABLED |
195 
196  /* Set the token source */
197  RtlCopyMemory(TokenSource.SourceName, User32TokenSourceName, sizeof(TokenSource.SourceName));
198  AllocateLocallyUniqueId(&TokenSource.SourceIdentifier);
199 
201  &OriginName,
202  Interactive,
204  (PVOID)AuthInfo,
205  AuthInfoLength,
206  TokenGroups,
207  &TokenSource,
208  (PVOID*)&ProfileBuffer,
210  &Luid,
211  &TokenHandle,
212  &QuotaLimits,
213  SubStatus);
214  if (!NT_SUCCESS(Status))
215  {
216  ERR("LsaLogonUser failed (Status 0x%08lx)\n", Status);
217  goto done;
218  }
219 
220  if (ProfileBuffer != NULL)
221  {
222  TRACE("ProfileBuffer: %p\n", ProfileBuffer);
223  TRACE("MessageType: %u\n", ProfileBuffer->MessageType);
224 
225  TRACE("FullName: %p\n", ProfileBuffer->FullName.Buffer);
226  TRACE("FullName: %S\n", ProfileBuffer->FullName.Buffer);
227 
228  TRACE("LogonServer: %p\n", ProfileBuffer->LogonServer.Buffer);
229  TRACE("LogonServer: %S\n", ProfileBuffer->LogonServer.Buffer);
230  }
231 
232  TRACE("Luid: 0x%08lx%08lx\n", Luid.HighPart, Luid.LowPart);
233 
234  if (TokenHandle != NULL)
235  {
236  TRACE("TokenHandle: %p\n", TokenHandle);
237  }
238 
239  *phToken = TokenHandle;
240 
241 done:
242  if (ProfileBuffer != NULL)
244 
245  if (!NT_SUCCESS(Status))
246  {
247  if (TokenHandle != NULL)
249  }
250 
251  if (TokenGroups != NULL)
252  RtlFreeHeap(RtlGetProcessHeap(), 0, TokenGroups);
253 
254  if (LocalSid != NULL)
256 
257  if (LogonSid != NULL)
258  RtlFreeSid(LogonSid);
259 
260  if (AuthInfo != NULL)
261  RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo);
262 
263  return Status;
264 }
265 
266 /* EOF */
* PNTSTATUS
Definition: strlen.c:14
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:84
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define CloseHandle
Definition: compat.h:407
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
MSV1_0_LOGON_SUBMIT_TYPE MessageType
Definition: ntsecapi.h:434
NTSTATUS MyLogonUser(HANDLE LsaHandle, ULONG AuthenticationPackage, LPWSTR lpszUsername, LPWSTR lpszDomain, LPWSTR lpszPassword, PHANDLE phToken, PNTSTATUS SubStatus)
Definition: lsa.c:55
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define ANYSIZE_ARRAY
Definition: typedefs.h:46
NTSTATUS ConnectToLsa(PGINA_CONTEXT pgContext)
Definition: lsa.c:11
NTSYSAPI PVOID NTAPI RtlFreeSid(_In_ _Post_invalid_ PSID Sid)
char CHAR
Definition: xmlstorage.h:175
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
C_ASSERT(sizeof(User32TokenSourceName)==RTL_FIELD_SIZE(TOKEN_SOURCE, SourceName)+1)
_In_opt_ LPSTR _In_opt_ LPSTR lpszPassword
Definition: winbase.h:2674
_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
uint16_t * PWCHAR
Definition: typedefs.h:55
PSID LocalSid
Definition: globals.c:15
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
_IRQL_requires_same_ _In_ PLSA_STRING OriginName
UNICODE_STRING Password
Definition: ntsecapi.h:437
NTSTATUS NTAPI LsaLogonUser(IN HANDLE LsaHandle, IN PLSA_STRING OriginName, IN SECURITY_LOGON_TYPE LogonType, IN ULONG AuthenticationPackage, IN PVOID AuthenticationInformation, IN ULONG AuthenticationInformationLength, IN PTOKEN_GROUPS LocalGroups OPTIONAL, IN PTOKEN_SOURCE SourceContext, OUT PVOID *ProfileBuffer, OUT PULONG ProfileBufferLength, OUT PLUID LogonId, OUT PHANDLE Token, OUT PQUOTA_LIMITS Quotas, OUT PNTSTATUS SubStatus)
Definition: lsa.c:184
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define SECURITY_LOGON_IDS_RID_COUNT
Definition: setypes.h:533
HANDLE LsaHandle
Definition: logon.c:17
_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
#define SECURITY_LOCAL_SID_AUTHORITY
Definition: setypes.h:502
NTSTATUS NTAPI LsaLookupAuthenticationPackage(IN HANDLE LsaHandle, IN PLSA_STRING PackageName, OUT PULONG AuthenticationPackage)
Definition: lsa.c:136
_IRQL_requires_same_ _Out_ PHANDLE _Out_ PLSA_OPERATIONAL_MODE SecurityMode
smooth NULL
Definition: ftsmooth.c:416
#define SE_GROUP_ENABLED_BY_DEFAULT
Definition: setypes.h:91
HANDLE LsaHandle
Definition: msgina.h:39
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
Definition: psfuncs.h:715
ULONG LSA_OPERATIONAL_MODE
Definition: ntsecapi.h:367
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:526
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
struct _MSV1_0_INTERACTIVE_LOGON MSV1_0_INTERACTIVE_LOGON
UNICODE_STRING UserName
Definition: ntsecapi.h:436
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SE_GROUP_ENABLED
Definition: setypes.h:92
DWORD LowPart
static const CHAR User32TokenSourceName[]
Definition: lsa.c:51
#define SECURITY_LOCAL_RID
Definition: setypes.h:514
_In_opt_ LPSTR _In_opt_ LPSTR _In_ DWORD _In_ DWORD _Out_opt_ PHANDLE phToken
Definition: winbase.h:2674
PCHAR Buffer
Definition: ntsecapi.h:174
#define SE_GROUP_MANDATORY
Definition: setypes.h:90
#define SECURITY_NULL_RID
Definition: setypes.h:512
ULONG AuthenticationPackage
Definition: msgina.h:40
LONG HighPart
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
_IRQL_requires_same_ _In_ PLSA_STRING _In_ SECURITY_LOGON_TYPE _In_ ULONG _In_ ULONG _In_opt_ PTOKEN_GROUPS _In_ PTOKEN_SOURCE _Out_ PVOID * ProfileBuffer
ULONG AuthenticationPackage
Definition: logon.c:18
Status
Definition: gdiplustypes.h:24
#define SE_GROUP_LOGON_ID
Definition: setypes.h:98
NTSTATUS NTAPI LsaFreeReturnBuffer(IN PVOID Buffer)
Definition: lsa.c:120
#define ERR(fmt,...)
Definition: debug.h:110
NTSTATUS NTAPI LsaRegisterLogonProcess(IN PLSA_STRING LogonProcessName, OUT PHANDLE LsaHandle, OUT PLSA_OPERATIONAL_MODE OperationalMode)
Definition: lsa.c:249
BOOL WINAPI AllocateLocallyUniqueId(PLUID Luid)
Definition: security.c:1097
_In_opt_ LPSTR lpszDomain
Definition: winbase.h:2674
WCHAR SourceName[256]
Definition: arping.c:28
_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
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define SECURITY_LOGON_IDS_RID
Definition: setypes.h:532
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ULONG_PTR
Definition: config.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:3014
UNICODE_STRING LogonDomainName
Definition: ntsecapi.h:435
static SID_IDENTIFIER_AUTHORITY SystemAuthority
Definition: msgina.c:38