From 35596ee290504d8b48ffe9711ccd2a66da18095c Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Wed, 26 Apr 2006 15:43:54 +0100 Subject: [PATCH] advapi32: Implement the majority of ImpersonateLoggedOnUser. --- dlls/advapi32/security.c | 48 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c index 0c7327d65ea..f5472a8215d 100644 --- a/dlls/advapi32/security.c +++ b/dlls/advapi32/security.c @@ -1667,8 +1667,52 @@ ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel) */ BOOL WINAPI ImpersonateLoggedOnUser(HANDLE hToken) { - FIXME("(%p):stub returning FALSE\n", hToken); - return FALSE; + NTSTATUS Status; + HANDLE ImpersonationToken; + TOKEN_TYPE Type = TokenImpersonation; + + FIXME( "(%p)\n", hToken ); + + /* FIXME: get token type */ + + if (Type == TokenPrimary) + { + OBJECT_ATTRIBUTES ObjectAttributes; + + InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL ); + + Status = NtDuplicateToken( hToken, + TOKEN_IMPERSONATE | TOKEN_QUERY, + &ObjectAttributes, + SecurityImpersonation, + TokenImpersonation, + &ImpersonationToken ); + if (Status != STATUS_SUCCESS) + { + ERR( "NtDuplicateToken failed with error 0x%08lx\n", Status ); + SetLastError( RtlNtStatusToDosError( Status ) ); + return FALSE; + } + } + else + ImpersonationToken = hToken; + + Status = NtSetInformationThread( GetCurrentThread(), + ThreadImpersonationToken, + &ImpersonationToken, + sizeof(ImpersonationToken) ); + + if (Type == TokenPrimary) + NtClose( ImpersonationToken ); + + if (Status != STATUS_SUCCESS) + { + ERR( "NtSetInformationThread failed with error 0x%08lx\n", Status ); + SetLastError( RtlNtStatusToDosError( Status ) ); + return FALSE; + } + + return TRUE; } /******************************************************************************