diff --git "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\ntpclient.c" "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\ntpclient.c" index 7442b49150..37a1af1272 100644 --- "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\ntpclient.c" +++ "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\ntpclient.c" @@ -4,6 +4,7 @@ * FILE: dll/cpl/timedate/ntpclient.c * PURPOSE: Queries the NTP server * COPYRIGHT: Copyright 2006 Ged Murphy + * Copyright 2017 Doug Lyons * */ @@ -121,15 +122,15 @@ ReceiveData(PINFO pInfo) if ((Ret != SOCKET_ERROR) && (Ret != 0)) { - Ret = recvfrom(pInfo->Sock, (char *)&pInfo->RecvPacket, sizeof(pInfo->RecvPacket), 0, NULL, NULL); + if (Ret != SOCKET_ERROR) - ulTime = ntohl(ulTime); + ulTime = ntohl(pInfo->RecvPacket.TransmitTimestamp.dwInteger); } return ulTime; diff --git "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\internettime.c" "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\internettime.c" index 9f0b851451..e6636a6a90 100644 --- "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\internettime.c" +++ "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\internettime.c" @@ -258,7 +258,7 @@ UpdateSystemTime(ULONG ulTime) return; } - if (!SystemSetLocalTime(&stNew)) + if (!SystemSetSystemTime(&stNew)) DisplayWin32Error(GetLastError()); } diff --git "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\dateandtime.c" "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\dateandtime.c" index c51e175cc9..c055baab8e 100644 --- "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\dateandtime.c" +++ "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\dateandtime.c" @@ -71,6 +71,64 @@ SystemSetLocalTime(LPSYSTEMTIME lpSystemTime) return Ret; } +BOOL +SystemSetSystemTime(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 (LookupPrivilegeValueW(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 = SetSystemTime(lpSystemTime) && + SetSystemTime(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) diff --git "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\timedate.h" "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\timedate.h" index 7442b49150..37a1af1272 100644 --- "a/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\timedate.h" +++ "b/D:\\ReactOS\\reactos\\dll\\cpl\\timedate\\timedate.h" @@ -18,6 +18,7 @@ #include #include "resource.h" +#include "time.h" #define MAX_KEY_LENGTH 255 #define MAX_VALUE_NAME 16383 @@ -40,6 +41,7 @@ extern HINSTANCE hApplet; /* dateandtime.c */ INT_PTR CALLBACK DateTimePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); BOOL SystemSetLocalTime(LPSYSTEMTIME lpSystemTime); +BOOL SystemSetSystemTime(LPSYSTEMTIME lpSystemTime); /* timezone.c */