[NET]
authorEric Kohl <eric.kohl@reactos.org>
Sat, 8 Nov 2014 21:44:32 +0000 (21:44 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sat, 8 Nov 2014 21:44:32 +0000 (21:44 +0000)
USER command:
- Replace stings by resource strings.
- Add a function to print padded resource strings.
- Fix the password input routine. Repeat if the passwords don't match.

svn path=/trunk/; revision=65332

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 0387ff6..e735723 100644 (file)
@@ -173,13 +173,25 @@ DisplayUser(LPWSTR lpUserName)
     if (Status != NERR_Success)
         goto done;
 
-    PrintToConsole(L"User name                    %s\n", pUserInfo->usri4_name);
-    PrintToConsole(L"Full name                    %s\n", pUserInfo->usri4_full_name);
-    PrintToConsole(L"Comment                      %s\n", pUserInfo->usri4_comment);
-    PrintToConsole(L"User comment                 %s\n", pUserInfo->usri4_usr_comment);
-    PrintToConsole(L"Country code                 %03ld ()\n", pUserInfo->usri4_country_code);
-    PrintToConsole(L"Account active               %s\n", (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE)? L"No" : ((pUserInfo->usri4_flags & UF_LOCKOUT) ? L"Locked" : L"Yes"));
-    PrintToConsole(L"Account expires              ");
+    PrintPaddedResourceString(IDS_USER_NAME);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_name);
+
+    PrintPaddedResourceString(IDS_USER_FULL_NAME);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_full_name);
+
+    PrintPaddedResourceString(IDS_USER_COMMENT);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_comment);
+
+    PrintPaddedResourceString(IDS_USER_USER_COMMENT);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_usr_comment);
+
+    PrintPaddedResourceString(IDS_USER_COUNTRY_CODE);
+    PrintToConsole(L"%03ld ()\n", pUserInfo->usri4_country_code);
+
+    PrintPaddedResourceString(IDS_USER_ACCOUNT_ACTIVE);
+    PrintToConsole(L"%s\n", (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE)? L"No" : ((pUserInfo->usri4_flags & UF_LOCKOUT) ? L"Locked" : L"Yes"));
+
+    PrintPaddedResourceString(IDS_USER_ACCOUNT_EXPIRES);
     if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER)
         PrintToConsole(L"Never\n");
     else
@@ -187,40 +199,55 @@ DisplayUser(LPWSTR lpUserName)
 
     PrintToConsole(L"\n");
 
-    PrintToConsole(L"Password last set            ");
+    PrintPaddedResourceString(IDS_USER_PW_LAST_SET);
     dwLastSet = GetTimeInSeconds() - pUserInfo->usri4_password_age;
     PrintDateTime(dwLastSet);
 
-    PrintToConsole(L"Password expires             ");
+    PrintPaddedResourceString(IDS_USER_PW_EXPIRES);
     if ((pUserInfo->usri4_flags & UF_DONT_EXPIRE_PASSWD) || pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER)
         PrintToConsole(L"Never\n");
     else
         PrintDateTime(dwLastSet + pUserModals->usrmod0_max_passwd_age);
 
-    PrintToConsole(L"Password changeable          ");
+    PrintPaddedResourceString(IDS_USER_PW_CHANGEABLE);
     PrintDateTime(dwLastSet + pUserModals->usrmod0_min_passwd_age);
 
