mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[MSV1_0] Add logon support for the LocalService and NetworkService accounts
This commit is contained in:
parent
fc788cf2fd
commit
f42b4bbe17
1 changed files with 266 additions and 140 deletions
|
@ -22,7 +22,7 @@ LSA_DISPATCH_TABLE DispatchTable;
|
||||||
|
|
||||||
static
|
static
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
GetDomainSid(PRPC_SID *Sid)
|
GetAccountDomainSid(PRPC_SID *Sid)
|
||||||
{
|
{
|
||||||
LSAPR_HANDLE PolicyHandle = NULL;
|
LSAPR_HANDLE PolicyHandle = NULL;
|
||||||
PLSAPR_POLICY_INFORMATION PolicyInfo = NULL;
|
PLSAPR_POLICY_INFORMATION PolicyInfo = NULL;
|
||||||
|
@ -69,6 +69,27 @@ done:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
NTSTATUS
|
||||||
|
GetNtAuthorityDomainSid(PRPC_SID *Sid)
|
||||||
|
{
|
||||||
|
SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
|
||||||
|
ULONG Length = 0;
|
||||||
|
|
||||||
|
Length = RtlLengthRequiredSid(0);
|
||||||
|
*Sid = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
|
||||||
|
if (*Sid == NULL)
|
||||||
|
{
|
||||||
|
ERR("Failed to allocate SID\n");
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtlInitializeSid(*Sid,&NtAuthority, 0);
|
||||||
|
|
||||||
|
return STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
BuildInteractiveProfileBuffer(IN PLSA_CLIENT_REQUEST ClientRequest,
|
BuildInteractiveProfileBuffer(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
|
@ -287,34 +308,72 @@ BuildTokenPrimaryGroup(OUT PTOKEN_PRIMARY_GROUP PrimaryGroup,
|
||||||
static
|
static
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
BuildTokenGroups(OUT PTOKEN_GROUPS *Groups,
|
BuildTokenGroups(OUT PTOKEN_GROUPS *Groups,
|
||||||
IN PSID AccountDomainSid)
|
IN PSID AccountDomainSid,
|
||||||
|
IN ULONG RelativeId,
|
||||||
|
IN BOOL SpecialAccount)
|
||||||
{
|
{
|
||||||
SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
|
SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
|
||||||
PTOKEN_GROUPS TokenGroups;
|
PTOKEN_GROUPS TokenGroups;
|
||||||
#define MAX_GROUPS 2
|
|
||||||
DWORD GroupCount = 0;
|
DWORD GroupCount = 0;
|
||||||
|
DWORD MaxGroups = 2;
|
||||||
PSID Sid;
|
PSID Sid;
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
|
||||||
|
if (SpecialAccount)
|
||||||
|
MaxGroups++;
|
||||||
|
|
||||||
TokenGroups = DispatchTable.AllocateLsaHeap(sizeof(TOKEN_GROUPS) +
|
TokenGroups = DispatchTable.AllocateLsaHeap(sizeof(TOKEN_GROUPS) +
|
||||||
MAX_GROUPS * sizeof(SID_AND_ATTRIBUTES));
|
MaxGroups * sizeof(SID_AND_ATTRIBUTES));
|
||||||
if (TokenGroups == NULL)
|
if (TokenGroups == NULL)
|
||||||
{
|
{
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SpecialAccount)
|
||||||
|
{
|
||||||
|
/* Self */
|
||||||
|
Sid = AppendRidToSid(AccountDomainSid, RelativeId);
|
||||||
|
if (Sid == NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TokenGroups->Groups[GroupCount].Sid = Sid;
|
||||||
|
TokenGroups->Groups[GroupCount].Attributes =
|
||||||
|
SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY;
|
||||||
|
GroupCount++;
|
||||||
|
|
||||||
|
/* Member of 'Users' alias */
|
||||||
|
RtlAllocateAndInitializeSid(&SystemAuthority,
|
||||||
|
2,
|
||||||
|
SECURITY_BUILTIN_DOMAIN_RID,
|
||||||
|
DOMAIN_ALIAS_RID_USERS,
|
||||||
|
SECURITY_NULL_RID,
|
||||||
|
SECURITY_NULL_RID,
|
||||||
|
SECURITY_NULL_RID,
|
||||||
|
SECURITY_NULL_RID,
|
||||||
|
SECURITY_NULL_RID,
|
||||||
|
SECURITY_NULL_RID,
|
||||||
|
&Sid);
|
||||||
|
TokenGroups->Groups[GroupCount].Sid = Sid;
|
||||||
|
TokenGroups->Groups[GroupCount].Attributes =
|
||||||
|
SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY;
|
||||||
|
GroupCount++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Member of the domains users group */
|
||||||
Sid = AppendRidToSid(AccountDomainSid, DOMAIN_GROUP_RID_USERS);
|
Sid = AppendRidToSid(AccountDomainSid, DOMAIN_GROUP_RID_USERS);
|
||||||
if (Sid == NULL)
|
if (Sid == NULL)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Member of the domain */
|
|
||||||
TokenGroups->Groups[GroupCount].Sid = Sid;
|
TokenGroups->Groups[GroupCount].Sid = Sid;
|
||||||
TokenGroups->Groups[GroupCount].Attributes =
|
TokenGroups->Groups[GroupCount].Attributes =
|
||||||
SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY;
|
SE_GROUP_ENABLED | SE_GROUP_ENABLED_BY_DEFAULT | SE_GROUP_MANDATORY;
|
||||||
GroupCount++;
|
GroupCount++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Member of 'Authenticated users' */
|
/* Member of 'Authenticated users' */
|
||||||
RtlAllocateAndInitializeSid(&SystemAuthority,
|
RtlAllocateAndInitializeSid(&SystemAuthority,
|
||||||
|
@ -334,7 +393,7 @@ BuildTokenGroups(OUT PTOKEN_GROUPS *Groups,
|
||||||
GroupCount++;
|
GroupCount++;
|
||||||
|
|
||||||
TokenGroups->GroupCount = GroupCount;
|
TokenGroups->GroupCount = GroupCount;
|
||||||
ASSERT(TokenGroups->GroupCount <= MAX_GROUPS);
|
ASSERT(TokenGroups->GroupCount <= MaxGroups);
|
||||||
|
|
||||||
*Groups = TokenGroups;
|
*Groups = TokenGroups;
|
||||||
|
|
||||||
|
@ -346,7 +405,8 @@ static
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
|
BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
|
||||||
PRPC_SID AccountDomainSid,
|
PRPC_SID AccountDomainSid,
|
||||||
PSAMPR_USER_INFO_BUFFER UserInfo)
|
PSAMPR_USER_INFO_BUFFER UserInfo,
|
||||||
|
BOOL SpecialAccount)
|
||||||
{
|
{
|
||||||
PLSA_TOKEN_INFORMATION_V1 Buffer = NULL;
|
PLSA_TOKEN_INFORMATION_V1 Buffer = NULL;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
@ -376,7 +436,9 @@ BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
Status = BuildTokenGroups(&Buffer->Groups,
|
Status = BuildTokenGroups(&Buffer->Groups,
|
||||||
(PSID)AccountDomainSid);
|
(PSID)AccountDomainSid,
|
||||||
|
UserInfo->All.UserId,
|
||||||
|
SpecialAccount);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
@ -970,9 +1032,10 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
// LARGE_INTEGER AccountExpires;
|
// LARGE_INTEGER AccountExpires;
|
||||||
LARGE_INTEGER PasswordMustChange;
|
LARGE_INTEGER PasswordMustChange;
|
||||||
LARGE_INTEGER PasswordLastSet;
|
LARGE_INTEGER PasswordLastSet;
|
||||||
|
BOOL SpecialAccount = FALSE;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
TRACE("()\n");
|
TRACE("LsaApLogonUser()\n");
|
||||||
|
|
||||||
TRACE("LogonType: %lu\n", LogonType);
|
TRACE("LogonType: %lu\n", LogonType);
|
||||||
TRACE("AuthenticationInformation: %p\n", AuthenticationInformation);
|
TRACE("AuthenticationInformation: %p\n", AuthenticationInformation);
|
||||||
|
@ -1012,11 +1075,72 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
/* Get the logon time */
|
/* Get the logon time */
|
||||||
NtQuerySystemTime(&LogonTime);
|
NtQuerySystemTime(&LogonTime);
|
||||||
|
|
||||||
/* Get the domain SID */
|
/* Check for special accounts */
|
||||||
Status = GetDomainSid(&AccountDomainSid);
|
if (_wcsicmp(LogonInfo->LogonDomainName.Buffer, L"NT AUTHORITY") == 0)
|
||||||
|
{
|
||||||
|
SpecialAccount = TRUE;
|
||||||
|
|
||||||
|
/* Get the authority domain SID */
|
||||||
|
Status = GetNtAuthorityDomainSid(&AccountDomainSid);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("GetDomainSid() failed (Status 0x%08lx)\n", Status);
|
ERR("GetNtAuthorityDomainSid() failed (Status 0x%08lx)\n", Status);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_wcsicmp(LogonInfo->UserName.Buffer, L"LocalService") == 0)
|
||||||
|
{
|
||||||
|
TRACE("SpecialAccount: LocalService\n");
|
||||||
|
|
||||||
|
if (LogonType != Service)
|
||||||
|
return STATUS_LOGON_FAILURE;
|
||||||
|
|
||||||
|
UserInfo = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(SAMPR_USER_ALL_INFORMATION));
|
||||||
|
if (UserInfo == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserInfo->All.UserId = SECURITY_LOCAL_SERVICE_RID;
|
||||||
|
UserInfo->All.PrimaryGroupId = SECURITY_LOCAL_SERVICE_RID;
|
||||||
|
}
|
||||||
|
else if (_wcsicmp(LogonInfo->UserName.Buffer, L"NetworkService") == 0)
|
||||||
|
{
|
||||||
|
TRACE("SpecialAccount: NetworkService\n");
|
||||||
|
|
||||||
|
if (LogonType != Service)
|
||||||
|
return STATUS_LOGON_FAILURE;
|
||||||
|
|
||||||
|
UserInfo = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
sizeof(SAMPR_USER_ALL_INFORMATION));
|
||||||
|
if (UserInfo == NULL)
|
||||||
|
{
|
||||||
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserInfo->All.UserId = SECURITY_NETWORK_SERVICE_RID;
|
||||||
|
UserInfo->All.PrimaryGroupId = SECURITY_NETWORK_SERVICE_RID;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Status = STATUS_NO_SUCH_USER;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TRACE("NormalAccount\n");
|
||||||
|
|
||||||
|
/* Get the account domain SID */
|
||||||
|
Status = GetAccountDomainSid(&AccountDomainSid);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
ERR("GetAccountDomainSid() failed (Status 0x%08lx)\n", Status);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1038,7 +1162,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
&DomainHandle);
|
&DomainHandle);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("SamrOpenDomain failed (Status %08lx)\n", Status);
|
ERR("SamrOpenDomain failed (Status %08lx)\n", Status);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,7 +1178,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
&Use);
|
&Use);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("SamrLookupNamesInDomain failed (Status %08lx)\n", Status);
|
ERR("SamrLookupNamesInDomain failed (Status %08lx)\n", Status);
|
||||||
Status = STATUS_NO_SUCH_USER;
|
Status = STATUS_NO_SUCH_USER;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -1062,7 +1186,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
/* Fail, if it is not a user account */
|
/* Fail, if it is not a user account */
|
||||||
if (Use.Element[0] != SidTypeUser)
|
if (Use.Element[0] != SidTypeUser)
|
||||||
{
|
{
|
||||||
TRACE("Account is not a user account!\n");
|
ERR("Account is not a user account!\n");
|
||||||
Status = STATUS_NO_SUCH_USER;
|
Status = STATUS_NO_SUCH_USER;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -1075,7 +1199,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
&UserHandle);
|
&UserHandle);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("SamrOpenUser failed (Status %08lx)\n", Status);
|
ERR("SamrOpenUser failed (Status %08lx)\n", Status);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1084,7 +1208,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
&UserInfo);
|
&UserInfo);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("SamrQueryInformationUser failed (Status %08lx)\n", Status);
|
ERR("SamrQueryInformationUser failed (Status %08lx)\n", Status);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1097,7 +1221,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
UserInfo);
|
UserInfo);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("MsvpCheckPassword failed (Status %08lx)\n", Status);
|
ERR("MsvpCheckPassword failed (Status %08lx)\n", Status);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1160,6 +1284,7 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
// STATUS_INVALID_LOGON_HOURS;
|
// STATUS_INVALID_LOGON_HOURS;
|
||||||
// STATUS_INVALID_WORKSTATION;
|
// STATUS_INVALID_WORKSTATION;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Return logon information */
|
/* Return logon information */
|
||||||
|
|
||||||
|
@ -1199,7 +1324,8 @@ LsaApLogonUser(IN PLSA_CLIENT_REQUEST ClientRequest,
|
||||||
/* Build and fill the token information buffer */
|
/* Build and fill the token information buffer */
|
||||||
Status = BuildTokenInformationBuffer((PLSA_TOKEN_INFORMATION_V1*)TokenInformation,
|
Status = BuildTokenInformationBuffer((PLSA_TOKEN_INFORMATION_V1*)TokenInformation,
|
||||||
AccountDomainSid,
|
AccountDomainSid,
|
||||||
UserInfo);
|
UserInfo,
|
||||||
|
SpecialAccount);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status);
|
TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status);
|
||||||
|
|
Loading…
Reference in a new issue