Skip to content

Commit

Permalink
Bug 1430: PuTTY is started with its executable directory as working d…
Browse files Browse the repository at this point in the history
…irectory 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
  • Loading branch information
martinprikryl committed Jan 26, 2018
1 parent 04d416b commit d2a35a3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion source/core/SessionData.cpp
Expand Up @@ -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
{
Expand Down
10 changes: 7 additions & 3 deletions source/windows/GUITools.cpp
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion source/windows/GUITools.h
Expand Up @@ -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);
Expand Down

0 comments on commit d2a35a3

Please sign in to comment.