ReactOS 0.4.16-dev-257-g6aa11ac
local_group.c File Reference
#include "netapi32.h"
Include dependency graph for local_group.c:

Go to the source code of this file.

Classes

struct  _ENUM_CONTEXT
 
struct  _MEMBER_ENUM_CONTEXT
 

Typedefs

typedef enum _ENUM_PHASE ENUM_PHASE
 
typedef struct _ENUM_CONTEXT ENUM_CONTEXT
 
typedef struct _ENUM_CONTEXTPENUM_CONTEXT
 
typedef struct _MEMBER_ENUM_CONTEXT MEMBER_ENUM_CONTEXT
 
typedef struct _MEMBER_ENUM_CONTEXTPMEMBER_ENUM_CONTEXT
 

Enumerations

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

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (netapi32)
 
static NET_API_STATUS BuildAliasInfoBuffer (PALIAS_GENERAL_INFORMATION AliasInfo, DWORD level, LPVOID *Buffer)
 
static VOID FreeAliasInfo (PALIAS_GENERAL_INFORMATION AliasInfo)
 
static NET_API_STATUS OpenAliasByName (SAM_HANDLE DomainHandle, PUNICODE_STRING AliasName, ULONG DesiredAccess, PSAM_HANDLE AliasHandle)
 
static NET_API_STATUS BuildSidListFromDomainAndName (IN PUNICODE_STRING ServerName, IN PLOCALGROUP_MEMBERS_INFO_3 buf, IN ULONG EntryCount, OUT PLOCALGROUP_MEMBERS_INFO_0 *MemberList)
 
NET_API_STATUS WINAPI NetLocalGroupAdd (LPCWSTR servername, DWORD level, LPBYTE buf, LPDWORD parm_err)
 
NET_API_STATUS WINAPI NetLocalGroupAddMember (LPCWSTR servername, LPCWSTR groupname, PSID membersid)
 
NET_API_STATUS WINAPI NetLocalGroupAddMembers (LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE buf, DWORD totalentries)
 
NET_API_STATUS WINAPI NetLocalGroupDel (LPCWSTR servername, LPCWSTR groupname)
 
NET_API_STATUS WINAPI NetLocalGroupDelMember (LPCWSTR servername, LPCWSTR groupname, PSID membersid)
 
NET_API_STATUS WINAPI NetLocalGroupDelMembers (LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE buf, DWORD totalentries)
 
NET_API_STATUS WINAPI NetLocalGroupEnum (LPCWSTR servername, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, PDWORD_PTR resumehandle)
 
NET_API_STATUS WINAPI NetLocalGroupGetInfo (LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE *bufptr)
 
NET_API_STATUS WINAPI NetLocalGroupGetMembers (LPCWSTR servername, LPCWSTR localgroupname, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, PDWORD_PTR resumehandle)
 
NET_API_STATUS WINAPI NetLocalGroupSetInfo (LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE buf, LPDWORD parm_err)
 
NET_API_STATUS WINAPI NetLocalGroupSetMembers (LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE buf, DWORD totalentries)
 

Typedef Documentation

◆ ENUM_CONTEXT

◆ ENUM_PHASE

◆ MEMBER_ENUM_CONTEXT

◆ PENUM_CONTEXT

◆ PMEMBER_ENUM_CONTEXT

Enumeration Type Documentation

◆ _ENUM_PHASE

Enumerator
BuiltinPhase 
AccountPhase 
DonePhase 
BuiltinPhase 
AccountPhase 
DonePhase 

Definition at line 25 of file local_group.c.

