Browse Source

Factoring out public key upload code

(cherry picked from commit 1f932ab0b061970663ceec274083bfd495e87c28)

Source commit: f3a7074952b7e4d3fee2ce1e345c79c31e0bf036
Martin Prikryl 4 years ago
parent
commit
0bf937ae5e

+ 1 - 0
source/core/Configuration.h

@@ -266,6 +266,7 @@ public:
   UnicodeString __fastcall GetFileMimeType(const UnicodeString & FileName);
   bool RegistryPathExists(const UnicodeString & RegistryPath);
   bool HasLocalPortNumberLimits();
+  virtual UnicodeString TemporaryDir(bool Mask = false) = 0;
 
   TStoredSessionList * __fastcall SelectFilezillaSessionsForImport(
     TStoredSessionList * Sessions, UnicodeString & Error);

+ 153 - 0
source/core/Terminal.cpp

@@ -8223,6 +8223,159 @@ UnicodeString __fastcall TTerminal::DecryptFileName(const UnicodeString & Path,
   return Result;
 }
 //---------------------------------------------------------------------------
+TRemoteFile * TTerminal::CheckRights(const UnicodeString & EntryType, const UnicodeString & FileName, bool & WrongRights)
+{
+  std::unique_ptr<TRemoteFile> FileOwner;
+  TRemoteFile * File;
+  try
+  {
+    LogEvent(FORMAT(L"Checking %s \"%s\"...", (LowerCase(EntryType), FileName)));
+    ReadFile(FileName, File);
+    FileOwner.reset(File);
+    int ForbiddenRights = TRights::rfGroupWrite | TRights::rfOtherWrite;
+    if ((File->Rights->Number & ForbiddenRights) != 0)
+    {
+      LogEvent(FORMAT(L"%s \"%s\" exists, but has incorrect permissions %s.", (EntryType, FileName, File->Rights->Octal)));
+      WrongRights = true;
+    }
+    else
+    {
+      LogEvent(FORMAT(L"%s \"%s\" exists and has correct permissions %s.", (EntryType, FileName, File->Rights->Octal)));
+    }
+  }
+  catch (Exception & E)
+  {
+  }
+  return FileOwner.release();
+}
+//---------------------------------------------------------------------------
+UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
+{
+  UnicodeString Result;
+
+  UnicodeString TemporaryDir;
+  bool PrevAutoReadDirectory = AutoReadDirectory;
+  bool PrevExceptionOnFail = ExceptionOnFail;
+
+  const UnicodeString SshFolder = L".ssh";
+  const UnicodeString AuthorizedKeysFile = L"authorized_keys";
+  UnicodeString AuthorizedKeysFilePath = FORMAT(L"%s/%s", (SshFolder, AuthorizedKeysFile));
+
+  try
+  {
+    AutoReadDirectory = false;
+    ExceptionOnFail = true;
+
+    Log->AddSeparator();
+
+    UnicodeString Comment;
+    UnicodeString Line = GetPublicKeyLine(FileName, Comment);
+
+    LogEvent(FORMAT(L"Adding public key line to \"%s\" file:\n%s", (AuthorizedKeysFilePath, Line)));
+
+    UnicodeString SshFolderAbsolutePath = UnixIncludeTrailingBackslash(GetHomeDirectory()) + SshFolder;
+    bool WrongRights = false;
+    std::unique_ptr<TRemoteFile> SshFolderFile(CheckRights(L"Folder", SshFolderAbsolutePath, WrongRights));
+    if (SshFolderFile.get() == NULL)
+    {
+      TRights SshFolderRights;
+      SshFolderRights.Number = TRights::rfUserRead | TRights::rfUserWrite | TRights::rfUserExec;
+      TRemoteProperties SshFolderProperties;
+      SshFolderProperties.Rights = SshFolderRights;
+      SshFolderProperties.Valid = TValidProperties() << vpRights;
+
+      LogEvent(FORMAT(L"Trying to create \"%s\" folder with permissions %s...", (SshFolder, SshFolderRights.Octal)));
+      CreateDirectory(SshFolderAbsolutePath, &SshFolderProperties);
+    }
+
+    TemporaryDir = ExcludeTrailingBackslash(Configuration->TemporaryDir());
+    if (!ForceDirectories(ApiPath(TemporaryDir)))
+    {
+      throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TemporaryDir)));
+    }
+    UnicodeString TemporaryAuthorizedKeysFile = IncludeTrailingBackslash(TemporaryDir) + AuthorizedKeysFile;
+
+    UnicodeString AuthorizedKeysFileAbsolutePath = UnixIncludeTrailingBackslash(SshFolderAbsolutePath) + AuthorizedKeysFile;
+
+    bool Updated = true;
+    TCopyParamType CopyParam; // Use factory defaults
+    CopyParam.ResumeSupport = rsOff; // not to break the permissions
+    CopyParam.PreserveTime = false; // not needed
+
+    UnicodeString AuthorizedKeys;
+    std::unique_ptr<TRemoteFile> AuthorizedKeysFileFile(CheckRights(L"File", AuthorizedKeysFileAbsolutePath, WrongRights));
+    if (AuthorizedKeysFileFile.get() != NULL)
+    {
+      AuthorizedKeysFileFile->FullFileName = AuthorizedKeysFileAbsolutePath;
+      std::unique_ptr<TStrings> Files(new TStringList());
+      Files->AddObject(AuthorizedKeysFileAbsolutePath, AuthorizedKeysFileFile.get());
+      LogEvent(FORMAT(L"Downloading current \"%s\" file...", (AuthorizedKeysFile)));
+      CopyToLocal(Files.get(), TemporaryDir, &CopyParam, cpNoConfirmation, NULL);
+      // Overload with Encoding parameter work incorrectly, when used on a file without BOM
+      AuthorizedKeys = TFile::ReadAllText(TemporaryAuthorizedKeysFile);
+
+      std::unique_ptr<TStrings> AuthorizedKeysLines(TextToStringList(AuthorizedKeys));
+      int P = Line.Pos(L" ");
+      if (DebugAlwaysTrue(P > 0))
+      {
+        P = PosEx(L" ", Line, P + 1);
+      }
+      UnicodeString Prefix = Line.SubString(1, P); // including the space
+      for (int Index = 0; Index < AuthorizedKeysLines->Count; Index++)
+      {
+        if (StartsStr(Prefix, AuthorizedKeysLines->Strings[Index]))
+        {
+          LogEvent(FORMAT(L"\"%s\" file already contains public key line:\n%s", (AuthorizedKeysFile, AuthorizedKeysLines->Strings[Index])));
+          Updated = false;
+        }
+      }
+
+      if (Updated)
+      {
+        LogEvent(FORMAT(L"\"%s\" file does not contain the public key line yet.", (AuthorizedKeysFile)));
+        if (!EndsStr(L"\n", AuthorizedKeys))
+        {
+          LogEvent(FORMAT(L"Adding missing trailing new line to \"%s\" file...", (AuthorizedKeysFile)));
+          AuthorizedKeys += L"\n";
+        }
+      }
+    }
+    else
+    {
+      LogEvent(FORMAT(L"Creating new \"%s\" file...", (AuthorizedKeysFile)));
+      CopyParam.PreserveRights = true;
+      CopyParam.Rights.Number = TRights::rfUserRead | TRights::rfUserWrite;
+    }
+
+    if (Updated)
+    {
+      AuthorizedKeys += Line + L"\n";
+      // Overload without Encoding parameter uses TEncoding::UTF8, but does not write BOM, what we want
+      TFile::WriteAllText(TemporaryAuthorizedKeysFile, AuthorizedKeys);
+      std::unique_ptr<TStrings> Files(new TStringList());
+      Files->Add(TemporaryAuthorizedKeysFile);
+      LogEvent(FORMAT(L"Uploading updated \"%s\" file...", (AuthorizedKeysFile)));
+      CopyToRemote(Files.get(), SshFolderAbsolutePath, &CopyParam, cpNoConfirmation, NULL);
+    }
+
+    Result = FMTLOAD(PUBLIC_KEY_UPLOADED, (Comment));
+    if (WrongRights)
+    {
+      Result += L"\n\n" + FMTLOAD(PUBLIC_KEY_PERMISSIONS, (AuthorizedKeysFilePath));
+    }
+  }
+  __finally
+  {
+    AutoReadDirectory = PrevAutoReadDirectory;
+    ExceptionOnFail = PrevExceptionOnFail;
+    if (!TemporaryDir.IsEmpty())
+    {
+      RecursiveDeleteFile(ExcludeTrailingBackslash(TemporaryDir), false);
+    }
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 __fastcall TSecondaryTerminal::TSecondaryTerminal(TTerminal * MainTerminal,
   TSessionData * ASessionData, TConfiguration * Configuration, const UnicodeString & Name) :

+ 2 - 0
source/core/Terminal.h

@@ -488,6 +488,7 @@ protected:
   void __fastcall UpdateTargetAttrs(
     const UnicodeString & DestFullName, const TRemoteFile * File, const TCopyParamType * CopyParam, int Attrs);
   void __fastcall UpdateTargetTime(HANDLE Handle, TDateTime Modification, TDSTMode DSTMode);
+  TRemoteFile * CheckRights(const UnicodeString & EntryType, const UnicodeString & FileName, bool & WrongRights);
 
   UnicodeString __fastcall EncryptFileName(const UnicodeString & Path, bool EncryptNewFiles);
   UnicodeString __fastcall DecryptFileName(const UnicodeString & Path, bool DecryptFullPath, bool DontCache);
@@ -610,6 +611,7 @@ public:
   TTerminal * __fastcall CreateSecondarySession(const UnicodeString & Name, TSessionData * SessionData);
   void __fastcall FillSessionDataForCode(TSessionData * Data);
   void __fastcall UpdateSessionCredentials(TSessionData * Data);
+  UnicodeString UploadPublicKey(const UnicodeString & FileName);
 
   const TSessionInfo & __fastcall GetSessionInfo();
   const TFileSystemInfo & __fastcall GetFileSystemInfo(bool Retrieve = false);

+ 3 - 0
source/resource/TextsCore.h

@@ -275,6 +275,7 @@
 #define STREAM_IN_SCRIPT_ERROR  751
 #define STREAM_READ_ERROR       752
 #define S3_CONFIG_ERROR         753
+#define CREATE_TEMP_DIR_ERROR   754
 
 #define CORE_CONFIRMATION_STRINGS 300
 #define CONFIRM_PROLONG_TIMEOUT3 301
@@ -487,6 +488,8 @@
 #define COPY_INFO_DONT_ENCRYPT_NEW_FILES 564
 #define COPY_INFO_EXCLUDE_HIDDEN_FILES 565
 #define COPY_INFO_EXCLUDE_EMPTY_DIRS 566
+#define PUBLIC_KEY_UPLOADED     6006
+#define PUBLIC_KEY_PERMISSIONS  6007
 
 #define CORE_VARIABLE_STRINGS   600
 #define PUTTY_BASED_ON          601

+ 3 - 0
source/resource/TextsCore1.rc

@@ -247,6 +247,7 @@ BEGIN
   STREAM_READ_ERROR, "Error reading input stream."
   S3_CONFIG_ERROR, "Error reading AWS configuration parameter %s"
   TIMEOUT_ERROR, "Timeout waiting for server to respond."
+  CREATE_TEMP_DIR_ERROR, "Cannot create temporary directory '%s'. You may change root directory to store temporary files in Preferences."
 
   CORE_CONFIRMATION_STRINGS, "CORE_CONFIRMATION"
   CONFIRM_PROLONG_TIMEOUT3, "Host is not communicating for %d seconds.\n\nWait for another %0:d seconds?"
@@ -456,6 +457,8 @@ BEGIN
   COPY_INFO_DONT_ENCRYPT_NEW_FILES, "Do not encrypt new files"
   COPY_INFO_EXCLUDE_HIDDEN_FILES, "Exclude hidden files"
   COPY_INFO_EXCLUDE_EMPTY_DIRS, "Exclude empty directories"
+  PUBLIC_KEY_UPLOADED, "**Public key \"%s\" was installed.**\n\nYou can now login to the server using the key pair."
+  PUBLIC_KEY_PERMISSIONS, "Though potentially wrong permissions of \"%s\" file and/or its parent folder were detected. Please check them."
 
   CORE_VARIABLE_STRINGS, "CORE_VARIABLE"
   PUTTY_BASED_ON, "SSH and SCP code based on PuTTY %s"

+ 0 - 3
source/resource/TextsWin.h

@@ -33,7 +33,6 @@
 #define EDIT_SESSION_CLOSED2    1143
 #define TOO_MANY_EDITORS        1144
 #define INVALID_DEFAULT_TRANSLATION 1146
-#define CREATE_TEMP_DIR_ERROR   1147
 #define OPEN_FILE_NO_PROCESS2   1148
 #define CLEANUP_TEMP_ERROR      1149
 #define CUSTOM_COMMAND_SELECTED_UNMATCH 1150
@@ -613,8 +612,6 @@
 #define LOGIN_AUTHORIZED_KEYS   6003
 #define LOGIN_NOT_OPENSSH       6004
 #define LOGIN_PUBLIC_KEY_UPLOAD 6005
-#define LOGIN_PUBLIC_KEY_UPLOADED 6006
-#define LOGIN_PUBLIC_KEY_PERMISSIONS 6007
 #define LOGIN_PUBLIC_KEY_TITLE  6008
 #define LOGIN_PUBLIC_KEY_FILTER 6009
 #define SYNCHRONIZE_CHECKLIST_CAPTION 6010

+ 0 - 3
source/resource/TextsWin1.rc

@@ -40,7 +40,6 @@ BEGIN
         EDIT_SESSION_CLOSED2, "**Cannot upload edited file '%s'**\n\nThe session '%s' has been already closed.\n\nOpen a new session on the same site and try saving file again."
         TOO_MANY_EDITORS, "There are too many opened files already. Please close some first."
         INVALID_DEFAULT_TRANSLATION, "%s Please remove the file. Otherwise the application will not work correctly."
-        CREATE_TEMP_DIR_ERROR, "Cannot create temporary directory '%s'. You may change root directory to store temporary files in Preferences."
         OPEN_FILE_NO_PROCESS2, "WinSCP was not able to determine application that was started to open the file. WinSCP cannot watch for changes in the file and thus it will not upload the changed file back.\n \nOne possible reason for the problem is that the file was opened in some already running application.\n \nIf you want to use the application to open files from WinSCP, consider configuring it as an external editor.\n \nNote that the file will remain in temporary folder."
         CLEANUP_TEMP_ERROR, "Some of the temporary folders have not been deleted. If you have some files stored in them still opened, close them and try again."
         CUSTOM_COMMAND_SELECTED_UNMATCH, "To use selected custom command only one file must be selected in one panel to execute the command with the file for each selected file in an opposite panel. Alternatively same number of files can be selected in both panels to execute the command for file pairs."
@@ -618,8 +617,6 @@ BEGIN
         LOGIN_AUTHORIZED_KEYS, "**Public key for pasting into OpenSSH authorized_keys file:**"
         LOGIN_NOT_OPENSSH, "**Install public key to non-OpenSSH server?**\n\nInstalling public key is supported for OpenSSH server only (authorized_keys file).\n\nYour server is %s."
         LOGIN_PUBLIC_KEY_UPLOAD, "Installing public key \"%s\"..."
-        LOGIN_PUBLIC_KEY_UPLOADED, "**Public key \"%s\" was installed.**\n\nYou can now login to the server using the key pair."
-        LOGIN_PUBLIC_KEY_PERMISSIONS, "Though potentially wrong permissions of \"%s\" file and/or its parent folder were detected. Please check them."
         LOGIN_PUBLIC_KEY_TITLE, "Select key to install into server"
         LOGIN_PUBLIC_KEY_FILTER, "PuTTY Private Key Files (*.ppk)|*.ppk|All Private Key Files (*.ppk;*.pem;*.key;id_*)|*.ppk;*.pem;*.key;id_*|All Files (*.*)|*.*"
         SYNCHRONIZE_CHECKLIST_CAPTION, "Synchronization checklist"

+ 6 - 146
source/windows/TerminalManager.cpp

@@ -1766,33 +1766,6 @@ TTerminalQueue * __fastcall TTerminalManager::FindQueueForTerminal(TTerminal * T
   return reinterpret_cast<TTerminalQueue *>(FQueues->Items[Index]);
 }
 //---------------------------------------------------------------------------
-TRemoteFile * __fastcall TTerminalManager::CheckRights(
-  TTerminal * Terminal, const UnicodeString & EntryType, const UnicodeString & FileName, bool & WrongRights)
-{
-  std::unique_ptr<TRemoteFile> FileOwner;
-  TRemoteFile * File;
-  try
-  {
-    Terminal->LogEvent(FORMAT(L"Checking %s \"%s\"...", (LowerCase(EntryType), FileName)));
-    Terminal->ReadFile(FileName, File);
-    FileOwner.reset(File);
-    int ForbiddenRights = TRights::rfGroupWrite | TRights::rfOtherWrite;
-    if ((File->Rights->Number & ForbiddenRights) != 0)
-    {
-      Terminal->LogEvent(FORMAT(L"%s \"%s\" exists, but has incorrect permissions %s.", (EntryType, FileName, File->Rights->Octal)));
-      WrongRights = true;
-    }
-    else
-    {
-      Terminal->LogEvent(FORMAT(L"%s \"%s\" exists and has correct permissions %s.", (EntryType, FileName, File->Rights->Octal)));
-    }
-  }
-  catch (Exception & E)
-  {
-  }
-  return FileOwner.release();
-}
-//---------------------------------------------------------------------------
 bool __fastcall TTerminalManager::UploadPublicKey(
   TTerminal * Terminal, TSessionData * Data, UnicodeString & FileName)
 {
@@ -1833,138 +1806,31 @@ bool __fastcall TTerminalManager::UploadPublicKey(
       }
     }
 
-    bool Installed = false;
-    bool WrongRights = false;
-
-    UnicodeString TemporaryDir;
-    bool AutoReadDirectory = Terminal->AutoReadDirectory;
-    bool ExceptionOnFail = Terminal->ExceptionOnFail;
-
-    const UnicodeString SshFolder = L".ssh";
-    const UnicodeString AuthorizedKeysFile = L"authorized_keys";
-    UnicodeString AuthorizedKeysFilePath = FORMAT(L"%s/%s", (SshFolder, AuthorizedKeysFile));
-
-    UnicodeString Comment;
-    UnicodeString Line = GetPublicKeyLine(FileName, Comment);
-
+    UnicodeString Installed;
     try
     {
-      Terminal->AutoReadDirectory = false;
-      Terminal->ExceptionOnFail = true;
-
       UnicodeString SshImplementation = Terminal->GetSessionInfo().SshImplementation;
       UnicodeString NotOpenSSHMessage = FMTLOAD(LOGIN_NOT_OPENSSH, (SshImplementation));
       if (IsOpenSSH(SshImplementation) ||
           (MessageDialog(NotOpenSSHMessage, qtConfirmation, qaOK | qaCancel, HELP_LOGIN_AUTHORIZED_KEYS) == qaOK))
       {
-        Terminal->Log->AddSeparator();
-        Terminal->LogEvent(FORMAT(L"Adding public key line to \"%s\" file:\n%s", (AuthorizedKeysFilePath, Line)));
-
         // Ad-hoc terminal
         if (FAuthenticateForm != NULL)
         {
+          UnicodeString Comment;
+          GetPublicKeyLine(FileName, Comment);
           FAuthenticateForm->Log(FMTLOAD(LOGIN_PUBLIC_KEY_UPLOAD, (Comment)));
         }
 
-        UnicodeString SshFolderAbsolutePath = UnixIncludeTrailingBackslash(Terminal->GetHomeDirectory()) + SshFolder;
-        std::unique_ptr<TRemoteFile> SshFolderFile(CheckRights(Terminal, L"Folder", SshFolderAbsolutePath, WrongRights));
-        if (SshFolderFile.get() == NULL)
-        {
-          TRights SshFolderRights;
-          SshFolderRights.Number = TRights::rfUserRead | TRights::rfUserWrite | TRights::rfUserExec;
-          TRemoteProperties SshFolderProperties;
-          SshFolderProperties.Rights = SshFolderRights;
-          SshFolderProperties.Valid = TValidProperties() << vpRights;
-
-          Terminal->LogEvent(FORMAT(L"Trying to create \"%s\" folder with permissions %s...", (SshFolder, SshFolderRights.Octal)));
-          Terminal->CreateDirectory(SshFolderAbsolutePath, &SshFolderProperties);
-        }
-
-        TemporaryDir = ExcludeTrailingBackslash(WinConfiguration->TemporaryDir());
-        if (!ForceDirectories(ApiPath(TemporaryDir)))
-        {
-          throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TemporaryDir)));
-        }
-        UnicodeString TemporaryAuthorizedKeysFile = IncludeTrailingBackslash(TemporaryDir) + AuthorizedKeysFile;
-
-        UnicodeString AuthorizedKeysFileAbsolutePath = UnixIncludeTrailingBackslash(SshFolderAbsolutePath) + AuthorizedKeysFile;
-
-        bool Updated = true;
-        TCopyParamType CopyParam; // Use factory defaults
-        CopyParam.ResumeSupport = rsOff; // not to break the permissions
-        CopyParam.PreserveTime = false; // not needed
-
-        UnicodeString AuthorizedKeys;
-        std::unique_ptr<TRemoteFile> AuthorizedKeysFileFile(CheckRights(Terminal, L"File", AuthorizedKeysFileAbsolutePath, WrongRights));
-        if (AuthorizedKeysFileFile.get() != NULL)
-        {
-          AuthorizedKeysFileFile->FullFileName = AuthorizedKeysFileAbsolutePath;
-          std::unique_ptr<TStrings> Files(new TStringList());
-          Files->AddObject(AuthorizedKeysFileAbsolutePath, AuthorizedKeysFileFile.get());
-          Terminal->LogEvent(FORMAT(L"Downloading current \"%s\" file...", (AuthorizedKeysFile)));
-          Terminal->CopyToLocal(Files.get(), TemporaryDir, &CopyParam, cpNoConfirmation, NULL);
-          // Overload with Encoding parameter work incorrectly, when used on a file without BOM
-          AuthorizedKeys = TFile::ReadAllText(TemporaryAuthorizedKeysFile);
-
-          std::unique_ptr<TStrings> AuthorizedKeysLines(TextToStringList(AuthorizedKeys));
-          int P = Line.Pos(L" ");
-          if (DebugAlwaysTrue(P > 0))
-          {
-            P = PosEx(L" ", Line, P + 1);
-          }
-          UnicodeString Prefix = Line.SubString(1, P); // including the space
-          for (int Index = 0; Index < AuthorizedKeysLines->Count; Index++)
-          {
-            if (StartsStr(Prefix, AuthorizedKeysLines->Strings[Index]))
-            {
-              Terminal->LogEvent(FORMAT(L"\"%s\" file already contains public key line:\n%s", (AuthorizedKeysFile, AuthorizedKeysLines->Strings[Index])));
-              Updated = false;
-            }
-          }
-
-          if (Updated)
-          {
-            Terminal->LogEvent(FORMAT(L"\"%s\" file does not contain the public key line yet.", (AuthorizedKeysFile)));
-            if (!EndsStr(L"\n", AuthorizedKeys))
-            {
-              Terminal->LogEvent(FORMAT(L"Adding missing trailing new line to \"%s\" file...", (AuthorizedKeysFile)));
-              AuthorizedKeys += L"\n";
-            }
-          }
-        }
-        else
-        {
-          Terminal->LogEvent(FORMAT(L"Creating new \"%s\" file...", (AuthorizedKeysFile)));
-          CopyParam.PreserveRights = true;
-          CopyParam.Rights.Number = TRights::rfUserRead | TRights::rfUserWrite;
-        }
-
-        if (Updated)
-        {
-          AuthorizedKeys += Line + L"\n";
-          // Overload without Encoding parameter uses TEncoding::UTF8, but does not write BOM, what we want
-          TFile::WriteAllText(TemporaryAuthorizedKeysFile, AuthorizedKeys);
-          std::unique_ptr<TStrings> Files(new TStringList());
-          Files->Add(TemporaryAuthorizedKeysFile);
-          Terminal->LogEvent(FORMAT(L"Uploading updated \"%s\" file...", (AuthorizedKeysFile)));
-          Terminal->CopyToRemote(Files.get(), SshFolderAbsolutePath, &CopyParam, cpNoConfirmation, NULL);
-        }
-
-        Installed = true;
+        Installed = Terminal->UploadPublicKey(FileName);
       }
     }
     __finally
     {
-      Terminal->AutoReadDirectory = AutoReadDirectory;
-      Terminal->ExceptionOnFail = ExceptionOnFail;
-      if (!TemporaryDir.IsEmpty())
-      {
-        RecursiveDeleteFile(ExcludeTrailingBackslash(TemporaryDir), false);
-      }
       CloseAutheticateForm(); // When uploading from Login dialog
     }
 
