ReactOS 0.4.15-dev-5672-gf73ac17
groupdb.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Service Control Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/services/groupdb.c
5 * PURPOSE: Service group control interface
6 * COPYRIGHT: Copyright 2005 Eric Kohl
7 *
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include "services.h"
13
14#define NDEBUG
15#include <debug.h>
16
17/* GLOBALS *******************************************************************/
18
21
22
23/* FUNCTIONS *****************************************************************/
24
27 _In_ LPCWSTR lpGroupName)
28{
29 PLIST_ENTRY GroupEntry;
30 PSERVICE_GROUP lpGroup;
31
32 DPRINT("ScmGetServiceGroupByName(%S)\n", lpGroupName);
33
34 GroupEntry = GroupListHead.Flink;
35 while (GroupEntry != &GroupListHead)
36 {
37 lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
38
39 if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
40 return lpGroup;
41
42 GroupEntry = GroupEntry->Flink;
43 }
44
45 GroupEntry = UnknownGroupListHead.Flink;
46 while (GroupEntry != &UnknownGroupListHead)
47 {
48 lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
49
50 if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
51 return lpGroup;
52
53 GroupEntry = GroupEntry->Flink;
54 }
55
56 return NULL;
57}
58
59
62 LPCWSTR lpGroupName)
63{
64 PLIST_ENTRY GroupEntry;
65 PSERVICE_GROUP lpGroup;
66
67 DPRINT("ScmSetServiceGroup(%S)\n", lpGroupName);
68
69 if (lpService->lpGroup != NULL)
70 {
71 ASSERT(lpService->lpGroup->dwRefCount != 0);
72 ASSERT(lpService->lpGroup->dwRefCount == (DWORD)-1 ||
73 lpService->lpGroup->dwRefCount < 10000);
74 if (lpService->lpGroup->dwRefCount != (DWORD)-1)
75 {
76 lpService->lpGroup->dwRefCount--;
77 if (lpService->lpGroup->dwRefCount == 0)
78 {
79 ASSERT(lpService->lpGroup->TagCount == 0);
80 ASSERT(lpService->lpGroup->TagArray == NULL);
82 HeapFree(GetProcessHeap(), 0, lpService->lpGroup);
83 lpService->lpGroup = NULL;
84 }
85 }
86 }
87
88 if (lpGroupName == NULL)
89 return ERROR_SUCCESS;
90
91 GroupEntry = GroupListHead.Flink;
92 while (GroupEntry != &GroupListHead)
93 {
94 lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
95
96 if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
97 {
98 lpService->lpGroup = lpGroup;
99 return ERROR_SUCCESS;
100 }
101
102 GroupEntry = GroupEntry->Flink;
103 }
104
105 GroupEntry = UnknownGroupListHead.Flink;
106 while (GroupEntry != &UnknownGroupListHead)
107 {
108 lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
109
110 if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
111 {
112 lpGroup->dwRefCount++;
113 lpService->lpGroup = lpGroup;
114 return ERROR_SUCCESS;
115 }
116
117 GroupEntry = GroupEntry->Flink;
118 }
119
122 sizeof(SERVICE_GROUP) + ((wcslen(lpGroupName) + 1)* sizeof(WCHAR)));
123 if (lpGroup == NULL)
125
126 wcscpy(lpGroup->szGroupName, lpGroupName);
127 lpGroup->lpGroupName = lpGroup->szGroupName;
128 lpGroup->dwRefCount = 1;
129 lpService->lpGroup = lpGroup;
130
132 &lpGroup->GroupListEntry);
133
134 return ERROR_SUCCESS;
135}
136
137
138static NTSTATUS WINAPI
145{
147
148 DPRINT("CreateGroupOrderListRoutine(%S, %x, %p, %x, %p, %p)\n",
150
151 if (ValueType == REG_BINARY &&
152 ValueData != NULL &&
153 ValueLength >= sizeof(DWORD) &&
154 ValueLength >= (*(PULONG)ValueData + 1) * sizeof(DWORD))
155 {
157 Group->TagCount = ((PULONG)ValueData)[0];
158 if (Group->TagCount > 0)
159 {
160 if (ValueLength >= (Group->TagCount + 1) * sizeof(DWORD))
161 {
162 Group->TagArray = (PULONG)HeapAlloc(GetProcessHeap(),
164 Group->TagCount * sizeof(DWORD));
165 if (Group->TagArray == NULL)
166 {
167 Group->TagCount = 0;
169 }
170
171 RtlCopyMemory(Group->TagArray,
172 (PULONG)ValueData + 1,
173 Group->TagCount * sizeof(DWORD));
174 }
175 else
176 {
177 Group->TagCount = 0;
178 return STATUS_UNSUCCESSFUL;
179 }
180 }
181 }
182
183 return STATUS_SUCCESS;
184}
185
186
187static NTSTATUS WINAPI
194{
198
199 if (ValueType == REG_SZ)
200 {
201 DPRINT("Data: '%S'\n", (PWCHAR)ValueData);
202
205 sizeof(SERVICE_GROUP) + ((wcslen((const wchar_t*) ValueData) + 1) * sizeof(WCHAR)));
206 if (Group == NULL)
207 {
209 }
210
211 wcscpy(Group->szGroupName, (const wchar_t*) ValueData);
212 Group->lpGroupName = Group->szGroupName;
213 Group->dwRefCount = (DWORD)-1;
214
218
220 L"GroupOrderList",
222 (PVOID)Group,
223 NULL);
224 DPRINT("%x %lu %S\n", Status, Group->TagCount, (PWSTR)ValueData);
225
227 &Group->GroupListEntry);
228 }
229
230 return STATUS_SUCCESS;
231}
232
233
234DWORD
236{
239
242
243 /* Build group order list */
245 sizeof(QueryTable));
246
247 QueryTable[0].Name = L"List";
249
251 L"ServiceGroupOrder",
253 NULL,
254 NULL);
255
257}
258
259/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
struct _SERVICE_GROUP * PSERVICE_GROUP
struct _SERVICE_GROUP SERVICE_GROUP
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
LIST_ENTRY UnknownGroupListHead
Definition: groupdb.c:20
static NTSTATUS WINAPI CreateGroupListRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: groupdb.c:188
DWORD ScmCreateGroupList(VOID)
Definition: groupdb.c:235
PSERVICE_GROUP ScmGetServiceGroupByName(_In_ LPCWSTR lpGroupName)
Definition: groupdb.c:26
static NTSTATUS WINAPI CreateGroupOrderListRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: groupdb.c:139
DWORD ScmSetServiceGroup(PSERVICE lpService, LPCWSTR lpGroupName)
Definition: groupdb.c:61
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define REG_SZ
Definition: layer.c:22
#define ASSERT(a)
Definition: mode.c:44
#define _In_
Definition: ms_sal.h:308
_In_opt_ PSID Group
Definition: rtlfuncs.h:1646
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4196
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4197
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
#define REG_BINARY
Definition: nt_native.h:1496
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
DWORD dwRefCount
Definition: services.h:35
WCHAR szGroupName[1]
Definition: services.h:40
PULONG TagArray
Definition: services.h:38
LIST_ENTRY GroupListEntry
Definition: services.h:32
ULONG TagCount
Definition: services.h:37
LPWSTR lpGroupName
Definition: services.h:33
PSERVICE_GROUP lpGroup
Definition: services.h:64
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG ValueLength
Definition: wdfregistry.h:275
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185