Ver código fonte

When opening a session in PuTTY, exporting also cached host keys

Source commit: c0c4c166b8e10c7547b206b26fc70cf3463fc6c6
Martin Prikryl 7 anos atrás
pai
commit
25b2cf883c

+ 13 - 11
source/core/SessionData.cpp

@@ -4677,21 +4677,14 @@ THierarchicalStorage * __fastcall TStoredSessionList::CreateHostKeysStorageForWr
   std::unique_ptr<THierarchicalStorage> Storage(Configuration->CreateScpStorage(SessionList));
   Storage->Explicit = true;
   Storage->AccessMode = smReadWrite;
-  if (!OpenHostKeysSubKey(Storage.get(), true))
-  {
-    Storage.reset(NULL);
-  }
   return Storage.release();
 }
 //---------------------------------------------------------------------------
 void __fastcall TStoredSessionList::ImportHostKeys(
-  const UnicodeString & SourceKey, TStoredSessionList * Sessions, bool OnlySelected)
+  THierarchicalStorage * SourceStorage, THierarchicalStorage * TargetStorage, TStoredSessionList * Sessions, bool OnlySelected)
 {
-  std::auto_ptr<THierarchicalStorage> TargetStorage(CreateHostKeysStorageForWritting());
-  std::auto_ptr<THierarchicalStorage> SourceStorage(new TRegistryStorage(SourceKey));
-
-  if ((TargetStorage.get() != NULL) &&
-      SourceStorage->OpenRootKey(false))
+  if (OpenHostKeysSubKey(SourceStorage, false) &&
+      OpenHostKeysSubKey(TargetStorage, true))
   {
     std::auto_ptr<TStringList> KeyList(new TStringList());
     SourceStorage->GetValueNames(KeyList.get());
@@ -4716,10 +4709,19 @@ void __fastcall TStoredSessionList::ImportHostKeys(
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TStoredSessionList::ImportHostKeys(
+  const UnicodeString & SourceKey, TStoredSessionList * Sessions, bool OnlySelected)
+{
+  std::auto_ptr<THierarchicalStorage> TargetStorage(CreateHostKeysStorageForWritting());
+  std::auto_ptr<THierarchicalStorage> SourceStorage(new TRegistryStorage(SourceKey));
+
+  ImportHostKeys(SourceStorage.get(), TargetStorage.get(), Sessions, OnlySelected);
+}
+//---------------------------------------------------------------------------
 void __fastcall TStoredSessionList::ImportSelectedKnownHosts(TStoredSessionList * Sessions)
 {
   std::unique_ptr<THierarchicalStorage> Storage(CreateHostKeysStorageForWritting());
-  if (Storage.get() != NULL)
+  if (OpenHostKeysSubKey(Storage.get(), true))
   {
     for (int Index = 0; Index < Sessions->Count; Index++)
     {

+ 3 - 1
source/core/SessionData.h

@@ -697,9 +697,12 @@ public:
   __property TSessionData * Sessions[int Index]  = { read=AtSession };
   __property TSessionData * DefaultSettings  = { read=FDefaultSettings, write=SetDefaultSettings };
 
+  static void __fastcall ImportHostKeys(
+    THierarchicalStorage * SourceStorage, THierarchicalStorage * TargetStorage, TStoredSessionList * Sessions, bool OnlySelected);
   static void __fastcall ImportHostKeys(
     const UnicodeString & SourceKey, TStoredSessionList * Sessions, bool OnlySelected);
   static void __fastcall ImportSelectedKnownHosts(TStoredSessionList * Sessions);
+  static bool __fastcall OpenHostKeysSubKey(THierarchicalStorage * Storage, bool CanCreate);
 
 private:
   TSessionData * FDefaultSettings;
@@ -718,7 +721,6 @@ private:
     TSessionData * Data, const UnicodeString & Name);
   void __fastcall ImportLevelFromFilezilla(_di_IXMLNode Node, const UnicodeString & Path, _di_IXMLNode SettingsNode);
   static THierarchicalStorage * __fastcall CreateHostKeysStorageForWritting();
-  static bool __fastcall OpenHostKeysSubKey(THierarchicalStorage * Storage, bool CanCreate);
 };
 //---------------------------------------------------------------------------
 UnicodeString GetExpandedLogFileName(UnicodeString LogFileName, TDateTime Started, TSessionData * SessionData);

+ 1 - 1
source/forms/ImportSessions.cpp

@@ -57,7 +57,7 @@ bool __fastcall DoImportSessionsDialog(TList * Imported)
     StoredSessions->Import(PuttyImportSessionList.get(), true, Imported);
     StoredSessions->Import(FilezillaImportSessionList.get(), true, Imported);
 
-    UnicodeString SourceKey = Configuration->PuttyRegistryStorageKey + L"\\" + Configuration->SshHostKeysSubKey;
+    UnicodeString SourceKey = Configuration->PuttyRegistryStorageKey;
 
     TStoredSessionList::ImportHostKeys(SourceKey, PuttyImportSessionList.get(), true);
 

+ 12 - 0
source/windows/GUITools.cpp

@@ -94,6 +94,18 @@ void __fastcall OpenSessionInPutty(const UnicodeString PuttyPath,
 
     if (!RemoteCustomCommand.IsSiteCommand(AParams))
     {
+      {
+        bool SessionList = false;
+        std::unique_ptr<THierarchicalStorage> SourceHostKeyStorage(Configuration->CreateScpStorage(SessionList));
+        std::unique_ptr<THierarchicalStorage> TargetHostKeyStorage(new TRegistryStorage(Configuration->PuttyRegistryStorageKey));
+        TargetHostKeyStorage->Explicit = true;
+        TargetHostKeyStorage->AccessMode = smReadWrite;
+        std::unique_ptr<TStoredSessionList> HostKeySessionList(new TStoredSessionList());
+        HostKeySessionList->OwnsObjects = false;
+        HostKeySessionList->Add(SessionData);
+        TStoredSessionList::ImportHostKeys(SourceHostKeyStorage.get(), TargetHostKeyStorage.get(), HostKeySessionList.get(), false);
+      }
+
       if (IsUWP())
       {
         bool Telnet = (SessionData->FSProtocol == fsFTP) && GUIConfiguration->TelnetForFtpInPutty;