ReactOS  0.4.14-dev-384-g5b37caa
netlogon.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS NetLogon Service
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: NetLogon service RPC server
5  * COPYRIGHT: Eric Kohl 2019 <eric.kohl@reactos.org>
6  */
7 
8 /* INCLUDES *****************************************************************/
9 
10 #include "precomp.h"
11 
13 
14 
15 /* GLOBALS ******************************************************************/
16 
18 
19 static WCHAR ServiceName[] = L"netlogon";
20 
23 
24 
25 /* FUNCTIONS *****************************************************************/
26 
27 static
28 VOID
30  DWORD dwState)
31 {
33  ServiceStatus.dwCurrentState = dwState;
38 
39  if (dwState == SERVICE_START_PENDING ||
40  dwState == SERVICE_STOP_PENDING ||
41  dwState == SERVICE_PAUSE_PENDING ||
42  dwState == SERVICE_CONTINUE_PENDING)
43  ServiceStatus.dwWaitHint = 10000;
44  else
46 
48  &ServiceStatus);
49 }
50 
51 
52 static
53 DWORD
54 WINAPI
56  DWORD dwControl,
57  DWORD dwEventType,
58  LPVOID lpEventData,
59  LPVOID lpContext)
60 {
61  TRACE("ServiceControlHandler()\n");
62 
63  switch (dwControl)
64  {
66  TRACE(" SERVICE_CONTROL_STOP received\n");
67  /* Stop listening to incoming RPC messages */
70  return ERROR_SUCCESS;
71 
73  TRACE(" SERVICE_CONTROL_PAUSE received\n");
75  return ERROR_SUCCESS;
76 
78  TRACE(" SERVICE_CONTROL_CONTINUE received\n");
80  return ERROR_SUCCESS;
81 
83  TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
85  &ServiceStatus);
86  return ERROR_SUCCESS;
87 
89  TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
91  return ERROR_SUCCESS;
92 
93  default :
94  TRACE(" Control %lu received\n", dwControl);
96  }
97 }
98 
99 
100 static
101 DWORD
103 {
104  HANDLE hThread;
105 
107  0,
109  NULL,
110  0,
111  NULL);
112 
113  if (!hThread)
114  {
115  ERR("Can't create PortThread\n");
116  return GetLastError();
117  }
118  else
120 
121  return ERROR_SUCCESS;
122 }
123 
124 
125 VOID WINAPI
127  _In_ INT ArgCount,
128  _In_ PWSTR *ArgVector)
129 {
130  DWORD dwError;
131 
132  UNREFERENCED_PARAMETER(ArgCount);
133  UNREFERENCED_PARAMETER(ArgVector);
134 
135  TRACE("NlNetlogonMain(%d %p)\n", ArgCount, ArgVector);
136 
139  NULL);
140  if (!ServiceStatusHandle)
141  {
142  ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
143  return;
144  }
145 
147 
148  dwError = ServiceInit();
149  if (dwError != ERROR_SUCCESS)
150  {
151  ERR("Service stopped (dwError: %lu\n", dwError);
153  return;
154  }
155 
157 }
158 
159 
160 BOOL
161 WINAPI
163  _In_ HINSTANCE hinstDLL,
164  _In_ DWORD fdwReason,
166 {
168 
169  switch (fdwReason)
170  {
171  case DLL_PROCESS_ATTACH:
172  DisableThreadLibraryCalls(hinstDLL);
173  hDllInstance = hinstDLL;
174  break;
175 
176  case DLL_PROCESS_DETACH:
177  break;
178  }
179 
180  return TRUE;
181 }
182 
183 /* EOF */
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1599
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwCurrentState
Definition: winsvc.h:100
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
uint16_t * PWSTR
Definition: typedefs.h:54
#define SERVICE_PAUSED
Definition: winsvc.h:27
WINE_DEFAULT_DEBUG_CHANNEL(netlogon)
static VOID UpdateServiceStatus(DWORD dwState)
Definition: netlogon.c:29
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
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
BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ PVOID pvReserved)
Definition: netlogon.c:162
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:995
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
unsigned int BOOL
Definition: ntddk_ex.h:94
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: netlogon.c:21
#define SERVICE_RUNNING
Definition: winsvc.h:24
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
smooth NULL
Definition: ftsmooth.c:416
static DWORD ServiceInit(VOID)
Definition: netlogon.c:102
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
static SERVICE_STATUS ServiceStatus
Definition: netlogon.c:22
#define DLL_PROCESS_DETACH
Definition: compat.h:119
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
#define TRACE(s)
Definition: solgame.cpp:4
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: netlogon.c:55
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwWaitHint
Definition: winsvc.h:105
static LPCSTR DWORD void * pvReserved
Definition: str.c:196
#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
VOID WINAPI NlNetlogonMain(_In_ INT ArgCount, _In_ PWSTR *ArgVector)
Definition: netlogon.c:126
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
HANDLE hThread
Definition: wizard.c:27
HINSTANCE hDllInstance
Definition: netlogon.c:17
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
static WCHAR ServiceName[]
Definition: netlogon.c:19
DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
Definition: rpcserver.c:16
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40