xref: /reactos/base/system/services/services.h (revision 90831e74)
1 /*
2  * services.h
3  */
4 
5 #ifndef _SERVICES_H
6 #define _SERVICES_H
7 
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 #define WIN32_NO_STATUS
12 #define _INC_WINDOWS
13 #define COM_NO_WINDOWS_H
14 
15 #include <windef.h>
16 #include <winbase.h>
17 #include <winsvc.h>
18 #include <winreg.h>
19 #include <winuser.h>
20 #include <netevent.h>
21 
22 #define NTOS_MODE_USER
23 #include <ndk/setypes.h>
24 #include <ndk/obfuncs.h>
25 #include <ndk/rtlfuncs.h>
26 
27 #include <services/services.h>
28 #include <svcctl_s.h>
29 
30 #include "resource.h"
31 
32 typedef struct _SERVICE_GROUP
33 {
34     LIST_ENTRY GroupListEntry;
35     LPWSTR lpGroupName;
36 
37     DWORD dwRefCount;
38     BOOLEAN ServicesRunning;
39     ULONG TagCount;
40     PULONG TagArray;
41 
42     WCHAR szGroupName[1];
43 } SERVICE_GROUP, *PSERVICE_GROUP;
44 
45 
46 typedef struct _SERVICE_IMAGE
47 {
48     LIST_ENTRY ImageListEntry;
49     LPWSTR pszImagePath;
50     LPWSTR pszAccountName;
51     DWORD dwImageRunCount;
52 
53     HANDLE hControlPipe;
54     HANDLE hProcess;
55     DWORD dwProcessId;
56     HANDLE hToken;
57     HANDLE hProfile;
58 } SERVICE_IMAGE, *PSERVICE_IMAGE;
59 
60 
61 typedef struct _SERVICE
62 {
63     LIST_ENTRY ServiceListEntry;
64     LPWSTR lpServiceName;
65     LPWSTR lpDisplayName;
66     PSERVICE_GROUP lpGroup;
67     PSERVICE_IMAGE lpImage;
68     BOOL bDeleted;
69     DWORD dwResumeCount;
70     LONG RefCount;
71 
72     SERVICE_STATUS Status;
73     DWORD dwStartType;
74     DWORD dwErrorControl;
75     DWORD dwTag;
76 
77     DWORD dwServiceBits;
78     DWORD dwServiceTag;
79 
80     ULONG Flags;
81 
82     PSECURITY_DESCRIPTOR pSecurityDescriptor;
83 
84     BOOLEAN ServiceVisited;
85 
86     WCHAR szServiceName[1];
87 } SERVICE, *PSERVICE;
88 
89 
90 #define LOCK_TAG 0x4C697041 /* 'ApiL' */
91 
92 typedef struct _START_LOCK
93 {
94     DWORD Tag;             /* Must be LOCK_TAG */
95     DWORD TimeWhenLocked;  /* Number of seconds since 1970 */
96     PSID LockOwnerSid;     /* It is NULL if the SCM acquired the lock */
97 } START_LOCK, *PSTART_LOCK;
98 
99 
100 /* VARIABLES ***************************************************************/
101 
102 extern LIST_ENTRY ServiceListHead;
103 extern LIST_ENTRY GroupListHead;
104 extern LIST_ENTRY ImageListHead;
105 extern BOOL ScmInitialize;
106 extern BOOL ScmShutdown;
107 extern BOOL ScmLiveSetup;
108 extern BOOL ScmSetupInProgress;
109 extern PSECURITY_DESCRIPTOR pPipeSD;
110 
111 
112 /* FUNCTIONS ***************************************************************/
113 
114 /* config.c */
115 
116 DWORD ScmOpenServiceKey(LPWSTR lpServiceName,
117                         REGSAM samDesired,
118                         PHKEY phKey);
119 
120 DWORD ScmCreateServiceKey(LPCWSTR lpServiceName,
121                           REGSAM samDesired,
122                           PHKEY phKey);
123 
124 DWORD ScmWriteDependencies(HKEY hServiceKey,
125                            LPCWSTR lpDependencies,
126                            DWORD dwDependenciesLength);
127 
128 DWORD ScmMarkServiceForDelete(PSERVICE pService);
129 BOOL ScmIsDeleteFlagSet(HKEY hServiceKey);
130 
131 DWORD ScmReadString(HKEY hServiceKey,
132                     LPCWSTR lpValueName,
133                     LPWSTR *lpValue);
134 
135 DWORD
136 ScmReadDependencies(HKEY hServiceKey,
137                     LPWSTR *lpDependencies,
138                     DWORD *lpdwDependenciesLength);
139 
140 DWORD
141 ScmSetServicePassword(
142     IN PCWSTR pszServiceName,
143     IN PCWSTR pszPassword);
144 
145 DWORD
146 ScmWriteSecurityDescriptor(
147     _In_ HKEY hServiceKey,
148     _In_ PSECURITY_DESCRIPTOR pSecurityDescriptor);
149 
150 DWORD
151 ScmReadSecurityDescriptor(
152     _In_ HKEY hServiceKey,
153     _Out_ PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
154 
155 DWORD
156 ScmDeleteRegKey(
157     _In_ HKEY hKey,
158     _In_ PCWSTR pszSubKey);
159 
160 DWORD
161 ScmDecryptPassword(
162     _In_ PVOID ContextHandle,
163     _In_ PBYTE pPassword,
164     _In_ DWORD dwPasswordSize,
165     _Out_ PWSTR *pDecryptedPassword);
166 
167 
168 /* controlset.c */
169 
170 DWORD
171 ScmCreateLastKnownGoodControlSet(VOID);
172 
173 DWORD
174 ScmAcceptBoot(VOID);
175 
176 DWORD
177 ScmRunLastKnownGood(VOID);
178 
179 
180 /* database.c */
181 
182 DWORD ScmCreateServiceDatabase(VOID);
183 VOID ScmShutdownServiceDatabase(VOID);
184 VOID ScmGetBootAndSystemDriverState(VOID);
185 VOID ScmAutoStartServices(VOID);
186 VOID ScmAutoShutdownServices(VOID);
187 DWORD ScmStartService(PSERVICE Service,
188                       DWORD argc,
189                       const PCWSTR* argv);
190 
191 DWORD ScmReferenceService(PSERVICE lpService);
192 DWORD ScmDereferenceService(PSERVICE lpService);
193 
194 VOID ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage);
195 PSERVICE ScmGetServiceEntryByName(LPCWSTR lpServiceName);
196 PSERVICE ScmGetServiceEntryByDisplayName(LPCWSTR lpDisplayName);
197 PSERVICE ScmGetServiceEntryByResumeCount(DWORD dwResumeCount);
198 DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
199                                 PSERVICE *lpServiceRecord,
200                                 DWORD dwServiceType,
201                                 DWORD dwStartType);
202 VOID ScmDeleteServiceRecord(PSERVICE lpService);
203 DWORD ScmMarkServiceForDelete(PSERVICE pService);
204 
205 DWORD
206 ScmControlService(
207     _In_ HANDLE hControlPipe,
208     _In_ PCWSTR pServiceName,
209     _In_ DWORD dwControl,
210     _In_ SERVICE_STATUS_HANDLE hServiceStatus);
211 
212 BOOL ScmLockDatabaseExclusive(VOID);
213 BOOL ScmLockDatabaseShared(VOID);
214 VOID ScmUnlockDatabase(VOID);
215 
216 VOID ScmInitNamedPipeCriticalSection(VOID);
217 VOID ScmDeleteNamedPipeCriticalSection(VOID);
218 
219 DWORD ScmGetServiceNameFromTag(PTAG_INFO_NAME_FROM_TAG_IN_PARAMS InParams,
220                                PTAG_INFO_NAME_FROM_TAG_OUT_PARAMS *OutParams);
221 
222 DWORD ScmGenerateServiceTag(PSERVICE lpServiceRecord);
223 
224 /* driver.c */
225 
226 DWORD ScmStartDriver(PSERVICE lpService);
227 DWORD ScmControlDriver(PSERVICE lpService,
228                        DWORD dwControl,
229                        LPSERVICE_STATUS lpServiceStatus);
230 
231 
232 /* groupdb.c */
233 
234 PSERVICE_GROUP
235 ScmGetServiceGroupByName(
236     _In_ LPCWSTR lpGroupName);
237 
238 DWORD ScmCreateGroupList(VOID);
239 DWORD ScmSetServiceGroup(PSERVICE lpService,
240                          LPCWSTR lpGroupName);
241 
242 
243 /* lock.c */
244 
245 DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController,
246                                  OUT LPSC_RPC_LOCK lpLock);
247 DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock);
248 VOID ScmQueryServiceLockStatusW(OUT LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus);
249 VOID ScmQueryServiceLockStatusA(OUT LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus);
250 
251 
252 /* rpcserver.c */
253 
254 VOID ScmStartRpcServer(VOID);
255 
256 
257 /* security.c */
258 
259 DWORD ScmInitializeSecurity(VOID);
260 VOID ScmShutdownSecurity(VOID);
261 
262 DWORD
263 ScmCreateDefaultServiceSD(
264     PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
265 
266 
267 /* services.c */
268 
269 VOID PrintString(LPCSTR fmt, ...);
270 DWORD SetSecurityServicesEvent(VOID);
271 VOID ScmLogEvent(DWORD dwEventId,
272                  WORD wType,
273                  WORD wStrings,
274                  LPCWSTR *lpStrings);
275 VOID ScmWaitForLsa(VOID);
276 
277 #endif /* _SERVICES_H */
278