From 8810aa8908ed7887616d86dd5fb821fcfa92f444 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Fri, 3 Jun 2022 17:50:22 -0500 Subject: Update Burn algorithm for picking elevated temp path to use SystemTemp. --- src/libs/dutil/WixToolset.DUtil/procutil.cpp | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/libs/dutil/WixToolset.DUtil/procutil.cpp') diff --git a/src/libs/dutil/WixToolset.DUtil/procutil.cpp b/src/libs/dutil/WixToolset.DUtil/procutil.cpp index a3131b7a..340a0cda 100644 --- a/src/libs/dutil/WixToolset.DUtil/procutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/procutil.cpp @@ -9,6 +9,7 @@ #define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) #define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) #define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) +#define ProcExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, e, s, __VA_ARGS__) #define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) #define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) #define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) @@ -75,6 +76,73 @@ LExit: return hr; } +extern "C" HRESULT DAPI ProcSystem( + __in HANDLE hProcess, + __out BOOL* pfSystem + ) +{ + HRESULT hr = S_OK; + TOKEN_USER* pTokenUser = NULL; + + hr = ProcTokenUser(hProcess, &pTokenUser); + ProcExitOnFailure(hr, "Failed to get TokenUser from process token."); + + *pfSystem = ::IsWellKnownSid(pTokenUser->User.Sid, WinLocalSystemSid); + +LExit: + ReleaseMem(pTokenUser); + + return hr; +} + +extern "C" HRESULT DAPI ProcTokenUser( + __in HANDLE hProcess, + __out TOKEN_USER** ppTokenUser + ) +{ + HRESULT hr = S_OK; + DWORD er = ERROR_SUCCESS; + HANDLE hToken = NULL; + TOKEN_USER* pTokenUser = NULL; + DWORD cbToken = 0; + + if (!::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) + { + ProcExitWithLastError(hr, "Failed to open process token."); + } + + if (::GetTokenInformation(hToken, TokenUser, pTokenUser, 0, &cbToken)) + { + er = ERROR_SUCCESS; + } + else + { + er = ::GetLastError(); + } + + if (er != ERROR_INSUFFICIENT_BUFFER) + { + ProcExitOnWin32Error(er, hr, "Failed to get user from process token size."); + } + + pTokenUser = reinterpret_cast(MemAlloc(cbToken, TRUE)); + ProcExitOnNull(pTokenUser, hr, E_OUTOFMEMORY, "Failed to allocate token information."); + + if (!::GetTokenInformation(hToken, TokenUser, pTokenUser, cbToken, &cbToken)) + { + ProcExitWithLastError(hr, "Failed to get user from process token."); + } + + *ppTokenUser = pTokenUser; + pTokenUser = NULL; + +LExit: + ReleaseMem(pTokenUser); + ReleaseHandle(hToken); + + return hr; +} + extern "C" HRESULT DAPI ProcWow64( __in HANDLE hProcess, __out BOOL* pfWow64 -- cgit v1.2.3-55-g6feb