ReactOS 0.4.16-dev-297-gc569aee
service.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wbemcli.h"
#include "winsvc.h"
#include "wine/debug.h"
#include "wbemprox_private.h"
Include dependency graph for service.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wbemprox)
 
static UINT map_error (DWORD error)
 
static HRESULT control_service (const WCHAR *name, DWORD control, VARIANT *retval)
 
HRESULT service_pause_service (IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out)
 
HRESULT service_resume_service (IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out)
 
static HRESULT start_service (const WCHAR *name, VARIANT *retval)
 
HRESULT service_start_service (IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out)
 
HRESULT service_stop_service (IWbemClassObject *obj, IWbemClassObject *in, IWbemClassObject **out)
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 21 of file service.c.

Function Documentation

◆ control_service()

static HRESULT control_service ( const WCHAR name,
DWORD  control,
VARIANT retval 
)
static

Definition at line 54 of file service.c.

55{
56 SC_HANDLE manager, service = NULL;
58 UINT error = 0;
59
61 {
63 goto done;
64 }
66 {
68 goto done;
69 }
70 if (!ControlService( service, control, &status )) error = map_error( GetLastError() );
71 CloseServiceHandle( service );
72
73done:
74 set_variant( VT_UI4, error, NULL, retval );
75 if (manager) CloseServiceHandle( manager );
76 return S_OK;
77}
#define NULL
Definition: types.h:112
@ VT_UI4
Definition: compat.h:2313
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:1093
static UINT map_error(DWORD error)
Definition: service.c:35
#define S_OK
Definition: intsafe.h:52
#define error(str)
Definition: mkdosfs.c:1605
unsigned int UINT
Definition: ndis.h:50
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
Definition: dialog.c:52
Definition: name.c:39
Definition: ps.c:97
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SERVICE_START
Definition: winsvc.h:57
#define SC_MANAGER_ENUMERATE_SERVICE
Definition: winsvc.h:16
#define SERVICE_PAUSE_CONTINUE
Definition: winsvc.h:59
#define SERVICE_STOP
Definition: winsvc.h:58

Referenced by service_pause_service(), service_resume_service(), and service_stop_service().

◆ map_error()

static UINT map_error ( DWORD  error)
static

Definition at line 35 of file service.c.

36{
37 switch (error)
38 {
39 case ERROR_SUCCESS: return 0;
40 case ERROR_ACCESS_DENIED: return 2;
42 case ERROR_INVALID_SERVICE_CONTROL: return 4;
44 case ERROR_SERVICE_NOT_ACTIVE: return 6;
45 case ERROR_SERVICE_REQUEST_TIMEOUT: return 7;
46 case ERROR_SERVICE_ALREADY_RUNNING: return 10;
47 default:
48 WARN("unknown error %u\n", error);
49 break;
50 }
51 return 8;
52}
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
#define ERROR_DEPENDENT_SERVICES_RUNNING
Definition: winerror.h:602
#define ERROR_SERVICE_REQUEST_TIMEOUT
Definition: winerror.h:604
#define ERROR_INVALID_SERVICE_CONTROL
Definition: winerror.h:603
#define ERROR_SERVICE_CANNOT_ACCEPT_CTRL
Definition: winerror.h:612

Referenced by control_service(), ldap_add_ext_sW(), ldap_add_extW(), ldap_add_sW(), ldap_bind_sW(), ldap_compare_ext_sW(), ldap_compare_extW(), ldap_compare_sW(), ldap_create_sort_controlW(), ldap_create_vlv_controlW(), ldap_delete_ext_sW(), ldap_delete_extW(), ldap_delete_sW(), ldap_extended_operation_sW(), ldap_extended_operationW(), ldap_get_optionW(), ldap_modify_ext_sW(), ldap_modify_extW(), ldap_modify_sW(), ldap_modrdn2_sW(), ldap_modrdn_sW(), ldap_parse_extended_resultW(), ldap_parse_referenceW(), ldap_parse_resultW(), ldap_parse_sort_controlW(), ldap_parse_vlv_controlW(), ldap_rename_ext_sW(), ldap_rename_extW(), ldap_sasl_bind_sW(), ldap_sasl_bindW(), ldap_search_ext_sW(), ldap_search_extW(), ldap_search_stW(), ldap_search_sW(), ldap_set_optionW(), ldap_simple_bind_sW(), ldap_start_tls_sW(), start_service(), WLDAP32_ldap_abandon(), WLDAP32_ldap_unbind(), and WLDAP32_ldap_unbind_s().

◆ service_pause_service()

HRESULT service_pause_service ( IWbemClassObject obj,
IWbemClassObject in,
IWbemClassObject **  out 
)

Definition at line 79 of file service.c.

