2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdGroup.c
5 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
13 CompareInfo(const void *a
,
16 return _wcsicmp(((PGROUP_INFO_0
)a
)->grpi0_name
,
17 ((PGROUP_INFO_0
)b
)->grpi0_name
);
25 PGROUP_INFO_0 pBuffer
= NULL
;
26 PSERVER_INFO_100 pServer
= NULL
;
27 DWORD dwRead
= 0, dwTotal
= 0;
29 DWORD_PTR ResumeHandle
= 0;
30 NET_API_STATUS Status
;
32 Status
= NetServerGetInfo(NULL
,
35 if (Status
!= NERR_Success
)
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");
44 NetApiBufferFree(pServer
);
46 Status
= NetGroupEnum(NULL
,
53 if (Status
!= NERR_Success
)
58 sizeof(PGROUP_INFO_0
),
61 for (i
= 0; i
< dwRead
; i
++)
63 if (pBuffer
[i
].grpi0_name
)
64 ConPrintf(StdOut
, L
"*%s\n", pBuffer
[i
].grpi0_name
);
67 NetApiBufferFree(pBuffer
);
75 DisplayGroup(LPWSTR lpGroupName
)
77 PGROUP_INFO_1 pGroupInfo
= NULL
;
78 PGROUP_USERS_INFO_0 pUsers
= NULL
;
79 LPWSTR
*pNames
= NULL
;
82 DWORD_PTR ResumeHandle
= 0;
84 INT nPaddedLength
= 15;
85 NET_API_STATUS Status
;
87 Status
= NetGroupGetInfo(NULL
,
90 (LPBYTE
*)&pGroupInfo
);
91 if (Status
!= NERR_Success
)
94 Status
= NetGroupGetUsers(NULL
,
102 if (Status
!= NERR_Success
)
105 pNames
= RtlAllocateHeap(RtlGetProcessHeap(),
107 dwRead
* sizeof(LPWSTR
));
110 Status
= ERROR_OUTOFMEMORY
;
114 for (i
= 0; i
< dwRead
; i
++)
116 pNames
[i
] = pUsers
[i
].grui0_name
;
119 PrintPaddedMessageString(4401, nPaddedLength
);
120 ConPrintf(StdOut
, L
"%s\n", pGroupInfo
->grpi1_name
);
122 PrintPaddedMessageString(4402, nPaddedLength
);
123 ConPrintf(StdOut
, L
"%s\n", pGroupInfo
->grpi1_comment
);
125 ConPuts(StdOut
, L
"\n");
127 PrintMessageString(4403);
128 ConPuts(StdOut
, L
"\n");
130 PrintPadding(L
'-', 79);
131 ConPuts(StdOut
, L
"\n");
133 for (i
= 0; i
< dwRead
; i
++)
136 ConPrintf(StdOut
, L
"%s\n", pNames
[i
]);
141 RtlFreeHeap(RtlGetProcessHeap(), 0, pNames
);
144 NetApiBufferFree(pUsers
);
146 if (pGroupInfo
!= NULL
)
147 NetApiBufferFree(pGroupInfo
);
160 ULONG dwUserCount
= 0;
162 BOOL bDelete
= FALSE
;
164 BOOL bDomain
= FALSE
;
166 PWSTR pGroupName
= NULL
;
167 PWSTR pComment
= NULL
;
168 PWSTR
*pUsers
= NULL
;
171 GROUP_INFO_1002 Info1002
;
172 NET_API_STATUS Status
;
176 Status
= EnumerateGroups();
177 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
182 Status
= DisplayGroup(argv
[2]);
183 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
188 if (argv
[i
][0] != L
'/')
190 pGroupName
= argv
[i
];
194 for (j
= i
; j
< argc
; j
++)
196 if (argv
[j
][0] == L
'/')
204 pUsers
= RtlAllocateHeap(RtlGetProcessHeap(),
206 dwUserCount
* sizeof(PGROUP_USERS_INFO_0
));
212 for (; i
< argc
; i
++)
214 if (argv
[i
][0] == L
'/')
221 for (; i
< argc
; i
++)
223 if (_wcsicmp(argv
[i
], L
"/help") == 0)
225 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
226 PrintNetMessage(MSG_GROUP_SYNTAX
);
227 PrintNetMessage(MSG_GROUP_HELP
);
230 else if (_wcsicmp(argv
[i
], L
"/add") == 0)
234 else if (_wcsicmp(argv
[i
], L
"/delete") == 0)
238 else if (_wcsnicmp(argv
[i
], L
"/comment:", 9) == 0)
240 pComment
= &argv
[i
][9];
242 else if (_wcsicmp(argv
[i
], L
"/domain") == 0)
244 ConResPrintf(StdErr
, IDS_ERROR_OPTION_NOT_SUPPORTED
, L
"/DOMAIN");
251 PrintErrorMessage(3506/*, argv[i]*/);
257 if (pGroupName
== NULL
)
271 if (!bAdd
&& !bDelete
&& pComment
!= NULL
)
273 /* Set group comment */
274 Info1002
.grpi1002_comment
= pComment
;
275 Status
= NetGroupSetInfo(NULL
,
280 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
282 else if (bAdd
&& !bDelete
)
285 if (pComment
== NULL
)
287 Info0
.grpi0_name
= pGroupName
;
291 Info1
.grpi1_name
= pGroupName
;
292 Info1
.grpi1_comment
= pComment
;
295 Status
= NetGroupAdd(NULL
,
296 (pComment
== NULL
) ? 0 : 1,
297 (pComment
== NULL
) ? (LPBYTE
)&Info0
: (LPBYTE
)&Info1
,
299 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
301 else if (!bAdd
&& bDelete
&& pComment
== NULL
)
303 /* Delete the group */
304 Status
= NetGroupDel(NULL
,
306 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
315 if (bAdd
&& !bDelete
&& pComment
== NULL
)
318 for (i
= 0; i
< dwUserCount
; i
++)
320 Status
= NetGroupAddUser(NULL
,
323 if (Status
!= NERR_Success
)
326 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
328 else if (!bAdd
&& bDelete
&& pComment
== NULL
)
330 /* Delete group members */
331 for (i
= 0; i
< dwUserCount
; i
++)
333 Status
= NetGroupDelUser(NULL
,
336 if (Status
!= NERR_Success
)
339 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
349 RtlFreeHeap(RtlGetProcessHeap(), 0, pUsers
);
353 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
354 PrintNetMessage(MSG_GROUP_SYNTAX
);