[NET]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 31 May 2014 08:32:54 +0000 (08:32 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 31 May 2014 08:32:54 +0000 (08:32 +0000)
- Fix an off-by-one bug in the ACCOUNTS command.
- Improve input validation for the ACCOUNTS command.
- Add the /help option to the CONTINUE command.
- Add version resource and start to move texts into resources.

svn path=/trunk/; revision=63509

reactos/base/applications/network/net/CMakeLists.txt
reactos/base/applications/network/net/cmdAccounts.c
reactos/base/applications/network/net/cmdContinue.c
reactos/base/applications/network/net/help.c
reactos/base/applications/network/net/lang/en-US.rc [new file with mode: 0644]
reactos/base/applications/network/net/main.c
reactos/base/applications/network/net/net.h
reactos/base/applications/network/net/net.rc [new file with mode: 0644]
reactos/base/applications/network/net/resource.h [new file with mode: 0644]

index 377065e..a740d3a 100644 (file)
@@ -12,8 +12,8 @@ list(APPEND SOURCE
     help.c
     net.h)
 
     help.c
     net.h)
 
-add_executable(net ${SOURCE})
+add_executable(net ${SOURCE} net.rc)
 set_module_type(net win32cui UNICODE)
 set_module_type(net win32cui UNICODE)
-add_importlibs(net advapi32 netapi32 msvcrt kernel32 ntdll)
+add_importlibs(net advapi32 netapi32 msvcrt kernel32 user32 ntdll)
 add_pch(net net.h SOURCE)
 add_cd_file(TARGET net DESTINATION reactos/system32 FOR all)
 add_pch(net net.h SOURCE)
 add_cd_file(TARGET net DESTINATION reactos/system32 FOR all)