26{
enum _ENUM_PHASE ENUM_PHASE
@ AccountPhase
Definition: local_group.c:28
@ DonePhase
Definition: local_group.c:29
@ BuiltinPhase
Definition: local_group.c:27

Function Documentation

◆ BuildAliasInfoBuffer()

static NET_API_STATUS BuildAliasInfoBuffer ( PALIAS_GENERAL_INFORMATION  AliasInfo,
DWORD  level,
LPVOID Buffer 
)
static

Definition at line 64 of file local_group.c.

67{
68 LPVOID LocalBuffer = NULL;
69 PLOCALGROUP_INFO_0 LocalInfo0;
70 PLOCALGROUP_INFO_1 LocalInfo1;
71 LPWSTR Ptr;
72 ULONG Size = 0;
73 NET_API_STATUS ApiStatus = NERR_Success;
74
75 *Buffer = NULL;
76
77 switch (level)
78 {
79 case 0:
80 Size = sizeof(LOCALGROUP_INFO_0) +
81 AliasInfo->Name.Length + sizeof(WCHAR);
82 break;
83
84 case 1:
85 Size = sizeof(LOCALGROUP_INFO_1) +
86 AliasInfo->Name.Length + sizeof(WCHAR) +
87 AliasInfo->AdminComment.Length + sizeof(WCHAR);
88 break;
89
90 default:
91 ApiStatus = ERROR_INVALID_LEVEL;
92 goto done;
93 }
94
95 ApiStatus = NetApiBufferAllocate(Size, &LocalBuffer);
96 if (ApiStatus != NERR_Success)
97 goto done;
98
99 ZeroMemory(LocalBuffer, Size);
100
101 switch (level)
102 {
103 case 0:
104 LocalInfo0 = (PLOCALGROUP_INFO_0)LocalBuffer;
105
106 Ptr = (LPWSTR)((ULONG_PTR)LocalInfo0 + sizeof(LOCALGROUP_INFO_0));
107 LocalInfo0->lgrpi0_name = Ptr;
108
109 memcpy(LocalInfo0->lgrpi0_name,
110 AliasInfo->Name.Buffer,
111 AliasInfo->Name.Length);
112 LocalInfo0->lgrpi0_name[AliasInfo->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
113 break;
114
115 case 1:
116 LocalInfo1 = (PLOCALGROUP_INFO_1)LocalBuffer;
117
118 Ptr = (LPWSTR)((ULONG_PTR)LocalInfo1 + sizeof(LOCALGROUP_INFO_1));
119 LocalInfo1->lgrpi1_name = Ptr;
120
121 memcpy(LocalInfo1->lgrpi1_name,
122 AliasInfo->Name.Buffer,
123 AliasInfo->Name.Length);
124 LocalInfo1->lgrpi1_name[AliasInfo->Name.Length / sizeof(WCHAR)] = UNICODE_NULL;
125
126 Ptr = (LPWSTR)((ULONG_PTR)Ptr + AliasInfo->Name.Length + sizeof(WCHAR));
127 LocalInfo1->lgrpi1_comment = Ptr;
128
129 memcpy(LocalInfo1->lgrpi1_comment,
130 AliasInfo->AdminComment.Buffer,
131 AliasInfo->AdminComment.Length);
132 LocalInfo1->lgrpi1_comment[AliasInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
133 break;
134 }
135
136done:
137 if (ApiStatus == NERR_Success)
138 {
139 *Buffer = LocalBuffer;
140 }
141 else
142 {
143 if (LocalBuffer != NULL)
144 NetApiBufferFree(LocalBuffer);
145 }
146
147 return ApiStatus;
148}
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
GLint level
Definition: gl.h:1546
struct _LOCALGROUP_INFO_1 LOCALGROUP_INFO_1
struct _LOCALGROUP_INFO_1 * PLOCALGROUP_INFO_1
struct _LOCALGROUP_INFO_0 * PLOCALGROUP_INFO_0
struct _LOCALGROUP_INFO_0 LOCALGROUP_INFO_0
#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
UNICODE_STRING AdminComment
Definition: ntsam.h:288
UNICODE_STRING Name
Definition: ntsam.h:286
LPWSTR lgrpi0_name
Definition: lmaccess.h:506
LPWSTR lgrpi1_comment
Definition: lmaccess.h:510
LPWSTR lgrpi1_name
Definition: lmaccess.h:509
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:1737
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by NetLocalGroupEnum(), and NetLocalGroupGetInfo().

◆ BuildSidListFromDomainAndName()

static NET_API_STATUS BuildSidListFromDomainAndName ( IN PUNICODE_STRING  ServerName,
IN PLOCALGROUP_MEMBERS_INFO_3  buf,
IN ULONG  EntryCount,
OUT PLOCALGROUP_MEMBERS_INFO_0 MemberList 
)
static

Definition at line 222 of file local_group.c.

226{
229 PUNICODE_STRING NamesArray = NULL;
230 ULONG i;
233 PLOCALGROUP_MEMBERS_INFO_0 MemberBuffer = NULL;
234 NET_API_STATUS ApiStatus = NERR_Success;
236
237 ApiStatus = NetApiBufferAllocate(sizeof(UNICODE_STRING) * EntryCount,
238 (LPVOID*)&NamesArray);
239 if (ApiStatus != NERR_Success)
240 {
241 goto done;
242 }
243
244 for (i = 0; i < EntryCount; i++)
245 {
246 RtlInitUnicodeString(&NamesArray[i],
247 buf[i].lgrmi3_domainandname);
248 }
249
251 NULL,
252 0,
253 0,
254 NULL);
255
256 Status = LsaOpenPolicy(ServerName,
259 &LsaHandle);
260 if (!NT_SUCCESS(Status))
261 {
262 ApiStatus = NetpNtStatusToApiStatus(Status);
263 goto done;
264 }
265
267 EntryCount,
268 NamesArray,
269 &Domains,
270 &Sids);
271 if (!NT_SUCCESS(Status))
272 {
273 ApiStatus = NetpNtStatusToApiStatus(Status);
274 goto done;
275 }
276
277 ApiStatus = NetApiBufferAllocate(sizeof(LOCALGROUP_MEMBERS_INFO_0) * EntryCount,
278 (LPVOID*)&MemberBuffer);
279 if (ApiStatus != NERR_Success)
280 {
281 goto done;
282 }
283
284 for (i = 0; i < EntryCount; i++)
285 {
286 ApiStatus = BuildSidFromSidAndRid(Domains->Domains[Sids[i].DomainIndex].Sid,
287 Sids[i].RelativeId,
288 &MemberBuffer[i].lgrmi0_sid);
289 if (ApiStatus != NERR_Success)
290 {
291 goto done;
292 }
293 }
294
295done:
296 if (ApiStatus != NERR_Success)
297 {
298 if (MemberBuffer != NULL)
299 {
300 for (i = 0; i < EntryCount; i++)
301 {
302 if (MemberBuffer[i].lgrmi0_sid != NULL)
303 NetApiBufferFree(MemberBuffer[i].lgrmi0_sid);
304 }
305
306 NetApiBufferFree(MemberBuffer);
307 MemberBuffer = NULL;
308 }
309 }
310
311 if (Sids != NULL)
312 LsaFreeMemory(Sids);
313
314 if (Domains != NULL)
315 LsaFreeMemory(Domains);
316
317 if (LsaHandle != NULL)
319
320 if (NamesArray != NULL)
321 NetApiBufferFree(NamesArray);
322
323 *MemberList = MemberBuffer;
324
325 return ApiStatus;
326}
LONG NTSTATUS
Definition: precomp.h:26
HANDLE LsaHandle
Definition: wkssvc.c:41
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1183
NTSTATUS WINAPI LsaFreeMemory(IN PVOID Buffer)
Definition: lsa.c:701
NTSTATUS WINAPI LsaLookupNames(IN LSA_HANDLE PolicyHandle, IN ULONG Count, IN PLSA_UNICODE_STRING Names, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_SID *Sids)
Definition: lsa.c:855
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:194
NET_API_STATUS WINAPI NetpNtStatusToApiStatus(_In_ NTSTATUS Status)
Definition: misc.c:289
Status
Definition: gdiplustypes.h:25
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
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 InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NET_API_STATUS BuildSidFromSidAndRid(IN PSID SrcSid, IN ULONG RelativeId, OUT PSID *DestSid)
Definition: utils.c:177
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define POLICY_EXECUTE
Definition: ntsecapi.h:76
#define STATUS_SUCCESS
Definition: shellext.h:65
PLSA_TRUST_INFORMATION Domains
Definition: ntsecapi.h:408

Referenced by NetLocalGroupAddMembers(), and NetLocalGroupDelMembers().

◆ FreeAliasInfo()

static VOID FreeAliasInfo ( PALIAS_GENERAL_INFORMATION  AliasInfo)
static

Definition at line 153 of file local_group.c.

154{
155 if (AliasInfo->Name.Buffer != NULL)
156 SamFreeMemory(AliasInfo->Name.Buffer);
157
158 if (AliasInfo->AdminComment.Buffer != NULL)
160
161 SamFreeMemory(AliasInfo);
162}
NTSTATUS NTAPI SamFreeMemory(IN PVOID Buffer)
Definition: samlib.c:983

Referenced by NetLocalGroupEnum(), and NetLocalGroupGetInfo().

◆ NetLocalGroupAdd()

NET_API_STATUS WINAPI NetLocalGroupAdd ( LPCWSTR  servername,
DWORD  level,
LPBYTE  buf,
LPDWORD  parm_err 
)

Definition at line 334 of file local_group.c.

339{
341 UNICODE_STRING ServerName;
342 UNICODE_STRING AliasName;
343 SAM_HANDLE ServerHandle = NULL;
344 SAM_HANDLE DomainHandle = NULL;
345 SAM_HANDLE AliasHandle = NULL;
346 LPWSTR aliasname = NULL;
347 LPWSTR aliascomment = NULL;
348 ULONG RelativeId;
349 NET_API_STATUS ApiStatus = NERR_Success;
351
352 TRACE("(%s %d %p %p) stub!\n", debugstr_w(servername), level, buf,
353 parm_err);
354
355 if (parm_err != NULL)
356 *parm_err = PARM_ERROR_NONE;
357
358 /* Initialize the Server name*/
359 if (servername != NULL)
360 RtlInitUnicodeString(&ServerName, servername);
361
362 /* Initialize the Alias name*/
363 switch (level)
364 {
365 case 0:
366 aliasname = ((PLOCALGROUP_INFO_0)buf)->lgrpi0_name;
367 aliascomment = NULL;
368 break;
369
370 case 1:
371 aliasname = ((PLOCALGROUP_INFO_1)buf)->lgrpi1_name;
372 aliascomment = ((PLOCALGROUP_INFO_1)buf)->lgrpi1_comment;
373 break;
374
375 default:
376 return ERROR_INVALID_LEVEL;
377 }
378
379 RtlInitUnicodeString(&AliasName, aliasname);
380
381 /* Connect to the SAM Server */
382 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
383 &ServerHandle,
385 NULL);
386 if (!NT_SUCCESS(Status))
387 {
388 ERR("SamConnect failed (Status %08lx)\n", Status);
389 ApiStatus = NetpNtStatusToApiStatus(Status);
390 goto done;
391 }
392
393 /* Open the Builtin Domain */
394 Status = OpenBuiltinDomain(ServerHandle,
396 &DomainHandle);
397 if (!NT_SUCCESS(Status))
398 {
399 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
400 ApiStatus = NetpNtStatusToApiStatus(Status);
401 goto done;
402 }
403
404 /* Try to open the Alias Account in the Builtin Domain */
405 ApiStatus = OpenAliasByName(DomainHandle,
406 &AliasName,
408 &AliasHandle);
409 if (ApiStatus == NERR_Success)
410 {
411 ERR("OpenAliasByName: alias %wZ already exists!\n", &AliasName);
412
413 SamCloseHandle(AliasHandle);
414 ApiStatus = ERROR_ALIAS_EXISTS;
415 goto done;
416 }
417
418 ApiStatus = NERR_Success;
419
420 /* Close the Builtin Domain */
421 SamCloseHandle(DomainHandle);
422 DomainHandle = NULL;
423
424 /* Open the account domain */
425 Status = OpenAccountDomain(ServerHandle,
426 (servername != NULL) ? &ServerName : NULL,
428 &DomainHandle);
429 if (!NT_SUCCESS(Status))
430 {
431 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
432 ApiStatus = NetpNtStatusToApiStatus(Status);
433 goto done;
434 }
435
436 /* Create the alias */
437 Status = SamCreateAliasInDomain(DomainHandle,
438 &AliasName,
440 &AliasHandle,
441 &RelativeId);
442 if (!NT_SUCCESS(Status))
443 {
444 ERR("SamCreateAliasInDomain failed (Status %08lx)\n", Status);
445 ApiStatus = NetpNtStatusToApiStatus(Status);
446 goto done;
447 }
448
449 TRACE("Created alias \"%wZ\" (RID: %lu)\n", &AliasName, RelativeId);
450
451 /* Set the admin comment */
452 if (level == 1)
453 {
454 RtlInitUnicodeString(&AdminComment.AdminComment, aliascomment);
455
456 Status = SamSetInformationAlias(AliasHandle,
458 &AdminComment);
459 if (!NT_SUCCESS(Status))
460 {
461 ERR("SamSetInformationAlias failed (Status %08lx)\n", Status);
462 ApiStatus = NetpNtStatusToApiStatus(Status);
463
464 /* Delete the Alias if the Comment could not be set */
465 SamDeleteAlias(AliasHandle);
466
467 goto done;
468 }
469 }
470
471done:
472 if (AliasHandle != NULL)
473 {
474 if (ApiStatus != NERR_Success)
475 SamDeleteAlias(AliasHandle);
476 else
477 SamCloseHandle(AliasHandle);
478 }
479
480 if (DomainHandle != NULL)
481 SamCloseHandle(DomainHandle);
482
483 if (ServerHandle != NULL)
484 SamCloseHandle(ServerHandle);
485
486 return ApiStatus;
487}
#define ERR(fmt,...)
Definition: precomp.h:57
#define debugstr_w
Definition: kernel32.h:32
#define PARM_ERROR_NONE
Definition: lmcons.h:56
static NET_API_STATUS OpenAliasByName(SAM_HANDLE DomainHandle, PUNICODE_STRING AliasName, ULONG DesiredAccess, PSAM_HANDLE AliasHandle)
Definition: local_group.c:167
NTSTATUS OpenBuiltinDomain(IN SAM_HANDLE ServerHandle, IN ULONG DesiredAccess, OUT SAM_HANDLE *DomainHandle)
NTSTATUS OpenAccountDomain(IN SAM_HANDLE ServerHandle, IN PUNICODE_STRING ServerName, IN ULONG DesiredAccess, OUT PSAM_HANDLE DomainHandle)
Definition: utils.c:113
#define DELETE
Definition: nt_native.h:57
@ AliasAdminCommentInformation
Definition: ntsam.h:281
#define DOMAIN_LOOKUP
Definition: ntsam.h:42
#define DOMAIN_CREATE_ALIAS
Definition: ntsam.h:39
#define SAM_SERVER_LOOKUP_DOMAIN
Definition: ntsam.h:104
#define ALIAS_WRITE_ACCOUNT
Definition: ntsam.h:13
#define SAM_SERVER_CONNECT
Definition: ntsam.h:99
#define ALIAS_READ_INFORMATION
Definition: ntsam.h:12
NTSTATUS NTAPI SamSetInformationAlias(IN SAM_HANDLE AliasHandle, IN ALIAS_INFORMATION_CLASS AliasInformationClass, IN PVOID Buffer)
Definition: samlib.c:1919
NTSTATUS NTAPI SamDeleteAlias(IN SAM_HANDLE AliasHandle)
Definition: samlib.c:704
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
NTSTATUS NTAPI SamCreateAliasInDomain(IN SAM_HANDLE DomainHandle, IN PUNICODE_STRING AccountName, IN ACCESS_MASK DesiredAccess, OUT PSAM_HANDLE AliasHandle, OUT PULONG RelativeId)
Definition: samlib.c:562
#define TRACE(s)
Definition: solgame.cpp:4
UNICODE_STRING AdminComment
Definition: ntsam.h:298
#define ERROR_ALIAS_EXISTS
Definition: winerror.h:860

