瀏覽代碼

Factoring out a constant for .ssh folder name

(cherry picked from commit 87717a9fab5fcc00bcff02d76e5fc92c5d589d78)

Source commit: db325e5f68a2000e1eccd4004d13f5fe9883abce
Martin Prikryl 3 年之前
父節點
當前提交
88f20f64be
共有 3 個文件被更改,包括 18 次插入14 次删除
  1. 4 1
      source/core/Configuration.cpp
  2. 3 0
      source/core/Configuration.h
  3. 11 13
      source/core/Terminal.cpp

+ 4 - 1
source/core/Configuration.cpp

@@ -43,6 +43,9 @@ const UnicodeString DirectoryStatisticsCacheKey(L"DirectoryStatisticsCache");
 const UnicodeString CDCacheKey(L"CDCache");
 const UnicodeString BannersKey(L"Banners");
 //---------------------------------------------------------------------------
+const UnicodeString OpensshFolderName(L".ssh");
+const UnicodeString OpensshAuthorizedKeysFileName(L"authorized_keys");
+//---------------------------------------------------------------------------
 const int BelowNormalLogLevels = 1;
 //---------------------------------------------------------------------------
 __fastcall TConfiguration::TConfiguration()
@@ -1473,7 +1476,7 @@ bool __fastcall TConfiguration::AnyFilezillaSessionForImport(TStoredSessionList
 static UnicodeString GetOpensshFolder()
 {
   UnicodeString ProfilePath = GetShellFolderPath(CSIDL_PROFILE);
-  UnicodeString Result = TPath::Combine(ProfilePath, L".ssh");
+  UnicodeString Result = TPath::Combine(ProfilePath, OpensshFolderName);
   return Result;
 }
 //---------------------------------------------------------------------

+ 3 - 0
source/core/Configuration.h

@@ -390,4 +390,7 @@ extern const UnicodeString HttpsCertificateStorageKey;
 //---------------------------------------------------------------------------
 extern const int BelowNormalLogLevels;
 //---------------------------------------------------------------------------
+extern const UnicodeString OpensshFolderName;
+extern const UnicodeString OpensshAuthorizedKeysFileName;
+//---------------------------------------------------------------------------
 #endif

+ 11 - 13
source/core/Terminal.cpp

@@ -8197,9 +8197,7 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
   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));
+  UnicodeString AuthorizedKeysFilePath = FORMAT(L"%s/%s", (OpensshFolderName, OpensshAuthorizedKeysFileName));
 
   try
   {
@@ -8213,7 +8211,7 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
 
     LogEvent(FORMAT(L"Adding public key line to \"%s\" file:\n%s", (AuthorizedKeysFilePath, Line)));
 
-    UnicodeString SshFolderAbsolutePath = UnixIncludeTrailingBackslash(GetHomeDirectory()) + SshFolder;
+    UnicodeString SshFolderAbsolutePath = UnixIncludeTrailingBackslash(GetHomeDirectory()) + OpensshFolderName;
     bool WrongRights = false;
     std::unique_ptr<TRemoteFile> SshFolderFile(CheckRights(L"Folder", SshFolderAbsolutePath, WrongRights));
     if (SshFolderFile.get() == NULL)
@@ -8224,7 +8222,7 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
       SshFolderProperties.Rights = SshFolderRights;
       SshFolderProperties.Valid = TValidProperties() << vpRights;
 
-      LogEvent(FORMAT(L"Trying to create \"%s\" folder with permissions %s...", (SshFolder, SshFolderRights.Octal)));
+      LogEvent(FORMAT(L"Trying to create \"%s\" folder with permissions %s...", (OpensshFolderName, SshFolderRights.Octal)));
       CreateDirectory(SshFolderAbsolutePath, &SshFolderProperties);
     }
 
@@ -8233,9 +8231,9 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
     {
       throw EOSExtException(FMTLOAD(CREATE_TEMP_DIR_ERROR, (TemporaryDir)));
     }
