Pārlūkot izejas kodu

Change: Bug 1647: Do not match URL after stripping protocol against stored site name in scripting/automation

https://winscp.net/tracker/1647

Source commit: 39373892b364674fc0c8db069d57df9e79949f4f
Martin Prikryl 7 gadi atpakaļ
vecāks
revīzija
29a505241b

+ 5 - 4
source/core/SessionData.cpp

@@ -1692,7 +1692,7 @@ void __fastcall TSessionData::MaskPasswords()
 //---------------------------------------------------------------------
 bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
   TStoredSessionList * StoredSessions, bool & DefaultsOnly, UnicodeString * FileName,
-  bool * AProtocolDefined, UnicodeString * MaskedUrl)
+  bool * AProtocolDefined, UnicodeString * MaskedUrl, int Flags)
 {
   bool ProtocolDefined = false;
   bool PortNumberDefined = false;
@@ -1793,7 +1793,8 @@ bool __fastcall TSessionData::ParseUrl(UnicodeString Url, TOptions * Options,
     // by creating stored session named by host)
     TSessionData * Data = NULL;
     // When using to paste URL on Login dialog, we do not want to lookup the stored sites
-    if (StoredSessions != NULL)
+    if ((StoredSessions != NULL) &&
+        (!ProtocolDefined || FLAGSET(Flags, pufAllowStoredSiteWithProtocol)))
     {
       // this can be optimized as the list is sorted
       for (Integer Index = 0; Index < StoredSessions->CountIncludingHidden; Index++)
@@ -4842,12 +4843,12 @@ bool __fastcall TStoredSessionList::HasAnyWorkspace()
 //---------------------------------------------------------------------------
 TSessionData * __fastcall TStoredSessionList::ParseUrl(UnicodeString Url,
   TOptions * Options, bool & DefaultsOnly, UnicodeString * FileName,
-  bool * AProtocolDefined, UnicodeString * MaskedUrl)
+  bool * AProtocolDefined, UnicodeString * MaskedUrl, int Flags)
 {
   TSessionData * Data = new TSessionData(L"");
   try
   {
-    Data->ParseUrl(Url, Options, this, DefaultsOnly, FileName, AProtocolDefined, MaskedUrl);
+    Data->ParseUrl(Url, Options, this, DefaultsOnly, FileName, AProtocolDefined, MaskedUrl, Flags);
   }
   catch(...)
   {

+ 6 - 2
source/core/SessionData.h

@@ -51,6 +51,10 @@ enum TSessionUrlFlags
   sufComplete = sufSession | sufRawSettings,
   sufOpen = sufUserName | sufPassword
 };
+enum TParseUrlFlags
+{
+  pufAllowStoredSiteWithProtocol = 0x01,
+};
 //---------------------------------------------------------------------------
 extern const UnicodeString CipherNames[CIPHER_COUNT];
 extern const UnicodeString KexNames[KEX_COUNT];
@@ -467,7 +471,7 @@ public:
   void __fastcall CopyDirectoriesStateData(TSessionData * SourceData);
   bool __fastcall ParseUrl(UnicodeString Url, TOptions * Options,
     TStoredSessionList * StoredSessions, bool & DefaultsOnly,
-    UnicodeString * FileName, bool * AProtocolDefined, UnicodeString * MaskedUrl);
+    UnicodeString * FileName, bool * AProtocolDefined, UnicodeString * MaskedUrl, int Flags);
   bool __fastcall ParseOptions(TOptions * Options);
   void __fastcall ConfigureTunnel(int PortNumber);
   void __fastcall RollbackTunnel();
@@ -675,7 +679,7 @@ public:
   bool __fastcall IsFolder(const UnicodeString & Name);
   bool __fastcall IsWorkspace(const UnicodeString & Name);
   TSessionData * __fastcall ParseUrl(UnicodeString Url, TOptions * Options, bool & DefaultsOnly,
-    UnicodeString * FileName = NULL, bool * ProtocolDefined = NULL, UnicodeString * MaskedUrl = NULL);
+    UnicodeString * FileName = NULL, bool * ProtocolDefined = NULL, UnicodeString * MaskedUrl = NULL, int Flags = 0);
   bool __fastcall IsUrl(UnicodeString Url);
   bool __fastcall CanLogin(TSessionData * Data);
   void __fastcall GetFolderOrWorkspace(const UnicodeString & Name, TList * List);

+ 1 - 1
source/forms/Login.cpp

@@ -2969,7 +2969,7 @@ void __fastcall TLoginDialog::ParseUrl(const UnicodeString & Url)
   // parsed as pointing to a stored site.
   // It also prevents resetting to defaults (do we want this?)
   bool DefaultsOnly; // unused
-  SessionData->ParseUrl(Url, NULL, NULL, DefaultsOnly, NULL, NULL, NULL);
+  SessionData->ParseUrl(Url, NULL, NULL, DefaultsOnly, NULL, NULL, NULL, 0);
 
   LoadSession(SessionData.get());
 }

+ 1 - 1
source/windows/WinInterface.h

@@ -150,7 +150,7 @@ bool __fastcall DoChangeMasterPasswordDialog(UnicodeString & NewPassword);
 // windows\WinMain.cpp
 int __fastcall Execute();
 void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
-  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm);
+  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm, int Flags = 0);
 
 // forms\InputDlg.cpp
 struct TInputDialogData

+ 3 - 4
source/windows/WinMain.cpp

@@ -23,7 +23,7 @@
 #pragma package(smart_init)
 //---------------------------------------------------------------------------
 void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
-  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm)
+  TObjectList * DataList, UnicodeString & DownloadFile, bool NeedSession, TForm * LinkedForm, int Flags)
 {
   bool DefaultsOnly = false;
 
@@ -36,8 +36,7 @@ void __fastcall GetLoginData(UnicodeString SessionName, TOptions * Options,
   else
   {
     TSessionData * SessionData =
-      StoredSessions->ParseUrl(SessionName, Options, DefaultsOnly,
-        &DownloadFile);
+      StoredSessions->ParseUrl(SessionName, Options, DefaultsOnly, &DownloadFile, NULL, NULL, Flags);
     DataList->Add(SessionData);
 
     if (DataList->Count == 1)
@@ -1044,7 +1043,7 @@ int __fastcall Execute()
         TObjectList * DataList = new TObjectList();
         try
         {
-          GetLoginData(AutoStartSession, Params, DataList, DownloadFile, NeedSession, NULL);
+          GetLoginData(AutoStartSession, Params, DataList, DownloadFile, NeedSession, NULL, pufAllowStoredSiteWithProtocol);
           // GetLoginData now Aborts when session is needed and none is selected
           if (DebugAlwaysTrue(!NeedSession || (DataList->Count > 0)))
           {