Referenced by cmdLocalGroup(), and GroupNew().

◆ NetLocalGroupAddMember()

NET_API_STATUS WINAPI NetLocalGroupAddMember ( LPCWSTR  servername,
LPCWSTR  groupname,
PSID  membersid 
)

Definition at line 495 of file local_group.c.

499{
501
502 TRACE("(%s %s %p)\n", debugstr_w(servername),
503 debugstr_w(groupname), membersid);
504
505 Member.lgrmi0_sid = membersid;
506
507 return NetLocalGroupAddMembers(servername,
508 groupname,
509 0,
510 (LPBYTE)&Member,
511 1);
512}
NET_API_STATUS WINAPI NetLocalGroupAddMembers(LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE buf, DWORD totalentries)
Definition: local_group.c:520
unsigned char * LPBYTE
Definition: typedefs.h:53

◆ NetLocalGroupAddMembers()

NET_API_STATUS WINAPI NetLocalGroupAddMembers ( LPCWSTR  servername,
LPCWSTR  groupname,
DWORD  level,
LPBYTE  buf,
DWORD  totalentries 
)

Definition at line 520 of file local_group.c.

526{
527 UNICODE_STRING ServerName;
528 UNICODE_STRING AliasName;
529 SAM_HANDLE ServerHandle = NULL;
530 SAM_HANDLE DomainHandle = NULL;
531 SAM_HANDLE AliasHandle = NULL;
532 PLOCALGROUP_MEMBERS_INFO_0 MemberList = NULL;
533 ULONG i;
534 NET_API_STATUS ApiStatus = NERR_Success;
536
537 TRACE("(%s %s %d %p %d)\n", debugstr_w(servername),
538 debugstr_w(groupname), level, buf, totalentries);
539
540 if (servername != NULL)
541 RtlInitUnicodeString(&ServerName, servername);
542
543 RtlInitUnicodeString(&AliasName, groupname);
544
545 switch (level)
546 {
547 case 0:
548 MemberList = (PLOCALGROUP_MEMBERS_INFO_0)buf;
549 break;
550
551 case 3:
552 Status = BuildSidListFromDomainAndName((servername != NULL) ? &ServerName : NULL,
554 totalentries,
555 &MemberList);
556 if (!NT_SUCCESS(Status))
557 {
558 ERR("BuildSidListFromDomainAndName failed (Status %08lx)\n", Status);
559 ApiStatus = NetpNtStatusToApiStatus(Status);
560 goto done;
561 }
562 break;
563
564 default:
565 ApiStatus = ERROR_INVALID_LEVEL;
566 goto done;
567 }
568
569 /* Connect to the SAM Server */
570 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
571 &ServerHandle,
573 NULL);
574 if (!NT_SUCCESS(Status))
575 {
576 ERR("SamConnect failed (Status %08lx)\n", Status);
577 ApiStatus = NetpNtStatusToApiStatus(Status);
578 goto done;
579 }
580
581 /* Open the Builtin Domain */
582 Status = OpenBuiltinDomain(ServerHandle,
584 &DomainHandle);
585 if (!NT_SUCCESS(Status))
586 {
587 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
588 ApiStatus = NetpNtStatusToApiStatus(Status);
589 goto done;
590 }
591
592 /* Open the alias account in the builtin domain */
593 ApiStatus = OpenAliasByName(DomainHandle,
594 &AliasName,
596 &AliasHandle);
597 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
598 {
599 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
600 goto done;
601 }
602
603 if (AliasHandle == NULL)
604 {
605 if (DomainHandle != NULL)
606 SamCloseHandle(DomainHandle);
607
608 /* Open the Acount Domain */
609 Status = OpenAccountDomain(ServerHandle,
610 (servername != NULL) ? &ServerName : NULL,
612 &DomainHandle);
613 if (!NT_SUCCESS(Status))
614 {
615 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
616 ApiStatus = NetpNtStatusToApiStatus(Status);
617 goto done;
618 }
619
620 /* Open the alias account in the account domain */
621 ApiStatus = OpenAliasByName(DomainHandle,
622 &AliasName,
624 &AliasHandle);
625 if (ApiStatus != NERR_Success)
626 {
627 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
628 if (ApiStatus == ERROR_NONE_MAPPED)
629 ApiStatus = NERR_GroupNotFound;
630 goto done;
631 }
632 }
633
634 /* Add new members to the alias */
635 for (i = 0; i < totalentries; i++)
636 {
637 Status = SamAddMemberToAlias(AliasHandle,
638 MemberList[i].lgrmi0_sid);
639 if (!NT_SUCCESS(Status))
640 {
641 ERR("SamAddMemberToAlias failed (Status %lu)\n", Status);
642 ApiStatus = NetpNtStatusToApiStatus(Status);
643 goto done;
644 }
645 }
646
647done:
648 if (level == 3 && MemberList != NULL)
649 {
650 for (i = 0; i < totalentries; i++)
651 {
652 if (MemberList[i].lgrmi0_sid != NULL)
653 NetApiBufferFree(MemberList[i].lgrmi0_sid);
654 }
655
656 NetApiBufferFree(MemberList);
657 }
658
659 if (AliasHandle != NULL)
660 SamCloseHandle(AliasHandle);
661
662 if (DomainHandle != NULL)
663 SamCloseHandle(DomainHandle);
664
665 if (ServerHandle != NULL)
666 SamCloseHandle(ServerHandle);
667
668 return ApiStatus;
669}
struct _LOCALGROUP_MEMBERS_INFO_0 * PLOCALGROUP_MEMBERS_INFO_0
#define NERR_GroupNotFound
Definition: lmerr.h:87
static NET_API_STATUS BuildSidListFromDomainAndName(IN PUNICODE_STRING ServerName, IN PLOCALGROUP_MEMBERS_INFO_3 buf, IN ULONG EntryCount, OUT PLOCALGROUP_MEMBERS_INFO_0 *MemberList)
Definition: local_group.c:222
#define ALIAS_ADD_MEMBER
Definition: ntsam.h:9
NTSTATUS NTAPI SamAddMemberToAlias(IN SAM_HANDLE AliasHandle, IN PSID MemberId)
Definition: samlib.c:235
#define ERROR_NONE_MAPPED
Definition: winerror.h:814

Referenced by AddSelectedGroupsToUser(), AddSelectedUsersToGroup(), cmdLocalGroup(), and NetLocalGroupAddMember().

◆ NetLocalGroupDel()

NET_API_STATUS WINAPI NetLocalGroupDel ( LPCWSTR  servername,
LPCWSTR  groupname 
)

Definition at line 677 of file local_group.c.

680{
681 UNICODE_STRING ServerName;
682 UNICODE_STRING GroupName;
683 SAM_HANDLE ServerHandle = NULL;
684 SAM_HANDLE DomainHandle = NULL;
685 SAM_HANDLE AliasHandle = NULL;
686 NET_API_STATUS ApiStatus = NERR_Success;
688
689 TRACE("(%s %s)\n", debugstr_w(servername), debugstr_w(groupname));
690
691 if (servername != NULL)
692 RtlInitUnicodeString(&ServerName, servername);
693
694 RtlInitUnicodeString(&GroupName, groupname);
695
696 /* Connect to the SAM Server */
697 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
698 &ServerHandle,
700 NULL);
701 if (!NT_SUCCESS(Status))
702 {
703 ERR("SamConnect failed (Status %08lx)\n", Status);
704 ApiStatus = NetpNtStatusToApiStatus(Status);
705 goto done;
706 }
707
708 /* Open the Builtin Domain */
709 Status = OpenBuiltinDomain(ServerHandle,
711 &DomainHandle);
712 if (!NT_SUCCESS(Status))
713 {
714 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
715 ApiStatus = NetpNtStatusToApiStatus(Status);
716 goto done;
717 }
718
719 /* Open the alias account in the builtin domain */
720 ApiStatus = OpenAliasByName(DomainHandle,
721 &GroupName,
722 DELETE,
723 &AliasHandle);
724 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
725 {
726 TRACE("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
727 goto done;
728 }
729
730 if (AliasHandle == NULL)
731 {
732 if (DomainHandle != NULL)
733 {
734 SamCloseHandle(DomainHandle);
735 DomainHandle = NULL;
736 }
737
738 /* Open the Acount Domain */
739 Status = OpenAccountDomain(ServerHandle,
740 (servername != NULL) ? &ServerName : NULL,
742 &DomainHandle);
743 if (!NT_SUCCESS(Status))
744 {
745 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
746 ApiStatus = NetpNtStatusToApiStatus(Status);
747 goto done;
748 }
749
750 /* Open the alias account in the account domain */
751 ApiStatus = OpenAliasByName(DomainHandle,
752 &GroupName,
753 DELETE,
754 &AliasHandle);
755 if (ApiStatus != NERR_Success)
756 {
757 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
758 if (ApiStatus == ERROR_NONE_MAPPED)
759 ApiStatus = NERR_GroupNotFound;
760 goto done;
761 }
762 }
763
764 /* Delete the alias */
765 Status = SamDeleteAlias(AliasHandle);
766 if (!NT_SUCCESS(Status))
767 {
768 ERR("SamDeleteAlias failed (Status %08lx)\n", Status);
769 ApiStatus = NetpNtStatusToApiStatus(Status);
770 goto done;
771 }
772
773done:
774 if (AliasHandle != NULL)
775 SamCloseHandle(AliasHandle);
776
777 if (DomainHandle != NULL)
778 SamCloseHandle(DomainHandle);
779
780 if (ServerHandle != NULL)
781 SamCloseHandle(ServerHandle);
782
783 return ApiStatus;
784}

