From: Eric Kohl Date: Sat, 31 May 2014 08:32:54 +0000 (+0000) Subject: [NET] X-Git-Tag: backups/0.3.17@66124~1075 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=6f830f27bb58b9abd5e8f0ce622e3fe37e1f1248;hp=a31b680c53e160be9e32a733928cfeb601017dc5 [NET] - 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 --- diff --git a/reactos/base/applications/network/net/CMakeLists.txt b/reactos/base/applications/network/net/CMakeLists.txt index 377065ebadf..a740d3a06de 100644 --- a/reactos/base/applications/network/net/CMakeLists.txt +++ b/reactos/base/applications/network/net/CMakeLists.txt @@ -12,8 +12,8 @@ list(APPEND SOURCE help.c net.h) -add_executable(net ${SOURCE}) +add_executable(net ${SOURCE} net.rc) 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) diff --git a/reactos/base/applications/network/net/cmdAccounts.c b/reactos/base/applications/network/net/cmdAccounts.c index eb91c85550e..456ac4c791e 100644 --- a/reactos/base/applications/network/net/cmdAccounts.c +++ b/reactos/base/applications/network/net/cmdAccounts.c @@ -18,33 +18,34 @@ cmdAccounts( 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; + 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 */ - puts("NET ACCOUNTS [/FORCELOGOFF:{Minutes|NO}] [/MINPWLEN:Length]"); - puts(" [/MAXPWAGE:{Days|UNLIMITED}] [/MINPWAGE:Days]"); - puts(" [/UNIQUEPW:Count] [/DOMAIN]"); + PrintResourceString(IDS_ACCOUNTS_SYNTAX); 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; } /* - if (wcsicmp(argv[i], L"/domain") == 0) + if (_wcsicmp(argv[i], L"/domain") == 0) { Domain = TRUE; } @@ -55,7 +56,7 @@ cmdAccounts( 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) { @@ -67,7 +68,13 @@ cmdAccounts( } 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; @@ -76,7 +83,14 @@ cmdAccounts( 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; } @@ -91,7 +105,13 @@ cmdAccounts( } 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; @@ -100,7 +120,13 @@ cmdAccounts( 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; @@ -108,7 +134,13 @@ cmdAccounts( 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; @@ -149,7 +181,12 @@ cmdAccounts( 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); @@ -186,7 +223,7 @@ done: if (Info0 != NULL) NetApiBufferFree(Info0); - return 0; + return result; } /* EOF */ diff --git a/reactos/base/applications/network/net/cmdContinue.c b/reactos/base/applications/network/net/cmdContinue.c index 7f23fa5777a..f36111af2c9 100644 --- a/reactos/base/applications/network/net/cmdContinue.c +++ b/reactos/base/applications/network/net/cmdContinue.c @@ -15,13 +15,23 @@ INT cmdContinue(INT argc, WCHAR **argv) SC_HANDLE hService = NULL; SERVICE_STATUS status; INT nError = 0; + INT i; if (argc != 3) { - puts("Usage: NET CONTINUE "); + PrintResourceString(IDS_CONTINUE_SYNTAX); 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) { diff --git a/reactos/base/applications/network/net/help.c b/reactos/base/applications/network/net/help.c index 089f4a64f20..46061566801 100644 --- a/reactos/base/applications/network/net/help.c +++ b/reactos/base/applications/network/net/help.c @@ -18,8 +18,7 @@ INT cmdHelp(INT argc, WCHAR **argv) if (_wcsicmp(argv[2],L"ACCOUNTS")==0) { - puts("ACCOUNTS"); - puts("help text"); + PrintResourceString(IDS_ACCOUNTS_HELP); return 0; } @@ -39,8 +38,7 @@ INT cmdHelp(INT argc, WCHAR **argv) if (_wcsicmp(argv[2],L"CONTINUE")==0) { - puts("CONTINUE"); - puts("help text"); + PrintResourceString(IDS_CONTINUE_HELP); 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 index 00000000000..99cd546c185 --- /dev/null +++ b/reactos/base/applications/network/net/lang/en-US.rc @@ -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 " + IDS_CONTINUE_HELP "CONTINUE\nhelp text" +END diff --git a/reactos/base/applications/network/net/main.c b/reactos/base/applications/network/net/main.c index ad702517e39..b0ae7a9c897 100644 --- a/reactos/base/applications/network/net/main.c +++ b/reactos/base/applications/network/net/main.c @@ -9,6 +9,8 @@ #include "net.h" +#define MAX_BUFFER_SIZE 4096 + typedef struct _COMMAND { WCHAR *name; @@ -43,6 +45,22 @@ COMMAND cmds[] = {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; diff --git a/reactos/base/applications/network/net/net.h b/reactos/base/applications/network/net/net.h index 91af9d06a96..93cf15d81c1 100644 --- a/reactos/base/applications/network/net/net.h +++ b/reactos/base/applications/network/net/net.h @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,13 @@ #include #include +#include "resource.h" + +VOID +PrintResourceString( + INT resID, + ...); + 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 index 00000000000..ef6ba03f034 --- /dev/null +++ b/reactos/base/applications/network/net/net.rc @@ -0,0 +1,17 @@ +#include + +#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 + +/* 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 index 00000000000..54d5913ddcf --- /dev/null +++ b/reactos/base/applications/network/net/resource.h @@ -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