diff options
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/procutil.cpp')
-rw-r--r-- | src/libs/dutil/WixToolset.DUtil/procutil.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
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 @@ | |||
9 | #define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | 9 | #define ProcExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) |
10 | #define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | 10 | #define ProcExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) |
11 | #define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | 11 | #define ProcExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) |
12 | #define ProcExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_PROCUTIL, x, e, s, __VA_ARGS__) | ||
12 | #define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) | 13 | #define ProcExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_PROCUTIL, x, s, __VA_ARGS__) |
13 | #define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) | 14 | #define ProcExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_PROCUTIL, p, x, e, s, __VA_ARGS__) |
14 | #define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) | 15 | #define ProcExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_PROCUTIL, p, x, s, __VA_ARGS__) |
@@ -75,6 +76,73 @@ LExit: | |||
75 | return hr; | 76 | return hr; |
76 | } | 77 | } |
77 | 78 | ||
79 | extern "C" HRESULT DAPI ProcSystem( | ||
80 | __in HANDLE hProcess, | ||
81 | __out BOOL* pfSystem | ||
82 | ) | ||
83 | { | ||
84 | HRESULT hr = S_OK; | ||
85 | TOKEN_USER* pTokenUser = NULL; | ||
86 | |||
87 | hr = ProcTokenUser(hProcess, &pTokenUser); | ||
88 | ProcExitOnFailure(hr, "Failed to get TokenUser from process token."); | ||
89 | |||
90 | *pfSystem = ::IsWellKnownSid(pTokenUser->User.Sid, WinLocalSystemSid); | ||
91 | |||
92 | LExit: | ||
93 | ReleaseMem(pTokenUser); | ||
94 | |||
95 | return hr; | ||
96 | } | ||
97 | |||
98 | extern "C" HRESULT DAPI ProcTokenUser( | ||
99 | __in HANDLE hProcess, | ||
100 | __out TOKEN_USER** ppTokenUser | ||
101 | ) | ||
102 | { | ||
103 | HRESULT hr = S_OK; | ||
104 | DWORD er = ERROR_SUCCESS; | ||
105 | HANDLE hToken = NULL; | ||
106 | TOKEN_USER* pTokenUser = NULL; | ||
107 | DWORD cbToken = 0; | ||
108 | |||
109 | if (!::OpenProcessToken(hProcess, TOKEN_QUERY, &hToken)) | ||
110 | { | ||
111 | ProcExitWithLastError(hr, "Failed to open process token."); | ||
112 | } | ||
113 | |||
114 | if (::GetTokenInformation(hToken, TokenUser, pTokenUser, 0, &cbToken)) | ||
115 | { | ||
116 | er = ERROR_SUCCESS; | ||
117 | } | ||
118 | else | ||
119 | { | ||
120 | er = ::GetLastError(); | ||
121 | } | ||
122 | |||
123 | if (er != ERROR_INSUFFICIENT_BUFFER) | ||
124 | { | ||
125 | ProcExitOnWin32Error(er, hr, "Failed to get user from process token size."); | ||
126 | } | ||
127 | |||
128 | pTokenUser = reinterpret_cast<TOKEN_USER*>(MemAlloc(cbToken, TRUE)); | ||
129 | ProcExitOnNull(pTokenUser, hr, E_OUTOFMEMORY, "Failed to allocate token information."); | ||
130 | |||
131 | if (!::GetTokenInformation(hToken, TokenUser, pTokenUser, cbToken, &cbToken)) | ||
132 | { | ||
133 | ProcExitWithLastError(hr, "Failed to get user from process token."); | ||
134 | } | ||
135 | |||
136 | *ppTokenUser = pTokenUser; | ||
137 | pTokenUser = NULL; | ||
138 | |||
139 | LExit: | ||
140 | ReleaseMem(pTokenUser); | ||
141 | ReleaseHandle(hToken); | ||
142 | |||
143 | return hr; | ||
144 | } | ||
145 | |||
78 | extern "C" HRESULT DAPI ProcWow64( | 146 | extern "C" HRESULT DAPI ProcWow64( |
79 | __in HANDLE hProcess, | 147 | __in HANDLE hProcess, |
80 | __out BOOL* pfWow64 | 148 | __out BOOL* pfWow64 |