Move group-list related code to a separate file and keep the group name in the group...
[reactos.git] / reactos / subsys / system / services / groupdb.c
1 /*
2 * groupdb.c
3 */
4
5 /* INCLUDES *****************************************************************/
6
7 #include "services.h"
8
9 #define NDEBUG
10 #include <debug.h>
11
12
13 /* GLOBALS *******************************************************************/
14
15 LIST_ENTRY GroupListHead;
16
17
18 /* FUNCTIONS *****************************************************************/
19
20 static NTSTATUS STDCALL
21 CreateGroupOrderListRoutine(PWSTR ValueName,
22 ULONG ValueType,
23 PVOID ValueData,
24 ULONG ValueLength,
25 PVOID Context,
26 PVOID EntryContext)
27 {
28 PSERVICE_GROUP Group;
29
30 DPRINT("CreateGroupOrderListRoutine(%S, %x, %x, %x, %x, %x)\n",
31 ValueName, ValueType, ValueData, ValueLength, Context, EntryContext);
32
33 if (ValueType == REG_BINARY &&
34 ValueData != NULL &&
35 ValueLength >= sizeof(DWORD) &&
36 ValueLength >= (*(PULONG)ValueData + 1) * sizeof(DWORD))
37 {
38 Group = (PSERVICE_GROUP)Context;
39 Group->TagCount = ((PULONG)ValueData)[0];
40 if (Group->TagCount > 0)
41 {
42 if (ValueLength >= (Group->TagCount + 1) * sizeof(DWORD))
43 {
44 Group->TagArray = (PULONG)HeapAlloc(GetProcessHeap(),
45 HEAP_ZERO_MEMORY,
46 Group->TagCount * sizeof(DWORD));
47 if (Group->TagArray == NULL)
48 {
49 Group->TagCount = 0;
50 return STATUS_INSUFFICIENT_RESOURCES;
51 }
52
53 RtlCopyMemory(Group->TagArray,
54 (PULONG)ValueData + 1,
55 Group->TagCount * sizeof(DWORD));
56 }
57 else
58 {
59 Group->TagCount = 0;
60 return STATUS_UNSUCCESSFUL;
61 }
62 }
63 }
64
65 return STATUS_SUCCESS;
66 }
67
68
69 static NTSTATUS STDCALL
70 CreateGroupListRoutine(PWSTR ValueName,
71 ULONG ValueType,
72 PVOID ValueData,
73 ULONG ValueLength,
74 PVOID Context,
75 PVOID EntryContext)
76 {
77 PSERVICE_GROUP Group;
78 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
79 NTSTATUS Status;
80
81 if (ValueType == REG_SZ)
82 {
83 DPRINT("Data: '%S'\n", (PWCHAR)ValueData);
84
85 Group = (PSERVICE_GROUP)HeapAlloc(GetProcessHeap(),
86 HEAP_ZERO_MEMORY,
87 sizeof(SERVICE_GROUP) + (wcslen(ValueData) * sizeof(WCHAR)));
88 if (Group == NULL)
89 {
90 return STATUS_INSUFFICIENT_RESOURCES;
91 }
92
93 wcscpy(Group->szGroupName, ValueData);
94 Group->lpGroupName = Group->szGroupName;
95 Group->dwRefCount = (DWORD)-1;
96
97 RtlZeroMemory(&QueryTable, sizeof(QueryTable));
98 QueryTable[0].Name = (PWSTR)ValueData;
99 QueryTable[0].QueryRoutine = CreateGroupOrderListRoutine;
100
101 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
102 L"GroupOrderList",
103 QueryTable,
104 (PVOID)Group,
105 NULL);
106 DPRINT("%x %d %S\n", Status, Group->TagCount, (PWSTR)ValueData);
107
108 InsertTailList(&GroupListHead,
109 &Group->GroupListEntry);
110 }
111
112 return STATUS_SUCCESS;
113 }
114
115
116 DWORD
117 ScmCreateGroupList(VOID)
118 {
119 RTL_QUERY_REGISTRY_TABLE QueryTable[2];
120 NTSTATUS Status;
121
122 InitializeListHead(&GroupListHead);
123
124 /* Build group order list */
125 RtlZeroMemory(&QueryTable,
126 sizeof(QueryTable));
127
128 QueryTable[0].Name = L"List";
129 QueryTable[0].QueryRoutine = CreateGroupListRoutine;
130
131 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL,
132 L"ServiceGroupOrder",
133 QueryTable,
134 NULL,
135 NULL);
136
137 return RtlNtStatusToDosError(Status);
138 }
139
140 /* EOF */