- Code clean-up.
- Take the user RID and pimary group RID from the user info data.

svn path=/trunk/; revision=61460
This commit is contained in:
Eric Kohl 2013-12-28 23:47:04 +00:00
parent 40814c5eb2
commit f0b87d5d81

View file

@ -257,7 +257,7 @@ BuildTokenUser(OUT PTOKEN_USER User,
if (User->User.Sid == NULL) if (User->User.Sid == NULL)
{ {
ERR("Could not create the user SID\n"); ERR("Could not create the user SID\n");
return STATUS_UNSUCCESSFUL; return STATUS_INSUFFICIENT_RESOURCES;
} }
User->User.Attributes = 0; User->User.Attributes = 0;
@ -268,10 +268,26 @@ BuildTokenUser(OUT PTOKEN_USER User,
static static
NTSTATUS NTSTATUS
BuildTokenGroups(IN PSID AccountDomainSid, BuildTokenPrimaryGroup(OUT PTOKEN_PRIMARY_GROUP PrimaryGroup,
IN PLUID LogonId, IN PSID AccountDomainSid,
OUT PTOKEN_GROUPS *Groups, IN ULONG RelativeId)
OUT PSID *PrimaryGroupSid) {
PrimaryGroup->PrimaryGroup = AppendRidToSid(AccountDomainSid,
RelativeId);
if (PrimaryGroup->PrimaryGroup == NULL)
{
ERR("Could not create the primary group SID\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
return STATUS_SUCCESS;
}
static
NTSTATUS
BuildTokenGroups(OUT PTOKEN_GROUPS *Groups,
IN PSID AccountDomainSid)
{ {
SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY}; SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
PTOKEN_GROUPS TokenGroups; PTOKEN_GROUPS TokenGroups;
@ -297,7 +313,6 @@ BuildTokenGroups(IN PSID AccountDomainSid,
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;
*PrimaryGroupSid = Sid;
GroupCount++; GroupCount++;
@ -366,30 +381,6 @@ BuildTokenGroups(IN PSID AccountDomainSid,
} }
static
NTSTATUS
BuildTokenPrimaryGroup(PTOKEN_PRIMARY_GROUP PrimaryGroup,
PSID PrimaryGroupSid)
{
ULONG RidCount;
ULONG Size;
RidCount = *RtlSubAuthorityCountSid(PrimaryGroupSid);
Size = RtlLengthRequiredSid(RidCount);
PrimaryGroup->PrimaryGroup = DispatchTable.AllocateLsaHeap(Size);
if (PrimaryGroup->PrimaryGroup == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlCopyMemory(PrimaryGroup->PrimaryGroup,
PrimaryGroupSid,
Size);
return STATUS_SUCCESS;
}
static static
NTSTATUS NTSTATUS
BuildTokenPrivileges(PTOKEN_PRIVILEGES *TokenPrivileges) BuildTokenPrivileges(PTOKEN_PRIVILEGES *TokenPrivileges)
@ -480,11 +471,9 @@ static
NTSTATUS NTSTATUS
BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation, BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
PRPC_SID AccountDomainSid, PRPC_SID AccountDomainSid,
ULONG RelativeId, PSAMPR_USER_INFO_BUFFER UserInfo)
PLUID LogonId)
{ {
PLSA_TOKEN_INFORMATION_V1 Buffer = NULL; PLSA_TOKEN_INFORMATION_V1 Buffer = NULL;
PSID PrimaryGroupSid = NULL;
ULONG i; ULONG i;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
@ -501,19 +490,18 @@ BuildTokenInformationBuffer(PLSA_TOKEN_INFORMATION_V1 *TokenInformation,
Status = BuildTokenUser(&Buffer->User, Status = BuildTokenUser(&Buffer->User,
(PSID)AccountDomainSid, (PSID)AccountDomainSid,
RelativeId); UserInfo->All.UserId);
if (!NT_SUCCESS(Status))
goto done;
Status = BuildTokenGroups((PSID)AccountDomainSid,
LogonId,
&Buffer->Groups,
&PrimaryGroupSid);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
goto done; goto done;
Status = BuildTokenPrimaryGroup(&Buffer->PrimaryGroup, Status = BuildTokenPrimaryGroup(&Buffer->PrimaryGroup,
PrimaryGroupSid); (PSID)AccountDomainSid,
UserInfo->All.PrimaryGroupId);
if (!NT_SUCCESS(Status))
goto done;
Status = BuildTokenGroups(&Buffer->Groups,
(PSID)AccountDomainSid);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
goto done; goto done;
@ -1047,8 +1035,7 @@ 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,
RelativeIds.Element[0], UserInfo);
LogonId);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status); TRACE("BuildTokenInformationBuffer failed (Status %08lx)\n", Status);