Referenced by cmdLocalGroup(), and GroupDelete().

◆ NetLocalGroupDelMember()

NET_API_STATUS WINAPI NetLocalGroupDelMember ( LPCWSTR  servername,
LPCWSTR  groupname,
PSID  membersid 
)

Definition at line 792 of file local_group.c.

796{
798
799 TRACE("(%s %s %p)\n", debugstr_w(servername),
800 debugstr_w(groupname), membersid);
801
802 Member.lgrmi0_sid = membersid;
803
804 return NetLocalGroupDelMembers(servername,
805 groupname,
806 0,
807 (LPBYTE)&Member,
808 1);
809}
NET_API_STATUS WINAPI NetLocalGroupDelMembers(LPCWSTR servername, LPCWSTR groupname, DWORD level, LPBYTE buf, DWORD totalentries)
Definition: local_group.c:817

◆ NetLocalGroupDelMembers()

NET_API_STATUS WINAPI NetLocalGroupDelMembers ( LPCWSTR  servername,
LPCWSTR  groupname,
DWORD  level,
LPBYTE  buf,
DWORD  totalentries 
)

Definition at line 817 of file local_group.c.

823{
824 UNICODE_STRING ServerName;
825 UNICODE_STRING AliasName;
826 SAM_HANDLE ServerHandle = NULL;
827 SAM_HANDLE DomainHandle = NULL;
828 SAM_HANDLE AliasHandle = NULL;
829 PLOCALGROUP_MEMBERS_INFO_0 MemberList = NULL;
830 ULONG i;
831 NET_API_STATUS ApiStatus = NERR_Success;
833
834 TRACE("(%s %s %d %p %d)\n", debugstr_w(servername),
835 debugstr_w(groupname), level, buf, totalentries);
836
837 if (servername != NULL)
838 RtlInitUnicodeString(&ServerName, servername);
839
840 RtlInitUnicodeString(&AliasName, groupname);
841
842 switch (level)
843 {
844 case 0:
845 MemberList = (PLOCALGROUP_MEMBERS_INFO_0)buf;
846 break;
847
848 case 3:
849 Status = BuildSidListFromDomainAndName((servername != NULL) ? &ServerName : NULL,
851 totalentries,
852 &MemberList);
853 if (!NT_SUCCESS(Status))
854 {
855 ERR("BuildSidListFromDomainAndName failed (Status %08lx)\n", Status);
856 ApiStatus = NetpNtStatusToApiStatus(Status);
857 goto done;
858 }
859 break;
860
861 default:
862 ApiStatus = ERROR_INVALID_LEVEL;
863 goto done;
864 }
865
866 /* Connect to the SAM Server */
867 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
868 &ServerHandle,
870 NULL);
871 if (!NT_SUCCESS(Status))
872 {
873 ERR("SamConnect failed (Status %08lx)\n", Status);
874 ApiStatus = NetpNtStatusToApiStatus(Status);
875 goto done;
876 }
877
878 /* Open the Builtin Domain */
879 Status = OpenBuiltinDomain(ServerHandle,
881 &DomainHandle);
882 if (!NT_SUCCESS(Status))
883 {
884 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
885 ApiStatus = NetpNtStatusToApiStatus(Status);
886 goto done;
887 }
888
889 /* Open the alias account in the builtin domain */
890 ApiStatus = OpenAliasByName(DomainHandle,
891 &AliasName,
893 &AliasHandle);
894 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
895 {
896 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
897 goto done;
898 }
899
900 if (AliasHandle == NULL)
901 {
902 if (DomainHandle != NULL)
903 SamCloseHandle(DomainHandle);
904
905 /* Open the Acount Domain */
906 Status = OpenAccountDomain(ServerHandle,
907 (servername != NULL) ? &ServerName : NULL,
909 &DomainHandle);
910 if (!NT_SUCCESS(Status))
911 {
912 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
913 ApiStatus = NetpNtStatusToApiStatus(Status);
914 goto done;
915 }
916
917 /* Open the alias account in the account domain */
918 ApiStatus = OpenAliasByName(DomainHandle,
919 &AliasName,
921 &AliasHandle);
922 if (ApiStatus != NERR_Success)
923 {
924 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
925 if (ApiStatus == ERROR_NONE_MAPPED)
926 ApiStatus = NERR_GroupNotFound;
927 goto done;
928 }
929 }
930
931 /* Remove members from the alias */
932 for (i = 0; i < totalentries; i++)
933 {
934 Status = SamRemoveMemberFromAlias(AliasHandle,
935 MemberList[i].lgrmi0_sid);
936 if (!NT_SUCCESS(Status))
937 {
938 ERR("SamAddMemberToAlias failed (Status %lu)\n", Status);
939 ApiStatus = NetpNtStatusToApiStatus(Status);
940 goto done;
941 }
942 }
943
944done:
945 if (level == 3 && MemberList != NULL)
946 {
947 for (i = 0; i < totalentries; i++)
948 {
949 if (MemberList[i].lgrmi0_sid != NULL)
950 NetApiBufferFree(MemberList[i].lgrmi0_sid);
951 }
952
953 NetApiBufferFree(MemberList);
954 }
955
956 if (AliasHandle != NULL)
957 SamCloseHandle(AliasHandle);
958
959 if (DomainHandle != NULL)
960 SamCloseHandle(DomainHandle);
961
962 if (ServerHandle != NULL)
963 SamCloseHandle(ServerHandle);
964
965 return ApiStatus;
966}
#define ALIAS_REMOVE_MEMBER
Definition: ntsam.h:10
NTSTATUS NTAPI SamRemoveMemberFromAlias(IN SAM_HANDLE AliasHandle, IN PSID MemberId)
Definition: samlib.c:1800

Referenced by cmdLocalGroup(), NetLocalGroupDelMember(), RemoveGroupFromUser(), and RemoveUserFromGroup().

◆ NetLocalGroupEnum()

NET_API_STATUS WINAPI NetLocalGroupEnum ( LPCWSTR  servername,
DWORD  level,
LPBYTE bufptr,
DWORD  prefmaxlen,
LPDWORD  entriesread,
LPDWORD  totalentries,
PDWORD_PTR  resumehandle 
)

Definition at line 974 of file local_group.c.

