ReactOS 0.4.15-dev-5667-ged97270
group_new.c File Reference
#include "netapi32.h"
Include dependency graph for group_new.c:

Go to the source code of this file.

Classes

struct  _GROUP_ENUM_CONTEXT
 
struct  _USER_ENUM_CONTEXT
 

Typedefs

typedef enum _ENUM_PHASE ENUM_PHASE
 
typedef struct _GROUP_ENUM_CONTEXT GROUP_ENUM_CONTEXT
 
typedef struct _GROUP_ENUM_CONTEXTPGROUP_ENUM_CONTEXT
 
typedef struct _USER_ENUM_CONTEXT USER_ENUM_CONTEXT
 
typedef struct _USER_ENUM_CONTEXTPUSER_ENUM_CONTEXT
 

Enumerations

enum  _ENUM_PHASE {
  BuiltinPhase , AccountPhase , DonePhase , BuiltinPhase ,
  AccountPhase , DonePhase
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (netapi32)
 
static NET_API_STATUS BuildGroupInfoBuffer (_In_ PGROUP_GENERAL_INFORMATION GroupInfo, _In_ DWORD Level, _In_ DWORD GroupId, _Out_ LPVOID *Buffer)
 
static VOID FreeGroupInfo (_In_ PGROUP_GENERAL_INFORMATION GroupInfo)
 
static NET_API_STATUS OpenGroupByName (_In_ SAM_HANDLE DomainHandle, _In_ PUNICODE_STRING GroupName, _In_ ULONG DesiredAccess, _Out_ PSAM_HANDLE GroupHandle, _Out_ PULONG RelativeId)
 
NET_API_STATUS WINAPI NetGroupAdd (_In_opt_ LPCWSTR servername, _In_ DWORD level, _In_ LPBYTE buf, _Out_opt_ LPDWORD parm_err)
 
NET_API_STATUS WINAPI NetGroupAddUser (_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ LPCWSTR username)
 
NET_API_STATUS WINAPI NetGroupDel (_In_opt_ LPCWSTR servername, _In_ IN LPCWSTR groupname)
 
NET_API_STATUS WINAPI NetGroupDelUser (_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ LPCWSTR username)
 
NET_API_STATUS WINAPI NetGroupEnum (_In_opt_ LPCWSTR servername, _In_ DWORD level, _Out_ LPBYTE *bufptr, _In_ DWORD prefmaxlen, _Out_ LPDWORD entriesread, _Out_ LPDWORD totalentries, _Inout_opt_ PDWORD_PTR resume_handle)
 
NET_API_STATUS WINAPI NetGroupGetInfo (_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _Out_ LPBYTE *bufptr)
 
NET_API_STATUS WINAPI NetGroupGetUsers (_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _Out_ LPBYTE *bufptr, _In_ DWORD prefmaxlen, _Out_ LPDWORD entriesread, _Out_ LPDWORD totalentries, _Inout_ PDWORD_PTR resume_handle)
 
NET_API_STATUS WINAPI NetGroupSetInfo (_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _In_ LPBYTE buf, _Out_opt_ LPDWORD parm_err)
 
NET_API_STATUS WINAPI NetGroupSetUsers (_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _In_ LPBYTE buf, _In_ DWORD totalentries)
 

Typedef Documentation

◆ ENUM_PHASE

◆ GROUP_ENUM_CONTEXT

◆ PGROUP_ENUM_CONTEXT

◆ PUSER_ENUM_CONTEXT

◆ USER_ENUM_CONTEXT

Enumeration Type Documentation

◆ _ENUM_PHASE

Enumerator
BuiltinPhase 
AccountPhase 
DonePhase 
BuiltinPhase 
AccountPhase 
DonePhase 

Definition at line 14 of file group_new.c.

15{
enum _ENUM_PHASE ENUM_PHASE
@ AccountPhase
Definition: group_new.c:17
@ DonePhase
Definition: group_new.c:18
@ BuiltinPhase
Definition: group_new.c:16

Function Documentation

◆ BuildGroupInfoBuffer()

static NET_API_STATUS BuildGroupInfoBuffer ( _In_ PGROUP_GENERAL_INFORMATION  GroupInfo,
_In_ DWORD  Level,
_In_ DWORD  GroupId,
_Out_ LPVOID Buffer 
)
static

Definition at line 55 of file group_new.c.

60{
61 PVOID GroupBuffer = NULL;
62 PGROUP_INFO_0 GroupInfo0;
63 PGROUP_INFO_1 GroupInfo1;
64 PGROUP_INFO_2 GroupInfo2;
65 PGROUP_INFO_3 GroupInfo3;
66 PWSTR Ptr;
67 ULONG Size = 0;
68 NET_API_STATUS ApiStatus = NERR_Success;
69
70 *Buffer = NULL;
71
72 switch (Level)
73 {
74 case 0:
75 Size = sizeof(GROUP_INFO_0) +
76 GroupInfo->Name.Length + sizeof(WCHAR);
77 break;
78
79 case 1:
80 Size = sizeof(GROUP_INFO_1) +
81 GroupInfo->Name.Length + sizeof(WCHAR) +
82 GroupInfo->AdminComment.Length + sizeof(WCHAR);
83 break;
84
85 case 2:
86 Size = sizeof(GROUP_INFO_2) +
87 GroupInfo->Name.Length + sizeof(WCHAR) +
88 GroupInfo->AdminComment.Length + sizeof(WCHAR);
89 break;
90
91 case 3:
92 Size = sizeof(GROUP_INFO_3) +
93 GroupInfo->Name.Length + sizeof(WCHAR) +
94 GroupInfo->AdminComment.Length + sizeof(WCHAR);
95 /* FIXME: Sid size */
96 break;
97
98 default:
99 ApiStatus = ERROR_INVALID_LEVEL;
100 goto done;
101 }
102
103 ApiStatus = NetApiBufferAllocate(Size, &GroupBuffer);
104 if (ApiStatus != NERR_Success)
105 goto done;
106
107 ZeroMemory(GroupBuffer, Size);
108
109 switch (Level)
110 {
111 case 0:
112 GroupInfo0 = (PGROUP_INFO_0)GroupBuffer;
113
114 Ptr = (PWSTR)((ULONG_PTR)GroupInfo0 + sizeof(LOCALGROUP_INFO_0));
115 GroupInfo0->grpi0_name = Ptr;
116
117 memcpy(GroupInfo0->grpi0_name,
118 GroupInfo->Name.Buffer,
119 GroupInfo->Name.Length);
120 GroupInfo0->grpi0_name[GroupInfo->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
121 break;
122
123 case 1:
124 GroupInfo1 = (PGROUP_INFO_1)GroupBuffer;
125
126 Ptr = (PWSTR)((ULONG_PTR)GroupInfo1 + sizeof(GROUP_INFO_1));
127 GroupInfo1->grpi1_name = Ptr;
128
129 memcpy(GroupInfo1->grpi1_name,
130 GroupInfo->Name.Buffer,
131 GroupInfo->Name.Length);
132 GroupInfo1->grpi1_name[GroupInfo->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
133
134 Ptr = (PWSTR)((ULONG_PTR)Ptr + GroupInfo->Name.Length + sizeof(WCHAR));
135 GroupInfo1->grpi1_comment = Ptr;
136
137 memcpy(GroupInfo1->grpi1_comment,
138 GroupInfo->AdminComment.Buffer,
139 GroupInfo->AdminComment.Length);
140 GroupInfo1->grpi1_comment[GroupInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
141 break;
142
143 case 2:
144 GroupInfo2 = (PGROUP_INFO_2)GroupBuffer;
145
146 Ptr = (PWSTR)((ULONG_PTR)GroupInfo2 + sizeof(GROUP_INFO_2));
147 GroupInfo2->grpi2_name = Ptr;
148
149 memcpy(GroupInfo2->grpi2_name,
150 GroupInfo->Name.Buffer,
151 GroupInfo->Name.Length);
152 GroupInfo2->grpi2_name[GroupInfo->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
153
154 Ptr = (PWSTR)((ULONG_PTR)Ptr + GroupInfo->Name.Length + sizeof(WCHAR));
155 GroupInfo2->grpi2_comment = Ptr;
156
157 memcpy(GroupInfo2->grpi2_comment,
158 GroupInfo->AdminComment.Buffer,
159 GroupInfo->AdminComment.Length);
160 GroupInfo2->grpi2_comment[GroupInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
161
162 GroupInfo2->grpi2_group_id = GroupId;
163
164 GroupInfo2->grpi2_attributes= GroupInfo->Attributes;
165 break;
166
167 case 3:
168 GroupInfo3 = (PGROUP_INFO_3)GroupBuffer;
169
170 Ptr = (PWSTR)((ULONG_PTR)GroupInfo3 + sizeof(GROUP_INFO_3));
171 GroupInfo3->grpi3_name = Ptr;
172
173 memcpy(GroupInfo3->grpi3_name,
174 GroupInfo->Name.Buffer,
175 GroupInfo->Name.Length);
176 GroupInfo3->grpi3_name[GroupInfo->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
177
178 Ptr = (PWSTR)((ULONG_PTR)Ptr + GroupInfo->Name.Length + sizeof(WCHAR));
179 GroupInfo3->grpi3_comment = Ptr;
180
181 memcpy(GroupInfo3->grpi3_comment,
182 GroupInfo->AdminComment.Buffer,
183 GroupInfo->AdminComment.Length);
184 GroupInfo3->grpi3_comment[GroupInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
185
186 GroupInfo3->grpi3_group_sid = NULL; /* FIXME */
187
188 GroupInfo3->grpi3_attributes= GroupInfo->Attributes;
189 break;
190 }
191
192done:
193 if (ApiStatus == NERR_Success)
194 {
195 *Buffer = GroupBuffer;
196 }
197 else
198 {
199 if (GroupBuffer != NULL)
200 NetApiBufferFree(GroupBuffer);
201 }
202
203 return ApiStatus;
204}
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetApiBufferAllocate(DWORD ByteCount, LPVOID *Buffer)
Definition: apibuf.c:28
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
struct _GROUP_INFO_2 * PGROUP_INFO_2
struct _GROUP_INFO_3 GROUP_INFO_3
struct _GROUP_INFO_0 * PGROUP_INFO_0
struct _GROUP_INFO_3 * PGROUP_INFO_3
struct _GROUP_INFO_1 GROUP_INFO_1
struct _GROUP_INFO_2 GROUP_INFO_2
struct _LOCALGROUP_INFO_0 LOCALGROUP_INFO_0
struct _GROUP_INFO_0 GROUP_INFO_0
struct _GROUP_INFO_1 * PGROUP_INFO_1
#define NERR_Success
Definition: lmerr.h:5
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define UNICODE_NULL
LPWSTR grpi0_name
Definition: lmaccess.h:474
LPWSTR grpi1_name
Definition: lmaccess.h:477
LPWSTR grpi1_comment
Definition: lmaccess.h:478
LPWSTR grpi2_comment
Definition: lmaccess.h:482
DWORD grpi2_group_id
Definition: lmaccess.h:483
DWORD grpi2_attributes
Definition: lmaccess.h:484
LPWSTR grpi2_name
Definition: lmaccess.h:481
LPWSTR grpi3_name
Definition: lmaccess.h:487
DWORD grpi3_attributes
Definition: lmaccess.h:490
LPWSTR grpi3_comment
Definition: lmaccess.h:488
PSID grpi3_group_sid
Definition: lmaccess.h:489
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define ZeroMemory
Definition: winbase.h:1670
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by NetGroupEnum(), and NetGroupGetInfo().

◆ FreeGroupInfo()

static VOID FreeGroupInfo ( _In_ PGROUP_GENERAL_INFORMATION  GroupInfo)
static

Definition at line 209 of file group_new.c.

211{
212 if (GroupInfo->Name.Buffer != NULL)
213 SamFreeMemory(GroupInfo->Name.Buffer);
214
215 if (GroupInfo->AdminComment.Buffer != NULL)
216 SamFreeMemory(GroupInfo->AdminComment.Buffer);
217
218 SamFreeMemory(GroupInfo);
219}
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:983

Referenced by NetGroupEnum(), and NetGroupGetInfo().

◆ NetGroupAdd()

NET_API_STATUS WINAPI NetGroupAdd ( _In_opt_ LPCWSTR  servername,
_In_ DWORD  level,
_In_ LPBYTE  buf,
_Out_opt_ LPDWORD  parm_err 
)

Definition at line 286 of file group_new.c.

291{
293 GROUP_ATTRIBUTE_INFORMATION AttributeInfo;
294 UNICODE_STRING ServerName;
295 UNICODE_STRING GroupName;
296 SAM_HANDLE ServerHandle = NULL;
297 SAM_HANDLE DomainHandle = NULL;
298 SAM_HANDLE GroupHandle = NULL;
299 PWSTR Name = NULL;
301 ULONG Attributes = 0;
302 ULONG RelativeId;
303 NET_API_STATUS ApiStatus = NERR_Success;
305
306 TRACE("NetGroupAdd(%s, %d, %p, %p)\n",
307 debugstr_w(servername), level, buf, parm_err);
308
309 if (parm_err != NULL)
310 *parm_err = PARM_ERROR_NONE;
311
312 /* Initialize the Server name*/
313 if (servername != NULL)
314 RtlInitUnicodeString(&ServerName, servername);
315
316 /* Initialize the Alias name*/
317 switch (level)
318 {
319 case 0:
320 Name = ((PGROUP_INFO_0)buf)->grpi0_name;
321 Comment = NULL;
322 Attributes = 0;
323 break;
324
325 case 1:
326 Name = ((PGROUP_INFO_1)buf)->grpi1_name;
327 Comment = ((PGROUP_INFO_1)buf)->grpi1_comment;
328 Attributes = 0;
329 break;
330
331 case 2:
332 Name = ((PGROUP_INFO_2)buf)->grpi2_name;
333 Comment = ((PGROUP_INFO_2)buf)->grpi2_comment;
334 Attributes = ((PGROUP_INFO_2)buf)->grpi2_attributes;
335 break;
336
337 case 3:
338 Name = ((PGROUP_INFO_3)buf)->grpi3_name;
339 Comment = ((PGROUP_INFO_3)buf)->grpi3_comment;
340 Attributes = ((PGROUP_INFO_3)buf)->grpi3_attributes;
341 break;
342
343 default:
344 return ERROR_INVALID_LEVEL;
345 }
346
347 RtlInitUnicodeString(&GroupName, Name);
348
349 /* Connect to the SAM Server */
350 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
351 &ServerHandle,
353 NULL);
354 if (!NT_SUCCESS(Status))
355 {
356 ERR("SamConnect failed (Status %08lx)\n", Status);
357 ApiStatus = NetpNtStatusToApiStatus(Status);
358 goto done;
359 }
360
361 /* Open the account domain */
362 Status = OpenAccountDomain(ServerHandle,
363 (servername != NULL) ? &ServerName : NULL,
365 &DomainHandle);
366 if (!NT_SUCCESS(Status))
367 {
368 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
369 ApiStatus = NetpNtStatusToApiStatus(Status);
370 goto done;
371 }
372
373 /* Try to open the group account */
374 ApiStatus = OpenGroupByName(DomainHandle,
375 &GroupName,
377 &GroupHandle,
378 NULL);
379 if (ApiStatus == NERR_Success)
380 {
381 ERR("OpenGroupByName: Group %wZ already exists!\n", &GroupName);
382
383 SamCloseHandle(GroupHandle);
384 ApiStatus = ERROR_GROUP_EXISTS;
385 goto done;
386 }
387
388 ApiStatus = NERR_Success;
389
390 /* Create the group */
391 Status = SamCreateGroupInDomain(DomainHandle,
392 &GroupName,
394 &GroupHandle,
395 &RelativeId);
396 if (!NT_SUCCESS(Status))
397 {
398 ERR("SamCreateGroupInDomain failed (Status %08lx)\n", Status);
399 ApiStatus = NetpNtStatusToApiStatus(Status);
400 goto done;
401 }
402
403 TRACE("Created group \"%wZ\" (RID: %lu)\n", &GroupName, RelativeId);
404
405 /* Set the admin comment */
406 if (level == 1 || level == 2 || level == 3)
407 {
409
410 Status = SamSetInformationGroup(GroupHandle,
412 &AdminComment);
413 if (!NT_SUCCESS(Status))
414 {
415 ERR("SamSetInformationAlias failed (Status %08lx)\n", Status);
416 ApiStatus = NetpNtStatusToApiStatus(Status);
417
418 /* Delete the Alias if the Comment could not be set */
419 SamDeleteGroup(GroupHandle);
420
421 goto done;
422 }
423 }
424
425 /* Set the attributes */
426 if (level == 2 || level == 3)
427 {
428 AttributeInfo.Attributes = Attributes;
429
430 Status = SamSetInformationGroup(GroupHandle,
432 &AttributeInfo);
433 if (!NT_SUCCESS(Status))
434 {
435 ERR("SamSetInformationAlias failed (Status %08lx)\n", Status);
436 ApiStatus = NetpNtStatusToApiStatus(Status);
437
438 /* Delete the Alias if the Attributes could not be set */
439 SamDeleteGroup(GroupHandle);
440
441 goto done;
442 }
443 }
444
445done:
446 if (GroupHandle != NULL)
447 {
448 if (ApiStatus != NERR_Success)
449 SamDeleteGroup(GroupHandle);
450 else
451 SamCloseHandle(GroupHandle);
452 }
453
454 if (DomainHandle != NULL)
455 SamCloseHandle(DomainHandle);
456
457 if (ServerHandle != NULL)
458 SamCloseHandle(ServerHandle);
459
460 return ApiStatus;
461}
@ Comment
Definition: asmpp.cpp:34
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: debug.h:110
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:289
Status
Definition: gdiplustypes.h:25
GLint level
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static NET_API_STATUS OpenGroupByName(_In_ SAM_HANDLE DomainHandle, _In_ PUNICODE_STRING GroupName, _In_ ULONG DesiredAccess, _Out_ PSAM_HANDLE GroupHandle, _Out_ PULONG RelativeId)
Definition: group_new.c:224
#define debugstr_w
Definition: kernel32.h:32
#define PARM_ERROR_NONE
Definition: lmcons.h:56
NTSTATUS OpenAccountDomain(IN SAM_HANDLE ServerHandle, IN PUNICODE_STRING ServerName, IN ULONG DesiredAccess, OUT PSAM_HANDLE DomainHandle)
Definition: utils.c:113
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define DELETE
Definition: nt_native.h:57
#define GROUP_READ_INFORMATION
Definition: ntsam.h:75
#define DOMAIN_CREATE_GROUP
Definition: ntsam.h:38
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
#define GROUP_WRITE_ACCOUNT
Definition: ntsam.h:76
@ GroupAttributeInformation
Definition: ntsam.h:466
@ GroupAdminCommentInformation
Definition: ntsam.h:467
NTSTATUS NTAPI SamSetInformationGroup(IN SAM_HANDLE GroupHandle, IN GROUP_INFORMATION_CLASS GroupInformationClass, IN PVOID Buffer)
Definition: samlib.c:1973
NTSTATUS NTAPI SamDeleteGroup(IN SAM_HANDLE GroupHandle)
Definition: samlib.c:732
NTSTATUS NTAPI SamCreateGroupInDomain(IN SAM_HANDLE DomainHandle, IN PUNICODE_STRING AccountName, IN ACCESS_MASK DesiredAccess, OUT PSAM_HANDLE GroupHandle, OUT PULONG RelativeId)
Definition: samlib.c:596
NTSTATUS NTAPI SamConnect(IN OUT PUNICODE_STRING ServerName OPTIONAL, OUT PSAM_HANDLE ServerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: samlib.c:519
NTSTATUS NTAPI SamCloseHandle(IN SAM_HANDLE SamHandle)
Definition: samlib.c:497
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
UNICODE_STRING AdminComment
Definition: ntsam.h:491
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
#define ERROR_GROUP_EXISTS
Definition: winerror.h:800

Referenced by cmdGroup().

◆ NetGroupAddUser()

NET_API_STATUS WINAPI NetGroupAddUser ( _In_opt_ LPCWSTR  servername,
_In_ LPCWSTR  groupname,
_In_ LPCWSTR  username 
)

Definition at line 466 of file group_new.c.

470{
471 UNICODE_STRING ServerName;
472 UNICODE_STRING GroupName;
473 UNICODE_STRING UserName;
474 SAM_HANDLE ServerHandle = NULL;
475 SAM_HANDLE DomainHandle = NULL;
476 SAM_HANDLE GroupHandle = NULL;
477 PULONG RelativeIds = NULL;
478 PSID_NAME_USE Use = NULL;
479 NET_API_STATUS ApiStatus = NERR_Success;
481
482 TRACE("NetGroupAddUser(%s, %s, %s)\n",
483 debugstr_w(servername), debugstr_w(groupname), debugstr_w(username));
484
485 if (servername != NULL)
486 RtlInitUnicodeString(&ServerName, servername);
487
488 RtlInitUnicodeString(&GroupName, groupname);
489
490 RtlInitUnicodeString(&UserName, username);
491
492 /* Connect to the SAM Server */
493 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
494 &ServerHandle,
496 NULL);
497 if (!NT_SUCCESS(Status))
498 {
499 ERR("SamConnect failed (Status %08lx)\n", Status);
500 ApiStatus = NetpNtStatusToApiStatus(Status);
501 goto done;
502 }
503
504 /* Open the Acount Domain */
505 Status = OpenAccountDomain(ServerHandle,
506 (servername != NULL) ? &ServerName : NULL,
508 &DomainHandle);
509 if (!NT_SUCCESS(Status))
510 {
511 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
512 ApiStatus = NetpNtStatusToApiStatus(Status);
513 goto done;
514 }
515
516 /* Open the group account */
517 ApiStatus = OpenGroupByName(DomainHandle,
518 &GroupName,
520 &GroupHandle,
521 NULL);
522 if (ApiStatus != NERR_Success)
523 {
524 ERR("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
525 if (ApiStatus == ERROR_NONE_MAPPED)
526 ApiStatus = NERR_GroupNotFound;
527 goto done;
528 }
529
530 Status = SamLookupNamesInDomain(DomainHandle,
531 1,
532 &UserName,
533 &RelativeIds,
534 &Use);
535 if (!NT_SUCCESS(Status))
536 {
537 ERR("SamLookupNamesInDomain(%wZ) failed (Status %08lx)\n", &UserName, Status);
538 ApiStatus = NetpNtStatusToApiStatus(Status);
539 goto done;
540 }
541
542 /* Fail, if it is not a user account */
543 if (Use[0] != SidTypeUser)
544 {
545 ERR("Object is not a user!\n");
546 ApiStatus = NERR_GroupNotFound;
547 goto done;
548 }
549
550 Status = SamAddMemberToGroup(GroupHandle,
551 RelativeIds[0],
552 0);
553 if (!NT_SUCCESS(Status))
554 {
555 ERR("SamAddMemberToGroup failed (Status %lu)\n", Status);
556 ApiStatus = NetpNtStatusToApiStatus(Status);
557 goto done;
558 }
559
560done:
561 if (RelativeIds != NULL)
562 SamFreeMemory(RelativeIds);
563
564 if (Use != NULL)
565 SamFreeMemory(Use);
566
567 if (GroupHandle != NULL)
568 SamCloseHandle(GroupHandle);
569
570 if (DomainHandle != NULL)
571 SamCloseHandle(DomainHandle);
572
573 if (ServerHandle != NULL)
574 SamCloseHandle(ServerHandle);
575
576 return ApiStatus;
577}
#define NERR_GroupNotFound
Definition: lmerr.h:87
enum _SID_NAME_USE * PSID_NAME_USE
@ SidTypeUser
Definition: lsa.idl:118
static WCHAR username[]
Definition: url.c:32
#define GROUP_ADD_MEMBER
Definition: ntsam.h:77
NTSTATUS NTAPI SamAddMemberToGroup(IN SAM_HANDLE GroupHandle, IN ULONG MemberId, IN ULONG Attributes)
Definition: samlib.c:260
NTSTATUS NTAPI SamLookupNamesInDomain(IN SAM_HANDLE DomainHandle, IN ULONG Count, IN PUNICODE_STRING Names, OUT PULONG *RelativeIds, OUT PSID_NAME_USE *Use)
Definition: samlib.c:1371
uint32_t * PULONG
Definition: typedefs.h:59
#define ERROR_NONE_MAPPED
Definition: winerror.h:814

Referenced by cmdGroup().

◆ NetGroupDel()

NET_API_STATUS WINAPI NetGroupDel ( _In_opt_ LPCWSTR  servername,
_In_ IN LPCWSTR  groupname 
)

Definition at line 582 of file group_new.c.

585{
586 UNICODE_STRING ServerName;
587 UNICODE_STRING GroupName;
588 SAM_HANDLE ServerHandle = NULL;
589 SAM_HANDLE DomainHandle = NULL;
590 SAM_HANDLE GroupHandle = NULL;
591 NET_API_STATUS ApiStatus = NERR_Success;
593
594 TRACE("NetGroupDel(%s, %s)\n",
595 debugstr_w(servername), debugstr_w(groupname));
596
597 if (servername != NULL)
598 RtlInitUnicodeString(&ServerName, servername);
599
600 RtlInitUnicodeString(&GroupName, groupname);
601
602 /* Connect to the SAM Server */
603 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
604 &ServerHandle,
606 NULL);
607 if (!NT_SUCCESS(Status))
608 {
609 ERR("SamConnect failed (Status %08lx)\n", Status);
610 ApiStatus = NetpNtStatusToApiStatus(Status);
611 goto done;
612 }
613
614 /* Open the Acount Domain */
615 Status = OpenAccountDomain(ServerHandle,
616 (servername != NULL) ? &ServerName : NULL,
618 &DomainHandle);
619 if (!NT_SUCCESS(Status))
620 {
621 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
622 ApiStatus = NetpNtStatusToApiStatus(Status);
623 goto done;
624 }
625
626 /* Open the group */
627 ApiStatus = OpenGroupByName(DomainHandle,
628 &GroupName,
629 DELETE,
630 &GroupHandle,
631 NULL);
632 if (ApiStatus != NERR_Success)
633 {
634 ERR("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
635 if (ApiStatus == ERROR_NONE_MAPPED)
636 ApiStatus = NERR_GroupNotFound;
637 goto done;
638 }
639
640 /* Delete the group */
641 Status = SamDeleteGroup(GroupHandle);
642 if (!NT_SUCCESS(Status))
643 {
644 ERR("SamDeleteGroup failed (Status %08lx)\n", Status);
645 ApiStatus = NetpNtStatusToApiStatus(Status);
646 goto done;
647 }
648
649done:
650 if (GroupHandle != NULL)
651 SamCloseHandle(GroupHandle);
652
653 if (DomainHandle != NULL)
654 SamCloseHandle(DomainHandle);
655
656 if (ServerHandle != NULL)
657 SamCloseHandle(ServerHandle);
658
659 return ApiStatus;
660}

Referenced by cmdGroup().

◆ NetGroupDelUser()

NET_API_STATUS WINAPI NetGroupDelUser ( _In_opt_ LPCWSTR  servername,
_In_ LPCWSTR  groupname,
_In_ LPCWSTR  username 
)

Definition at line 665 of file group_new.c.

669{
670 UNICODE_STRING ServerName;
671 UNICODE_STRING GroupName;
672 UNICODE_STRING UserName;
673 SAM_HANDLE ServerHandle = NULL;
674 SAM_HANDLE DomainHandle = NULL;
675 SAM_HANDLE GroupHandle = NULL;
676 PULONG RelativeIds = NULL;
677 PSID_NAME_USE Use = NULL;
678 NET_API_STATUS ApiStatus = NERR_Success;
680
681 TRACE("NetGroupDelUser(%s, %s, %s)\n",
682 debugstr_w(servername), debugstr_w(groupname), debugstr_w(username));
683
684 if (servername != NULL)
685 RtlInitUnicodeString(&ServerName, servername);
686
687 RtlInitUnicodeString(&GroupName, groupname);
688
689 RtlInitUnicodeString(&UserName, username);
690
691 /* Connect to the SAM Server */
692 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
693 &ServerHandle,
695 NULL);
696 if (!NT_SUCCESS(Status))
697 {
698 ERR("SamConnect failed (Status %08lx)\n", Status);
699 ApiStatus = NetpNtStatusToApiStatus(Status);
700 goto done;
701 }
702
703 /* Open the Acount Domain */
704 Status = OpenAccountDomain(ServerHandle,
705 (servername != NULL) ? &ServerName : NULL,
707 &DomainHandle);
708 if (!NT_SUCCESS(Status))
709 {
710 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
711 ApiStatus = NetpNtStatusToApiStatus(Status);
712 goto done;
713 }
714
715 /* Open the group account */
716 ApiStatus = OpenGroupByName(DomainHandle,
717 &GroupName,
719 &GroupHandle,
720 NULL);
721 if (ApiStatus != NERR_Success)
722 {
723 ERR("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
724 if (ApiStatus == ERROR_NONE_MAPPED)
725 ApiStatus = NERR_GroupNotFound;
726 goto done;
727 }
728
729 Status = SamLookupNamesInDomain(DomainHandle,
730 1,
731 &UserName,
732 &RelativeIds,
733 &Use);
734 if (!NT_SUCCESS(Status))
735 {
736 ERR("SamLookupNamesInDomain(%wZ) failed (Status %08lx)\n", &UserName, Status);
737 ApiStatus = NetpNtStatusToApiStatus(Status);
738 goto done;
739 }
740
741 /* Fail, if it is not a user account */
742 if (Use[0] != SidTypeUser)
743 {
744 ERR("Object is not a user!\n");
745 ApiStatus = NERR_GroupNotFound;
746 goto done;
747 }
748
749 Status = SamRemoveMemberFromGroup(GroupHandle,
750 RelativeIds[0]);
751 if (!NT_SUCCESS(Status))
752 {
753 ERR("SamRemoveMemberFromGroup failed (Status %lu)\n", Status);
754 ApiStatus = NetpNtStatusToApiStatus(Status);
755 goto done;
756 }
757
758done:
759 if (RelativeIds != NULL)
760 SamFreeMemory(RelativeIds);
761
762 if (Use != NULL)
763 SamFreeMemory(Use);
764
765 if (GroupHandle != NULL)
766 SamCloseHandle(GroupHandle);
767
768 if (DomainHandle != NULL)
769 SamCloseHandle(DomainHandle);
770
771 if (ServerHandle != NULL)
772 SamCloseHandle(ServerHandle);
773
774 return ApiStatus;
775}
#define GROUP_REMOVE_MEMBER
Definition: ntsam.h:78
NTSTATUS NTAPI SamRemoveMemberFromGroup(IN SAM_HANDLE GroupHandle, IN ULONG MemberId)
Definition: samlib.c:1850

Referenced by cmdGroup().

◆ NetGroupEnum()

NET_API_STATUS WINAPI NetGroupEnum ( _In_opt_ LPCWSTR  servername,
_In_ DWORD  level,
_Out_ LPBYTE bufptr,
_In_ DWORD  prefmaxlen,
_Out_ LPDWORD  entriesread,
_Out_ LPDWORD  totalentries,
_Inout_opt_ PDWORD_PTR  resume_handle 
)

Definition at line 780 of file group_new.c.

788{
789 UNICODE_STRING ServerName;
790 PSAM_RID_ENUMERATION CurrentGroup;
791 PGROUP_ENUM_CONTEXT EnumContext = NULL;
792 ULONG i;
793 SAM_HANDLE GroupHandle = NULL;
795 PVOID Buffer = NULL;
796 NET_API_STATUS ApiStatus = NERR_Success;
798
799 TRACE("NetGroupEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
800 level, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
801
802 *entriesread = 0;
803 *totalentries = 0;
804 *bufptr = NULL;
805
806 if (servername != NULL)
807 RtlInitUnicodeString(&ServerName, servername);
808
809 if (resume_handle != NULL && *resume_handle != 0)
810 {
811 EnumContext = (PGROUP_ENUM_CONTEXT)*resume_handle;
812 }
813 else
814 {
815 ApiStatus = NetApiBufferAllocate(sizeof(GROUP_ENUM_CONTEXT), (PVOID*)&EnumContext);
816 if (ApiStatus != NERR_Success)
817 goto done;
818
819 EnumContext->EnumerationContext = 0;
820 EnumContext->Buffer = NULL;
821 EnumContext->Returned = 0;
822 EnumContext->Index = 0;
823
824 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
825 &EnumContext->ServerHandle,
827 NULL);
828 if (!NT_SUCCESS(Status))
829 {
830 ERR("SamConnect failed (Status %08lx)\n", Status);
831 ApiStatus = NetpNtStatusToApiStatus(Status);
832 goto done;
833 }
834
836 (servername != NULL) ? &ServerName : NULL,
838 &EnumContext->AccountDomainHandle);
839 if (!NT_SUCCESS(Status))
840 {
841 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
842 ApiStatus = NetpNtStatusToApiStatus(Status);
843 goto done;
844 }
845
848 &EnumContext->BuiltinDomainHandle);
849 if (!NT_SUCCESS(Status))
850 {
851 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
852 ApiStatus = NetpNtStatusToApiStatus(Status);
853 goto done;
854 }
855
856 EnumContext->Phase = AccountPhase; //BuiltinPhase;
857 EnumContext->DomainHandle = EnumContext->AccountDomainHandle; //BuiltinDomainHandle;
858 }
859
860
861// while (TRUE)
862// {
863 TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
864 TRACE("EnumContext->Returned: %lu\n", EnumContext->Returned);
865
866 if (EnumContext->Index >= EnumContext->Returned)
867 {
868 TRACE("Calling SamEnumerateGroupsInDomain\n");
869
871 &EnumContext->EnumerationContext,
872 (PVOID *)&EnumContext->Buffer,
873 prefmaxlen,
874 &EnumContext->Returned);
875
876 TRACE("SamEnumerateGroupsInDomain returned (Status %08lx)\n", Status);
877 if (!NT_SUCCESS(Status))
878 {
879 ERR("SamEnumerateAliasesInDomain failed (Status %08lx)\n", Status);
880 ApiStatus = NetpNtStatusToApiStatus(Status);
881 goto done;
882 }
883
885 {
886 ApiStatus = NERR_BufTooSmall;
887 goto done;
888 }
889 }
890
891 TRACE("EnumContext: %lu\n", EnumContext);
892 TRACE("EnumContext->Returned: %lu\n", EnumContext->Returned);
893 TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
894
895 /* Get a pointer to the current group */
896 CurrentGroup = &EnumContext->Buffer[EnumContext->Index];
897
898 TRACE("RID: %lu\n", CurrentGroup->RelativeId);
899
900 Status = SamOpenGroup(EnumContext->DomainHandle,
902 CurrentGroup->RelativeId,
903 &GroupHandle);
904 if (!NT_SUCCESS(Status))
905 {
906 ERR("SamOpenGroup failed (Status %08lx)\n", Status);
907 ApiStatus = NetpNtStatusToApiStatus(Status);
908 goto done;
909 }
910
911 Status = SamQueryInformationGroup(GroupHandle,
913 (PVOID *)&GroupInfo);
914 if (!NT_SUCCESS(Status))
915 {
916 ERR("SamQueryInformationGroup failed (Status %08lx)\n", Status);
917 ApiStatus = NetpNtStatusToApiStatus(Status);
918 goto done;
919 }
920
921 SamCloseHandle(GroupHandle);
922 GroupHandle = NULL;
923
924 TRACE("Name: %S\n", GroupInfo->Name.Buffer);
925 TRACE("Comment: %S\n", GroupInfo->AdminComment.Buffer);
926
927 ApiStatus = BuildGroupInfoBuffer(GroupInfo,
928 level,
929 CurrentGroup->RelativeId,
930 &Buffer);
931 if (ApiStatus != NERR_Success)
932 goto done;
933
934 if (GroupInfo != NULL)
935 {
936 FreeGroupInfo(GroupInfo);
937 GroupInfo = NULL;
938 }
939
940 EnumContext->Index++;
941
942 (*entriesread)++;
943
944 if (EnumContext->Index == EnumContext->Returned)
945 {
946 switch (EnumContext->Phase)
947 {
948 case BuiltinPhase:
949 EnumContext->Phase = AccountPhase;
950 EnumContext->DomainHandle = EnumContext->AccountDomainHandle;
951 EnumContext->EnumerationContext = 0;
952 EnumContext->Index = 0;
953 EnumContext->Returned = 0;
954
955 if (EnumContext->Buffer != NULL)
956 {
957 for (i = 0; i < EnumContext->Returned; i++)
958 {
959 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
960 }
961
962 SamFreeMemory(EnumContext->Buffer);
963 EnumContext->Buffer = NULL;
964 }
965 break;
966
967 case AccountPhase:
968 case DonePhase:
969 EnumContext->Phase = DonePhase;
970 break;
971 }
972 }
973// }
974
975done:
976 if (ApiStatus == NERR_Success && EnumContext != NULL && EnumContext->Phase != DonePhase)
977 ApiStatus = ERROR_MORE_DATA;
978
979 if (EnumContext != NULL)
980 *totalentries = EnumContext->Returned;
981
982 if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
983 {
984 if (EnumContext != NULL)
985 {
986 if (EnumContext->BuiltinDomainHandle != NULL)
988
989 if (EnumContext->AccountDomainHandle != NULL)
991
992 if (EnumContext->ServerHandle != NULL)
993 SamCloseHandle(EnumContext->ServerHandle);
994
995 if (EnumContext->Buffer != NULL)
996 {
997 for (i = 0; i < EnumContext->Returned; i++)
998 {
999 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
1000 }
1001
1002 SamFreeMemory(EnumContext->Buffer);
1003 }
1004
1005 NetApiBufferFree(EnumContext);
1006 EnumContext = NULL;
1007 }
1008 }
1009
1010 if (GroupHandle != NULL)
1011 SamCloseHandle(GroupHandle);
1012
1013 if (GroupInfo != NULL)
1014 FreeGroupInfo(GroupInfo);
1015
1016 if (resume_handle != NULL)
1017 *resume_handle = (DWORD_PTR)EnumContext;
1018
1019 *bufptr = (LPBYTE)Buffer;
1020
1021 TRACE("return %lu\n", ApiStatus);
1022
1023 return ApiStatus;
1024}
#define ERROR_MORE_DATA
Definition: dderror.h:13
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
struct _GROUP_ENUM_CONTEXT * PGROUP_ENUM_CONTEXT
static NET_API_STATUS BuildGroupInfoBuffer(_In_ PGROUP_GENERAL_INFORMATION GroupInfo, _In_ DWORD Level, _In_ DWORD GroupId, _Out_ LPVOID *Buffer)
Definition: group_new.c:55
static VOID FreeGroupInfo(_In_ PGROUP_GENERAL_INFORMATION GroupInfo)
Definition: group_new.c:209
#define NERR_BufTooSmall
Definition: lmerr.h:21
NTSTATUS OpenBuiltinDomain(IN SAM_HANDLE ServerHandle, IN ULONG DesiredAccess, OUT SAM_HANDLE *DomainHandle)
#define DOMAIN_LIST_ACCOUNTS
Definition: ntsam.h:41
@ GroupGeneralInformation
Definition: ntsam.h:464
NTSTATUS NTAPI SamOpenGroup(IN SAM_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG GroupId, OUT PSAM_HANDLE GroupHandle)
Definition: samlib.c:1506
NTSTATUS NTAPI SamQueryInformationGroup(IN SAM_HANDLE GroupHandle, IN GROUP_INFORMATION_CLASS GroupInformationClass, OUT PVOID *Buffer)
Definition: samlib.c:1704
NTSTATUS NTAPI SamEnumerateGroupsInDomain(IN SAM_HANDLE DomainHandle, IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext, IN PVOID *Buffer, IN ULONG PreferedMaximumLength, OUT PULONG CountReturned)
Definition: samlib.c:888
PSAM_RID_ENUMERATION Buffer
Definition: group_new.c:29
SAM_HANDLE DomainHandle
Definition: group_new.c:24
SAM_ENUMERATE_HANDLE EnumerationContext
Definition: group_new.c:28
ENUM_PHASE Phase
Definition: group_new.c:32
SAM_HANDLE AccountDomainHandle
Definition: group_new.c:26
SAM_HANDLE BuiltinDomainHandle
Definition: group_new.c:25
SAM_HANDLE ServerHandle
Definition: group_new.c:23
UNICODE_STRING AdminComment
Definition: ntsam.h:476
UNICODE_STRING Name
Definition: ntsam.h:473
UNICODE_STRING Name
Definition: ntsam.h:268
static unsigned int bufptr
Definition: tncon.cpp:77
#define DWORD_PTR
Definition: treelist.c:76
unsigned char * LPBYTE
Definition: typedefs.h:53
#define STATUS_MORE_ENTRIES
Definition: udferr_usr.h:124

Referenced by EnumerateGroups().

◆ NetGroupGetInfo()

NET_API_STATUS WINAPI NetGroupGetInfo ( _In_opt_ LPCWSTR  servername,
_In_ LPCWSTR  groupname,
_In_ DWORD  level,
_Out_ LPBYTE bufptr 
)

Definition at line 1029 of file group_new.c.

1034{
1035 UNICODE_STRING ServerName;
1036 UNICODE_STRING GroupName;
1037 SAM_HANDLE ServerHandle = NULL;
1038 SAM_HANDLE DomainHandle = NULL;
1039 SAM_HANDLE GroupHandle = NULL;
1040 PGROUP_GENERAL_INFORMATION GroupInfo = NULL;
1041 PVOID Buffer = NULL;
1042 ULONG RelativeId;
1043 NET_API_STATUS ApiStatus = NERR_Success;
1045
1046 TRACE("NetGroupGetInfo(%s, %s, %d, %p)\n",
1047 debugstr_w(servername), debugstr_w(groupname), level, bufptr);
1048
1049 if (servername != NULL)
1050 RtlInitUnicodeString(&ServerName, servername);
1051
1052 RtlInitUnicodeString(&GroupName, groupname);
1053
1054 /* Connect to the SAM Server */
1055 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1056 &ServerHandle,
1058 NULL);
1059 if (!NT_SUCCESS(Status))
1060 {
1061 ERR("SamConnect failed (Status %08lx)\n", Status);
1062 ApiStatus = NetpNtStatusToApiStatus(Status);
1063 goto done;
1064 }
1065
1066 /* Open the Acount Domain */
1067 Status = OpenAccountDomain(ServerHandle,
1068 (servername != NULL) ? &ServerName : NULL,
1070 &DomainHandle);
1071 if (!NT_SUCCESS(Status))
1072 {
1073 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1074 ApiStatus = NetpNtStatusToApiStatus(Status);
1075 goto done;
1076 }
1077
1078 /* Open the group account in the account domain */
1079 ApiStatus = OpenGroupByName(DomainHandle,
1080 &GroupName,
1082 &GroupHandle,
1083 &RelativeId);
1084 if (ApiStatus != NERR_Success)
1085 {
1086 ERR("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
1087 if (ApiStatus == ERROR_NONE_MAPPED)
1088 ApiStatus = NERR_GroupNotFound;
1089 goto done;
1090 }
1091
1092 Status = SamQueryInformationGroup(GroupHandle,
1094 (PVOID *)&GroupInfo);
1095 if (!NT_SUCCESS(Status))
1096 {
1097 ERR("SamQueryInformationGroup failed (Status %08lx)\n", Status);
1098 ApiStatus = NetpNtStatusToApiStatus(Status);
1099 goto done;
1100 }
1101
1102 ApiStatus = BuildGroupInfoBuffer(GroupInfo,
1103 level,
1104 RelativeId,
1105 &Buffer);
1106 if (ApiStatus != NERR_Success)
1107 goto done;
1108
1109done:
1110 if (GroupInfo != NULL)
1111 FreeGroupInfo(GroupInfo);
1112
1113 if (GroupHandle != NULL)
1114 SamCloseHandle(GroupHandle);
1115
1116 if (DomainHandle != NULL)
1117 SamCloseHandle(DomainHandle);
1118
1119 if (ServerHandle != NULL)
1120 SamCloseHandle(ServerHandle);
1121
1122 *bufptr = (LPBYTE)Buffer;
1123
1124 return ApiStatus;
1125}

Referenced by DisplayGroup().

◆ NetGroupGetUsers()

NET_API_STATUS WINAPI NetGroupGetUsers ( _In_opt_ LPCWSTR  servername,
_In_ LPCWSTR  groupname,
_In_ DWORD  level,
_Out_ LPBYTE bufptr,
_In_ DWORD  prefmaxlen,
_Out_ LPDWORD  entriesread,
_Out_ LPDWORD  totalentries,
_Inout_ PDWORD_PTR  resume_handle 
)

Definition at line 1130 of file group_new.c.

1139{
1140 UNICODE_STRING ServerName;
1141 UNICODE_STRING GroupName;
1142 PGROUP_USERS_INFO_0 UserInfo0;
1143 PGROUP_USERS_INFO_1 UserInfo1;
1144 PUSER_ENUM_CONTEXT EnumContext = NULL;
1145 PVOID Buffer = NULL;
1146 ULONG i, idx, Size;
1147 PWSTR Ptr;
1148 NET_API_STATUS ApiStatus = NERR_Success;
1150
1151 TRACE("NetGroupGetUsers(%s, %s, %d, %p, %d, %p, %p, %p)\n",
1152 debugstr_w(servername), debugstr_w(groupname), level, bufptr,
1153 prefmaxlen, entriesread, totalentries, resume_handle);
1154
1155 *entriesread = 0;
1156 *totalentries = 0;
1157 *bufptr = NULL;
1158
1159 if (servername != NULL)
1160 RtlInitUnicodeString(&ServerName, servername);
1161
1162 RtlInitUnicodeString(&GroupName, groupname);
1163
1164 if (resume_handle != NULL && *resume_handle != 0)
1165 {
1166 EnumContext = (PUSER_ENUM_CONTEXT)*resume_handle;
1167 }
1168 else
1169 {
1170 ApiStatus = NetApiBufferAllocate(sizeof(USER_ENUM_CONTEXT), (PVOID*)&EnumContext);
1171 if (ApiStatus != NERR_Success)
1172 goto done;
1173
1174 EnumContext->MemberCount = 0;
1175 EnumContext->MemberIds = NULL;
1176 EnumContext->Attributes = NULL;
1177 EnumContext->Names = NULL;
1178 EnumContext->Start = 0;
1179 EnumContext->Count = 0;
1180
1181 /* Connect to the SAM Server */
1182 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1183 &EnumContext->ServerHandle,
1185 NULL);
1186 if (!NT_SUCCESS(Status))
1187 {
1188 ERR("SamConnect failed (Status %08lx)\n", Status);
1189 ApiStatus = NetpNtStatusToApiStatus(Status);
1190 goto done;
1191 }
1192
1193 /* Open the Acount Domain */
1194 Status = OpenAccountDomain(EnumContext->ServerHandle,
1195 (servername != NULL) ? &ServerName : NULL,
1197 &EnumContext->DomainHandle);
1198 if (!NT_SUCCESS(Status))
1199 {
1200 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1201 ApiStatus = NetpNtStatusToApiStatus(Status);
1202 goto done;
1203 }
1204
1205 /* Open the group account */
1206 ApiStatus = OpenGroupByName(EnumContext->DomainHandle,
1207 &GroupName,
1209 &EnumContext->GroupHandle,
1210 NULL);
1211 if (ApiStatus != NERR_Success)
1212 {
1213 ERR("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
1214 if (ApiStatus == ERROR_NONE_MAPPED)
1215 ApiStatus = NERR_GroupNotFound;
1216 goto done;
1217 }
1218
1219 /* Get the group members */
1221 &EnumContext->MemberIds,
1222 &EnumContext->Attributes,
1223 &EnumContext->MemberCount);
1224 if (!NT_SUCCESS(Status))
1225 {
1226 ERR("SamGetMembersInGroup failed (Status %08lx)\n", Status);
1227 ApiStatus = NetpNtStatusToApiStatus(Status);
1228 goto done;
1229 }
1230
1231 if (EnumContext->MemberCount > 0)
1232 {
1233 /* Get all member names */
1235 EnumContext->MemberCount,
1236 EnumContext->MemberIds,
1237 &EnumContext->Names,
1238 NULL);
1239 if (!NT_SUCCESS(Status))
1240 {
1241 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
1242 ApiStatus = NetpNtStatusToApiStatus(Status);
1243 goto done;
1244 }
1245 }
1246 }
1247
1248 /* Calculate the required buffer size */
1249 Size = 0;
1250 if (prefmaxlen == -1)
1251 {
1252 Size = EnumContext->MemberCount *
1253 ((level == 0) ? sizeof(GROUP_USERS_INFO_0) : sizeof(GROUP_USERS_INFO_1));
1254 for (i = EnumContext->Start; i < EnumContext->MemberCount; i++)
1255 Size += EnumContext->Names[i].Length + sizeof(WCHAR);
1256
1257 EnumContext->Count = EnumContext->MemberCount;
1258 }
1259 else
1260 {
1261 for (i = EnumContext->Start; i < EnumContext->MemberCount; i++)
1262 {
1263 Size += (level == 0) ? sizeof(GROUP_USERS_INFO_0) : sizeof(GROUP_USERS_INFO_1);
1264 Size += EnumContext->Names[i].Length + sizeof(WCHAR);
1265
1266 EnumContext->Count++;
1267
1268 if (Size >= prefmaxlen)
1269 break;
1270 }
1271 }
1272
1273 TRACE("Buffer size: %lu\n", Size);
1274
1275 /* Allocate and clear the buffer */
1276 ApiStatus = NetApiBufferAllocate(Size, &Buffer);
1277 if (ApiStatus != NERR_Success)
1278 goto done;
1279
1281
1282 /* Fill the buffer */
1283 if (level == 0)
1284 Ptr = (PWCHAR)((LONG_PTR)Buffer + EnumContext->Count * sizeof(GROUP_USERS_INFO_0));
1285 else
1286 Ptr = (PWCHAR)((LONG_PTR)Buffer + EnumContext->Count * sizeof(GROUP_USERS_INFO_1));
1287
1288 for (i = 0; i < EnumContext->Count; i++)
1289 {
1290 idx = EnumContext->Start + i;
1291
1292 if (level == 0)
1293 {
1294 UserInfo0 = (PGROUP_USERS_INFO_0)Buffer;
1295
1296 UserInfo0[i].grui0_name = Ptr;
1297
1298 memcpy(UserInfo0[i].grui0_name,
1299 EnumContext->Names[idx].Buffer,
1300 EnumContext->Names[idx].Length);
1301 UserInfo0[i].grui0_name[EnumContext->Names[idx].Length / sizeof(WCHAR)] = UNICODE_NULL;
1302
1303 Ptr = (PWSTR)((ULONG_PTR)Ptr + EnumContext->Names[idx].Length + sizeof(WCHAR));
1304 }
1305 else
1306 {
1307 UserInfo1 = (PGROUP_USERS_INFO_1)Buffer;
1308
1309 UserInfo1[i].grui1_name = Ptr;
1310
1311 memcpy(UserInfo1[i].grui1_name,
1312 EnumContext->Names[idx].Buffer,
1313 EnumContext->Names[idx].Length);
1314 UserInfo1[i].grui1_name[EnumContext->Names[idx].Length / sizeof(WCHAR)] = UNICODE_NULL;
1315
1316 UserInfo1[i].grui1_attributes = EnumContext->Attributes[idx];
1317
1318 Ptr = (PWSTR)((ULONG_PTR)Ptr + EnumContext->Names[idx].Length + sizeof(WCHAR));
1319 }
1320 }
1321
1322 /* Set the new start index */
1323 EnumContext->Start += EnumContext->Count;
1324
1325 /* Only return ERROR_MORE_DATA if we are not done yet */
1326 if (EnumContext->MemberCount > EnumContext->Start)
1327 ApiStatus = ERROR_MORE_DATA;
1328 else
1329 ApiStatus = NERR_Success;
1330
1331done:
1332 if (EnumContext != NULL)
1333 {
1334 *entriesread = EnumContext->Count;
1335 *totalentries = EnumContext->MemberCount;
1336 }
1337
1338 if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
1339 {
1340 if (EnumContext != NULL)
1341 {
1342 if (EnumContext->Names != NULL)
1343 {
1344 for (i = 0; i < EnumContext->MemberCount; i++)
1345 SamFreeMemory(EnumContext->Names[i].Buffer);
1346
1347 SamFreeMemory(EnumContext->Names);
1348 }
1349
1350 if (EnumContext->Attributes != NULL)
1351 SamFreeMemory(EnumContext->Attributes);
1352
1353 if (EnumContext->MemberIds != NULL)
1354 SamFreeMemory(EnumContext->MemberIds);
1355
1356
1357 if (EnumContext->GroupHandle != NULL)
1358 SamCloseHandle(EnumContext->GroupHandle);
1359
1360 if (EnumContext->DomainHandle != NULL)
1361 SamCloseHandle(EnumContext->DomainHandle);
1362
1363 if (EnumContext->ServerHandle != NULL)
1364 SamCloseHandle(EnumContext->ServerHandle);
1365
1366 NetApiBufferFree(EnumContext);
1367 EnumContext = NULL;
1368 }
1369 }
1370
1371 *bufptr = (LPBYTE)Buffer;
1372
1373 if (resume_handle != NULL)
1374 *resume_handle = (DWORD_PTR)EnumContext;
1375
1376 return ApiStatus;
1377}
unsigned int idx
Definition: utils.c:41
struct _USER_ENUM_CONTEXT * PUSER_ENUM_CONTEXT
struct _GROUP_USERS_INFO_1 GROUP_USERS_INFO_1
struct _GROUP_USERS_INFO_0 * PGROUP_USERS_INFO_0
struct _GROUP_USERS_INFO_0 GROUP_USERS_INFO_0
struct _GROUP_USERS_INFO_1 * PGROUP_USERS_INFO_1
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GROUP_LIST_MEMBERS
Definition: ntsam.h:79
NTSTATUS NTAPI SamLookupIdsInDomain(IN SAM_HANDLE DomainHandle, IN ULONG Count, IN PULONG RelativeIds, OUT PUNICODE_STRING *Names, OUT PSID_NAME_USE *Use OPTIONAL)
Definition: samlib.c:1256
NTSTATUS NTAPI SamGetMembersInGroup(IN SAM_HANDLE GroupHandle, OUT PULONG *MemberIds, OUT PULONG *Attributes, OUT PULONG MemberCount)
Definition: samlib.c:1180
DWORD grui1_attributes
Definition: lmaccess.h:503
SAM_HANDLE GroupHandle
Definition: group_new.c:39
PUNICODE_STRING Names
Definition: group_new.c:44
SAM_HANDLE DomainHandle
Definition: group_new.c:38
SAM_HANDLE ServerHandle
Definition: group_new.c:37
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by DisplayGroup().

◆ NetGroupSetInfo()

NET_API_STATUS WINAPI NetGroupSetInfo ( _In_opt_ LPCWSTR  servername,
_In_ LPCWSTR  groupname,
_In_ DWORD  level,
_In_ LPBYTE  buf,
_Out_opt_ LPDWORD  parm_err 
)

Definition at line 1382 of file group_new.c.

1388{
1389 UNICODE_STRING ServerName;
1390 UNICODE_STRING GroupName;
1391 SAM_HANDLE ServerHandle = NULL;
1392 SAM_HANDLE DomainHandle = NULL;
1393 SAM_HANDLE GroupHandle = NULL;
1394 GROUP_NAME_INFORMATION GroupNameInfo;
1395 GROUP_ADM_COMMENT_INFORMATION AdminCommentInfo;
1396 GROUP_ATTRIBUTE_INFORMATION AttributeInfo;
1397 NET_API_STATUS ApiStatus = NERR_Success;
1399
1400 TRACE("NetGroupSetInfo(%s, %s, %d, %p, %p)\n",
1401 debugstr_w(servername), debugstr_w(groupname), level, buf, parm_err);
1402
1403 if (parm_err != NULL)
1404 *parm_err = PARM_ERROR_NONE;
1405
1406 if (servername != NULL)
1407 RtlInitUnicodeString(&ServerName, servername);
1408
1409 RtlInitUnicodeString(&GroupName, groupname);
1410
1411 /* Connect to the SAM Server */
1412 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1413 &ServerHandle,
1415 NULL);
1416 if (!NT_SUCCESS(Status))
1417 {
1418 ERR("SamConnect failed (Status %08lx)\n", Status);
1419 ApiStatus = NetpNtStatusToApiStatus(Status);
1420 goto done;
1421 }
1422
1423 /* Open the Acount Domain */
1424 Status = OpenAccountDomain(ServerHandle,
1425 (servername != NULL) ? &ServerName : NULL,
1427 &DomainHandle);
1428 if (!NT_SUCCESS(Status))
1429 {
1430 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1431 ApiStatus = NetpNtStatusToApiStatus(Status);
1432 goto done;
1433 }
1434
1435 /* Open the group */
1436 ApiStatus = OpenGroupByName(DomainHandle,
1437 &GroupName,
1439 &GroupHandle,
1440 NULL);
1441 if (ApiStatus != NERR_Success)
1442 {
1443 WARN("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
1444 if (ApiStatus == ERROR_NONE_MAPPED)
1445 ApiStatus = NERR_GroupNotFound;
1446 goto done;
1447 }
1448
1449 switch (level)
1450 {
1451 case 0:
1452 /* Set the group name */
1453 RtlInitUnicodeString(&GroupNameInfo.Name,
1454 ((PGROUP_INFO_0)buf)->grpi0_name);
1455
1456 Status = SamSetInformationGroup(GroupHandle,
1458 &GroupNameInfo);
1459 if (!NT_SUCCESS(Status))
1460 {
1461 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1462 ApiStatus = NetpNtStatusToApiStatus(Status);
1463 goto done;
1464 }
1465 break;
1466
1467 case 1:
1468 /* Set the group name */
1469 RtlInitUnicodeString(&GroupNameInfo.Name,
1470 ((PGROUP_INFO_1)buf)->grpi1_name);
1471
1472 Status = SamSetInformationGroup(GroupHandle,
1474 &GroupNameInfo);
1475 if (!NT_SUCCESS(Status))
1476 {
1477 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1478 ApiStatus = NetpNtStatusToApiStatus(Status);
1479 goto done;
1480 }
1481
1482 /* Set the admin comment */
1483 RtlInitUnicodeString(&AdminCommentInfo.AdminComment,
1484 ((PGROUP_INFO_1)buf)->grpi1_comment);
1485
1486 Status = SamSetInformationGroup(GroupHandle,
1488 &AdminCommentInfo);
1489 if (!NT_SUCCESS(Status))
1490 {
1491 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1492 ApiStatus = NetpNtStatusToApiStatus(Status);
1493 goto done;
1494 }
1495 break;
1496
1497 case 2:
1498 /* Set the group name */
1499 RtlInitUnicodeString(&GroupNameInfo.Name,
1500 ((PGROUP_INFO_2)buf)->grpi2_name);
1501
1502 Status = SamSetInformationGroup(GroupHandle,
1504 &GroupNameInfo);
1505 if (!NT_SUCCESS(Status))
1506 {
1507 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1508 ApiStatus = NetpNtStatusToApiStatus(Status);
1509 goto done;
1510 }
1511
1512 /* Set the admin comment */
1513 RtlInitUnicodeString(&AdminCommentInfo.AdminComment,
1514 ((PGROUP_INFO_2)buf)->grpi2_comment);
1515
1516 Status = SamSetInformationGroup(GroupHandle,
1518 &AdminCommentInfo);
1519 if (!NT_SUCCESS(Status))
1520 {
1521 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1522 ApiStatus = NetpNtStatusToApiStatus(Status);
1523 goto done;
1524 }
1525
1526 /* Set the attributes */
1527 AttributeInfo.Attributes = ((PGROUP_INFO_2)buf)->grpi2_attributes;
1528
1529 Status = SamSetInformationGroup(GroupHandle,
1531 &AttributeInfo);
1532 if (!NT_SUCCESS(Status))
1533 {
1534 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1535 ApiStatus = NetpNtStatusToApiStatus(Status);
1536 goto done;
1537 }
1538 break;
1539
1540 case 3:
1541 /* Set the group name */
1542 RtlInitUnicodeString(&GroupNameInfo.Name,
1543 ((PGROUP_INFO_3)buf)->grpi3_name);
1544
1545 Status = SamSetInformationGroup(GroupHandle,
1547 &GroupNameInfo);
1548 if (!NT_SUCCESS(Status))
1549 {
1550 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1551 ApiStatus = NetpNtStatusToApiStatus(Status);
1552 goto done;
1553 }
1554
1555 /* Set the admin comment */
1556 RtlInitUnicodeString(&AdminCommentInfo.AdminComment,
1557 ((PGROUP_INFO_3)buf)->grpi3_comment);
1558
1559 Status = SamSetInformationGroup(GroupHandle,
1561 &AdminCommentInfo);
1562 if (!NT_SUCCESS(Status))
1563 {
1564 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1565 ApiStatus = NetpNtStatusToApiStatus(Status);
1566 goto done;
1567 }
1568
1569 /* Set the attributes */
1570 AttributeInfo.Attributes = ((PGROUP_INFO_3)buf)->grpi3_attributes;
1571
1572 Status = SamSetInformationGroup(GroupHandle,
1574 &AttributeInfo);
1575 if (!NT_SUCCESS(Status))
1576 {
1577 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1578 ApiStatus = NetpNtStatusToApiStatus(Status);
1579 goto done;
1580 }
1581 break;
1582
1583 case 1002:
1584 /* Set the admin comment */
1585 RtlInitUnicodeString(&AdminCommentInfo.AdminComment,
1586 ((PGROUP_INFO_1002)buf)->grpi1002_comment);
1587
1588 Status = SamSetInformationGroup(GroupHandle,
1590 &AdminCommentInfo);
1591 if (!NT_SUCCESS(Status))
1592 {
1593 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1594 ApiStatus = NetpNtStatusToApiStatus(Status);
1595 goto done;
1596 }
1597 break;
1598
1599 case 1005:
1600 /* Set the attributes */
1601 AttributeInfo.Attributes = ((PGROUP_INFO_1005)buf)->grpi1005_attributes;
1602
1603 Status = SamSetInformationGroup(GroupHandle,
1605 &AttributeInfo);
1606 if (!NT_SUCCESS(Status))
1607 {
1608 ERR("SamSetInformationGroup failed (ApiStatus %lu)\n", ApiStatus);
1609 ApiStatus = NetpNtStatusToApiStatus(Status);
1610 goto done;
1611 }
1612 break;
1613
1614 default:
1615 ApiStatus = ERROR_INVALID_LEVEL;
1616 goto done;
1617 }
1618
1619done:
1620 if (GroupHandle != NULL)
1621 SamCloseHandle(GroupHandle);
1622
1623 if (DomainHandle != NULL)
1624 SamCloseHandle(DomainHandle);
1625
1626 if (ServerHandle != NULL)
1627 SamCloseHandle(ServerHandle);
1628
1629 return ApiStatus;
1630}
#define WARN(fmt,...)
Definition: debug.h:112
struct _GROUP_INFO_1005 * PGROUP_INFO_1005
@ GroupNameInformation
Definition: ntsam.h:465
UNICODE_STRING Name
Definition: ntsam.h:481

Referenced by cmdGroup().

◆ NetGroupSetUsers()

NET_API_STATUS WINAPI NetGroupSetUsers ( _In_opt_ LPCWSTR  servername,
_In_ LPCWSTR  groupname,
_In_ DWORD  level,
_In_ LPBYTE  buf,
_In_ DWORD  totalentries 
)

Definition at line 1635 of file group_new.c.

1641{
1642 UNICODE_STRING ServerName;
1643 UNICODE_STRING GroupName;
1644 SAM_HANDLE ServerHandle = NULL;
1645 SAM_HANDLE DomainHandle = NULL;
1646 SAM_HANDLE GroupHandle = NULL;
1647 ULONG OldMemberCount = 0;
1648 PULONG OldMemberIDs = NULL;
1649 PULONG OldAttributes = NULL;
1650 PUNICODE_STRING NamesArray = NULL;
1651 PGROUP_USERS_INFO_0 UserInfo0;
1652 PGROUP_USERS_INFO_1 UserInfo1;
1653 PULONG NewMemberIDs = NULL;
1654 PSID_NAME_USE NewMemberUse = NULL;
1655 ULONG i, j;
1656 BOOL Found;
1657 NET_API_STATUS ApiStatus = NERR_Success;
1659
1660 TRACE("NetGroupSetUsers(%s, %s, %d, %p, %d) stub!\n",
1661 debugstr_w(servername), debugstr_w(groupname), level, buf, totalentries);
1662
1663 if (servername != NULL)
1664 RtlInitUnicodeString(&ServerName, servername);
1665
1666 RtlInitUnicodeString(&GroupName, groupname);
1667
1668 /* Connect to the SAM Server */
1669 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1670 &ServerHandle,
1672 NULL);
1673 if (!NT_SUCCESS(Status))
1674 {
1675 ERR("SamConnect failed (Status %08lx)\n", Status);
1676 ApiStatus = NetpNtStatusToApiStatus(Status);
1677 goto done;
1678 }
1679
1680 /* Open the Acount Domain */
1681 Status = OpenAccountDomain(ServerHandle,
1682 (servername != NULL) ? &ServerName : NULL,
1684 &DomainHandle);
1685 if (!NT_SUCCESS(Status))
1686 {
1687 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1688 ApiStatus = NetpNtStatusToApiStatus(Status);
1689 goto done;
1690 }
1691
1692 /* Open the group account in the account domain */
1693 ApiStatus = OpenGroupByName(DomainHandle,
1694 &GroupName,
1696 &GroupHandle,
1697 NULL);
1698 if (ApiStatus != NERR_Success)
1699 {
1700 ERR("OpenGroupByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
1701 if (ApiStatus == ERROR_NONE_MAPPED)
1702 ApiStatus = NERR_GroupNotFound;
1703 goto done;
1704 }
1705
1706 /* Get the group members */
1707 Status = SamGetMembersInGroup(GroupHandle,
1708 &OldMemberIDs,
1709 &OldAttributes,
1710 &OldMemberCount);
1711 if (!NT_SUCCESS(Status))
1712 {
1713 ERR("SamGetMembersInGroup failed (Status %08lx)\n", Status);
1714 ApiStatus = NetpNtStatusToApiStatus(Status);
1715 goto done;
1716 }
1717
1718 NamesArray = RtlAllocateHeap(RtlGetProcessHeap(),
1720 totalentries * sizeof(UNICODE_STRING));
1721 if (NamesArray == NULL)
1722 {
1723 ERR("RtlAllocateHeap failed\n");
1724 ApiStatus = ERROR_OUTOFMEMORY;
1725 goto done;
1726 }
1727
1728 UserInfo0 = (PGROUP_USERS_INFO_0)buf;
1729 UserInfo1 = (PGROUP_USERS_INFO_1)buf;
1730 for (i = 0; i < totalentries; i++)
1731 {
1732 if (level == 0)
1733 RtlInitUnicodeString(&NamesArray[i], UserInfo0[i].grui0_name);
1734 else
1735 RtlInitUnicodeString(&NamesArray[i], UserInfo1[i].grui1_name);
1736 }
1737
1738 Status = SamLookupNamesInDomain(DomainHandle,
1739 totalentries,
1740 NamesArray,
1741 &NewMemberIDs,
1742 &NewMemberUse);
1743 if (!NT_SUCCESS(Status))
1744 {
1745 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
1746
1748 {
1749 ApiStatus = NERR_UserNotFound;
1750 goto done;
1751 }
1752
1753 ApiStatus = NetpNtStatusToApiStatus(Status);
1754 goto done;
1755 }
1756
1757 /* Add members and set attributes for existing members */
1758 for (i = 0; i < totalentries; i++)
1759 {
1760 Found = FALSE;
1761 for (j = 0; j < OldMemberCount; j++)
1762 {
1763 if (NewMemberIDs[i] == OldMemberIDs[j])
1764 {
1765 if (level == 1)
1766 {
1768 NewMemberIDs[i],
1769 UserInfo1[i].grui1_attributes);
1770 if (!NT_SUCCESS(Status))
1771 {
1772 ERR("SamSetMemberAttributesOfGroup failed (Status %lu)\n", Status);
1773 ApiStatus = NetpNtStatusToApiStatus(Status);
1774 goto done;
1775 }
1776 }
1777
1778 Found = TRUE;
1779 break;
1780 }
1781 }
1782
1783 if (Found == FALSE)
1784 {
1785 TRACE("Add member %lx\n", NewMemberIDs[i]);
1786
1787 if (NewMemberUse[i] != SidTypeUser)
1788 {
1789 ERR("New member is not a user!\n");
1790 ApiStatus = NERR_GroupNotFound;
1791 goto done;
1792 }
1793
1794 Status = SamAddMemberToGroup(GroupHandle,
1795 NewMemberIDs[i],
1796 (level == 0) ? 0 : UserInfo1[i].grui1_attributes);
1797 if (!NT_SUCCESS(Status))
1798 {
1799 ERR("SamAddMemberToGroup failed (Status %lu)\n", Status);
1800 ApiStatus = NetpNtStatusToApiStatus(Status);
1801 goto done;
1802 }
1803 }
1804 }
1805
1806 /* Remove members */
1807 for (i = 0; i < OldMemberCount; i++)
1808 {
1809 Found = FALSE;
1810 for (j = 0; j < totalentries; j++)
1811 {
1812 if (OldMemberIDs[i] == NewMemberIDs[j])
1813 {
1814 Found = TRUE;
1815 break;
1816 }
1817 }
1818
1819 if (Found == FALSE)
1820 {
1821 TRACE("Delete member %lx\n", OldMemberIDs[i]);
1822
1823 Status = SamRemoveMemberFromGroup(GroupHandle,
1824 OldMemberIDs[i]);
1825 if (!NT_SUCCESS(Status))
1826 {
1827 ERR("SamRemoveMemberFromGroup failed (Status %lu)\n", Status);
1828 ApiStatus = NetpNtStatusToApiStatus(Status);
1829 goto done;
1830 }
1831 }
1832 }
1833
1834done:
1835 if (NewMemberUse != NULL)
1836 SamFreeMemory(NewMemberUse);
1837
1838 if (NewMemberIDs != NULL)
1839 SamFreeMemory(NewMemberIDs);
1840
1841 if (NamesArray != NULL)
1842 RtlFreeHeap(RtlGetProcessHeap(), 0, NamesArray);
1843
1844 if (OldMemberIDs != NULL)
1845 SamFreeMemory(OldMemberIDs);
1846
1847 if (GroupHandle != NULL)
1848 SamCloseHandle(GroupHandle);
1849
1850 if (DomainHandle != NULL)
1851 SamCloseHandle(DomainHandle);
1852
1853 if (ServerHandle != NULL)
1854 SamCloseHandle(ServerHandle);
1855
1856 return ApiStatus;
1857}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
return Found
Definition: dirsup.c:1270
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
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 GLint GLint j
Definition: glfuncs.h:250
#define NERR_UserNotFound
Definition: lmerr.h:88
#define STATUS_NONE_MAPPED
Definition: ntstatus.h:351
NTSTATUS NTAPI SamSetMemberAttributesOfGroup(IN SAM_HANDLE GroupHandle, IN ULONG MemberId, IN ULONG Attributes)
Definition: samlib.c:2205

◆ OpenGroupByName()

static NET_API_STATUS OpenGroupByName ( _In_ SAM_HANDLE  DomainHandle,
_In_ PUNICODE_STRING  GroupName,
_In_ ULONG  DesiredAccess,
_Out_ PSAM_HANDLE  GroupHandle,
_Out_ PULONG  RelativeId 
)
static

Definition at line 224 of file group_new.c.

230{
231 PULONG RelativeIds = NULL;
232 PSID_NAME_USE Use = NULL;
233 NET_API_STATUS ApiStatus = NERR_Success;
235
236 /* Get the RID for the given user name */
237 Status = SamLookupNamesInDomain(DomainHandle,
238 1,
239 GroupName,
240 &RelativeIds,
241 &Use);
242 if (!NT_SUCCESS(Status))
243 {
244 WARN("SamLookupNamesInDomain(%wZ) failed (Status %08lx)\n", GroupName, Status);
246 }
247
248 /* Fail, if it is not an alias account */
249 if (Use[0] != SidTypeGroup)
250 {
251 ERR("Object is not a group!\n");
252 ApiStatus = NERR_GroupNotFound;
253 goto done;
254 }
255
256 /* Open the alias account */
257 Status = SamOpenGroup(DomainHandle,
259 RelativeIds[0],
260 GroupHandle);
261 if (!NT_SUCCESS(Status))
262 {
263 ERR("SamOpenGroup failed (Status %08lx)\n", Status);
264 ApiStatus = NetpNtStatusToApiStatus(Status);
265 goto done;
266 }
267
268 if (RelativeId != NULL)
269 *RelativeId = RelativeIds[0];
270
271done:
272 if (RelativeIds != NULL)
273 SamFreeMemory(RelativeIds);
274
275 if (Use != NULL)
276 SamFreeMemory(Use);
277
278 return ApiStatus;
279}
@ SidTypeGroup
Definition: lsa.idl:119
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658

Referenced by NetGroupAdd(), NetGroupAddUser(), NetGroupDel(), NetGroupDelUser(), NetGroupGetInfo(), NetGroupGetUsers(), NetGroupSetInfo(), and NetGroupSetUsers().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( netapi32  )