ReactOS  0.4.14-dev-52-g6116262
srvsvc.c
Go to the documentation of this file.
1 /*
2  * ReactOS Services
3  * Copyright (C) 2015 ReactOS Team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 /*
20  * COPYRIGHT: See COPYING in the top level directory
21  * PROJECT: ReactOS Services
22  * FILE: base/services/srvsvc/srvsvc.c
23  * PURPOSE: Server service
24  * PROGRAMMER: Eric Kohl
25  */
26 
27 /* INCLUDES *****************************************************************/
28 
29 #include "precomp.h"
30 
32 
33 /* GLOBALS ******************************************************************/
34 
35 static WCHAR ServiceName[] = L"Lanmanserver";
36 
39 
41 
42 
43 /* FUNCTIONS *****************************************************************/
44 
45 static VOID
47 {
49  ServiceStatus.dwCurrentState = dwState;
54 
55  if (dwState == SERVICE_START_PENDING ||
56  dwState == SERVICE_STOP_PENDING ||
57  dwState == SERVICE_PAUSE_PENDING ||
58  dwState == SERVICE_CONTINUE_PENDING)
59  ServiceStatus.dwWaitHint = 10000;
60  else
62 
63  if (dwState == SERVICE_RUNNING)
65 
67  &ServiceStatus);
68 }
69 
70 static DWORD WINAPI
72  DWORD dwEventType,
73  LPVOID lpEventData,
74  LPVOID lpContext)
75 {
76  TRACE("ServiceControlHandler() called\n");
77 
78  switch (dwControl)
79  {
81  TRACE(" SERVICE_CONTROL_STOP received\n");
83  /* Stop listening to incoming RPC messages */
86  return ERROR_SUCCESS;
87 
89  TRACE(" SERVICE_CONTROL_PAUSE received\n");
91  return ERROR_SUCCESS;
92 
94  TRACE(" SERVICE_CONTROL_CONTINUE received\n");
96  return ERROR_SUCCESS;
97 
99  TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
101  &ServiceStatus);
102  return ERROR_SUCCESS;
103 
105  TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
107  /* Stop listening to incoming RPC messages */
110  return ERROR_SUCCESS;
111 
112  default :
113  TRACE(" Control %lu received\n", dwControl);
115  }
116 }
117 
118 
119 static
120 DWORD
122 {
123  HANDLE hThread;
124 
126  0,
128  NULL,
129  0,
130  NULL);
131 
132  if (!hThread)
133  {
134  ERR("Can't create PortThread\n");
135  return GetLastError();
136  }
137  else
139 
140  /* Report a running server service */
143  TRUE,
144  TRUE);
145 
146  return ERROR_SUCCESS;
147 }
148 
149 
150 VOID
151 WINAPI
153 {
154  DWORD dwError;
155 
158 
159  TRACE("ServiceMain() called\n");
160 
163  NULL);
164  if (!ServiceStatusHandle)
165  {
166  ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
167  return;
168  }
169 
171 
172  dwError = ServiceInit();
173  if (dwError != ERROR_SUCCESS)
174  {
175  ERR("Service stopped (dwError: %lu\n", dwError);
177  return;
178  }
179 
181 }
182 
183 
184 BOOL WINAPI
186  DWORD fdwReason,
188 {
189  switch (fdwReason)
190  {
191  case DLL_PROCESS_ATTACH:
192  DisableThreadLibraryCalls(hinstDLL);
193  break;
194 
195  case DLL_PROCESS_DETACH:
196  break;
197  }
198 
199  return TRUE;
200 }
static int argc
Definition: ServiceArgs.c:12
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
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
static SERVICE_STATUS ServiceStatus
Definition: srvsvc.c:38
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SV_TYPE_SERVER
Definition: lmserver.h:428
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
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
#define argv
Definition: mplay32.c:18
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: srvsvc.c:71
CHAR * LPTSTR
Definition: xmlstorage.h:192
static IN DWORD IN LPVOID lpvReserved
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: srvsvc.c:185
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
#define SERVICE_RUNNING
Definition: winsvc.h:24
DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
Definition: rpc.c:26
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
#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
BOOL WINAPI SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwServiceBits, BOOL bSetBitsOn, BOOL bUpdateImmediately)
Definition: sctrl.c:973
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwServiceBits
Definition: srvsvc.c:40
#define WINAPI
Definition: msvc.h:8
DWORD dwWin32ExitCode
Definition: winsvc.h:102
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: srvsvc.c:152
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
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: srvsvc.c:37
static WCHAR ServiceName[]
Definition: srvsvc.c:35
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:810
static DWORD ServiceInit(VOID)
Definition: srvsvc.c:121
#define ERR(fmt,...)
Definition: debug.h:109
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
static VOID UpdateServiceStatus(DWORD dwState)
Definition: srvsvc.c:46
HANDLE hThread
Definition: wizard.c:27
WINE_DEFAULT_DEBUG_CHANNEL(srvsvc)
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40