982{
983 UNICODE_STRING ServerName;
984 PSAM_RID_ENUMERATION CurrentAlias;
985 PENUM_CONTEXT EnumContext = NULL;
986 ULONG i;
987 SAM_HANDLE AliasHandle = NULL;
990 NET_API_STATUS ApiStatus = NERR_Success;
992
993 TRACE("(%s %d %p %d %p %p %p) stub!\n", debugstr_w(servername),
994 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
995
996 *entriesread = 0;
997 *totalentries = 0;
998 *bufptr = NULL;
999
1000 if (servername != NULL)
1001 RtlInitUnicodeString(&ServerName, servername);
1002
1003 if (resumehandle != NULL && *resumehandle != 0)
1004 {
1005 EnumContext = (PENUM_CONTEXT)*resumehandle;
1006 }
1007 else
1008 {
1009 ApiStatus = NetApiBufferAllocate(sizeof(ENUM_CONTEXT), (PVOID*)&EnumContext);
1010 if (ApiStatus != NERR_Success)
1011 goto done;
1012
1013 EnumContext->EnumerationContext = 0;
1014 EnumContext->Buffer = NULL;
1015 EnumContext->Returned = 0;
1016 EnumContext->Index = 0;
1017
1018 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1019 &EnumContext->ServerHandle,
1021 NULL);
1022 if (!NT_SUCCESS(Status))
1023 {
1024 ERR("SamConnect failed (Status %08lx)\n", Status);
1025 ApiStatus = NetpNtStatusToApiStatus(Status);
1026 goto done;
1027 }
1028
1029 Status = OpenAccountDomain(EnumContext->ServerHandle,
1030 (servername != NULL) ? &ServerName : NULL,
1032 &EnumContext->AccountDomainHandle);
1033 if (!NT_SUCCESS(Status))
1034 {
1035 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1036 ApiStatus = NetpNtStatusToApiStatus(Status);
1037 goto done;
1038 }
1039
1040 Status = OpenBuiltinDomain(EnumContext->ServerHandle,
1042 &EnumContext->BuiltinDomainHandle);
1043 if (!NT_SUCCESS(Status))
1044 {
1045 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1046 ApiStatus = NetpNtStatusToApiStatus(Status);
1047 goto done;
1048 }
1049
1050 EnumContext->Phase = BuiltinPhase;
1051 EnumContext->DomainHandle = EnumContext->BuiltinDomainHandle;
1052 }
1053
1054
1055// while (TRUE)
1056// {
1057 TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
1058 TRACE("EnumContext->Returned: %lu\n", EnumContext->Returned);
1059
1060 if (EnumContext->Index >= EnumContext->Returned)
1061 {
1062 TRACE("Calling SamEnumerateAliasesInDomain\n");
1063
1065 &EnumContext->EnumerationContext,
1066 (PVOID *)&EnumContext->Buffer,
1067 prefmaxlen,
1068 &EnumContext->Returned);
1069
1070 TRACE("SamEnumerateAliasesInDomain returned (Status %08lx)\n", Status);
1071 if (!NT_SUCCESS(Status))
1072 {
1073 ERR("SamEnumerateAliasesInDomain failed (Status %08lx)\n", Status);
1074 ApiStatus = NetpNtStatusToApiStatus(Status);
1075 goto done;
1076 }
1077
1079 {
1080 ApiStatus = NERR_BufTooSmall;
1081 goto done;
1082 }
1083 }
1084
1085 TRACE("EnumContext: %lu\n", EnumContext);
1086 TRACE("EnumContext->Returned: %lu\n", EnumContext->Returned);
1087 TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
1088
1089 /* Get a pointer to the current alias */
1090 CurrentAlias = &EnumContext->Buffer[EnumContext->Index];
1091
1092 TRACE("RID: %lu\n", CurrentAlias->RelativeId);
1093
1094 Status = SamOpenAlias(EnumContext->DomainHandle,
1096 CurrentAlias->RelativeId,
1097 &AliasHandle);
1098 if (!NT_SUCCESS(Status))
1099 {
1100 ERR("SamOpenAlias failed (Status %08lx)\n", Status);
1101 ApiStatus = NetpNtStatusToApiStatus(Status);
1102 goto done;
1103 }
1104
1105 Status = SamQueryInformationAlias(AliasHandle,
1107 (PVOID *)&AliasInfo);
1108 if (!NT_SUCCESS(Status))
1109 {
1110 ERR("SamQueryInformationAlias failed (Status %08lx)\n", Status);
1111 ApiStatus = NetpNtStatusToApiStatus(Status);
1112 goto done;
1113 }
1114
1115 SamCloseHandle(AliasHandle);
1116 AliasHandle = NULL;
1117
1118 TRACE("Name: %S\n", AliasInfo->Name.Buffer);
1119 TRACE("Comment: %S\n", AliasInfo->AdminComment.Buffer);
1120
1121 ApiStatus = BuildAliasInfoBuffer(AliasInfo,
1122 level,
1123 &Buffer);
1124 if (ApiStatus != NERR_Success)
1125 goto done;
1126
1127 if (AliasInfo != NULL)
1128 {
1129 FreeAliasInfo(AliasInfo);
1130 AliasInfo = NULL;
1131 }
1132
1133 EnumContext->Index++;
1134
1135 (*entriesread)++;
1136
1137 if (EnumContext->Index == EnumContext->Returned)
1138 {
1139 switch (EnumContext->Phase)
1140 {
1141 case BuiltinPhase:
1142 EnumContext->Phase = AccountPhase;
1143 EnumContext->DomainHandle = EnumContext->AccountDomainHandle;
1144 EnumContext->EnumerationContext = 0;
1145 EnumContext->Index = 0;
1146 EnumContext->Returned = 0;
1147
1148 if (EnumContext->Buffer != NULL)
1149 {
1150 for (i = 0; i < EnumContext->Returned; i++)
1151 {
1152 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
1153 }
1154
1155 SamFreeMemory(EnumContext->Buffer);
1156 EnumContext->Buffer = NULL;
1157 }
1158 break;
1159
1160 case AccountPhase:
1161 case DonePhase:
1162 EnumContext->Phase = DonePhase;
1163 break;
1164 }
1165 }
1166// }
1167
1168done:
1169 if (ApiStatus == NERR_Success && EnumContext != NULL && EnumContext->Phase != DonePhase)
1170 ApiStatus = ERROR_MORE_DATA;
1171
1172 if (EnumContext != NULL)
1173 *totalentries = EnumContext->Returned;
1174
1175 if (resumehandle == NULL || ApiStatus != ERROR_MORE_DATA)
1176 {
1177 if (EnumContext != NULL)
1178 {
1179 if (EnumContext->BuiltinDomainHandle != NULL)
1180 SamCloseHandle(EnumContext->BuiltinDomainHandle);
1181
1182 if (EnumContext->AccountDomainHandle != NULL)
1183 SamCloseHandle(EnumContext->AccountDomainHandle);
1184
1185 if (EnumContext->ServerHandle != NULL)
1186 SamCloseHandle(EnumContext->ServerHandle);
1187
1188 if (EnumContext->Buffer != NULL)
1189 {
1190 for (i = 0; i < EnumContext->Returned; i++)
1191 {
1192 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
1193 }
1194
1195 SamFreeMemory(EnumContext->Buffer);
1196 }
1197
1198 NetApiBufferFree(EnumContext);
1199 EnumContext = NULL;
1200 }
1201 }
1202
1203 if (AliasHandle != NULL)
1204 SamCloseHandle(AliasHandle);
1205
1206 if (AliasInfo != NULL)
1207 FreeAliasInfo(AliasInfo);
1208
1209 if (resumehandle != NULL)
1210 *resumehandle = (DWORD_PTR)EnumContext;
1211
1212 *bufptr = (LPBYTE)Buffer;
1213
1214 TRACE ("return %lu\n", ApiStatus);
1215
1216 return ApiStatus;
1217}
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define NERR_BufTooSmall
Definition: lmerr.h:21
static VOID FreeAliasInfo(PALIAS_GENERAL_INFORMATION AliasInfo)
Definition: local_group.c:153
struct _ENUM_CONTEXT * PENUM_CONTEXT
static NET_API_STATUS BuildAliasInfoBuffer(PALIAS_GENERAL_INFORMATION AliasInfo, DWORD level, LPVOID *Buffer)
Definition: local_group.c:64
@ AliasGeneralInformation
Definition: ntsam.h:279
#define DOMAIN_LIST_ACCOUNTS
Definition: ntsam.h:41
NTSTATUS NTAPI SamOpenAlias(IN SAM_HANDLE DomainHandle, IN ACCESS_MASK DesiredAccess, IN ULONG AliasId, OUT PSAM_HANDLE AliasHandle)
Definition: samlib.c:1448
NTSTATUS NTAPI SamQueryInformationAlias(IN SAM_HANDLE AliasHandle, IN ALIAS_INFORMATION_CLASS AliasInformationClass, OUT PVOID *Buffer)
Definition: samlib.c:1650
NTSTATUS NTAPI SamEnumerateAliasesInDomain(IN SAM_HANDLE DomainHandle, IN OUT PSAM_ENUMERATE_HANDLE EnumerationContext, OUT PVOID *Buffer, IN ULONG PreferedMaximumLength, OUT PULONG CountReturned)
Definition: samlib.c:788
ULONG Returned
Definition: local_group.c:41
SAM_HANDLE BuiltinDomainHandle
Definition: local_group.c:36
ENUM_PHASE Phase
Definition: local_group.c:43
SAM_HANDLE AccountDomainHandle
Definition: local_group.c:37
SAM_HANDLE ServerHandle
Definition: local_group.c:34
SAM_ENUMERATE_HANDLE EnumerationContext
Definition: local_group.c:39
PSAM_RID_ENUMERATION Buffer
Definition: local_group.c:40
SAM_HANDLE DomainHandle
Definition: local_group.c:35
UNICODE_STRING Name
Definition: ntsam.h:268
static unsigned int bufptr
Definition: tncon.cpp:77
#define DWORD_PTR
Definition: treelist.c:76
#define STATUS_MORE_ENTRIES
Definition: udferr_usr.h:124

Referenced by EnumerateLocalGroups(), InitUserGroupsList(), and UpdateGroupsList().

◆ NetLocalGroupGetInfo()

NET_API_STATUS WINAPI NetLocalGroupGetInfo ( LPCWSTR  servername,
LPCWSTR  groupname,
DWORD  level,
LPBYTE bufptr 
)

Definition at line 1225 of file local_group.c.

