ReactOS 0.4.16-dev-122-g325d74c
alias.c
Go to the documentation of this file.
1/*
2 * PROJECT: Local Security Authority Server DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/samsrv/alias.c
5 * PURPOSE: Alias specific helper functions
6 * COPYRIGHT: Copyright 2013 Eric Kohl
7 */
8
9#include "samsrv.h"
10
11/* FUNCTIONS ***************************************************************/
12
15 IN ULONG AliasId,
17 OUT PSAM_DB_OBJECT *AliasObject)
18{
19 WCHAR szRid[9];
20
21 TRACE("(%p %lu %lx %p)\n",
22 DomainObject, AliasId, DesiredAccess, AliasObject);
23
24 /* Convert the RID into a string (hex) */
25 swprintf(szRid, L"%08lX", AliasId);
26
27 /* Create the user object */
28 return SampOpenDbObject(DomainObject,
29 L"Aliases",
30 szRid,
31 AliasId,
34 AliasObject);
35}
36
37
40 IN PRPC_SID MemberId)
41{
42 LPWSTR MemberIdString = NULL;
43 HANDLE MembersKeyHandle = NULL;
44 HANDLE MemberKeyHandle = NULL;
45 ULONG MemberIdLength;
47
48 TRACE("(%p %p)\n",
49 AliasObject, MemberId);
50
51 ConvertSidToStringSidW(MemberId, &MemberIdString);
52 TRACE("Member SID: %S\n", MemberIdString);
53
54 MemberIdLength = RtlLengthSid(MemberId);
55
56 Status = SampRegCreateKey(AliasObject->KeyHandle,
57 L"Members",
59 &MembersKeyHandle);
60 if (!NT_SUCCESS(Status))
61 {
62 TRACE("SampRegCreateKey failed with status 0x%08lx\n", Status);
63 goto done;
64 }
65
66 Status = SampRegSetValue(MembersKeyHandle,
67 MemberIdString,
69 MemberId,
70 MemberIdLength);
71 if (!NT_SUCCESS(Status))
72 {
73 TRACE("SampRegSetValue failed with status 0x%08lx\n", Status);
74 goto done;
75 }
76
77 Status = SampRegCreateKey(AliasObject->MembersKeyHandle,
78 MemberIdString,
80 &MemberKeyHandle);
81 if (!NT_SUCCESS(Status))
82 {
83 TRACE("SampRegCreateKey failed with status 0x%08lx\n", Status);
84 goto done;
85 }
86
87 Status = SampRegSetValue(MemberKeyHandle,
88 AliasObject->Name,
90 MemberId,
91 MemberIdLength);
92 if (!NT_SUCCESS(Status))
93 {
94 TRACE("SampRegSetValue failed with status 0x%08lx\n", Status);
95 goto done;
96 }
97
98done:
99 SampRegCloseKey(&MemberKeyHandle);
100 SampRegCloseKey(&MembersKeyHandle);
101
102 if (MemberIdString != NULL)
103 LocalFree(MemberIdString);
104
105 return Status;
106}
107
108
110NTAPI
112 IN PRPC_SID MemberId)
113{
114 LPWSTR MemberIdString = NULL;
115 HANDLE MembersKeyHandle = NULL;
116 HANDLE MemberKeyHandle = NULL;
117 ULONG ulValueCount;
119
120 TRACE("(%p %p)\n",
121 AliasObject, MemberId);
122
123 ConvertSidToStringSidW(MemberId, &MemberIdString);
124 TRACE("Member SID: %S\n", MemberIdString);
125
126 Status = SampRegOpenKey(AliasObject->MembersKeyHandle,
127 MemberIdString,
129 &MemberKeyHandle);
130 if (!NT_SUCCESS(Status))
131 {
132 TRACE("SampRegOpenKey failed with status 0x%08lx\n", Status);
133 goto done;
134 }
135
136 Status = SampRegDeleteValue(MemberKeyHandle,
137 AliasObject->Name);
138 if (!NT_SUCCESS(Status))
139 {
140 TRACE("SampRegDeleteValue failed with status 0x%08lx\n", Status);
141 goto done;
142 }
143
144 Status = SampRegQueryKeyInfo(MemberKeyHandle,
145 NULL,
146 &ulValueCount);
147 if (!NT_SUCCESS(Status))
148 {
149 TRACE("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
150 goto done;
151 }
152
153 if (ulValueCount == 0)
154 {
155 SampRegCloseKey(&MemberKeyHandle);
156
157 Status = SampRegDeleteKey(AliasObject->MembersKeyHandle,
158 MemberIdString);
159 if (!NT_SUCCESS(Status))
160 {
161 TRACE("SampRegDeleteKey failed with status 0x%08lx\n", Status);
162 goto done;
163 }
164 }
165
166 Status = SampRegOpenKey(AliasObject->KeyHandle,
167 L"Members",
169 &MembersKeyHandle);
170 if (!NT_SUCCESS(Status))
171 {
172 TRACE("SampRegOpenKey failed with status 0x%08lx\n", Status);
173 goto done;
174 }
175
176 Status = SampRegDeleteValue(MembersKeyHandle,
177 MemberIdString);
178 if (!NT_SUCCESS(Status))
179 {
180 TRACE("SampRegDeleteValue failed with status 0x%08lx\n", Status);
181 goto done;
182 }
183
184 Status = SampRegQueryKeyInfo(MembersKeyHandle,
185 NULL,
186 &ulValueCount);
187 if (!NT_SUCCESS(Status))
188 {
189 TRACE("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
190 goto done;
191 }
192
193 if (ulValueCount == 0)
194 {
195 SampRegCloseKey(&MembersKeyHandle);
196
197 Status = SampRegDeleteKey(AliasObject->KeyHandle,
198 L"Members");
199 if (!NT_SUCCESS(Status))
200 {
201 TRACE("SampRegDeleteKey failed with status 0x%08lx\n", Status);
202 goto done;
203 }
204 }
205
206done:
207 SampRegCloseKey(&MemberKeyHandle);
208 SampRegCloseKey(&MembersKeyHandle);
209
210 if (MemberIdString != NULL)
211 LocalFree(MemberIdString);
212
213 return Status;
214}
215
216
219 OUT PULONG MemberCount,
220 OUT PSAMPR_SID_INFORMATION *MemberArray)
221{
222 HANDLE MembersKeyHandle = NULL;
224 ULONG Count = 0;
226 ULONG Index;
228
229 /* Open the members key of the alias object */
230 Status = SampRegOpenKey(AliasObject->KeyHandle,
231 L"Members",
232 KEY_READ,
233 &MembersKeyHandle);
234 if (!NT_SUCCESS(Status))
235 {
236 ERR("SampRegOpenKey failed with status 0x%08lx\n", Status);
237 goto done;
238 }
239
240 /* Get the number of members */
241 Status = SampRegQueryKeyInfo(MembersKeyHandle,
242 NULL,
243 &Count);
244 if (!NT_SUCCESS(Status))
245 {
246 ERR("SampRegQueryKeyInfo failed with status 0x%08lx\n", Status);
247 goto done;
248 }
249
250 /* Allocate the member array */
252 if (Members == NULL)
253 {
255 goto done;
256 }
257
258 /* Enumerate the members */
259 Index = 0;
260 while (TRUE)
261 {
262 /* Get the size of the next SID */
263 DataLength = 0;
264 Status = SampRegEnumerateValue(MembersKeyHandle,
265 Index,
266 NULL,
267 NULL,
268 NULL,
269 NULL,
270 &DataLength);
271 if (!NT_SUCCESS(Status))
272 {
275 break;
276 }
277
278 /* Allocate a buffer for the SID */
280 if (Members[Index].SidPointer == NULL)
281 {
283 goto done;
284 }
285
286 /* Read the SID into the buffer */
287 Status = SampRegEnumerateValue(MembersKeyHandle,
288 Index,
289 NULL,
290 NULL,
291 NULL,
292 (PVOID)Members[Index].SidPointer,
293 &DataLength);
294 if (!NT_SUCCESS(Status))
295 {
296 goto done;
297 }
298
299 Index++;
300 }
301
302 if (NT_SUCCESS(Status))
303 {
304 *MemberCount = Count;
305 *MemberArray = Members;
306 }
307
308done:
309 return Status;
310}
311
312
315{
316 HANDLE MembersKeyHandle = NULL;
317 PSAMPR_SID_INFORMATION MemberArray = NULL;
318 ULONG MemberCount = 0;
319 ULONG Index;
321
322 TRACE("(%p)\n", AliasObject);
323
324 /* Open the members key of the alias object */
325 Status = SampRegOpenKey(AliasObject->KeyHandle,
326 L"Members",
327 KEY_READ,
328 &MembersKeyHandle);
329 if (!NT_SUCCESS(Status))
330 {
331 ERR("SampRegOpenKey failed (Status 0x%08lx)\n", Status);
332 goto done;
333 }
334
335 /* Get a list of all members of the alias */
336 Status = SampGetMembersInAlias(AliasObject,
337 &MemberCount,
338 &MemberArray);
339 if (!NT_SUCCESS(Status))
340 {
341 ERR("SampGetMembersInAlias failed (Status 0x%08lx)\n", Status);
342 goto done;
343 }
344
345 /* Remove all members from the alias */
346 for (Index = 0; Index < MemberCount; Index++)
347 {
348 Status = SampRemoveMemberFromAlias(AliasObject,
349 MemberArray[Index].SidPointer);
350 if (!NT_SUCCESS(Status))
351 goto done;
352 }
353
354done:
355 if (MemberArray != NULL)
356 {
357 for (Index = 0; Index < MemberCount; Index++)
358 {
359 if (MemberArray[Index].SidPointer != NULL)
360 midl_user_free(MemberArray[Index].SidPointer);
361 }
362
363 midl_user_free(MemberArray);
364 }
365
366 SampRegCloseKey(&MembersKeyHandle);
367
368 return Status;
369}
370
371/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid)
Definition: security.c:3583
NTSTATUS SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject, OUT PULONG MemberCount, OUT PSAMPR_SID_INFORMATION *MemberArray)
Definition: alias.c:218
NTSTATUS SampRemoveAllMembersFromAlias(IN PSAM_DB_OBJECT AliasObject)
Definition: alias.c:314
NTSTATUS SampAddMemberToAlias(IN PSAM_DB_OBJECT AliasObject, IN PRPC_SID MemberId)
Definition: alias.c:39
NTSTATUS SampOpenAliasObject(IN PSAM_DB_OBJECT DomainObject, IN ULONG AliasId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *AliasObject)
Definition: alias.c:14
NTSTATUS NTAPI SampRemoveMemberFromAlias(IN PSAM_DB_OBJECT AliasObject, IN PRPC_SID MemberId)
Definition: alias.c:111
NTSTATUS SampOpenDbObject(IN PSAM_DB_OBJECT ParentObject, IN LPWSTR ContainerName, IN LPWSTR ObjectName, IN ULONG RelativeId, IN SAM_DB_OBJECT_TYPE ObjectType, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *DbObject)
Definition: database.c:173
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
NTSTATUS SampRegEnumerateValue(IN HANDLE KeyHandle, IN ULONG Index, OUT LPWSTR Name, IN OUT PULONG NameLength, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
Definition: registry.c:226
NTSTATUS SampRegQueryKeyInfo(IN HANDLE KeyHandle, OUT PULONG SubKeyCount, OUT PULONG ValueCount)
Definition: registry.c:181
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
NTSTATUS SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
NTSTATUS SampRegDeleteValue(IN HANDLE KeyHandle, IN LPCWSTR ValueName)
Definition: registry.c:212
NTSTATUS SampRegCreateKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:42
@ SamDbAliasObject
Definition: samsrv.h:40
#define swprintf
Definition: precomp.h:40
Status
Definition: gdiplustypes.h:25
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
int Count
Definition: noreturn.cpp:7
#define REG_BINARY
Definition: nt_native.h:1496
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_WRITE
Definition: nt_native.h:1031
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
#define L(x)
Definition: ntvdm.h:50
#define midl_user_free
Definition: rpc.h:45
#define midl_user_allocate
Definition: rpc.h:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184