-    UnicodeString TemporaryAuthorizedKeysFile = IncludeTrailingBackslash(TemporaryDir) + AuthorizedKeysFile;
+    UnicodeString TemporaryAuthorizedKeysFile = IncludeTrailingBackslash(TemporaryDir) + OpensshAuthorizedKeysFileName;
 
-    UnicodeString AuthorizedKeysFileAbsolutePath = UnixIncludeTrailingBackslash(SshFolderAbsolutePath) + AuthorizedKeysFile;
+    UnicodeString AuthorizedKeysFileAbsolutePath = UnixIncludeTrailingBackslash(SshFolderAbsolutePath) + OpensshAuthorizedKeysFileName;
 
     bool Updated = true;
     TCopyParamType CopyParam; // Use factory defaults
@@ -8249,7 +8247,7 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
       AuthorizedKeysFileFile->FullFileName = AuthorizedKeysFileAbsolutePath;
       std::unique_ptr<TStrings> Files(new TStringList());
       Files->AddObject(AuthorizedKeysFileAbsolutePath, AuthorizedKeysFileFile.get());
-      LogEvent(FORMAT(L"Downloading current \"%s\" file...", (AuthorizedKeysFile)));
+      LogEvent(FORMAT(L"Downloading current \"%s\" file...", (OpensshAuthorizedKeysFileName)));
       CopyToLocal(Files.get(), TemporaryDir, &CopyParam, cpNoConfirmation, NULL);
       // Overload with Encoding parameter work incorrectly, when used on a file without BOM
       AuthorizedKeys = TFile::ReadAllText(TemporaryAuthorizedKeysFile);
@@ -8265,24 +8263,24 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
       {
         if (StartsStr(Prefix, AuthorizedKeysLines->Strings[Index]))
         {
-          LogEvent(FORMAT(L"\"%s\" file already contains public key line:\n%s", (AuthorizedKeysFile, AuthorizedKeysLines->Strings[Index])));
+          LogEvent(FORMAT(L"\"%s\" file already contains public key line:\n%s", (OpensshAuthorizedKeysFileName, AuthorizedKeysLines->Strings[Index])));
           Updated = false;
         }
       }
 
       if (Updated)
       {
-        LogEvent(FORMAT(L"\"%s\" file does not contain the public key line yet.", (AuthorizedKeysFile)));
+        LogEvent(FORMAT(L"\"%s\" file does not contain the public key line yet.", (OpensshAuthorizedKeysFileName)));
         if (!EndsStr(L"\n", AuthorizedKeys))
         {
-          LogEvent(FORMAT(L"Adding missing trailing new line to \"%s\" file...", (AuthorizedKeysFile)));
+          LogEvent(FORMAT(L"Adding missing trailing new line to \"%s\" file...", (OpensshAuthorizedKeysFileName)));
           AuthorizedKeys += L"\n";
         }
       }
     }
     else
     {
-      LogEvent(FORMAT(L"Creating new \"%s\" file...", (AuthorizedKeysFile)));
+      LogEvent(FORMAT(L"Creating new \"%s\" file...", (OpensshAuthorizedKeysFileName)));
       CopyParam.PreserveRights = true;
       CopyParam.Rights.Number = TRights::rfUserRead | TRights::rfUserWrite;
     }
@@ -8294,7 +8292,7 @@ UnicodeString TTerminal::UploadPublicKey(const UnicodeString & FileName)
       TFile::WriteAllText(TemporaryAuthorizedKeysFile, AuthorizedKeys);
       std::unique_ptr<TStrings> Files(new TStringList());
       Files->Add(TemporaryAuthorizedKeysFile);
-      LogEvent(FORMAT(L"Uploading updated \"%s\" file...", (AuthorizedKeysFile)));
+      LogEvent(FORMAT(L"Uploading updated \"%s\" file...", (OpensshAuthorizedKeysFileName)));
       CopyToRemote(Files.get(), SshFolderAbsolutePath, &CopyParam, cpNoConfirmation, NULL);
     }