Browse Source

Bug 1430: PuTTY is started with its executable directory as working directory to allow relative private key paths in PuTTY's stored sessions + When opening WinSCP session in PuTTY, expanding the relative paths.

https://winscp.net/tracker/1430

Source commit: c223ff3bdb55813e2ee20161c42a7ac8cd2699f5
Martin Prikryl 9 years ago
parent
commit
d2a35a3cfa
3 changed files with 11 additions and 5 deletions
  1. 3 1
      source/core/SessionData.cpp
  2. 7 3
      source/windows/GUITools.cpp
  3. 1 1
      source/windows/GUITools.h

+ 3 - 1
source/core/SessionData.cpp

@@ -865,7 +865,9 @@ void __fastcall TSessionData::DoSave(THierarchicalStorage * Storage,
   if (PuttyExport)
   {
     WRITE_DATA(StringRaw, UserName);
-    WRITE_DATA(StringRaw, PublicKeyFile);
+    // PuTTY is started in its binary directory to allow relative paths when opening PuTTY's own stored session.
+    // To allow relative paths in our sessions, we have to expand them for PuTTY.
+    WRITE_DATA_EX(StringRaw, L"PublicKeyFile", PublicKeyFile, ExpandFileName);
   }
   else
   {

+ 7 - 3
source/windows/GUITools.cpp

@@ -143,7 +143,9 @@ void __fastcall OpenSessionInPutty(const UnicodeString PuttyPath,
 
     AddToList(PuttyParams, Params, L" ");
 
-    if (!ExecuteShell(Program, PuttyParams))
+    // PuTTY is started in its binary directory to allow relative paths in private key,
+    // when opening PuTTY's own stored session.
+    if (!ExecuteShell(Program, PuttyParams, true))
     {
       throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Program)));
     }
@@ -185,14 +187,16 @@ static bool __fastcall CopyShellCommandToClipboard(const UnicodeString & Path, c
   return Result;
 }
 //---------------------------------------------------------------------------
-bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params)
+bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params, bool ChangeWorkingDirectory)
 {
   bool Result = true;
   if (!CopyShellCommandToClipboard(Path, Params))
   {
+    UnicodeString Directory = ExtractFilePath(Path);
+    const wchar_t * PDirectory = (ChangeWorkingDirectory ? Directory.c_str() : NULL);
     Result =
       ((int)ShellExecute(NULL, L"open", (wchar_t*)Path.data(),
-        (wchar_t*)Params.data(), NULL, SW_SHOWNORMAL) > 32);
+        (wchar_t*)Params.data(), PDirectory, SW_SHOWNORMAL) > 32);
   }
   return Result;
 }

+ 1 - 1
source/windows/GUITools.h

@@ -20,7 +20,7 @@ typedef void __fastcall (__closure* TProcessMessagesEvent)();
 //---------------------------------------------------------------------------
 bool __fastcall FindFile(UnicodeString & Path);
 bool __fastcall FindTool(const UnicodeString & Name, UnicodeString & Path);
-bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params);
+bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params, bool ChangeWorkingDirectory = false);
 bool __fastcall ExecuteShell(const UnicodeString Command);
 bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params,
   HANDLE & Handle);