-    PrintToConsole(L"Password required            %s\n", (pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? L"No" : L"Yes");
-    PrintToConsole(L"User may change password     %s\n", (pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? L"No" : L"Yes");
+    PrintPaddedResourceString(IDS_USER_PW_REQUIRED);
+    PrintToConsole(L"%s\n", (pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? L"No" : L"Yes");
+
+    PrintPaddedResourceString(IDS_USER_CHANGE_PW);
+    PrintToConsole(L"%s\n", (pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? L"No" : L"Yes");
 
     PrintToConsole(L"\n");
-    PrintToConsole(L"Workstations allowed         %s\n", (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0) ? L"All" : pUserInfo->usri4_workstations);
-    PrintToConsole(L"Logon script                 %s\n", pUserInfo->usri4_script_path);
-    PrintToConsole(L"User profile                 %s\n", pUserInfo->usri4_profile);
-    PrintToConsole(L"Home directory               %s\n", pUserInfo->usri4_home_dir);
-    PrintToConsole(L"Last logon                   ");
+
+    PrintPaddedResourceString(IDS_USER_WORKSTATIONS);
+    PrintToConsole(L"%s\n", (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0) ? L"All" : pUserInfo->usri4_workstations);
+
+    PrintPaddedResourceString(IDS_USER_LOGON_SCRIPT);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_script_path);
+
+    PrintPaddedResourceString(IDS_USER_PROFILE);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_profile);
+
+    PrintPaddedResourceString(IDS_USER_HOME_DIR);
+    PrintToConsole(L"%s\n", pUserInfo->usri4_home_dir);
+
+    PrintPaddedResourceString(IDS_USER_LAST_LOGON);
     if (pUserInfo->usri4_last_logon == 0)
         PrintToConsole(L"Never\n");
     else
         PrintDateTime(pUserInfo->usri4_last_logon);
+
     PrintToConsole(L"\n");
-    PrintToConsole(L"Logon hours allowed          ");
+
+    PrintPaddedResourceString(IDS_USER_LOGON_HOURS);
     if (pUserInfo->usri4_logon_hours == NULL)
         PrintToConsole(L"All\n");
+
     PrintToConsole(L"\n");
 
     PrintToConsole(L"\n");
-    PrintToConsole(L"Local group memberships      ");
+    PrintPaddedResourceString(IDS_USER_LOCAL_GROUPS);
     if (dwLocalGroupTotal != 0 && pLocalGroupInfo != NULL)
     {
         for (i = 0; i < dwLocalGroupTotal; i++)
@@ -235,7 +262,7 @@ DisplayUser(LPWSTR lpUserName)
         PrintToConsole(L"\n");
     }
 
-    PrintToConsole(L"Global group memberships     ");
+    PrintPaddedResourceString(IDS_USER_GLOBAL_GROUPS);
     if (dwGroupTotal != 0 && pGroupInfo != NULL)
     {
         for (i = 0; i < dwGroupTotal; i++)
@@ -279,32 +306,36 @@ ReadPassword(
 
     *lpAllocated = FALSE;
 
-    printf("Enter the password for user xxx: ");
-    ReadFromConsole(szPassword1, PWLEN + 1, FALSE);
-    printf("\n");
+    while (TRUE)
+    {
+        PrintResourceString(IDS_USER_ENTER_PASSWORD1);
+        ReadFromConsole(szPassword1, PWLEN + 1, FALSE);
+        printf("\n");
 
-    printf("Enter the password again: ");
-    ReadFromConsole(szPassword2, PWLEN + 1, FALSE);
-    printf("\n");
+        PrintResourceString(IDS_USER_ENTER_PASSWORD2);
+        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)
+        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;
+                return;
+            }
+        }
+        else
         {
-            wcscpy(ptr, szPassword1);
-            *lpPassword = ptr;
-            *lpAllocated = TRUE;
+            PrintResourceString(IDS_USER_NO_PASSWORD_MATCH);
+            *lpPassword = NULL;
         }
     }
-    else
-    {
-        printf("The passwords do not match!");
-        *lpPassword = NULL;
-    }
 }
 
 
index ae076a1..e360cb3 100644 (file)
@@ -65,6 +65,31 @@ BEGIN
       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |\n\
       SHARE | START | STATISTICS | STOP | TIME | USE | NET USER | VIEW ]\n"
 