-    if (Installed)
+    if (!Installed.IsEmpty())
     {
       Terminal->LogEvent(L"Public key installation done.");
       if (AdHocTerminal)
@@ -1976,13 +1842,7 @@ bool __fastcall TTerminalManager::UploadPublicKey(
         Terminal->Log->AddSeparator();
       }
 
-      UnicodeString Message = FMTLOAD(LOGIN_PUBLIC_KEY_UPLOADED, (Comment));
-      if (WrongRights)
-      {
-        Message += L"\n\n" + FMTLOAD(LOGIN_PUBLIC_KEY_PERMISSIONS, (AuthorizedKeysFilePath));
-      }
-
-      MessageDialog(Message, qtInformation, qaOK, HELP_LOGIN_AUTHORIZED_KEYS);
+      MessageDialog(Installed, qtInformation, qaOK, HELP_LOGIN_AUTHORIZED_KEYS);
     }
   }
 

+ 0 - 2
source/windows/TerminalManager.h

@@ -182,8 +182,6 @@ private:
   void __fastcall SetupTerminal(TTerminal * Terminal);
   void __fastcall CloseAutheticateForm();
   void __fastcall AuthenticatingDone();
-  TRemoteFile * __fastcall CheckRights(
-    TTerminal * Terminal, const UnicodeString & EntryType, const UnicodeString & FileName, bool & WrongRights);
   TManagedTerminal * __fastcall CreateManagedTerminal(TSessionData * Data);
   TManagedTerminal * __fastcall GetTerminal(int Index);
 };

+ 1 - 1
source/windows/WinConfiguration.cpp

@@ -2456,7 +2456,7 @@ UnicodeString __fastcall TWinConfiguration::ExpandedTemporaryDirectory()
   return Result;
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TWinConfiguration::TemporaryDir(bool Mask)
+UnicodeString TWinConfiguration::TemporaryDir(bool Mask)
 {
   return UniqTempDir(ExpandedTemporaryDirectory(), L"scp", Mask);
 }

+ 1 - 1
source/windows/WinConfiguration.h

@@ -625,7 +625,7 @@ public:
   virtual void __fastcall Default();
   void __fastcall ClearTemporaryLoginData();
   virtual THierarchicalStorage * CreateScpStorage(bool & SessionList);
-  UnicodeString __fastcall TemporaryDir(bool Mask = false);
+  virtual UnicodeString TemporaryDir(bool Mask = false);
   TStrings * __fastcall FindTemporaryFolders();
   bool __fastcall AnyTemporaryFolders();
   void __fastcall CleanupTemporaryFolders();