[NET]
[reactos.git] / reactos / base / applications / network / net / cmdUser.c
index e735723..3525ccb 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS net command
- * FILE:
+ * FILE:            base/applications/network/net/cmdUser.c
  * PURPOSE:
  *
  * PROGRAMMERS:     Eric Kohl
+ *                  Curtis Wilson
  */
 
 #include "net.h"
@@ -37,37 +38,42 @@ EnumerateUsers(VOID)
     if (Status != NERR_Success)
         return Status;
 
-    PrintToConsole(L"\nUser accounts for \\\\%s\n\n", pServer->sv100_name);
+    PrintToConsole(L"\n");
+    PrintResourceString(IDS_USER_ACCOUNTS, pServer->sv100_name);
+    PrintToConsole(L"\n\n");
+    PrintPadding(L'-', 79);
+    PrintToConsole(L"\n");
 
     NetApiBufferFree(pServer);
 
-    PrintToConsole(L"------------------------------------------\n");
-
-    Status = NetUserEnum(NULL,
-                         0,
-                         0,
-                         (LPBYTE*)&pBuffer,
-                         MAX_PREFERRED_LENGTH,
-                         &dwRead,
-                         &dwTotal,
-                         &ResumeHandle);
-    if (Status != NERR_Success)
-        return Status;
-
-    qsort(pBuffer,
-          dwRead,
-          sizeof(PUSER_INFO_0),
-          CompareInfo);
-
-//    printf("dwRead: %lu  dwTotal: %lu\n", dwRead, dwTotal);
-    for (i = 0; i < dwRead; i++)
+    do
     {
-//        printf("%p\n", pBuffer[i].lgrpi0_name);
-         if (pBuffer[i].usri0_name)
-            PrintToConsole(L"%s\n", pBuffer[i].usri0_name);
-    }
+        Status = NetUserEnum(NULL,
+                             0,
+                             0,
+                             (LPBYTE*)&pBuffer,
+                             MAX_PREFERRED_LENGTH,
+                             &dwRead,
+                             &dwTotal,
+                             &ResumeHandle);
+        if ((Status != NERR_Success) && (Status != ERROR_MORE_DATA))
+            return Status;
+
+        qsort(pBuffer,
+              dwRead,
+              sizeof(PUSER_INFO_0),
+              CompareInfo);
+
+        for (i = 0; i < dwRead; i++)
+        {
+            if (pBuffer[i].usri0_name)
+                PrintToConsole(L"%s\n", pBuffer[i].usri0_name);
+        }
 
-    NetApiBufferFree(pBuffer);
+        NetApiBufferFree(pBuffer);
+        pBuffer = NULL;
+    }
+    while (Status == ERROR_MORE_DATA);
 
     return NERR_Success;
 }
@@ -103,7 +109,7 @@ PrintDateTime(DWORD dwSeconds)
                    TimeBuffer,
                    80);
 
-    PrintToConsole(L"%s %s\n", DateBuffer, TimeBuffer);
+    PrintToConsole(L"%s %s", DateBuffer, TimeBuffer);
 }
 
 
@@ -136,6 +142,7 @@ DisplayUser(LPWSTR lpUserName)
     DWORD dwGroupRead, dwGroupTotal;
     DWORD dwLastSet;
     DWORD i;
+    INT nPaddedLength = 29;
     NET_API_STATUS Status;
 
     /* Modify the user */
@@ -173,87 +180,95 @@ DisplayUser(LPWSTR lpUserName)
     if (Status != NERR_Success)
         goto done;
 
-    PrintPaddedResourceString(IDS_USER_NAME);
+    PrintPaddedResourceString(IDS_USER_NAME, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_name);
 
-    PrintPaddedResourceString(IDS_USER_FULL_NAME);
+    PrintPaddedResourceString(IDS_USER_FULL_NAME, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_full_name);
 
-    PrintPaddedResourceString(IDS_USER_COMMENT);
+    PrintPaddedResourceString(IDS_USER_COMMENT, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_comment);
 
-    PrintPaddedResourceString(IDS_USER_USER_COMMENT);
+    PrintPaddedResourceString(IDS_USER_USER_COMMENT, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_usr_comment);
 
-    PrintPaddedResourceString(IDS_USER_COUNTRY_CODE);
+    PrintPaddedResourceString(IDS_USER_COUNTRY_CODE, nPaddedLength);
     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_ACTIVE, nPaddedLength);
+    if (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE)
+        PrintResourceString(IDS_GENERIC_NO);
+    else if (pUserInfo->usri4_flags & UF_LOCKOUT)
+        PrintResourceString(IDS_GENERIC_LOCKED);
+    else
+        PrintResourceString(IDS_GENERIC_YES);
+    PrintToConsole(L"\n");
 
-    PrintPaddedResourceString(IDS_USER_ACCOUNT_EXPIRES);
+    PrintPaddedResourceString(IDS_USER_ACCOUNT_EXPIRES, nPaddedLength);
     if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER)
-        PrintToConsole(L"Never\n");
+        PrintResourceString(IDS_GENERIC_NEVER);
     else
         PrintDateTime(pUserInfo->usri4_acct_expires);
+    PrintToConsole(L"\n\n");
 
-    PrintToConsole(L"\n");
-
-    PrintPaddedResourceString(IDS_USER_PW_LAST_SET);
+    PrintPaddedResourceString(IDS_USER_PW_LAST_SET, nPaddedLength);
     dwLastSet = GetTimeInSeconds() - pUserInfo->usri4_password_age;
     PrintDateTime(dwLastSet);
 