+   IDS_USER_NAME "User name"
+   IDS_USER_FULL_NAME "Full name"
+   IDS_USER_COMMENT "Comment"
+   IDS_USER_USER_COMMENT "User comment"
+   IDS_USER_COUNTRY_CODE "Country code"
+   IDS_USER_ACCOUNT_ACTIVE "Account active"
+   IDS_USER_ACCOUNT_EXPIRES "Account expires"
+   IDS_USER_PW_LAST_SET "Password last set"
+   IDS_USER_PW_EXPIRES "Password expires"
+   IDS_USER_PW_CHANGEABLE "Password changeable"
+   IDS_USER_PW_REQUIRED "Password required"
+   IDS_USER_CHANGE_PW "User may change password"
+   IDS_USER_WORKSTATIONS "Workstations allowed"
+   IDS_USER_LOGON_SCRIPT "Logon script"
+   IDS_USER_PROFILE "User profile"
+   IDS_USER_HOME_DIR "Home directory"
+   IDS_USER_LAST_LOGON "Last logon"
+   IDS_USER_LOGON_HOURS "Logon hours allowed"
+   IDS_USER_LOCAL_GROUPS "Local group memberships"
+   IDS_USER_GLOBAL_GROUPS "Global group memberships"
+
+   IDS_USER_ENTER_PASSWORD1 "Enter a new password for the user: "
+   IDS_USER_ENTER_PASSWORD2 "Enter the password again: "
+   IDS_USER_NO_PASSWORD_MATCH "\nThe passwords do not match!\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 ad04716..292bd1d 100644 (file)
@@ -71,6 +71,31 @@ BEGIN
       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |\n\
       SHARE | START | STATISTICS | STOP | TIME | USE | NET USER | VIEW ]\n"
 
+   IDS_USER_NAME "User name"
+   IDS_USER_FULL_NAME "Full name"
+   IDS_USER_COMMENT "Comment"
+   IDS_USER_USER_COMMENT "User comment"
+   IDS_USER_COUNTRY_CODE "Country code"
+   IDS_USER_ACCOUNT_ACTIVE "Account active"
+   IDS_USER_ACCOUNT_EXPIRES "Account expires"
+   IDS_USER_PW_LAST_SET "Password last set"
+   IDS_USER_PW_EXPIRES "Password expires"
+   IDS_USER_PW_CHANGEABLE "Password changeable"
+   IDS_USER_PW_REQUIRED "Password required"
+   IDS_USER_CHANGE_PW "User may change password"
+   IDS_USER_WORKSTATIONS "Workstations allowed"
+   IDS_USER_LOGON_SCRIPT "Logon script"
+   IDS_USER_PROFILE "User profile"
+   IDS_USER_HOME_DIR "Home directory"
+   IDS_USER_LAST_LOGON "Last logon"
+   IDS_USER_LOGON_HOURS "Logon hours allowed"
+   IDS_USER_LOCAL_GROUPS "Local group memberships"
+   IDS_USER_GLOBAL_GROUPS "Global group memberships"
+
+   IDS_USER_ENTER_PASSWORD1 "Enter a new password for the user: "
+   IDS_USER_ENTER_PASSWORD2 "Enter the password again: "
+   IDS_USER_NO_PASSWORD_MATCH "\nThe passwords do not match!\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 c073f50..d9c4a0d 100644 (file)
@@ -67,6 +67,31 @@ BEGIN
       HELPMSG | LOCALGROUP | NAME | PAUSE | PRINT | SEND | SESSION |\n\
       SHARE | START | STATISTICS | STOP | TIME | USE | NET USER | VIEW ]\n"
 
