ReactOS  0.4.14-dev-41-g31d7680
wuauserv.c
Go to the documentation of this file.
1 /*
2 * PROJECT: ReactOS Update Service
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Automatic Updates service stub.
5 * Stub is required for some application at the installation phase.
6 * COPYRIGHT: Copyright 2018 Denis Malikov (filedem@gmail.com)
7 */
8 
9 #include "wuauserv.h"
10 
11 /* GLOBALS ******************************************************************/
12 
13 static WCHAR ServiceName[] = L"wuauserv";
14 
17 
19 
20 /* FUNCTIONS *****************************************************************/
21 
22 static VOID
24 {
26  ServiceStatus.dwCurrentState = dwState;
31 
32  if (dwState == SERVICE_START_PENDING ||
33  dwState == SERVICE_STOP_PENDING ||
34  dwState == SERVICE_PAUSE_PENDING ||
35  dwState == SERVICE_CONTINUE_PENDING)
37  else
39 
40  if (dwState == SERVICE_RUNNING)
42 
44  &ServiceStatus);
45  DPRINT1("WU UpdateServiceStatus() called\n");
46 }
47 
48 static DWORD WINAPI
50  DWORD dwEventType,
51  LPVOID lpEventData,
52  LPVOID lpContext)
53 {
54  switch (dwControl)
55  {
57  DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_STOP received\n");
60  return ERROR_SUCCESS;
61 
63  DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_PAUSE received\n");
65  return ERROR_SUCCESS;
66 
68  DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_CONTINUE received\n");
70  return ERROR_SUCCESS;
71 
73  DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_INTERROGATE received\n");
75  &ServiceStatus);
76  return ERROR_SUCCESS;
77 
79  DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_SHUTDOWN received\n");
82  return ERROR_SUCCESS;
83 
84  default :
85  DPRINT1("WU ServiceControlHandler() Control %lu received\n");
87  }
88 }
89 
92 {
95 
96  DPRINT("WU ServiceMain() called\n");
97 
100  NULL);
101  if (!ServiceStatusHandle)
102  {
103  DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
104  return;
105  }
106 
108  if (hStopEvent == NULL)
109  {
110  DPRINT1("CreateEvent() failed! (Error %lu)\n", GetLastError());
111  goto done;
112  }
113 
115 
118 
119 done:
121 }
122 
123 BOOL WINAPI
125  DWORD fdwReason,
127 {
128  switch (fdwReason)
129  {
130  case DLL_PROCESS_ATTACH:
131  DisableThreadLibraryCalls(hinstDLL);
132  break;
133 
134  case DLL_PROCESS_DETACH:
135  break;
136  }
137 
138  return TRUE;
139 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wuauserv.c:15
DWORD dwCurrentState
Definition: winsvc.h:100
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: wuauserv.c:49
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define argv
Definition: mplay32.c:18
CHAR * LPTSTR
Definition: xmlstorage.h:192
static IN DWORD IN LPVOID lpvReserved
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:995
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define DLL_PROCESS_DETACH
Definition: compat.h:119
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwWaitHint
Definition: winsvc.h:105
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wuauserv.c:23
#define WINAPI
Definition: msvc.h:8
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
static const WCHAR L[]
Definition: oid.c:1250
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:810
static WCHAR ServiceName[]
Definition: wuauserv.c:13
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: wuauserv.c:124
static HANDLE hStopEvent
Definition: wuauserv.c:18
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define DPRINT1
Definition: precomp.h:8
static SERVICE_STATUS ServiceStatus
Definition: wuauserv.c:16
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define INFINITE
Definition: serial.h:102
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: wuauserv.c:91
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40