diff --git a/reactos/dll/cpl/timedate/timedate.c b/reactos/dll/cpl/timedate/timedate.c index d782192c452..749ac9796b6 100644 --- a/reactos/dll/cpl/timedate/timedate.c +++ b/reactos/dll/cpl/timedate/timedate.c @@ -56,6 +56,64 @@ APPLET Applets[NUM_APPLETS] = {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet} }; +static BOOL +SystemSetLocalTime(LPSYSTEMTIME lpSystemTime) +{ + HANDLE hToken; + DWORD PrevSize; + TOKEN_PRIVILEGES priv, previouspriv; + BOOL Ret = FALSE; + + /* + * Enable the SeSystemtimePrivilege privilege + */ + + if (OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, + &hToken)) + { + priv.PrivilegeCount = 1; + priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + if (LookupPrivilegeValue(NULL, + SE_SYSTEMTIME_NAME, + &priv.Privileges[0].Luid)) + { + if (AdjustTokenPrivileges(hToken, + FALSE, + &priv, + sizeof(previouspriv), + &previouspriv, + &PrevSize) && + GetLastError() == ERROR_SUCCESS) + { + /* + * We successfully enabled it, we're permitted to change the system time + * Call SetLocalTime twice to ensure correct results + */ + Ret = SetLocalTime(lpSystemTime) && + SetLocalTime(lpSystemTime); + + /* + * For the sake of security, restore the previous status again + */ + if (previouspriv.PrivilegeCount > 0) + { + AdjustTokenPrivileges(hToken, + FALSE, + &previouspriv, + 0, + NULL, + 0); + } + } + } + CloseHandle(hToken); + } + + return Ret; +} + static VOID SetLocalSystemTime(HWND hwnd) @@ -71,9 +129,7 @@ SetLocalSystemTime(HWND hwnd) (WPARAM)&Time, 0)) { - /* Call SetLocalTime twice to ensure correct results */ - SetLocalTime(&Time); - SetLocalTime(&Time); + SystemSetLocalTime(&Time); SetWindowLong(hwnd, DWL_MSGRESULT, diff --git a/reactos/dll/win32/syssetup/wizard.c b/reactos/dll/win32/syssetup/wizard.c index bc023198dbb..d4be51b121a 100644 --- a/reactos/dll/win32/syssetup/wizard.c +++ b/reactos/dll/win32/syssetup/wizard.c @@ -1204,9 +1204,11 @@ SetSystemLocalTime(HWND hwnd, PSETUPDATA SetupData) GetLastError() == ERROR_SUCCESS) { /* - * we successfully enabled it, we're permitted to change the system time + * We successfully enabled it, we're permitted to change the system time + * Call SetLocalTime twice to ensure correct results */ - Ret = SetLocalTime(&SetupData->SystemTime); + Ret = SetLocalTime(&SetupData->SystemTime) && + SetLocalTime(&SetupData->SystemTime); /* * for the sake of security, restore the previous status again