ntdll: Simplify RtlFormatCurrentUserKeyPath using GetCurrentThreadEffectiveToken.
Signed-off-by: Sebastian Lackner <sebastian@fds-team.de> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
b0534c12c0
commit
be74d3a5d5
|
@ -911,42 +911,33 @@ NTSTATUS WINAPI NtUnloadKey(IN POBJECT_ATTRIBUTES attr)
|
||||||
NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
|
NTSTATUS WINAPI RtlFormatCurrentUserKeyPath( IN OUT PUNICODE_STRING KeyPath)
|
||||||
{
|
{
|
||||||
static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
|
static const WCHAR pathW[] = {'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\'};
|
||||||
HANDLE token;
|
char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
|
||||||
|
DWORD len = sizeof(buffer);
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
|
|
||||||
status = NtOpenThreadToken(GetCurrentThread(), TOKEN_READ, TRUE, &token);
|
status = NtQueryInformationToken(GetCurrentThreadEffectiveToken(), TokenUser, buffer, len, &len);
|
||||||
if (status == STATUS_NO_TOKEN)
|
|
||||||
status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token);
|
|
||||||
if (status == STATUS_SUCCESS)
|
if (status == STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
char buffer[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD)*SID_MAX_SUB_AUTHORITIES];
|
KeyPath->MaximumLength = 0;
|
||||||
DWORD len = sizeof(buffer);
|
status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
|
||||||
|
if (status == STATUS_BUFFER_OVERFLOW)
|
||||||
status = NtQueryInformationToken(token, TokenUser, buffer, len, &len);
|
|
||||||
if (status == STATUS_SUCCESS)
|
|
||||||
{
|
{
|
||||||
KeyPath->MaximumLength = 0;
|
PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
|
||||||
status = RtlConvertSidToUnicodeString(KeyPath, ((TOKEN_USER *)buffer)->User.Sid, FALSE);
|
sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
|
||||||
if (status == STATUS_BUFFER_OVERFLOW)
|
if (buf)
|
||||||
{
|
{
|
||||||
PWCHAR buf = RtlAllocateHeap(GetProcessHeap(), 0,
|
memcpy(buf, pathW, sizeof(pathW));
|
||||||
sizeof(pathW) + KeyPath->Length + sizeof(WCHAR));
|
KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
|
||||||
if (buf)
|
KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
|
||||||
{
|
status = RtlConvertSidToUnicodeString(KeyPath,
|
||||||
memcpy(buf, pathW, sizeof(pathW));
|
((TOKEN_USER *)buffer)->User.Sid, FALSE);
|
||||||
KeyPath->MaximumLength = KeyPath->Length + sizeof(WCHAR);
|
KeyPath->Buffer = buf;
|
||||||
KeyPath->Buffer = (PWCHAR)((LPBYTE)buf + sizeof(pathW));
|
KeyPath->Length += sizeof(pathW);
|
||||||
status = RtlConvertSidToUnicodeString(KeyPath,
|
KeyPath->MaximumLength += sizeof(pathW);
|
||||||
((TOKEN_USER *)buffer)->User.Sid, FALSE);
|
|
||||||
KeyPath->Buffer = buf;
|
|
||||||
KeyPath->Length += sizeof(pathW);
|
|
||||||
KeyPath->MaximumLength += sizeof(pathW);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
status = STATUS_NO_MEMORY;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
status = STATUS_NO_MEMORY;
|
||||||
}
|
}
|
||||||
NtClose(token);
|
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue