3 * Copyright (C) 2015 ReactOS Team
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.
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.
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.
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
27 /* INCLUDES *****************************************************************/
31 WINE_DEFAULT_DEBUG_CHANNEL(wkssvc
);
33 /* GLOBALS ******************************************************************/
35 static WCHAR ServiceName
[] = L
"lanmanworkstation";
37 static SERVICE_STATUS_HANDLE ServiceStatusHandle
;
38 static SERVICE_STATUS ServiceStatus
;
40 /* FUNCTIONS *****************************************************************/
43 UpdateServiceStatus(DWORD dwState
)
45 ServiceStatus
.dwServiceType
= SERVICE_WIN32_OWN_PROCESS
;
46 ServiceStatus
.dwCurrentState
= dwState
;
47 ServiceStatus
.dwControlsAccepted
= 0;
48 ServiceStatus
.dwWin32ExitCode
= 0;
49 ServiceStatus
.dwServiceSpecificExitCode
= 0;
50 ServiceStatus
.dwCheckPoint
= 0;
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;
58 ServiceStatus
.dwWaitHint
= 0;
60 SetServiceStatus(ServiceStatusHandle
,
65 ServiceControlHandler(DWORD dwControl
,
70 TRACE("ServiceControlHandler() called\n");
74 case SERVICE_CONTROL_STOP
:
75 TRACE(" SERVICE_CONTROL_STOP received\n");
76 /* Stop listening to incoming RPC messages */
77 RpcMgmtStopServerListening(NULL
);
78 UpdateServiceStatus(SERVICE_STOPPED
);
81 case SERVICE_CONTROL_PAUSE
:
82 TRACE(" SERVICE_CONTROL_PAUSE received\n");
83 UpdateServiceStatus(SERVICE_PAUSED
);
86 case SERVICE_CONTROL_CONTINUE
:
87 TRACE(" SERVICE_CONTROL_CONTINUE received\n");
88 UpdateServiceStatus(SERVICE_RUNNING
);
91 case SERVICE_CONTROL_INTERROGATE
:
92 TRACE(" SERVICE_CONTROL_INTERROGATE received\n");
93 SetServiceStatus(ServiceStatusHandle
,
97 case SERVICE_CONTROL_SHUTDOWN
:
98 TRACE(" SERVICE_CONTROL_SHUTDOWN received\n");
99 UpdateServiceStatus(SERVICE_STOPPED
);
100 return ERROR_SUCCESS
;
103 TRACE(" Control %lu received\n", dwControl
);
104 return ERROR_CALL_NOT_IMPLEMENTED
;
115 hThread
= CreateThread(NULL
,
117 (LPTHREAD_START_ROUTINE
)RpcThreadRoutine
,
124 ERR("Can't create PortThread\n");
125 return GetLastError();
128 CloseHandle(hThread
);
130 /* Report a running workstation service */
131 SetServiceBits(ServiceStatusHandle
,
136 return ERROR_SUCCESS
;
141 ServiceMain(DWORD argc
, LPTSTR
*argv
)
145 UNREFERENCED_PARAMETER(argc
);
146 UNREFERENCED_PARAMETER(argv
);
148 TRACE("ServiceMain() called\n");
150 ServiceStatusHandle
= RegisterServiceCtrlHandlerExW(ServiceName
,
151 ServiceControlHandler
,
153 if (!ServiceStatusHandle
)
155 ERR("RegisterServiceCtrlHandlerExW() failed! (Error %lu)\n", GetLastError());
159 UpdateServiceStatus(SERVICE_START_PENDING
);
161 dwError
= ServiceInit();
162 if (dwError
!= ERROR_SUCCESS
)
164 ERR("Service stopped (dwError: %lu\n", dwError
);
165 UpdateServiceStatus(SERVICE_STOPPED
);
169 UpdateServiceStatus(SERVICE_RUNNING
);
174 DllMain(HINSTANCE hinstDLL
,
180 case DLL_PROCESS_ATTACH
:
181 DisableThreadLibraryCalls(hinstDLL
);
184 case DLL_PROCESS_DETACH
: