Browse Source

Bug 2102: Reading password from a file (also in commandline)

https://winscp.net/tracker/2102

Source commit: d289a6b641f6abdd82dd978b5b43bf14d62b915a
Martin Prikryl 3 years ago
parent
commit
c1a1f3e945

+ 1 - 0
source/core/Interface.h

@@ -28,6 +28,7 @@
 #define USERNAME_SWITCH L"username"
 #define PASSWORD_SWITCH L"password"
 #define PRIVATEKEY_SWITCH L"privatekey"
+#define PASSWORDSFROMFILES_SWITCH L"passwordsfromfiles"
 extern const wchar_t * TransferModeNames[];
 extern const int TransferModeNamesCount;
 extern const wchar_t * ToggleNames[];

+ 0 - 5
source/core/Script.cpp

@@ -2715,11 +2715,6 @@ void __fastcall TManagementScript::Connect(const UnicodeString Session,
 
     try
     {
-      if (Options->FindSwitch(L"passwordsfromfiles"))
-      {
-        Data->ReadPasswordsFromFiles();
-      }
-
       if (CheckParams)
       {
         if (Options->ParamCount > 1)

+ 4 - 0
source/core/SessionData.cpp

@@ -2521,6 +2521,10 @@ bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
         ApplyRawSettings(RawSettings.get(), Unsafe);
       }
     }
+    if (Options->FindSwitch(PASSWORDSFROMFILES_SWITCH))
+    {
+      ReadPasswordsFromFiles();
+    }
   }
 
   return true;

+ 1 - 1
source/core/SessionData.h

@@ -450,6 +450,7 @@ private:
   void __fastcall CopyStateData(TSessionData * SourceData);
   void __fastcall CopyNonCoreData(TSessionData * SourceData);
   UnicodeString __fastcall GetNormalizedPuttyProtocol() const;
+  void ReadPasswordsFromFiles();
   static RawByteString __fastcall EncryptPassword(const UnicodeString & Password, UnicodeString Key);
   static UnicodeString __fastcall DecryptPassword(const RawByteString & Password, UnicodeString Key);
   static RawByteString __fastcall StronglyRecryptPassword(const RawByteString & Password, UnicodeString Key);
@@ -498,7 +499,6 @@ public:
     const TSessionData * Default = NULL);
   void __fastcall SaveRecryptedPasswords(THierarchicalStorage * Storage);
   void __fastcall RecryptPasswords();
-  void ReadPasswordsFromFiles();
   bool __fastcall HasPassword();
   bool __fastcall HasAnySessionPassword();
   bool __fastcall HasAnyPassword();

+ 1 - 0
source/resource/TextsWin.h

@@ -308,6 +308,7 @@
 #define STORE_MIGRATION_THANKS  1595
 #define STORE_MIGRATION_LEARN   1596
 #define MESSAGE_DISMISS         1597
+#define USAGE_PASSWORDSFROMFILES 1598
 
 #define WIN_FORMS_STRINGS       1600
 #define COPY_FILE               1605

+ 1 - 0
source/resource/TextsWin1.rc

@@ -313,6 +313,7 @@ BEGIN
         STORE_MIGRATION_THANKS, "Thanks for buying WinSCP."
         STORE_MIGRATION_LEARN, "Learn about transitioning from classic installation."
         MESSAGE_DISMISS, "Dismiss"
+        USAGE_PASSWORDSFROMFILES, "Read all passwords from files"
 
         WIN_FORMS_STRINGS, "WIN_FORMS_STRINGS"
         COPY_FILE, "%s file '%s' to %s:"

+ 2 - 0
source/windows/ConsoleRunner.cpp

@@ -2307,6 +2307,7 @@ void __fastcall Usage(TConsole * Console)
     PrintUsageSyntax(Console, FORMAT(L"[mysession] [/%s=<file> [/%s=<passphrase>]]", (LowerCase(PRIVATEKEY_SWITCH), 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] [/%s]", (LowerCase(PASSWORDSFROMFILES_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]");
@@ -2364,6 +2365,7 @@ void __fastcall Usage(TConsole * Console)
     RegisterSwitch(SwitchesUsage, L"/hostkey=", USAGE_HOSTKEY);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(USERNAME_SWITCH), USAGE_USERNAME);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(PASSWORD_SWITCH), USAGE_PASSWORD);
+    RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(PASSWORDSFROMFILES_SWITCH), USAGE_PASSWORDSFROMFILES);
     RegisterSwitch(SwitchesUsage, L"/clientcert=", USAGE_CLIENTCERT);
     RegisterSwitch(SwitchesUsage, L"/certificate=", USAGE_CERTIFICATE);
     RegisterSwitch(SwitchesUsage, TProgramParams::FormatSwitch(PassphraseOption) + L"=", USAGE_PASSPHRASE);