ReactOS  0.4.15-dev-2487-g7b27e7c
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 
43 
44 /* FUNCTIONS *****************************************************************/
45 
46 static VOID
48 {
50  ServiceStatus.dwCurrentState = dwState;
55 
56  if (dwState == SERVICE_START_PENDING ||
57  dwState == SERVICE_STOP_PENDING ||
58  dwState == SERVICE_PAUSE_PENDING ||
59  dwState == SERVICE_CONTINUE_PENDING)
60  ServiceStatus.dwWaitHint = 10000;
61  else
63 
64  if (dwState == SERVICE_RUNNING)
66 
68  &ServiceStatus);
69 }
70 
71 
72 static
73 DWORD
75 {
76  LSA_STRING ProcessName, PackageName;
80 
81  ERR("ServiceInit()\n");
82 
83  /* Get the OS version */
86 
87  ProcessName.Buffer = "Workstation";
88  ProcessName.Length = strlen(ProcessName.Buffer);
89  ProcessName.MaximumLength = ProcessName.Length + 1;
90 
91  Status = LsaRegisterLogonProcess(&ProcessName,
92  &LsaHandle,
93  &Mode);
94  if (!NT_SUCCESS(Status))
95  {
96  ERR("LsaRegisterLogonProcess() failed! (Status 0x%08lx)\n", Status);
97  return 1;
98  }
99 
100  PackageName.Buffer = MSV1_0_PACKAGE_NAME;
101  PackageName.Length = strlen(PackageName.Buffer);
102  PackageName.MaximumLength = PackageName.Length + 1;
103 
105  &PackageName,
107  if (!NT_SUCCESS(Status))
108  {
109  ERR("LsaLookupAuthenticationPackage() failed! (Status 0x%08lx)\n", Status);
110  return 1;
111  }
112 
114  0,
116  NULL,
117  0,
118  NULL);
119 
120  if (!hThread)
121  {
122  ERR("Can't create PortThread\n");
123  return GetLastError();
124  }
125  else
127 
128  /* Report a running workstation service */
131  TRUE,
132  TRUE);
133 
134  return ERROR_SUCCESS;
135 }
136 
137 
138 static
139 VOID
141 {
143 
144  ERR("ServiceShutdown()\n");
145 
147  if (!NT_SUCCESS(Status))
148  {
149  ERR("LsaDeRegisterLogonProcess() failed! (Status 0x%08lx)\n", Status);
150  return;
151  }
152 }
153 
154 
155 static DWORD WINAPI
157  DWORD dwEventType,
158  LPVOID lpEventData,
159  LPVOID lpContext)
160 {
161  TRACE("ServiceControlHandler() called\n");
162 
163  switch (dwControl)
164  {
166  TRACE(" SERVICE_CONTROL_STOP received\n");
168  /* Stop listening to incoming RPC messages */
170  ServiceShutdown();
172  return ERROR_SUCCESS;
173 
175  TRACE(" SERVICE_CONTROL_PAUSE received\n");
177  return ERROR_SUCCESS;
178 
180  TRACE(" SERVICE_CONTROL_CONTINUE received\n");
182  return ERROR_SUCCESS;
183 
185  TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
187  &ServiceStatus);
188  return ERROR_SUCCESS;
189 
191  TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
193  /* Stop listening to incoming RPC messages */
195  ServiceShutdown();
197  return ERROR_SUCCESS;
198 
199  default :
200  TRACE(" Control %lu received\n", dwControl);
202  }
203 }
204 
205 
206 VOID WINAPI
208 {
209  DWORD dwError;
210 
213 
214  TRACE("ServiceMain() called\n");
215 
218  NULL);
219  if (!ServiceStatusHandle)
220  {
221  ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
222  return;
223  }
224 
226 
227  dwError = ServiceInit();
228  if (dwError != ERROR_SUCCESS)
229  {
230  ERR("Service stopped (dwError: %lu\n", dwError);
232  return;
233  }
234 
236 }
237 
238 
239 BOOL WINAPI
241  DWORD fdwReason,
243 {
244  switch (fdwReason)
245  {
246  case DLL_PROCESS_ATTACH:
247  DisableThreadLibraryCalls(hinstDLL);
248  break;
249 
250  case DLL_PROCESS_DETACH:
251  break;
252  }
253 
254  return TRUE;
255 }
static int argc
Definition: ServiceArgs.c:12
#define SV_TYPE_WORKSTATION
Definition: lmserver.h:427
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:723
#define CloseHandle
Definition: compat.h:598
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: wkssvc.c:156
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596
DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
Definition: rpcserver.c:20
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwCurrentState
Definition: winsvc.h:100
_In_ ULONG Mode
Definition: hubbusif.h:303
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define SERVICE_PAUSED
Definition: winsvc.h:27
LONG NTSTATUS
Definition: precomp.h:26
#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:1044
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: wkssvc.c:207
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define argv
Definition: mplay32.c:18
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
CHAR * LPTSTR
Definition: xmlstorage.h:192
static IN DWORD IN LPVOID lpvReserved
ULONG LsaAuthenticationPackage
Definition: wkssvc.c:42
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:997
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
static VOID ServiceShutdown(VOID)
Definition: wkssvc.c:140
unsigned int BOOL
Definition: ntddk_ex.h:94
#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
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
ULONG LSA_OPERATIONAL_MODE
Definition: ntsecapi.h:367
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
#define DLL_PROCESS_DETACH
Definition: compat.h:130
HANDLE LsaHandle
Definition: wkssvc.c:41
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
Status
Definition: gdiplustypes.h:24
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
BOOL WINAPI SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwServiceBits, BOOL bSetBitsOn, BOOL bUpdateImmediately)
Definition: sctrl.c:975
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD dwWaitHint
Definition: winsvc.h:105
USHORT Length
Definition: ntsecapi.h:172
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
#define WINAPI
Definition: msvc.h:6
DWORD dwWin32ExitCode
Definition: winsvc.h:102
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwServiceType
Definition: winsvc.h:99
PCHAR Buffer
Definition: ntsecapi.h:174
WINE_DEFAULT_DEBUG_CHANNEL(wkssvc)
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
NTSTATUS NTAPI LsaDeregisterLogonProcess(HANDLE)
static const WCHAR L[]
Definition: oid.c:1250
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:812
#define ERR(fmt,...)
Definition: debug.h:110
DWORD dwControlsAccepted
Definition: winsvc.h:101
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wkssvc.c:47
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: wkssvc.c:240
USHORT MaximumLength
Definition: ntsecapi.h:173
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
NTSTATUS NTAPI LsaLookupAuthenticationPackage(HANDLE, PLSA_STRING, PULONG)
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define NULL
Definition: types.h:112
HANDLE hThread
Definition: wizard.c:28
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wkssvc.c:37
unsigned int ULONG
Definition: retypes.h:1
static DWORD ServiceInit(VOID)
Definition: wkssvc.c:74
NTSTATUS NTAPI LsaRegisterLogonProcess(PLSA_STRING, PHANDLE, PLSA_OPERATIONAL_MODE)
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40