ReactOS 0.4.17-dev-1281-g065abb3
user.c File Reference
#include "samsrv.h"
Include dependency graph for user.c:

Go to the source code of this file.

Functions

NTSTATUS SampOpenUserObject (IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *UserObject)
 
NTSTATUS SampAddGroupMembershipToUser (IN PSAM_DB_OBJECT UserObject, IN ULONG GroupId, IN ULONG Attributes)
 
NTSTATUS SampRemoveGroupMembershipFromUser (IN PSAM_DB_OBJECT UserObject, IN ULONG GroupId)
 
NTSTATUS SampGetUserGroupAttributes (IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ULONG GroupId, OUT PULONG GroupAttributes)
 
NTSTATUS SampSetUserGroupAttributes (IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ULONG GroupId, IN ULONG GroupAttributes)
 
NTSTATUS SampRemoveUserFromAllGroups (IN PSAM_DB_OBJECT UserObject)
 
static NTSTATUS SampRemoveUserFromDomainAliases (_In_ HANDLE DomainKeyHandle, _In_ PSAM_DB_OBJECT UserObject, _In_ PWSTR UserSidString)
 
NTSTATUS SampRemoveUserFromAllAliases (_In_ PSAM_DB_OBJECT UserObject)
 
NTSTATUS SampSetUserPassword (IN PSAM_DB_OBJECT UserObject, IN PENCRYPTED_NT_OWF_PASSWORD NtPassword, IN BOOLEAN NtPasswordPresent, IN PENCRYPTED_LM_OWF_PASSWORD LmPassword, IN BOOLEAN LmPasswordPresent)
 
NTSTATUS SampGetLogonHoursAttribute (IN PSAM_DB_OBJECT UserObject, IN OUT PSAMPR_LOGON_HOURS LogonHours)
 
NTSTATUS SampSetLogonHoursAttribute (IN PSAM_DB_OBJECT UserObject, IN PSAMPR_LOGON_HOURS LogonHours)
 

Function Documentation

◆ SampAddGroupMembershipToUser()

NTSTATUS SampAddGroupMembershipToUser ( IN PSAM_DB_OBJECT  UserObject,
IN ULONG  GroupId,
IN ULONG  Attributes 
)

Definition at line 39 of file user.c.

42{
43 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
44 ULONG GroupsCount = 0;
45 ULONG Length = 0;
46 ULONG i;
48
49 TRACE("(%p %lu %lx)\n",
50 UserObject, GroupId, Attributes);
51
52 Status = SampGetObjectAttribute(UserObject,
53 L"Groups",
54 NULL,
55 NULL,
56 &Length);
58 goto done;
59
60 GroupsBuffer = midl_user_allocate(Length + sizeof(GROUP_MEMBERSHIP));
61 if (GroupsBuffer == NULL)
62 {
64 goto done;
65 }
66
68 {
69 Status = SampGetObjectAttribute(UserObject,
70 L"Groups",
71 NULL,
72 GroupsBuffer,
73 &Length);
74 if (!NT_SUCCESS(Status))
75 goto done;
76
77 GroupsCount = Length / sizeof(GROUP_MEMBERSHIP);
78 }
79
80 for (i = 0; i < GroupsCount; i++)
81 {
82 if (GroupsBuffer[i].RelativeId == GroupId)
83 {
85 goto done;
86 }
87 }
88
89 GroupsBuffer[GroupsCount].RelativeId = GroupId;
90 GroupsBuffer[GroupsCount].Attributes = Attributes;
91 Length += sizeof(GROUP_MEMBERSHIP);
92
93 Status = SampSetObjectAttribute(UserObject,
94 L"Groups",
96 GroupsBuffer,
97 Length);
98
99done:
100 if (GroupsBuffer != NULL)
101 midl_user_free(GroupsBuffer);
102
103 return Status;
104}
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG Attributes
Definition: dispmprt.h:1077
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS SampGetObjectAttribute(PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, PULONG AttributeType, LPVOID AttributeData, PULONG AttributeSize)
Definition: database.c:516
NTSTATUS SampSetObjectAttribute(PSAM_DB_OBJECT DbObject, LPWSTR AttributeName, ULONG AttributeType, LPVOID AttributeData, ULONG AttributeSize)
Definition: database.c:501
#define L(x)
Definition: resources.c:13
Status
Definition: gdiplustypes.h:24
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define REG_BINARY
Definition: nt_native.h:1499
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
struct _GROUP_MEMBERSHIP GROUP_MEMBERSHIP
#define STATUS_MEMBER_IN_GROUP
Definition: ntstatus.h:433
#define midl_user_free
Definition: rpc.h:41
#define midl_user_allocate
Definition: rpc.h:40
#define TRACE(s)
Definition: solgame.cpp:4
ULONG RelativeId
Definition: ntsam.h:496
ULONG Attributes
Definition: ntsam.h:497
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by SamrAddMemberToGroup().

