ReactOS 0.4.16-dev-297-gc569aee
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 {
177 ConPrintf(StdOut, L"Status: %lu\n", Status);
178 return 0;
179 }
180 else if (argc == 3)
181 {
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 {
225 PrintMessageString(4381);
226 ConPuts(StdOut, L"\n");
227 PrintNetMessage(MSG_GROUP_SYNTAX);
228 PrintNetMessage(MSG_GROUP_HELP);
229 return 0;
230 }
231 else if (_wcsicmp(argv[i], L"/add") == 0)
232 {
233 bAdd = TRUE;
234 }
235 else if (_wcsicmp(argv[i], L"/delete") == 0)
236 {
237 bDelete = TRUE;
238 }
239 else if (_wcsnicmp(argv[i], L"/comment:", 9) == 0)
240 {
241 pComment = &argv[i][9];
242 }
243 else if (_wcsicmp(argv[i], L"/domain") == 0)
244 {
245 ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n");
246#if 0
247 bDomain = TRUE;
248#endif
249 }
250 else
251 {
252 PrintErrorMessage(3506/*, argv[i]*/);
253 result = 1;
254 goto done;
255 }
256 }
257
258 if (pGroupName == NULL)
259 {
260 result = 1;
261 goto done;
262 }
263
264 if (bAdd && bDelete)
265 {
266 result = 1;
267 goto done;
268 }
269
270 if (pUsers == NULL)
271 {
272 if (!bAdd && !bDelete && pComment != NULL)
273 {
274 /* Set group comment */
275 Info1002.grpi1002_comment = pComment;
277 pGroupName,
278 1002,
279 (LPBYTE)&Info1002,
280 NULL);
281 ConPrintf(StdOut, L"Status: %lu\n", Status);
282 }
283 else if (bAdd && !bDelete)
284 {
285 /* Add the group */
286 if (pComment == NULL)
287 {
288 Info0.grpi0_name = pGroupName;
289 }
290 else
291 {
292 Info1.grpi1_name = pGroupName;
293 Info1.grpi1_comment = pComment;
294 }
295
297 (pComment == NULL) ? 0 : 1,
298 (pComment == NULL) ? (LPBYTE)&Info0 : (LPBYTE)&Info1,
299 NULL);
300 ConPrintf(StdOut, L"Status: %lu\n", Status);
301 }
302 else if (!bAdd && bDelete && pComment == NULL)
303 {
304 /* Delete the group */
306 pGroupName);
307 ConPrintf(StdOut, L"Status: %lu\n", Status);
308 }
309 else
310 {
311 result = 1;
312 }
313 }
314 else
315 {
316 if (bAdd && !bDelete && pComment == NULL)
317 {
318 /* Add group user */
319 for (i = 0; i < dwUserCount; i++)
320 {
322 pGroupName,
323 pUsers[i]);
324 if (Status != NERR_Success)
325 break;
326 }
327 ConPrintf(StdOut, L"Status: %lu\n", Status);
328 }
329 else if (!bAdd && bDelete && pComment == NULL)
330 {
331 /* Delete group members */
332 for (i = 0; i < dwUserCount; i++)
333 {
335 pGroupName,
336 pUsers[i]);
337 if (Status != NERR_Success)
338 break;
339 }
340 ConPrintf(StdOut, L"Status: %lu\n", Status);
341 }
342 else
343 {
344 result = 1;
345 }
346 }
347
348done:
349 if (pUsers != NULL)
350 RtlFreeHeap(RtlGetProcessHeap(), 0, pUsers);
351
352 if (result != 0)
353 {
354 PrintMessageString(4381);
355 ConPuts(StdOut, L"\n");
356 PrintNetMessage(MSG_GROUP_SYNTAX);
357 }
358
359 return result;
360}
static int argc
Definition: ServiceArgs.c:12
static VOID PrintErrorMessage(DWORD dwError)
Definition: at.c:308
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
static NET_API_STATUS DisplayGroup(LPWSTR lpGroupName)
Definition: cmdGroup.c:75
static NET_API_STATUS EnumerateGroups(VOID)
Definition: cmdGroup.c:23
#define NULL
Definition: types.h:112
#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
Status
Definition: gdiplustypes.h:25
GLuint64EXT * result
Definition: glext.h:11304
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
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
NET_API_STATUS WINAPI NetGroupDelUser(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ LPCWSTR username)
Definition: group_new.c:665
NET_API_STATUS WINAPI NetGroupDel(_In_opt_ LPCWSTR servername, _In_ IN LPCWSTR groupname)
Definition: group_new.c:582
NET_API_STATUS WINAPI NetGroupAddUser(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ LPCWSTR username)
Definition: group_new.c:466
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
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:1382
#define NERR_Success
Definition: lmerr.h:5
#define argv
Definition: mplay32.c:18
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_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)
LPWSTR grpi0_name
Definition: lmaccess.h:474
LPWSTR grpi1002_comment
Definition: lmaccess.h:493
LPWSTR grpi1_name
Definition: lmaccess.h:477
LPWSTR grpi1_comment
Definition: lmaccess.h:478
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59

