- Convert error messages to resource strings.
- ACCOUNTS: Add some padding to display strings.
- USER: Support interactive password input.
svn path=/trunk/; revision=65323
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
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;
}
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;
}
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;
}
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;
}
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;
}
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)
{
}
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
}
+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,
LPWSTR p;
LPWSTR endptr;
DWORD value;
+ BOOL bPasswordAllocated = FALSE;
NET_API_STATUS Status;
if (argc == 2)
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++;
}
}
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
goto done;
}
+ /* Interactive password input */
+ if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0)
+ {
+ ReadPassword(&lpPassword,
+ &bPasswordAllocated);
+ }
+
if (!bAdd && !bDelete)
{
/* Modify the user */
}
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;
}
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;
}
}
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)
{
}
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;
}
}
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;
}
}
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)
{
}
else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0)
{
+ /* FIXME */
+ PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/WORKSTATIONS");
}
}
}
done:
+ if (bPasswordAllocated == TRUE && lpPassword != NULL)
+ HeapFree(GetProcessHeap(), 0, lpPassword);
+
if (!bAdd && !bDelete && pUserInfo != NULL)
NetApiBufferFree(pUserInfo);
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..."
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
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
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
}
+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;
WriteToConsole(
LPWSTR lpString);
+VOID
+ReadFromConsole(
+ LPWSTR lpInput,
+ DWORD dwLength,
+ BOOL bEcho);
+
VOID help(VOID);
INT unimplemented(INT argc, WCHAR **argv);
#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