◆ SampGetLogonHoursAttribute()

NTSTATUS SampGetLogonHoursAttribute ( IN PSAM_DB_OBJECT  UserObject,
IN OUT PSAMPR_LOGON_HOURS  LogonHours 
)

Definition at line 810 of file user.c.

812{
813 PUCHAR RawBuffer = NULL;
814 ULONG Length = 0;
817
818 Status = SampGetObjectAttribute(UserObject,
819 L"LogonHours",
820 NULL,
821 NULL,
822 &Length);
824 {
825 TRACE("SampGetObjectAttribute failed (Status 0x%08lx)\n", Status);
826 return Status;
827 }
828
830
831 if (Length == 0)
832 {
833 LogonHours->UnitsPerWeek = 0;
834 LogonHours->LogonHours = NULL;
835 }
836 else
837 {
838 RawBuffer = midl_user_allocate(Length);
839 if (RawBuffer == NULL)
840 {
842 goto done;
843 }
844
845 Status = SampGetObjectAttribute(UserObject,
846 L"LogonHours",
847 NULL,
848 (PVOID)RawBuffer,
849 &Length);
850 if (!NT_SUCCESS(Status))
851 goto done;
852
853 LogonHours->UnitsPerWeek = *((PUSHORT)RawBuffer);
854
855 BufferLength = (((ULONG)LogonHours->UnitsPerWeek) + 7) / 8;
856
857 LogonHours->LogonHours = midl_user_allocate(BufferLength);
858 if (LogonHours->LogonHours == NULL)
859 {
860 TRACE("Failed to allocate LogonHours buffer!\n");
862 goto done;
863 }
864
865 memcpy(LogonHours->LogonHours,
866 &(RawBuffer[2]),
868 }
869
870done:
871
872 if (RawBuffer != NULL)
873 midl_user_free(RawBuffer);
874
875 return Status;
876}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777

Referenced by SampQueryUserAccount(), SampQueryUserAll(), SampQueryUserLogon(), and SampQueryUserLogonHours().

◆ SampGetUserGroupAttributes()

NTSTATUS SampGetUserGroupAttributes ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  UserId,
IN ULONG  GroupId,
OUT PULONG  GroupAttributes 
)

Definition at line 183 of file user.c.

187{
188 PSAM_DB_OBJECT UserObject = NULL;
189 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
190 ULONG Length = 0;
191 ULONG i;
193
194 Status = SampOpenUserObject(DomainObject,
195 UserId,
196 0,
197 &UserObject);
198 if (!NT_SUCCESS(Status))
199 {
200 return Status;
201 }
202
203 SampGetObjectAttribute(UserObject,
204 L"Groups",
205 NULL,
206 NULL,
207 &Length);
208
209 if (Length == 0)
210 return STATUS_UNSUCCESSFUL; /* FIXME */
211
212 GroupsBuffer = midl_user_allocate(Length);
213 if (GroupsBuffer == NULL)
214 {
216 goto done;
217 }
218
219 Status = SampGetObjectAttribute(UserObject,
220 L"Groups",
221 NULL,
222 GroupsBuffer,
223 &Length);
224 if (!NT_SUCCESS(Status))
225 goto done;
226
227 for (i = 0; i < (Length / sizeof(GROUP_MEMBERSHIP)); i++)
228 {
229 if (GroupsBuffer[i].RelativeId == GroupId)
230 {
231 *GroupAttributes = GroupsBuffer[i].Attributes;
232 goto done;
233 }
234 }
235
236done:
237 if (GroupsBuffer != NULL)
238 midl_user_free(GroupsBuffer);
239
240 if (UserObject != NULL)
241 SampCloseDbObject(UserObject);
242
243 return Status;
244}
NTSTATUS SampCloseDbObject(PSAM_DB_OBJECT DbObject)
Definition: database.c:346
NTSTATUS SampOpenUserObject(IN PSAM_DB_OBJECT DomainObject, IN ULONG UserId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *UserObject)
Definition: user.c:14
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by SamrGetMembersInGroup().

