ReactOS 0.4.15-dev-8390-g075894b
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
35static WCHAR ServiceName[] = L"lanmanworkstation";
36
39
43
44/* FUNCTIONS *****************************************************************/
45
46static VOID
48{
55
56 if (dwState == SERVICE_START_PENDING ||
57 dwState == SERVICE_STOP_PENDING ||
58 dwState == SERVICE_PAUSE_PENDING ||
59 dwState == SERVICE_CONTINUE_PENDING)
61 else
63
64 if (dwState == SERVICE_RUNNING)
66
69}
70
71
72static
75{
76 LSA_STRING ProcessName = RTL_CONSTANT_STRING("Workstation");
81
82 ERR("ServiceInit()\n");
83
84 /* Get the OS version */
87
88 Status = LsaRegisterLogonProcess(&ProcessName,
89 &LsaHandle,
90 &Mode);
91 if (!NT_SUCCESS(Status))
92 {
93 ERR("LsaRegisterLogonProcess() failed! (Status 0x%08lx)\n", Status);
94 return 1;
95 }
96
98 &PackageName,
100 if (!NT_SUCCESS(Status))
101 {
102 ERR("LsaLookupAuthenticationPackage() failed! (Status 0x%08lx)\n", Status);
103 return 1;
104 }
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 /* Report a running workstation service */
124 TRUE,
125 TRUE);
126
127 return ERROR_SUCCESS;
128}
129
130
131static
132VOID
134{
136
137 ERR("ServiceShutdown()\n");
138
140 if (!NT_SUCCESS(Status))
141 {
142 ERR("LsaDeRegisterLogonProcess() failed! (Status 0x%08lx)\n", Status);
143 return;
144 }
145}
146
147
148static DWORD WINAPI
150 DWORD dwEventType,
151 LPVOID lpEventData,
152 LPVOID lpContext)
153{
154 TRACE("ServiceControlHandler() called\n");
155
156 switch (dwControl)
157 {
159 TRACE(" SERVICE_CONTROL_STOP received\n");
161 /* Stop listening to incoming RPC messages */
165 return ERROR_SUCCESS;
166
168 TRACE(" SERVICE_CONTROL_PAUSE received\n");
170 return ERROR_SUCCESS;
171
173 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
175 return ERROR_SUCCESS;
176
178 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
181 return ERROR_SUCCESS;
182
184 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
186 /* Stop listening to incoming RPC messages */
190 return ERROR_SUCCESS;
191
192 default :
193 TRACE(" Control %lu received\n", dwControl);
195 }
196}
197
198
201{
202 DWORD dwError;
203
206
207 TRACE("ServiceMain() called\n");
208
211 NULL);
213 {
214 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
215 return;
216 }
217
219
220 dwError = ServiceInit();
221 if (dwError != ERROR_SUCCESS)
222 {
223 ERR("Service stopped (dwError: %lu\n", dwError);
225 return;
226 }
227
229}
230
231
234 DWORD fdwReason,
236{
237 switch (fdwReason)
238 {
241 break;
242
244 break;
245 }
246
247 return TRUE;
248}
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
static int argc
Definition: ServiceArgs.c:12
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
DWORD WINAPI RpcThreadRoutine(LPVOID lpParameter)
Definition: rpcserver.c:20
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define CloseHandle
Definition: compat.h:739
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
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:137
BOOL WINAPI GetVersionExW(IN LPOSVERSIONINFOW lpVersionInformation)
Definition: version.c:37
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
_In_ ULONG Mode
Definition: hubbusif.h:303
#define SV_TYPE_WORKSTATION
Definition: lmserver.h:427
static IN DWORD IN LPVOID lpvReserved
#define argv
Definition: mplay32.c:18
HANDLE hThread
Definition: wizard.c:28
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
NTSTATUS NTAPI LsaLookupAuthenticationPackage(HANDLE, PLSA_STRING, PULONG)
#define MSV1_0_PACKAGE_NAME
Definition: ntsecapi.h:42
ULONG LSA_OPERATIONAL_MODE
Definition: ntsecapi.h:367
NTSTATUS NTAPI LsaDeregisterLogonProcess(HANDLE)
NTSTATUS NTAPI LsaRegisterLogonProcess(PLSA_STRING, PHANDLE, PLSA_OPERATIONAL_MODE)
#define L(x)
Definition: ntvdm.h:50
RPC_STATUS WINAPI RpcMgmtStopServerListening(RPC_BINDING_HANDLE Binding)
Definition: rpc_server.c:1596
BOOL WINAPI SetServiceBits(SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwServiceBits, BOOL bSetBitsOn, BOOL bUpdateImmediately)
Definition: sctrl.c:975
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:812
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
#define TRACE(s)
Definition: solgame.cpp:4
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwControlsAccepted
Definition: winsvc.h:101
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwCurrentState
Definition: winsvc.h:100
DWORD dwCheckPoint
Definition: winsvc.h:104
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:729
#define WINAPI
Definition: msvc.h:6
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_PAUSED
Definition: winsvc.h:27
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
#define SERVICE_PAUSE_PENDING
Definition: winsvc.h:26
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
#define SERVICE_CONTINUE_PENDING
Definition: winsvc.h:25
static WCHAR ServiceName[]
Definition: wkssvc.c:35
static VOID ServiceShutdown(VOID)
Definition: wkssvc.c:133
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: wkssvc.c:233
HANDLE LsaHandle
Definition: wkssvc.c:41
static DWORD ServiceInit(VOID)
Definition: wkssvc.c:74
OSVERSIONINFOW VersionInfo
Definition: wkssvc.c:40
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: wkssvc.c:149
static VOID UpdateServiceStatus(DWORD dwState)
Definition: wkssvc.c:47
static SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: wkssvc.c:37
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
Definition: wkssvc.c:200
ULONG LsaAuthenticationPackage
Definition: wkssvc.c:42
static SERVICE_STATUS ServiceStatus
Definition: wkssvc.c:38
#define SERVICE_WIN32_SHARE_PROCESS
Definition: cmtypes.h:963
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR * LPTSTR
Definition: xmlstorage.h:192