[NET]
authorEric Kohl <eric.kohl@reactos.org>
Sun, 19 Oct 2014 20:12:19 +0000 (20:12 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 19 Oct 2014 20:12:19 +0000 (20:12 +0000)
- Add the localgroup command. It does not work properly on ReactOS yet.
- Print a warning when the domain option of the accounts command is used.

svn path=/trunk/; revision=64834

reactos/base/applications/network/net/CMakeLists.txt
reactos/base/applications/network/net/cmdAccounts.c
reactos/base/applications/network/net/cmdLocalGroup.c [new file with mode: 0644]
reactos/base/applications/network/net/lang/en-US.rc
reactos/base/applications/network/net/lang/ro-RO.rc
reactos/base/applications/network/net/lang/ru-RU.rc
reactos/base/applications/network/net/main.c
reactos/base/applications/network/net/net.h

index a740d3a..c3507d6 100644 (file)
@@ -4,11 +4,12 @@ add_definitions(-D__USE_W32_SOCKETS)
 list(APPEND SOURCE
     main.c
     cmdAccounts.c
 list(APPEND SOURCE
     main.c
     cmdAccounts.c
-    cmdStart.c
-    cmdStop.c
+    cmdContinue.c
     cmdHelpMsg.c
     cmdHelpMsg.c
+    cmdLocalGroup.c
     cmdPause.c
     cmdPause.c
-    cmdContinue.c
+    cmdStart.c
+    cmdStop.c
     help.c
     net.h)
 
     help.c
     net.h)
 
index 456ac4c..c297da0 100644 (file)
@@ -24,7 +24,9 @@ cmdAccounts(
     ULONG value;
     INT i;
     BOOL Modified = FALSE;
     ULONG value;
     INT i;
     BOOL Modified = FALSE;
-//    BOOL Domain = FALSE;
+#if 0
+    BOOL Domain = FALSE;
+#endif
     NET_API_STATUS Status;
     INT result = 0;
 
     NET_API_STATUS Status;
     INT result = 0;
 
@@ -44,12 +46,13 @@ cmdAccounts(
             return 0;
         }
 
             return 0;
         }
 
-/*
         if (_wcsicmp(argv[i], L"/domain") == 0)
         {
         if (_wcsicmp(argv[i], L"/domain") == 0)
         {
+            printf("The /DOMAIN option is not supported yet!\n");
+#if 0
             Domain = TRUE;
             Domain = TRUE;
+#endif
         }
         }
-*/
     }
 
     Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
     }
 
     Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
