2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE: base/applications/network/net/cmdLocalGroup.c
7 * PROGRAMMERS: Eric Kohl
15 CompareInfo(const void *a
,
18 return _wcsicmp(((PLOCALGROUP_INFO_0
)a
)->lgrpi0_name
,
19 ((PLOCALGROUP_INFO_0
)b
)->lgrpi0_name
);
25 EnumerateLocalGroups(VOID
)
27 PLOCALGROUP_INFO_0 pBuffer
= NULL
;
28 PSERVER_INFO_100 pServer
= NULL
;
29 DWORD dwRead
= 0, dwTotal
= 0;
31 DWORD_PTR ResumeHandle
= 0;
32 NET_API_STATUS Status
;
35 Status
= NetServerGetInfo(NULL
,
38 if (Status
!= NERR_Success
)
41 ConPuts(StdOut
, L
"\n");
42 ConResPrintf(StdOut
, IDS_LOCALGROUP_ALIASES
, pServer
->sv100_name
);
43 ConPuts(StdOut
, L
"\n\n");
44 PrintPadding(L
'-', 79);
45 ConPuts(StdOut
, L
"\n");
47 NetApiBufferFree(pServer
);
49 Status
= NetLocalGroupEnum(NULL
,
56 if (Status
!= NERR_Success
)
61 sizeof(PLOCALGROUP_INFO_0
),
64 for (i
= 0; i
< dwRead
; i
++)
66 if (pBuffer
[i
].lgrpi0_name
)
67 ConPrintf(StdOut
, L
"*%s\n", pBuffer
[i
].lgrpi0_name
);
70 NetApiBufferFree(pBuffer
);
78 DisplayLocalGroup(LPWSTR lpGroupName
)
80 PLOCALGROUP_INFO_1 pGroupInfo
= NULL
;
81 PLOCALGROUP_MEMBERS_INFO_3 pMembers
= NULL
;
82 PSERVER_INFO_100 pServer
= NULL
;
83 LPWSTR
*pNames
= NULL
;
86 DWORD_PTR ResumeHandle
= 0;
89 INT nPaddedLength
= 18;
90 NET_API_STATUS Status
;
92 Status
= NetLocalGroupGetInfo(NULL
,
95 (LPBYTE
*)&pGroupInfo
);
96 if (Status
!= NERR_Success
)
99 Status
= NetLocalGroupGetMembers(NULL
,
103 MAX_PREFERRED_LENGTH
,
107 if (Status
!= NERR_Success
)
110 Status
= NetServerGetInfo(NULL
,
113 if (Status
!= NERR_Success
)
116 pNames
= RtlAllocateHeap(RtlGetProcessHeap(),
118 dwRead
* sizeof(LPWSTR
));
121 Status
= ERROR_OUTOFMEMORY
;
125 len
= wcslen(pServer
->sv100_name
);
126 for (i
= 0; i
< dwRead
; i
++)
128 if (!wcsncmp(pMembers
[i
].lgrmi3_domainandname
, pServer
->sv100_name
, len
))
129 pNames
[i
] = &pMembers
[i
].lgrmi3_domainandname
[len
+ 1];
131 pNames
[i
] = pMembers
[i
].lgrmi3_domainandname
;
134 PrintPaddedResourceString(IDS_LOCALGROUP_ALIAS_NAME
, nPaddedLength
);
135 ConPrintf(StdOut
, L
"%s\n", pGroupInfo
->lgrpi1_name
);
137 PrintPaddedResourceString(IDS_LOCALGROUP_COMMENT
, nPaddedLength
);
138 ConPrintf(StdOut
, L
"%s\n", pGroupInfo
->lgrpi1_comment
);
140 ConPuts(StdOut
, L
"\n");
142 ConResPuts(StdOut
, IDS_LOCALGROUP_MEMBERS
);
143 ConPuts(StdOut
, L
"\n\n");
145 PrintPadding(L
'-', 79);
146 ConPuts(StdOut
, L
"\n");
148 for (i
= 0; i
< dwRead
; i
++)
151 ConPrintf(StdOut
, L
"%s\n", pNames
[i
]);
156 RtlFreeHeap(RtlGetProcessHeap(), 0, pNames
);
159 NetApiBufferFree(pServer
);
161 if (pMembers
!= NULL
)
162 NetApiBufferFree(pMembers
);
164 if (pGroupInfo
!= NULL
)
165 NetApiBufferFree(pGroupInfo
);
178 ULONG dwMemberCount
= 0;
180 BOOL bDelete
= FALSE
;
182 BOOL bDomain
= FALSE
;
184 LPWSTR lpGroupName
= NULL
;
185 LPWSTR lpComment
= NULL
;
186 LPLOCALGROUP_MEMBERS_INFO_3 lpMembers
= NULL
;
187 LOCALGROUP_INFO_0 Info0
;
188 LOCALGROUP_INFO_1 Info1
;
189 LOCALGROUP_INFO_1002 Info1002
;
190 NET_API_STATUS Status
;
194 Status
= EnumerateLocalGroups();
195 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
200 Status
= DisplayLocalGroup(argv
[2]);
201 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
206 if (argv
[i
][0] != L
'/')
208 lpGroupName
= argv
[i
];
212 for (j
= i
; j
< argc
; j
++)
214 if (argv
[j
][0] == L
'/')
220 ConPrintf(StdOut
, L
"Member count: %lu\n", dwMemberCount
);
222 if (dwMemberCount
> 0)
224 lpMembers
= RtlAllocateHeap(RtlGetProcessHeap(),
226 dwMemberCount
* sizeof(LPLOCALGROUP_MEMBERS_INFO_3
));
227 if (lpMembers
== NULL
)
232 for (; i
< argc
; i
++)
234 if (argv
[i
][0] == L
'/')
237 lpMembers
[j
].lgrmi3_domainandname
= argv
[i
];
241 for (; i
< argc
; i
++)
243 if (_wcsicmp(argv
[i
], L
"/help") == 0)
245 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
246 PrintNetMessage(MSG_LOCALGROUP_SYNTAX
);
247 PrintNetMessage(MSG_LOCALGROUP_HELP
);
248 ConResPuts(StdOut
, IDS_GENERIC_PAGE
);
251 else if (_wcsicmp(argv
[i
], L
"/add") == 0)
255 else if (_wcsicmp(argv
[i
], L
"/delete") == 0)
259 else if (_wcsnicmp(argv
[i
], L
"/comment:", 9) == 0)
261 lpComment
= &argv
[i
][9];
263 else if (_wcsicmp(argv
[i
], L
"/domain") == 0)
265 ConResPrintf(StdErr
, IDS_ERROR_OPTION_NOT_SUPPORTED
, L
"/DOMAIN");
272 PrintErrorMessage(3506/*, argv[i]*/);
278 if (lpGroupName
== NULL
)
291 ConPrintf(StdOut
, L
"Group:\n %s\n", lpGroupName
);
293 if (lpMembers
!= NULL
)
295 ConPuts(StdOut
, L
"\nMembers:\n");
296 for (i
= 0; i
< dwMemberCount
; i
++)
297 ConPrintf(StdOut
, L
" %s\n", lpMembers
[i
].lgrmi3_domainandname
);
300 if (lpComment
!= NULL
)
302 ConPrintf(StdOut
, L
"\nComment:\n %s\n", lpComment
);
306 if (lpMembers
== NULL
)
308 if (!bAdd
&& !bDelete
&& lpComment
!= NULL
)
310 /* Set group comment */
311 Info1002
.lgrpi1002_comment
= lpComment
;
312 Status
= NetLocalGroupSetInfo(NULL
,
317 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
319 else if (bAdd
&& !bDelete
)
322 if (lpComment
== NULL
)
324 Info0
.lgrpi0_name
= lpGroupName
;
328 Info1
.lgrpi1_name
= lpGroupName
;
329 Info1
.lgrpi1_comment
= lpComment
;
332 Status
= NetLocalGroupAdd(NULL
,
333 (lpComment
== NULL
) ? 0 : 1,
334 (lpComment
== NULL
) ? (LPBYTE
)&Info0
: (LPBYTE
)&Info1
,
336 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
338 else if (!bAdd
&& bDelete
&& lpComment
== NULL
)
340 /* Delete the group */
341 Status
= NetLocalGroupDel(NULL
,
343 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
352 if (bAdd
&& !bDelete
&& lpComment
== NULL
)
354 /* Add group members */
355 Status
= NetLocalGroupAddMembers(NULL
,
360 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
362 else if (!bAdd
&& bDelete
&& lpComment
== NULL
)
364 /* Delete group members */
365 Status
= NetLocalGroupDelMembers(NULL
,
370 ConPrintf(StdOut
, L
"Status: %lu\n", Status
);
379 if (lpMembers
!= NULL
)
380 RtlFreeHeap(RtlGetProcessHeap(), 0, lpMembers
);
384 ConResPuts(StdOut
, IDS_GENERIC_SYNTAX
);
385 PrintNetMessage(MSG_LOCALGROUP_SYNTAX
);