From e91cfb506502e48844d17998a4734c5c60db98eb Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Tue, 25 Jan 2005 23:57:57 +0000 Subject: [PATCH] enable the SeSystemtimePrivilege privilege which is required to call SetLocalTime svn path=/trunk/; revision=13300 --- reactos/lib/syssetup/wizard.c | 64 ++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/reactos/lib/syssetup/wizard.c b/reactos/lib/syssetup/wizard.c index 6ab8f1df3b3..4ddca5662b1 100644 --- a/reactos/lib/syssetup/wizard.c +++ b/reactos/lib/syssetup/wizard.c @@ -1121,6 +1121,62 @@ SetAutoDaylightInfo(HWND hwnd) } +static BOOL +SetSystemLocalTime(HWND hwnd, PSETUPDATA SetupData) +{ + HANDLE hToken; + TOKEN_PRIVILEGES priv, previouspriv; + BOOL Ret = FALSE; + + /* + * enable the SeSystemtimePrivilege privilege + */ + + if(OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES, + &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, + 0) && + GetLastError() == ERROR_SUCCESS) + { + /* + * we successfully enabled it, we're permitted to change the system time + */ + Ret = SetLocalTime(&SetupData->SystemTime); + + /* + * 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; +} + + INT_PTR CALLBACK DateTimePageDlgProc(HWND hwndDlg, UINT uMsg, @@ -1167,7 +1223,13 @@ DateTimePageDlgProc(HWND hwndDlg, SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST), SetupData); SetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT)); - SetLocalTime(&SetupData->SystemTime); + if(!SetSystemLocalTime(hwndDlg, SetupData)) + { + MessageBox(hwndDlg, + _T("Setup was unable to set the local time."), + _T("ReactOS Setup"), + MB_ICONWARNING | MB_OK); + } } break;