Browse Source

Bug fix: It was not possible to mass-modify stored sites, when a master password was set (2nd)

Previous implementation broke a prompt for master password, when logging to a site wit encrypted passwords.

Source commit: 0cf714c96ffbdcc593c094f7a30a35664e275aff
Martin Prikryl 6 years ago
parent
commit
2061ad0031
3 changed files with 24 additions and 3 deletions
  1. 21 2
      source/core/SessionData.cpp
  2. 2 0
      source/core/SessionData.h
  3. 1 1
      source/windows/ConsoleRunner.cpp

+ 21 - 2
source/core/SessionData.cpp

@@ -448,6 +448,7 @@ void __fastcall TSessionData::Assign(TPersistent * Source)
   if (Source && Source->InheritsFrom(__classid(TSessionData)))
   {
     TSessionData * SourceData = (TSessionData *)Source;
+    // Master password prompt shows implicitly here, when cloning the session data for a new terminal
     CopyData(SourceData);
     FSource = SourceData->FSource;
   }
@@ -457,9 +458,17 @@ void __fastcall TSessionData::Assign(TPersistent * Source)
   }
 }
 //---------------------------------------------------------------------
-void __fastcall TSessionData::CopyData(TSessionData * SourceData)
+void __fastcall TSessionData::DoCopyData(TSessionData * SourceData, bool NoRecrypt)
 {
-  #define PROPERTY_HANDLER(P, F) F##P = SourceData->F##P
+  #define PROPERTY_HANDLER(P, F) \
+    if (NoRecrypt) \
+    { \
+      F##P = SourceData->F##P; \
+    } \
+    else \
+    { \
+      P = SourceData->P; \
+    }
   PROPERTY(Name);
   BASE_PROPERTIES;
   ADVANCED_PROPERTIES;
@@ -470,6 +479,16 @@ void __fastcall TSessionData::CopyData(TSessionData * SourceData)
   FSaveOnly = SourceData->FSaveOnly;
 }
 //---------------------------------------------------------------------
+void __fastcall TSessionData::CopyData(TSessionData * SourceData)
+{
+  DoCopyData(SourceData, false);
+}
+//---------------------------------------------------------------------
+void __fastcall TSessionData::CopyDataNoRecrypt(TSessionData * SourceData)
+{
+  DoCopyData(SourceData, true);
+}
+//---------------------------------------------------------------------
 void __fastcall TSessionData::CopyDirectoriesStateData(TSessionData * SourceData)
 {
   RemoteDirectory = SourceData->RemoteDirectory;

+ 2 - 0
source/core/SessionData.h

@@ -445,6 +445,7 @@ private:
   TStrings * __fastcall SaveToOptions(const TSessionData * Default);
   void __fastcall ApplyRawSettings(TStrings * RawSettings);
   TStrings * __fastcall GetRawSettingsForUrl();
+  void __fastcall DoCopyData(TSessionData * SourceData, bool NoRecrypt);
   template<class AlgoT>
   void __fastcall SetAlgoList(AlgoT * List, const AlgoT * DefaultList, const UnicodeString * Names,
     int Count, AlgoT WarnAlgo, UnicodeString value);
@@ -475,6 +476,7 @@ public:
   virtual void __fastcall Assign(TPersistent * Source);
   virtual int __fastcall Compare(TNamedObject * Other);
   void __fastcall CopyData(TSessionData * Source);
+  void __fastcall CopyDataNoRecrypt(TSessionData * SourceData);
   void __fastcall CopyDirectoriesStateData(TSessionData * SourceData);
   bool __fastcall ParseUrl(UnicodeString Url, TOptions * Options,
     TStoredSessionList * StoredSessions, bool & DefaultsOnly,

+ 1 - 1
source/windows/ConsoleRunner.cpp

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