ReactOS 0.4.15-dev-7942-gd23573b
failure.c File Reference
#include "sc.h"
Include dependency graph for failure.c:

Go to the source code of this file.

Functions

BOOL QueryFailure (LPCTSTR ServiceName)
 
BOOL SetFailure (LPCTSTR *ServiceArgs, INT ArgCount)
 

Function Documentation

◆ QueryFailure()

BOOL QueryFailure ( LPCTSTR  ServiceName)

Definition at line 11 of file failure.c.

12{
13 SC_HANDLE hManager = NULL;
14 SC_HANDLE hService = NULL;
15 BOOL bResult = TRUE;
16 DWORD cbBytesNeeded = 0;
17 LPSERVICE_FAILURE_ACTIONS pServiceFailure = NULL;
18 INT i;
19
20#ifdef SCDBG
21 _tprintf(_T("service to show failure action - %s\n\n"), ServiceName);
22#endif
23
24 hManager = OpenSCManager(NULL,
25 NULL,
27 if (hManager == NULL)
28 {
29 bResult = FALSE;
30 goto done;
31 }
32
33 hService = OpenService(hManager, ServiceName, SERVICE_QUERY_CONFIG);
34 if (hService == NULL)
35 {
36 bResult = FALSE;
37 goto done;
38 }
39
40 if (!QueryServiceConfig2(hService,
42 NULL,
43 0,
44 &cbBytesNeeded))
45 {
46 if (cbBytesNeeded == 0)
47 {
48 bResult = FALSE;
49 goto done;
50 }
51 }
52
53 pServiceFailure = HeapAlloc(GetProcessHeap(), 0, cbBytesNeeded);
54 if (pServiceFailure == NULL)
55 {
57 bResult = FALSE;
58 goto done;
59 }
60
61 if (!QueryServiceConfig2(hService,
63 (LPBYTE)pServiceFailure,
64 cbBytesNeeded,
65 &cbBytesNeeded))
66 {
67 bResult = FALSE;
68 goto done;
69 }
70
71 _tprintf(_T("SERVICE_NAME: %s\n"), ServiceName);
72 _tprintf(_T(" RESET_PERIOD : %lu seconds\n"), pServiceFailure->dwResetPeriod);
73 _tprintf(_T(" REBOOT_MESSAGE : %s\n"), (pServiceFailure->lpRebootMsg) ? pServiceFailure->lpRebootMsg : _T(""));
74 _tprintf(_T(" COMMAND_LINE : %s\n"), (pServiceFailure->lpCommand) ? pServiceFailure->lpCommand : _T(""));
75 _tprintf(_T(" FAILURE_ACTIONS : "));
76 for (i = 0; i < pServiceFailure->cActions; i++)
77 {
78 if (i != 0)
79 _tprintf(_T(" "));
80 switch (pServiceFailure->lpsaActions[i].Type)
81 {
82 case SC_ACTION_NONE:
83 continue;
84
86 _tprintf(_T("RESTART -- Delay = %lu milliseconds.\n"), pServiceFailure->lpsaActions[i].Delay);
87 break;
88
90 _tprintf(_T("REBOOT -- Delay = %lu milliseconds.\n"), pServiceFailure->lpsaActions[i].Delay);
91 break;
92
94 _tprintf(_T("RUN_COMMAND -- Delay = %lu milliseconds.\n"), pServiceFailure->lpsaActions[i].Delay);
95 break;
96
97 default:
98 _tprintf(_T("\n"));
99 break;
100 }
101 }
102
103done:
104 if (bResult == FALSE)
106
107 if (pServiceFailure != NULL)
108 HeapFree(GetProcessHeap(), 0, pServiceFailure);
109
110 if (hService)
111 CloseServiceHandle(hService);
112
113 if (hManager)
114 CloseServiceHandle(hManager);
115
116 return bResult;
117}
static WCHAR ServiceName[]
Definition: browser.c:19
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tprintf
Definition: tchar.h:506
DWORD ReportLastError(void)
Definition: loadlib.c:67
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define OpenSCManager
Definition: winsvc.h:575
@ SC_ACTION_RUN_COMMAND
Definition: winsvc.h:202
@ SC_ACTION_REBOOT
Definition: winsvc.h:201
@ SC_ACTION_RESTART
Definition: winsvc.h:200
@ SC_ACTION_NONE
Definition: winsvc.h:199
#define SC_MANAGER_CONNECT
Definition: winsvc.h:14
#define SERVICE_CONFIG_FAILURE_ACTIONS
Definition: winsvc.h:66
#define QueryServiceConfig2
Definition: winsvc.h:581
#define SERVICE_QUERY_CONFIG
Definition: winsvc.h:53
#define OpenService
Definition: winsvc.h:576

Referenced by ScControl().

◆ SetFailure()

BOOL SetFailure ( LPCTSTR ServiceArgs,
INT  ArgCount 
)

Definition at line 120 of file failure.c.

123{
124 SC_HANDLE hManager = NULL;
125 SC_HANDLE hService = NULL;
126 BOOL bResult = TRUE;
127 SERVICE_FAILURE_ACTIONS FailureActions;
128 LPCTSTR lpServiceName = NULL;
129 BOOLEAN Old = FALSE;
130
131 ZeroMemory(&FailureActions, sizeof(SERVICE_FAILURE_ACTIONS));
132
133 if (!ParseFailureArguments(ServiceArgs, ArgCount, &lpServiceName, &FailureActions))
134 {
136 return FALSE;
137 }
138
139 hManager = OpenSCManager(NULL,
140 NULL,
142 if (hManager == NULL)
143 {
144 _tprintf(_T("[SC] OpenSCManager FAILED %lu:\n\n"), GetLastError());
145 bResult = FALSE;
146 goto done;
147 }
148
149 hService = OpenService(hManager,
150 lpServiceName,
152 if (hService == NULL)
153 {
154 _tprintf(_T("[SC] OpenService FAILED %lu:\n\n"), GetLastError());
155 bResult = FALSE;
156 goto done;
157 }
158
160
161 if (!ChangeServiceConfig2(hService,
163 (LPBYTE)&FailureActions))
164 {
165 _tprintf(_T("[SC] ChangeServiceConfig2 FAILED %lu:\n\n"), GetLastError());
166 bResult = FALSE;
167 goto done;
168 }
169
170 _tprintf(_T("[SC] ChangeServiceConfig2 SUCCESS\n\n"));
171
172done:
174
175 if (bResult == FALSE)
177
178 if (FailureActions.lpsaActions != NULL)
179 HeapFree(GetProcessHeap(), 0, FailureActions.lpsaActions);
180
181 if (hService)
182 CloseServiceHandle(hService);
183
184 if (hManager)
185 CloseServiceHandle(hManager);
186
187 return bResult;
188}
unsigned char BOOLEAN
BOOL ParseFailureArguments(IN LPCTSTR *ServiceArgs, IN INT ArgCount, OUT LPCTSTR *ppServiceName, OUT LPSERVICE_FAILURE_ACTIONS pFailureActions)
Definition: misc.c:259
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
VOID SetFailureUsage(VOID)
Definition: usage.c:249
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SERVICE_START
Definition: winsvc.h:57
#define ChangeServiceConfig2
Definition: winsvc.h:568
#define SERVICE_CHANGE_CONFIG
Definition: winsvc.h:54
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

Referenced by ScControl().