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
)
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
);
56 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
;
81 NTSTATUS SubStatus
= STATUS_SUCCESS
;
86 RtlInitAnsiString((PANSI_STRING
)&OriginName
,
89 RtlInitUnicodeString(&DomainName
,
92 RtlInitUnicodeString(&UserName
,
95 RtlInitUnicodeString(&Password
,
98 AuthInfoLength
= sizeof(MSV1_0_INTERACTIVE_LOGON
)+
99 DomainName
.MaximumLength
+
100 UserName
.MaximumLength
+
101 Password
.MaximumLength
;
103 AuthInfo
= RtlAllocateHeap(RtlGetProcessHeap(),
106 if (AuthInfo
== NULL
)
108 Status
= STATUS_INSUFFICIENT_RESOURCES
;
112 AuthInfo
->MessageType
= MsV1_0InteractiveLogon
;
114 Ptr
= (ULONG_PTR
)AuthInfo
+ sizeof(MSV1_0_INTERACTIVE_LOGON
);
116 AuthInfo
->LogonDomainName
.Length
= DomainName
.Length
;
117 AuthInfo
->LogonDomainName
.MaximumLength
= DomainName
.MaximumLength
;
118 AuthInfo
->LogonDomainName
.Buffer
= (DomainName
.Buffer
== NULL
) ? NULL
: (PWCHAR
)Ptr
;
119 if (DomainName
.MaximumLength
> 0)
121 RtlCopyMemory(AuthInfo
->LogonDomainName
.Buffer
,
123 DomainName
.MaximumLength
);
125 Ptr
+= DomainName
.MaximumLength
;
128 AuthInfo
->UserName
.Length
= UserName
.Length
;
129 AuthInfo
->UserName
.MaximumLength
= UserName
.MaximumLength
;
130 AuthInfo
->UserName
.Buffer
= (PWCHAR
)Ptr
;
131 if (UserName
.MaximumLength
> 0)
132 RtlCopyMemory(AuthInfo
->UserName
.Buffer
,
134 UserName
.MaximumLength
);
136 Ptr
+= UserName
.MaximumLength
;
138 AuthInfo
->Password
.Length
= Password
.Length
;
139 AuthInfo
->Password
.MaximumLength
= Password
.MaximumLength
;
140 AuthInfo
->Password
.Buffer
= (PWCHAR
)Ptr
;
141 if (Password
.MaximumLength
> 0)
142 RtlCopyMemory(AuthInfo
->Password
.Buffer
,
144 Password
.MaximumLength
);
146 /* Create the Logon SID*/
147 AllocateLocallyUniqueId(&LogonId
);
148 Status
= RtlAllocateAndInitializeSid(&SystemAuthority
,
149 SECURITY_LOGON_IDS_RID_COUNT
,
150 SECURITY_LOGON_IDS_RID
,
159 if (!NT_SUCCESS(Status
))
162 /* Create the Local SID*/
163 Status
= RtlAllocateAndInitializeSid(&LocalAuthority
,
174 if (!NT_SUCCESS(Status
))
177 /* Allocate and set the token groups */
178 TokenGroups
= RtlAllocateHeap(RtlGetProcessHeap(),
180 sizeof(TOKEN_GROUPS
) + ((2 - ANYSIZE_ARRAY
) * sizeof(SID_AND_ATTRIBUTES
)));
181 if (TokenGroups
== NULL
)
183 Status
= STATUS_INSUFFICIENT_RESOURCES
;
187 TokenGroups
->GroupCount
= 2;
188 TokenGroups
->Groups
[0].Sid
= LogonSid
;
189 TokenGroups
->Groups
[0].Attributes
= SE_GROUP_MANDATORY
| SE_GROUP_ENABLED
|
190 SE_GROUP_ENABLED_BY_DEFAULT
| SE_GROUP_LOGON_ID
;
191 TokenGroups
->Groups
[1].Sid
= LocalSid
;
192 TokenGroups
->Groups
[1].Attributes
= SE_GROUP_MANDATORY
| SE_GROUP_ENABLED
|
193 SE_GROUP_ENABLED_BY_DEFAULT
;
195 /* Set the token source */
196 strcpy(TokenSource
.SourceName
, "LogonUser");
197 AllocateLocallyUniqueId(&TokenSource
.SourceIdentifier
);
199 Status
= LsaLogonUser(LsaHandle
,
202 AuthenticationPackage
,
207 (PVOID
*)&ProfileBuffer
,
208 &ProfileBufferLength
,
213 if (!NT_SUCCESS(Status
))
215 ERR("LsaLogonUser failed (Status 0x%08lx)\n", Status
);
219 if (ProfileBuffer
!= NULL
)
221 TRACE("ProfileBuffer: %p\n", ProfileBuffer
);
222 TRACE("MessageType: %u\n", ProfileBuffer
->MessageType
);
224 TRACE("FullName: %p\n", ProfileBuffer
->FullName
.Buffer
);
225 TRACE("FullName: %S\n", ProfileBuffer
->FullName
.Buffer
);
227 TRACE("LogonServer: %p\n", ProfileBuffer
->LogonServer
.Buffer
);
228 TRACE("LogonServer: %S\n", ProfileBuffer
->LogonServer
.Buffer
);
231 TRACE("Luid: 0x%08lx%08lx\n", Luid
.HighPart
, Luid
.LowPart
);
233 if (TokenHandle
!= NULL
)
235 TRACE("TokenHandle: %p\n", TokenHandle
);
238 *phToken
= TokenHandle
;
241 if (ProfileBuffer
!= NULL
)
242 LsaFreeReturnBuffer(ProfileBuffer
);
244 if (!NT_SUCCESS(Status
))
246 if (TokenHandle
!= NULL
)
247 CloseHandle(TokenHandle
);
250 if (TokenGroups
!= NULL
)
251 RtlFreeHeap(RtlGetProcessHeap(), 0, TokenGroups
);
253 if (LocalSid
!= NULL
)
254 RtlFreeSid(LocalSid
);
256 if (LogonSid
!= NULL
)
257 RtlFreeSid(LogonSid
);
259 if (AuthInfo
!= NULL
)
260 RtlFreeHeap(RtlGetProcessHeap(), 0, AuthInfo
);
262 if (!NT_SUCCESS(Status
))
264 SetLastError(RtlNtStatusToDosError(Status
));