PuttyIntf.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "PuttyIntf.h"
  5. #include "Interface.h"
  6. #include "SecureShell.h"
  7. #include "Exceptions.h"
  8. #include "CoreMain.h"
  9. #include "TextsCore.h"
  10. #include <StrUtils.hpp>
  11. #include <Soap.EncdDecd.hpp>
  12. //---------------------------------------------------------------------------
  13. char sshver[50];
  14. extern const char commitid[] = "";
  15. const bool platform_uses_x11_unix_by_default = true;
  16. CRITICAL_SECTION putty_section;
  17. bool SaveRandomSeed;
  18. bool HadRandomSeed;
  19. char appname_[50];
  20. const char *const appname = appname_;
  21. extern const bool share_can_be_downstream = false;
  22. extern const bool share_can_be_upstream = false;
  23. THierarchicalStorage * PuttyStorage = NULL;
  24. //---------------------------------------------------------------------------
  25. extern "C"
  26. {
  27. #include <winstuff.h>
  28. }
  29. const UnicodeString OriginalPuttyRegistryStorageKey(_T(PUTTY_REG_POS));
  30. const UnicodeString KittyRegistryStorageKey(L"Software\\9bis.com\\KiTTY");
  31. const UnicodeString OriginalPuttyExecutable("putty.exe");
  32. const UnicodeString KittyExecutable("kitty.exe");
  33. const UnicodeString PuttyKeyExt(L"ppk");
  34. //---------------------------------------------------------------------------
  35. void __fastcall PuttyInitialize()
  36. {
  37. SaveRandomSeed = true;
  38. InitializeCriticalSection(&putty_section);
  39. HadRandomSeed = FileExists(ApiPath(Configuration->RandomSeedFileName));
  40. // make sure random generator is initialised, so random_save_seed()
  41. // in destructor can proceed
  42. random_ref();
  43. sk_init();
  44. AnsiString VersionString = AnsiString(SshVersionString());
  45. DebugAssert(!VersionString.IsEmpty() && (static_cast<size_t>(VersionString.Length()) < LENOF(sshver)));
  46. strcpy(sshver, VersionString.c_str());
  47. AnsiString AppName = AnsiString(AppNameString());
  48. DebugAssert(!AppName.IsEmpty() && (static_cast<size_t>(AppName.Length()) < LENOF(appname_)));
  49. strcpy(appname_, AppName.c_str());
  50. }
  51. //---------------------------------------------------------------------------
  52. static bool DeleteRandomSeedOnExit()
  53. {
  54. return !HadRandomSeed && !SaveRandomSeed;
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall PuttyFinalize()
  58. {
  59. if (SaveRandomSeed)
  60. {
  61. random_save_seed();
  62. }
  63. random_unref();
  64. // random_ref in PuttyInitialize creates the seed file. Delete it, if we didn't want to create it.
  65. if (DeleteRandomSeedOnExit())
  66. {
  67. DeleteFile(ApiPath(Configuration->RandomSeedFileName));
  68. }
  69. sk_cleanup();
  70. win_misc_cleanup();
  71. win_secur_cleanup();
  72. ec_cleanup();
  73. wingss_cleanup();
  74. DeleteCriticalSection(&putty_section);
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall DontSaveRandomSeed()
  78. {
  79. SaveRandomSeed = false;
  80. }
  81. //---------------------------------------------------------------------------
  82. bool RandomSeedExists()
  83. {
  84. return
  85. !DeleteRandomSeedOnExit() &&
  86. FileExists(ApiPath(Configuration->RandomSeedFileName));
  87. }
  88. //---------------------------------------------------------------------------
  89. TSecureShell * GetSecureShell(Plug * plug, bool & pfwd)
  90. {
  91. if (!is_ssh(plug) && !is_pfwd(plug))
  92. {
  93. // If it is not SSH/PFwd plug, then it must be Proxy plug.
  94. // Get SSH/PFwd plug which it wraps.
  95. ProxySocket * AProxySocket = get_proxy_plug_socket(plug);
  96. plug = AProxySocket->plug;
  97. }
  98. pfwd = is_pfwd(plug);
  99. Seat * seat;
  100. if (pfwd)
  101. {
  102. seat = get_pfwd_seat(plug);
  103. }
  104. else
  105. {
  106. seat = get_ssh_seat(plug);
  107. }
  108. DebugAssert(seat != NULL);
  109. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  110. return SecureShell;
  111. }
  112. //---------------------------------------------------------------------------
  113. struct callback_set * get_callback_set(Plug * plug)
  114. {
  115. bool pfwd;
  116. TSecureShell * SecureShell = GetSecureShell(plug, pfwd);
  117. return SecureShell->GetCallbackSet();
  118. }
  119. //---------------------------------------------------------------------------
  120. struct callback_set * get_seat_callback_set(Seat * seat)
  121. {
  122. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  123. return SecureShell->GetCallbackSet();
  124. }
  125. //---------------------------------------------------------------------------
  126. extern "C" const char * do_select(Plug * plug, SOCKET skt, bool enable)
  127. {
  128. bool pfwd;
  129. TSecureShell * SecureShell = GetSecureShell(plug, pfwd);
  130. if (!pfwd)
  131. {
  132. SecureShell->UpdateSocket(skt, enable);
  133. }
  134. else
  135. {
  136. SecureShell->UpdatePortFwdSocket(skt, enable);
  137. }
  138. return NULL;
  139. }
  140. //---------------------------------------------------------------------------
  141. static size_t output(Seat * seat, bool is_stderr, const void * data, size_t len)
  142. {
  143. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  144. if (static_cast<int>(static_cast<char>(is_stderr)) == -1)
  145. {
  146. SecureShell->CWrite(reinterpret_cast<const char *>(data), len);
  147. }
  148. else if (!is_stderr)
  149. {
  150. SecureShell->FromBackend(reinterpret_cast<const unsigned char *>(data), len);
  151. }
  152. else
  153. {
  154. SecureShell->AddStdError(reinterpret_cast<const char *>(data), len);
  155. }
  156. return 0;
  157. }
  158. //---------------------------------------------------------------------------
  159. static bool eof(Seat *)
  160. {
  161. return false;
  162. }
  163. //---------------------------------------------------------------------------
  164. static int get_userpass_input(Seat * seat, prompts_t * p, bufchain * DebugUsedArg(input))
  165. {
  166. DebugAssert(p != NULL);
  167. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  168. DebugAssert(SecureShell != NULL);
  169. int Result;
  170. TStrings * Prompts = new TStringList();
  171. TStrings * Results = new TStringList();
  172. try
  173. {
  174. UnicodeString Name = UTF8ToString(p->name);
  175. UnicodeString AName = Name;
  176. TPromptKind PromptKind = SecureShell->IdentifyPromptKind(AName);
  177. bool UTF8Prompt = (PromptKind != pkPassphrase);
  178. for (int Index = 0; Index < int(p->n_prompts); Index++)
  179. {
  180. prompt_t * Prompt = p->prompts[Index];
  181. UnicodeString S;
  182. if (UTF8Prompt)
  183. {
  184. S = UTF8ToString(Prompt->prompt);
  185. }
  186. else
  187. {
  188. S = UnicodeString(AnsiString(Prompt->prompt));
  189. }
  190. Prompts->AddObject(S, (TObject *)(FLAGMASK(Prompt->echo, pupEcho)));
  191. // this fails, when new passwords do not match on change password prompt,
  192. // and putty retries the prompt
  193. DebugAssert(strlen(prompt_get_result_ref(Prompt)) == 0);
  194. Results->Add(L"");
  195. }
  196. UnicodeString Instructions = UTF8ToString(p->instruction);
  197. if (SecureShell->PromptUser(p->to_server, Name, p->name_reqd,
  198. Instructions, p->instr_reqd, Prompts, Results))
  199. {
  200. for (int Index = 0; Index < int(p->n_prompts); Index++)
  201. {
  202. prompt_t * Prompt = p->prompts[Index];
  203. RawByteString S;
  204. if (UTF8Prompt)
  205. {
  206. S = RawByteString(UTF8String(Results->Strings[Index]));
  207. }
  208. else
  209. {
  210. S = RawByteString(AnsiString(Results->Strings[Index]));
  211. }
  212. prompt_set_result(Prompt, S.c_str());
  213. }
  214. Result = 1;
  215. }
  216. else
  217. {
  218. Result = 0;
  219. }
  220. }
  221. __finally
  222. {
  223. delete Prompts;
  224. delete Results;
  225. }
  226. return Result;
  227. }
  228. //---------------------------------------------------------------------------
  229. static void connection_fatal(Seat * seat, const char * message)
  230. {
  231. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  232. SecureShell->PuttyFatalError(UnicodeString(AnsiString(message)));
  233. }
  234. //---------------------------------------------------------------------------
  235. int verify_ssh_host_key(Seat * seat, const char * host, int port, const char * keytype,
  236. char * keystr, const char * DebugUsedArg(keydisp), char ** key_fingerprints,
  237. void (*DebugUsedArg(callback))(void *ctx, int result), void * DebugUsedArg(ctx))
  238. {
  239. UnicodeString FingerprintSHA256, FingerprintMD5;
  240. if (key_fingerprints[SSH_FPTYPE_SHA256] != NULL)
  241. {
  242. FingerprintSHA256 = key_fingerprints[SSH_FPTYPE_SHA256];
  243. }
  244. if (DebugAlwaysTrue(key_fingerprints[SSH_FPTYPE_MD5] != NULL))
  245. {
  246. FingerprintMD5 = key_fingerprints[SSH_FPTYPE_MD5];
  247. }
  248. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  249. SecureShell->VerifyHostKey(host, port, keytype, keystr, FingerprintSHA256, FingerprintMD5);
  250. // We should return 0 when key was not confirmed, we throw exception instead.
  251. return 1;
  252. }
  253. //---------------------------------------------------------------------------
  254. bool have_ssh_host_key(Seat * seat, const char * hostname, int port,
  255. const char * keytype)
  256. {
  257. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  258. return SecureShell->HaveHostKey(hostname, port, keytype) ? 1 : 0;
  259. }
  260. //---------------------------------------------------------------------------
  261. int confirm_weak_crypto_primitive(Seat * seat, const char * algtype, const char * algname,
  262. void (*/*callback*/)(void * ctx, int result), void * /*ctx*/)
  263. {
  264. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  265. SecureShell->AskAlg(algtype, algname);
  266. // We should return 0 when alg was not confirmed, we throw exception instead.
  267. return 1;
  268. }
  269. //---------------------------------------------------------------------------
  270. int confirm_weak_cached_hostkey(Seat *, const char * /*algname*/, const char * /*betteralgs*/,
  271. void (*/*callback*/)(void *ctx, int result), void * /*ctx*/)
  272. {
  273. return 1;
  274. }
  275. //---------------------------------------------------------------------------
  276. void old_keyfile_warning(void)
  277. {
  278. // no reference to TSecureShell instance available
  279. }
  280. //---------------------------------------------------------------------------
  281. void display_banner(Seat * seat, const char * banner, int size)
  282. {
  283. TSecureShell * SecureShell = static_cast<ScpSeat *>(seat)->SecureShell;
  284. UnicodeString Banner(UTF8String(banner, size));
  285. SecureShell->DisplayBanner(Banner);
  286. }
  287. //---------------------------------------------------------------------------
  288. static void SSHFatalError(const char * Format, va_list Param)
  289. {
  290. char Buf[200];
  291. vsnprintf(Buf, LENOF(Buf), Format, Param);
  292. Buf[LENOF(Buf) - 1] = '\0';
  293. // Only few calls from putty\winnet.c might be connected with specific
  294. // TSecureShell. Otherwise called only for really fatal errors
  295. // like 'out of memory' from putty\ssh.c.
  296. throw ESshFatal(NULL, Buf);
  297. }
  298. //---------------------------------------------------------------------------
  299. void modalfatalbox(const char * fmt, ...)
  300. {
  301. va_list Param;
  302. va_start(Param, fmt);
  303. SSHFatalError(fmt, Param);
  304. va_end(Param);
  305. }
  306. //---------------------------------------------------------------------------
  307. void nonfatal(const char * fmt, ...)
  308. {
  309. va_list Param;
  310. va_start(Param, fmt);
  311. SSHFatalError(fmt, Param);
  312. va_end(Param);
  313. }
  314. //---------------------------------------------------------------------------
  315. void ldisc_echoedit_update(Ldisc * /*handle*/)
  316. {
  317. DebugFail();
  318. }
  319. //---------------------------------------------------------------------------
  320. unsigned long schedule_timer(int ticks, timer_fn_t /*fn*/, void * /*ctx*/)
  321. {
  322. return ticks + GetTickCount();
  323. }
  324. //---------------------------------------------------------------------------
  325. void expire_timer_context(void * /*ctx*/)
  326. {
  327. // nothing
  328. }
  329. //---------------------------------------------------------------------------
  330. Pinger * pinger_new(Conf * /*conf*/, Backend * /*back*/)
  331. {
  332. return NULL;
  333. }
  334. //---------------------------------------------------------------------------
  335. void pinger_reconfig(Pinger * /*pinger*/, Conf * /*oldconf*/, Conf * /*newconf*/)
  336. {
  337. // nothing
  338. }
  339. //---------------------------------------------------------------------------
  340. void pinger_free(Pinger * /*pinger*/)
  341. {
  342. // nothing
  343. }
  344. //---------------------------------------------------------------------------
  345. void platform_get_x11_auth(struct X11Display * /*display*/, Conf * /*conf*/)
  346. {
  347. // nothing, therefore no auth.
  348. }
  349. //---------------------------------------------------------------------------
  350. // Based on PuTTY's settings.c
  351. char * get_remote_username(Conf * conf)
  352. {
  353. char * username = conf_get_str(conf, CONF_username);
  354. char * result;
  355. if (*username)
  356. {
  357. result = dupstr(username);
  358. }
  359. else
  360. {
  361. result = NULL;
  362. }
  363. return result;
  364. }
  365. //---------------------------------------------------------------------------
  366. static const SeatVtable ScpSeatVtable =
  367. {
  368. output,
  369. eof,
  370. get_userpass_input,
  371. nullseat_notify_remote_exit,
  372. connection_fatal,
  373. nullseat_update_specials_menu,
  374. nullseat_get_ttymode,
  375. nullseat_set_busy_status,
  376. verify_ssh_host_key,
  377. confirm_weak_crypto_primitive,
  378. confirm_weak_cached_hostkey,
  379. nullseat_is_always_utf8,
  380. nullseat_echoedit_update,
  381. nullseat_get_x_display,
  382. nullseat_get_windowid,
  383. nullseat_get_window_pixel_size,
  384. nullseat_stripctrl_new,
  385. nullseat_set_trust_status_vacuously,
  386. nullseat_verbose_yes,
  387. nullseat_interactive_no,
  388. nullseat_get_cursor_position,
  389. };
  390. //---------------------------------------------------------------------------
  391. ScpSeat::ScpSeat(TSecureShell * ASecureShell)
  392. {
  393. SecureShell = ASecureShell;
  394. vt = &ScpSeatVtable;
  395. }
  396. //---------------------------------------------------------------------------
  397. static std::unique_ptr<TCriticalSection> PuttyRegistrySection(TraceInitPtr(new TCriticalSection()));
  398. enum TPuttyRegistryMode { prmPass, prmRedirect, prmCollect, prmFail };
  399. static TPuttyRegistryMode PuttyRegistryMode = prmRedirect;
  400. typedef std::map<UnicodeString, unsigned long> TPuttyRegistryTypes;
  401. TPuttyRegistryTypes PuttyRegistryTypes;
  402. //---------------------------------------------------------------------------
  403. static long OpenWinSCPKey(HKEY Key, const char * SubKey, HKEY * Result, bool CanCreate)
  404. {
  405. long R;
  406. DebugAssert(Key == HKEY_CURRENT_USER);
  407. DebugUsedParam(Key);
  408. UnicodeString RegKey = SubKey;
  409. int PuttyKeyLen = OriginalPuttyRegistryStorageKey.Length();
  410. DebugAssert(RegKey.SubString(1, PuttyKeyLen) == OriginalPuttyRegistryStorageKey);
  411. RegKey = RegKey.SubString(PuttyKeyLen + 1, RegKey.Length() - PuttyKeyLen);
  412. if (!RegKey.IsEmpty())
  413. {
  414. DebugAssert(RegKey[1] == L'\\');
  415. RegKey.Delete(1, 1);
  416. }
  417. if (RegKey.IsEmpty())
  418. {
  419. *Result = static_cast<HKEY>(NULL);
  420. R = ERROR_SUCCESS;
  421. }
  422. else
  423. {
  424. // we expect this to be called only from retrieve_host_key() or store_host_key()
  425. DebugAssert(RegKey == L"SshHostKeys");
  426. DebugAssert(PuttyStorage != NULL);
  427. DebugAssert(PuttyStorage->AccessMode == (CanCreate ? smReadWrite : smRead));
  428. if (PuttyStorage->OpenSubKey(RegKey, CanCreate))
  429. {
  430. *Result = reinterpret_cast<HKEY>(PuttyStorage);
  431. R = ERROR_SUCCESS;
  432. }
  433. else
  434. {
  435. R = ERROR_CANTOPEN;
  436. }
  437. }
  438. return R;
  439. }
  440. //---------------------------------------------------------------------------
  441. long reg_open_winscp_key(HKEY Key, const char * SubKey, HKEY * Result)
  442. {
  443. if (PuttyRegistryMode == prmPass)
  444. {
  445. return RegOpenKeyA(Key, SubKey, Result);
  446. }
  447. else if (PuttyRegistryMode == prmCollect)
  448. {
  449. *Result = reinterpret_cast<HKEY>(1);
  450. return ERROR_SUCCESS;
  451. }
  452. else if (PuttyRegistryMode == prmFail)
  453. {
  454. return ERROR_CANTOPEN;
  455. }
  456. DebugAssert(PuttyRegistryMode == prmRedirect);
  457. return OpenWinSCPKey(Key, SubKey, Result, false);
  458. }
  459. //---------------------------------------------------------------------------
  460. long reg_create_winscp_key(HKEY Key, const char * SubKey, HKEY * Result)
  461. {
  462. if (PuttyRegistryMode == prmPass)
  463. {
  464. return RegCreateKeyA(Key, SubKey, Result);
  465. }
  466. else if (PuttyRegistryMode == prmCollect)
  467. {
  468. *Result = reinterpret_cast<HKEY>(1);
  469. return ERROR_SUCCESS;
  470. }
  471. DebugAssert(PuttyRegistryMode == prmRedirect);
  472. return OpenWinSCPKey(Key, SubKey, Result, true);
  473. }
  474. //---------------------------------------------------------------------------
  475. long reg_query_winscp_value_ex(HKEY Key, const char * ValueName, unsigned long * Reserved,
  476. unsigned long * Type, unsigned char * Data, unsigned long * DataSize)
  477. {
  478. if (PuttyRegistryMode == prmPass)
  479. {
  480. return RegQueryValueExA(Key, ValueName, Reserved, Type, Data, DataSize);
  481. }
  482. else if (PuttyRegistryMode == prmCollect)
  483. {
  484. return ERROR_READ_FAULT;
  485. }
  486. DebugAssert(PuttyRegistryMode == prmRedirect);
  487. long R;
  488. DebugAssert(Configuration != NULL);
  489. THierarchicalStorage * Storage = reinterpret_cast<THierarchicalStorage *>(Key);
  490. AnsiString Value;
  491. if (Storage == NULL)
  492. {
  493. if (UnicodeString(ValueName) == L"RandSeedFile")
  494. {
  495. Value = AnsiString(Configuration->RandomSeedFileName);
  496. R = ERROR_SUCCESS;
  497. }
  498. else
  499. {
  500. DebugFail();
  501. R = ERROR_READ_FAULT;
  502. }
  503. }
  504. else
  505. {
  506. if (Storage->ValueExists(ValueName))
  507. {
  508. Value = AnsiString(Storage->ReadStringRaw(ValueName, L""));
  509. R = ERROR_SUCCESS;
  510. }
  511. else
  512. {
  513. R = ERROR_READ_FAULT;
  514. }
  515. }
  516. if (R == ERROR_SUCCESS)
  517. {
  518. DebugAssert(Type != NULL);
  519. *Type = REG_SZ;
  520. char * DataStr = reinterpret_cast<char *>(Data);
  521. strncpy(DataStr, Value.c_str(), *DataSize);
  522. DataStr[*DataSize - 1] = '\0';
  523. *DataSize = strlen(DataStr);
  524. }
  525. return R;
  526. }
  527. //---------------------------------------------------------------------------
  528. long reg_set_winscp_value_ex(HKEY Key, const char * ValueName, unsigned long Reserved,
  529. unsigned long Type, const unsigned char * Data, unsigned long DataSize)
  530. {
  531. if (PuttyRegistryMode == prmPass)
  532. {
  533. return RegSetValueExA(Key, ValueName, Reserved, Type, Data, DataSize);
  534. }
  535. else if (PuttyRegistryMode == prmCollect)
  536. {
  537. PuttyRegistryTypes[ValueName] = Type;
  538. return ERROR_SUCCESS;
  539. }
  540. DebugAssert(PuttyRegistryMode == prmRedirect);
  541. DebugAssert(Type == REG_SZ);
  542. DebugUsedParam(Type);
  543. THierarchicalStorage * Storage = reinterpret_cast<THierarchicalStorage *>(Key);
  544. DebugAssert(Storage != NULL);
  545. if (Storage != NULL)
  546. {
  547. UnicodeString Value(reinterpret_cast<const char*>(Data), DataSize - 1);
  548. Storage->WriteStringRaw(ValueName, Value);
  549. }
  550. return ERROR_SUCCESS;
  551. }
  552. //---------------------------------------------------------------------------
  553. long reg_close_winscp_key(HKEY Key)
  554. {
  555. if (PuttyRegistryMode == prmPass)
  556. {
  557. return RegCloseKey(Key);
  558. }
  559. else if (PuttyRegistryMode == prmCollect)
  560. {
  561. return ERROR_SUCCESS;
  562. }
  563. DebugAssert(PuttyRegistryMode == prmRedirect);
  564. return ERROR_SUCCESS;
  565. }
  566. //---------------------------------------------------------------------------
  567. TKeyType KeyType(UnicodeString FileName)
  568. {
  569. DebugAssert(ktUnopenable == SSH_KEYTYPE_UNOPENABLE);
  570. DebugAssert(ktSSHCom == SSH_KEYTYPE_SSHCOM);
  571. DebugAssert(ktSSH2PublicOpenSSH == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH);
  572. UTF8String UtfFileName = UTF8String(FileName);
  573. Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  574. TKeyType Result = (TKeyType)key_type(KeyFile);
  575. filename_free(KeyFile);
  576. return Result;
  577. }
  578. //---------------------------------------------------------------------------
  579. bool IsKeyEncrypted(TKeyType KeyType, const UnicodeString & FileName, UnicodeString & Comment)
  580. {
  581. UTF8String UtfFileName = UTF8String(FileName);
  582. bool Result;
  583. char * CommentStr = NULL;
  584. Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  585. try
  586. {
  587. switch (KeyType)
  588. {
  589. case ktSSH2:
  590. Result = (ppk_encrypted_f(KeyFile, &CommentStr) != 0);
  591. break;
  592. case ktOpenSSHPEM:
  593. case ktOpenSSHNew:
  594. case ktSSHCom:
  595. Result = (import_encrypted(KeyFile, KeyType, &CommentStr) != NULL);
  596. break;
  597. default:
  598. DebugFail();
  599. Result = false;
  600. break;
  601. }
  602. }
  603. __finally
  604. {
  605. filename_free(KeyFile);
  606. }
  607. if (CommentStr != NULL)
  608. {
  609. Comment = UnicodeString(AnsiString(CommentStr));
  610. // ktOpenSSH has no comment, PuTTY defaults to file path
  611. if (Comment == FileName)
  612. {
  613. Comment = ExtractFileName(FileName);
  614. }
  615. sfree(CommentStr);
  616. }
  617. return Result;
  618. }
  619. //---------------------------------------------------------------------------
  620. TPrivateKey * LoadKey(TKeyType KeyType, const UnicodeString & FileName, const UnicodeString & Passphrase)
  621. {
  622. UTF8String UtfFileName = UTF8String(FileName);
  623. Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  624. struct ssh2_userkey * Ssh2Key = NULL;
  625. const char * ErrorStr = NULL;
  626. AnsiString AnsiPassphrase = Passphrase;
  627. try
  628. {
  629. switch (KeyType)
  630. {
  631. case ktSSH2:
  632. Ssh2Key = ppk_load_f(KeyFile, AnsiPassphrase.c_str(), &ErrorStr);
  633. break;
  634. case ktOpenSSHPEM:
  635. case ktOpenSSHNew:
  636. case ktSSHCom:
  637. Ssh2Key = import_ssh2(KeyFile, KeyType, AnsiPassphrase.c_str(), &ErrorStr);
  638. break;
  639. default:
  640. DebugFail();
  641. break;
  642. }
  643. }
  644. __finally
  645. {
  646. Shred(AnsiPassphrase);
  647. filename_free(KeyFile);
  648. }
  649. if (Ssh2Key == NULL)
  650. {
  651. UnicodeString Error = AnsiString(ErrorStr);
  652. // While theoretically we may get "unable to open key file" and
  653. // so we should check system error code,
  654. // we actully never get here unless we call KeyType previously
  655. // and handle ktUnopenable accordingly.
  656. throw Exception(Error);
  657. }
  658. else if (Ssh2Key == SSH2_WRONG_PASSPHRASE)
  659. {
  660. throw Exception(LoadStr(AUTH_TRANSL_WRONG_PASSPHRASE));
  661. }
  662. return reinterpret_cast<TPrivateKey *>(Ssh2Key);
  663. }
  664. //---------------------------------------------------------------------------
  665. void ChangeKeyComment(TPrivateKey * PrivateKey, const UnicodeString & Comment)
  666. {
  667. AnsiString AnsiComment(Comment);
  668. struct ssh2_userkey * Ssh2Key = reinterpret_cast<struct ssh2_userkey *>(PrivateKey);
  669. sfree(Ssh2Key->comment);
  670. Ssh2Key->comment = dupstr(AnsiComment.c_str());
  671. }
  672. //---------------------------------------------------------------------------
  673. void SaveKey(TKeyType KeyType, const UnicodeString & FileName,
  674. const UnicodeString & Passphrase, TPrivateKey * PrivateKey)
  675. {
  676. UTF8String UtfFileName = UTF8String(FileName);
  677. Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  678. try
  679. {
  680. struct ssh2_userkey * Ssh2Key = reinterpret_cast<struct ssh2_userkey *>(PrivateKey);
  681. AnsiString AnsiPassphrase = Passphrase;
  682. char * PassphrasePtr = (AnsiPassphrase.IsEmpty() ? NULL : AnsiPassphrase.c_str());
  683. switch (KeyType)
  684. {
  685. case ktSSH2:
  686. {
  687. ppk_save_parameters Params = ppk_save_default_parameters;
  688. if (Configuration->KeyVersion != 0)
  689. {
  690. Params.fmt_version = Configuration->KeyVersion;
  691. }
  692. if (!ppk_save_f(KeyFile, Ssh2Key, PassphrasePtr, &Params))
  693. {
  694. int Error = errno;
  695. throw EOSExtException(FMTLOAD(KEY_SAVE_ERROR, (FileName)), Error);
  696. }
  697. }
  698. break;
  699. default:
  700. DebugFail();
  701. break;
  702. }
  703. }
  704. __finally
  705. {
  706. filename_free(KeyFile);
  707. }
  708. }
  709. //---------------------------------------------------------------------------
  710. void FreeKey(TPrivateKey * PrivateKey)
  711. {
  712. struct ssh2_userkey * Ssh2Key = reinterpret_cast<struct ssh2_userkey *>(PrivateKey);
  713. ssh_key_free(Ssh2Key->key);
  714. sfree(Ssh2Key->comment);
  715. sfree(Ssh2Key);
  716. }
  717. //---------------------------------------------------------------------------
  718. RawByteString LoadPublicKey(const UnicodeString & FileName, UnicodeString & Algorithm, UnicodeString & Comment)
  719. {
  720. RawByteString Result;
  721. UTF8String UtfFileName = UTF8String(FileName);
  722. Filename * KeyFile = filename_from_str(UtfFileName.c_str());
  723. try
  724. {
  725. char * AlgorithmStr = NULL;
  726. char * CommentStr = NULL;
  727. const char * ErrorStr = NULL;
  728. strbuf * PublicKeyBuf = strbuf_new();
  729. if (!ppk_loadpub_f(KeyFile, &AlgorithmStr, BinarySink_UPCAST(PublicKeyBuf), &CommentStr, &ErrorStr))
  730. {
  731. UnicodeString Error = UnicodeString(AnsiString(ErrorStr));
  732. throw Exception(Error);
  733. }
  734. Algorithm = UnicodeString(AnsiString(AlgorithmStr));
  735. sfree(AlgorithmStr);
  736. Comment = UnicodeString(AnsiString(CommentStr));
  737. sfree(CommentStr);
  738. Result = RawByteString(reinterpret_cast<char *>(PublicKeyBuf->s), PublicKeyBuf->len);
  739. strbuf_free(PublicKeyBuf);
  740. }
  741. __finally
  742. {
  743. filename_free(KeyFile);
  744. }
  745. return Result;
  746. }
  747. //---------------------------------------------------------------------------
  748. UnicodeString GetPublicKeyLine(const UnicodeString & FileName, UnicodeString & Comment)
  749. {
  750. UnicodeString Algorithm;
  751. RawByteString PublicKey = LoadPublicKey(FileName, Algorithm, Comment);
  752. UnicodeString PublicKeyBase64 = EncodeBase64(PublicKey.c_str(), PublicKey.Length());
  753. PublicKeyBase64 = ReplaceStr(PublicKeyBase64, L"\r", L"");
  754. PublicKeyBase64 = ReplaceStr(PublicKeyBase64, L"\n", L"");
  755. UnicodeString Result = FORMAT(L"%s %s %s", (Algorithm, PublicKeyBase64, Comment));
  756. return Result;
  757. }
  758. //---------------------------------------------------------------------------
  759. bool __fastcall HasGSSAPI(UnicodeString CustomPath)
  760. {
  761. static int has = -1;
  762. if (has < 0)
  763. {
  764. Conf * conf = conf_new();
  765. ssh_gss_liblist * List = NULL;
  766. try
  767. {
  768. Filename * filename = filename_from_str(UTF8String(CustomPath).c_str());
  769. conf_set_filename(conf, CONF_ssh_gss_custom, filename);
  770. filename_free(filename);
  771. List = ssh_gss_setup(conf, NULL);
  772. for (int Index = 0; (has <= 0) && (Index < List->nlibraries); Index++)
  773. {
  774. ssh_gss_library * library = &List->libraries[Index];
  775. Ssh_gss_ctx ctx;
  776. memset(&ctx, 0, sizeof(ctx));
  777. has =
  778. ((library->acquire_cred(library, &ctx, NULL) == SSH_GSS_OK) &&
  779. (library->release_cred(library, &ctx) == SSH_GSS_OK)) ? 1 : 0;
  780. }
  781. }
  782. __finally
  783. {
  784. ssh_gss_cleanup(List);
  785. conf_free(conf);
  786. }
  787. if (has < 0)
  788. {
  789. has = 0;
  790. }
  791. }
  792. return (has > 0);
  793. }
  794. //---------------------------------------------------------------------------
  795. static void __fastcall DoNormalizeFingerprint(UnicodeString & Fingerprint, UnicodeString & KeyName, UnicodeString & KeyType)
  796. {
  797. const int MaxCount = 10;
  798. const ssh_keyalg * SignKeys[MaxCount];
  799. int Count = LENOF(SignKeys);
  800. // We may use find_pubkey_alg, but it gets complicated with normalized fingerprint
  801. // as the names have different number of dashes
  802. get_hostkey_algs(&Count, SignKeys);
  803. for (int Index = 0; Index < Count; Index++)
  804. {
  805. const ssh_keyalg * SignKey = SignKeys[Index];
  806. UnicodeString Name = UnicodeString(SignKey->ssh_id);
  807. if (StartsStr(Name + L" ", Fingerprint))
  808. {
  809. UnicodeString Rest = Fingerprint.SubString(Name.Length() + 2, Fingerprint.Length() - Name.Length() - 1);
  810. int Space = Rest.Pos(L" ");
  811. // If not a number, it's an invalid input,
  812. // either something completelly wrong, or it can be OpenSSH base64 public key,
  813. // that got here from TPasteKeyHandler::Paste
  814. if (IsNumber(Rest.SubString(1, Space - 1)))
  815. {
  816. KeyName = Name;
  817. Fingerprint = Rest.SubString(Space + 1, Fingerprint.Length() - Space);
  818. Fingerprint = Base64ToUrlSafe(Fingerprint);
  819. Fingerprint = MD5ToUrlSafe(Fingerprint);
  820. KeyType = UnicodeString(SignKey->cache_id);
  821. return;
  822. }
  823. }
  824. else if (StartsStr(Name + NormalizedFingerprintSeparator, Fingerprint))
  825. {
  826. KeyType = UnicodeString(SignKey->cache_id);
  827. KeyName = Name;
  828. Fingerprint.Delete(1, Name.Length() + 1);
  829. return;
  830. }
  831. }
  832. }
  833. //---------------------------------------------------------------------------
  834. void __fastcall NormalizeFingerprint(UnicodeString & Fingerprint, UnicodeString & KeyName)
  835. {
  836. UnicodeString KeyType;
  837. DoNormalizeFingerprint(Fingerprint, KeyName, KeyType);
  838. }
  839. //---------------------------------------------------------------------------
  840. UnicodeString __fastcall KeyTypeFromFingerprint(UnicodeString Fingerprint)
  841. {
  842. UnicodeString KeyType;
  843. UnicodeString KeyName; // unused
  844. DoNormalizeFingerprint(Fingerprint, KeyName, KeyType);
  845. return KeyType;
  846. }
  847. //---------------------------------------------------------------------------
  848. UnicodeString __fastcall GetPuTTYVersion()
  849. {
  850. // "Release 0.64"
  851. // "Pre-release 0.65:2015-07-20.95501a1"
  852. // "Development snapshot 2015-12-22.51465fa"
  853. UnicodeString Result = get_putty_version();
  854. // Skip "Release", "Pre-release", "Development snapshot"
  855. int P = Result.LastDelimiter(L" ");
  856. Result.Delete(1, P);
  857. return Result;
  858. }
  859. //---------------------------------------------------------------------------
  860. UnicodeString __fastcall Sha256(const char * Data, size_t Size)
  861. {
  862. unsigned char Digest[32];
  863. hash_simple(&ssh_sha256, make_ptrlen(Data, Size), Digest);
  864. UnicodeString Result(BytesToHex(Digest, LENOF(Digest)));
  865. return Result;
  866. }
  867. //---------------------------------------------------------------------------
  868. void __fastcall DllHijackingProtection()
  869. {
  870. dll_hijacking_protection();
  871. }
  872. //---------------------------------------------------------------------------
  873. UnicodeString __fastcall ParseOpenSshPubLine(const UnicodeString & Line, const struct ssh_keyalg *& Algorithm)
  874. {
  875. UTF8String UtfLine = UTF8String(Line);
  876. char * AlgorithmName = NULL;
  877. char * CommentPtr = NULL;
  878. const char * ErrorStr = NULL;
  879. strbuf * PubBlobBuf = strbuf_new();
  880. BinarySource Source[1];
  881. BinarySource_BARE_INIT(Source, UtfLine.c_str(), UtfLine.Length());
  882. UnicodeString Result;
  883. if (!openssh_loadpub(Source, &AlgorithmName, BinarySink_UPCAST(PubBlobBuf), &CommentPtr, &ErrorStr))
  884. {
  885. throw Exception(UnicodeString(ErrorStr));
  886. }
  887. else
  888. {
  889. try
  890. {
  891. Algorithm = find_pubkey_alg(AlgorithmName);
  892. if (Algorithm == NULL)
  893. {
  894. throw Exception(FORMAT(L"Unknown public key algorithm \"%s\".", (AlgorithmName)));
  895. }
  896. ptrlen PtrLen = { PubBlobBuf->s, PubBlobBuf->len };
  897. ssh_key * Key = Algorithm->new_pub(Algorithm, PtrLen);
  898. if (Key == NULL)
  899. {
  900. throw Exception(L"Invalid public key.");
  901. }
  902. char * FmtKey = Algorithm->cache_str(Key);
  903. Result = UnicodeString(FmtKey);
  904. sfree(FmtKey);
  905. Algorithm->freekey(Key);
  906. }
  907. __finally
  908. {
  909. strbuf_free(PubBlobBuf);
  910. sfree(AlgorithmName);
  911. sfree(CommentPtr);
  912. }
  913. }
  914. return Result;
  915. }
  916. //---------------------------------------------------------------------------
  917. UnicodeString __fastcall GetSsh1KeyType()
  918. {
  919. return UnicodeString(ssh_rsa.cache_id);
  920. }
  921. //---------------------------------------------------------------------------
  922. UnicodeString __fastcall GetKeyTypeHuman(const UnicodeString & KeyType)
  923. {
  924. UnicodeString Result;
  925. if (KeyType == ssh_dss.cache_id)
  926. {
  927. Result = L"DSA";
  928. }
  929. else if ((KeyType == ssh_rsa.cache_id) ||
  930. (KeyType == L"rsa")) // SSH1
  931. {
  932. Result = L"RSA";
  933. }
  934. else if (KeyType == ssh_ecdsa_ed25519.cache_id)
  935. {
  936. Result = L"Ed25519";
  937. }
  938. else if (KeyType == ssh_ecdsa_nistp256.cache_id)
  939. {
  940. Result = L"ECDSA/nistp256";
  941. }
  942. else if (KeyType == ssh_ecdsa_nistp384.cache_id)
  943. {
  944. Result = L"ECDSA/nistp384";
  945. }
  946. else if (KeyType == ssh_ecdsa_nistp521.cache_id)
  947. {
  948. Result = L"ECDSA/nistp521";
  949. }
  950. else
  951. {
  952. DebugFail();
  953. Result = KeyType;
  954. }
  955. return Result;
  956. }
  957. //---------------------------------------------------------------------------
  958. bool IsOpenSSH(const UnicodeString & SshImplementation)
  959. {
  960. return
  961. // e.g. "OpenSSH_5.3"
  962. (SshImplementation.Pos(L"OpenSSH") == 1) ||
  963. // Sun SSH is based on OpenSSH (suffers the same bugs)
  964. (SshImplementation.Pos(L"Sun_SSH") == 1);
  965. }
  966. //---------------------------------------------------------------------------
  967. TStrings * SshCipherList()
  968. {
  969. std::unique_ptr<TStrings> Result(new TStringList());
  970. // Same order as DefaultCipherList
  971. const ssh2_ciphers * Ciphers[] = { &ssh2_aes, &ssh2_ccp, &ssh2_blowfish, &ssh2_3des, &ssh2_arcfour, &ssh2_des };
  972. for (unsigned int Index = 0; Index < LENOF(Ciphers); Index++)
  973. {
  974. for (int Index2 = 0; Index2 < Ciphers[Index]->nciphers; Index2++)
  975. {
  976. UnicodeString Name = UnicodeString(Ciphers[Index]->list[Index2]->ssh2_id);
  977. Result->Add(Name);
  978. }
  979. }
  980. return Result.release();
  981. }
  982. //---------------------------------------------------------------------------
  983. TStrings * SshKexList()
  984. {
  985. std::unique_ptr<TStrings> Result(new TStringList());
  986. // Same order as DefaultKexList
  987. const ssh_kexes * Kexes[] = { &ssh_ecdh_kex, &ssh_diffiehellman_gex, &ssh_diffiehellman_group14, &ssh_rsa_kex, &ssh_diffiehellman_group1 };
  988. for (unsigned int Index = 0; Index < LENOF(Kexes); Index++)
  989. {
  990. for (int Index2 = 0; Index2 < Kexes[Index]->nkexes; Index2++)
  991. {
  992. UnicodeString Name = UnicodeString(Kexes[Index]->list[Index2]->name);
  993. Result->Add(Name);
  994. }
  995. }
  996. return Result.release();
  997. }
  998. //---------------------------------------------------------------------------
  999. TStrings * SshHostKeyList()
  1000. {
  1001. std::unique_ptr<TStrings> Result(new TStringList());
  1002. const int MaxCount = 10;
  1003. const ssh_keyalg * SignKeys[MaxCount];
  1004. int Count = LENOF(SignKeys);
  1005. get_hostkey_algs(&Count, SignKeys);
  1006. for (int Index = 0; Index < Count; Index++)
  1007. {
  1008. const ssh_keyalg * SignKey = SignKeys[Index];
  1009. UnicodeString Name = UnicodeString(SignKey->ssh_id);
  1010. Result->Add(Name);
  1011. }
  1012. return Result.release();
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. TStrings * SshMacList()
  1016. {
  1017. std::unique_ptr<TStrings> Result(new TStringList());
  1018. const struct ssh2_macalg ** Macs = NULL;
  1019. int Count = 0;
  1020. get_macs(&Count, &Macs);
  1021. for (int Index = 0; Index < Count; Index++)
  1022. {
  1023. UnicodeString Name = UnicodeString(Macs[Index]->name);
  1024. UnicodeString S = Name;
  1025. UnicodeString ETMName = UnicodeString(Macs[Index]->etm_name);
  1026. if (!ETMName.IsEmpty())
  1027. {
  1028. S = FORMAT(L"%s (%s)", (S, ETMName));
  1029. }
  1030. Result->Add(S);
  1031. }
  1032. return Result.release();
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. UnicodeString GetCipherName(const ssh_cipher * Cipher)
  1036. {
  1037. return UnicodeString(UTF8String(Cipher->vt->text_name));
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. UnicodeString GetCompressorName(const ssh_compressor * Compressor)
  1041. {
  1042. UnicodeString Result;
  1043. if (Compressor != NULL)
  1044. {
  1045. Result = UnicodeString(UTF8String(Compressor->vt->name));
  1046. }
  1047. return Result;
  1048. }
  1049. //---------------------------------------------------------------------------
  1050. UnicodeString GetDecompressorName(const ssh_decompressor * Decompressor)
  1051. {
  1052. UnicodeString Result;
  1053. if (Decompressor != NULL)
  1054. {
  1055. Result = UnicodeString(UTF8String(Decompressor->vt->name));
  1056. }
  1057. return Result;
  1058. }
  1059. //---------------------------------------------------------------------------
  1060. void WritePuttySettings(THierarchicalStorage * Storage, const UnicodeString & ASettings)
  1061. {
  1062. if (PuttyRegistryTypes.empty())
  1063. {
  1064. TGuard Guard(PuttyRegistrySection.get());
  1065. TValueRestorer<TPuttyRegistryMode> PuttyRegistryModeRestorer(PuttyRegistryMode);
  1066. PuttyRegistryMode = prmCollect;
  1067. Conf * conf = conf_new();
  1068. try
  1069. {
  1070. do_defaults(NULL, conf);
  1071. save_settings(NULL, conf);
  1072. }
  1073. __finally
  1074. {
  1075. conf_free(conf);
  1076. }
  1077. }
  1078. std::unique_ptr<TStrings> Settings(new TStringList());
  1079. UnicodeString Buf = ASettings;
  1080. UnicodeString Setting;
  1081. while (CutToken(Buf, Setting))
  1082. {
  1083. Settings->Add(Setting);
  1084. }
  1085. for (int Index = 0; Index < Settings->Count; Index++)
  1086. {
  1087. UnicodeString Name = Settings->Names[Index];
  1088. TPuttyRegistryTypes::const_iterator IType = PuttyRegistryTypes.find(Name);
  1089. if (IType != PuttyRegistryTypes.end())
  1090. {
  1091. UnicodeString Value = Settings->ValueFromIndex[Index];
  1092. int I;
  1093. if (IType->second == REG_SZ)
  1094. {
  1095. Storage->WriteStringRaw(Name, Value);
  1096. }
  1097. else if (DebugAlwaysTrue(IType->second == REG_DWORD) &&
  1098. TryStrToInt(Value, I))
  1099. {
  1100. Storage->WriteInteger(Name, I);
  1101. }
  1102. }
  1103. }
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void PuttyDefaults(Conf * conf)
  1107. {
  1108. TGuard Guard(PuttyRegistrySection.get());
  1109. TValueRestorer<TPuttyRegistryMode> PuttyRegistryModeRestorer(PuttyRegistryMode);
  1110. PuttyRegistryMode = prmFail;
  1111. do_defaults(NULL, conf);
  1112. }
  1113. //---------------------------------------------------------------------------
  1114. void SavePuttyDefaults(const UnicodeString & Name)
  1115. {
  1116. TGuard Guard(PuttyRegistrySection.get());
  1117. TValueRestorer<TPuttyRegistryMode> PuttyRegistryModeRestorer(PuttyRegistryMode);
  1118. PuttyRegistryMode = prmPass;
  1119. Conf * conf = conf_new();
  1120. try
  1121. {
  1122. PuttyDefaults(conf);
  1123. AnsiString PuttyName = PuttyStr(Name);
  1124. save_settings(PuttyName.c_str(), conf);
  1125. }
  1126. __finally
  1127. {
  1128. conf_free(conf);
  1129. }
  1130. }
  1131. //---------------------------------------------------------------------------
  1132. //---------------------------------------------------------------------------