ReactOS 0.4.15-dev-8241-g63935f8
domain.c File Reference
#include "samsrv.h"
Include dependency graph for domain.c:

Go to the source code of this file.

Functions

NTSTATUS SampSetAccountNameInDomain (IN PSAM_DB_OBJECT DomainObject, IN LPCWSTR lpContainerName, IN LPCWSTR lpAccountName, IN ULONG ulRelativeId)
 
NTSTATUS SampRemoveAccountNameFromDomain (IN PSAM_DB_OBJECT DomainObject, IN LPCWSTR lpContainerName, IN LPCWSTR lpAccountName)
 
NTSTATUS SampCheckAccountNameInDomain (IN PSAM_DB_OBJECT DomainObject, IN LPCWSTR lpAccountName)
 
NTSTATUS SampRemoveMemberFromAllAliases (IN PSAM_DB_OBJECT DomainObject, IN PRPC_SID MemberSid)
 
NTSTATUS SampCreateAccountSid (IN PSAM_DB_OBJECT DomainObject, IN ULONG ulRelativeId, IN OUT PSID *AccountSid)
 

Function Documentation

◆ SampCheckAccountNameInDomain()

NTSTATUS SampCheckAccountNameInDomain ( IN PSAM_DB_OBJECT  DomainObject,
IN LPCWSTR  lpAccountName 
)

Definition at line 96 of file domain.c.

98{
99 HANDLE AccountKey = NULL;
100 HANDLE NamesKey = NULL;
102
103 TRACE("SampCheckAccountNameInDomain()\n");
104
105 Status = SampRegOpenKey(DomainObject->KeyHandle,
106 L"Aliases",
107 KEY_READ,
108 &AccountKey);
109 if (NT_SUCCESS(Status))
110 {
111 Status = SampRegOpenKey(AccountKey,
112 L"Names",
113 KEY_READ,
114 &NamesKey);
115 if (NT_SUCCESS(Status))
116 {
117 Status = SampRegQueryValue(NamesKey,
119 NULL,
120 NULL,
121 NULL);
122 if (Status == STATUS_SUCCESS)
123 {
124 SampRegCloseKey(&NamesKey);
126 }
129 }
130
131 SampRegCloseKey(&AccountKey);
132 }
133
134 if (!NT_SUCCESS(Status))
135 {
136 TRACE("Checking for alias account failed (Status 0x%08lx)\n", Status);
137 return Status;
138 }
139
140 Status = SampRegOpenKey(DomainObject->KeyHandle,
141 L"Groups",
142 KEY_READ,
143 &AccountKey);
144 if (NT_SUCCESS(Status))
145 {
146 Status = SampRegOpenKey(AccountKey,
147 L"Names",
148 KEY_READ,
149 &NamesKey);
150 if (NT_SUCCESS(Status))
151 {
152 Status = SampRegQueryValue(NamesKey,
154 NULL,
155 NULL,
156 NULL);
157 if (Status == STATUS_SUCCESS)
158 {
159 SampRegCloseKey(&NamesKey);
161 }
164 }
165
166 SampRegCloseKey(&AccountKey);
167 }
168
169 if (!NT_SUCCESS(Status))
170 {
171 TRACE("Checking for group account failed (Status 0x%08lx)\n", Status);
172 return Status;
173 }
174
175 Status = SampRegOpenKey(DomainObject->KeyHandle,
176 L"Users",
177 KEY_READ,
178 &AccountKey);
179 if (NT_SUCCESS(Status))
180 {
181 Status = SampRegOpenKey(AccountKey,
182 L"Names",
183 KEY_READ,
184 &NamesKey);
185 if (NT_SUCCESS(Status))
186 {
187 Status = SampRegQueryValue(NamesKey,
189 NULL,
190 NULL,
191 NULL);
192 if (Status == STATUS_SUCCESS)
193 {
194 SampRegCloseKey(&NamesKey);
196 }
199 }
200
201 SampRegCloseKey(&AccountKey);
202 }
203
204 if (!NT_SUCCESS(Status))
205 {
206 TRACE("Checking for user account failed (Status 0x%08lx)\n", Status);
207 }
208
209 return Status;
210}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS SampRegQueryValue(IN HANDLE KeyHandle, IN LPCWSTR ValueName, OUT PULONG Type OPTIONAL, OUT PVOID Data OPTIONAL, IN OUT PULONG DataLength OPTIONAL)
Definition: registry.c:332
NTSTATUS SampRegCloseKey(IN OUT PHANDLE KeyHandle)
Definition: registry.c:26
NTSTATUS SampRegOpenKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName, IN ACCESS_MASK DesiredAccess, OUT PHANDLE KeyHandle)
Definition: registry.c:158
Status
Definition: gdiplustypes.h:25
#define KEY_READ
Definition: nt_native.h:1023
#define STATUS_ALIAS_EXISTS
Definition: ntstatus.h:576
#define STATUS_USER_EXISTS
Definition: ntstatus.h:335
#define STATUS_GROUP_EXISTS
Definition: ntstatus.h:337
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_In_ LPCSTR lpAccountName
Definition: winbase.h:2741

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserName(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampCreateAccountSid()

NTSTATUS SampCreateAccountSid ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  ulRelativeId,
IN OUT PSID AccountSid 
)

