Browse Source

Bug 2142: With password storing administratively disabled, the /rawsettings switch cannot be used to set passwords

https://winscp.net/tracker/2142

Source commit: 9da6941ad11f40f5a5804b626d8b5d104ae931ee
Martin Prikryl 2 years ago
parent
commit
64e39e9e21
3 changed files with 12 additions and 11 deletions
  1. 9 8
      source/core/SessionData.cpp
  2. 2 2
      source/core/SessionData.h
  3. 1 1
      source/windows/ConsoleRunner.cpp

+ 9 - 8
source/core/SessionData.cpp

@@ -656,7 +656,7 @@ bool __fastcall TSessionData::IsInFolderOrWorkspace(UnicodeString AFolder)
   return StartsText(UnixIncludeTrailingBackslash(AFolder), Name);
 }
 //---------------------------------------------------------------------
-void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyImport, bool & RewritePassword, bool Unsafe)
+void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyImport, bool & RewritePassword, bool Unsafe, bool RespectDisablePasswordStoring)
 {
   // Make sure we only ever use methods supported by TOptionsStorage
   // (implemented by TOptionsIniFile)
@@ -678,7 +678,8 @@ void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyI
       SET_SESSION_PROPERTY_FROM(PROP, A##PROP); \
     }
   #define LOAD_PASSWORD(PROP, PLAIN_NAME) LOAD_PASSWORD_EX(PROP, PLAIN_NAME, TEXT(#PROP), RewritePassword = true;)
-  if (!Configuration->DisablePasswordStoring)
+  bool LoadPasswords = !Configuration->DisablePasswordStoring || !RespectDisablePasswordStoring;
+  if (LoadPasswords)
   {
     LOAD_PASSWORD(Password, L"PasswordPlain");
   }
@@ -863,14 +864,14 @@ void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyI
   // must be loaded after TunnelUserName,
   // because TunnelHostName may be in format user@host
   TunnelHostName = Storage->ReadString(L"TunnelHostName", TunnelHostName);
-  if (!Configuration->DisablePasswordStoring)
+  if (LoadPasswords)
   {
     LOAD_PASSWORD(TunnelPassword, L"TunnelPasswordPlain");
   }
   TunnelPublicKeyFile = Storage->ReadString(L"TunnelPublicKeyFile", TunnelPublicKeyFile);
   // Contrary to main session passphrase (which has -passphrase switch in scripting),
   // we are loading tunnel passphrase, as there's no other way to provide it in scripting
-  if (!Configuration->DisablePasswordStoring)
+  if (LoadPasswords)
   {
     LOAD_PASSWORD(TunnelPassphrase, L"TunnelPassphrasePlain");
   }
@@ -978,7 +979,7 @@ void __fastcall TSessionData::Load(THierarchicalStorage * Storage, bool PuttyImp
     ClearSessionPasswords();
     FProxyPassword = L"";
 
-    DoLoad(Storage, PuttyImport, RewritePassword, false);
+    DoLoad(Storage, PuttyImport, RewritePassword, false, true);
 
     Storage->CloseSubKey();
   }
@@ -2562,13 +2563,13 @@ bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
 void __fastcall TSessionData::ApplyRawSettings(TStrings * RawSettings, bool Unsafe)
 {
   std::unique_ptr<TOptionsStorage> OptionsStorage(new TOptionsStorage(RawSettings, false));
-  ApplyRawSettings(OptionsStorage.get(), Unsafe);
+  ApplyRawSettings(OptionsStorage.get(), Unsafe, false);
 }
 //---------------------------------------------------------------------
-void __fastcall TSessionData::ApplyRawSettings(THierarchicalStorage * Storage, bool Unsafe)
+void __fastcall TSessionData::ApplyRawSettings(THierarchicalStorage * Storage, bool Unsafe, bool RespectDisablePasswordStoring)
 {
   bool Dummy;
-  DoLoad(Storage, false, Dummy, Unsafe);
+  DoLoad(Storage, false, Dummy, Unsafe, RespectDisablePasswordStoring);
 }
 //---------------------------------------------------------------------
 void __fastcall TSessionData::ConfigureTunnel(int APortNumber)

+ 2 - 2
source/core/SessionData.h

@@ -438,7 +438,7 @@ private:
   UnicodeString __fastcall GetFolderName();
   void __fastcall Modify();
   UnicodeString __fastcall GetSource();
-  void __fastcall DoLoad(THierarchicalStorage * Storage, bool PuttyImport, bool & RewritePassword, bool Unsafe);
+  void __fastcall DoLoad(THierarchicalStorage * Storage, bool PuttyImport, bool & RewritePassword, bool Unsafe, bool RespectDisablePasswordStoring);
   void __fastcall DoSave(THierarchicalStorage * Storage,
     bool PuttyExport, const TSessionData * Default, bool DoNotEncryptPasswords);
   UnicodeString __fastcall ReadXmlNode(_di_IXMLNode Node, const UnicodeString & Name, const UnicodeString & Default);
@@ -494,7 +494,7 @@ public:
   void __fastcall NonPersistant();
   void __fastcall Load(THierarchicalStorage * Storage, bool PuttyImport);
   void __fastcall ApplyRawSettings(TStrings * RawSettings, bool Unsafe);
-  void __fastcall ApplyRawSettings(THierarchicalStorage * Storage, bool Unsafe);
+  void __fastcall ApplyRawSettings(THierarchicalStorage * Storage, bool Unsafe, bool RespectDisablePasswordStoring);
   void __fastcall ImportFromFilezilla(_di_IXMLNode Node, const UnicodeString & Path, _di_IXMLNode SettingsNode);
   void ImportFromOpenssh(TStrings * Lines);
   void __fastcall Save(THierarchicalStorage * Storage, bool PuttyExport,

+ 1 - 1
source/windows/ConsoleRunner.cpp

@@ -2505,7 +2505,7 @@ int __fastcall BatchSettings(TConsole * Console, TProgramParams * Params)
             Matches++;
             std::unique_ptr<TSessionData> OriginalData(new TSessionData(L""));
             OriginalData->CopyDataNoRecrypt(Data);
-            Data->ApplyRawSettings(OptionsStorage.get(), false);
+            Data->ApplyRawSettings(OptionsStorage.get(), false, true);
             bool Changed = !OriginalData->IsSame(Data, false);
             if (Changed)
             {