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