+   IDS_USER_NAME "User name"
+   IDS_USER_FULL_NAME "Full name"
+   IDS_USER_COMMENT "Comment"
+   IDS_USER_USER_COMMENT "User comment"
+   IDS_USER_COUNTRY_CODE "Country code"
+   IDS_USER_ACCOUNT_ACTIVE "Account active"
+   IDS_USER_ACCOUNT_EXPIRES "Account expires"
+   IDS_USER_PW_LAST_SET "Password last set"
+   IDS_USER_PW_EXPIRES "Password expires"
+   IDS_USER_PW_CHANGEABLE "Password changeable"
+   IDS_USER_PW_REQUIRED "Password required"
+   IDS_USER_CHANGE_PW "User may change password"
+   IDS_USER_WORKSTATIONS "Workstations allowed"
+   IDS_USER_LOGON_SCRIPT "Logon script"
+   IDS_USER_PROFILE "User profile"
+   IDS_USER_HOME_DIR "Home directory"
+   IDS_USER_LAST_LOGON "Last logon"
+   IDS_USER_LOGON_HOURS "Logon hours allowed"
+   IDS_USER_LOCAL_GROUPS "Local group memberships"
+   IDS_USER_GLOBAL_GROUPS "Global group memberships"
+
+   IDS_USER_ENTER_PASSWORD1 "Enter a new password for the user: "
+   IDS_USER_ENTER_PASSWORD2 "Enter the password again: "
+   IDS_USER_NO_PASSWORD_MATCH "\nThe passwords do not match!\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 54ae670..19898d3 100644 (file)
@@ -64,6 +64,25 @@ PrintResourceString(
 }
 
 
+VOID
+PrintPaddedResourceString(
+    INT resID)
+{
+    WCHAR szMsgBuffer[MAX_BUFFER_SIZE];
+    INT nLength, nPaddedLength = 29, i;
+
+    nLength = LoadStringW(GetModuleHandle(NULL), resID, szMsgBuffer, MAX_BUFFER_SIZE);
+    if (nLength < nPaddedLength)
+    {
+        for (i = nLength; i < nPaddedLength; i++)
+            szMsgBuffer[i] = L' ';
+        szMsgBuffer[nPaddedLength] = UNICODE_NULL;
+    }
+
+    WriteToConsole(szMsgBuffer);
+}
+
+
 VOID
 PrintToConsole(
     LPWSTR lpFormat,
index 09d6b3d..4fdf7d1 100644 (file)
@@ -30,6 +30,10 @@ PrintResourceString(
     INT resID,
     ...);
 
+VOID
+PrintPaddedResourceString(
+    INT resID);
+
 VOID
 PrintToConsole(
     LPWSTR lpFormat,
index d0de884..f1721eb 100644 (file)
 #define IDS_HELP_SYNTAX       142
 #define IDS_NET_SYNTAX        143
 
+#define IDS_USER_NAME                  450
+#define IDS_USER_FULL_NAME             451
+#define IDS_USER_COMMENT               452
+#define IDS_USER_USER_COMMENT          453
+#define IDS_USER_COUNTRY_CODE          454
+#define IDS_USER_ACCOUNT_ACTIVE        455
+#define IDS_USER_ACCOUNT_EXPIRES       456
+#define IDS_USER_PW_LAST_SET           457
+#define IDS_USER_PW_EXPIRES            458
+#define IDS_USER_PW_CHANGEABLE         459
+#define IDS_USER_PW_REQUIRED           460
+#define IDS_USER_CHANGE_PW             461
+#define IDS_USER_WORKSTATIONS          462
+#define IDS_USER_LOGON_SCRIPT          463
+#define IDS_USER_PROFILE               464
+#define IDS_USER_HOME_DIR              465
+#define IDS_USER_LAST_LOGON            466
+#define IDS_USER_LOGON_HOURS           467
+#define IDS_USER_LOCAL_GROUPS          468
+#define IDS_USER_GLOBAL_GROUPS         469
+
+#define IDS_USER_ENTER_PASSWORD1       490
+#define IDS_USER_ENTER_PASSWORD2       491
+#define IDS_USER_NO_PASSWORD_MATCH     492
+
 #define IDS_ERROR_OPTION_NOT_SUPPORTED 500
 #define IDS_ERROR_INVALID_OPTION_VALUE 501