Browse Source

Bug fix: When default session setting has any password stored, Login dialog always opens on NewSite page

Caused by 2061ad00
https://winscp.net/forum/viewtopic.php?t=28005

Source commit: 7b949cc22ef25c0e56ea6c333481555ae0f8e581
Martin Prikryl 6 years ago
parent
commit
b53ebad494
3 changed files with 18 additions and 11 deletions
  1. 13 6
      source/core/SessionData.cpp
  2. 2 1
      source/core/SessionData.h
  3. 3 4
      source/forms/Login.cpp

+ 13 - 6
source/core/SessionData.cpp

@@ -518,11 +518,13 @@ void __fastcall TSessionData::CopyNonCoreData(TSessionData * SourceData)
   Note = SourceData->Note;
 }
 //---------------------------------------------------------------------
-bool __fastcall TSessionData::IsSame(const TSessionData * Default, bool AdvancedOnly, TStrings * DifferentProperties)
+bool __fastcall TSessionData::IsSame(
+  const TSessionData * Default, bool AdvancedOnly, TStrings * DifferentProperties, bool Decrypted)
 {
   bool Result = true;
   #define PROPERTY_HANDLER(P, F) \
-    if (F##P != Default->F##P) \
+    if ((Decrypted && (P != Default->P)) || \
+        (!Decrypted && (F##P != Default->F##P))) \
     { \
       Result = false; \
       if (DifferentProperties != NULL) \
@@ -547,7 +549,12 @@ bool __fastcall TSessionData::IsSame(const TSessionData * Default, bool Advanced
 //---------------------------------------------------------------------
 bool __fastcall TSessionData::IsSame(const TSessionData * Default, bool AdvancedOnly)
 {
-  return IsSame(Default, AdvancedOnly, NULL);
+  return IsSame(Default, AdvancedOnly, NULL, false);
+}
+//---------------------------------------------------------------------
+bool __fastcall TSessionData::IsSameDecrypted(const TSessionData * Default)
+{
+  return IsSame(Default, false, NULL, true);
 }
 //---------------------------------------------------------------------
 TFSProtocol NormalizeFSProtocol(TFSProtocol FSProtocol)
@@ -4610,9 +4617,9 @@ void __fastcall TStoredSessionList::UpdateStaticUsage()
         Note++;
       }
 
-      // this effectively does not take passwords (proxy + tunnel) into account,
-      // when master password is set, as master password handler in not set up yet
-      if (!Data->IsSame(FactoryDefaults.get(), true, DifferentAdvancedProperties.get()))
+      // This would not work for passwords, as they are compared in their encrypted form.
+      // But there are no passwords set in factory defaults anyway.
+      if (!Data->IsSame(FactoryDefaults.get(), true, DifferentAdvancedProperties.get(), false))
       {
         Advanced++;
       }

+ 2 - 1
source/core/SessionData.h

@@ -414,7 +414,7 @@ private:
   _di_IXMLNode __fastcall FindSettingsNode(_di_IXMLNode Node, const UnicodeString & Name);
   UnicodeString __fastcall ReadSettingsNode(_di_IXMLNode Node, const UnicodeString & Name, const UnicodeString & Default);
   int __fastcall ReadSettingsNode(_di_IXMLNode Node, const UnicodeString & Name, int Default);
-  bool __fastcall IsSame(const TSessionData * Default, bool AdvancedOnly, TStrings * DifferentProperties);
+  bool __fastcall IsSame(const TSessionData * Default, bool AdvancedOnly, TStrings * DifferentProperties, bool Decrypted);
   UnicodeString __fastcall GetNameWithoutHiddenPrefix();
   bool __fastcall HasStateData();
   void __fastcall CopyStateData(TSessionData * SourceData);
@@ -487,6 +487,7 @@ public:
   void __fastcall ExpandEnvironmentVariables();
   void __fastcall DisableAuthentationsExceptPassword();
   bool __fastcall IsSame(const TSessionData * Default, bool AdvancedOnly);
+  bool __fastcall IsSameDecrypted(const TSessionData * Default);
   bool __fastcall IsSameSite(const TSessionData * Default);
   bool __fastcall IsInFolderOrWorkspace(UnicodeString Name);
   UnicodeString __fastcall GenerateSessionUrl(unsigned int Flags);

+ 3 - 4
source/forms/Login.cpp

@@ -1270,12 +1270,11 @@ bool __fastcall TLoginDialog::Execute(TList * DataList)
       FNewSiteData->CopyData(SessionData);
       FNewSiteData->Special = false;
 
-      // This is actualy bit pointless, as we focus the last selected site anyway
-      // in LoadState(). As of now, we hardly get any useful data
-      // in ad-hoc DataList anyway, so it is not a big deal
+      // This is actualy bit pointless.
+      // As of now, we hardly ever get any useful data in ad-hoc DataList.
       // (this was implemented for support taking session url from clipboard instead
       // of command-line, but without autoconnect, but this functionality was cancelled)
-      if (!FNewSiteData->IsSame(StoredSessions->DefaultSettings, false))
+      if (!FNewSiteData->IsSameDecrypted(StoredSessions->DefaultSettings))
       {
         // we want to start with new site page
         FForceNewSite = true;