2018-02-02 22:03:17 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Update Service
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* PURPOSE: Automatic Updates service stub.
|
|
|
|
* Stub is required for some application at the installation phase.
|
|
|
|
* COPYRIGHT: Copyright 2018 Denis Malikov (filedem@gmail.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wuauserv.h"
|
|
|
|
|
|
|
|
/* GLOBALS ******************************************************************/
|
|
|
|
|
|
|
|
static WCHAR ServiceName[] = L"wuauserv";
|
|
|
|
|
|
|
|
static SERVICE_STATUS_HANDLE ServiceStatusHandle;
|
|
|
|
static SERVICE_STATUS ServiceStatus;
|
|
|
|
|
2019-07-21 16:51:33 +00:00
|
|
|
static HANDLE hStopEvent = NULL;
|
2018-02-02 22:03:17 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
static VOID
|
|
|
|
UpdateServiceStatus(DWORD dwState)
|
|
|
|
{
|
|
|
|
ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
|
|
|
ServiceStatus.dwCurrentState = dwState;
|
|
|
|
ServiceStatus.dwControlsAccepted = 0;
|
|
|
|
ServiceStatus.dwWin32ExitCode = 0;
|
|
|
|
ServiceStatus.dwServiceSpecificExitCode = 0;
|
|
|
|
ServiceStatus.dwCheckPoint = 0;
|
|
|
|
|
|
|
|
if (dwState == SERVICE_START_PENDING ||
|
|
|
|
dwState == SERVICE_STOP_PENDING ||
|
|
|
|
dwState == SERVICE_PAUSE_PENDING ||
|
|
|
|
dwState == SERVICE_CONTINUE_PENDING)
|
|
|
|
ServiceStatus.dwWaitHint = 1000;
|
|
|
|
else
|
|
|
|
ServiceStatus.dwWaitHint = 0;
|
|
|
|
|
2019-07-20 17:27:22 +00:00
|
|
|
if (dwState == SERVICE_RUNNING)
|
|
|
|
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
|
|
|
|
2018-02-02 22:03:17 +00:00
|
|
|
SetServiceStatus(ServiceStatusHandle,
|
|
|
|
&ServiceStatus);
|
|
|
|
DPRINT1("WU UpdateServiceStatus() called\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI
|
|
|
|
ServiceControlHandler(DWORD dwControl,
|
|
|
|
DWORD dwEventType,
|
|
|
|
LPVOID lpEventData,
|
|
|
|
LPVOID lpContext)
|
|
|
|
{
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_STOP received\n");
|
2019-07-21 16:51:33 +00:00
|
|
|
SetEvent(hStopEvent);
|
2019-07-20 17:27:22 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOP_PENDING);
|
2018-02-02 22:03:17 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_PAUSE:
|
|
|
|
DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_PAUSE received\n");
|
|
|
|
UpdateServiceStatus(SERVICE_PAUSED);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_CONTINUE:
|
|
|
|
DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_CONTINUE received\n");
|
|
|
|
UpdateServiceStatus(SERVICE_RUNNING);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_INTERROGATE received\n");
|
|
|
|
SetServiceStatus(ServiceStatusHandle,
|
|
|
|
&ServiceStatus);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
DPRINT1("WU ServiceControlHandler() SERVICE_CONTROL_SHUTDOWN received\n");
|
2019-07-21 16:51:33 +00:00
|
|
|
SetEvent(hStopEvent);
|
2019-07-20 17:27:22 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOP_PENDING);
|
2018-02-02 22:03:17 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
default :
|
2021-11-21 17:37:04 +00:00
|
|
|
DPRINT1("WU ServiceControlHandler() Control %lu received\n", dwControl);
|
2018-02-02 22:03:17 +00:00
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID WINAPI
|
|
|
|
ServiceMain(DWORD argc, LPTSTR *argv)
|
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(argc);
|
|
|
|
UNREFERENCED_PARAMETER(argv);
|
|
|
|
|
|
|
|
DPRINT("WU ServiceMain() called\n");
|
2021-09-13 01:33:14 +00:00
|
|
|
|
2018-02-02 22:03:17 +00:00
|
|
|
ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName,
|
|
|
|
ServiceControlHandler,
|
|
|
|
NULL);
|
|
|
|
if (!ServiceStatusHandle)
|
|
|
|
{
|
|
|
|
DPRINT1("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-21 16:51:33 +00:00
|
|
|
hStopEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
if (hStopEvent == NULL)
|
|
|
|
{
|
|
|
|
DPRINT1("CreateEvent() failed! (Error %lu)\n", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
2019-07-20 17:27:22 +00:00
|
|
|
|
2018-02-02 22:03:17 +00:00
|
|
|
UpdateServiceStatus(SERVICE_RUNNING);
|
|
|
|
|
2019-07-21 16:51:33 +00:00
|
|
|
WaitForSingleObject(hStopEvent, INFINITE);
|
|
|
|
CloseHandle(hStopEvent);
|
2018-02-02 22:03:17 +00:00
|
|
|
|
2019-07-21 16:51:33 +00:00
|
|
|
done:
|
2018-02-02 22:03:17 +00:00
|
|
|
UpdateServiceStatus(SERVICE_STOPPED);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
DllMain(HINSTANCE hinstDLL,
|
|
|
|
DWORD fdwReason,
|
|
|
|
LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|