mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 01:15:09 +00:00
[NTOSKRNL]
Fix error handling for SepDuplicateToken and SeCreateToken. svn path=/trunk/; revision=56800
This commit is contained in:
parent
fd6fcab2ca
commit
94405388d5
1 changed files with 142 additions and 89 deletions
|
@ -234,7 +234,7 @@ SepDuplicateToken(PTOKEN Token,
|
|||
ULONG uLength;
|
||||
ULONG i;
|
||||
PVOID EndMem;
|
||||
PTOKEN AccessToken;
|
||||
PTOKEN AccessToken = NULL;
|
||||
NTSTATUS Status;
|
||||
|
||||
PAGED_CODE();
|
||||
|
@ -290,10 +290,14 @@ SepDuplicateToken(PTOKEN Token,
|
|||
for (i = 0; i < Token->UserAndGroupCount; i++)
|
||||
uLength += RtlLengthSid(Token->UserAndGroups[i].Sid);
|
||||
|
||||
AccessToken->UserAndGroups =
|
||||
(PSID_AND_ATTRIBUTES)ExAllocatePoolWithTag(PagedPool,
|
||||
AccessToken->UserAndGroups = ExAllocatePoolWithTag(PagedPool,
|
||||
uLength,
|
||||
TAG_TOKEN_USERS);
|
||||
if (AccessToken->UserAndGroups == NULL)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto done;
|
||||
}
|
||||
|
||||
EndMem = &AccessToken->UserAndGroups[AccessToken->UserAndGroupCount];
|
||||
|
||||
|
@ -304,23 +308,26 @@ SepDuplicateToken(PTOKEN Token,
|
|||
EndMem,
|
||||
&EndMem,
|
||||
&uLength);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = SepFindPrimaryGroupAndDefaultOwner(
|
||||
AccessToken,
|
||||
if (!NT_SUCCESS(Status))
|
||||
goto done;
|
||||
|
||||
Status = SepFindPrimaryGroupAndDefaultOwner(AccessToken,
|
||||
Token->PrimaryGroup,
|
||||
0);
|
||||
}
|
||||
if (!NT_SUCCESS(Status))
|
||||
goto done;
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
AccessToken->PrivilegeCount = Token->PrivilegeCount;
|
||||
|
||||
uLength = AccessToken->PrivilegeCount * sizeof(LUID_AND_ATTRIBUTES);
|
||||
AccessToken->Privileges =
|
||||
(PLUID_AND_ATTRIBUTES)ExAllocatePoolWithTag(PagedPool,
|
||||
AccessToken->Privileges = ExAllocatePoolWithTag(PagedPool,
|
||||
uLength,
|
||||
TAG_TOKEN_PRIVILAGES);
|
||||
if (AccessToken->Privileges == NULL)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto done;
|
||||
}
|
||||
|
||||
for (i = 0; i < AccessToken->PrivilegeCount; i++)
|
||||
{
|
||||
|
@ -332,20 +339,38 @@ SepDuplicateToken(PTOKEN Token,
|
|||
|
||||
if (Token->DefaultDacl)
|
||||
{
|
||||
AccessToken->DefaultDacl =
|
||||
(PACL) ExAllocatePoolWithTag(PagedPool,
|
||||
AccessToken->DefaultDacl = ExAllocatePoolWithTag(PagedPool,
|
||||
Token->DefaultDacl->AclSize,
|
||||
TAG_TOKEN_ACL);
|
||||
if (AccessToken->DefaultDacl == NULL)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto done;
|
||||
}
|
||||
|
||||
memcpy(AccessToken->DefaultDacl,
|
||||
Token->DefaultDacl,
|
||||
Token->DefaultDacl->AclSize);
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
*NewAccessToken = AccessToken;
|
||||
return(STATUS_SUCCESS);
|
||||
|
||||
done:
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
if (AccessToken)
|
||||
{
|
||||
if (AccessToken->UserAndGroups)
|
||||
ExFreePoolWithTag(AccessToken->UserAndGroups, TAG_TOKEN_USERS);
|
||||
|
||||
if (AccessToken->Privileges)
|
||||
ExFreePoolWithTag(AccessToken->Privileges, TAG_TOKEN_PRIVILAGES);
|
||||
|
||||
if (AccessToken->DefaultDacl)
|
||||
ExFreePoolWithTag(AccessToken->DefaultDacl, TAG_TOKEN_ACL);
|
||||
|
||||
ObDereferenceObject(AccessToken);
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
|
@ -636,10 +661,14 @@ SepCreateToken(OUT PHANDLE TokenHandle,
|
|||
for (i = 0; i < GroupCount; i++)
|
||||
uLength += RtlLengthSid(Groups[i].Sid);
|
||||
|
||||
AccessToken->UserAndGroups =
|
||||
(PSID_AND_ATTRIBUTES)ExAllocatePoolWithTag(PagedPool,
|
||||
AccessToken->UserAndGroups = ExAllocatePoolWithTag(PagedPool,
|
||||
uLength,
|
||||
TAG_TOKEN_USERS);
|
||||
if (AccessToken->UserAndGroups == NULL)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto done;
|
||||
}
|
||||
|
||||
EndMem = &AccessToken->UserAndGroups[AccessToken->UserAndGroupCount];
|
||||
|
||||
|
@ -650,8 +679,9 @@ SepCreateToken(OUT PHANDLE TokenHandle,
|
|||
EndMem,
|
||||
&EndMem,
|
||||
&uLength);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
if (!NT_SUCCESS(Status))
|
||||
goto done;
|
||||
|
||||
Status = RtlCopySidAndAttributesArray(GroupCount,
|
||||
Groups,
|
||||
uLength,
|
||||
|
@ -659,23 +689,24 @@ SepCreateToken(OUT PHANDLE TokenHandle,
|
|||
EndMem,
|
||||
&EndMem,
|
||||
&uLength);
|
||||
}
|
||||
if (!NT_SUCCESS(Status))
|
||||
goto done;
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = SepFindPrimaryGroupAndDefaultOwner(
|
||||
AccessToken,
|
||||
Status = SepFindPrimaryGroupAndDefaultOwner(AccessToken,
|
||||
PrimaryGroup,
|
||||
Owner);
|
||||
}
|
||||
if (!NT_SUCCESS(Status))
|
||||
goto done;
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
uLength = PrivilegeCount * sizeof(LUID_AND_ATTRIBUTES);
|
||||
AccessToken->Privileges =
|
||||
(PLUID_AND_ATTRIBUTES)ExAllocatePoolWithTag(PagedPool,
|
||||
AccessToken->Privileges = ExAllocatePoolWithTag(PagedPool,
|
||||
uLength,
|
||||
TAG_TOKEN_PRIVILAGES);
|
||||
if (AccessToken->Privileges == NULL)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (PreviousMode != KernelMode)
|
||||
{
|
||||
|
@ -697,18 +728,22 @@ SepCreateToken(OUT PHANDLE TokenHandle,
|
|||
Privileges,
|
||||
PrivilegeCount * sizeof(LUID_AND_ATTRIBUTES));
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
AccessToken->DefaultDacl =
|
||||
(PACL) ExAllocatePoolWithTag(PagedPool,
|
||||
if (!NT_SUCCESS(Status))
|
||||
goto done;
|
||||
|
||||
AccessToken->DefaultDacl = ExAllocatePoolWithTag(PagedPool,
|
||||
DefaultDacl->AclSize,
|
||||
TAG_TOKEN_ACL);
|
||||
memcpy(AccessToken->DefaultDacl,
|
||||
if (AccessToken->DefaultDacl == NULL)
|
||||
{
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
goto done;
|
||||
}
|
||||
|
||||
RtlCopyMemory(AccessToken->DefaultDacl,
|
||||
DefaultDacl,
|
||||
DefaultDacl->AclSize);
|
||||
}
|
||||
|
||||
if (!SystemToken)
|
||||
{
|
||||
|
@ -729,6 +764,24 @@ SepCreateToken(OUT PHANDLE TokenHandle,
|
|||
*TokenHandle = (HANDLE)AccessToken;
|
||||
}
|
||||
|
||||
done:
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
if (AccessToken)
|
||||
{
|
||||
if (AccessToken->UserAndGroups)
|
||||
ExFreePoolWithTag(AccessToken->UserAndGroups, TAG_TOKEN_USERS);
|
||||
|
||||
if (AccessToken->Privileges)
|
||||
ExFreePoolWithTag(AccessToken->Privileges, TAG_TOKEN_PRIVILAGES);
|
||||
|
||||
if (AccessToken->DefaultDacl)
|
||||
ExFreePoolWithTag(AccessToken->DefaultDacl, TAG_TOKEN_ACL);
|
||||
|
||||
ObDereferenceObject(AccessToken);
|
||||
}
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue