#include "w32time.h"
#include <debug.h>
#include <strsafe.h>
Go to the source code of this file.
◆ ControlHandler()
Definition at line 214 of file w32time.c.
215{
217 {
220 DPRINT(
"Stopping W32Time Service\n");
221
225
228 return;
229
230 default:
231 break;
232 }
233}
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
SERVICE_STATUS_HANDLE hStatus
SERVICE_STATUS ServiceStatus
#define SERVICE_STOP_PENDING
#define SERVICE_CONTROL_SHUTDOWN
#define SERVICE_CONTROL_STOP
Referenced by W32TmServiceMain().
◆ DllMain()
Definition at line 341 of file w32time.c.
344{
345 switch (fdwReason)
346 {
349 break;
350
352 break;
353 }
354
356}
#define DLL_PROCESS_ATTACH
#define DLL_PROCESS_DETACH
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
◆ GetIntervalSetting()
Definition at line 125 of file w32time.c.
126{
131
134 L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\TimeProviders\\NtpClient",
135 0,
139 {
140
141
142
143
144
145
147 L"SpecialPollInterval",
153 }
154
157 else
159}
#define RegCloseKey(hKey)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
static HANDLE ULONG_PTR dwData
#define W32TIME_POLL_INTERVAL
#define HKEY_LOCAL_MACHINE
Referenced by W32TmServiceMain().
◆ InitService()
◆ SetTime()
Definition at line 163 of file w32time.c.
164{
169 DWORD cbName =
sizeof(szData);
170
171 DPRINT(
"Entered SetTime.\n");
172
174 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers",
175 0,
179 {
180 return lRet;
181 }
182
185 {
186 cbName = sizeof(szData);
188 }
189
191
192 DPRINT(
"Time Server is '%S'.\n", szData);
193
194
195 if (cbName == 0 || szData[0] == '\0')
196 {
197 DPRINT(
"The time NTP server couldn't be found, the string is empty!\n");
199 }
200
202
203 if (ulTime != 0)
204 {
206 }
207 else
209}
ULONG GetServerTime(LPWSTR lpAddress)
static DWORD UpdateSystemTime(ULONG ulTime)
#define ERROR_GEN_FAILURE
#define ERROR_INVALID_DATA
Referenced by DECLARE_INTERFACE_(), W32TimeSyncNow(), and W32TmServiceMain().
◆ SystemSetTime()
Definition at line 21 of file w32time.c.
22{
27
28
29
30
31
34 &hToken))
35 {
38
42 {
45 &priv,
46 sizeof(previouspriv),
47 &previouspriv,
48 &PrevSize) &&
50 {
51
52
53
55
56
57
58
60 {
63 &previouspriv,
64 0,
66 0);
67 }
68 }
69 }
71 }
72
73 return Ret;
74}
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
#define GetCurrentProcess()
BOOL WINAPI SetSystemTime(IN CONST SYSTEMTIME *lpSystemTime)
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
DWORD WINAPI GetLastError(void)
#define SE_SYSTEMTIME_NAME
#define TOKEN_ADJUST_PRIVILEGES
#define SE_PRIVILEGE_ENABLED
Referenced by UpdateSystemTime().
◆ UpdateSystemTime()
Definition at line 83 of file w32time.c.
84{
88
89
97
98
100 {
102 }
103
104
108
109
111 {
113 }
114
116 {
118 }
119
121}
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
BOOL SystemSetTime(LPSYSTEMTIME lpSystemTime)
Referenced by SetTime().
◆ W32TimeSyncNow()
Definition at line 360 of file w32time.c.
363{
367 {
368 DPRINT(
"W32TimeSyncNow failed and clock not set.\n");
369 }
370 else
371 {
372 DPRINT(
"W32TimeSyncNow succeeded and clock set.\n");
373 }
375}
Referenced by UpdateThread().
◆ W32TmServiceMain()
Definition at line 238 of file w32time.c.
239{
246
249
257
261 {
262
263 return;
264 }
265
266
269 {
274 return;
275 }
276
277
279
280
283
284
285 for (;;)
286 {
287
289
290
292 L"SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters",
293 0,
296 {
297 cbData = sizeof(szData);
300 bNoSync = (
_wcsicmp(szData,
L"NoSync") == 0);
302 }
303
304 if (!bNoSync)
305 {
308 {
309 DPRINT(
"W32Time Service failed to set clock: 0x%08lX\n",
error);
310#if 0
311
312
313
314
315
319 return;
320#endif
321 }
322 }
323
325 {
328
333 DPRINT(
"Stopped W32Time Service\n");
334 return;
335 }
336 }
337}
#define UNREFERENCED_PARAMETER(P)
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
DWORD dwServiceSpecificExitCode
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
static WCHAR ServiceName[]
static DWORD GetIntervalSetting(VOID)
VOID WINAPI ControlHandler(DWORD request)
#define SERVICE_ACCEPT_STOP
#define SERVICE_START_PENDING
#define SERVICE_ACCEPT_SHUTDOWN
◆ hStatus
◆ hStopEvent
◆ ServiceName
WCHAR ServiceName[] = L"W32Time" |
|
static |
◆ ServiceStatus