80{
81 VARIANT name, retval;
83 HRESULT hr;
84
85 TRACE("%p, %p, %p\n", obj, in, out);
86
87 hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
88 if (hr != S_OK) return hr;
89
91 if (hr != S_OK)
92 {
94 return hr;
95 }
96 if (out)
97 {
98 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
99 if (hr != S_OK)
100 {
101 VariantClear( &name );
102 IWbemClassObject_Release( sig );
103 return hr;
104 }
105 }
107 if (hr != S_OK) goto done;
108
109 if (out_params)
110 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
111
112done:
113 VariantClear( &name );
114 IWbemClassObject_Release( sig );
115 if (hr == S_OK && out)
116 {
117 *out = out_params;
118 IWbemClassObject_AddRef( out_params );
119 }
120 if (out_params) IWbemClassObject_Release( out_params );
121 return hr;
122}
HRESULT create_signature(const WCHAR *class, const WCHAR *method, enum param_direction dir, IWbemClassObject **sig)
Definition: class.c:819
static HRESULT control_service(const WCHAR *name, DWORD control, VARIANT *retval)
Definition: service.c:54
GLuint in
Definition: glext.h:9616
static void out_params(void)
Definition: nanoxwin.c:1413
#define V_BSTR(A)
Definition: oleauto.h:226
static FILE * out
Definition: regtests2xml.c:44
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
@ CIM_UINT32
Definition: wbemcli.idl:249
static const WCHAR class_serviceW[]
static const WCHAR method_pauseserviceW[]
@ PARAM_OUT
static const WCHAR param_returnvalueW[]
static const WCHAR prop_nameW[]
#define SERVICE_CONTROL_PAUSE
Definition: winsvc.h:37

Referenced by fill_service().

◆ service_resume_service()

HRESULT service_resume_service ( IWbemClassObject obj,
IWbemClassObject in,
IWbemClassObject **  out 
)

Definition at line 124 of file service.c.

125{
126 VARIANT name, retval;
128 HRESULT hr;
129
130 TRACE("%p, %p, %p\n", obj, in, out);
131
132 hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
133 if (hr != S_OK) return hr;
134
136 if (hr != S_OK)
137 {
138 VariantClear( &name );
139 return hr;
140 }
141 if (out)
142 {
143 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
144 if (hr != S_OK)
145 {
146 VariantClear( &name );
147 IWbemClassObject_Release( sig );
148 return hr;
149 }
150 }
152 if (hr != S_OK) goto done;
153
154 if (out_params)
155 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
156
157done:
158 VariantClear( &name );
159 IWbemClassObject_Release( sig );
160 if (hr == S_OK && out)
161 {
162 *out = out_params;
163 IWbemClassObject_AddRef( out_params );
164 }
165 if (out_params) IWbemClassObject_Release( out_params );
166 return hr;
167}
static const WCHAR method_resumeserviceW[]
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38

Referenced by fill_service().

◆ service_start_service()

HRESULT service_start_service ( IWbemClassObject obj,
IWbemClassObject in,
IWbemClassObject **  out 
)

Definition at line 193 of file service.c.

194{
195 VARIANT name, retval;
197 HRESULT hr;
198
199 TRACE("%p, %p, %p\n", obj, in, out);
200
201 hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
202 if (hr != S_OK) return hr;
203
205 if (hr != S_OK)
206 {
207 VariantClear( &name );
208 return hr;
209 }
210 if (out)
211 {
212 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
213 if (hr != S_OK)
214 {
215 VariantClear( &name );
216 IWbemClassObject_Release( sig );
217 return hr;
218 }
219 }
220 hr = start_service( V_BSTR(&name), &retval );
221 if (hr != S_OK) goto done;
222
223 if (out_params)
224 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
225
226done:
227 VariantClear( &name );
228 IWbemClassObject_Release( sig );
229 if (hr == S_OK && out)
230 {
231 *out = out_params;
232 IWbemClassObject_AddRef( out_params );
233 }
234 if (out_params) IWbemClassObject_Release( out_params );
235 return hr;
236}
static HRESULT start_service(const WCHAR *name, VARIANT *retval)
Definition: service.c:169
static const WCHAR method_startserviceW[]

Referenced by fill_service().

◆ service_stop_service()

HRESULT service_stop_service ( IWbemClassObject obj,
IWbemClassObject in,
IWbemClassObject **  out 
)

Definition at line 238 of file service.c.

239{
240 VARIANT name, retval;
242 HRESULT hr;
243
244 TRACE("%p, %p, %p\n", obj, in, out);
245
246 hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
247 if (hr != S_OK) return hr;
248
250 if (hr != S_OK)
251 {
252 VariantClear( &name );
253 return hr;
254 }
255 if (out)
256 {
257 hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
258 if (hr != S_OK)
259 {
260 VariantClear( &name );
261 IWbemClassObject_Release( sig );
262 return hr;
263 }
264 }
266 if (hr != S_OK) goto done;
267
268 if (out_params)
269 hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
270
271done:
272 VariantClear( &name );
273 IWbemClassObject_Release( sig );
274 if (hr == S_OK && out)
275 {
276 *out = out_params;
277 IWbemClassObject_AddRef( out_params );
278 }
279 if (out_params) IWbemClassObject_Release( out_params );
280 return hr;
281}
static const WCHAR method_stopserviceW[]
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36

Referenced by fill_service().

◆ start_service()

static HRESULT start_service ( const WCHAR name,
VARIANT retval 
)
static

Definition at line 169 of file service.c.

170{
171 SC_HANDLE manager, service = NULL;
172 UINT error = 0;
173
175 {
177 goto done;
178 }
179 if (!(service = OpenServiceW( manager, name, SERVICE_START )))
180 {
182 goto done;
183 }
184 if (!StartServiceW( service, 0, NULL )) error = map_error( GetLastError() );
185 CloseServiceHandle( service );
186
187done:
188 set_variant( VT_UI4, error, NULL, retval );
189 if (manager) CloseServiceHandle( manager );
190 return S_OK;
191}
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2980

Referenced by service_process(), and service_start_service().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wbemprox  )