ReactOS 0.4.16-dev-197-g92996da
group.c File Reference
#include "samsrv.h"
Include dependency graph for group.c:

Go to the source code of this file.

Functions

NTSTATUS SampOpenGroupObject (IN PSAM_DB_OBJECT DomainObject, IN ULONG GroupId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *GroupObject)
 
NTSTATUS SampAddMemberToGroup (IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
 
NTSTATUS SampRemoveMemberFromGroup (IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
 

Function Documentation

◆ SampAddMemberToGroup()

NTSTATUS SampAddMemberToGroup ( IN PSAM_DB_OBJECT  GroupObject,
IN ULONG  MemberId 
)

Definition at line 39 of file group.c.

41{
42 PULONG MembersBuffer = NULL;
43 ULONG MembersCount = 0;
44 ULONG Length = 0;
45 ULONG i;
47
48 Status = SampGetObjectAttribute(GroupObject,
49 L"Members",
50 NULL,
51 NULL,
52 &Length);
54 goto done;
55
56 MembersBuffer = midl_user_allocate(Length + sizeof(ULONG));
57 if (MembersBuffer == NULL)
58 {
60 goto done;
61 }
62
64 {
65 Status = SampGetObjectAttribute(GroupObject,
66 L"Members",
67 NULL,
68 MembersBuffer,
69 &Length);
70 if (!NT_SUCCESS(Status))
71 goto done;
72
73 MembersCount = Length / sizeof(ULONG);
74 }
75
76 for (i = 0; i < MembersCount; i++)
77 {
78 if (MembersBuffer[i] == MemberId)
79 {
81 goto done;
82 }
83 }
84
85 MembersBuffer[MembersCount] = MemberId;
86 Length += sizeof(ULONG);
87
88 Status = SampSetObjectAttribute(GroupObject,
89 L"Members",
91 MembersBuffer,
92 Length);
93
94done:
95 if (MembersBuffer != NULL)
96 midl_user_free(MembersBuffer);
97
98 return Status;
99}
LONG NTSTATUS
Definition: precomp.h:26
#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
Status
Definition: gdiplustypes.h:25
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:1496
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_MEMBER_IN_GROUP
Definition: ntstatus.h:339
#define L(x)
Definition: ntvdm.h:50
#define midl_user_free
Definition: rpc.h:45
#define midl_user_allocate
Definition: rpc.h:44
uint32_t * PULONG
Definition: typedefs.h:59
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().

◆ SampOpenGroupObject()

NTSTATUS SampOpenGroupObject ( IN PSAM_DB_OBJECT  DomainObject,
IN ULONG  GroupId,
IN ACCESS_MASK  DesiredAccess,
OUT PSAM_DB_OBJECT GroupObject 
)

Definition at line 14 of file group.c.

18{
19 WCHAR szRid[9];
20
21 TRACE("(%p %lu %lx %p)\n",
22 DomainObject, GroupId, DesiredAccess, GroupObject);
23
24 /* Convert the RID into a string (hex) */
25 swprintf(szRid, L"%08lX", GroupId);
26
27 /* Create the user object */
28 return SampOpenDbObject(DomainObject,
29 L"Groups",
30 szRid,
31 GroupId,
34 GroupObject);
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
@ SamDbGroupObject
Definition: samsrv.h:41
#define swprintf
Definition: precomp.h:40
#define TRACE(s)
Definition: solgame.cpp:4
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by SampRemoveUserFromAllGroups().

◆ SampRemoveMemberFromGroup()

NTSTATUS SampRemoveMemberFromGroup ( IN PSAM_DB_OBJECT  GroupObject,
IN ULONG  MemberId 
)

Definition at line 103 of file group.c.

105{
106 PULONG MembersBuffer = NULL;
107 ULONG MembersCount = 0;
108 ULONG Length = 0;
109 ULONG i;
111
112 SampGetObjectAttribute(GroupObject,
113 L"Members",
114 NULL,
115 NULL,
116 &Length);
117
118 if (Length == 0)
120
121 MembersBuffer = midl_user_allocate(Length);
122 if (MembersBuffer == NULL)
123 {
125 goto done;
126 }
127
128 Status = SampGetObjectAttribute(GroupObject,
129 L"Members",
130 NULL,
131 MembersBuffer,
132 &Length);
133 if (!NT_SUCCESS(Status))
134 goto done;
135
137
138 MembersCount = Length / sizeof(ULONG);
139 for (i = 0; i < MembersCount; i++)
140 {
141 if (MembersBuffer[i] == MemberId)
142 {
143 Length -= sizeof(ULONG);
145
146 if (MembersCount - i - 1 > 0)
147 {
148 CopyMemory(&MembersBuffer[i],
149 &MembersBuffer[i + 1],
150 (MembersCount - i - 1) * sizeof(ULONG));
151 }
152
153 break;
154 }
155 }
156
157 if (!NT_SUCCESS(Status))
158 goto done;
159
160 Status = SampSetObjectAttribute(GroupObject,
161 L"Members",
163 MembersBuffer,
164 Length);
165
166done:
167 if (MembersBuffer != NULL)
168 midl_user_free(MembersBuffer);
169
170 return Status;
171}
#define STATUS_MEMBER_NOT_IN_GROUP
Definition: ntstatus.h:340
#define STATUS_SUCCESS
Definition: shellext.h:65
#define CopyMemory
Definition: winbase.h:1734

Referenced by SampRemoveUserFromAllGroups(), and SamrRemoveMemberFromGroup().