Merge PR #283 "[USBPORT] Transaction Translator (TT) support bringup"
[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 VOID ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage);
168 PSERVICE ScmGetServiceEntryByName(LPCWSTR lpServiceName);
169 PSERVICE ScmGetServiceEntryByDisplayName(LPCWSTR lpDisplayName);
170 PSERVICE ScmGetServiceEntryByResumeCount(DWORD dwResumeCount);
171 DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
172 PSERVICE *lpServiceRecord,
173 DWORD dwServiceType,
174 DWORD dwStartType);
175 VOID ScmDeleteServiceRecord(PSERVICE lpService);
176 DWORD ScmMarkServiceForDelete(PSERVICE pService);
177
178 DWORD ScmControlService(HANDLE hControlPipe,
179 PWSTR pServiceName,
180 SERVICE_STATUS_HANDLE hServiceStatus,
181 DWORD dwControl);
182
183 BOOL ScmLockDatabaseExclusive(VOID);
184 BOOL ScmLockDatabaseShared(VOID);
185 VOID ScmUnlockDatabase(VOID);
186
187 VOID ScmInitNamedPipeCriticalSection(VOID);
188 VOID ScmDeleteNamedPipeCriticalSection(VOID);
189
190
191 /* driver.c */
192
193 DWORD ScmStartDriver(PSERVICE lpService);
194 DWORD ScmControlDriver(PSERVICE lpService,
195 DWORD dwControl,
196 LPSERVICE_STATUS lpServiceStatus);
197
198
199 /* groupdb.c */
200
201 PSERVICE_GROUP
202 ScmGetServiceGroupByName(
203 _In_ LPCWSTR lpGroupName);
204
205 DWORD ScmCreateGroupList(VOID);
206 DWORD ScmSetServiceGroup(PSERVICE lpService,
207 LPCWSTR lpGroupName);
208
209
210 /* lock.c */
211
212 DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController,
213 OUT LPSC_RPC_LOCK lpLock);
214 DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock);
215 VOID ScmQueryServiceLockStatusW(OUT LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus);
216 VOID ScmQueryServiceLockStatusA(OUT LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus);
217
218
219 /* rpcserver.c */
220
221 VOID ScmStartRpcServer(VOID);
222
223
224 /* security.c */
225
226 DWORD ScmInitializeSecurity(VOID);
227 VOID ScmShutdownSecurity(VOID);
228
229 DWORD
230 ScmCreateDefaultServiceSD(
231 PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
232
233
234 /* services.c */
235
236 VOID PrintString(LPCSTR fmt, ...);
237 VOID ScmLogEvent(DWORD dwEventId,
238 WORD wType,
239 WORD wStrings,
240 LPCWSTR *lpStrings);
241 VOID ScmWaitForLsa(VOID);
242
243 #endif /* _SERVICES_H */