diff --git a/reactos/base/applications/network/net/cmdLocalGroup.c b/reactos/base/applications/network/net/cmdLocalGroup.c
new file mode 100644 (file)
index 0000000..43400d1
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * COPYRIGHT:       See COPYING in the top level directory
+ * PROJECT:         ReactOS net command
+ * FILE:
+ * 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;
+
+    printf("\nAliases for \\\\%S\n\n", pServer->sv100_name);
+    printf("------------------------------------------\n");
+
+    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);
+
+//    printf("dwRead: %lu  dwTotal: %lu\n", dwRead, dwTotal);
+    for (i = 0; i < dwRead; i++)
+    {
+//        printf("%p\n", pBuffer[i].lgrpi0_name);
+         if (pBuffer[i].lgrpi0_name)
+            printf("*%S\n", pBuffer[i].lgrpi0_name);
+    }
+
+    NetApiBufferFree(pBuffer);
+
+    return NERR_Success;
+}
+
+
+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();
+        printf("Status: %lu\n", Status);
+        return 0;
+    }
+
+    i = 2;
+    if (argv[i][0] != L'/')
+    {
+        lpGroupName = argv[i];
+        i++;
+    }
+
+    for (j = i; j < argc; j++)
+    {
+        if (argv[j][0] == L'/')
+            break;
+
+        dwMemberCount++;
+    }
+
+    printf("Member count: %lu\n", dwMemberCount);
+
+    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)
+        {
+            PrintResourceString(IDS_LOCALGROUP_HELP);
+            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)
+        {
+            printf("The /DOMAIN option is not supported yet!\n");
+#if 0
+            bDomain = TRUE;
+#endif
+        }
+        else
+        {
+            result = 1;
+            goto done;
+        }
+    }
+
+    if (lpGroupName == NULL)
+    {
+        result = 1;
+        goto done;
+    }
+
+    if (bAdd && bDelete)
+    {
+        result = 1;
+        goto done;
+    }
+
+#if 0
+    printf("Group:\n  %S\n", lpGroupName);
+
+    if (lpMembers != NULL)
+    {
+        printf("\nMembers:\n");
+        for (i = 0; i < dwMemberCount; i++)
+            printf("  %S\n", lpMembers[i].lgrmi3_domainandname);
+    }
+
+    if (lpComment != NULL)
+    {
+        printf("\nComment:\n  %S\n", lpComment);
+    }
+#endif
+
+    if (lpMembers == NULL)
+    {
+        if (!bAdd && !bDelete && lpComment != NULL)
+        {
+            /* Set group comment */
+            Info1002.lgrpi1002_comment = lpComment;
+            Status = NetLocalGroupSetInfo(NULL,
+                                          lpGroupName,
+                                          1002,
+                                          (LPBYTE)&Info1002,
+                                          NULL);
+            printf("Status: %lu\n", Status);
+        }
+        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,
+                             (lpComment == NULL) ? 0 : 1,
+                             (lpComment == NULL) ? (LPBYTE)&Info0 : (LPBYTE)&Info1,
+                             NULL);
+            printf("Status: %lu\n", Status);
+        }
+        else if (!bAdd && bDelete && lpComment == NULL)
+        {
+            /* Delete the group */
+            Status = NetLocalGroupDel(NULL,
+                                      lpGroupName);
+            printf("Status: %lu\n", Status);
+        }
+        else
+        {
+            result = 1;
+        }
+    }
+    else
+    {
+        if (bAdd && !bDelete && lpComment == NULL)
+        {
+            /* Add group members */
+            Status = NetLocalGroupAddMembers(NULL,
+                                    lpGroupName,
+                                    3,
+                                    (LPBYTE)lpMembers,
+                                    dwMemberCount);
+            printf("Status: %lu\n", Status);
+        }
+        else if (!bAdd && bDelete && lpComment == NULL)
+        {
+            /* Delete group members */
+            Status = NetLocalGroupDelMembers(NULL,
+                                    lpGroupName,
+                                    3,
+                                    (LPBYTE)lpMembers,
+                                    dwMemberCount);
+            printf("Status: %lu\n", Status);
+        }
+        else
+        {
+            result = 1;
+        }
+    }
+
+done:
+    if (lpMembers != NULL)
+        RtlFreeHeap(RtlGetProcessHeap(), 0, lpMembers);
+
+    if (result != 0)
+        PrintResourceString(IDS_LOCALGROUP_SYNTAX);
+
+    return result;
+}
+
+/* EOF */
index 3571f66..2d9083e 100644 (file)
@@ -18,7 +18,9 @@ BEGIN
     IDS_GROUP_HELP "GROUP\n..."
     IDS_HELPMSG_SYNTAX "Usage:\nNET HELPMSG <Error Code>"
     IDS_HELPMSG_HELP "HELPMSG\n..."
     IDS_GROUP_HELP "GROUP\n..."
     IDS_HELPMSG_SYNTAX "Usage:\nNET HELPMSG <Error Code>"
     IDS_HELPMSG_HELP "HELPMSG\n..."
-    IDS_LOCALGROUP_SYNTAX "Usage:\nNET LOCALGROUP ..."
+    IDS_LOCALGROUP_SYNTAX "Usage:\nNET LOCALGROUP [groupname [/COMMENT:""text""]] [/DOMAIN]\n\
+               groupname {/ADD [/COMMENT:""text""] | /DELETE} [/DOMAIN]\n\
+               groupname name [...] {/ADD | /DELETE} [/DOMAIN]"
     IDS_LOCALGROUP_HELP "LOCALGROUP\n..."
     IDS_NAME_SYNTAX "Usage:\nNET NAME ..."
     IDS_NAME_HELP "NAME\n..."
     IDS_LOCALGROUP_HELP "LOCALGROUP\n..."
     IDS_NAME_SYNTAX "Usage:\nNET NAME ..."
     IDS_NAME_HELP "NAME\n..."