1230{
1231 UNICODE_STRING ServerName;
1232 UNICODE_STRING GroupName;
1233 SAM_HANDLE ServerHandle = NULL;
1234 SAM_HANDLE DomainHandle = NULL;
1235 SAM_HANDLE AliasHandle = NULL;
1236 PALIAS_GENERAL_INFORMATION AliasInfo = NULL;
1237 LPVOID Buffer = NULL;
1238 NET_API_STATUS ApiStatus = NERR_Success;
1240
1241 TRACE("(%s %s %d %p) stub!\n", debugstr_w(servername),
1242 debugstr_w(groupname), level, bufptr);
1243
1244 if (servername != NULL)
1245 RtlInitUnicodeString(&ServerName, servername);
1246
1247 RtlInitUnicodeString(&GroupName, groupname);
1248
1249 /* Connect to the SAM Server */
1250 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1251 &ServerHandle,
1253 NULL);
1254 if (!NT_SUCCESS(Status))
1255 {
1256 ERR("SamConnect failed (Status %08lx)\n", Status);
1257 ApiStatus = NetpNtStatusToApiStatus(Status);
1258 goto done;
1259 }
1260
1261 /* Open the Builtin Domain */
1262 Status = OpenBuiltinDomain(ServerHandle,
1264 &DomainHandle);
1265 if (!NT_SUCCESS(Status))
1266 {
1267 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1268 ApiStatus = NetpNtStatusToApiStatus(Status);
1269 goto done;
1270 }
1271
1272 /* Open the alias account in the builtin domain */
1273 ApiStatus = OpenAliasByName(DomainHandle,
1274 &GroupName,
1276 &AliasHandle);
1277 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
1278 {
1279 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
1280 goto done;
1281 }
1282
1283 if (AliasHandle == NULL)
1284 {
1285 if (DomainHandle != NULL)
1286 SamCloseHandle(DomainHandle);
1287
1288 /* Open the Acount Domain */
1289 Status = OpenAccountDomain(ServerHandle,
1290 (servername != NULL) ? &ServerName : NULL,
1292 &DomainHandle);
1293 if (!NT_SUCCESS(Status))
1294 {
1295 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1296 ApiStatus = NetpNtStatusToApiStatus(Status);
1297 goto done;
1298 }
1299
1300 /* Open the alias account in the account domain */
1301 ApiStatus = OpenAliasByName(DomainHandle,
1302 &GroupName,
1304 &AliasHandle);
1305 if (ApiStatus != NERR_Success)
1306 {
1307 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &GroupName, ApiStatus);
1308 if (ApiStatus == ERROR_NONE_MAPPED)
1309 ApiStatus = NERR_GroupNotFound;
1310 goto done;
1311 }
1312 }
1313
1314 Status = SamQueryInformationAlias(AliasHandle,
1316 (PVOID *)&AliasInfo);
1317 if (!NT_SUCCESS(Status))
1318 {
1319 ERR("SamQueryInformationAlias failed (Status %08lx)\n", Status);
1320 ApiStatus = NetpNtStatusToApiStatus(Status);
1321 goto done;
1322 }
1323
1324 ApiStatus = BuildAliasInfoBuffer(AliasInfo,
1325 level,
1326 &Buffer);
1327 if (ApiStatus != NERR_Success)
1328 goto done;
1329
1330done:
1331 if (AliasInfo != NULL)
1332 FreeAliasInfo(AliasInfo);
1333
1334 if (AliasHandle != NULL)
1335 SamCloseHandle(AliasHandle);
1336
1337 if (DomainHandle != NULL)
1338 SamCloseHandle(DomainHandle);
1339
1340 if (ServerHandle != NULL)
1341 SamCloseHandle(ServerHandle);
1342
1343 *bufptr = (LPBYTE)Buffer;
1344
1345 return ApiStatus;
1346}

Referenced by DisplayLocalGroup(), GetGeneralGroupData(), and UpdateGroupProperties().

◆ NetLocalGroupGetMembers()

NET_API_STATUS WINAPI NetLocalGroupGetMembers ( LPCWSTR  servername,
LPCWSTR  localgroupname,
DWORD  level,
LPBYTE bufptr,
DWORD  prefmaxlen,
LPDWORD  entriesread,
LPDWORD  totalentries,
PDWORD_PTR  resumehandle 
)

Definition at line 1354 of file local_group.c.