◆ SampOpenUserObject()

NTSTATUS SampOpenUserObject ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  UserId,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT *  UserObject 
)

Definition at line 14 of file user.c.

18{
19 WCHAR szRid[9];
20
21 TRACE("(%p %lu %lx %p)\n",
22 DomainObject, UserId, DesiredAccess, UserObject);
23
24 /* Convert the RID into a string (hex) */
25 _swprintf(szRid, L"%08lX", UserId);
26
27 /* Create the user object */
28 return SampOpenDbObject(DomainObject,
29 L"Users",
30 szRid,
31 UserId,
34 UserObject);
35}
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
@ SamDbUserObject
Definition: samsrv.h:42
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
short WCHAR
Definition: pedump.c:58
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664

Referenced by SampGetUserGroupAttributes(), SampSetUserGroupAttributes(), SamrAddMemberToGroup(), and SamrRemoveMemberFromGroup().

◆ SampRemoveGroupMembershipFromUser()

NTSTATUS SampRemoveGroupMembershipFromUser ( IN PSAM_DB_OBJECT  UserObject,
IN ULONG  GroupId 
)

Definition at line 108 of file user.c.

110{
111 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
112 ULONG GroupsCount = 0;
113 ULONG Length = 0;
114 ULONG i;
116
117 TRACE("(%p %lu)\n",
118 UserObject, GroupId);
119
120 SampGetObjectAttribute(UserObject,
121 L"Groups",
122 NULL,
123 NULL,
124 &Length);
125
126 if (Length == 0)
128
129 GroupsBuffer = midl_user_allocate(Length);
130 if (GroupsBuffer == NULL)
131 {
133 goto done;
134 }
135
136 Status = SampGetObjectAttribute(UserObject,
137 L"Groups",
138 NULL,
139 GroupsBuffer,
140 &Length);
141 if (!NT_SUCCESS(Status))
142 goto done;
143
145
146 GroupsCount = Length / sizeof(GROUP_MEMBERSHIP);
147 for (i = 0; i < GroupsCount; i++)
148 {
149 if (GroupsBuffer[i].RelativeId == GroupId)
150 {
151 Length -= sizeof(GROUP_MEMBERSHIP);
153
154 if (GroupsCount - i - 1 > 0)
155 {
156 CopyMemory(&GroupsBuffer[i],
157 &GroupsBuffer[i + 1],
158 (GroupsCount - i - 1) * sizeof(GROUP_MEMBERSHIP));
159 }
160
161 break;
162 }
163 }
164
165 if (!NT_SUCCESS(Status))
166 goto done;
167
168 Status = SampSetObjectAttribute(UserObject,
169 L"Groups",
171 GroupsBuffer,
172 Length);
173
174done:
175 if (GroupsBuffer != NULL)
176 midl_user_free(GroupsBuffer);
177
178 return Status;
179}
#define CopyMemory
Definition: minwinbase.h:29
#define STATUS_MEMBER_NOT_IN_GROUP
Definition: ntstatus.h:434

Referenced by SamrRemoveMemberFromGroup().

◆ SampRemoveUserFromAllAliases()

NTSTATUS SampRemoveUserFromAllAliases ( _In_ PSAM_DB_OBJECT  UserObject)

Definition at line 499 of file user.c.

