瀏覽代碼

Bug 1821: Alternative way to provide credentials in scripting/command-line without URL-encoding

https://winscp.net/tracker/1821
(cherry picked from commit 4fd4cfb6e549230f4b5598b0101357c43949ca1c)

Source commit: f59af04612a1fb28a685ace02aef573b426e4de7
Martin Prikryl 5 年之前
父節點
當前提交
809cf184ac

+ 2 - 0
source/core/Interface.h

@@ -25,6 +25,8 @@
 #define DELETE_SWITCH L"delete"
 #define REFRESH_SWITCH L"refresh"
 #define RAWTRANSFERSETTINGS_SWITCH L"rawtransfersettings"
+#define USERNAME_SWITCH L"username"
+#define PASSWORD_SWITCH L"password"
 extern const wchar_t * TransferModeNames[];
 extern const int TransferModeNamesCount;
 extern const wchar_t * ToggleNames[];

+ 9 - 0
source/core/SessionData.cpp

@@ -1784,6 +1784,7 @@ bool __fastcall TSessionData::IsSensitiveOption(const UnicodeString & Option)
 {
   return
     SameText(Option, PassphraseOption) ||
+    SameText(Option, PASSWORD_SWITCH) ||
     SameText(Option, NEWPASSWORD_SWITCH);
 }
 //---------------------------------------------------------------------
@@ -2185,6 +2186,14 @@ bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
     // as the option should not make session "connectable"
 
     UnicodeString Value;
+    if (Options->FindSwitch(USERNAME_SWITCH, Value))
+    {
+      UserName = Value;
+    }
+    if (Options->FindSwitch(PASSWORD_SWITCH, Value))
+    {
+      Password = Value;
+    }
     if (Options->FindSwitch(SESSIONNAME_SWICH, Value))
     {
       Name = Value;

+ 2 - 0
source/resource/TextsCore2.rc

@@ -77,6 +77,8 @@ BEGIN
     "  -implicit          Implicit TLS/SSL (FTP protocol only)\n"
     "  -explicit          Explicit TLS/SSL (FTP protocol only)\n"
     "  -timeout=<sec>     Server response timeout\n"
+    "  -username=<user>   An alternative way to provide a username\n"
+    "  -password=<password> An alternative way to provide a password\n"
     "  -rawsettings setting1=value1 setting2=value2 ...\n"
     "                     Configures any site settings using raw format\n"
     "                     as in an INI file\n"

+ 2 - 0
source/resource/TextsWin.h

@@ -296,6 +296,8 @@
 #define USAGE_BROWSE            1586
 #define PUTTY_SETTINGS_INSTRUCTIONS 1587
 #define PUTTY_SETTINGS_SITE_NAME 1588
+#define USAGE_USERNAME          1589
+#define USAGE_PASSWORD          1590
 
 #define WIN_FORMS_STRINGS       1600
 #define COPY_FILE               1605

+ 2 - 0
source/resource/TextsWin1.rc

@@ -301,6 +301,8 @@ BEGIN
         USAGE_BROWSE, "Selects the specified file in file panel(s)."
         PUTTY_SETTINGS_INSTRUCTIONS, "**Edit terminal settings in PuTTY.**\n\nPuTTY will be started. Edit terminal settings of a temporary site %s. WinSCP will remember these settings after you close PuTTY."
         PUTTY_SETTINGS_SITE_NAME, "Terminal settings for %s"
+        USAGE_USERNAME, "An alternative way to provide a username"
+        USAGE_PASSWORD, "An alternative way to provide a password"
 
         WIN_FORMS_STRINGS, "WIN_FORMS_STRINGS"
         COPY_FILE, "%s file '%s' to %s:"

+ 3 - 0
source/windows/ConsoleRunner.cpp

@@ -2196,6 +2196,7 @@ void __fastcall Usage(TConsole * Console)
     PrintUsageSyntax(Console, FORMAT(L"[mysession] /%s [path]", (LowerCase(REFRESH_SWITCH))));
     PrintUsageSyntax(Console, FORMAT(L"[mysession] [/privatekey=<file> [/%s=<passphrase>]]", (PassphraseOption)));
     PrintUsageSyntax(Console, L"[mysession] [/hostkey=<fingerprint>]");
+    PrintUsageSyntax(Console, FORMAT(L"[mysession] [/%s=<user> [/%s=<password>]]", (LowerCase(USERNAME_SWITCH), LowerCase(PASSWORD_SWITCH))));
     PrintUsageSyntax(Console, FORMAT(L"[mysession] [/clientcert=<file> [/%s=<passphrase>]]", (PassphraseOption)));
     PrintUsageSyntax(Console, L"[mysession] [/certificate=<fingerprint>]");
     PrintUsageSyntax(Console, L"[mysession] [/passive[=on|off]] [/implicit|explicit]");
@@ -2238,6 +2239,8 @@ void __fastcall Usage(TConsole * Console)
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(DEFAULTS_SWITCH), USAGE_DEFAULTS);
     RegisterSwitch(SwitchesUsage, L"/privatekey=", USAGE_PRIVATEKEY);
     RegisterSwitch(SwitchesUsage, L"/hostkey=", USAGE_HOSTKEY);
+    RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(USERNAME_SWITCH), USAGE_USERNAME);
+    RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(PASSWORD_SWITCH), USAGE_PASSWORD);
     RegisterSwitch(SwitchesUsage, L"/clientcert=", USAGE_CLIENTCERT);
     RegisterSwitch(SwitchesUsage, L"/certificate=", USAGE_CERTIFICATE);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(PassphraseOption) + L"=", USAGE_PASSPHRASE);