aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/osutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/osutil.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/dutil/osutil.cpp b/src/dutil/osutil.cpp
index 8834cd30..880ec3ea 100644
--- a/src/dutil/osutil.cpp
+++ b/src/dutil/osutil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5
6// Exit macros
7#define OsExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
8#define OsExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
9#define OsExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
10#define OsExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
11#define OsExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
12#define OsExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_OSUTIL, x, s, __VA_ARGS__)
13#define OsExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_OSUTIL, p, x, e, s, __VA_ARGS__)
14#define OsExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__)
15#define OsExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_OSUTIL, p, x, e, s, __VA_ARGS__)
16#define OsExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_OSUTIL, p, x, s, __VA_ARGS__)
17#define OsExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_OSUTIL, e, x, s, __VA_ARGS__)
18#define OsExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_OSUTIL, g, x, s, __VA_ARGS__)
19
5typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation); 20typedef NTSTATUS(NTAPI* PFN_RTL_GET_VERSION)(_Out_ PRTL_OSVERSIONINFOEXW lpVersionInformation);
6 21
7OS_VERSION vOsVersion = OS_VERSION_UNKNOWN; 22OS_VERSION vOsVersion = OS_VERSION_UNKNOWN;
@@ -127,7 +142,7 @@ extern "C" HRESULT DAPI OsIsRunningPrivileged(
127 142
128 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &hToken)) 143 if (!::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &hToken))
129 { 144 {
130 ExitOnLastError(hr, "Failed to open process token."); 145 OsExitOnLastError(hr, "Failed to open process token.");
131 } 146 }
132 147
133 if (::GetTokenInformation(hToken, TokenElevationType, &elevationType, sizeof(TOKEN_ELEVATION_TYPE), &dwSize)) 148 if (::GetTokenInformation(hToken, TokenElevationType, &elevationType, sizeof(TOKEN_ELEVATION_TYPE), &dwSize))
@@ -142,7 +157,7 @@ extern "C" HRESULT DAPI OsIsRunningPrivileged(
142 { 157 {
143 er = ERROR_SUCCESS; 158 er = ERROR_SUCCESS;
144 } 159 }
145 ExitOnWin32Error(er, hr, "Failed to get process token information."); 160 OsExitOnWin32Error(er, hr, "Failed to get process token information.");
146 161
147 // Fallback to this check for some OS's (like XP) 162 // Fallback to this check for some OS's (like XP)
148 *pfPrivileged = ::AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup); 163 *pfPrivileged = ::AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup);
@@ -180,14 +195,14 @@ extern "C" HRESULT DAPI OsIsUacEnabled(
180 { 195 {
181 ExitFunction1(hr = S_OK); 196 ExitFunction1(hr = S_OK);
182 } 197 }
183 ExitOnFailure(hr, "Failed to open system policy key to detect UAC."); 198 OsExitOnFailure(hr, "Failed to open system policy key to detect UAC.");
184 199
185 hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled); 200 hr = RegReadNumber(hk, L"EnableLUA", &dwUacEnabled);
186 if (E_FILENOTFOUND == hr) 201 if (E_FILENOTFOUND == hr)
187 { 202 {
188 ExitFunction1(hr = S_OK); 203 ExitFunction1(hr = S_OK);
189 } 204 }
190 ExitOnFailure(hr, "Failed to read registry value to detect UAC."); 205 OsExitOnFailure(hr, "Failed to read registry value to detect UAC.");
191 206
192 *pfUacEnabled = (0 != dwUacEnabled); 207 *pfUacEnabled = (0 != dwUacEnabled);
193 208
@@ -215,12 +230,12 @@ HRESULT DAPI OsRtlGetVersion(
215 hr = LoadSystemLibrary(L"ntdll.dll", &hNtdll); 230 hr = LoadSystemLibrary(L"ntdll.dll", &hNtdll);
216 if (E_MODNOTFOUND == hr) 231 if (E_MODNOTFOUND == hr)
217 { 232 {
218 ExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll"); 233 OsExitOnRootFailure(hr = E_NOTIMPL, "Failed to load ntdll.dll");
219 } 234 }
220 ExitOnFailure(hr, "Failed to load ntdll.dll."); 235 OsExitOnFailure(hr, "Failed to load ntdll.dll.");
221 236
222 pfnRtlGetVersion = reinterpret_cast<PFN_RTL_GET_VERSION>(::GetProcAddress(hNtdll, "RtlGetVersion")); 237 pfnRtlGetVersion = reinterpret_cast<PFN_RTL_GET_VERSION>(::GetProcAddress(hNtdll, "RtlGetVersion"));
223 ExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion."); 238 OsExitOnNullWithLastError(pfnRtlGetVersion, hr, "Failed to locate RtlGetVersion.");
224 239
225 hr = static_cast<HRESULT>(pfnRtlGetVersion(&vovix)); 240 hr = static_cast<HRESULT>(pfnRtlGetVersion(&vovix));
226 241