-    PrintPaddedResourceString(IDS_USER_PW_EXPIRES);
+    PrintPaddedResourceString(IDS_USER_PW_EXPIRES, nPaddedLength);
     if ((pUserInfo->usri4_flags & UF_DONT_EXPIRE_PASSWD) || pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER)
-        PrintToConsole(L"Never\n");
+        PrintResourceString(IDS_GENERIC_NEVER);
     else
         PrintDateTime(dwLastSet + pUserModals->usrmod0_max_passwd_age);
+    PrintToConsole(L"\n");
 
-    PrintPaddedResourceString(IDS_USER_PW_CHANGEABLE);
+    PrintPaddedResourceString(IDS_USER_PW_CHANGEABLE, nPaddedLength);
     PrintDateTime(dwLastSet + pUserModals->usrmod0_min_passwd_age);
 
-    PrintPaddedResourceString(IDS_USER_PW_REQUIRED);
-    PrintToConsole(L"%s\n", (pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? L"No" : L"Yes");
+    PrintPaddedResourceString(IDS_USER_PW_REQUIRED, nPaddedLength);
+    PrintResourceString((pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? IDS_GENERIC_NO : IDS_GENERIC_YES);
+    PrintToConsole(L"\n");
 
-    PrintPaddedResourceString(IDS_USER_CHANGE_PW);
-    PrintToConsole(L"%s\n", (pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? L"No" : L"Yes");
+    PrintPaddedResourceString(IDS_USER_CHANGE_PW, nPaddedLength);
+    PrintResourceString((pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? IDS_GENERIC_NO : IDS_GENERIC_YES);
+    PrintToConsole(L"\n\n");
 
+    PrintPaddedResourceString(IDS_USER_WORKSTATIONS, nPaddedLength);
+    if (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0)
+        PrintResourceString(IDS_GENERIC_ALL);
+    else
+        PrintToConsole(L"%s", pUserInfo->usri4_workstations);
     PrintToConsole(L"\n");
 
-    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);
+    PrintPaddedResourceString(IDS_USER_LOGON_SCRIPT, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_script_path);
 
-    PrintPaddedResourceString(IDS_USER_PROFILE);
+    PrintPaddedResourceString(IDS_USER_PROFILE, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_profile);
 
-    PrintPaddedResourceString(IDS_USER_HOME_DIR);
+    PrintPaddedResourceString(IDS_USER_HOME_DIR, nPaddedLength);
     PrintToConsole(L"%s\n", pUserInfo->usri4_home_dir);
 
-    PrintPaddedResourceString(IDS_USER_LAST_LOGON);
+    PrintPaddedResourceString(IDS_USER_LAST_LOGON, nPaddedLength);
     if (pUserInfo->usri4_last_logon == 0)
-        PrintToConsole(L"Never\n");
+        PrintResourceString(IDS_GENERIC_NEVER);
     else
         PrintDateTime(pUserInfo->usri4_last_logon);
+    PrintToConsole(L"\n\n");
 
-    PrintToConsole(L"\n");
-
-    PrintPaddedResourceString(IDS_USER_LOGON_HOURS);
+    PrintPaddedResourceString(IDS_USER_LOGON_HOURS, nPaddedLength);
     if (pUserInfo->usri4_logon_hours == NULL)
-        PrintToConsole(L"All\n");
-
-    PrintToConsole(L"\n");
+        PrintResourceString(IDS_GENERIC_ALL);
+    PrintToConsole(L"\n\n");
 
     PrintToConsole(L"\n");
-    PrintPaddedResourceString(IDS_USER_LOCAL_GROUPS);
+    PrintPaddedResourceString(IDS_USER_LOCAL_GROUPS, nPaddedLength);
     if (dwLocalGroupTotal != 0 && pLocalGroupInfo != NULL)
     {
         for (i = 0; i < dwLocalGroupTotal; i++)
         {
             if (i != 0)
-                PrintToConsole(L"                             ");
+                PrintPadding(L' ', nPaddedLength);
             PrintToConsole(L"*%s\n", pLocalGroupInfo[i].lgrui0_name);
         }
     }
@@ -262,13 +277,13 @@ DisplayUser(LPWSTR lpUserName)
         PrintToConsole(L"\n");
     }
 
-    PrintPaddedResourceString(IDS_USER_GLOBAL_GROUPS);
+    PrintPaddedResourceString(IDS_USER_GLOBAL_GROUPS, nPaddedLength);
     if (dwGroupTotal != 0 && pGroupInfo != NULL)
     {
         for (i = 0; i < dwGroupTotal; i++)
         {
             if (i != 0)
-                PrintToConsole(L"                             ");
+                PrintPadding(L' ', nPaddedLength);
             PrintToConsole(L"*%s\n", pGroupInfo[i].grui0_name);
         }
     }
@@ -310,11 +325,11 @@ ReadPassword(
     {
         PrintResourceString(IDS_USER_ENTER_PASSWORD1);
         ReadFromConsole(szPassword1, PWLEN + 1, FALSE);
-        printf("\n");
+        PrintToConsole(L"\n");
 
         PrintResourceString(IDS_USER_ENTER_PASSWORD2);
         ReadFromConsole(szPassword2, PWLEN + 1, FALSE);
-        printf("\n");
+        PrintToConsole(L"\n");
 
         if (wcslen(szPassword1) == wcslen(szPassword2) &&
             wcscmp(szPassword1, szPassword2) == 0)
@@ -332,7 +347,9 @@ ReadPassword(
         }
         else
         {
+            PrintToConsole(L"\n");
             PrintResourceString(IDS_USER_NO_PASSWORD_MATCH);
+            PrintToConsole(L"\n");
             *lpPassword = NULL;
         }
     }