SessionData.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "SessionData.h"
  5. #include "Common.h"
  6. #include "Exceptions.h"
  7. #include "FileBuffer.h"
  8. #include "CoreMain.h"
  9. #include "Security.h"
  10. #include "TextsCore.h"
  11. #include "PuttyIntf.h"
  12. #include "RemoteFiles.h"
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. //---------------------------------------------------------------------------
  16. enum TProxyType { pxNone, pxHTTP, pxSocks, pxTelnet }; // 0.53b and older
  17. const char * DefaultSessionName = "Default Settings";
  18. const char CipherNames[CIPHER_COUNT][10] = {"WARN", "3des", "blowfish", "aes", "des", "arcfour"};
  19. const char KexNames[KEX_COUNT][20] = {"WARN", "dh-group1-sha1", "dh-group14-sha1", "dh-gex-sha1", "rsa" };
  20. const char ProtocolNames[PROTOCOL_COUNT][10] = { "raw", "telnet", "rlogin", "ssh" };
  21. const char SshProtList[][10] = {"1 only", "1", "2", "2 only"};
  22. const char ProxyMethodList[][10] = {"none", "SOCKS4", "SOCKS5", "HTTP", "Telnet", "Cmd" };
  23. const TCipher DefaultCipherList[CIPHER_COUNT] =
  24. { cipAES, cipBlowfish, cip3DES, cipWarn, cipArcfour, cipDES };
  25. const TKex DefaultKexList[KEX_COUNT] =
  26. { kexDHGEx, kexDHGroup14, kexDHGroup1, kexRSA, kexWarn };
  27. const char FSProtocolNames[FSPROTOCOL_COUNT][11] = { "SCP", "SFTP (SCP)", "SFTP", "", "", "FTP" };
  28. const int SshPortNumber = 22;
  29. const int FtpPortNumber = 21;
  30. const int FtpsImplicitPortNumber = 990;
  31. //---------------------------------------------------------------------
  32. TDateTime __fastcall SecToDateTime(int Sec)
  33. {
  34. return TDateTime((unsigned short)(Sec/60/60),
  35. (unsigned short)(Sec/60%60), (unsigned short)(Sec%60), 0);
  36. }
  37. //--- TSessionData ----------------------------------------------------
  38. __fastcall TSessionData::TSessionData(AnsiString aName):
  39. TNamedObject(aName)
  40. {
  41. Default();
  42. FModified = true;
  43. }
  44. //---------------------------------------------------------------------
  45. void __fastcall TSessionData::Default()
  46. {
  47. HostName = "";
  48. PortNumber = SshPortNumber;
  49. UserName = "";
  50. Password = "";
  51. Passwordless = false;
  52. PingInterval = 30;
  53. // when changing default, update load/save logic
  54. PingType = ptOff;
  55. Timeout = 15;
  56. TryAgent = true;
  57. AgentFwd = false;
  58. AuthTIS = false;
  59. AuthKI = true;
  60. AuthKIPassword = true;
  61. AuthGSSAPI = false;
  62. GSSAPIFwdTGT = false;
  63. GSSAPIServerRealm = "";
  64. ChangeUsername = false;
  65. Compression = false;
  66. SshProt = ssh2;
  67. Ssh2DES = false;
  68. SshNoUserAuth = false;
  69. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  70. {
  71. Cipher[Index] = DefaultCipherList[Index];
  72. }
  73. for (int Index = 0; Index < KEX_COUNT; Index++)
  74. {
  75. Kex[Index] = DefaultKexList[Index];
  76. }
  77. PublicKeyFile = "";
  78. FProtocol = ptSSH;
  79. TcpNoDelay = true;
  80. HostKey = "";
  81. ProxyMethod = pmNone;
  82. ProxyHost = "proxy";
  83. ProxyPort = 80;
  84. ProxyUsername = "";
  85. ProxyPassword = "";
  86. ProxyTelnetCommand = "connect %host %port\\n";
  87. ProxyLocalCommand = "";
  88. ProxyDNS = asAuto;
  89. ProxyLocalhost = false;
  90. for (int Index = 0; Index < LENOF(FBugs); Index++)
  91. {
  92. Bug[(TSshBug)Index] = asAuto;
  93. }
  94. Special = false;
  95. FSProtocol = fsSFTP;
  96. AddressFamily = afAuto;
  97. RekeyData = "1G";
  98. RekeyTime = 60;
  99. // FS common
  100. LocalDirectory = "";
  101. RemoteDirectory = "";
  102. UpdateDirectories = false;
  103. CacheDirectories = true;
  104. CacheDirectoryChanges = true;
  105. PreserveDirectoryChanges = true;
  106. LockInHome = false;
  107. ResolveSymlinks = true;
  108. DSTMode = dstmUnix;
  109. DeleteToRecycleBin = false;
  110. OverwrittenToRecycleBin = false;
  111. RecycleBinPath = "/tmp";
  112. Color = 0;
  113. PostLoginCommands = "";
  114. // SCP
  115. ReturnVar = "";
  116. LookupUserGroups = true;
  117. EOLType = eolLF;
  118. Shell = ""; //default shell
  119. ReturnVar = "";
  120. ClearAliases = true;
  121. UnsetNationalVars = true;
  122. ListingCommand = "ls -la";
  123. IgnoreLsWarnings = true;
  124. Scp1Compatibility = false;
  125. TimeDifference = 0;
  126. SCPLsFullTime = asAuto;
  127. Utf = asAuto;
  128. FtpListAll = asAuto;
  129. // SFTP
  130. SftpServer = "";
  131. SFTPDownloadQueue = 4;
  132. SFTPUploadQueue = 4;
  133. SFTPListingQueue = 2;
  134. SFTPMaxVersion = 5;
  135. SFTPMaxPacketSize = 0;
  136. for (int Index = 0; Index < LENOF(FSFTPBugs); Index++)
  137. {
  138. SFTPBug[(TSftpBug)Index] = asAuto;
  139. }
  140. Tunnel = false;
  141. TunnelHostName = "";
  142. TunnelPortNumber = SshPortNumber;
  143. TunnelUserName = "";
  144. TunnelPassword = "";
  145. TunnelPublicKeyFile = "";
  146. TunnelLocalPortNumber = 0;
  147. TunnelPortFwd = "";
  148. // FTP
  149. FtpPasvMode = false;
  150. FtpAccount = "";
  151. FtpPingInterval = 30;
  152. FtpPingType = ptDummyCommand;
  153. Ftps = ftpsNone;
  154. CustomParam1 = "";
  155. CustomParam2 = "";
  156. Selected = false;
  157. FModified = false;
  158. // add also to TSessionLog::AddStartupInfo()
  159. }
  160. //---------------------------------------------------------------------
  161. void __fastcall TSessionData::NonPersistant()
  162. {
  163. UpdateDirectories = false;
  164. PreserveDirectoryChanges = false;
  165. }
  166. //---------------------------------------------------------------------
  167. void __fastcall TSessionData::Assign(TPersistent * Source)
  168. {
  169. if (Source && Source->InheritsFrom(__classid(TSessionData)))
  170. {
  171. #define DUPL(P) P = ((TSessionData *)Source)->P
  172. DUPL(Name);
  173. DUPL(HostName);
  174. DUPL(PortNumber);
  175. DUPL(UserName);
  176. DUPL(Password);
  177. DUPL(Passwordless);
  178. DUPL(PingInterval);
  179. DUPL(PingType);
  180. DUPL(Timeout);
  181. DUPL(TryAgent);
  182. DUPL(AgentFwd);
  183. DUPL(AuthTIS);
  184. DUPL(ChangeUsername);
  185. DUPL(Compression);
  186. DUPL(SshProt);
  187. DUPL(Ssh2DES);
  188. DUPL(SshNoUserAuth);
  189. DUPL(CipherList);
  190. DUPL(KexList);
  191. DUPL(PublicKeyFile);
  192. DUPL(AddressFamily);
  193. DUPL(RekeyData);
  194. DUPL(RekeyTime);
  195. DUPL(HostKey);
  196. DUPL(FSProtocol);
  197. DUPL(LocalDirectory);
  198. DUPL(RemoteDirectory);
  199. DUPL(UpdateDirectories);
  200. DUPL(CacheDirectories);
  201. DUPL(CacheDirectoryChanges);
  202. DUPL(PreserveDirectoryChanges);
  203. DUPL(ResolveSymlinks);
  204. DUPL(DSTMode);
  205. DUPL(LockInHome);
  206. DUPL(Special);
  207. DUPL(Selected);
  208. DUPL(ReturnVar);
  209. DUPL(LookupUserGroups);
  210. DUPL(EOLType);
  211. DUPL(Shell);
  212. DUPL(ClearAliases);
  213. DUPL(Scp1Compatibility);
  214. DUPL(UnsetNationalVars);
  215. DUPL(ListingCommand);
  216. DUPL(IgnoreLsWarnings);
  217. DUPL(SCPLsFullTime);
  218. DUPL(FtpListAll);
  219. DUPL(TimeDifference);
  220. // new in 53b
  221. DUPL(TcpNoDelay);
  222. DUPL(AuthKI);
  223. DUPL(AuthKIPassword);
  224. DUPL(AuthGSSAPI);
  225. DUPL(GSSAPIFwdTGT);
  226. DUPL(GSSAPIServerRealm);
  227. DUPL(DeleteToRecycleBin);
  228. DUPL(OverwrittenToRecycleBin);
  229. DUPL(RecycleBinPath);
  230. DUPL(Utf);
  231. DUPL(PostLoginCommands);
  232. DUPL(ProxyMethod);
  233. DUPL(ProxyHost);
  234. DUPL(ProxyPort);
  235. DUPL(ProxyUsername);
  236. DUPL(ProxyPassword);
  237. DUPL(ProxyTelnetCommand);
  238. DUPL(ProxyLocalCommand);
  239. DUPL(ProxyDNS);
  240. DUPL(ProxyLocalhost);
  241. for (int Index = 0; Index < LENOF(FBugs); Index++)
  242. {
  243. DUPL(Bug[(TSshBug)Index]);
  244. }
  245. // SFTP
  246. DUPL(SftpServer);
  247. DUPL(SFTPDownloadQueue);
  248. DUPL(SFTPUploadQueue);
  249. DUPL(SFTPListingQueue);
  250. DUPL(SFTPMaxVersion);
  251. DUPL(SFTPMaxPacketSize);
  252. for (int Index = 0; Index < LENOF(FSFTPBugs); Index++)
  253. {
  254. DUPL(SFTPBug[(TSftpBug)Index]);
  255. }
  256. DUPL(Color);
  257. DUPL(Tunnel);
  258. DUPL(TunnelHostName);
  259. DUPL(TunnelPortNumber);
  260. DUPL(TunnelUserName);
  261. DUPL(TunnelPassword);
  262. DUPL(TunnelPublicKeyFile);
  263. DUPL(TunnelLocalPortNumber);
  264. DUPL(TunnelPortFwd);
  265. DUPL(FtpPasvMode);
  266. DUPL(FtpAccount);
  267. DUPL(FtpPingInterval);
  268. DUPL(FtpPingType);
  269. DUPL(Ftps);
  270. DUPL(CustomParam1);
  271. DUPL(CustomParam2);
  272. #undef DUPL
  273. FModified = ((TSessionData *)Source)->Modified;
  274. }
  275. else
  276. {
  277. TNamedObject::Assign(Source);
  278. }
  279. }
  280. //---------------------------------------------------------------------
  281. void __fastcall TSessionData::Load(THierarchicalStorage * Storage)
  282. {
  283. bool RewritePassword = false;
  284. if (Storage->OpenSubKey(InternalStorageKey, False))
  285. {
  286. PortNumber = Storage->ReadInteger("PortNumber", PortNumber);
  287. UserName = Storage->ReadString("UserName", UserName);
  288. // must be loaded after UserName, because HostName may be in format user@host
  289. HostName = Storage->ReadString("HostName", HostName);
  290. if (!Configuration->DisablePasswordStoring)
  291. {
  292. if (Storage->ValueExists("PasswordPlain"))
  293. {
  294. Password = Storage->ReadString("PasswordPlain", Password);
  295. RewritePassword = true;
  296. }
  297. else
  298. {
  299. FPassword = Storage->ReadString("Password", FPassword);
  300. }
  301. }
  302. Passwordless = Storage->ReadBool("Passwordless", Passwordless);
  303. // Putty uses PingIntervalSecs
  304. int PingIntervalSecs = Storage->ReadInteger("PingIntervalSecs", -1);
  305. if (PingIntervalSecs < 0)
  306. {
  307. PingIntervalSecs = Storage->ReadInteger("PingIntervalSec", PingInterval%60);
  308. }
  309. PingInterval =
  310. Storage->ReadInteger("PingInterval", PingInterval/60)*60 +
  311. PingIntervalSecs;
  312. if (PingInterval == 0)
  313. {
  314. PingInterval = 30;
  315. }
  316. // PingType has not existed before 3.5, where PingInterval > 0 meant today's ptNullPacket
  317. // Since 3.5, until 4.1 PingType was stored unconditionally.
  318. // Since 4.1 PingType is stored when it is not ptOff (default) or
  319. // when PingInterval is stored.
  320. if (!Storage->ValueExists("PingType"))
  321. {
  322. if (Storage->ReadInteger("PingInterval", 0) > 0)
  323. {
  324. PingType = ptNullPacket;
  325. }
  326. }
  327. else
  328. {
  329. PingType = static_cast<TPingType>(Storage->ReadInteger("PingType", ptOff));
  330. }
  331. Timeout = Storage->ReadInteger("Timeout", Timeout);
  332. TryAgent = Storage->ReadBool("TryAgent", TryAgent);
  333. AgentFwd = Storage->ReadBool("AgentFwd", AgentFwd);
  334. AuthTIS = Storage->ReadBool("AuthTIS", AuthTIS);
  335. AuthKI = Storage->ReadBool("AuthKI", AuthKI);
  336. AuthKIPassword = Storage->ReadBool("AuthKIPassword", AuthKIPassword);
  337. // Continue to use setting keys of previous kerberos implementation (vaclav tomec),
  338. // but fallback to keys of other implementations (official putty and vintela quest putty),
  339. // to allow imports from all putty versions.
  340. // Both vaclav tomec and official putty use AuthGSSAPI
  341. AuthGSSAPI = Storage->ReadBool("AuthGSSAPI", Storage->ReadBool("AuthSSPI", AuthGSSAPI));
  342. GSSAPIFwdTGT = Storage->ReadBool("GSSAPIFwdTGT", Storage->ReadBool("GssapiFwd", Storage->ReadBool("SSPIFwdTGT", GSSAPIFwdTGT)));
  343. GSSAPIServerRealm = Storage->ReadString("GSSAPIServerRealm", Storage->ReadString("KerbPrincipal", GSSAPIServerRealm));
  344. ChangeUsername = Storage->ReadBool("ChangeUsername", ChangeUsername);
  345. Compression = Storage->ReadBool("Compression", Compression);
  346. SshProt = (TSshProt)Storage->ReadInteger("SshProt", SshProt);
  347. Ssh2DES = Storage->ReadBool("Ssh2DES", Ssh2DES);
  348. SshNoUserAuth = Storage->ReadBool("SshNoUserAuth", SshNoUserAuth);
  349. CipherList = Storage->ReadString("Cipher", CipherList);
  350. KexList = Storage->ReadString("KEX", KexList);
  351. PublicKeyFile = Storage->ReadString("PublicKeyFile", PublicKeyFile);
  352. AddressFamily = static_cast<TAddressFamily>
  353. (Storage->ReadInteger("AddressFamily", AddressFamily));
  354. RekeyData = Storage->ReadString("RekeyBytes", RekeyData);
  355. RekeyTime = Storage->ReadInteger("RekeyTime", RekeyTime);
  356. FSProtocol = (TFSProtocol)Storage->ReadInteger("FSProtocol", FSProtocol);
  357. LocalDirectory = Storage->ReadString("LocalDirectory", LocalDirectory);
  358. RemoteDirectory = Storage->ReadString("RemoteDirectory", RemoteDirectory);
  359. UpdateDirectories = Storage->ReadBool("UpdateDirectories", UpdateDirectories);
  360. CacheDirectories = Storage->ReadBool("CacheDirectories", CacheDirectories);
  361. CacheDirectoryChanges = Storage->ReadBool("CacheDirectoryChanges", CacheDirectoryChanges);
  362. PreserveDirectoryChanges = Storage->ReadBool("PreserveDirectoryChanges", PreserveDirectoryChanges);
  363. ResolveSymlinks = Storage->ReadBool("ResolveSymlinks", ResolveSymlinks);
  364. DSTMode = (TDSTMode)Storage->ReadInteger("ConsiderDST", DSTMode);
  365. LockInHome = Storage->ReadBool("LockInHome", LockInHome);
  366. Special = Storage->ReadBool("Special", Special);
  367. Shell = Storage->ReadString("Shell", Shell);
  368. ClearAliases = Storage->ReadBool("ClearAliases", ClearAliases);
  369. UnsetNationalVars = Storage->ReadBool("UnsetNationalVars", UnsetNationalVars);
  370. ListingCommand = Storage->ReadString("ListingCommand",
  371. Storage->ReadBool("AliasGroupList", false) ? AnsiString("ls -gla") : ListingCommand);
  372. IgnoreLsWarnings = Storage->ReadBool("IgnoreLsWarnings", IgnoreLsWarnings);
  373. SCPLsFullTime = TAutoSwitch(Storage->ReadInteger("SCPLsFullTime", SCPLsFullTime));
  374. FtpListAll = TAutoSwitch(Storage->ReadInteger("FtpListAll", FtpListAll));
  375. Scp1Compatibility = Storage->ReadBool("Scp1Compatibility", Scp1Compatibility);
  376. TimeDifference = Storage->ReadFloat("TimeDifference", TimeDifference);
  377. DeleteToRecycleBin = Storage->ReadBool("DeleteToRecycleBin", DeleteToRecycleBin);
  378. OverwrittenToRecycleBin = Storage->ReadBool("OverwrittenToRecycleBin", OverwrittenToRecycleBin);
  379. RecycleBinPath = Storage->ReadString("RecycleBinPath", RecycleBinPath);
  380. PostLoginCommands = Storage->ReadString("PostLoginCommands", PostLoginCommands);
  381. ReturnVar = Storage->ReadString("ReturnVar", ReturnVar);
  382. LookupUserGroups = Storage->ReadBool("LookupUserGroups", LookupUserGroups);
  383. EOLType = (TEOLType)Storage->ReadInteger("EOLType", EOLType);
  384. Utf = TAutoSwitch(Storage->ReadInteger("Utf", Storage->ReadInteger("SFTPUtfBug", Utf)));
  385. TcpNoDelay = Storage->ReadBool("TcpNoDelay", TcpNoDelay);
  386. ProxyMethod = (TProxyMethod)Storage->ReadInteger("ProxyMethod", -1);
  387. if (ProxyMethod < 0)
  388. {
  389. int ProxyType = Storage->ReadInteger("ProxyType", pxNone);
  390. int ProxySOCKSVersion;
  391. switch (ProxyType) {
  392. case pxHTTP:
  393. ProxyMethod = pmHTTP;
  394. break;
  395. case pxTelnet:
  396. ProxyMethod = pmTelnet;
  397. break;
  398. case pxSocks:
  399. ProxySOCKSVersion = Storage->ReadInteger("ProxySOCKSVersion", 5);
  400. ProxyMethod = ProxySOCKSVersion == 5 ? pmSocks5 : pmSocks4;
  401. break;
  402. default:
  403. case pxNone:
  404. ProxyMethod = pmNone;
  405. break;
  406. }
  407. }
  408. ProxyHost = Storage->ReadString("ProxyHost", ProxyHost);
  409. ProxyPort = Storage->ReadInteger("ProxyPort", ProxyPort);
  410. ProxyUsername = Storage->ReadString("ProxyUsername", ProxyUsername);
  411. if (Storage->ValueExists("ProxyPassword"))
  412. {
  413. // encrypt unencrypted password
  414. ProxyPassword = Storage->ReadString("ProxyPassword", "");
  415. }
  416. else
  417. {
  418. // load encrypted password
  419. FProxyPassword = Storage->ReadString("ProxyPasswordEnc", FProxyPassword);
  420. }
  421. if (ProxyMethod == pmCmd)
  422. {
  423. ProxyLocalCommand = Storage->ReadStringRaw("ProxyTelnetCommand", ProxyLocalCommand);
  424. }
  425. else
  426. {
  427. ProxyTelnetCommand = Storage->ReadStringRaw("ProxyTelnetCommand", ProxyTelnetCommand);
  428. }
  429. ProxyDNS = TAutoSwitch((Storage->ReadInteger("ProxyDNS", (ProxyDNS + 2) % 3) + 1) % 3);
  430. ProxyLocalhost = Storage->ReadBool("ProxyLocalhost", ProxyLocalhost);
  431. #define READ_BUG(BUG) \
  432. Bug[sb##BUG] = TAutoSwitch(2 - Storage->ReadInteger("Bug"#BUG, \
  433. 2 - Bug[sb##BUG]));
  434. READ_BUG(Ignore1);
  435. READ_BUG(PlainPW1);
  436. READ_BUG(RSA1);
  437. READ_BUG(HMAC2);
  438. READ_BUG(DeriveKey2);
  439. READ_BUG(RSAPad2);
  440. READ_BUG(Rekey2);
  441. READ_BUG(PKSessID2);
  442. READ_BUG(MaxPkt2);
  443. #undef READ_BUG
  444. if ((Bug[sbHMAC2] == asAuto) &&
  445. Storage->ReadBool("BuggyMAC", false))
  446. {
  447. Bug[sbHMAC2] = asOn;
  448. }
  449. SftpServer = Storage->ReadString("SftpServer", SftpServer);
  450. #define READ_SFTP_BUG(BUG) \
  451. SFTPBug[sb##BUG] = TAutoSwitch(Storage->ReadInteger("SFTP" #BUG "Bug", SFTPBug[sb##BUG]));
  452. READ_SFTP_BUG(Symlink);
  453. READ_SFTP_BUG(SignedTS);
  454. #undef READ_SFTP_BUG
  455. SFTPMaxVersion = Storage->ReadInteger("SFTPMaxVersion", SFTPMaxVersion);
  456. SFTPMaxPacketSize = Storage->ReadInteger("SFTPMaxPacketSize", SFTPMaxPacketSize);
  457. Color = Storage->ReadInteger("Color", Color);
  458. ProtocolStr = Storage->ReadString("Protocol", ProtocolStr);
  459. Tunnel = Storage->ReadBool("Tunnel", Tunnel);
  460. TunnelPortNumber = Storage->ReadInteger("TunnelPortNumber", TunnelPortNumber);
  461. TunnelUserName = Storage->ReadString("TunnelUserName", TunnelUserName);
  462. // must be loaded after TunnelUserName,
  463. // because TunnelHostName may be in format user@host
  464. TunnelHostName = Storage->ReadString("TunnelHostName", TunnelHostName);
  465. if (!Configuration->DisablePasswordStoring)
  466. {
  467. FTunnelPassword = Storage->ReadString("TunnelPassword", FTunnelPassword);
  468. }
  469. TunnelPublicKeyFile = Storage->ReadString("TunnelPublicKeyFile", TunnelPublicKeyFile);
  470. TunnelLocalPortNumber = Storage->ReadInteger("TunnelLocalPortNumber", TunnelLocalPortNumber);
  471. // Ftp prefix
  472. FtpPasvMode = Storage->ReadBool("FtpPasvMode", FtpPasvMode);
  473. FtpAccount = Storage->ReadString("FtpAccount", FtpAccount);
  474. FtpPingInterval = Storage->ReadInteger("FtpPingInterval", FtpPingInterval);
  475. FtpPingType = static_cast<TPingType>(Storage->ReadInteger("FtpPingType", FtpPingType));
  476. Ftps = static_cast<TFtps>(Storage->ReadInteger("Ftps", Ftps));
  477. CustomParam1 = Storage->ReadString("CustomParam1", CustomParam1);
  478. CustomParam2 = Storage->ReadString("CustomParam2", CustomParam2);
  479. Storage->CloseSubKey();
  480. };
  481. if (RewritePassword)
  482. {
  483. TStorageAccessMode AccessMode = Storage->AccessMode;
  484. Storage->AccessMode = smReadWrite;
  485. try
  486. {
  487. if (Storage->OpenSubKey(InternalStorageKey, true))
  488. {
  489. Storage->DeleteValue("PasswordPlain");
  490. if (!Password.IsEmpty())
  491. {
  492. Storage->WriteString("Password", FPassword);
  493. }
  494. Storage->CloseSubKey();
  495. }
  496. }
  497. catch(...)
  498. {
  499. // ignore errors (like read-only INI file)
  500. }
  501. Storage->AccessMode = AccessMode;
  502. }
  503. FModified = false;
  504. }
  505. //---------------------------------------------------------------------
  506. void __fastcall TSessionData::Save(THierarchicalStorage * Storage,
  507. bool PuttyExport, const TSessionData * Default)
  508. {
  509. if (Storage->OpenSubKey(InternalStorageKey, true))
  510. {
  511. #define WRITE_DATA_EX(TYPE, NAME, PROPERTY, CONV) \
  512. if ((Default != NULL) && (CONV(Default->PROPERTY) == CONV(PROPERTY))) \
  513. { \
  514. Storage->DeleteValue(NAME); \
  515. } \
  516. else \
  517. { \
  518. Storage->Write ## TYPE(NAME, CONV(PROPERTY)); \
  519. }
  520. #define WRITE_DATA_CONV(TYPE, NAME, PROPERTY) WRITE_DATA_EX(TYPE, NAME, PROPERTY, WRITE_DATA_CONV_FUNC)
  521. #define WRITE_DATA(TYPE, PROPERTY) WRITE_DATA_EX(TYPE, #PROPERTY, PROPERTY, )
  522. WRITE_DATA(String, HostName);
  523. WRITE_DATA(Integer, PortNumber);
  524. if (!Configuration->DisablePasswordStoring && !PuttyExport && !Password.IsEmpty())
  525. {
  526. WRITE_DATA_EX(String, "Password", FPassword, );
  527. }
  528. else
  529. {
  530. Storage->DeleteValue("Password");
  531. }
  532. Storage->DeleteValue("PasswordPlain");
  533. WRITE_DATA(Bool, Passwordless);
  534. WRITE_DATA_EX(Integer, "PingInterval", PingInterval / 60, );
  535. WRITE_DATA_EX(Integer, "PingIntervalSecs", PingInterval % 60, );
  536. Storage->DeleteValue("PingIntervalSec"); // obsolete
  537. // when PingInterval is stored always store PingType not to attempt to
  538. // deduce PingType from PingInterval (backward compatibility with pre 3.5)
  539. if (((Default != NULL) && (PingType != Default->PingType)) ||
  540. Storage->ValueExists("PingInterval"))
  541. {
  542. Storage->WriteInteger("PingType", PingType);
  543. }
  544. else
  545. {
  546. Storage->DeleteValue("PingType");
  547. }
  548. WRITE_DATA(Integer, Timeout);
  549. WRITE_DATA(Bool, TryAgent);
  550. WRITE_DATA(Bool, AgentFwd);
  551. WRITE_DATA(Bool, AuthTIS);
  552. WRITE_DATA(Bool, AuthKI);
  553. WRITE_DATA(Bool, AuthKIPassword);
  554. WRITE_DATA(Bool, AuthGSSAPI);
  555. WRITE_DATA(Bool, GSSAPIFwdTGT);
  556. WRITE_DATA(String, GSSAPIServerRealm);
  557. Storage->DeleteValue("TryGSSKEX");
  558. Storage->DeleteValue("UserNameFromEnvironment");
  559. Storage->DeleteValue("GSSAPIServerChoosesUserName");
  560. Storage->DeleteValue("GSSAPITrustDNS");
  561. if (PuttyExport)
  562. {
  563. // duplicate kerberos setting with keys of the vintela quest putty
  564. WRITE_DATA_EX(Bool, "AuthSSPI", AuthGSSAPI, );
  565. WRITE_DATA_EX(Bool, "SSPIFwdTGT", GSSAPIFwdTGT, );
  566. WRITE_DATA_EX(String, "KerbPrincipal", GSSAPIServerRealm, );
  567. // duplicate kerberos setting with keys of the official putty
  568. WRITE_DATA_EX(Bool, "GssapiFwd", GSSAPIFwdTGT, );
  569. }
  570. WRITE_DATA(Bool, ChangeUsername);
  571. WRITE_DATA(Bool, Compression);
  572. WRITE_DATA(Integer, SshProt);
  573. WRITE_DATA(Bool, Ssh2DES);
  574. WRITE_DATA(Bool, SshNoUserAuth);
  575. WRITE_DATA_EX(String, "Cipher", CipherList, );
  576. WRITE_DATA_EX(String, "KEX", KexList, );
  577. WRITE_DATA(Integer, AddressFamily);
  578. WRITE_DATA_EX(String, "RekeyBytes", RekeyData, );
  579. WRITE_DATA(Integer, RekeyTime);
  580. WRITE_DATA(Bool, TcpNoDelay);
  581. if (PuttyExport)
  582. {
  583. WRITE_DATA(StringRaw, UserName);
  584. WRITE_DATA(StringRaw, PublicKeyFile);
  585. }
  586. else
  587. {
  588. WRITE_DATA(String, UserName);
  589. WRITE_DATA(String, PublicKeyFile);
  590. WRITE_DATA(Integer, FSProtocol);
  591. WRITE_DATA(String, LocalDirectory);
  592. WRITE_DATA(String, RemoteDirectory);
  593. WRITE_DATA(Bool, UpdateDirectories);
  594. WRITE_DATA(Bool, CacheDirectories);
  595. WRITE_DATA(Bool, CacheDirectoryChanges);
  596. WRITE_DATA(Bool, PreserveDirectoryChanges);
  597. WRITE_DATA(Bool, ResolveSymlinks);
  598. WRITE_DATA_EX(Integer, "ConsiderDST", DSTMode, );
  599. WRITE_DATA(Bool, LockInHome);
  600. // Special is never stored (if it would, login dialog must be modified not to
  601. // duplicate Special parameter when Special session is loaded and then stored
  602. // under different name)
  603. // WRITE_DATA(Bool, Special);
  604. WRITE_DATA(String, Shell);
  605. WRITE_DATA(Bool, ClearAliases);
  606. WRITE_DATA(Bool, UnsetNationalVars);
  607. WRITE_DATA(String, ListingCommand);
  608. WRITE_DATA(Bool, IgnoreLsWarnings);
  609. WRITE_DATA(Integer, SCPLsFullTime);
  610. WRITE_DATA(Integer, FtpListAll);
  611. WRITE_DATA(Bool, Scp1Compatibility);
  612. WRITE_DATA(Float, TimeDifference);
  613. WRITE_DATA(Bool, DeleteToRecycleBin);
  614. WRITE_DATA(Bool, OverwrittenToRecycleBin);
  615. WRITE_DATA(String, RecycleBinPath);
  616. WRITE_DATA(String, PostLoginCommands);
  617. WRITE_DATA(String, ReturnVar);
  618. WRITE_DATA(Bool, LookupUserGroups);
  619. WRITE_DATA(Integer, EOLType);
  620. Storage->DeleteValue("SFTPUtfBug");
  621. WRITE_DATA(Integer, Utf);
  622. }
  623. WRITE_DATA(Integer, ProxyMethod);
  624. if (PuttyExport)
  625. {
  626. // support for Putty 0.53b and older
  627. int ProxyType;
  628. int ProxySOCKSVersion = 5;
  629. switch (ProxyMethod) {
  630. case pmHTTP:
  631. ProxyType = pxHTTP;
  632. break;
  633. case pmTelnet:
  634. ProxyType = pxTelnet;
  635. break;
  636. case pmSocks5:
  637. ProxyType = pxSocks;
  638. ProxySOCKSVersion = 5;
  639. break;
  640. case pmSocks4:
  641. ProxyType = pxSocks;
  642. ProxySOCKSVersion = 4;
  643. break;
  644. default:
  645. case pmNone:
  646. ProxyType = pxNone;
  647. break;
  648. }
  649. Storage->WriteInteger("ProxyType", ProxyType);
  650. Storage->WriteInteger("ProxySOCKSVersion", ProxySOCKSVersion);
  651. }
  652. else
  653. {
  654. Storage->DeleteValue("ProxyType");
  655. Storage->DeleteValue("ProxySOCKSVersion");
  656. }
  657. WRITE_DATA(String, ProxyHost);
  658. WRITE_DATA(Integer, ProxyPort);
  659. WRITE_DATA(String, ProxyUsername);
  660. if (PuttyExport)
  661. {
  662. // save password unencrypted
  663. WRITE_DATA(String, ProxyPassword);
  664. }
  665. else
  666. {
  667. // save password encrypted
  668. if (!ProxyPassword.IsEmpty())
  669. {
  670. WRITE_DATA_EX(String, "ProxyPasswordEnc", FProxyPassword, );
  671. }
  672. else
  673. {
  674. Storage->DeleteValue("ProxyPasswordEnc");
  675. }
  676. Storage->DeleteValue("ProxyPassword");
  677. }
  678. if (ProxyMethod == pmCmd)
  679. {
  680. WRITE_DATA_EX(StringRaw, "ProxyTelnetCommand", ProxyLocalCommand, );
  681. }
  682. else
  683. {
  684. WRITE_DATA(StringRaw, ProxyTelnetCommand);
  685. }
  686. #define WRITE_DATA_CONV_FUNC(X) (((X) + 2) % 3)
  687. WRITE_DATA_CONV(Integer, "ProxyDNS", ProxyDNS);
  688. #undef WRITE_DATA_CONV_FUNC
  689. WRITE_DATA(Bool, ProxyLocalhost);
  690. #define WRITE_DATA_CONV_FUNC(X) (2 - (X))
  691. #define WRITE_BUG(BUG) WRITE_DATA_CONV(Integer, "Bug" #BUG, Bug[sb##BUG]);
  692. WRITE_BUG(Ignore1);
  693. WRITE_BUG(PlainPW1);
  694. WRITE_BUG(RSA1);
  695. WRITE_BUG(HMAC2);
  696. WRITE_BUG(DeriveKey2);
  697. WRITE_BUG(RSAPad2);
  698. WRITE_BUG(Rekey2);
  699. WRITE_BUG(PKSessID2);
  700. WRITE_BUG(MaxPkt2);
  701. #undef WRITE_BUG
  702. #undef WRITE_DATA_CONV_FUNC
  703. Storage->DeleteValue("BuggyMAC");
  704. Storage->DeleteValue("AliasGroupList");
  705. if (PuttyExport)
  706. {
  707. WRITE_DATA_EX(String, "Protocol", ProtocolStr, );
  708. }
  709. if (!PuttyExport)
  710. {
  711. WRITE_DATA(String, SftpServer);
  712. #define WRITE_SFTP_BUG(BUG) WRITE_DATA_EX(Integer, "SFTP" #BUG "Bug", SFTPBug[sb##BUG], );
  713. WRITE_SFTP_BUG(Symlink);
  714. WRITE_SFTP_BUG(SignedTS);
  715. #undef WRITE_SFTP_BUG
  716. WRITE_DATA(Integer, SFTPMaxVersion);
  717. WRITE_DATA(Integer, SFTPMaxPacketSize);
  718. WRITE_DATA(Integer, Color);
  719. WRITE_DATA(Bool, Tunnel);
  720. WRITE_DATA(String, TunnelHostName);
  721. WRITE_DATA(Integer, TunnelPortNumber);
  722. WRITE_DATA(String, TunnelUserName);
  723. if (!Configuration->DisablePasswordStoring && !TunnelPassword.IsEmpty())
  724. {
  725. WRITE_DATA_EX(String, "TunnelPassword", FTunnelPassword, );
  726. }
  727. else
  728. {
  729. Storage->DeleteValue("TunnelPassword");
  730. }
  731. WRITE_DATA(String, TunnelPublicKeyFile);
  732. WRITE_DATA(Integer, TunnelLocalPortNumber);
  733. WRITE_DATA(Bool, FtpPasvMode);
  734. WRITE_DATA(String, FtpAccount);
  735. WRITE_DATA(Integer, FtpPingInterval);
  736. WRITE_DATA(Integer, FtpPingType);
  737. WRITE_DATA(Integer, Ftps);
  738. WRITE_DATA(String, CustomParam1);
  739. WRITE_DATA(String, CustomParam2);
  740. }
  741. Storage->CloseSubKey();
  742. }
  743. }
  744. //---------------------------------------------------------------------
  745. void __fastcall TSessionData::Remove()
  746. {
  747. THierarchicalStorage * Storage = Configuration->CreateScpStorage(true);
  748. try
  749. {
  750. Storage->Explicit = true;
  751. if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, false))
  752. {
  753. Storage->RecursiveDeleteSubKey(InternalStorageKey);
  754. }
  755. }
  756. __finally
  757. {
  758. delete Storage;
  759. }
  760. }
  761. //---------------------------------------------------------------------
  762. bool __fastcall TSessionData::ParseUrl(AnsiString Url, TOptions * Options,
  763. TStoredSessionList * StoredSessions, bool & DefaultsOnly, AnsiString * FileName,
  764. bool * AProtocolDefined)
  765. {
  766. bool ProtocolDefined = false;
  767. bool PortNumberDefined = false;
  768. TFSProtocol AFSProtocol;
  769. int APortNumber;
  770. TFtps AFtps = ftpsNone;
  771. if (Url.SubString(1, 4).LowerCase() == "scp:")
  772. {
  773. AFSProtocol = fsSCPonly;
  774. APortNumber = SshPortNumber;
  775. Url.Delete(1, 4);
  776. ProtocolDefined = true;
  777. }
  778. else if (Url.SubString(1, 5).LowerCase() == "sftp:")
  779. {
  780. AFSProtocol = fsSFTPonly;
  781. APortNumber = SshPortNumber;
  782. Url.Delete(1, 5);
  783. ProtocolDefined = true;
  784. }
  785. else if (Url.SubString(1, 4).LowerCase() == "ftp:")
  786. {
  787. AFSProtocol = fsFTP;
  788. Ftps = ftpsNone;
  789. APortNumber = FtpPortNumber;
  790. Url.Delete(1, 4);
  791. ProtocolDefined = true;
  792. }
  793. else if (Url.SubString(1, 5).LowerCase() == "ftps:")
  794. {
  795. AFSProtocol = fsFTP;
  796. AFtps = ftpsImplicit;
  797. // adjust default port number to default Ftps mode
  798. if (AFtps == ftpsImplicit)
  799. {
  800. APortNumber = FtpsImplicitPortNumber;
  801. }
  802. else
  803. {
  804. APortNumber = FtpPortNumber;
  805. }
  806. Url.Delete(1, 5);
  807. ProtocolDefined = true;
  808. }
  809. if (ProtocolDefined && (Url.SubString(1, 2) == "//"))
  810. {
  811. Url.Delete(1, 2);
  812. }
  813. if (AProtocolDefined != NULL)
  814. {
  815. *AProtocolDefined = ProtocolDefined;
  816. }
  817. if (!Url.IsEmpty())
  818. {
  819. AnsiString DecodedUrl = DecodeUrlChars(Url);
  820. // lookup stored session even if protocol was defined
  821. // (this allows setting for example default username for host
  822. // by creating stored session named by host)
  823. TSessionData * Data = NULL;
  824. for (Integer Index = 0; Index < StoredSessions->Count + StoredSessions->HiddenCount; Index++)
  825. {
  826. TSessionData * AData = (TSessionData *)StoredSessions->Items[Index];
  827. if (AnsiSameText(AData->Name, DecodedUrl) ||
  828. AnsiSameText(AData->Name + "/", DecodedUrl.SubString(1, AData->Name.Length() + 1)))
  829. {
  830. Data = AData;
  831. break;
  832. }
  833. }
  834. AnsiString ARemoteDirectory;
  835. if (Data != NULL)
  836. {
  837. DefaultsOnly = false;
  838. Assign(Data);
  839. int P = 1;
  840. while (!AnsiSameText(DecodeUrlChars(Url.SubString(1, P)), Data->Name))
  841. {
  842. P++;
  843. assert(P <= Url.Length());
  844. }
  845. ARemoteDirectory = Url.SubString(P + 1, Url.Length() - P);
  846. if (StoredSessions->IsHidden(Data))
  847. {
  848. Data->Remove();
  849. StoredSessions->Remove(Data);
  850. // only modified, implicit
  851. StoredSessions->Save(false, false);
  852. }
  853. }
  854. else
  855. {
  856. Assign(StoredSessions->DefaultSettings);
  857. Name = "";
  858. int PSlash = Url.Pos("/");
  859. if (PSlash == 0)
  860. {
  861. PSlash = Url.Length() + 1;
  862. }
  863. AnsiString ConnectInfo = Url.SubString(1, PSlash - 1);
  864. int P = ConnectInfo.LastDelimiter("@");
  865. AnsiString UserInfo;
  866. AnsiString HostInfo;
  867. if (P > 0)
  868. {
  869. UserInfo = ConnectInfo.SubString(1, P - 1);
  870. HostInfo = ConnectInfo.SubString(P + 1, ConnectInfo.Length() - P);
  871. }
  872. else
  873. {
  874. HostInfo = ConnectInfo;
  875. }
  876. HostName = DecodeUrlChars(CutToChar(HostInfo, ':', true));
  877. // expanded from ?: operator, as it caused strange "access violation" errors
  878. if (!HostInfo.IsEmpty())
  879. {
  880. PortNumber = StrToIntDef(DecodeUrlChars(HostInfo), -1);
  881. PortNumberDefined = true;
  882. }
  883. else if (ProtocolDefined)
  884. {
  885. PortNumber = APortNumber;
  886. Ftps = AFtps;
  887. }
  888. bool PasswordSeparator = (UserInfo.Pos(':') != 0);
  889. UserName = DecodeUrlChars(CutToChar(UserInfo, ':', false));
  890. Password = DecodeUrlChars(UserInfo);
  891. Passwordless = Password.IsEmpty() && PasswordSeparator;
  892. ARemoteDirectory = Url.SubString(PSlash, Url.Length() - PSlash + 1);
  893. }
  894. if (!ARemoteDirectory.IsEmpty() && (ARemoteDirectory != "/"))
  895. {
  896. if ((ARemoteDirectory[ARemoteDirectory.Length()] != '/') &&
  897. (FileName != NULL))
  898. {
  899. *FileName = DecodeUrlChars(UnixExtractFileName(ARemoteDirectory));
  900. ARemoteDirectory = UnixExtractFilePath(ARemoteDirectory);
  901. }
  902. RemoteDirectory = DecodeUrlChars(ARemoteDirectory);
  903. }
  904. DefaultsOnly = false;
  905. }
  906. else
  907. {
  908. Assign(StoredSessions->DefaultSettings);
  909. DefaultsOnly = true;
  910. }
  911. if (ProtocolDefined)
  912. {
  913. FSProtocol = AFSProtocol;
  914. }
  915. if (Options != NULL)
  916. {
  917. // we deliberatelly do keep defaultonly to false, in presence of any option,
  918. // as the option should not make session "connectable"
  919. AnsiString Value;
  920. if (Options->FindSwitch("privatekey", Value))
  921. {
  922. PublicKeyFile = Value;
  923. }
  924. if (Options->FindSwitch("timeout", Value))
  925. {
  926. Timeout = StrToInt(Value);
  927. }
  928. if (Options->FindSwitch("hostkey", Value) ||
  929. Options->FindSwitch("certificate", Value))
  930. {
  931. HostKey = Value;
  932. }
  933. if (Options->FindSwitch("passive", Value))
  934. {
  935. FtpPasvMode = (StrToIntDef(Value, 1) != 0);
  936. }
  937. if (Options->FindSwitch("implicit", Value))
  938. {
  939. bool Enabled = (StrToIntDef(Value, 1) != 0);
  940. Ftps = Enabled ? ftpsImplicit : ftpsNone;
  941. if (!PortNumberDefined && Enabled)
  942. {
  943. PortNumber = FtpsImplicitPortNumber;
  944. }
  945. }
  946. if (Options->FindSwitch("explicitssl", Value))
  947. {
  948. bool Enabled = (StrToIntDef(Value, 1) != 0);
  949. Ftps = Enabled ? ftpsExplicitSsl : ftpsNone;
  950. if (!PortNumberDefined && Enabled)
  951. {
  952. PortNumber = FtpPortNumber;
  953. }
  954. }
  955. if (Options->FindSwitch("explicittls", Value))
  956. {
  957. bool Enabled = (StrToIntDef(Value, 1) != 0);
  958. Ftps = Enabled ? ftpsExplicitTls : ftpsNone;
  959. if (!PortNumberDefined && Enabled)
  960. {
  961. PortNumber = FtpPortNumber;
  962. }
  963. }
  964. }
  965. return true;
  966. }
  967. //---------------------------------------------------------------------
  968. void __fastcall TSessionData::ConfigureTunnel(int APortNumber)
  969. {
  970. FOrigHostName = HostName;
  971. FOrigPortNumber = PortNumber;
  972. FOrigProxyMethod = ProxyMethod;
  973. HostName = "127.0.0.1";
  974. PortNumber = APortNumber;
  975. // proxy settings is used for tunnel
  976. ProxyMethod = pmNone;
  977. }
  978. //---------------------------------------------------------------------
  979. void __fastcall TSessionData::RollbackTunnel()
  980. {
  981. HostName = FOrigHostName;
  982. PortNumber = FOrigPortNumber;
  983. ProxyMethod = FOrigProxyMethod;
  984. }
  985. //---------------------------------------------------------------------
  986. void __fastcall TSessionData::ValidatePath(const AnsiString Path)
  987. {
  988. // noop
  989. }
  990. //---------------------------------------------------------------------
  991. void __fastcall TSessionData::ValidateName(const AnsiString Name)
  992. {
  993. if (Name.LastDelimiter("/") > 0)
  994. {
  995. throw Exception(FMTLOAD(ITEM_NAME_INVALID, (Name, "/")));
  996. }
  997. }
  998. //---------------------------------------------------------------------
  999. bool __fastcall TSessionData::GetCanLogin()
  1000. {
  1001. return !FHostName.IsEmpty();
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. AnsiString __fastcall TSessionData::GetSessionKey()
  1005. {
  1006. return FORMAT("%s@%s", (UserName, HostName));
  1007. }
  1008. //---------------------------------------------------------------------
  1009. AnsiString __fastcall TSessionData::GetInternalStorageKey()
  1010. {
  1011. if (Name.IsEmpty())
  1012. {
  1013. return SessionKey;
  1014. }
  1015. else
  1016. {
  1017. return Name;
  1018. }
  1019. }
  1020. //---------------------------------------------------------------------
  1021. AnsiString __fastcall TSessionData::GetStorageKey()
  1022. {
  1023. return SessionName;
  1024. }
  1025. //---------------------------------------------------------------------
  1026. void __fastcall TSessionData::SetHostName(AnsiString value)
  1027. {
  1028. if (FHostName != value)
  1029. {
  1030. // HostName is key for password encryption
  1031. AnsiString XPassword = Password;
  1032. int P = value.LastDelimiter("@");
  1033. if (P > 0)
  1034. {
  1035. UserName = value.SubString(1, P - 1);
  1036. value = value.SubString(P + 1, value.Length() - P);
  1037. }
  1038. FHostName = value;
  1039. FModified = true;
  1040. Password = XPassword;
  1041. if (!XPassword.IsEmpty())
  1042. {
  1043. XPassword.Unique();
  1044. memset(XPassword.c_str(), 0, XPassword.Length());
  1045. }
  1046. }
  1047. }
  1048. //---------------------------------------------------------------------
  1049. void __fastcall TSessionData::SetPortNumber(int value)
  1050. {
  1051. SET_SESSION_PROPERTY(PortNumber);
  1052. }
  1053. //---------------------------------------------------------------------------
  1054. void __fastcall TSessionData::SetShell(AnsiString value)
  1055. {
  1056. SET_SESSION_PROPERTY(Shell);
  1057. }
  1058. //---------------------------------------------------------------------------
  1059. void __fastcall TSessionData::SetSftpServer(AnsiString value)
  1060. {
  1061. SET_SESSION_PROPERTY(SftpServer);
  1062. }
  1063. //---------------------------------------------------------------------------
  1064. void __fastcall TSessionData::SetClearAliases(bool value)
  1065. {
  1066. SET_SESSION_PROPERTY(ClearAliases);
  1067. }
  1068. //---------------------------------------------------------------------------
  1069. void __fastcall TSessionData::SetListingCommand(AnsiString value)
  1070. {
  1071. SET_SESSION_PROPERTY(ListingCommand);
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. void __fastcall TSessionData::SetIgnoreLsWarnings(bool value)
  1075. {
  1076. SET_SESSION_PROPERTY(IgnoreLsWarnings);
  1077. }
  1078. //---------------------------------------------------------------------------
  1079. void __fastcall TSessionData::SetUnsetNationalVars(bool value)
  1080. {
  1081. SET_SESSION_PROPERTY(UnsetNationalVars);
  1082. }
  1083. //---------------------------------------------------------------------
  1084. void __fastcall TSessionData::SetUserName(AnsiString value)
  1085. {
  1086. // UserName is key for password encryption
  1087. AnsiString XPassword = Password;
  1088. SET_SESSION_PROPERTY(UserName);
  1089. Password = XPassword;
  1090. if (!XPassword.IsEmpty())
  1091. {
  1092. XPassword.Unique();
  1093. memset(XPassword.c_str(), 0, XPassword.Length());
  1094. }
  1095. }
  1096. //---------------------------------------------------------------------
  1097. void __fastcall TSessionData::SetPassword(AnsiString value)
  1098. {
  1099. if (!value.IsEmpty())
  1100. {
  1101. Passwordless = false;
  1102. }
  1103. value = EncryptPassword(value, UserName+HostName);
  1104. SET_SESSION_PROPERTY(Password);
  1105. }
  1106. //---------------------------------------------------------------------
  1107. AnsiString __fastcall TSessionData::GetPassword()
  1108. {
  1109. return DecryptPassword(FPassword, UserName+HostName);
  1110. }
  1111. //---------------------------------------------------------------------
  1112. void __fastcall TSessionData::SetPasswordless(bool value)
  1113. {
  1114. SET_SESSION_PROPERTY(Passwordless);
  1115. }
  1116. //---------------------------------------------------------------------
  1117. void __fastcall TSessionData::SetPingInterval(int value)
  1118. {
  1119. SET_SESSION_PROPERTY(PingInterval);
  1120. }
  1121. //---------------------------------------------------------------------
  1122. void __fastcall TSessionData::SetTryAgent(bool value)
  1123. {
  1124. SET_SESSION_PROPERTY(TryAgent);
  1125. }
  1126. //---------------------------------------------------------------------
  1127. void __fastcall TSessionData::SetAgentFwd(bool value)
  1128. {
  1129. SET_SESSION_PROPERTY(AgentFwd);
  1130. }
  1131. //---------------------------------------------------------------------
  1132. void __fastcall TSessionData::SetAuthTIS(bool value)
  1133. {
  1134. SET_SESSION_PROPERTY(AuthTIS);
  1135. }
  1136. //---------------------------------------------------------------------
  1137. void __fastcall TSessionData::SetAuthKI(bool value)
  1138. {
  1139. SET_SESSION_PROPERTY(AuthKI);
  1140. }
  1141. //---------------------------------------------------------------------
  1142. void __fastcall TSessionData::SetAuthKIPassword(bool value)
  1143. {
  1144. SET_SESSION_PROPERTY(AuthKIPassword);
  1145. }
  1146. //---------------------------------------------------------------------
  1147. void __fastcall TSessionData::SetAuthGSSAPI(bool value)
  1148. {
  1149. SET_SESSION_PROPERTY(AuthGSSAPI);
  1150. }
  1151. //---------------------------------------------------------------------
  1152. void __fastcall TSessionData::SetGSSAPIFwdTGT(bool value)
  1153. {
  1154. SET_SESSION_PROPERTY(GSSAPIFwdTGT);
  1155. }
  1156. //---------------------------------------------------------------------
  1157. void __fastcall TSessionData::SetGSSAPIServerRealm(AnsiString value)
  1158. {
  1159. SET_SESSION_PROPERTY(GSSAPIServerRealm);
  1160. }
  1161. //---------------------------------------------------------------------
  1162. void __fastcall TSessionData::SetChangeUsername(bool value)
  1163. {
  1164. SET_SESSION_PROPERTY(ChangeUsername);
  1165. }
  1166. //---------------------------------------------------------------------
  1167. void __fastcall TSessionData::SetCompression(bool value)
  1168. {
  1169. SET_SESSION_PROPERTY(Compression);
  1170. }
  1171. //---------------------------------------------------------------------
  1172. void __fastcall TSessionData::SetSshProt(TSshProt value)
  1173. {
  1174. SET_SESSION_PROPERTY(SshProt);
  1175. }
  1176. //---------------------------------------------------------------------
  1177. void __fastcall TSessionData::SetSsh2DES(bool value)
  1178. {
  1179. SET_SESSION_PROPERTY(Ssh2DES);
  1180. }
  1181. //---------------------------------------------------------------------
  1182. void __fastcall TSessionData::SetSshNoUserAuth(bool value)
  1183. {
  1184. SET_SESSION_PROPERTY(SshNoUserAuth);
  1185. }
  1186. //---------------------------------------------------------------------
  1187. AnsiString __fastcall TSessionData::GetSshProtStr()
  1188. {
  1189. return SshProtList[FSshProt];
  1190. }
  1191. //---------------------------------------------------------------------
  1192. bool __fastcall TSessionData::GetUsesSsh()
  1193. {
  1194. return (FSProtocol != fsFTP);
  1195. }
  1196. //---------------------------------------------------------------------
  1197. void __fastcall TSessionData::SetCipher(int Index, TCipher value)
  1198. {
  1199. assert(Index >= 0 && Index < CIPHER_COUNT);
  1200. SET_SESSION_PROPERTY(Ciphers[Index]);
  1201. }
  1202. //---------------------------------------------------------------------
  1203. TCipher __fastcall TSessionData::GetCipher(int Index) const
  1204. {
  1205. assert(Index >= 0 && Index < CIPHER_COUNT);
  1206. return FCiphers[Index];
  1207. }
  1208. //---------------------------------------------------------------------
  1209. void __fastcall TSessionData::SetCipherList(AnsiString value)
  1210. {
  1211. bool Used[CIPHER_COUNT];
  1212. for (int C = 0; C < CIPHER_COUNT; C++) Used[C] = false;
  1213. AnsiString CipherStr;
  1214. int Index = 0;
  1215. while (!value.IsEmpty() && (Index < CIPHER_COUNT))
  1216. {
  1217. CipherStr = CutToChar(value, ',', true);
  1218. for (int C = 0; C < CIPHER_COUNT; C++)
  1219. {
  1220. if (!CipherStr.AnsiCompareIC(CipherNames[C]))
  1221. {
  1222. Cipher[Index] = (TCipher)C;
  1223. Used[C] = true;
  1224. Index++;
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. for (int C = 0; C < CIPHER_COUNT && Index < CIPHER_COUNT; C++)
  1230. {
  1231. if (!Used[DefaultCipherList[C]]) Cipher[Index++] = DefaultCipherList[C];
  1232. }
  1233. }
  1234. //---------------------------------------------------------------------
  1235. AnsiString __fastcall TSessionData::GetCipherList() const
  1236. {
  1237. AnsiString Result;
  1238. for (int Index = 0; Index < CIPHER_COUNT; Index++)
  1239. {
  1240. Result += AnsiString(Index ? "," : "") + CipherNames[Cipher[Index]];
  1241. }
  1242. return Result;
  1243. }
  1244. //---------------------------------------------------------------------
  1245. void __fastcall TSessionData::SetKex(int Index, TKex value)
  1246. {
  1247. assert(Index >= 0 && Index < KEX_COUNT);
  1248. SET_SESSION_PROPERTY(Kex[Index]);
  1249. }
  1250. //---------------------------------------------------------------------
  1251. TKex __fastcall TSessionData::GetKex(int Index) const
  1252. {
  1253. assert(Index >= 0 && Index < KEX_COUNT);
  1254. return FKex[Index];
  1255. }
  1256. //---------------------------------------------------------------------
  1257. void __fastcall TSessionData::SetKexList(AnsiString value)
  1258. {
  1259. bool Used[KEX_COUNT];
  1260. for (int K = 0; K < KEX_COUNT; K++) Used[K] = false;
  1261. AnsiString KexStr;
  1262. int Index = 0;
  1263. while (!value.IsEmpty() && (Index < KEX_COUNT))
  1264. {
  1265. KexStr = CutToChar(value, ',', true);
  1266. for (int K = 0; K < KEX_COUNT; K++)
  1267. {
  1268. if (!KexStr.AnsiCompareIC(KexNames[K]))
  1269. {
  1270. Kex[Index] = (TKex)K;
  1271. Used[K] = true;
  1272. Index++;
  1273. break;
  1274. }
  1275. }
  1276. }
  1277. for (int K = 0; K < KEX_COUNT && Index < KEX_COUNT; K++)
  1278. {
  1279. if (!Used[DefaultKexList[K]]) Kex[Index++] = DefaultKexList[K];
  1280. }
  1281. }
  1282. //---------------------------------------------------------------------
  1283. AnsiString __fastcall TSessionData::GetKexList() const
  1284. {
  1285. AnsiString Result;
  1286. for (int Index = 0; Index < KEX_COUNT; Index++)
  1287. {
  1288. Result += AnsiString(Index ? "," : "") + KexNames[Kex[Index]];
  1289. }
  1290. return Result;
  1291. }
  1292. //---------------------------------------------------------------------
  1293. void __fastcall TSessionData::SetPublicKeyFile(AnsiString value)
  1294. {
  1295. if (FPublicKeyFile != value)
  1296. {
  1297. FPublicKeyFile = StripPathQuotes(value);
  1298. FModified = true;
  1299. }
  1300. }
  1301. //---------------------------------------------------------------------
  1302. void __fastcall TSessionData::SetReturnVar(AnsiString value)
  1303. {
  1304. SET_SESSION_PROPERTY(ReturnVar);
  1305. }
  1306. //---------------------------------------------------------------------------
  1307. void __fastcall TSessionData::SetLookupUserGroups(bool value)
  1308. {
  1309. SET_SESSION_PROPERTY(LookupUserGroups);
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. void __fastcall TSessionData::SetEOLType(TEOLType value)
  1313. {
  1314. SET_SESSION_PROPERTY(EOLType);
  1315. }
  1316. //---------------------------------------------------------------------------
  1317. TDateTime __fastcall TSessionData::GetTimeoutDT()
  1318. {
  1319. return SecToDateTime(Timeout);
  1320. }
  1321. //---------------------------------------------------------------------------
  1322. void __fastcall TSessionData::SetTimeout(int value)
  1323. {
  1324. SET_SESSION_PROPERTY(Timeout);
  1325. }
  1326. //---------------------------------------------------------------------------
  1327. void __fastcall TSessionData::SetProtocol(TProtocol value)
  1328. {
  1329. SET_SESSION_PROPERTY(Protocol);
  1330. }
  1331. //---------------------------------------------------------------------------
  1332. void __fastcall TSessionData::SetFSProtocol(TFSProtocol value)
  1333. {
  1334. SET_SESSION_PROPERTY(FSProtocol);
  1335. }
  1336. //---------------------------------------------------------------------
  1337. AnsiString __fastcall TSessionData::GetFSProtocolStr()
  1338. {
  1339. assert(FSProtocol >= 0 && FSProtocol < FSPROTOCOL_COUNT);
  1340. return FSProtocolNames[FSProtocol];
  1341. }
  1342. //---------------------------------------------------------------------------
  1343. void __fastcall TSessionData::SetDetectReturnVar(bool value)
  1344. {
  1345. if (value != DetectReturnVar)
  1346. {
  1347. ReturnVar = value ? "" : "$?";
  1348. }
  1349. }
  1350. //---------------------------------------------------------------------------
  1351. bool __fastcall TSessionData::GetDetectReturnVar()
  1352. {
  1353. return ReturnVar.IsEmpty();
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TSessionData::SetDefaultShell(bool value)
  1357. {
  1358. if (value != DefaultShell)
  1359. {
  1360. Shell = value ? "" : "/bin/bash";
  1361. }
  1362. }
  1363. //---------------------------------------------------------------------------
  1364. bool __fastcall TSessionData::GetDefaultShell()
  1365. {
  1366. return Shell.IsEmpty();
  1367. }
  1368. //---------------------------------------------------------------------------
  1369. void __fastcall TSessionData::SetProtocolStr(AnsiString value)
  1370. {
  1371. FProtocol = ptRaw;
  1372. for (int Index = 0; Index < PROTOCOL_COUNT; Index++)
  1373. {
  1374. if (value.AnsiCompareIC(ProtocolNames[Index]) == 0)
  1375. {
  1376. FProtocol = TProtocol(Index);
  1377. break;
  1378. }
  1379. }
  1380. }
  1381. //---------------------------------------------------------------------
  1382. AnsiString __fastcall TSessionData::GetProtocolStr() const
  1383. {
  1384. return ProtocolNames[Protocol];
  1385. }
  1386. //---------------------------------------------------------------------
  1387. void __fastcall TSessionData::SetPingIntervalDT(TDateTime value)
  1388. {
  1389. unsigned short hour, min, sec, msec;
  1390. value.DecodeTime(&hour, &min, &sec, &msec);
  1391. PingInterval = ((int)hour)*60*60 + ((int)min)*60 + sec;
  1392. }
  1393. //---------------------------------------------------------------------------
  1394. TDateTime __fastcall TSessionData::GetPingIntervalDT()
  1395. {
  1396. return SecToDateTime(PingInterval);
  1397. }
  1398. //---------------------------------------------------------------------------
  1399. void __fastcall TSessionData::SetPingType(TPingType value)
  1400. {
  1401. SET_SESSION_PROPERTY(PingType);
  1402. }
  1403. //---------------------------------------------------------------------------
  1404. void __fastcall TSessionData::SetAddressFamily(TAddressFamily value)
  1405. {
  1406. SET_SESSION_PROPERTY(AddressFamily);
  1407. }
  1408. //---------------------------------------------------------------------------
  1409. void __fastcall TSessionData::SetRekeyData(AnsiString value)
  1410. {
  1411. SET_SESSION_PROPERTY(RekeyData);
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TSessionData::SetRekeyTime(unsigned int value)
  1415. {
  1416. SET_SESSION_PROPERTY(RekeyTime);
  1417. }
  1418. //---------------------------------------------------------------------
  1419. AnsiString __fastcall TSessionData::GetSessionName()
  1420. {
  1421. if (!Name.IsEmpty() && !TNamedObjectList::IsHidden(this) &&
  1422. (Name != DefaultSessionName))
  1423. {
  1424. return Name;
  1425. }
  1426. else if (!HostName.IsEmpty() && !UserName.IsEmpty())
  1427. {
  1428. return FORMAT("%s@%s", (UserName, HostName));
  1429. }
  1430. else if (!HostName.IsEmpty())
  1431. {
  1432. return HostName;
  1433. }
  1434. else
  1435. {
  1436. return "session";
  1437. }
  1438. }
  1439. //---------------------------------------------------------------------
  1440. AnsiString __fastcall TSessionData::GetSessionUrl()
  1441. {
  1442. AnsiString Url;
  1443. if (!Name.IsEmpty() && !TNamedObjectList::IsHidden(this) &&
  1444. (Name != DefaultSessionName))
  1445. {
  1446. Url = Name;
  1447. }
  1448. else
  1449. {
  1450. switch (FSProtocol)
  1451. {
  1452. case fsSCPonly:
  1453. Url = "scp://";
  1454. break;
  1455. default:
  1456. assert(false);
  1457. // fallback
  1458. case fsSFTP:
  1459. case fsSFTPonly:
  1460. Url = "sftp://";
  1461. break;
  1462. case fsFTP:
  1463. Url = "ftp://";
  1464. break;
  1465. }
  1466. if (!HostName.IsEmpty() && !UserName.IsEmpty())
  1467. {
  1468. Url += FORMAT("%s@%s", (UserName, HostName));
  1469. }
  1470. else if (!HostName.IsEmpty())
  1471. {
  1472. Url += HostName;
  1473. }
  1474. else
  1475. {
  1476. Url = "";
  1477. }
  1478. }
  1479. return Url;
  1480. }
  1481. //---------------------------------------------------------------------
  1482. void __fastcall TSessionData::SetTimeDifference(TDateTime value)
  1483. {
  1484. SET_SESSION_PROPERTY(TimeDifference);
  1485. }
  1486. //---------------------------------------------------------------------
  1487. void __fastcall TSessionData::SetLocalDirectory(AnsiString value)
  1488. {
  1489. SET_SESSION_PROPERTY(LocalDirectory);
  1490. }
  1491. //---------------------------------------------------------------------
  1492. void __fastcall TSessionData::SetRemoteDirectory(AnsiString value)
  1493. {
  1494. SET_SESSION_PROPERTY(RemoteDirectory);
  1495. }
  1496. //---------------------------------------------------------------------
  1497. void __fastcall TSessionData::SetUpdateDirectories(bool value)
  1498. {
  1499. SET_SESSION_PROPERTY(UpdateDirectories);
  1500. }
  1501. //---------------------------------------------------------------------
  1502. void __fastcall TSessionData::SetCacheDirectories(bool value)
  1503. {
  1504. SET_SESSION_PROPERTY(CacheDirectories);
  1505. }
  1506. //---------------------------------------------------------------------
  1507. void __fastcall TSessionData::SetCacheDirectoryChanges(bool value)
  1508. {
  1509. SET_SESSION_PROPERTY(CacheDirectoryChanges);
  1510. }
  1511. //---------------------------------------------------------------------
  1512. void __fastcall TSessionData::SetPreserveDirectoryChanges(bool value)
  1513. {
  1514. SET_SESSION_PROPERTY(PreserveDirectoryChanges);
  1515. }
  1516. //---------------------------------------------------------------------
  1517. void __fastcall TSessionData::SetResolveSymlinks(bool value)
  1518. {
  1519. SET_SESSION_PROPERTY(ResolveSymlinks);
  1520. }
  1521. //---------------------------------------------------------------------------
  1522. void __fastcall TSessionData::SetDSTMode(TDSTMode value)
  1523. {
  1524. SET_SESSION_PROPERTY(DSTMode);
  1525. }
  1526. //---------------------------------------------------------------------------
  1527. void __fastcall TSessionData::SetDeleteToRecycleBin(bool value)
  1528. {
  1529. SET_SESSION_PROPERTY(DeleteToRecycleBin);
  1530. }
  1531. //---------------------------------------------------------------------------
  1532. void __fastcall TSessionData::SetOverwrittenToRecycleBin(bool value)
  1533. {
  1534. SET_SESSION_PROPERTY(OverwrittenToRecycleBin);
  1535. }
  1536. //---------------------------------------------------------------------------
  1537. void __fastcall TSessionData::SetRecycleBinPath(AnsiString value)
  1538. {
  1539. SET_SESSION_PROPERTY(RecycleBinPath);
  1540. }
  1541. //---------------------------------------------------------------------------
  1542. void __fastcall TSessionData::SetPostLoginCommands(AnsiString value)
  1543. {
  1544. SET_SESSION_PROPERTY(PostLoginCommands);
  1545. }
  1546. //---------------------------------------------------------------------
  1547. void __fastcall TSessionData::SetLockInHome(bool value)
  1548. {
  1549. SET_SESSION_PROPERTY(LockInHome);
  1550. }
  1551. //---------------------------------------------------------------------
  1552. void __fastcall TSessionData::SetSpecial(bool value)
  1553. {
  1554. SET_SESSION_PROPERTY(Special);
  1555. }
  1556. //---------------------------------------------------------------------------
  1557. void __fastcall TSessionData::SetScp1Compatibility(bool value)
  1558. {
  1559. SET_SESSION_PROPERTY(Scp1Compatibility);
  1560. }
  1561. //---------------------------------------------------------------------
  1562. void __fastcall TSessionData::SetTcpNoDelay(bool value)
  1563. {
  1564. SET_SESSION_PROPERTY(TcpNoDelay);
  1565. }
  1566. //---------------------------------------------------------------------
  1567. void __fastcall TSessionData::SetProxyMethod(TProxyMethod value)
  1568. {
  1569. SET_SESSION_PROPERTY(ProxyMethod);
  1570. }
  1571. //---------------------------------------------------------------------
  1572. void __fastcall TSessionData::SetProxyHost(AnsiString value)
  1573. {
  1574. SET_SESSION_PROPERTY(ProxyHost);
  1575. }
  1576. //---------------------------------------------------------------------
  1577. void __fastcall TSessionData::SetProxyPort(int value)
  1578. {
  1579. SET_SESSION_PROPERTY(ProxyPort);
  1580. }
  1581. //---------------------------------------------------------------------
  1582. void __fastcall TSessionData::SetProxyUsername(AnsiString value)
  1583. {
  1584. SET_SESSION_PROPERTY(ProxyUsername);
  1585. }
  1586. //---------------------------------------------------------------------
  1587. void __fastcall TSessionData::SetProxyPassword(AnsiString value)
  1588. {
  1589. value = EncryptPassword(value, ProxyUsername+ProxyHost);
  1590. SET_SESSION_PROPERTY(ProxyPassword);
  1591. }
  1592. //---------------------------------------------------------------------
  1593. AnsiString __fastcall TSessionData::GetProxyPassword() const
  1594. {
  1595. return DecryptPassword(FProxyPassword, ProxyUsername+ProxyHost);
  1596. }
  1597. //---------------------------------------------------------------------
  1598. void __fastcall TSessionData::SetProxyTelnetCommand(AnsiString value)
  1599. {
  1600. SET_SESSION_PROPERTY(ProxyTelnetCommand);
  1601. }
  1602. //---------------------------------------------------------------------
  1603. void __fastcall TSessionData::SetProxyLocalCommand(AnsiString value)
  1604. {
  1605. SET_SESSION_PROPERTY(ProxyLocalCommand);
  1606. }
  1607. //---------------------------------------------------------------------
  1608. void __fastcall TSessionData::SetProxyDNS(TAutoSwitch value)
  1609. {
  1610. SET_SESSION_PROPERTY(ProxyDNS);
  1611. }
  1612. //---------------------------------------------------------------------
  1613. void __fastcall TSessionData::SetProxyLocalhost(bool value)
  1614. {
  1615. SET_SESSION_PROPERTY(ProxyLocalhost);
  1616. }
  1617. //---------------------------------------------------------------------
  1618. void __fastcall TSessionData::SetBug(TSshBug Bug, TAutoSwitch value)
  1619. {
  1620. assert(Bug >= 0 && Bug < LENOF(FBugs));
  1621. SET_SESSION_PROPERTY(Bugs[Bug]);
  1622. }
  1623. //---------------------------------------------------------------------
  1624. TAutoSwitch __fastcall TSessionData::GetBug(TSshBug Bug) const
  1625. {
  1626. assert(Bug >= 0 && Bug < LENOF(FBugs));
  1627. return FBugs[Bug];
  1628. }
  1629. //---------------------------------------------------------------------
  1630. void __fastcall TSessionData::SetCustomParam1(AnsiString value)
  1631. {
  1632. SET_SESSION_PROPERTY(CustomParam1);
  1633. }
  1634. //---------------------------------------------------------------------
  1635. void __fastcall TSessionData::SetCustomParam2(AnsiString value)
  1636. {
  1637. SET_SESSION_PROPERTY(CustomParam2);
  1638. }
  1639. //---------------------------------------------------------------------
  1640. void __fastcall TSessionData::SetSFTPDownloadQueue(int value)
  1641. {
  1642. SET_SESSION_PROPERTY(SFTPDownloadQueue);
  1643. }
  1644. //---------------------------------------------------------------------
  1645. void __fastcall TSessionData::SetSFTPUploadQueue(int value)
  1646. {
  1647. SET_SESSION_PROPERTY(SFTPUploadQueue);
  1648. }
  1649. //---------------------------------------------------------------------
  1650. void __fastcall TSessionData::SetSFTPListingQueue(int value)
  1651. {
  1652. SET_SESSION_PROPERTY(SFTPListingQueue);
  1653. }
  1654. //---------------------------------------------------------------------
  1655. void __fastcall TSessionData::SetSFTPMaxVersion(int value)
  1656. {
  1657. SET_SESSION_PROPERTY(SFTPMaxVersion);
  1658. }
  1659. //---------------------------------------------------------------------
  1660. void __fastcall TSessionData::SetSFTPMaxPacketSize(unsigned long value)
  1661. {
  1662. SET_SESSION_PROPERTY(SFTPMaxPacketSize);
  1663. }
  1664. //---------------------------------------------------------------------
  1665. void __fastcall TSessionData::SetSFTPBug(TSftpBug Bug, TAutoSwitch value)
  1666. {
  1667. assert(Bug >= 0 && Bug < LENOF(FSFTPBugs));
  1668. SET_SESSION_PROPERTY(SFTPBugs[Bug]);
  1669. }
  1670. //---------------------------------------------------------------------
  1671. TAutoSwitch __fastcall TSessionData::GetSFTPBug(TSftpBug Bug) const
  1672. {
  1673. assert(Bug >= 0 && Bug < LENOF(FSFTPBugs));
  1674. return FSFTPBugs[Bug];
  1675. }
  1676. //---------------------------------------------------------------------
  1677. void __fastcall TSessionData::SetSCPLsFullTime(TAutoSwitch value)
  1678. {
  1679. SET_SESSION_PROPERTY(SCPLsFullTime);
  1680. }
  1681. //---------------------------------------------------------------------
  1682. void __fastcall TSessionData::SetFtpListAll(TAutoSwitch value)
  1683. {
  1684. SET_SESSION_PROPERTY(FtpListAll);
  1685. }
  1686. //---------------------------------------------------------------------------
  1687. void __fastcall TSessionData::SetColor(int value)
  1688. {
  1689. SET_SESSION_PROPERTY(Color);
  1690. }
  1691. //---------------------------------------------------------------------------
  1692. void __fastcall TSessionData::SetTunnel(bool value)
  1693. {
  1694. SET_SESSION_PROPERTY(Tunnel);
  1695. }
  1696. //---------------------------------------------------------------------
  1697. void __fastcall TSessionData::SetTunnelHostName(AnsiString value)
  1698. {
  1699. if (FTunnelHostName != value)
  1700. {
  1701. // HostName is key for password encryption
  1702. AnsiString XTunnelPassword = TunnelPassword;
  1703. int P = value.LastDelimiter("@");
  1704. if (P > 0)
  1705. {
  1706. TunnelUserName = value.SubString(1, P - 1);
  1707. value = value.SubString(P + 1, value.Length() - P);
  1708. }
  1709. FTunnelHostName = value;
  1710. FModified = true;
  1711. TunnelPassword = XTunnelPassword;
  1712. if (!XTunnelPassword.IsEmpty())
  1713. {
  1714. XTunnelPassword.Unique();
  1715. memset(XTunnelPassword.c_str(), 0, XTunnelPassword.Length());
  1716. }
  1717. }
  1718. }
  1719. //---------------------------------------------------------------------
  1720. void __fastcall TSessionData::SetTunnelPortNumber(int value)
  1721. {
  1722. SET_SESSION_PROPERTY(TunnelPortNumber);
  1723. }
  1724. //---------------------------------------------------------------------
  1725. void __fastcall TSessionData::SetTunnelUserName(AnsiString value)
  1726. {
  1727. // TunnelUserName is key for password encryption
  1728. AnsiString XTunnelPassword = TunnelPassword;
  1729. SET_SESSION_PROPERTY(TunnelUserName);
  1730. TunnelPassword = XTunnelPassword;
  1731. if (!XTunnelPassword.IsEmpty())
  1732. {
  1733. XTunnelPassword.Unique();
  1734. memset(XTunnelPassword.c_str(), 0, XTunnelPassword.Length());
  1735. }
  1736. }
  1737. //---------------------------------------------------------------------
  1738. void __fastcall TSessionData::SetTunnelPassword(AnsiString value)
  1739. {
  1740. value = EncryptPassword(value, TunnelUserName+TunnelHostName);
  1741. SET_SESSION_PROPERTY(TunnelPassword);
  1742. }
  1743. //---------------------------------------------------------------------
  1744. AnsiString __fastcall TSessionData::GetTunnelPassword()
  1745. {
  1746. return DecryptPassword(FTunnelPassword, TunnelUserName+TunnelHostName);
  1747. }
  1748. //---------------------------------------------------------------------
  1749. void __fastcall TSessionData::SetTunnelPublicKeyFile(AnsiString value)
  1750. {
  1751. if (FTunnelPublicKeyFile != value)
  1752. {
  1753. FTunnelPublicKeyFile = StripPathQuotes(value);
  1754. FModified = true;
  1755. }
  1756. }
  1757. //---------------------------------------------------------------------
  1758. void __fastcall TSessionData::SetTunnelLocalPortNumber(int value)
  1759. {
  1760. SET_SESSION_PROPERTY(TunnelLocalPortNumber);
  1761. }
  1762. //---------------------------------------------------------------------
  1763. bool __fastcall TSessionData::GetTunnelAutoassignLocalPortNumber()
  1764. {
  1765. return (FTunnelLocalPortNumber <= 0);
  1766. }
  1767. //---------------------------------------------------------------------
  1768. void __fastcall TSessionData::SetTunnelPortFwd(AnsiString value)
  1769. {
  1770. SET_SESSION_PROPERTY(TunnelPortFwd);
  1771. }
  1772. //---------------------------------------------------------------------
  1773. void __fastcall TSessionData::SetFtpPasvMode(bool value)
  1774. {
  1775. SET_SESSION_PROPERTY(FtpPasvMode);
  1776. }
  1777. //---------------------------------------------------------------------
  1778. void __fastcall TSessionData::SetFtpAccount(AnsiString value)
  1779. {
  1780. SET_SESSION_PROPERTY(FtpAccount);
  1781. }
  1782. //---------------------------------------------------------------------
  1783. void __fastcall TSessionData::SetFtpPingInterval(int value)
  1784. {
  1785. SET_SESSION_PROPERTY(FtpPingInterval);
  1786. }
  1787. //---------------------------------------------------------------------------
  1788. TDateTime __fastcall TSessionData::GetFtpPingIntervalDT()
  1789. {
  1790. return SecToDateTime(FtpPingInterval);
  1791. }
  1792. //---------------------------------------------------------------------------
  1793. void __fastcall TSessionData::SetFtpPingType(TPingType value)
  1794. {
  1795. SET_SESSION_PROPERTY(FtpPingType);
  1796. }
  1797. //---------------------------------------------------------------------------
  1798. void __fastcall TSessionData::SetFtps(TFtps value)
  1799. {
  1800. SET_SESSION_PROPERTY(Ftps);
  1801. }
  1802. //---------------------------------------------------------------------
  1803. void __fastcall TSessionData::SetUtf(TAutoSwitch value)
  1804. {
  1805. SET_SESSION_PROPERTY(Utf);
  1806. }
  1807. //---------------------------------------------------------------------
  1808. void __fastcall TSessionData::SetHostKey(AnsiString value)
  1809. {
  1810. SET_SESSION_PROPERTY(HostKey);
  1811. }
  1812. //---------------------------------------------------------------------
  1813. AnsiString __fastcall TSessionData::GetInfoTip()
  1814. {
  1815. if (UsesSsh)
  1816. {
  1817. return FMTLOAD(SESSION_INFO_TIP,
  1818. (HostName, UserName,
  1819. (PublicKeyFile.IsEmpty() ? LoadStr(NO_STR) : LoadStr(YES_STR)),
  1820. SshProtStr, FSProtocolStr));
  1821. }
  1822. else
  1823. {
  1824. return FMTLOAD(SESSION_INFO_TIP_NO_SSH,
  1825. (HostName, UserName, FSProtocolStr));
  1826. }
  1827. }
  1828. //=== TStoredSessionList ----------------------------------------------
  1829. __fastcall TStoredSessionList::TStoredSessionList(bool aReadOnly):
  1830. TNamedObjectList(), FReadOnly(aReadOnly)
  1831. {
  1832. assert(Configuration);
  1833. FDefaultSettings = new TSessionData(DefaultSessionName);
  1834. }
  1835. //---------------------------------------------------------------------
  1836. __fastcall TStoredSessionList::~TStoredSessionList()
  1837. {
  1838. assert(Configuration);
  1839. delete FDefaultSettings;
  1840. }
  1841. //---------------------------------------------------------------------
  1842. void __fastcall TStoredSessionList::Load(THierarchicalStorage * Storage,
  1843. bool AsModified, bool UseDefaults)
  1844. {
  1845. TStringList *SubKeys = new TStringList();
  1846. TList * Loaded = new TList;
  1847. try
  1848. {
  1849. Storage->GetSubKeyNames(SubKeys);
  1850. for (int Index = 0; Index < SubKeys->Count; Index++)
  1851. {
  1852. TSessionData *SessionData;
  1853. AnsiString SessionName = SubKeys->Strings[Index];
  1854. bool ValidName = true;
  1855. try
  1856. {
  1857. TSessionData::ValidatePath(SessionName);
  1858. }
  1859. catch(...)
  1860. {
  1861. ValidName = false;
  1862. }
  1863. if (ValidName)
  1864. {
  1865. if (SessionName == FDefaultSettings->Name) SessionData = FDefaultSettings;
  1866. else SessionData = (TSessionData*)FindByName(SessionName);
  1867. if ((SessionData != FDefaultSettings) || !UseDefaults)
  1868. {
  1869. if (!SessionData)
  1870. {
  1871. SessionData = new TSessionData("");
  1872. if (UseDefaults)
  1873. {
  1874. SessionData->Assign(DefaultSettings);
  1875. }
  1876. SessionData->Name = SessionName;
  1877. Add(SessionData);
  1878. }
  1879. Loaded->Add(SessionData);
  1880. SessionData->Load(Storage);
  1881. if (AsModified)
  1882. {
  1883. SessionData->Modified = true;
  1884. }
  1885. }
  1886. }
  1887. }
  1888. if (!AsModified)
  1889. {
  1890. for (int Index = 0; Index < TObjectList::Count; Index++)
  1891. {
  1892. if (Loaded->IndexOf(Items[Index]) < 0)
  1893. {
  1894. Delete(Index);
  1895. Index--;
  1896. }
  1897. }
  1898. }
  1899. }
  1900. __finally
  1901. {
  1902. delete SubKeys;
  1903. delete Loaded;
  1904. }
  1905. }
  1906. //---------------------------------------------------------------------
  1907. void __fastcall TStoredSessionList::Load(AnsiString aKey, bool UseDefaults)
  1908. {
  1909. TRegistryStorage * Storage = new TRegistryStorage(aKey);
  1910. try {
  1911. if (Storage->OpenRootKey(False)) Load(Storage, false, UseDefaults);
  1912. } __finally {
  1913. delete Storage;
  1914. }
  1915. }
  1916. //---------------------------------------------------------------------
  1917. void __fastcall TStoredSessionList::Load()
  1918. {
  1919. THierarchicalStorage * Storage = Configuration->CreateScpStorage(true);
  1920. try {
  1921. if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, False))
  1922. Load(Storage);
  1923. } __finally {
  1924. delete Storage;
  1925. }
  1926. }
  1927. //---------------------------------------------------------------------
  1928. void __fastcall TStoredSessionList::Save(THierarchicalStorage * Storage, bool All)
  1929. {
  1930. TSessionData * FactoryDefaults = new TSessionData("");
  1931. try
  1932. {
  1933. if (All || FDefaultSettings->Modified)
  1934. {
  1935. FDefaultSettings->Save(Storage, false, FactoryDefaults);
  1936. }
  1937. for (int Index = 0; Index < Count+HiddenCount; Index++)
  1938. {
  1939. TSessionData *SessionData = (TSessionData *)Items[Index];
  1940. if (All || SessionData->Modified)
  1941. {
  1942. SessionData->Save(Storage, false, FactoryDefaults);
  1943. }
  1944. }
  1945. }
  1946. __finally
  1947. {
  1948. delete FactoryDefaults;
  1949. }
  1950. }
  1951. //---------------------------------------------------------------------
  1952. void __fastcall TStoredSessionList::Save(bool All, bool Explicit)
  1953. {
  1954. THierarchicalStorage * Storage = Configuration->CreateScpStorage(true);
  1955. try {
  1956. Storage->AccessMode = smReadWrite;
  1957. Storage->Explicit = Explicit;
  1958. if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, True))
  1959. Save(Storage, All);
  1960. } __finally {
  1961. delete Storage;
  1962. }
  1963. Saved();
  1964. }
  1965. //---------------------------------------------------------------------
  1966. void __fastcall TStoredSessionList::Saved()
  1967. {
  1968. FDefaultSettings->Modified = false;
  1969. for (int Index = 0; Index < Count + HiddenCount; Index++)
  1970. {
  1971. ((TSessionData *)Items[Index])->Modified = false;
  1972. }
  1973. }
  1974. //---------------------------------------------------------------------
  1975. void __fastcall TStoredSessionList::Export(const AnsiString FileName)
  1976. {
  1977. THierarchicalStorage * Storage = new TIniFileStorage(FileName);
  1978. try
  1979. {
  1980. Storage->AccessMode = smReadWrite;
  1981. if (Storage->OpenSubKey(Configuration->StoredSessionsSubKey, true))
  1982. {
  1983. Save(Storage, true);
  1984. }
  1985. }
  1986. __finally
  1987. {
  1988. delete Storage;
  1989. }
  1990. }
  1991. //---------------------------------------------------------------------
  1992. void __fastcall TStoredSessionList::SelectAll(bool Select)
  1993. {
  1994. for (int Index = 0; Index < Count; Index++)
  1995. Sessions[Index]->Selected = Select;
  1996. }
  1997. //---------------------------------------------------------------------
  1998. void __fastcall TStoredSessionList::Import(TStoredSessionList * From,
  1999. bool OnlySelected)
  2000. {
  2001. for (int Index = 0; Index < From->Count; Index++)
  2002. {
  2003. if (!OnlySelected || From->Sessions[Index]->Selected)
  2004. {
  2005. TSessionData *Session = new TSessionData("");
  2006. Session->Assign(From->Sessions[Index]);
  2007. Session->Modified = true;
  2008. Session->MakeUniqueIn(this);
  2009. Add(Session);
  2010. }
  2011. }
  2012. // only modified, explicit
  2013. Save(false, true);
  2014. }
  2015. //---------------------------------------------------------------------
  2016. void __fastcall TStoredSessionList::SelectSessionsToImport
  2017. (TStoredSessionList * Dest, bool SSHOnly)
  2018. {
  2019. for (int Index = 0; Index < Count; Index++)
  2020. {
  2021. Sessions[Index]->Selected =
  2022. (!SSHOnly || (Sessions[Index]->Protocol == ptSSH)) &&
  2023. !Dest->FindByName(Sessions[Index]->Name);
  2024. }
  2025. }
  2026. //---------------------------------------------------------------------
  2027. void __fastcall TStoredSessionList::Cleanup()
  2028. {
  2029. try {
  2030. if (Configuration->Storage == stRegistry) Clear();
  2031. TRegistryStorage * Storage = new TRegistryStorage(Configuration->RegistryStorageKey);
  2032. try {
  2033. Storage->AccessMode = smReadWrite;
  2034. if (Storage->OpenRootKey(False))
  2035. Storage->RecursiveDeleteSubKey(Configuration->StoredSessionsSubKey);
  2036. } __finally {
  2037. delete Storage;
  2038. }
  2039. } catch (Exception &E) {
  2040. throw ExtException(&E, CLEANUP_SESSIONS_ERROR);
  2041. }
  2042. }
  2043. //---------------------------------------------------------------------------
  2044. int __fastcall TStoredSessionList::IndexOf(TSessionData * Data)
  2045. {
  2046. for (int Index = 0; Index < Count; Index++)
  2047. if (Data == Sessions[Index]) return Index;
  2048. return -1;
  2049. }
  2050. //---------------------------------------------------------------------------
  2051. TSessionData * __fastcall TStoredSessionList::NewSession(
  2052. AnsiString SessionName, TSessionData * Session)
  2053. {
  2054. TSessionData * DuplicateSession = (TSessionData*)FindByName(SessionName);
  2055. if (!DuplicateSession)
  2056. {
  2057. DuplicateSession = new TSessionData("");
  2058. DuplicateSession->Assign(Session);
  2059. DuplicateSession->Name = SessionName;
  2060. // make sure, that new stored session is saved to registry
  2061. DuplicateSession->Modified = true;
  2062. Add(DuplicateSession);
  2063. }
  2064. else
  2065. {
  2066. DuplicateSession->Assign(Session);
  2067. DuplicateSession->Name = SessionName;
  2068. DuplicateSession->Modified = true;
  2069. }
  2070. // list was saved here before to default storage, but it would not allow
  2071. // to work with special lists (export/import) not using default storage
  2072. return DuplicateSession;
  2073. }
  2074. //---------------------------------------------------------------------------
  2075. void __fastcall TStoredSessionList::SetDefaultSettings(TSessionData * value)
  2076. {
  2077. assert(FDefaultSettings);
  2078. if (FDefaultSettings != value)
  2079. {
  2080. FDefaultSettings->Assign(value);
  2081. FDefaultSettings->Name = DefaultSessionName;
  2082. if (!FReadOnly)
  2083. {
  2084. // only modified, explicit
  2085. Save(false, true);
  2086. }
  2087. }
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TStoredSessionList::ImportHostKeys(const AnsiString TargetKey,
  2091. const AnsiString SourceKey, TStoredSessionList * Sessions,
  2092. bool OnlySelected)
  2093. {
  2094. TRegistryStorage * SourceStorage = NULL;
  2095. TRegistryStorage * TargetStorage = NULL;
  2096. TStringList * KeyList = NULL;
  2097. try
  2098. {
  2099. SourceStorage = new TRegistryStorage(SourceKey);
  2100. TargetStorage = new TRegistryStorage(TargetKey);
  2101. TargetStorage->AccessMode = smReadWrite;
  2102. KeyList = new TStringList();
  2103. if (SourceStorage->OpenRootKey(false) &&
  2104. TargetStorage->OpenRootKey(true))
  2105. {
  2106. SourceStorage->GetValueNames(KeyList);
  2107. TSessionData * Session;
  2108. AnsiString HostKeyName;
  2109. assert(Sessions != NULL);
  2110. for (int Index = 0; Index < Sessions->Count; Index++)
  2111. {
  2112. Session = Sessions->Sessions[Index];
  2113. if (!OnlySelected || Session->Selected)
  2114. {
  2115. HostKeyName = PuttyMungeStr(FORMAT("@%d:%s", (Session->PortNumber, Session->HostName)));
  2116. AnsiString KeyName;
  2117. for (int KeyIndex = 0; KeyIndex < KeyList->Count; KeyIndex++)
  2118. {
  2119. KeyName = KeyList->Strings[KeyIndex];
  2120. int P = KeyName.Pos(HostKeyName);
  2121. if ((P > 0) && (P == KeyName.Length() - HostKeyName.Length() + 1))
  2122. {
  2123. TargetStorage->WriteStringRaw(KeyName,
  2124. SourceStorage->ReadStringRaw(KeyName, ""));
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. }
  2131. __finally
  2132. {
  2133. delete SourceStorage;
  2134. delete TargetStorage;
  2135. delete KeyList;
  2136. }
  2137. }
  2138. //---------------------------------------------------------------------------
  2139. TSessionData * __fastcall TStoredSessionList::ParseUrl(AnsiString Url,
  2140. TOptions * Options, bool & DefaultsOnly, AnsiString * FileName,
  2141. bool * AProtocolDefined)
  2142. {
  2143. TSessionData * Data = new TSessionData("");
  2144. try
  2145. {
  2146. Data->ParseUrl(Url, Options, this, DefaultsOnly, FileName, AProtocolDefined);
  2147. }
  2148. catch(...)
  2149. {
  2150. delete Data;
  2151. throw;
  2152. }
  2153. return Data;
  2154. }