- Enable SE_SYSTEMTIME_NAME privilege for timedate.cpl

- fixes bug 1337
- by Thomas Weidenmueller


svn path=/trunk/; revision=21249
This commit is contained in:
Ged Murphy
2006-03-08 19:28:44 +00:00
parent daa4402f55
commit 7dfc2dfebb
2 changed files with 63 additions and 5 deletions
+59 -3
View File
@@ -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,
+4 -2
View File
@@ -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