Definition at line 303 of file domain.c.

306{
307 PSID DomainSid = NULL;
308 ULONG Length = 0;
310
311 Status = SampGetObjectAttribute(DomainObject,
312 L"SID",
313 NULL,
314 NULL,
315 &Length);
317 {
318 TRACE("Status 0x%08lx\n", Status);
319 goto done;
320 }
321
322 TRACE("Length: %lu\n", Length);
323
324 DomainSid = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
325 if (DomainSid == NULL)
326 {
328 goto done;
329 }
330
331 Status = SampGetObjectAttribute(DomainObject,
332 L"SID",
333 NULL,
334 DomainSid,
335 &Length);
336 if (!NT_SUCCESS(Status))
337 {
338 TRACE("Status 0x%08lx\n", Status);
339 goto done;
340 }
341
342 *AccountSid = AppendRidToSid(DomainSid,
343 ulRelativeId);
344
345done:
346 if (DomainSid != NULL)
347 RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
348
349 return Status;
350}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
NTSTATUS SampGetObjectAttribute(PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, PULONG AttributeType, LPVOID AttributeData, PULONG AttributeSize)
Definition: database.c:516
static PSID AppendRidToSid(PSID SrcSid, ULONG Rid)
Definition: msv1_0.c:280
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by SamrCreateUser2InDomain(), and SamrCreateUserInDomain().

◆ SampRemoveAccountNameFromDomain()

NTSTATUS SampRemoveAccountNameFromDomain ( IN PSAM_DB_OBJECT  DomainObject,
IN LPCWSTR  lpContainerName,
IN LPCWSTR  lpAccountName 
)

Definition at line 57 of file domain.c.