◆ CompareInfo()

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

Definition at line 13 of file cmdGroup.c.

15{
16 return _wcsicmp(((PGROUP_INFO_0)a)->grpi0_name,
17 ((PGROUP_INFO_0)b)->grpi0_name);
18}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by EnumerateGroups().

◆ DisplayGroup()

static NET_API_STATUS DisplayGroup ( LPWSTR  lpGroupName)
static

Definition at line 75 of file cmdGroup.c.

76{
77 PGROUP_INFO_1 pGroupInfo = 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
88 lpGroupName,
89 1,
90 (LPBYTE*)&pGroupInfo);
91 if (Status != NERR_Success)
92 return Status;
93
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 {
111 goto done;
112 }
113
114 for (i = 0; i < dwRead; i++)
115 {
116 pNames[i] = pUsers[i].grui0_name;
117 }
118
119 PrintPaddedMessageString(4401, nPaddedLength);
120 ConPrintf(StdOut, L"%s\n", pGroupInfo->grpi1_name);
121
122 PrintPaddedMessageString(4402, nPaddedLength);
123 ConPrintf(StdOut, L"%s\n", pGroupInfo->grpi1_comment);
124
125 ConPuts(StdOut, L"\n");
126
127 PrintMessageString(4403);
128 ConPuts(StdOut, L"\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
139done:
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}
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:143
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
unsigned long DWORD
Definition: ntddk_ex.h:95
NET_API_STATUS WINAPI NetGroupGetInfo(_In_opt_ LPCWSTR servername, _In_ LPCWSTR groupname, _In_ DWORD level, _Out_ LPBYTE *bufptr)
Definition: group_new.c:1029
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:1130
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
uint32_t DWORD_PTR
Definition: typedefs.h:65
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by cmdGroup().

◆ EnumerateGroups()

static NET_API_STATUS EnumerateGroups ( VOID  )
static

Definition at line 23 of file cmdGroup.c.

24{
26 PSERVER_INFO_100 pServer = NULL;
27 DWORD dwRead = 0, dwTotal = 0;
28 DWORD i;
29 DWORD_PTR ResumeHandle = 0;
31
33 100,
34 (LPBYTE*)&pServer);
35 if (Status != NERR_Success)
36 return Status;
37
38 ConPuts(StdOut, L"\n");
39 PrintMessageStringV(4400, pServer->sv100_name);
40 ConPuts(StdOut, L"\n");
41 PrintPadding(L'-', 79);
42 ConPuts(StdOut, L"\n");
43
44 NetApiBufferFree(pServer);
45
47 0,
48 (LPBYTE*)&pBuffer,
50 &dwRead,
51 &dwTotal,
52 &ResumeHandle);
53 if (Status != NERR_Success)
54 return Status;
55
57 dwRead,
58 sizeof(PGROUP_INFO_0),
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
68
69 return NERR_Success;
70}
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:93
static int CompareInfo(const void *a, const void *b)
Definition: cmdGroup.c:13
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
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:780
PVOID pBuffer
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 *))
LPWSTR sv100_name
Definition: lmserver.h:13

Referenced by cmdGroup().