1363{
1365 UNICODE_STRING ServerName;
1366 UNICODE_STRING AliasName;
1367 PMEMBER_ENUM_CONTEXT EnumContext = NULL;
1368 LPVOID Buffer = NULL;
1369 PLOCALGROUP_MEMBERS_INFO_0 MembersInfo0;
1370 PLOCALGROUP_MEMBERS_INFO_1 MembersInfo1;
1371 PLOCALGROUP_MEMBERS_INFO_2 MembersInfo2;
1372 PLOCALGROUP_MEMBERS_INFO_3 MembersInfo3;
1373 LPWSTR Ptr;
1374 ULONG Size = 0;
1375 ULONG SidLength;
1376 ULONG i;
1377 NET_API_STATUS ApiStatus = NERR_Success;
1379
1380 TRACE("(%s %s %d %p %d %p %p %p)\n", debugstr_w(servername),
1381 debugstr_w(localgroupname), level, bufptr, prefmaxlen, entriesread,
1382 totalentries, resumehandle);
1383
1384 *entriesread = 0;
1385 *totalentries = 0;
1386 *bufptr = NULL;
1387
1388 if (servername != NULL)
1389 RtlInitUnicodeString(&ServerName, servername);
1390
1391 RtlInitUnicodeString(&AliasName, localgroupname);
1392
1393 if (resumehandle != NULL && *resumehandle != 0)
1394 {
1395 EnumContext = (PMEMBER_ENUM_CONTEXT)*resumehandle;
1396 }
1397 else
1398 {
1399 /* Allocate the enumeration context */
1400 ApiStatus = NetApiBufferAllocate(sizeof(MEMBER_ENUM_CONTEXT), (PVOID*)&EnumContext);
1401 if (ApiStatus != NERR_Success)
1402 goto done;
1403
1404 /* Connect to the SAM Server */
1405 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1406 &EnumContext->ServerHandle,
1408 NULL);
1409 if (!NT_SUCCESS(Status))
1410 {
1411 ERR("SamConnect failed (Status %08lx)\n", Status);
1412 ApiStatus = NetpNtStatusToApiStatus(Status);
1413 goto done;
1414 }
1415
1416 /* Open the Builtin Domain */
1417 Status = OpenBuiltinDomain(EnumContext->ServerHandle,
1419 &EnumContext->DomainHandle);
1420 if (!NT_SUCCESS(Status))
1421 {
1422 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1423 ApiStatus = NetpNtStatusToApiStatus(Status);
1424 goto done;
1425 }
1426
1427 /* Open the alias account in the builtin domain */
1428 ApiStatus = OpenAliasByName(EnumContext->DomainHandle,
1429 &AliasName,
1431 &EnumContext->AliasHandle);
1432 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
1433 {
1434 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
1435 goto done;
1436 }
1437
1438 if (EnumContext->AliasHandle == NULL)
1439 {
1440 if (EnumContext->DomainHandle != NULL)
1441 SamCloseHandle(EnumContext->DomainHandle);
1442
1443 /* Open the Acount Domain */
1444 Status = OpenAccountDomain(EnumContext->ServerHandle,
1445 (servername != NULL) ? &ServerName : NULL,
1447 &EnumContext->DomainHandle);
1448 if (!NT_SUCCESS(Status))
1449 {
1450 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1451 ApiStatus = NetpNtStatusToApiStatus(Status);
1452 goto done;
1453 }
1454
1455 /* Open the alias account in the account domain */
1456 ApiStatus = OpenAliasByName(EnumContext->DomainHandle,
1457 &AliasName,
1459 &EnumContext->AliasHandle);
1460 if (ApiStatus != NERR_Success)
1461 {
1462 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
1463 if (ApiStatus == ERROR_NONE_MAPPED)
1464 ApiStatus = NERR_GroupNotFound;
1465 goto done;
1466 }
1467 }
1468
1469 /* Get the member list */
1471 &EnumContext->Sids,
1472 &EnumContext->Count);
1473 if (!NT_SUCCESS(Status))
1474 {
1475 ERR("SamGetMemberInAlias failed (Status %08lx)\n", Status);
1476 ApiStatus = NetpNtStatusToApiStatus(Status);
1477 goto done;
1478 }
1479
1480 if (EnumContext->Count == 0)
1481 {
1482 TRACE("No member found. We're done.\n");
1483 ApiStatus = NERR_Success;
1484 goto done;
1485 }
1486
1487 /* Get name and domain information for all members */
1488 if (level != 0)
1489 {
1491 NULL,
1492 0,
1493 0,
1494 NULL);
1495
1496 Status = LsaOpenPolicy((servername != NULL) ? &ServerName : NULL,
1499 &EnumContext->LsaHandle);
1500 if (!NT_SUCCESS(Status))
1501 {
1502 ApiStatus = NetpNtStatusToApiStatus(Status);
1503 goto done;
1504 }
1505
1506 Status = LsaLookupSids(EnumContext->LsaHandle,
1507 EnumContext->Count,
1508 EnumContext->Sids,
1509 &EnumContext->Domains,
1510 &EnumContext->Names);
1511 if (!NT_SUCCESS(Status))
1512 {
1513 ApiStatus = NetpNtStatusToApiStatus(Status);
1514 goto done;
1515 }
1516 }
1517 }
1518
1519 /* Calculate the required buffer size */
1520 for (i = 0; i < EnumContext->Count; i++)
1521 {
1522 switch (level)
1523 {
1524 case 0:
1525 Size += sizeof(LOCALGROUP_MEMBERS_INFO_0) +
1526 RtlLengthSid(EnumContext->Sids[i]);
1527 break;
1528
1529 case 1:
1530 Size += sizeof(LOCALGROUP_MEMBERS_INFO_1) +
1531 RtlLengthSid(EnumContext->Sids[i]) +
1532 EnumContext->Names[i].Name.Length + sizeof(WCHAR);
1533 break;
1534
1535 case 2:
1536 Size += sizeof(LOCALGROUP_MEMBERS_INFO_2) +
1537 RtlLengthSid(EnumContext->Sids[i]) +
1538 EnumContext->Names[i].Name.Length + sizeof(WCHAR);
1539 if (EnumContext->Names[i].DomainIndex >= 0)
1540 Size += EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Length + sizeof(WCHAR);
1541 break;
1542
1543 case 3:
1544 Size += sizeof(LOCALGROUP_MEMBERS_INFO_3) +
1545 EnumContext->Names[i].Name.Length + sizeof(WCHAR);
1546 if (EnumContext->Names[i].DomainIndex >= 0)
1547 Size += EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Length + sizeof(WCHAR);
1548 break;
1549
1550 default:
1551 ApiStatus = ERROR_INVALID_LEVEL;
1552 goto done;
1553 }
1554 }
1555
1556 /* Allocate the member buffer */
1557 ApiStatus = NetApiBufferAllocate(Size, &Buffer);
1558 if (ApiStatus != NERR_Success)
1559 goto done;
1560
1562
1563 /* Fill the member buffer */
1564 switch (level)
1565 {
1566 case 0:
1567 MembersInfo0 = (PLOCALGROUP_MEMBERS_INFO_0)Buffer;
1568 Ptr = (PVOID)((ULONG_PTR)Buffer + sizeof(LOCALGROUP_MEMBERS_INFO_0) * EnumContext->Count);
1569 break;
1570
1571 case 1:
1572 MembersInfo1 = (PLOCALGROUP_MEMBERS_INFO_1)Buffer;
1573 Ptr = (PVOID)((ULONG_PTR)Buffer + sizeof(LOCALGROUP_MEMBERS_INFO_1) * EnumContext->Count);
1574 break;
1575
1576 case 2:
1577 MembersInfo2 = (PLOCALGROUP_MEMBERS_INFO_2)Buffer;
1578 Ptr = (PVOID)((ULONG_PTR)Buffer + sizeof(LOCALGROUP_MEMBERS_INFO_2) * EnumContext->Count);
1579 break;
1580
1581 case 3:
1582 MembersInfo3 = (PLOCALGROUP_MEMBERS_INFO_3)Buffer;
1583 Ptr = (PVOID)((ULONG_PTR)Buffer + sizeof(LOCALGROUP_MEMBERS_INFO_3) * EnumContext->Count);
1584 break;
1585 }
1586
1587 for (i = 0; i < EnumContext->Count; i++)
1588 {
1589 switch (level)
1590 {
1591 case 0:
1592 MembersInfo0->lgrmi0_sid = (PSID)Ptr;
1593
1594 SidLength = RtlLengthSid(EnumContext->Sids[i]);
1595 memcpy(MembersInfo0->lgrmi0_sid,
1596 EnumContext->Sids[i],
1597 SidLength);
1598 Ptr = (PVOID)((ULONG_PTR)Ptr + SidLength);
1599 MembersInfo0++;
1600 break;
1601
1602 case 1:
1603 MembersInfo1->lgrmi1_sid = (PSID)Ptr;
1604
1605 SidLength = RtlLengthSid(EnumContext->Sids[i]);
1606 memcpy(MembersInfo1->lgrmi1_sid,
1607 EnumContext->Sids[i],
1608 SidLength);
1609
1610 Ptr = (PVOID)((ULONG_PTR)Ptr + SidLength);
1611
1612 MembersInfo1->lgrmi1_sidusage = EnumContext->Names[i].Use;
1613
1614 TRACE("Name: %S\n", EnumContext->Names[i].Name.Buffer);
1615
1616 MembersInfo1->lgrmi1_name = Ptr;
1617
1618 memcpy(MembersInfo1->lgrmi1_name,
1619 EnumContext->Names[i].Name.Buffer,
1620 EnumContext->Names[i].Name.Length);
1621 Ptr = (PVOID)((ULONG_PTR)Ptr + EnumContext->Names[i].Name.Length + sizeof(WCHAR));
1622 MembersInfo1++;
1623 break;
1624
1625 case 2:
1626 MembersInfo2->lgrmi2_sid = (PSID)Ptr;
1627
1628 SidLength = RtlLengthSid(EnumContext->Sids[i]);
1629 memcpy(MembersInfo2->lgrmi2_sid,
1630 EnumContext->Sids[i],
1631 SidLength);
1632
1633 Ptr = (PVOID)((ULONG_PTR)Ptr + SidLength);
1634
1635 MembersInfo2->lgrmi2_sidusage = EnumContext->Names[i].Use;
1636
1637 MembersInfo2->lgrmi2_domainandname = Ptr;
1638
1639 if (EnumContext->Names[i].DomainIndex >= 0)
1640 {
1641 memcpy(MembersInfo2->lgrmi2_domainandname,
1642 EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Buffer,
1643 EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Length);
1644
1645 Ptr = (PVOID)((ULONG_PTR)Ptr + EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Length);
1646
1647 *((LPWSTR)Ptr) = L'\\';
1648
1649 Ptr = (PVOID)((ULONG_PTR)Ptr + sizeof(WCHAR));
1650 }
1651
1652 memcpy(Ptr,
1653 EnumContext->Names[i].Name.Buffer,
1654 EnumContext->Names[i].Name.Length);
1655 Ptr = (PVOID)((ULONG_PTR)Ptr + EnumContext->Names[i].Name.Length + sizeof(WCHAR));
1656 MembersInfo2++;
1657 break;
1658
1659 case 3:
1660 MembersInfo3->lgrmi3_domainandname = Ptr;
1661
1662 if (EnumContext->Names[i].DomainIndex >= 0)
1663 {
1664 memcpy(MembersInfo3->lgrmi3_domainandname,
1665 EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Buffer,
1666 EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Length);
1667
1668 Ptr = (PVOID)((ULONG_PTR)Ptr + EnumContext->Domains->Domains[EnumContext->Names[i].DomainIndex].Name.Length);
1669
1670 *((LPWSTR)Ptr) = L'\\';
1671
1672 Ptr = (PVOID)((ULONG_PTR)Ptr + sizeof(WCHAR));
1673 }
1674
1675 memcpy(Ptr,
1676 EnumContext->Names[i].Name.Buffer,
1677 EnumContext->Names[i].Name.Length);
1678 Ptr = (PVOID)((ULONG_PTR)Ptr + EnumContext->Names[i].Name.Length + sizeof(WCHAR));
1679 MembersInfo3++;
1680 break;
1681 }
1682 }
1683
1684 *entriesread = EnumContext->Count;
1685
1686 *bufptr = (LPBYTE)Buffer;
1687
1688done:
1689 if (EnumContext != NULL)
1690 *totalentries = EnumContext->Count;
1691
1692 if (resumehandle == NULL || ApiStatus != ERROR_MORE_DATA)
1693 {
1694 /* Release the enumeration context */
1695 if (EnumContext != NULL)
1696 {
1697 if (EnumContext->LsaHandle != NULL)
1698 LsaClose(EnumContext->LsaHandle);
1699
1700 if (EnumContext->AliasHandle != NULL)
1701 SamCloseHandle(EnumContext->AliasHandle);
1702
1703 if (EnumContext->DomainHandle != NULL)
1704 SamCloseHandle(EnumContext->DomainHandle);
1705
1706 if (EnumContext->ServerHandle != NULL)
1707 SamCloseHandle(EnumContext->ServerHandle);
1708
1709 if (EnumContext->Sids != NULL)
1710 SamFreeMemory(EnumContext->Sids);
1711
1712 if (EnumContext->Domains != NULL)
1713 LsaFreeMemory(EnumContext->Domains);
1714
1715 if (EnumContext->Names != NULL)
1716 LsaFreeMemory(EnumContext->Names);
1717
1718 NetApiBufferFree(EnumContext);
1719 EnumContext = NULL;
1720 }
1721 }
1722
1723 return ApiStatus;
1724}
NTSTATUS WINAPI LsaLookupSids(IN LSA_HANDLE PolicyHandle, IN ULONG Count, IN PSID *Sids, OUT PLSA_REFERENCED_DOMAIN_LIST *ReferencedDomains, OUT PLSA_TRANSLATED_NAME *Names)
Definition: lsa.c:1069
struct _LOCALGROUP_MEMBERS_INFO_2 LOCALGROUP_MEMBERS_INFO_2
struct _LOCALGROUP_MEMBERS_INFO_2 * PLOCALGROUP_MEMBERS_INFO_2
struct _LOCALGROUP_MEMBERS_INFO_1 * PLOCALGROUP_MEMBERS_INFO_1
struct _LOCALGROUP_MEMBERS_INFO_3 * PLOCALGROUP_MEMBERS_INFO_3
struct _LOCALGROUP_MEMBERS_INFO_1 LOCALGROUP_MEMBERS_INFO_1
struct _LOCALGROUP_MEMBERS_INFO_3 LOCALGROUP_MEMBERS_INFO_3
struct _LOCALGROUP_MEMBERS_INFO_0 LOCALGROUP_MEMBERS_INFO_0
struct _MEMBER_ENUM_CONTEXT * PMEMBER_ENUM_CONTEXT
struct _SID * PSID
Definition: eventlog.c:35
NTSYSAPI ULONG NTAPI RtlLengthSid(IN PSID Sid)
Definition: sid.c:150
#define ALIAS_LIST_MEMBERS
Definition: ntsam.h:11
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI SamGetMembersInAlias(IN SAM_HANDLE AliasHandle, OUT PSID **MemberIds, OUT PULONG MemberCount)
Definition: samlib.c:1138
SID_NAME_USE lgrmi1_sidusage
Definition: lmaccess.h:520
SID_NAME_USE lgrmi2_sidusage
Definition: lmaccess.h:525
LSA_UNICODE_STRING Name
Definition: ntsecapi.h:423
SID_NAME_USE Use
Definition: ntsecapi.h:422
LSA_UNICODE_STRING Name
Definition: ntsecapi.h:403
PLSA_REFERENCED_DOMAIN_LIST Domains
Definition: local_group.c:56
SAM_HANDLE DomainHandle
Definition: local_group.c:50
SAM_HANDLE ServerHandle
Definition: local_group.c:49
SAM_HANDLE AliasHandle
Definition: local_group.c:51
LSA_HANDLE LsaHandle
Definition: local_group.c:52
PLSA_TRANSLATED_NAME Names
Definition: local_group.c:57
void * PVOID
Definition: typedefs.h:50

