ReactOS  0.4.12-dev-36-g472787f
cmdGroup.c File Reference
#include "net.h"
Include dependency graph for cmdGroup.c:

Go to the source code of this file.

Functions

static int CompareInfo (const void *a, const void *b)
 
static NET_API_STATUS EnumerateGroups (VOID)
 
static NET_API_STATUS DisplayGroup (LPWSTR lpGroupName)
 
INT cmdGroup (INT argc, WCHAR **argv)
 

Function Documentation

◆ cmdGroup()

INT cmdGroup ( INT  argc,
WCHAR **  argv 
)

Definition at line 154 of file cmdGroup.c.

157 {
158  INT i, j;
159  INT result = 0;
160  ULONG dwUserCount = 0;
161  BOOL bAdd = FALSE;
162  BOOL bDelete = FALSE;
163 #if 0
164  BOOL bDomain = FALSE;
165 #endif
166  PWSTR pGroupName = NULL;
167  PWSTR pComment = NULL;
168  PWSTR *pUsers = NULL;
169  GROUP_INFO_0 Info0;
170  GROUP_INFO_1 Info1;
171  GROUP_INFO_1002 Info1002;
173 
174  if (argc == 2)
175  {
176  Status = EnumerateGroups();
177  ConPrintf(StdOut, L"Status: %lu\n", Status);
178  return 0;
179  }
180  else if (argc == 3)
181  {
182  Status = DisplayGroup(argv[2]);
183  ConPrintf(StdOut, L"Status: %lu\n", Status);
184  return 0;
185  }
186 
187  i = 2;
188  if (argv[i][0] != L'/')
189  {
190  pGroupName = argv[i];
191  i++;
192  }
193 
194  for (j = i; j < argc; j++)
195  {
196  if (argv[j][0] == L'/')
197  break;
198 
199  dwUserCount++;
200  }
201 
202  if (dwUserCount > 0)
203  {
204  pUsers = RtlAllocateHeap(RtlGetProcessHeap(),
206  dwUserCount * sizeof(PGROUP_USERS_INFO_0));
207  if (pUsers == NULL)
208  return 0;
209  }
210 
211  j = 0;
212  for (; i < argc; i++)
213  {
214  if (argv[i][0] == L'/')
215  break;
216 
217  pUsers[j] = argv[i];
218  j++;
219  }
220 
221  for (; i < argc; i++)
222  {
223  if (_wcsicmp(argv[i], L"/help") == 0)
224  {
235  return 0;
236  }
237  else if (_wcsicmp(argv[i], L"/add") == 0)
238  {
239  bAdd = TRUE;
240  }
241  else if (_wcsicmp(argv[i], L"/delete") == 0)
242  {
243  bDelete = TRUE;
244  }
245  else if (_wcsnicmp(argv[i], L"/comment:", 9) == 0)
246  {
247  pComment = &argv[i][9];
248  }
249  else if (_wcsicmp(argv[i], L"/domain") == 0)
250  {
252 #if 0
253  bDomain = TRUE;
254 #endif
255  }
256  else
257  {
258  result = 1;
259  goto done;
260  }
261  }
262 
263  if (pGroupName == NULL)
264  {
265  result = 1;
266  goto done;
267  }
268 
269  if (bAdd && bDelete)
270  {
271  result = 1;
272  goto done;
273  }
274 
275  if (pUsers == NULL)
276  {
277  if (!bAdd && !bDelete && pComment != NULL)
278  {
279  /* Set group comment */
280  Info1002.grpi1002_comment = pComment;
281  Status = NetGroupSetInfo(NULL,
282  pGroupName,
283  1002,
284  (LPBYTE)&Info1002,
285  NULL);
286  ConPrintf(StdOut, L"Status: %lu\n", Status);
287  }
288  else if (bAdd && !bDelete)
289  {
290  /* Add the group */
291  if (pComment == NULL)
292  {
293  Info0.grpi0_name = pGroupName;
294  }
295  else
296  {
297  Info1.grpi1_name = pGroupName;
298  Info1.grpi1_comment = pComment;
299  }
300 
301  Status = NetGroupAdd(NULL,
302  (pComment == NULL) ? 0 : 1,
303  (pComment == NULL) ? (LPBYTE)&Info0 : (LPBYTE)&Info1,
304  NULL);
305  ConPrintf(StdOut, L"Status: %lu\n", Status);
306  }
307  else if (!bAdd && bDelete && pComment == NULL)
308  {
309  /* Delete the group */
310  Status = NetGroupDel(NULL,
311  pGroupName);
312  ConPrintf(StdOut, L"Status: %lu\n", Status);
313  }
314  else
315  {
316  result = 1;
317  }
318  }
319  else
320  {
321  if (bAdd && !bDelete && pComment == NULL)
322  {
323  /* Add group user */
324  for (i = 0; i < dwUserCount; i++)
325  {
326  Status = NetGroupAddUser(NULL,
327  pGroupName,
328  pUsers[i]);
329  if (Status != NERR_Success)
330  break;
331  }
332  ConPrintf(StdOut, L"Status: %lu\n", Status);
333  }
334  else if (!bAdd && bDelete && pComment == NULL)
335  {
336  /* Delete group members */
337  for (i = 0; i < dwUserCount; i++)
338  {
339  Status = NetGroupDelUser(NULL,
340  pGroupName,
341  pUsers[i]);
342  if (Status != NERR_Success)
343  break;
344  }
345  ConPrintf(StdOut, L"Status: %lu\n", Status);
346  }
347  else
348  {
349  result = 1;
350  }
351  }
352 
353 done:
354  if (pUsers != NULL)
355  RtlFreeHeap(RtlGetProcessHeap(), 0, pUsers);
356 
357  if (result != 0)
358  {
361  }
362 
363  return result;
364 }
#define IDS_GROUP_HELP_7
Definition: resource.h:38
static int argc
Definition: ServiceArgs.c:12
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TRUE
Definition: types.h:120
uint16_t * PWSTR
Definition: typedefs.h:54
LPWSTR grpi0_name
Definition: lmaccess.h:474
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
LPWSTR grpi1002_comment
Definition: lmaccess.h:493
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
NET_API_STATUS WINAPI NetGroupSetInfo(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _In_ LPBYTE buf, _Out_opt_ LPDWORD parm_err)
Definition: group_new.c:1379
int32_t INT
Definition: typedefs.h:56
static char ** argv
Definition: ServiceArgs.c:11
#define NERR_Success
Definition: lmerr.h:5
static NET_API_STATUS EnumerateGroups(VOID)
Definition: cmdGroup.c:23
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_GENERIC_SYNTAX
Definition: resource.h:202
unsigned char * LPBYTE
Definition: typedefs.h:52
static NET_API_STATUS DisplayGroup(LPWSTR lpGroupName)
Definition: cmdGroup.c:75
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
#define IDS_GENERIC_PAGE
Definition: resource.h:203
smooth NULL
Definition: ftsmooth.c:416
NET_API_STATUS WINAPI NetGroupAddUser(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ LPCWSTR username)
Definition: group_new.c:463
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_GROUP_SYNTAX
Definition: resource.h:31
#define IDS_GROUP_HELP_2
Definition: resource.h:33
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define IDS_ERROR_OPTION_NOT_SUPPORTED
Definition: resource.h:205
static const WCHAR L[]
Definition: oid.c:1087
#define IDS_GROUP_HELP_5
Definition: resource.h:36
LPWSTR grpi1_comment
Definition: lmaccess.h:478
LPWSTR grpi1_name
Definition: lmaccess.h:477
Status
Definition: gdiplustypes.h:24
#define IDS_GROUP_HELP_1
Definition: resource.h:32
NET_API_STATUS WINAPI NetGroupAdd(_In_opt_ LPCWSTR servername, _In_ DWORD level, _In_ LPBYTE buf, _Out_opt_ LPDWORD parm_err)
Definition: group_new.c:286
#define IDS_GROUP_HELP_4
Definition: resource.h:35
NET_API_STATUS WINAPI NetGroupDelUser(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ LPCWSTR username)
Definition: group_new.c:662
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define StdOut
Definition: stream.h:76
unsigned int ULONG
Definition: retypes.h:1
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
NET_API_STATUS WINAPI NetGroupDel(_In_opt_ LPCWSTR servername, _In_ IN LPCWSTR groupname)
Definition: group_new.c:579
#define IDS_GROUP_HELP_3
Definition: resource.h:34
#define IDS_GROUP_HELP_6
Definition: resource.h:37

