ReactOS  0.4.11-dev-946-g431643b
wkssvc.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/wkssvc/wkssvc.c
23  * PURPOSE: Workstation service
24  * PROGRAMMER: Eric Kohl
25  */
26 
27 /* INCLUDES *****************************************************************/
28 
29 #include "precomp.h"
30 
32 
33 /* GLOBALS ******************************************************************/
34 
35 static WCHAR ServiceName[] = L"lanmanworkstation";
36 
39 
40 /* FUNCTIONS *****************************************************************/
41 
42 static VOID
44 {
46  ServiceStatus.dwCurrentState = dwState;
47  ServiceStatus.dwControlsAccepted = 0;
48  ServiceStatus.dwWin32ExitCode = 0;
49  ServiceStatus.dwServiceSpecificExitCode = 0;
50  ServiceStatus.dwCheckPoint = 0;
51 
52  if (dwState == SERVICE_START_PENDING ||
53  dwState == SERVICE_STOP_PENDING ||
54  dwState == SERVICE_PAUSE_PENDING ||
55  dwState == SERVICE_CONTINUE_PENDING)
56  ServiceStatus.dwWaitHint = 10000;
57  else
58  ServiceStatus.dwWaitHint = 0;
59 
61  &ServiceStatus);
62 }
63 
64 static DWORD WINAPI
66  DWORD dwEventType,
67  LPVOID lpEventData,
68  LPVOID lpContext)
69 {
70  TRACE("ServiceControlHandler() called\n");
71 
72  switch (dwControl)
73  {
75  TRACE(" SERVICE_CONTROL_STOP received\n");
76  /* Stop listening to incoming RPC messages */
79  return ERROR_SUCCESS;
80 
82  TRACE(" SERVICE_CONTROL_PAUSE received\n");
84  return ERROR_SUCCESS;
85 
87  TRACE(" SERVICE_CONTROL_CONTINUE received\n");
89  return ERROR_SUCCESS;
90 
92  TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
94  &ServiceStatus);
95  return ERROR_SUCCESS;
96 
98  TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
100  return ERROR_SUCCESS;
101 
102  default :
103  TRACE(" Control %lu received\n", dwControl);
105  }
106 }
107 
108 
109 static
110 DWORD
112 {
113  HANDLE hThread;
114 
115  hThread = CreateThread(NULL,
116  0,
118  NULL,
119  0,
120  NULL);
121 
122  if (!hThread)
123  {
124  ERR("Can't create PortThread\n");
125  return GetLastError();
126  }
127  else
128  CloseHandle(hThread);
129 
130  /* Report a running workstation service */
133  TRUE,
134  TRUE);
135 
136  return ERROR_SUCCESS;
137 }
138 
139 
140 VOID WINAPI
142 {
143  DWORD dwError;
144 
147 
148  TRACE("ServiceMain() called\n");
149 
152  NULL);
153  if (!ServiceStatusHandle)
154  {
155  ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
156  return;
157  }
158 
160 
161  dwError = ServiceInit();
162  if (dwError != ERROR_SUCCESS)
163  {
164  ERR("Service stopped (dwError: %lu\n", dwError);
166  return;
167  }
168 
170 }
171 
172 
173 BOOL WINAPI
175  DWORD fdwReason,
177 {
178  switch (fdwReason)
179  {
180  case DLL_PROCESS_ATTACH:
181  DisableThreadLibraryCalls(hinstDLL);
182  break;
183 
184  case DLL_PROCESS_DETACH:
185  break;
186  }
187 
188  return TRUE;
189 }
static int argc
Definition: ServiceArgs.c:12
#define SV_TYPE_WORKSTATION
Definition: lmserver.h:427
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: wkssvc.c:65
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SERVICE_PAUSED
Definition: winsvc.h:27
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
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: wkssvc.c:141
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
static char ** argv
Definition: ServiceArgs.c:11
CHAR * LPTSTR
Definition: xmlstorage.h:192
static IN DWORD IN LPVOID lpvReserved
static WCHAR ServiceName[]
Definition: wkssvc.c:35
static SERVICE_STATUS ServiceStatus
Definition: wkssvc.c:38
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
#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:112
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
BOOL WINAPI SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwServiceBits, BOOL bSetBitsOn, BOOL bUpdateImmediately)
Definition: sctrl.c:935
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
WINE_DEFAULT_DEBUG_CHANNEL(wkssvc)
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
static const WCHAR L[]
Definition: oid.c:1087
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:773
#define WINAPI
Definition: msvc.h:20
#define ERR(fmt,...)
Definition: debug.h:109
DWORD dwControlsAccepted
Definition: winsvc.h:101
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wkssvc.c:43
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: wkssvc.c:174
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
HANDLE hThread
Definition: wizard.c:27
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wkssvc.c:37
static DWORD ServiceInit(VOID)
Definition: wkssvc.c:111
#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