index eb91c85..456ac4c 100644 (file)
@@ -18,33 +18,34 @@ cmdAccounts(
     PUSER_MODALS_INFO_1 Info1 = NULL;
     PUSER_MODALS_INFO_3 Info3 = NULL;
     NT_PRODUCT_TYPE ProductType;
     PUSER_MODALS_INFO_1 Info1 = NULL;
     PUSER_MODALS_INFO_3 Info3 = NULL;
     NT_PRODUCT_TYPE ProductType;
-    LPWSTR p, perr;
+    LPWSTR p;
+    LPWSTR endptr;
     DWORD ParamErr;
     ULONG value;
     INT i;
     BOOL Modified = FALSE;
 //    BOOL Domain = FALSE;
     NET_API_STATUS Status;
     DWORD ParamErr;
     ULONG value;
     INT i;
     BOOL Modified = FALSE;
 //    BOOL Domain = FALSE;
     NET_API_STATUS Status;
+    INT result = 0;
 
 
-    for (i = 3; i < argc; i++)
+    for (i = 2; i < argc; i++)
     {
     {
-        if (wcsicmp(argv[i], L"help") == 0)
+        if (_wcsicmp(argv[i], L"help") == 0)
         {
             /* Print short syntax help */
         {
             /* Print short syntax help */
-            puts("NET ACCOUNTS [/FORCELOGOFF:{Minutes|NO}] [/MINPWLEN:Length]");
-            puts("             [/MAXPWAGE:{Days|UNLIMITED}] [/MINPWAGE:Days]");
-            puts("             [/UNIQUEPW:Count] [/DOMAIN]");
+            PrintResourceString(IDS_ACCOUNTS_SYNTAX);
             return 0;
         }
 
             return 0;
         }
 
-        if (wcsicmp(argv[i], L"/help") == 0)
+        if (_wcsicmp(argv[i], L"/help") == 0)
         {
         {
-            /* FIXME: Print long help text*/
+            /* Print full help text*/
+            PrintResourceString(IDS_ACCOUNTS_HELP);
             return 0;
         }
 
 /*
             return 0;
         }
 
 /*
-        if (wcsicmp(argv[i], L"/domain") == 0)
+        if (_wcsicmp(argv[i], L"/domain") == 0)
         {
             Domain = TRUE;
         }
         {
             Domain = TRUE;
         }
@@ -55,7 +56,7 @@ cmdAccounts(
     if (Status != NERR_Success)
         goto done;
 
     if (Status != NERR_Success)
         goto done;
 
-    for (i = 3; i < argc; i++)
+    for (i = 2; i < argc; i++)
     {
         if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
         {
     {
         if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
         {
@@ -67,7 +68,13 @@ cmdAccounts(
             }
             else
             {
             }
             else
             {
-                value = wcstoul(p, &perr, 10);
+                value = wcstoul(p, &endptr, 10);
+                if (*endptr != 0)
+                {
+                    printf("You entered an invalid value for the /FORCELOGOFF option.\n");
+                    result = 1;
+                    goto done;
+                }
 
                 Info0->usrmod0_force_logoff = value * 60;
                 Modified = TRUE;
 
                 Info0->usrmod0_force_logoff = value * 60;
                 Modified = TRUE;
@@ -76,7 +83,14 @@ cmdAccounts(
         else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
         {
             p = &argv[i][10];
         else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
         {
             p = &argv[i][10];
-            value = wcstoul(p, &perr, 10);
+            value = wcstoul(p, &endptr, 10);
+            if (*endptr != 0)
+            {
+                    printf("You entered an invalid value for the /MINPWLEN option.\n");
+                    result = 1;
+                    goto done;
+            }
+
             Info0->usrmod0_min_passwd_len = value;
             Modified = TRUE;
         }
             Info0->usrmod0_min_passwd_len = value;
             Modified = TRUE;
         }
@@ -91,7 +105,13 @@ cmdAccounts(
             }
             else
             {
             }
             else
             {
-                value = wcstoul(p, &perr, 10);
+                value = wcstoul(p, &endptr, 10);
+                if (*endptr != 0)
+                {
+                    printf("You entered an invalid value for the /MAXPWAGE option.\n");
+                    result = 1;
+                    goto done;
+                }
 
                 Info0->usrmod0_max_passwd_age = value * 86400;
                 Modified = TRUE;
 
                 Info0->usrmod0_max_passwd_age = value * 86400;
                 Modified = TRUE;
@@ -100,7 +120,13 @@ cmdAccounts(
         else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
         {
             p = &argv[i][10];
         else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
         {
             p = &argv[i][10];
-            value = wcstoul(p, &perr, 10);
+            value = wcstoul(p, &endptr, 10);
+            if (*endptr != 0)
+            {
+                printf("You entered an invalid value for the /MINPWAGE option.\n");
+                result = 1;
+                goto done;
+            }
 
             Info0->usrmod0_min_passwd_age = value * 86400;
             Modified = TRUE;
 
             Info0->usrmod0_min_passwd_age = value * 86400;
             Modified = TRUE;
@@ -108,7 +134,13 @@ cmdAccounts(
         else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
         {
             p = &argv[i][10];
         else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
         {
             p = &argv[i][10];
-            value = wcstoul(p, &perr, 10);
+            value = wcstoul(p, &endptr, 10);
+            if (*endptr != 0)
+            {
+                printf("You entered an invalid value for the /UNIQUEPW option.\n");
+                result = 1;
+                goto done;
+            }
 
             Info0->usrmod0_password_hist_len = value;
             Modified = TRUE;
 
             Info0->usrmod0_password_hist_len = value;
             Modified = TRUE;
@@ -149,7 +181,12 @@ cmdAccounts(
         else
             printf("%lu\n", Info0->usrmod0_password_hist_len);
 
         else
             printf("%lu\n", Info0->usrmod0_password_hist_len);
 
-        printf("Lockout threshold: %lu\n", Info3->usrmod3_lockout_threshold);
+        printf("Lockout threshold: ");
+        if (Info3->usrmod3_lockout_threshold == 0)
+            printf("Never\n");
+        else
+            printf("%lu\n", Info3->usrmod3_lockout_threshold);
+
         printf("Lockout duration (in minutes): %lu\n", Info3->usrmod3_lockout_duration / 60);
         printf("Lockout observation window (in minutes): %lu\n", Info3->usrmod3_lockout_observation_window / 60);
 
         printf("Lockout duration (in minutes): %lu\n", Info3->usrmod3_lockout_duration / 60);
         printf("Lockout observation window (in minutes): %lu\n", Info3->usrmod3_lockout_observation_window / 60);
 
@@ -186,7 +223,7 @@ done:
     if (Info0 != NULL)
         NetApiBufferFree(Info0);
 
     if (Info0 != NULL)
         NetApiBufferFree(Info0);
 
-    return 0;
+    return result;
 }
 
 /* EOF */
 }
 
 /* EOF */
index 7f23fa5..f36111a 100644 (file)
@@ -15,13 +15,23 @@ INT cmdContinue(INT argc, WCHAR **argv)
     SC_HANDLE hService = NULL;
     SERVICE_STATUS status;
     INT nError = 0;
     SC_HANDLE hService = NULL;
     SERVICE_STATUS status;
     INT nError = 0;
+    INT i;
 
     if (argc != 3)
     {
 
     if (argc != 3)
     {
-        puts("Usage: NET CONTINUE <Service Name>");
+        PrintResourceString(IDS_CONTINUE_SYNTAX);
         return 1;
     }
 
         return 1;
     }
 
+    for (i = 2; i < argc; i++)
+    {
+        if (_wcsicmp(argv[i], L"/help") == 0)
+        {
+            PrintResourceString(IDS_CONTINUE_HELP);
+            return 1;
+        }
+    }
+
     hManager = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE);
     if (hManager == NULL)
     {
     hManager = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ENUMERATE_SERVICE);
     if (hManager == NULL)
     {
index 089f4a6..4606156 100644 (file)
@@ -18,8 +18,7 @@ INT cmdHelp(INT argc, WCHAR **argv)
 
     if (_wcsicmp(argv[2],L"ACCOUNTS")==0)
     {
 
     if (_wcsicmp(argv[2],L"ACCOUNTS")==0)
     {
-        puts("ACCOUNTS");
-        puts("help text");
+        PrintResourceString(IDS_ACCOUNTS_HELP);
         return 0;
     }
 
         return 0;
     }
 
@@ -39,8 +38,7 @@ INT cmdHelp(INT argc, WCHAR **argv)
 
     if (_wcsicmp(argv[2],L"CONTINUE")==0)
     {
 
     if (_wcsicmp(argv[2],L"CONTINUE")==0)
     {
-        puts("CONTINUE");
-        puts("help text");
+        PrintResourceString(IDS_CONTINUE_HELP);
         return 0;
     }
 
         return 0;
     }
 
diff --git a/reactos/base/applications/network/net/lang/en-US.rc b/reactos/base/applications/network/net/lang/en-US.rc
new file mode 100644 (file)
index 0000000..99cd546
--- /dev/null
@@ -0,0 +1,11 @@
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+STRINGTABLE
+BEGIN
+    IDS_ACCOUNTS_SYNTAX "Usage:\nNET ACCOUNTS [/FORCELOGOFF:{Minutes|NO}] [/MINPWLEN:Length]\n\
+             [/MAXPWAGE:{Days|UNLIMITED}] [/MINPWAGE:Days]\n\
+             [/UNIQUEPW:Count] [/DOMAIN]\n"
+    IDS_ACCOUNTS_HELP "ACCOUNTS\nhelp text"
+    IDS_CONTINUE_SYNTAX "Usage:\nNET CONTINUE <Service Name>"
+    IDS_CONTINUE_HELP "CONTINUE\nhelp text"
+END
index ad70251..b0ae7a9 100644 (file)
@@ -9,6 +9,8 @@
 
 #include "net.h"
 
 
 #include "net.h"
 
+#define MAX_BUFFER_SIZE 4096
+
 typedef struct _COMMAND
 {
     WCHAR *name;
 typedef struct _COMMAND
 {
     WCHAR *name;
@@ -43,6 +45,22 @@ COMMAND cmds[] =
     {NULL,          NULL}
 };
 
     {NULL,          NULL}
 };
 
+
+VOID
+PrintResourceString(
+    INT resID,
+    ...)
+{
+    WCHAR szMsgBuf[MAX_BUFFER_SIZE];
+    va_list arg_ptr;
+
+    va_start(arg_ptr, resID);
+    LoadStringW(GetModuleHandle(NULL), resID, szMsgBuf, MAX_BUFFER_SIZE);
+    vwprintf(szMsgBuf, arg_ptr);
+    va_end(arg_ptr);
+}
+
+
 int wmain(int argc, WCHAR **argv)
 {
     PCOMMAND cmdptr;
 int wmain(int argc, WCHAR **argv)
 {
     PCOMMAND cmdptr;
index 91af9d0..93cf15d 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <windef.h>
 #include <winbase.h>
 
 #include <windef.h>
 #include <winbase.h>
+#include <winuser.h>
 #include <winsvc.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <winsvc.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <lm.h>
 #include <ndk/rtlfuncs.h>
 
 #include <lm.h>
 #include <ndk/rtlfuncs.h>
 
+#include "resource.h"
+
+VOID
+PrintResourceString(
+    INT resID,
+    ...);
+
 VOID help(VOID);
 INT unimplemented(INT argc, WCHAR **argv);
 
 VOID help(VOID);
 INT unimplemented(INT argc, WCHAR **argv);
 
diff --git a/reactos/base/applications/network/net/net.rc b/reactos/base/applications/network/net/net.rc
new file mode 100644 (file)
index 0000000..ef6ba03
--- /dev/null
@@ -0,0 +1,17 @@
+#include <windef.h>
+
+#include "resource.h"
+
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+
+#define REACTOS_STR_FILE_DESCRIPTION   "ReactOS Net Command"
+#define REACTOS_STR_INTERNAL_NAME      "net"
+#define REACTOS_STR_ORIGINAL_FILENAME  "net.exe"
+#include <reactos/version.rc>
+
+/* UTF-8 */
+#pragma code_page(65001)
+
+#ifdef LANGUAGE_EN_US
+    #include "lang/en-US.rc"
+#endif
diff --git a/reactos/base/applications/network/net/resource.h b/reactos/base/applications/network/net/resource.h
new file mode 100644 (file)
index 0000000..54d5913
--- /dev/null
@@ -0,0 +1,6 @@
+#pragma once
+
+#define IDS_ACCOUNTS_SYNTAX 100
+#define IDS_ACCOUNTS_HELP   101
+#define IDS_CONTINUE_SYNTAX 102
+#define IDS_CONTINUE_HELP   103
\ No newline at end of file