◆ CompareInfo()

static int CompareInfo ( const void a,
const void b 
)
static

Definition at line 13 of file cmdGroup.c.

Referenced by EnumerateGroups().

15 {
16  return _wcsicmp(((PGROUP_INFO_0)a)->grpi0_name,
17  ((PGROUP_INFO_0)b)->grpi0_name);
18 }
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

◆ DisplayGroup()

static NET_API_STATUS DisplayGroup ( LPWSTR  lpGroupName)
static

Definition at line 75 of file cmdGroup.c.

Referenced by cmdGroup().

76 {
77  PGROUP_INFO_1 pGroupInfo = NULL;
78  PGROUP_USERS_INFO_0 pUsers = NULL;
79  LPWSTR *pNames = NULL;
80  DWORD dwRead = 0;
81  DWORD dwTotal = 0;
82  DWORD_PTR ResumeHandle = 0;
83  DWORD i;
84  INT nPaddedLength = 15;
86 
87  Status = NetGroupGetInfo(NULL,
88  lpGroupName,
89  1,
90  (LPBYTE*)&pGroupInfo);
91  if (Status != NERR_Success)
92  return Status;
93 
94  Status = NetGroupGetUsers(NULL,
95  lpGroupName,
96  0,
97  (LPBYTE*)&pUsers,
99  &dwRead,
100  &dwTotal,
101  &ResumeHandle);
102  if (Status != NERR_Success)
103  goto done;
104 
105  pNames = RtlAllocateHeap(RtlGetProcessHeap(),
107  dwRead * sizeof(LPWSTR));
108  if (pNames == NULL)
109  {
110  Status = ERROR_OUTOFMEMORY;
111  goto done;
112  }
113 
114  for (i = 0; i < dwRead; i++)
115  {
116  pNames[i] = pUsers[i].grui0_name;
117  }
118 
120  ConPrintf(StdOut, L"%s\n", pGroupInfo->grpi1_name);
121 
123  ConPrintf(StdOut, L"%s\n", pGroupInfo->grpi1_comment);
124 
125  ConPuts(StdOut, L"\n");
126 
128  ConPuts(StdOut, L"\n\n");
129 
130  PrintPadding(L'-', 79);
131  ConPuts(StdOut, L"\n");
132 
133  for (i = 0; i < dwRead; i++)
134  {
135  if (pNames[i])
136  ConPrintf(StdOut, L"%s\n", pNames[i]);
137  }
138 
139 done:
140  if (pNames != NULL)
141  RtlFreeHeap(RtlGetProcessHeap(), 0, pNames);
142 
143  if (pUsers != NULL)
144  NetApiBufferFree(pUsers);
145 
146  if (pGroupInfo != NULL)
147  NetApiBufferFree(pGroupInfo);
148 
149  return Status;
150 }
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
int32_t INT
Definition: typedefs.h:56
#define NERR_Success
Definition: lmerr.h:5
GLenum GLclampf GLint i
Definition: glfuncs.h:14
unsigned char * LPBYTE
Definition: typedefs.h:52
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define IDS_GROUP_MEMBERS
Definition: resource.h:122
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: group_new.c:1127
unsigned long DWORD
Definition: ntddk_ex.h:95
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
uint32_t DWORD_PTR
Definition: typedefs.h:63
LPWSTR grpi1_comment
Definition: lmaccess.h:478
LPWSTR grpi1_name
Definition: lmaccess.h:477
Status
Definition: gdiplustypes.h:24
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetGroupGetInfo(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _Out_ LPBYTE *bufptr)
Definition: group_new.c:1026
VOID PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:51
#define IDS_GROUP_COMMENT
Definition: resource.h:121
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:64
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define IDS_GROUP_NAME
Definition: resource.h:120
#define StdOut
Definition: stream.h:76
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