501{
502 PSAM_DB_OBJECT DomainObject;
503 PSID UserSid = NULL;
504 LPWSTR UserSidString = NULL;
505 WCHAR DomainKeyName[64];
506 HANDLE DomainsKeyHandle = NULL, DomainKeyHandle = NULL;
507 ULONG DomainEnumIndex;
509
510 TRACE("SampRemoveUserFromAllAliases(%p)\n", UserObject);
511
512 DomainObject = UserObject->ParentObject;
513 if (DomainObject == NULL || DomainObject->ObjectType != SamDbDomainObject)
514 {
515 ERR("Invalid domain object!\n");
516 return STATUS_UNSUCCESSFUL;
517 }
518
519 Status = SampCreateAccountSid(DomainObject,
520 UserObject->RelativeId,
521 &UserSid);
522 if (!NT_SUCCESS(Status))
523 {
524 ERR("SampCreateAccountSid() failed (Status 0x%08lx)\n", Status);
525 return Status;
526 }
527
528 ConvertSidToStringSidW(UserSid, &UserSidString);
529 TRACE("User SID: %S\n", UserSidString);
530
531 Status = SampRegOpenKey(NULL, //SamKeyHandle,
532 L"\\Registry\\Machine\\SAM\\SAM\\Domains", //L"SAM\\Domains",
534 &DomainsKeyHandle);
535 if (!NT_SUCCESS(Status))
536 {
537 ERR("SampRegOpenKey() failed (Status 0x%08lx)\n", Status);
538 goto done;
539 }
540
541 DomainEnumIndex = 0;
542 while (TRUE)
543 {
544 Status = SampRegEnumerateSubKey(DomainsKeyHandle,
545 DomainEnumIndex,
546 64 * sizeof(WCHAR),
547 DomainKeyName);
548 if (!NT_SUCCESS(Status))
549 {
551 break;
552 }
553
554 TRACE("DomainEnumIndex: %lu\n", DomainEnumIndex);
555 TRACE("Domain key name: %S\n", DomainKeyName);
556
557 Status = SampRegOpenKey(DomainsKeyHandle,
558 DomainKeyName,
559 KEY_READ,
560 &DomainKeyHandle);
561 if (NT_SUCCESS(Status))
562 {
563 Status = SampRemoveUserFromDomainAliases(DomainKeyHandle,
564 UserObject,
565 UserSidString);
566 SampRegCloseKey(&DomainKeyHandle);
567
568 if (!NT_SUCCESS(Status))
569 break;
570 }
571
572 DomainEnumIndex++;
573 }
574
575done:
576 if (DomainsKeyHandle != NULL)
577 SampRegCloseKey(&DomainsKeyHandle);
578
579 if (UserSidString != NULL)
580 LocalFree(UserSidString);
581
582 if (UserSid != NULL)
583 RtlFreeHeap(RtlGetProcessHeap(), 0, UserSid);
584
585 return Status;
586}
#define ERR(fmt,...)
Definition: precomp.h:57
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
#define TRUE
Definition: types.h:120
BOOL WINAPI ConvertSidToStringSidW(PSID Sid, LPWSTR *StringSid)
Definition: security.c:3583
NTSTATUS SampCreateAccountSid(IN PSAM_DB_OBJECT DomainObject, IN ULONG ulRelativeId, IN OUT PSID *AccountSid)
Definition: domain.c:303
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
NTSTATUS SampRegEnumerateSubKey(IN HANDLE KeyHandle, IN ULONG Index, IN ULONG Length, OUT LPWSTR Buffer)
Definition: registry.c:101
@ SamDbDomainObject
Definition: samsrv.h:39
static NTSTATUS SampRemoveUserFromDomainAliases(_In_ HANDLE DomainKeyHandle, _In_ PSAM_DB_OBJECT UserObject, _In_ PWSTR UserSidString)
Definition: user.c:392
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define KEY_READ
Definition: nt_native.h:1026
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1022
SAM_DB_OBJECT_TYPE ObjectType
Definition: samsrv.h:48
struct _SAM_DB_OBJECT * ParentObject
Definition: samsrv.h:56
uint16_t * LPWSTR
Definition: typedefs.h:56

◆ SampRemoveUserFromAllGroups()

NTSTATUS SampRemoveUserFromAllGroups ( IN PSAM_DB_OBJECT  UserObject)

