[NET]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 8 Nov 2014 14:35:27 +0000 (14:35 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 8 Nov 2014 14:35:27 +0000 (14:35 +0000)
- Convert error messages to resource strings.
- ACCOUNTS: Add some padding to display strings.
- USER: Support interactive password input.

svn path=/trunk/; revision=65323

reactos/base/applications/network/net/cmdAccounts.c
reactos/base/applications/network/net/cmdLocalGroup.c
reactos/base/applications/network/net/cmdUser.c
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
reactos/base/applications/network/net/resource.h

index dcd93de..63ffc61 100644 (file)
@@ -48,7 +48,7 @@ cmdAccounts(
 
         if (_wcsicmp(argv[i], L"/domain") == 0)
         {
-            PrintToConsole(L"The /DOMAIN option is not supported yet!\n");
+            PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
 #if 0
             Domain = TRUE;
 #endif
@@ -74,7 +74,7 @@ cmdAccounts(
                 value = wcstoul(p, &endptr, 10);
                 if (*endptr != 0)
                 {
-                    PrintToConsole(L"You entered an invalid value for the /FORCELOGOFF option.\n");
+                    PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/FORCELOGOFF");
                     result = 1;
                     goto done;
                 }
@@ -89,7 +89,7 @@ cmdAccounts(
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                    PrintToConsole(L"You entered an invalid value for the /MINPWLEN option.\n");
+                    PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWLEN");
                     result = 1;
                     goto done;
             }
@@ -111,7 +111,7 @@ cmdAccounts(
                 value = wcstoul(p, &endptr, 10);
                 if (*endptr != 0)
                 {
-                    PrintToConsole(L"You entered an invalid value for the /MAXPWAGE option.\n");
+                    PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/MAXPWLEN");
                     result = 1;
                     goto done;
                 }
@@ -126,7 +126,7 @@ cmdAccounts(
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                PrintToConsole(L"You entered an invalid value for the /MINPWAGE option.\n");
+                PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWAGE");
                 result = 1;
                 goto done;
             }
@@ -140,7 +140,7 @@ cmdAccounts(
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                PrintToConsole(L"You entered an invalid value for the /UNIQUEPW option.\n");
+                PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/UNIQUEPW");
                 result = 1;
                 goto done;
             }
@@ -168,32 +168,32 @@ cmdAccounts(
 
         RtlGetNtProductType(&ProductType);
 
-        PrintToConsole(L"Force logoff after: ");
+        PrintToConsole(L"Force logoff after:                                       ");
         if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
             PrintToConsole(L"Never\n");
         else
             PrintToConsole(L"%lu seconds\n", Info0->usrmod0_force_logoff);
 
-        PrintToConsole(L"Minimum password age (in days): %lu\n", Info0->usrmod0_min_passwd_age / 86400);
-        PrintToConsole(L"Maximum password age (in days): %lu\n", Info0->usrmod0_max_passwd_age / 86400);
-        PrintToConsole(L"Minimum password length: %lu\n", Info0->usrmod0_min_passwd_len);
+        PrintToConsole(L"Minimum password age (in days):                           %lu\n", Info0->usrmod0_min_passwd_age / 86400);
+        PrintToConsole(L"Maximum password age (in days):                           %lu\n", Info0->usrmod0_max_passwd_age / 86400);
+        PrintToConsole(L"Minimum password length:                                  %lu\n", Info0->usrmod0_min_passwd_len);
 
-        PrintToConsole(L"Password history length: ");
+        PrintToConsole(L"Password history length:                                  ");
         if (Info0->usrmod0_password_hist_len == 0)
             PrintToConsole(L"None\n");
         else
             PrintToConsole(L"%lu\n", Info0->usrmod0_password_hist_len);
 
-        PrintToConsole(L"Lockout threshold: ");
+        PrintToConsole(L"Lockout threshold:                                        ");
         if (Info3->usrmod3_lockout_threshold == 0)
             PrintToConsole(L"Never\n");
         else
             PrintToConsole(L"%lu\n", Info3->usrmod3_lockout_threshold);
 
-        PrintToConsole(L"Lockout duration (in minutes): %lu\n", Info3->usrmod3_lockout_duration / 60);
-        PrintToConsole(L"Lockout observation window (in minutes): %lu\n", Info3->usrmod3_lockout_observation_window / 60);
+        PrintToConsole(L"Lockout duration (in minutes):                            %lu\n", Info3->usrmod3_lockout_duration / 60);
+        PrintToConsole(L"Lockout observation window (in minutes):                  %lu\n", Info3->usrmod3_lockout_observation_window / 60);
 
-        PrintToConsole(L"Computer role: ");
+        PrintToConsole(L"Computer role:                                            ");
 
         if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
         {
index 3cd5af4..adce9d1 100644 (file)
@@ -248,7 +248,7 @@ cmdLocalGroup(
         }
         else if (_wcsicmp(argv[i], L"/domain") == 0)
         {
-            printf("The /DOMAIN option is not supported yet!\n");
+            PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
 #if 0
             bDomain = TRUE;
 #endif
index c9d07c4..0387ff6 100644 (file)
@@ -267,6 +267,47 @@ done:
 }
 
 
+static
+VOID
+ReadPassword(
+    LPWSTR *lpPassword,
+    LPBOOL lpAllocated)
+{
+    WCHAR szPassword1[PWLEN + 1];
+    WCHAR szPassword2[PWLEN + 1];
+    LPWSTR ptr;
+
+    *lpAllocated = FALSE;
+
+    printf("Enter the password for user xxx: ");
+    ReadFromConsole(szPassword1, PWLEN + 1, FALSE);
+    printf("\n");
+
+    printf("Enter the password again: ");
+    ReadFromConsole(szPassword2, PWLEN + 1, FALSE);
+    printf("\n");
+
+    if (wcslen(szPassword1) == wcslen(szPassword2) &&
+        wcscmp(szPassword1, szPassword2) == 0)
+    {
+        ptr = HeapAlloc(GetProcessHeap(),
+                        0,
+                        (wcslen(szPassword1) + 1) * sizeof(WCHAR));
+        if (ptr != NULL)
+        {
+            wcscpy(ptr, szPassword1);
+            *lpPassword = ptr;
+            *lpAllocated = TRUE;
+        }
+    }
+    else
+    {
+        printf("The passwords do not match!");
+        *lpPassword = NULL;
+    }
+}
+
+
 INT
 cmdUser(
     INT argc,
@@ -286,6 +327,7 @@ cmdUser(
     LPWSTR p;
     LPWSTR endptr;
     DWORD value;
+    BOOL bPasswordAllocated = FALSE;
     NET_API_STATUS Status;
 
     if (argc == 2)
@@ -305,14 +347,14 @@ cmdUser(
     if (argv[i][0] != L'/')
     {
         lpUserName = argv[i];
-        printf("User: %S\n", lpUserName);
+//        printf("User: %S\n", lpUserName);
         i++;
     }
 
     if (argv[i][0] != L'/')
     {
         lpPassword = argv[i];
-        printf("Password: %S\n", lpPassword);
+//        printf("Password: %S\n", lpPassword);
         i++;
     }
 
@@ -333,7 +375,7 @@ cmdUser(
         }
         else if (_wcsicmp(argv[j], L"/domain") == 0)
         {
-            printf("The /DOMAIN option is not supported yet!\n");
+            PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
 #if 0
             bDomain = TRUE;
 #endif
@@ -346,6 +388,13 @@ cmdUser(
         goto done;
     }
 
+    /* Interactive password input */
+    if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0)
+    {
+        ReadPassword(&lpPassword,
+                     &bPasswordAllocated);
+    }
+
     if (!bAdd && !bDelete)
     {
         /* Modify the user */
@@ -387,7 +436,7 @@ cmdUser(
             }
             else
             {
-                PrintToConsole(L"You entered an invalid value for the /ACTIVE option.\n");
+                PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/ACTIVE");
                 result = 1;
                 goto done;
             }
@@ -402,7 +451,7 @@ cmdUser(
             value = wcstoul(p, &endptr, 10);
             if (*endptr != 0)
             {
-                PrintToConsole(L"You entered an invalid value for the /COUNTRYCODE option.\n");
+                PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/COUNTRYCODE");
                 result = 1;
                 goto done;
             }
@@ -413,6 +462,16 @@ cmdUser(
         }
         else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0)
         {
+            p = &argv[i][9];
+            if (_wcsicmp(p, L"never") == 0)
+            {
+                pUserInfo->usri4_acct_expires = TIMEQ_FOREVER;
+            }
+            else
+            {
+                /* FIXME: Parse the date */
+                PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/EXPIRES");
+            }
         }
         else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0)
         {
@@ -435,7 +494,7 @@ cmdUser(
             }
             else
             {
-                PrintToConsole(L"You entered an invalid value for the /PASSWORDCHG option.\n");
+                PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDCHG");
                 result = 1;
                 goto done;
             }
@@ -453,7 +512,7 @@ cmdUser(
             }
             else
             {
-                PrintToConsole(L"You entered an invalid value for the /PASSWORDREQ option.\n");
+                PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDREQ");
                 result = 1;
                 goto done;
             }
@@ -468,6 +527,8 @@ cmdUser(
         }
         else if (_wcsnicmp(argv[j], L"/times:", 7) == 0)
         {
+            /* FIXME */
+            PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/TIMES");
         }
         else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0)
         {
@@ -475,6 +536,8 @@ cmdUser(
         }
         else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0)
         {
+            /* FIXME */
+            PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/WORKSTATIONS");
         }
     }
 
@@ -506,6 +569,9 @@ cmdUser(
     }
 
 done:
+    if (bPasswordAllocated == TRUE && lpPassword != NULL)
+        HeapFree(GetProcessHeap(), 0, lpPassword);
+
     if (!bAdd && !bDelete && pUserInfo != NULL)
         NetApiBufferFree(pUserInfo);
 
index d84ca73..ae076a1 100644 (file)
@@ -34,7 +34,7 @@ BEGIN
     IDS_SESSION_HELP "SESSION\n..."
     IDS_SHARE_SYNTAX "Usage:\nNET SHARE ..."
     IDS_SHARE_HELP "SHARE\n..."
-    IDS_START_SYNTAX "Usage:\nNET START ..."
+    IDS_START_SYNTAX "Usage:\nNET START <Service name>"
     IDS_START_HELP "START\n..."
     IDS_STATISTICS_SYNTAX "Usage:\nNET STATISTICS ..."
     IDS_STATISTICS_HELP "STATISTICS\n..."
@@ -64,4 +64,7 @@ BEGIN
     IDS_NET_SYNTAX "Usage:\nNET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |\n\
       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |\n\
       SHARE | START | STATISTICS | STOP | TIME | USE | NET USER | VIEW ]\n"
+
+   IDS_ERROR_OPTION_NOT_SUPPORTED "The %s option is not supported yet.\n"
+   IDS_ERROR_INVALID_OPTION_VALUE "You entered an invalid value for the %s option.\n"
 END
index 6ed299c..ad04716 100644 (file)
@@ -70,4 +70,7 @@ BEGIN
     IDS_NET_SYNTAX "Utilizare:\nNET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |\n\
       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |\n\
       SHARE | START | STATISTICS | STOP | TIME | USE | NET USER | VIEW ]\n"
+
+   IDS_ERROR_OPTION_NOT_SUPPORTED "The %s option is not supported yet.\n"
+   IDS_ERROR_INVALID_OPTION_VALUE "You entered an invalid value for the %s option.\n"
 END
index aa5c2da..c073f50 100644 (file)
@@ -66,4 +66,7 @@ BEGIN
     IDS_NET_SYNTAX "Использование:\nNET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP |\n\
       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |\n\
       SHARE | START | STATISTICS | STOP | TIME | USE | NET USER | VIEW ]\n"
+
+   IDS_ERROR_OPTION_NOT_SUPPORTED "The %s option is not supported yet.\n"
+   IDS_ERROR_INVALID_OPTION_VALUE "You entered an invalid value for the %s option.\n"
 END
index 1b489cc..54ae670 100644 (file)
@@ -118,6 +118,43 @@ WriteToConsole(
 }
 
 
+VOID
+ReadFromConsole(
+    LPWSTR lpInput,
+    DWORD dwLength,
+    BOOL bEcho)
+{
+    DWORD dwOldMode;
+    DWORD dwRead = 0;
+    HANDLE hFile;
+    LPWSTR p;
+    PCHAR pBuf;
+
+    pBuf = HeapAlloc(GetProcessHeap(), 0, dwLength - 1);
+    ZeroMemory(lpInput, dwLength * sizeof(WCHAR));
+    hFile = GetStdHandle(STD_INPUT_HANDLE);
+    GetConsoleMode(hFile, &dwOldMode);
+
+    SetConsoleMode(hFile, ENABLE_LINE_INPUT | (bEcho ? ENABLE_ECHO_INPUT : 0));
+
+    ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
+
+    MultiByteToWideChar(CP_OEMCP, 0, pBuf, dwRead, lpInput, dwLength - 1);
+    HeapFree(GetProcessHeap(), 0, pBuf);
+
+    for (p = lpInput; *p; p++)
+    {
+        if (*p == L'\x0d')
+        {
+            *p = L'\0';
+            break;
+        }
+    }
+
+    SetConsoleMode(hFile, dwOldMode);
+}
+
+
 int wmain(int argc, WCHAR **argv)
 {
     PCOMMAND cmdptr;
index 7f1d059..09d6b3d 100644 (file)
@@ -39,6 +39,12 @@ VOID
 WriteToConsole(
     LPWSTR lpString);
 
+VOID
+ReadFromConsole(
+    LPWSTR lpInput,
+    DWORD dwLength,
+    BOOL bEcho);
+
 VOID help(VOID);
 INT unimplemented(INT argc, WCHAR **argv);
 
index f13e3e1..d0de884 100644 (file)
@@ -44,3 +44,6 @@
 #define IDS_VIEW_HELP         141
 #define IDS_HELP_SYNTAX       142
 #define IDS_NET_SYNTAX        143
+
+#define IDS_ERROR_OPTION_NOT_SUPPORTED 500
+#define IDS_ERROR_INVALID_OPTION_VALUE 501