◆ EnumerateGroups()

static NET_API_STATUS EnumerateGroups ( VOID  )
static

Definition at line 23 of file cmdGroup.c.

Referenced by cmdGroup().

24 {
26  PSERVER_INFO_100 pServer = NULL;
27  DWORD dwRead = 0, dwTotal = 0;
28  DWORD i;
29  DWORD_PTR ResumeHandle = 0;
31 
32  Status = NetServerGetInfo(NULL,
33  100,
34  (LPBYTE*)&pServer);
35  if (Status != NERR_Success)
36  return Status;
37 
38  ConPuts(StdOut, L"\n");
40  ConPuts(StdOut, L"\n\n");
41  PrintPadding(L'-', 79);
42  ConPuts(StdOut, L"\n");
43 
44  NetApiBufferFree(pServer);
45 
46  Status = NetGroupEnum(NULL,
47  0,
48  (LPBYTE*)&pBuffer,
50  &dwRead,
51  &dwTotal,
52  &ResumeHandle);
53  if (Status != NERR_Success)
54  return Status;
55 
56  qsort(pBuffer,
57  dwRead,
58  sizeof(PGROUP_INFO_0),
59  CompareInfo);
60 
61  for (i = 0; i < dwRead; i++)
62  {
63  if (pBuffer[i].grpi0_name)
64  ConPrintf(StdOut, L"*%s\n", pBuffer[i].grpi0_name);
65  }
66 
67  NetApiBufferFree(pBuffer);
68 
69  return NERR_Success;
70 }
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
#define NERR_Success
Definition: lmerr.h:5
GLenum GLclampf GLint i
Definition: glfuncs.h:14
unsigned char * LPBYTE
Definition: typedefs.h:52
LPWSTR sv100_name
Definition: lmserver.h:13
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
unsigned long DWORD
Definition: ntddk_ex.h:95
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: group_new.c:777
static int CompareInfo(const void *a, const void *b)
Definition: cmdGroup.c:13
static const WCHAR L[]
Definition: oid.c:1087
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
#define IDS_GROUP_GROUPS
Definition: resource.h:119
uint32_t DWORD_PTR
Definition: typedefs.h:63
Status
Definition: gdiplustypes.h:24
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:64
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define StdOut
Definition: stream.h:76