2 * PROJECT: ReactOS msgina.dll
3 * FILE: dll/win32/msgina/gui.c
4 * PURPOSE: ReactOS Logon GINA DLL
5 * PROGRAMMER: Eric Kohl
12 PGINA_CONTEXT pgContext
)
14 LSA_STRING LogonProcessName
;
15 LSA_STRING PackageName
;
16 LSA_OPERATIONAL_MODE SecurityMode
= 0;
19 /* We are already connected to the LSA */
20 if (pgContext
->LsaHandle
!= NULL
)
21 return STATUS_SUCCESS
;
23 /* Connect to the LSA server */
24 RtlInitAnsiString((PANSI_STRING
)&LogonProcessName
,
27 Status
= LsaRegisterLogonProcess(&LogonProcessName
,
28 &pgContext
->LsaHandle
,
30 if (!NT_SUCCESS(Status
))
32 ERR("LsaRegisterLogonProcess failed (Status 0x%08lx)\n", Status
);
36 /* Get the authentication package */
37 RtlInitAnsiString((PANSI_STRING
)&PackageName
,
40 Status
= LsaLookupAuthenticationPackage(pgContext
->LsaHandle
,
42 &pgContext
->AuthenticationPackage
);
43 if (!NT_SUCCESS(Status
))
45 ERR("LsaLookupAuthenticationPackage failed (Status 0x%08lx)\n", Status
);
55 ULONG AuthenticationPackage
,
62 SID_IDENTIFIER_AUTHORITY LocalAuthority
= {SECURITY_LOCAL_SID_AUTHORITY
};
63 SID_IDENTIFIER_AUTHORITY SystemAuthority
= {SECURITY_NT_AUTHORITY
};
66 LSA_STRING OriginName
;
67 UNICODE_STRING DomainName
;
68 UNICODE_STRING UserName
;
69 UNICODE_STRING Password
;
70 PMSV1_0_INTERACTIVE_LOGON AuthInfo
= NULL
;
73 TOKEN_SOURCE TokenSource
;
74 PTOKEN_GROUPS TokenGroups
= NULL
;
75 PMSV1_0_INTERACTIVE_PROFILE ProfileBuffer
= NULL
;
76 ULONG ProfileBufferLength
= 0;
78 LUID LogonId
= {0, 0};
79 HANDLE TokenHandle
= NULL
;
80 QUOTA_LIMITS QuotaLimits
;
85 RtlInitAnsiString((PANSI_STRING
)&OriginName
,
88 RtlInitUnicodeString(&DomainName
,
91 RtlInitUnicodeString(&UserName
,
94 RtlInitUnicodeString(&Password
,
97 AuthInfoLength
= sizeof(MSV1_0_INTERACTIVE_LOGON
)+
98 DomainName
.MaximumLength
+
99 UserName
.MaximumLength
+
100 Password
.MaximumLength
;
102 AuthInfo
= RtlAllocateHeap(RtlGetProcessHeap(),
105 if (AuthInfo
== NULL
)
107 Status
= STATUS_INSUFFICIENT_RESOURCES
;
111 AuthInfo
->MessageType
= MsV1_0InteractiveLogon
;
113 Ptr
= (ULONG_PTR
)AuthInfo
+ sizeof(MSV1_0_INTERACTIVE_LOGON
);
115 AuthInfo
->LogonDomainName
.Length
= DomainName
.Length
;
116 AuthInfo
->LogonDomainName
.MaximumLength
= DomainName
.MaximumLength
;
117 AuthInfo
->LogonDomainName
.Buffer
= (DomainName
.Buffer
== NULL
) ? NULL
: (PWCHAR
)Ptr
;
118 if (DomainName
.MaximumLength
> 0)
120 RtlCopyMemory(AuthInfo
->LogonDomainName
.Buffer
,
122 DomainName
.MaximumLength
);
124 Ptr
+= DomainName
.MaximumLength
;
127 AuthInfo
->UserName
.Length
= UserName
.Length
;
128 AuthInfo
->UserName
.MaximumLength
= UserName
.MaximumLength
;
129 AuthInfo
->UserName
.Buffer
= (PWCHAR
)Ptr
;
130 if (UserName
.MaximumLength
> 0)
131 RtlCopyMemory(AuthInfo
->UserName
.Buffer
,
133 UserName
.MaximumLength
);
135 Ptr
+= UserName
.MaximumLength
;
137 AuthInfo
->Password
.Length
= Password
.Length
;
138 AuthInfo
->Password
.MaximumLength
= Password
.MaximumLength
;
139 AuthInfo
->Password
.Buffer
= (PWCHAR
)Ptr
;
140 if (Password
.MaximumLength
> 0)
141 RtlCopyMemory(AuthInfo
->Password
.Buffer
,
143 Password
.MaximumLength
);
145 /* Create the Logon SID*/
146 AllocateLocallyUniqueId(&LogonId
);
147 Status
= RtlAllocateAndInitializeSid(&SystemAuthority
,
148 SECURITY_LOGON_IDS_RID_COUNT
,
149 SECURITY_LOGON_IDS_RID
,
158 if (!NT_SUCCESS(Status
))
161 /* Create the Local SID*/
162 Status
= RtlAllocateAndInitializeSid(&LocalAuthority
,
173 if (!NT_SUCCESS(Status
))
176 /* Allocate and set the token groups */
177 TokenGroups
= RtlAllocateHeap(RtlGetProcessHeap(),
179 sizeof(TOKEN_GROUPS
) + ((2 - ANYSIZE_ARRAY
) * sizeof(SID_AND_ATTRIBUTES
)));
180 if (TokenGroups
== NULL
)
182 Status
= STATUS_INSUFFICIENT_RESOURCES
;
186 TokenGroups
->GroupCount
= 2;
187 TokenGroups
->Groups
[0].Sid
= LogonSid
;
188 TokenGroups
->Groups
[0].Attributes
= SE_GROUP_MANDATORY
| SE_GROUP_ENABLED
|
189 SE_GROUP_ENABLED_BY_DEFAULT
| SE_GROUP_LOGON_ID
;
190 TokenGroups
->Groups
[1].Sid
= LocalSid
;
191 TokenGroups
->Groups
[1].Attributes
= SE_GROUP_MANDATORY
| SE_GROUP_ENABLED
|
192 SE_GROUP_ENABLED_BY_DEFAULT
;
194 /* Set the token source */
195 strcpy(TokenSource
.SourceName
, "LogonUser");
196 AllocateLocallyUniqueId(&TokenSource
.SourceIdentifier
);
198 Status
= LsaLogonUser(LsaHandle
,
201 AuthenticationPackage
,
206 (PVOID
*)&ProfileBuffer
,
207 &ProfileBufferLength
,
212 if (!NT_SUCCESS(Status
))
214 ERR("LsaLogonUser failed (Status 0x%08lx)\n", Status
);
218 if (ProfileBuffer
!= NULL
)
220 TRACE("ProfileBuffer: %p\n", ProfileBuffer
);
221 TRACE("MessageType: %u\n", ProfileBuffer
->MessageType
);
223 TRACE("FullName: %p\n", ProfileBuffer
->FullName
.Buffer
);
224 TRACE("FullName: %S\n", ProfileBuffer
->FullName
.Buffer
);
226 TRACE("LogonServer: %p\n", ProfileBuffer
->LogonServer
.Buffer
);
227 TRACE("LogonServer: %S\n", ProfileBuffer
->LogonServer
.Buffer
);
230 TRACE("Luid: 0x%08lx%08lx\n", Luid
.HighPart
, Luid
.LowPart
);
232 if (TokenHandle
!= NULL
)
234 TRACE("TokenHandle: %p\n", TokenHandle
);
237 *phToken
= TokenHandle
;
240 if (ProfileBuffer
!= NULL
)
241 LsaFreeReturnBuffer(ProfileBuffer
);
243 if (!NT_SUCCESS(Status
))
245 if (TokenHandle
!= NULL
)
246 CloseHandle(TokenHandle
);
249 if (TokenGroups
!= NULL
)
250 RtlFreeHeap(RtlGetProcessHeap(), 0, TokenGroups
);
252 if (LocalSid
!= NULL
)
253 RtlFreeSid(LocalSid
);
255 if (LogonSid
!= NULL
)
256 RtlFreeSid(LogonSid
);
258 if (AuthInfo
!= NULL
)
259 RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo
);