ReactOS  0.4.14-dev-368-gfa26425
service.c File Reference
#include "config.h"
#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 55 of file service.c.

56 {
57  SC_HANDLE manager, service = NULL;
59  UINT error = 0;
60 
62  {
64  goto done;
65  }
67  {
69  goto done;
70  }
71  if (!ControlService( service, control, &status )) error = map_error( GetLastError() );
72  CloseServiceHandle( service );
73 
74 done:
75  set_variant( VT_UI4, error, NULL, retval );
76  if (manager) CloseServiceHandle( manager );
77  return S_OK;
78 }
#define SC_MANAGER_ENUMERATE_SERVICE
Definition: winsvc.h:16
#define error(str)
Definition: mkdosfs.c:1605
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:797
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
#define SERVICE_START
Definition: winsvc.h:57
#define S_OK
Definition: intsafe.h:59
#define SERVICE_STOP
Definition: winsvc.h:58
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:619
unsigned int UINT
Definition: ndis.h:50
Definition: name.c:36
static UINT map_error(DWORD error)
Definition: service.c:36
static SERVICE_STATUS status
Definition: service.c:31
#define SERVICE_PAUSE_CONTINUE
Definition: winsvc.h:59
Definition: ps.c:97

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

◆ map_error()

static UINT map_error ( DWORD  error)
static

Definition at line 36 of file service.c.

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

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 80 of file service.c.

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

Referenced by fill_service().

◆ service_resume_service()

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

Definition at line 125 of file service.c.

126 {
127  VARIANT name, retval;
129  HRESULT hr;
130 
131  TRACE("%p, %p, %p\n", obj, in, out);
132 
133  hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
134  if (hr != S_OK) return hr;
135 
137  if (hr != S_OK)
138  {
139  VariantClear( &name );
140  return hr;
141  }
142  if (out)
143  {
144  hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
145  if (hr != S_OK)
146  {
147  VariantClear( &name );
148  IWbemClassObject_Release( sig );
149  return hr;
150  }
151  }
153  if (hr != S_OK) goto done;
154 
155  if (out_params)
156  hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
157 
158 done:
159  VariantClear( &name );
160  IWbemClassObject_Release( sig );
161  if (hr == S_OK && out)
162  {
163  *out = out_params;
164  IWbemClassObject_AddRef( out_params );
165  }
166  if (out_params) IWbemClassObject_Release( out_params );
167  return hr;
168 }
HRESULT hr
Definition: shlfolder.c:183
static const WCHAR method_resumeserviceW[]
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR prop_nameW[]
#define TRACE(s)
Definition: solgame.cpp:4
static HRESULT control_service(const WCHAR *name, DWORD control, VARIANT *retval)
Definition: service.c:55
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR class_serviceW[]
static FILE * out
Definition: regtests2xml.c:44
static void out_params(void)
Definition: nanoxwin.c:1413
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
#define V_BSTR(A)
Definition: oleauto.h:226
#define S_OK
Definition: intsafe.h:59
GLuint in
Definition: glext.h:9616
#define SERVICE_CONTROL_CONTINUE
Definition: winsvc.h:38
HRESULT create_signature(const WCHAR *class, const WCHAR *method, enum param_direction dir, IWbemClassObject **sig)
Definition: class.c:818
Definition: name.c:36
static const WCHAR param_returnvalueW[]
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by fill_service().

◆ service_start_service()

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

Definition at line 194 of file service.c.