Definition at line 319 of file user.c.

320{
321 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
322 PSAM_DB_OBJECT GroupObject;
323 ULONG Length = 0;
324 ULONG i;
326
327 SampGetObjectAttribute(UserObject,
328 L"Groups",
329 NULL,
330 NULL,
331 &Length);
332
333 if (Length == 0)
334 return STATUS_SUCCESS;
335
336 GroupsBuffer = midl_user_allocate(Length);
337 if (GroupsBuffer == NULL)
338 {
340 goto done;
341 }
342
343 Status = SampGetObjectAttribute(UserObject,
344 L"Groups",
345 NULL,
346 GroupsBuffer,
347 &Length);
348 if (!NT_SUCCESS(Status))
349 goto done;
350
351 for (i = 0; i < (Length / sizeof(GROUP_MEMBERSHIP)); i++)
352 {
353 Status = SampOpenGroupObject(UserObject->ParentObject,
354 GroupsBuffer[i].RelativeId,
355 0,
356 &GroupObject);
357 if (!NT_SUCCESS(Status))
358 {
359 goto done;
360 }
361
362 Status = SampRemoveMemberFromGroup(GroupObject,
363 UserObject->RelativeId);
366
367 SampCloseDbObject(GroupObject);
368
369 if (!NT_SUCCESS(Status))
370 {
371 goto done;
372 }
373 }
374
375 /* Remove all groups from the Groups attribute */
376 Status = SampSetObjectAttribute(UserObject,
377 L"Groups",
379 NULL,
380 0);
381
382done:
383 if (GroupsBuffer != NULL)
384 midl_user_free(GroupsBuffer);
385
386 return Status;
387}
NTSTATUS SampRemoveMemberFromGroup(IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
Definition: group.c:103
NTSTATUS SampOpenGroupObject(IN PSAM_DB_OBJECT DomainObject, IN ULONG GroupId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *GroupObject)
Definition: group.c:14

Referenced by SamrDeleteUser().

◆ SampRemoveUserFromDomainAliases()

static NTSTATUS SampRemoveUserFromDomainAliases ( _In_ HANDLE  DomainKeyHandle,
_In_ PSAM_DB_OBJECT  UserObject,
_In_ PWSTR  UserSidString 
)
static

Definition at line 392 of file user.c.

396{
397 WCHAR UserIdBuffer[64];
399 HANDLE AliasesKeyHandle = NULL, AliasesMembersKeyHandle = NULL;
400 HANDLE UserSidKeyHandle = NULL, UserIdKeyHandle, UserIdMembersKeyHandle;
402
403 TRACE("SampRemoveUserFromDomainAliases(%p %p)\n", DomainKeyHandle, UserObject);
404
405 Status = SampRegOpenKey(DomainKeyHandle,
406 L"Aliases",
407 KEY_READ,
408 &AliasesKeyHandle);
409 if (!NT_SUCCESS(Status))
410 {
411 ERR("Failed to open the Aliases key (Status %08lX)\n", Status);
412 goto done;
413 }
414
415 Status = SampRegOpenKey(AliasesKeyHandle,
416 L"Members",
418 &AliasesMembersKeyHandle);
419 if (!NT_SUCCESS(Status))
420 {
421 ERR("Failed to open the Members key (Status %08lX)\n", Status);
422 goto done;
423 }
424
425 Status = SampRegOpenKey(AliasesMembersKeyHandle,
426 UserSidString,
427 KEY_READ,
428 &UserSidKeyHandle);
429 if (NT_SUCCESS(Status))
430 {
431 TRACE("Opend the key for the users SID (%S)!\n", UserSidString);
432 Index = 0;
433 for (;;)
434 {
435 NameLength = sizeof(UserIdBuffer);
436 Status = SampRegEnumerateValue(UserSidKeyHandle,
437 Index,
438 UserIdBuffer,
439 &NameLength,
440 NULL,
441 NULL,
442 NULL);
443 if (!NT_SUCCESS(Status))
444 {
447 break;
448 }
449
450 TRACE("User ID: %S\n", UserIdBuffer);
451
452 Status = SampRegOpenKey(AliasesKeyHandle,
453 UserIdBuffer,
454 KEY_READ,
455 &UserIdKeyHandle);
456 if (NT_SUCCESS(Status))
457 {
458 Status = SampRegOpenKey(UserIdKeyHandle,
459 L"Members",
461 &UserIdMembersKeyHandle);
462 if (NT_SUCCESS(Status))
463 {
464 Status = SampRegDeleteValue(UserIdMembersKeyHandle,
465 UserSidString);
466 SampRegCloseKey(&UserIdMembersKeyHandle);
467
468 if (!NT_SUCCESS(Status))
469 break;
470 }
471
472 SampRegCloseKey(&UserIdKeyHandle);
473 }
474
475 Index++;
476 }
477
478 SampRegCloseKey(&UserSidKeyHandle);
479 }
480 else
481 {
482 TRACE("No key for the user SID (%S) here!\n", UserSidString);
484 goto done;
485 }
486
487 Status = SampRegDeleteKey(AliasesMembersKeyHandle,
488 UserSidString);
489
490done:
491 SampRegCloseKey(&AliasesMembersKeyHandle);
492 SampRegCloseKey(&AliasesKeyHandle);
493
494 return Status;
495}
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 SampRegDeleteKey(IN HANDLE ParentKeyHandle, IN LPCWSTR KeyName)
Definition: registry.c:71
NTSTATUS SampRegDeleteValue(IN HANDLE KeyHandle, IN LPCWSTR ValueName)
Definition: registry.c:212
#define KEY_WRITE
Definition: nt_native.h:1034
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:285
Input NameLength
Definition: portacpi.cpp:298
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by SampRemoveUserFromAllAliases().

◆ SampSetLogonHoursAttribute()

NTSTATUS SampSetLogonHoursAttribute ( IN PSAM_DB_OBJECT  UserObject,
IN PSAMPR_LOGON_HOURS  LogonHours 
)

Definition at line 880 of file user.c.

882{
883 PUCHAR RawBuffer = NULL;
885 ULONG Length = 0;
887
888 if (LogonHours->UnitsPerWeek > 0)
889 {
890 BufferLength = (((ULONG)LogonHours->UnitsPerWeek) + 7) / 8;
891
892 Length = BufferLength + sizeof(USHORT);
893
894 RawBuffer = midl_user_allocate(Length);
895 if (RawBuffer == NULL)
896 {
898 goto done;
899 }
900
901 *((PUSHORT)RawBuffer) = LogonHours->UnitsPerWeek;
902
903 memcpy(&(RawBuffer[2]),
904 LogonHours->LogonHours,
906 }
907
908 Status = SampSetObjectAttribute(UserObject,
909 L"LogonHours",
911 RawBuffer,
912 Length);
913
914done:
915 if (RawBuffer != NULL)
916 midl_user_free(RawBuffer);
917
918 return Status;
919}
unsigned short USHORT
Definition: pedump.c:61

Referenced by SampSetUserAll(), and SamrSetInformationUser2().

◆ SampSetUserGroupAttributes()

NTSTATUS SampSetUserGroupAttributes ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  UserId,
IN ULONG  GroupId,
IN ULONG  GroupAttributes 
)

Definition at line 248 of file user.c.

252{
253 PSAM_DB_OBJECT UserObject = NULL;
254 PGROUP_MEMBERSHIP GroupsBuffer = NULL;
255 ULONG Length = 0;
256 ULONG i;
258
259 Status = SampOpenUserObject(DomainObject,
260 UserId,
261 0,
262 &UserObject);
263 if (!NT_SUCCESS(Status))
264 {
265 return Status;
266 }
267
268 SampGetObjectAttribute(UserObject,
269 L"Groups",
270 NULL,
271 NULL,
272 &Length);
273
274 if (Length == 0)
275 return STATUS_UNSUCCESSFUL; /* FIXME */
276
277 GroupsBuffer = midl_user_allocate(Length);
278 if (GroupsBuffer == NULL)
279 {
281 goto done;
282 }
283
284 Status = SampGetObjectAttribute(UserObject,
285 L"Groups",
286 NULL,
287 GroupsBuffer,
288 &Length);
289 if (!NT_SUCCESS(Status))
290 goto done;
291
292 for (i = 0; i < (Length / sizeof(GROUP_MEMBERSHIP)); i++)
293 {
294 if (GroupsBuffer[i].RelativeId == GroupId)
295 {
296 GroupsBuffer[i].Attributes = GroupAttributes;
297 break;
298 }
299 }
300
301 Status = SampSetObjectAttribute(UserObject,
302 L"Groups",
304 GroupsBuffer,
305 Length);
306
307done:
308 if (GroupsBuffer != NULL)
309 midl_user_free(GroupsBuffer);
310
311 if (UserObject != NULL)
312 SampCloseDbObject(UserObject);
313
314 return Status;
315}

Referenced by SamrSetMemberAttributesOfGroup().

◆ SampSetUserPassword()

NTSTATUS SampSetUserPassword ( IN PSAM_DB_OBJECT  UserObject,
IN PENCRYPTED_NT_OWF_PASSWORD  NtPassword,
IN BOOLEAN  NtPasswordPresent,
IN PENCRYPTED_LM_OWF_PASSWORD  LmPassword,
IN BOOLEAN  LmPasswordPresent 
)

Definition at line 590 of file user.c.

595{
598 ULONG NtHistoryLength = 0;
599 ULONG LmHistoryLength = 0;
600 ULONG CurrentHistoryLength;
601 ULONG MaxHistoryLength = 3;
602 ULONG Length = 0;
603 BOOLEAN UseNtPassword;
604 BOOLEAN UseLmPassword;
606
607 UseNtPassword =
608 ((NtPasswordPresent != FALSE) &&
609 (NtPassword != NULL) &&
610 (memcmp(NtPassword, &EmptyNtHash, sizeof(ENCRYPTED_NT_OWF_PASSWORD)) != 0));
611
612 UseLmPassword =
613 ((LmPasswordPresent != FALSE) &&
614 (LmPassword != NULL) &&
615 (memcmp(LmPassword, &EmptyLmHash, sizeof(ENCRYPTED_LM_OWF_PASSWORD)) != 0));
616
617 /* Update the NT password history only if we have a new non-empty NT password */
618 if (UseNtPassword)
619 {
620 /* Get the size of the NT history */
621 SampGetObjectAttribute(UserObject,
622 L"NTPwdHistory",
623 NULL,
624 NULL,
625 &Length);
626
627 CurrentHistoryLength = Length / sizeof(ENCRYPTED_NT_OWF_PASSWORD);
628 if (CurrentHistoryLength < MaxHistoryLength)
629 {
630 NtHistoryLength = (CurrentHistoryLength + 1) * sizeof(ENCRYPTED_NT_OWF_PASSWORD);
631 }
632 else
633 {
634 NtHistoryLength = MaxHistoryLength * sizeof(ENCRYPTED_NT_OWF_PASSWORD);
635 }
636
637 /* Allocate the history buffer */
638 NtHistory = midl_user_allocate(NtHistoryLength);
639 if (NtHistory == NULL)
641
642 if (Length > 0)
643 {
644 /* Get the history */
645 Status = SampGetObjectAttribute(UserObject,
646 L"NTPwdHistory",
647 NULL,
648 NtHistory,
649 &Length);
650 if (!NT_SUCCESS(Status))
651 goto done;
652 }
653
654 /* Move the old passwords down by one entry */
655 if (NtHistoryLength > sizeof(ENCRYPTED_NT_OWF_PASSWORD))
656 {
657 MoveMemory(&(NtHistory[1]),
658 &(NtHistory[0]),
659 NtHistoryLength - sizeof(ENCRYPTED_NT_OWF_PASSWORD));
660 }
661
662 /* Add the new password to the top of the history */
663 if (NtPasswordPresent)
664 {
665 CopyMemory(&(NtHistory[0]),
666 NtPassword,
668 }
669 else
670 {
671 ZeroMemory(&(NtHistory[0]),
673 }
674
675 /* Set the history */
676 Status = SampSetObjectAttribute(UserObject,
677 L"NTPwdHistory",
679 (PVOID)NtHistory,
680 NtHistoryLength);
681 if (!NT_SUCCESS(Status))
682 goto done;
683 }
684
685 /* Update the LM password history only if we have a new non-empty LM password */
686 if (UseLmPassword)
687 {
688 /* Get the size of the LM history */
689 Length = 0;
690 SampGetObjectAttribute(UserObject,
691 L"LMPwdHistory",
692 NULL,
693 NULL,
694 &Length);
695
696 CurrentHistoryLength = Length / sizeof(ENCRYPTED_LM_OWF_PASSWORD);
697 if (CurrentHistoryLength < MaxHistoryLength)
698 {
699 LmHistoryLength = (CurrentHistoryLength + 1) * sizeof(ENCRYPTED_LM_OWF_PASSWORD);
700 }
701 else
702 {
703 LmHistoryLength = MaxHistoryLength * sizeof(ENCRYPTED_LM_OWF_PASSWORD);
704 }
705
706 /* Allocate the history buffer */
707 LmHistory = midl_user_allocate(LmHistoryLength);
708 if (LmHistory == NULL)
710
711 if (Length > 0)
712 {
713 /* Get the history */
714 Status = SampGetObjectAttribute(UserObject,
715 L"LMPwdHistory",
716 NULL,
717 LmHistory,
718 &Length);
719 if (!NT_SUCCESS(Status))
720 goto done;
721 }
722
723 /* Move the old passwords down by one entry */
724 if (LmHistoryLength > sizeof(ENCRYPTED_LM_OWF_PASSWORD))
725 {
726 MoveMemory(&(LmHistory[1]),
727 &(LmHistory[0]),
728 LmHistoryLength - sizeof(ENCRYPTED_LM_OWF_PASSWORD));
729 }
730
731 /* Add the new password to the top of the history */
732 if (LmPasswordPresent)
733 {
734 CopyMemory(&(LmHistory[0]),
735 LmPassword,
737 }
738 else
739 {
740 ZeroMemory(&(LmHistory[0]),
742 }
743
744 /* Set the LM password history */
745 Status = SampSetObjectAttribute(UserObject,
746 L"LMPwdHistory",
748 (PVOID)LmHistory,
749 LmHistoryLength);
750 if (!NT_SUCCESS(Status))
751 goto done;
752 }
753
754 /* Set the new NT password */
755 if (UseNtPassword)
756 {
757 Status = SampSetObjectAttribute(UserObject,
758 L"NTPwd",
760 (PVOID)NtPassword,
762 if (!NT_SUCCESS(Status))
763 goto done;
764 }
765 else
766 {
767 Status = SampSetObjectAttribute(UserObject,
768 L"NTPwd",
772 if (!NT_SUCCESS(Status))
773 goto done;
774 }
775
776 /* Set the new LM password */
777 if (UseLmPassword)
778 {
779 Status = SampSetObjectAttribute(UserObject,
780 L"LMPwd",
782 (PVOID)LmPassword,
784 if (!NT_SUCCESS(Status))
785 goto done;
786 }
787 else
788 {
789 Status = SampSetObjectAttribute(UserObject,
790 L"LMPwd",
794 if (!NT_SUCCESS(Status))
795 goto done;
796 }
797
798done:
799 if (NtHistory != NULL)
800 midl_user_free(NtHistory);
801
802 if (LmHistory != NULL)
803 midl_user_free(LmHistory);
804
805 return Status;
806}
unsigned char BOOLEAN
Definition: actypes.h:127
#define FALSE
Definition: types.h:117
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
#define ZeroMemory
Definition: minwinbase.h:31
#define MoveMemory
Definition: minwinbase.h:28
struct _ENCRYPTED_LM_OWF_PASSWORD ENCRYPTED_NT_OWF_PASSWORD
struct _ENCRYPTED_LM_OWF_PASSWORD ENCRYPTED_LM_OWF_PASSWORD
ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash
Definition: samsrv.c:27
ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash
Definition: samsrv.c:26

Referenced by SampSetUserAll(), SampSetUserInternal1(), and SamrChangePasswordUser().