ReactOS 0.4.15-dev-5667-ged97270
group.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/group.c
5 * PURPOSE: Group specific helper functions
6 * COPYRIGHT: Copyright 2013 Eric Kohl
7 */
8
9#include "samsrv.h"
10
11/* FUNCTIONS ***************************************************************/
12
15 IN ULONG GroupId,
17 OUT PSAM_DB_OBJECT *GroupObject)
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}
36
37
40 IN ULONG MemberId)
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}
100
101
104 IN ULONG MemberId)
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}
172
173/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
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 SampRemoveMemberFromGroup(IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
Definition: group.c:103
NTSTATUS SampAddMemberToGroup(IN PSAM_DB_OBJECT GroupObject, IN ULONG MemberId)
Definition: group.c:39
NTSTATUS SampOpenGroupObject(IN PSAM_DB_OBJECT DomainObject, IN ULONG GroupId, IN ACCESS_MASK DesiredAccess, OUT PSAM_DB_OBJECT *GroupObject)
Definition: group.c:14
@ SamDbGroupObject
Definition: samsrv.h:41
#define swprintf
Definition: precomp.h:40
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
ULONG ACCESS_MASK
Definition: nt_native.h:40
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_MEMBER_IN_GROUP
Definition: ntstatus.h:339
#define STATUS_MEMBER_NOT_IN_GROUP
Definition: ntstatus.h:340
#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 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
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
#define CopyMemory
Definition: winbase.h:1668
__wchar_t WCHAR
Definition: xmlstorage.h:180