2014-10-19 20:12:19 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS net command
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/network/net/cmdLocalGroup.c
|
2014-10-19 20:12:19 +00:00
|
|
|
* PURPOSE:
|
|
|
|
*
|
|
|
|
* PROGRAMMERS: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "net.h"
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
CompareInfo(const void *a,
|
|
|
|
const void *b)
|
|
|
|
{
|
|
|
|
return _wcsicmp(((PLOCALGROUP_INFO_0)a)->lgrpi0_name,
|
|
|
|
((PLOCALGROUP_INFO_0)b)->lgrpi0_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
NET_API_STATUS
|
|
|
|
EnumerateLocalGroups(VOID)
|
|
|
|
{
|
|
|
|
PLOCALGROUP_INFO_0 pBuffer = NULL;
|
|
|
|
PSERVER_INFO_100 pServer = NULL;
|
|
|
|
DWORD dwRead = 0, dwTotal = 0;
|
|
|
|
DWORD i;
|
|
|
|
DWORD_PTR ResumeHandle = 0;
|
|
|
|
NET_API_STATUS Status;
|
|
|
|
|
|
|
|
|
|
|
|
Status = NetServerGetInfo(NULL,
|
|
|
|
100,
|
|
|
|
(LPBYTE*)&pServer);
|
|
|
|
if (Status != NERR_Success)
|
|
|
|
return Status;
|
|
|
|
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
2019-04-05 21:14:07 +00:00
|
|
|
PrintMessageStringV(4405, pServer->sv100_name);
|
|
|
|
ConPuts(StdOut, L"\n");
|
2014-11-16 10:34:49 +00:00
|
|
|
PrintPadding(L'-', 79);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
2014-10-19 20:12:19 +00:00
|
|
|
|
|
|
|
NetApiBufferFree(pServer);
|
|
|
|
|
|
|
|
Status = NetLocalGroupEnum(NULL,
|
|
|
|
0,
|
|
|
|
(LPBYTE*)&pBuffer,
|
|
|
|
MAX_PREFERRED_LENGTH,
|
|
|
|
&dwRead,
|
|
|
|
&dwTotal,
|
|
|
|
&ResumeHandle);
|
|
|
|
if (Status != NERR_Success)
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
qsort(pBuffer,
|
|
|
|
dwRead,
|
|
|
|
sizeof(PLOCALGROUP_INFO_0),
|
|
|
|
CompareInfo);
|
|
|
|
|
|
|
|
for (i = 0; i < dwRead; i++)
|
|
|
|
{
|
2014-11-16 10:34:49 +00:00
|
|
|
if (pBuffer[i].lgrpi0_name)
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"*%s\n", pBuffer[i].lgrpi0_name);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NetApiBufferFree(pBuffer);
|
|
|
|
|
|
|
|
return NERR_Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-25 14:28:38 +00:00
|
|
|
static
|
|
|
|
NET_API_STATUS
|
|
|
|
DisplayLocalGroup(LPWSTR lpGroupName)
|
|
|
|
{
|
|
|
|
PLOCALGROUP_INFO_1 pGroupInfo = NULL;
|
|
|
|
PLOCALGROUP_MEMBERS_INFO_3 pMembers = NULL;
|
|
|
|
PSERVER_INFO_100 pServer = NULL;
|
|
|
|
LPWSTR *pNames = NULL;
|
|
|
|
DWORD dwRead = 0;
|
|
|
|
DWORD dwTotal = 0;
|
|
|
|
DWORD_PTR ResumeHandle = 0;
|
|
|
|
DWORD i;
|
|
|
|
DWORD len;
|
2014-11-09 13:39:20 +00:00
|
|
|
INT nPaddedLength = 18;
|
2014-10-25 14:28:38 +00:00
|
|
|
NET_API_STATUS Status;
|
|
|
|
|
|
|
|
Status = NetLocalGroupGetInfo(NULL,
|
|
|
|
lpGroupName,
|
|
|
|
1,
|
|
|
|
(LPBYTE*)&pGroupInfo);
|
|
|
|
if (Status != NERR_Success)
|
|
|
|
return Status;
|
|
|
|
|
|
|
|
Status = NetLocalGroupGetMembers(NULL,
|
|
|
|
lpGroupName,
|
|
|
|
3,
|
|
|
|
(LPBYTE*)&pMembers,
|
|
|
|
MAX_PREFERRED_LENGTH,
|
|
|
|
&dwRead,
|
|
|
|
&dwTotal,
|
|
|
|
&ResumeHandle);
|
|
|
|
if (Status != NERR_Success)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
Status = NetServerGetInfo(NULL,
|
|
|
|
100,
|
|
|
|
(LPBYTE*)&pServer);
|
|
|
|
if (Status != NERR_Success)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
pNames = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
dwRead * sizeof(LPWSTR));
|
|
|
|
if (pNames == NULL)
|
|
|
|
{
|
|
|
|
Status = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = wcslen(pServer->sv100_name);
|
|
|
|
for (i = 0; i < dwRead; i++)
|
|
|
|
{
|
|
|
|
if (!wcsncmp(pMembers[i].lgrmi3_domainandname, pServer->sv100_name, len))
|
|
|
|
pNames[i] = &pMembers[i].lgrmi3_domainandname[len + 1];
|
|
|
|
else
|
|
|
|
pNames[i] = pMembers[i].lgrmi3_domainandname;
|
|
|
|
}
|
|
|
|
|
2019-04-05 21:14:07 +00:00
|
|
|
PrintPaddedMessageString(4406, nPaddedLength);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"%s\n", pGroupInfo->lgrpi1_name);
|
2014-11-09 13:39:20 +00:00
|
|
|
|
2019-04-05 21:14:07 +00:00
|
|
|
PrintPaddedMessageString(4407, nPaddedLength);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"%s\n", pGroupInfo->lgrpi1_comment);
|
2014-11-09 13:39:20 +00:00
|
|
|
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
2014-11-09 13:39:20 +00:00
|
|
|
|
2019-04-05 21:14:07 +00:00
|
|
|
PrintMessageString(4408);
|
|
|
|
ConPuts(StdOut, L"\n");
|
2014-11-09 13:39:20 +00:00
|
|
|
|
2014-11-16 10:34:49 +00:00
|
|
|
PrintPadding(L'-', 79);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\n");
|
2014-10-25 14:28:38 +00:00
|
|
|
|
|
|
|
for (i = 0; i < dwRead; i++)
|
|
|
|
{
|
2014-10-25 21:27:05 +00:00
|
|
|
if (pNames[i])
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"%s\n", pNames[i]);
|
2014-10-25 14:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (pNames != NULL)
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, pNames);
|
|
|
|
|
|
|
|
if (pServer != NULL)
|
|
|
|
NetApiBufferFree(pServer);
|
|
|
|
|
|
|
|
if (pMembers != NULL)
|
|
|
|
NetApiBufferFree(pMembers);
|
|
|
|
|
|
|
|
if (pGroupInfo != NULL)
|
|
|
|
NetApiBufferFree(pGroupInfo);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-19 20:12:19 +00:00
|
|
|
INT
|
|
|
|
cmdLocalGroup(
|
|
|
|
INT argc,
|
|
|
|
WCHAR **argv)
|
|
|
|
{
|
|
|
|
INT i, j;
|
|
|
|
INT result = 0;
|
|
|
|
ULONG dwMemberCount = 0;
|
|
|
|
BOOL bAdd = FALSE;
|
|
|
|
BOOL bDelete = FALSE;
|
|
|
|
#if 0
|
|
|
|
BOOL bDomain = FALSE;
|
|
|
|
#endif
|
|
|
|
LPWSTR lpGroupName = NULL;
|
|
|
|
LPWSTR lpComment = NULL;
|
|
|
|
LPLOCALGROUP_MEMBERS_INFO_3 lpMembers = NULL;
|
|
|
|
LOCALGROUP_INFO_0 Info0;
|
|
|
|
LOCALGROUP_INFO_1 Info1;
|
|
|
|
LOCALGROUP_INFO_1002 Info1002;
|
|
|
|
NET_API_STATUS Status;
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
Status = EnumerateLocalGroups();
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-19 20:12:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-25 14:28:38 +00:00
|
|
|
else if (argc == 3)
|
|
|
|
{
|
|
|
|
Status = DisplayLocalGroup(argv[2]);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-25 14:28:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-10-19 20:12:19 +00:00
|
|
|
|
|
|
|
i = 2;
|
|
|
|
if (argv[i][0] != L'/')
|
|
|
|
{
|
|
|
|
lpGroupName = argv[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = i; j < argc; j++)
|
|
|
|
{
|
|
|
|
if (argv[j][0] == L'/')
|
|
|
|
break;
|
|
|
|
|
|
|
|
dwMemberCount++;
|
|
|
|
}
|
|
|
|
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Member count: %lu\n", dwMemberCount);
|
2014-10-19 20:12:19 +00:00
|
|
|
|
|
|
|
if (dwMemberCount > 0)
|
|
|
|
{
|
|
|
|
lpMembers = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
|
|
|
dwMemberCount * sizeof(LPLOCALGROUP_MEMBERS_INFO_3));
|
|
|
|
if (lpMembers == NULL)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (argv[i][0] == L'/')
|
|
|
|
break;
|
|
|
|
|
|
|
|
lpMembers[j].lgrmi3_domainandname = argv[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (_wcsicmp(argv[i], L"/help") == 0)
|
|
|
|
{
|
2019-04-09 19:44:03 +00:00
|
|
|
PrintMessageString(4381);
|
|
|
|
ConPuts(StdOut, L"\n");
|
2018-12-23 23:13:16 +00:00
|
|
|
PrintNetMessage(MSG_LOCALGROUP_SYNTAX);
|
|
|
|
PrintNetMessage(MSG_LOCALGROUP_HELP);
|
2014-10-19 20:12:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(argv[i], L"/add") == 0)
|
|
|
|
{
|
|
|
|
bAdd = TRUE;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(argv[i], L"/delete") == 0)
|
|
|
|
{
|
|
|
|
bDelete = TRUE;
|
|
|
|
}
|
|
|
|
else if (_wcsnicmp(argv[i], L"/comment:", 9) == 0)
|
|
|
|
{
|
|
|
|
lpComment = &argv[i][9];
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(argv[i], L"/domain") == 0)
|
|
|
|
{
|
2019-04-09 19:44:03 +00:00
|
|
|
ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n");
|
2014-10-19 20:12:19 +00:00
|
|
|
#if 0
|
|
|
|
bDomain = TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-23 13:16:53 +00:00
|
|
|
PrintErrorMessage(3506/*, argv[i]*/);
|
2014-10-19 20:12:19 +00:00
|
|
|
result = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpGroupName == NULL)
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bAdd && bDelete)
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Group:\n %s\n", lpGroupName);
|
2014-10-19 20:12:19 +00:00
|
|
|
|
|
|
|
if (lpMembers != NULL)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPuts(StdOut, L"\nMembers:\n");
|
2014-10-19 20:12:19 +00:00
|
|
|
for (i = 0; i < dwMemberCount; i++)
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L" %s\n", lpMembers[i].lgrmi3_domainandname);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lpComment != NULL)
|
|
|
|
{
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"\nComment:\n %s\n", lpComment);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (lpMembers == NULL)
|
|
|
|
{
|
|
|
|
if (!bAdd && !bDelete && lpComment != NULL)
|
|
|
|
{
|
|
|
|
/* Set group comment */
|
|
|
|
Info1002.lgrpi1002_comment = lpComment;
|
|
|
|
Status = NetLocalGroupSetInfo(NULL,
|
|
|
|
lpGroupName,
|
|
|
|
1002,
|
|
|
|
(LPBYTE)&Info1002,
|
|
|
|
NULL);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
else if (bAdd && !bDelete)
|
|
|
|
{
|
|
|
|
/* Add the group */
|
|
|
|
if (lpComment == NULL)
|
|
|
|
{
|
|
|
|
Info0.lgrpi0_name = lpGroupName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info1.lgrpi1_name = lpGroupName;
|
|
|
|
Info1.lgrpi1_comment = lpComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = NetLocalGroupAdd(NULL,
|
2018-08-26 22:43:34 +00:00
|
|
|
(lpComment == NULL) ? 0 : 1,
|
|
|
|
(lpComment == NULL) ? (LPBYTE)&Info0 : (LPBYTE)&Info1,
|
|
|
|
NULL);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
else if (!bAdd && bDelete && lpComment == NULL)
|
|
|
|
{
|
|
|
|
/* Delete the group */
|
|
|
|
Status = NetLocalGroupDel(NULL,
|
|
|
|
lpGroupName);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bAdd && !bDelete && lpComment == NULL)
|
|
|
|
{
|
|
|
|
/* Add group members */
|
|
|
|
Status = NetLocalGroupAddMembers(NULL,
|
2018-08-26 22:43:34 +00:00
|
|
|
lpGroupName,
|
|
|
|
3,
|
|
|
|
(LPBYTE)lpMembers,
|
|
|
|
dwMemberCount);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
else if (!bAdd && bDelete && lpComment == NULL)
|
|
|
|
{
|
|
|
|
/* Delete group members */
|
|
|
|
Status = NetLocalGroupDelMembers(NULL,
|
2018-08-26 22:43:34 +00:00
|
|
|
lpGroupName,
|
|
|
|
3,
|
|
|
|
(LPBYTE)lpMembers,
|
|
|
|
dwMemberCount);
|
2016-10-07 22:50:32 +00:00
|
|
|
ConPrintf(StdOut, L"Status: %lu\n", Status);
|
2014-10-19 20:12:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (lpMembers != NULL)
|
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, lpMembers);
|
|
|
|
|
|
|
|
if (result != 0)
|
2018-04-01 10:23:15 +00:00
|
|
|
{
|
2019-04-09 19:44:03 +00:00
|
|
|
PrintMessageString(4381);
|
|
|
|
ConPuts(StdOut, L"\n");
|
2018-12-23 23:13:16 +00:00
|
|
|
PrintNetMessage(MSG_LOCALGROUP_SYNTAX);
|
2018-04-01 10:23:15 +00:00
|
|
|
}
|
2014-10-19 20:12:19 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|