1 /* 2 * PROJECT: ReactOS Secondary Logon Service 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Secondary Logon service RPC server 5 * COPYRIGHT: Eric Kohl 2022 <eric.kohl@reactos.org> 6 */ 7 8 /* INCLUDES *****************************************************************/ 9 10 #include "precomp.h" 11 12 WINE_DEFAULT_DEBUG_CHANNEL(seclogon); 13 14 15 /* GLOBALS ******************************************************************/ 16 17 HINSTANCE hDllInstance; 18 SVCHOST_GLOBALS *lpServiceGlobals; 19 20 static WCHAR ServiceName[] = L"seclogon"; 21 22 static SERVICE_STATUS_HANDLE ServiceStatusHandle; 23 static SERVICE_STATUS ServiceStatus; 24 25 26 /* FUNCTIONS *****************************************************************/ 27 28 static 29 VOID 30 UpdateServiceStatus( 31 _In_ DWORD dwState) 32 { 33 ServiceStatus.dwServiceType = SERVICE_WIN32_SHARE_PROCESS; 34 ServiceStatus.dwCurrentState = dwState; 35 36 if (dwState == SERVICE_PAUSED || dwState == SERVICE_RUNNING) 37 ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | 38 SERVICE_ACCEPT_SHUTDOWN | 39 SERVICE_ACCEPT_PAUSE_CONTINUE; 40 else 41 ServiceStatus.dwControlsAccepted = 0; 42 43 ServiceStatus.dwWin32ExitCode = 0; 44 ServiceStatus.dwServiceSpecificExitCode = 0; 45 ServiceStatus.dwCheckPoint = 0; 46 47 if (dwState == SERVICE_START_PENDING || 48 dwState == SERVICE_STOP_PENDING || 49 dwState == SERVICE_PAUSE_PENDING || 50 dwState == SERVICE_CONTINUE_PENDING) 51 ServiceStatus.dwWaitHint = 10000; 52 else 53 ServiceStatus.dwWaitHint = 0; 54 55 SetServiceStatus(ServiceStatusHandle, 56 &ServiceStatus); 57 } 58 59 60 static 61 DWORD 62 WINAPI 63 ServiceControlHandlerEx( 64 _In_ DWORD dwControl, 65 _In_ DWORD dwEventType, 66 _In_ LPVOID lpEventData, 67 _In_ LPVOID lpContext) 68 { 69 TRACE("ServiceControlHandlerEx()\n"); 70 71 switch (dwControl) 72 { 73 case SERVICE_CONTROL_STOP: 74 TRACE(" SERVICE_CONTROL_STOP received\n"); 75 UpdateServiceStatus(SERVICE_STOP_PENDING); 76 StopRpcServer(); 77 return ERROR_SUCCESS; 78 79 case SERVICE_CONTROL_PAUSE: 80 TRACE(" SERVICE_CONTROL_PAUSE received\n"); 81 UpdateServiceStatus(SERVICE_PAUSE_PENDING); 82 StopRpcServer(); 83 UpdateServiceStatus(SERVICE_PAUSED); 84 return ERROR_SUCCESS; 85 86 case SERVICE_CONTROL_CONTINUE: 87 TRACE(" SERVICE_CONTROL_CONTINUE received\n"); 88 UpdateServiceStatus(SERVICE_CONTINUE_PENDING); 89 StartRpcServer(); 90 UpdateServiceStatus(SERVICE_RUNNING); 91 return ERROR_SUCCESS; 92 93 case SERVICE_CONTROL_INTERROGATE: 94 TRACE(" SERVICE_CONTROL_INTERROGATE received\n"); 95 SetServiceStatus(ServiceStatusHandle, 96 &ServiceStatus); 97 return ERROR_SUCCESS; 98 99 case SERVICE_CONTROL_SHUTDOWN: 100 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n"); 101 UpdateServiceStatus(SERVICE_STOP_PENDING); 102 StopRpcServer(); 103 return ERROR_SUCCESS; 104 105 default : 106 TRACE(" Control %lu received\n", dwControl); 107 return ERROR_CALL_NOT_IMPLEMENTED; 108 } 109 } 110 111 112 VOID 113 WINAPI 114 SvchostPushServiceGlobals( 115 _In_ SVCHOST_GLOBALS *lpGlobals) 116 { 117 TRACE("SvchostPushServiceGlobals(%p)\n", lpGlobals); 118 lpServiceGlobals = lpGlobals; 119 } 120 121 122 VOID 123 WINAPI 124 SvcEntry_Seclogon( 125 _In_ INT ArgCount, 126 _In_ PWSTR *ArgVector) 127 { 128 DWORD dwError; 129 130 UNREFERENCED_PARAMETER(ArgCount); 131 UNREFERENCED_PARAMETER(ArgVector); 132 133 TRACE("ServiceMain(%d %p)\n", ArgCount, ArgVector); 134 135 ServiceStatusHandle = RegisterServiceCtrlHandlerExW(ServiceName, 136 ServiceControlHandlerEx, 137 NULL); 138 if (!ServiceStatusHandle) 139 { 140 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError()); 141 return; 142 } 143 144 UpdateServiceStatus(SERVICE_START_PENDING); 145 146 dwError = StartRpcServer(); 147 if (dwError != ERROR_SUCCESS) 148 { 149 ERR("Service stopped (dwError: %lu\n", dwError); 150 UpdateServiceStatus(SERVICE_STOPPED); 151 return; 152 } 153 154 UpdateServiceStatus(SERVICE_RUNNING); 155 } 156 157 158 BOOL 159 WINAPI 160 DllMain( 161 _In_ HINSTANCE hinstDLL, 162 _In_ DWORD fdwReason, 163 _In_ PVOID pvReserved) 164 { 165 UNREFERENCED_PARAMETER(pvReserved); 166 167 switch (fdwReason) 168 { 169 case DLL_PROCESS_ATTACH: 170 DisableThreadLibraryCalls(hinstDLL); 171 hDllInstance = hinstDLL; 172 break; 173 174 case DLL_PROCESS_DETACH: 175 break; 176 } 177 178 return TRUE; 179 } 180 181 /* EOF */ 182