195 {
196  VARIANT name, retval;
198  HRESULT hr;
199 
200  TRACE("%p, %p, %p\n", obj, in, out);
201 
202  hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
203  if (hr != S_OK) return hr;
204 
206  if (hr != S_OK)
207  {
208  VariantClear( &name );
209  return hr;
210  }
211  if (out)
212  {
213  hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
214  if (hr != S_OK)
215  {
216  VariantClear( &name );
217  IWbemClassObject_Release( sig );
218  return hr;
219  }
220  }
221  hr = start_service( V_BSTR(&name), &retval );
222  if (hr != S_OK) goto done;
223 
224  if (out_params)
225  hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
226 
227 done:
228  VariantClear( &name );
229  IWbemClassObject_Release( sig );
230  if (hr == S_OK && out)
231  {
232  *out = out_params;
233  IWbemClassObject_AddRef( out_params );
234  }
235  if (out_params) IWbemClassObject_Release( out_params );
236  return hr;
237 }
HRESULT hr
Definition: shlfolder.c:183
smooth NULL
Definition: ftsmooth.c:416
static HRESULT start_service(const WCHAR *name, VARIANT *retval)
Definition: service.c:170
static const WCHAR prop_nameW[]
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR class_serviceW[]
static FILE * out
Definition: regtests2xml.c:44
static void out_params(void)
Definition: nanoxwin.c:1413
static const WCHAR method_startserviceW[]
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
#define V_BSTR(A)
Definition: oleauto.h:226
#define S_OK
Definition: intsafe.h:59
GLuint in
Definition: glext.h:9616
HRESULT create_signature(const WCHAR *class, const WCHAR *method, enum param_direction dir, IWbemClassObject **sig)
Definition: class.c:818
Definition: name.c:36
static const WCHAR param_returnvalueW[]
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by fill_service().

◆ service_stop_service()

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

Definition at line 239 of file service.c.

240 {
241  VARIANT name, retval;
243  HRESULT hr;
244 
245  TRACE("%p, %p, %p\n", obj, in, out);
246 
247  hr = IWbemClassObject_Get( obj, prop_nameW, 0, &name, NULL, NULL );
248  if (hr != S_OK) return hr;
249 
251  if (hr != S_OK)
252  {
253  VariantClear( &name );
254  return hr;
255  }
256  if (out)
257  {
258  hr = IWbemClassObject_SpawnInstance( sig, 0, &out_params );
259  if (hr != S_OK)
260  {
261  VariantClear( &name );
262  IWbemClassObject_Release( sig );
263  return hr;
264  }
265  }
267  if (hr != S_OK) goto done;
268 
269  if (out_params)
270  hr = IWbemClassObject_Put( out_params, param_returnvalueW, 0, &retval, CIM_UINT32 );
271 
272 done:
273  VariantClear( &name );
274  IWbemClassObject_Release( sig );
275  if (hr == S_OK && out)
276  {
277  *out = out_params;
278  IWbemClassObject_AddRef( out_params );
279  }
280  if (out_params) IWbemClassObject_Release( out_params );
281  return hr;
282 }
HRESULT hr
Definition: shlfolder.c:183
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR prop_nameW[]
#define TRACE(s)
Definition: solgame.cpp:4
static HRESULT control_service(const WCHAR *name, DWORD control, VARIANT *retval)
Definition: service.c:55
LONG HRESULT
Definition: typedefs.h:77
static const WCHAR class_serviceW[]
static FILE * out
Definition: regtests2xml.c:44
static void out_params(void)
Definition: nanoxwin.c:1413
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:651
#define V_BSTR(A)
Definition: oleauto.h:226
static const WCHAR method_stopserviceW[]
#define S_OK
Definition: intsafe.h:59
GLuint in
Definition: glext.h:9616
HRESULT create_signature(const WCHAR *class, const WCHAR *method, enum param_direction dir, IWbemClassObject **sig)
Definition: class.c:818
Definition: name.c:36
static const WCHAR param_returnvalueW[]
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by fill_service().

◆ start_service()

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

Definition at line 170 of file service.c.

171 {
172  SC_HANDLE manager, service = NULL;
173  UINT error = 0;
174 
176  {
178  goto done;
179  }
180  if (!(service = OpenServiceW( manager, name, SERVICE_START )))
181  {
183  goto done;
184  }
185  if (!StartServiceW( service, 0, NULL )) error = map_error( GetLastError() );
186  CloseServiceHandle( service );
187 
188 done:
189  set_variant( VT_UI4, error, NULL, retval );
190  if (manager) CloseServiceHandle( manager );
191  return S_OK;
192 }
#define SC_MANAGER_ENUMERATE_SERVICE
Definition: winsvc.h:16
#define error(str)
Definition: mkdosfs.c:1605
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
void set_variant(VARTYPE type, LONGLONG val, void *val_ptr, VARIANT *ret)
Definition: query.c:797
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2923
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
#define SERVICE_START
Definition: winsvc.h:57
#define S_OK
Definition: intsafe.h:59
unsigned int UINT
Definition: ndis.h:50
Definition: name.c:36
static UINT map_error(DWORD error)
Definition: service.c:36

Referenced by service_process(), and service_start_service().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wbemprox  )