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