60{
61 HANDLE ContainerKeyHandle = NULL;
62 HANDLE NamesKeyHandle = NULL;
64
65 TRACE("(%S %S)\n", lpContainerName, lpAccountName);
66
67 /* Open the container key */
68 Status = SampRegOpenKey(DomainObject->KeyHandle,
69 lpContainerName,
71 &ContainerKeyHandle);
72 if (!NT_SUCCESS(Status))
73 return Status;
74
75 /* Open the 'Names' key */
76 Status = SampRegOpenKey(ContainerKeyHandle,
77 L"Names",
79 &NamesKeyHandle);
80 if (!NT_SUCCESS(Status))
81 goto done;
82
83 /* Delete the account name value */
84 Status = SampRegDeleteValue(NamesKeyHandle,
86
87done:
88 SampRegCloseKey(&NamesKeyHandle);
89 SampRegCloseKey(&ContainerKeyHandle);
90
91 return Status;
92}
NTSTATUS SampRegDeleteValue(IN HANDLE KeyHandle, IN LPCWSTR ValueName)
Definition: registry.c:212
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_SET_VALUE
Definition: nt_native.h:1017

Referenced by SampSetAliasName(), SampSetGroupName(), and SampSetUserName().

◆ SampRemoveMemberFromAllAliases()

NTSTATUS SampRemoveMemberFromAllAliases ( IN PSAM_DB_OBJECT  DomainObject,
IN PRPC_SID  MemberSid 
)

Definition at line 214 of file domain.c.

216{
217 WCHAR AliasKeyName[64];
218 LPWSTR MemberSidString = NULL;
219 HANDLE AliasesKey = NULL;
220 HANDLE MembersKey = NULL;
221 HANDLE AliasKey = NULL;
222 ULONG Index;
224
225 TRACE("(%p %p)\n", DomainObject, MemberSid);
226
227 ConvertSidToStringSidW(MemberSid, &MemberSidString);
228 TRACE("Member SID: %S\n", MemberSidString);
229
230 Status = SampRegOpenKey(DomainObject->KeyHandle,
231 L"Aliases",
232 KEY_READ,
233 &AliasesKey);
234 if (NT_SUCCESS(Status))
235 {
236 Index = 0;
237 while (TRUE)
238 {
239 Status = SampRegEnumerateSubKey(AliasesKey,
240 Index,
241 64,
242 AliasKeyName);
243 if (!NT_SUCCESS(Status))
244 {
247 break;
248 }
249
250 TRACE("Alias key name: %S\n", AliasKeyName);
251
252 Status = SampRegOpenKey(AliasesKey,
253 AliasKeyName,
254 KEY_READ,
255 &AliasKey);
256 if (NT_SUCCESS(Status))
257 {
258 Status = SampRegOpenKey(AliasKey,
259 L"Members",
260 KEY_WRITE,
261 &MembersKey);
262 if (NT_SUCCESS(Status))
263 {
264 Status = SampRegDeleteValue(AliasKey,
265 MemberSidString);
266
267 SampRegCloseKey(&MembersKey);
268 }
271
272 SampRegCloseKey(&AliasKey);
273 }
274
275 Index++;
276 }
277
278 Status = SampRegOpenKey(AliasesKey,
279 L"Members",
280 KEY_WRITE,
281 &MembersKey);
282 if (NT_SUCCESS(Status))
283 {
284 Status = SampRegDeleteKey(MembersKey,
285 MemberSidString);
288
289 SampRegCloseKey(&MembersKey);
290 }
291
292 SampRegCloseKey(&AliasesKey);
293 }
294
295 if (MemberSidString != NULL)
296 LocalFree(MemberSidString);
297
298 return Status;
299}
#define TRUE
Definition: types.h:120
BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid)
Definition: security.c:3583
NTSTATUS SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
NTSTATUS SampRegEnumerateSubKey(IN HANDLE KeyHandle, IN ULONG Index, IN ULONG Length, OUT LPWSTR Buffer)
Definition: registry.c:101
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define KEY_WRITE
Definition: nt_native.h:1031
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
_In_ WDFCOLLECTION _In_ ULONG Index
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by SamrRemoveMemberFromForeignDomain().

◆ SampSetAccountNameInDomain()

NTSTATUS SampSetAccountNameInDomain ( IN PSAM_DB_OBJECT  DomainObject,
IN LPCWSTR  lpContainerName,
IN LPCWSTR  lpAccountName,
IN ULONG  ulRelativeId 
)

Definition at line 14 of file domain.c.

18{
19 HANDLE ContainerKeyHandle = NULL;
20 HANDLE NamesKeyHandle = NULL;
22
23 TRACE("SampSetAccountNameInDomain()\n");
24
25 /* Open the container key */
26 Status = SampRegOpenKey(DomainObject->KeyHandle,
27 lpContainerName,
29 &ContainerKeyHandle);
30 if (!NT_SUCCESS(Status))
31 return Status;
32
33 /* Open the 'Names' key */
34 Status = SampRegOpenKey(ContainerKeyHandle,
35 L"Names",
37 &NamesKeyHandle);
38 if (!NT_SUCCESS(Status))
39 goto done;
40
41 /* Set the alias value */
42 Status = SampRegSetValue(NamesKeyHandle,
45 (LPVOID)&ulRelativeId,
46 sizeof(ULONG));
47
48done:
49 SampRegCloseKey(&NamesKeyHandle);
50 SampRegCloseKey(&ContainerKeyHandle);
51
52 return Status;
53}
NTSTATUS SampRegSetValue(HANDLE KeyHandle, LPCWSTR ValueName, ULONG Type, LPVOID Data, ULONG DataLength)
Definition: registry.c:402
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by SampSetAliasName(), SampSetGroupName(), SampSetUserName(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), and SamrCreateUserInDomain().