Module: wine Branch: master Commit: 739c5c547c361880a69993b21855af0fa00ade76 URL: https://gitlab.winehq.org/wine/wine/-/commit/739c5c547c361880a69993b21855af0...
Author: Francois Gouget fgouget@codeweavers.com Date: Sat Mar 25 17:52:59 2023 +0100
schtasks/tests: Deleting folders requires elevated privileges on Windows 7 & 8.
This means skipping any test that requires creating a task as the test would be unable to clean up after itself.
Wine-Bug: https://bugs.winehq.org//show_bug.cgi?id=52193 Wine-Bug: https://bugs.winehq.org//show_bug.cgi?id=54634
---
programs/schtasks/tests/Makefile.in | 2 +- programs/schtasks/tests/schtasks.c | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/programs/schtasks/tests/Makefile.in b/programs/schtasks/tests/Makefile.in index dcf641c4b13..424f9a294d1 100644 --- a/programs/schtasks/tests/Makefile.in +++ b/programs/schtasks/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = schtasks.exe -IMPORTS = ole32 +IMPORTS = advapi32 ole32
C_SRCS = \ diff --git a/programs/schtasks/tests/schtasks.c b/programs/schtasks/tests/schtasks.c index c1168d4b209..238dc3bdc16 100644 --- a/programs/schtasks/tests/schtasks.c +++ b/programs/schtasks/tests/schtasks.c @@ -16,8 +16,11 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include <stdarg.h> + #define COBJMACROS
+#include "winternl.h" #include "initguid.h" #include "taskschd.h"
@@ -58,6 +61,37 @@ static WCHAR *a2w(const char *str) return ret; }
+static BOOL is_process_elevated(void) +{ + HANDLE token; + if (OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &token )) + { + TOKEN_ELEVATION_TYPE type; + DWORD size; + BOOL ret; + + ret = GetTokenInformation( token, TokenElevationType, &type, sizeof(type), &size ); + CloseHandle( token ); + return (ret && type == TokenElevationTypeFull); + } + return FALSE; +} + +static BOOL check_win_version(int min_major, int min_minor) +{ + HMODULE hntdll = GetModuleHandleA("ntdll.dll"); + NTSTATUS (WINAPI *pRtlGetVersion)(RTL_OSVERSIONINFOEXW *); + RTL_OSVERSIONINFOEXW rtlver; + + rtlver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); + pRtlGetVersion = (void *)GetProcAddress(hntdll, "RtlGetVersion"); + pRtlGetVersion(&rtlver); + return rtlver.dwMajorVersion > min_major || + (rtlver.dwMajorVersion == min_major && + rtlver.dwMinorVersion >= min_minor); +} +#define is_win10_plus() check_win_version(10, 0) + #define run_command(a) _run_command(__LINE__,a) static DWORD _run_command(unsigned line, const char *cmd) { @@ -173,6 +207,12 @@ START_TEST(schtasks) static WCHAR wine_testW[] = L"\wine\test"; DWORD r;
+ if (!is_process_elevated() && !is_win10_plus()) + { + win_skip("Deleting the test folders requires elevated privileges on Windows <= 8\n"); + return; + } + CoInitialize(NULL); if(!initialize_task_service()) { CoUninitialize();