Referenced by AddUsersToGroup(), DisplayLocalGroup(), and GetGeneralGroupData().

◆ NetLocalGroupSetInfo()

NET_API_STATUS WINAPI NetLocalGroupSetInfo ( LPCWSTR  servername,
LPCWSTR  groupname,
DWORD  level,
LPBYTE  buf,
LPDWORD  parm_err 
)

Definition at line 1732 of file local_group.c.

1738{
1739 UNICODE_STRING ServerName;
1740 UNICODE_STRING AliasName;
1741 SAM_HANDLE ServerHandle = NULL;
1742 SAM_HANDLE DomainHandle = NULL;
1743 SAM_HANDLE AliasHandle = NULL;
1744 ALIAS_NAME_INFORMATION AliasNameInfo;
1745 ALIAS_ADM_COMMENT_INFORMATION AdminCommentInfo;
1746 NET_API_STATUS ApiStatus = NERR_Success;
1748
1749 TRACE("(%s %s %d %p %p)\n", debugstr_w(servername),
1750 debugstr_w(groupname), level, buf, parm_err);
1751
1752 if (parm_err != NULL)
1753 *parm_err = PARM_ERROR_NONE;
1754
1755 if (servername != NULL)
1756 RtlInitUnicodeString(&ServerName, servername);
1757
1758 RtlInitUnicodeString(&AliasName, groupname);
1759
1760 /* Connect to the SAM Server */
1761 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1762 &ServerHandle,
1764 NULL);
1765 if (!NT_SUCCESS(Status))
1766 {
1767 ERR("SamConnect failed (Status %08lx)\n", Status);
1768 ApiStatus = NetpNtStatusToApiStatus(Status);
1769 goto done;
1770 }
1771
1772 /* Open the Builtin Domain */
1773 Status = OpenBuiltinDomain(ServerHandle,
1775 &DomainHandle);
1776 if (!NT_SUCCESS(Status))
1777 {
1778 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1779 ApiStatus = NetpNtStatusToApiStatus(Status);
1780 goto done;
1781 }
1782
1783 /* Open the alias account in the builtin domain */
1784 ApiStatus = OpenAliasByName(DomainHandle,
1785 &AliasName,
1787 &AliasHandle);
1788 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
1789 {
1790 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
1791 goto done;
1792 }
1793
1794 if (AliasHandle == NULL)
1795 {
1796 if (DomainHandle != NULL)
1797 SamCloseHandle(DomainHandle);
1798
1799 /* Open the Acount Domain */
1800 Status = OpenAccountDomain(ServerHandle,
1801 (servername != NULL) ? &ServerName : NULL,
1803 &DomainHandle);
1804 if (!NT_SUCCESS(Status))
1805 {
1806 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1807 ApiStatus = NetpNtStatusToApiStatus(Status);
1808 goto done;
1809 }
1810
1811 /* Open the alias account in the account domain */
1812 ApiStatus = OpenAliasByName(DomainHandle,
1813 &AliasName,
1815 &AliasHandle);
1816 if (ApiStatus != NERR_Success)
1817 {
1818 ERR("OpenAliasByName(%wZ) failed (ApiStatus %lu)\n", &AliasName, ApiStatus);
1819 if (ApiStatus == ERROR_NONE_MAPPED)
1820 ApiStatus = NERR_GroupNotFound;
1821 goto done;
1822 }
1823 }
1824
1825 switch (level)
1826 {
1827 case 0:
1828 /* Set the alias name */
1829 RtlInitUnicodeString(&AliasNameInfo.Name,
1830 ((PLOCALGROUP_INFO_0)buf)->lgrpi0_name);
1831
1832 Status = SamSetInformationAlias(AliasHandle,
1834 &AliasNameInfo);
1835 if (!NT_SUCCESS(Status))
1836 {
1837 TRACE("SamSetInformationAlias failed (ApiStatus %lu)\n", ApiStatus);
1838 ApiStatus = NetpNtStatusToApiStatus(Status);
1839 goto done;
1840 }
1841 break;
1842
1843 case 1:
1844 case 1002:
1845 /* Set the alias admin comment */
1846 if (level == 1)
1847 RtlInitUnicodeString(&AdminCommentInfo.AdminComment,
1848 ((PLOCALGROUP_INFO_1)buf)->lgrpi1_comment);
1849 else
1850 RtlInitUnicodeString(&AdminCommentInfo.AdminComment,
1851 ((PLOCALGROUP_INFO_1002)buf)->lgrpi1002_comment);
1852
1853 Status = SamSetInformationAlias(AliasHandle,
1855 &AdminCommentInfo);
1856 if (!NT_SUCCESS(Status))
1857 {
1858 TRACE("SamSetInformationAlias failed (ApiStatus %lu)\n", ApiStatus);
1859 ApiStatus = NetpNtStatusToApiStatus(Status);
1860 goto done;
1861 }
1862 break;
1863
1864 default:
1865 ApiStatus = ERROR_INVALID_LEVEL;
1866 goto done;
1867 }
1868
1869done:
1870 if (AliasHandle != NULL)
1871 SamCloseHandle(AliasHandle);
1872
1873 if (DomainHandle != NULL)
1874 SamCloseHandle(DomainHandle);
1875
1876 if (ServerHandle != NULL)
1877 SamCloseHandle(ServerHandle);
1878
1879 return ApiStatus;
1880}
@ AliasNameInformation
Definition: ntsam.h:280
UNICODE_STRING Name
Definition: ntsam.h:293

Referenced by cmdLocalGroup(), OnGroupsPageEndLabelEdit(), and SetGeneralGroupData().

◆ NetLocalGroupSetMembers()

NET_API_STATUS WINAPI NetLocalGroupSetMembers ( LPCWSTR  servername,
LPCWSTR  groupname,
DWORD  level,
LPBYTE  buf,
DWORD  totalentries 
)

Definition at line 1888 of file local_group.c.

1894{
1895 FIXME("(%s %s %d %p %d) stub!\n", debugstr_w(servername),
1896 debugstr_w(groupname), level, buf, totalentries);
1897 return NERR_Success;
1898}
#define FIXME(fmt,...)
Definition: precomp.h:53

◆ OpenAliasByName()

static NET_API_STATUS OpenAliasByName ( SAM_HANDLE  DomainHandle,
PUNICODE_STRING  AliasName,
ULONG  DesiredAccess,
PSAM_HANDLE  AliasHandle 
)
static

Definition at line 167 of file local_group.c.

171{
172 PULONG RelativeIds = NULL;
173 PSID_NAME_USE Use = NULL;
174 NET_API_STATUS ApiStatus = NERR_Success;
176
177 /* Get the RID for the given user name */
178 Status = SamLookupNamesInDomain(DomainHandle,
179 1,
180 AliasName,
181 &RelativeIds,
182 &Use);
183 if (!NT_SUCCESS(Status))
184 {
185 ERR("SamLookupNamesInDomain(%wZ) failed (Status %08lx)\n", AliasName, Status);
187 }
188
189 /* Fail, if it is not an alias account */
190 if (Use[0] != SidTypeAlias)
191 {
192 ERR("Object is not an Alias!\n");
193 ApiStatus = NERR_GroupNotFound;
194 goto done;
195 }
196
197 /* Open the alias account */
198 Status = SamOpenAlias(DomainHandle,
200 RelativeIds[0],
201 AliasHandle);
202 if (!NT_SUCCESS(Status))
203 {
204 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
205 ApiStatus = NetpNtStatusToApiStatus(Status);
206 goto done;
207 }
208
209done:
210 if (RelativeIds != NULL)
211 SamFreeMemory(RelativeIds);
212
213 if (Use != NULL)
214 SamFreeMemory(Use);
215
216 return ApiStatus;
217}
enum _SID_NAME_USE * PSID_NAME_USE
@ SidTypeAlias
Definition: lsa.idl:121
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658

Referenced by NetLocalGroupAdd(), NetLocalGroupAddMembers(), NetLocalGroupDel(), NetLocalGroupDelMembers(), NetLocalGroupGetInfo(), NetLocalGroupGetMembers(), and NetLocalGroupSetInfo().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( netapi32  )