index 56241fa..c8641eb 100644 (file)
@@ -24,7 +24,9 @@ BEGIN
     IDS_GROUP_HELP "GROUP\n..."
     IDS_HELPMSG_SYNTAX "Utilizare:\nNET HELPMSG <Error Code>"
     IDS_HELPMSG_HELP "HELPMSG\n..."
     IDS_GROUP_HELP "GROUP\n..."
     IDS_HELPMSG_SYNTAX "Utilizare:\nNET HELPMSG <Error Code>"
     IDS_HELPMSG_HELP "HELPMSG\n..."
-    IDS_LOCALGROUP_SYNTAX "Utilizare:\nNET LOCALGROUP ..."
+    IDS_LOCALGROUP_SYNTAX "Utilizare:\nNET LOCALGROUP [groupname [/COMMENT:""text""]] [/DOMAIN]\n\
+               groupname {/ADD [/COMMENT:""text""] | /DELETE} [/DOMAIN]\n\
+               groupname name [...] {/ADD | /DELETE} [/DOMAIN]"
     IDS_LOCALGROUP_HELP "LOCALGROUP\n..."
     IDS_NAME_SYNTAX "Utilizare:\nNET NAME ..."
     IDS_NAME_HELP "NAME\n..."
     IDS_LOCALGROUP_HELP "LOCALGROUP\n..."
     IDS_NAME_SYNTAX "Utilizare:\nNET NAME ..."
     IDS_NAME_HELP "NAME\n..."
index 29ec6f0..63531a8 100644 (file)
@@ -19,7 +19,9 @@ BEGIN
     IDS_GROUP_HELP "GROUP\n..."
     IDS_HELPMSG_SYNTAX "Использование:\nNET HELPMSG <Код ошибки>"
     IDS_HELPMSG_HELP "HELPMSG\n..."
     IDS_GROUP_HELP "GROUP\n..."
     IDS_HELPMSG_SYNTAX "Использование:\nNET HELPMSG <Код ошибки>"
     IDS_HELPMSG_HELP "HELPMSG\n..."
-    IDS_LOCALGROUP_SYNTAX "Использование:\nNET LOCALGROUP ..."
+    IDS_LOCALGROUP_SYNTAX "Использование:\nNET LOCALGROUP [groupname [/COMMENT:""text""]] [/DOMAIN]\n\
+               groupname {/ADD [/COMMENT:""text""] | /DELETE} [/DOMAIN]\n\
+               groupname name [...] {/ADD | /DELETE} [/DOMAIN]"
     IDS_LOCALGROUP_HELP "LOCALGROUP\n..."
     IDS_NAME_SYNTAX "Использование:\nNET NAME ..."
     IDS_NAME_HELP "NAME\n..."
     IDS_LOCALGROUP_HELP "LOCALGROUP\n..."
     IDS_NAME_SYNTAX "Использование:\nNET NAME ..."
     IDS_NAME_HELP "NAME\n..."
index f1560dd..9f226be 100644 (file)
@@ -28,7 +28,7 @@ COMMAND cmds[] =
     {L"group",      unimplemented},
     {L"help",       cmdHelp},
     {L"helpmsg",    cmdHelpMsg},
     {L"group",      unimplemented},
     {L"help",       cmdHelp},
     {L"helpmsg",    cmdHelpMsg},
-    {L"localgroup", unimplemented},
+    {L"localgroup", cmdLocalGroup},
     {L"name",       unimplemented},
     {L"pause",      cmdPause},
     {L"print",      unimplemented},
     {L"name",       unimplemented},
     {L"pause",      cmdPause},
     {L"print",      unimplemented},
index 93cf15d..016c018 100644 (file)
@@ -35,6 +35,7 @@ INT cmdAccounts(INT argc, WCHAR **argv);
 INT cmdContinue(INT argc, WCHAR **argv);
 INT cmdHelp(INT argc, WCHAR **argv);
 INT cmdHelpMsg(INT argc, WCHAR **argv);
 INT cmdContinue(INT argc, WCHAR **argv);
 INT cmdHelp(INT argc, WCHAR **argv);
 INT cmdHelpMsg(INT argc, WCHAR **argv);
+INT cmdLocalGroup(INT argc, WCHAR **argv);
 INT cmdPause(INT argc, WCHAR **argv);
 INT cmdStart(INT argc, WCHAR **argv);
 INT cmdStop(INT argc, WCHAR **argv);
 INT cmdPause(INT argc, WCHAR **argv);
 INT cmdStart(INT argc, WCHAR **argv);
 INT cmdStop(INT argc, WCHAR **argv);