common_p.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*
  2. * Supporting routines used in common by all the various components of
  3. * the SSH system.
  4. */
  5. #include <assert.h>
  6. #include <stdlib.h>
  7. #include "putty.h"
  8. #include "mpint.h"
  9. #include "ssh.h"
  10. #include "storage.h"
  11. #include "bpp.h"
  12. #include "ppl.h"
  13. #include "channel.h"
  14. /* ----------------------------------------------------------------------
  15. * Implementation of PacketQueue.
  16. */
  17. static void pq_ensure_unlinked(PacketQueueNode *node)
  18. {
  19. if (node->on_free_queue) {
  20. node->next->prev = node->prev;
  21. node->prev->next = node->next;
  22. } else {
  23. assert(!node->next);
  24. assert(!node->prev);
  25. }
  26. }
  27. void pq_base_push(PacketQueueBase *pqb, PacketQueueNode *node)
  28. {
  29. pq_ensure_unlinked(node);
  30. node->next = &pqb->end;
  31. node->prev = pqb->end.prev;
  32. node->next->prev = node;
  33. node->prev->next = node;
  34. pqb->total_size += node->formal_size;
  35. if (pqb->ic)
  36. queue_idempotent_callback(pqb->ic);
  37. }
  38. void pq_base_push_front(PacketQueueBase *pqb, PacketQueueNode *node)
  39. {
  40. pq_ensure_unlinked(node);
  41. node->prev = &pqb->end;
  42. node->next = pqb->end.next;
  43. node->next->prev = node;
  44. node->prev->next = node;
  45. pqb->total_size += node->formal_size;
  46. if (pqb->ic)
  47. queue_idempotent_callback(pqb->ic);
  48. }
  49. #ifndef WINSCP
  50. static PacketQueueNode pktin_freeq_head = {
  51. &pktin_freeq_head, &pktin_freeq_head, true
  52. };
  53. #endif
  54. /*WINSCP static*/ void pktin_free_queue_callback(void *vctx)
  55. {
  56. struct callback_set * set = (struct callback_set *)vctx;
  57. while (set->pktin_freeq_head->next != set->pktin_freeq_head) {
  58. PacketQueueNode *node = set->pktin_freeq_head->next;
  59. PktIn *pktin = container_of(node, PktIn, qnode);
  60. set->pktin_freeq_head->next = node->next;
  61. sfree(pktin);
  62. }
  63. set->pktin_freeq_head->prev = set->pktin_freeq_head;
  64. }
  65. #ifndef WINSCP
  66. static IdempotentCallback ic_pktin_free = {
  67. pktin_free_queue_callback, NULL, false
  68. };
  69. #endif
  70. static inline void pq_unlink_common(PacketQueueBase *pqb,
  71. PacketQueueNode *node)
  72. {
  73. node->next->prev = node->prev;
  74. node->prev->next = node->next;
  75. /* Check total_size doesn't drift out of sync downwards, by
  76. * ensuring it doesn't underflow when we do this subtraction */
  77. assert(pqb->total_size >= node->formal_size);
  78. pqb->total_size -= node->formal_size;
  79. /* Check total_size doesn't drift out of sync upwards, by checking
  80. * that it's returned to exactly zero whenever a queue is
  81. * emptied */
  82. assert(pqb->end.next != &pqb->end || pqb->total_size == 0);
  83. }
  84. static PktIn *pq_in_after(PacketQueueBase *pqb,
  85. PacketQueueNode *prev, bool pop)
  86. {
  87. PacketQueueNode *node = prev->next;
  88. if (node == &pqb->end)
  89. return NULL;
  90. if (pop) {
  91. #ifdef WINSCP
  92. struct callback_set * set = get_seat_callback_set(pqb->seat);
  93. assert(set != NULL);
  94. if (set->ic_pktin_free == NULL)
  95. {
  96. set->pktin_freeq_head = snew(PacketQueueNode);
  97. set->pktin_freeq_head->next = set->pktin_freeq_head;
  98. set->pktin_freeq_head->prev = set->pktin_freeq_head;
  99. set->pktin_freeq_head->on_free_queue = TRUE;
  100. set->ic_pktin_free = snew(IdempotentCallback);
  101. set->ic_pktin_free->fn = pktin_free_queue_callback;
  102. set->ic_pktin_free->ctx = set;
  103. set->ic_pktin_free->queued = FALSE;
  104. set->ic_pktin_free->set = set;
  105. }
  106. #endif
  107. pq_unlink_common(pqb, node);
  108. node->prev = set->pktin_freeq_head->prev; // WINSCP
  109. node->next = set->pktin_freeq_head; // WINSCP
  110. node->next->prev = node;
  111. node->prev->next = node;
  112. node->on_free_queue = true;
  113. queue_idempotent_callback(set->ic_pktin_free); // WINSCP
  114. }
  115. return container_of(node, PktIn, qnode);
  116. }
  117. static PktOut *pq_out_after(PacketQueueBase *pqb,
  118. PacketQueueNode *prev, bool pop)
  119. {
  120. PacketQueueNode *node = prev->next;
  121. if (node == &pqb->end)
  122. return NULL;
  123. if (pop) {
  124. pq_unlink_common(pqb, node);
  125. node->prev = node->next = NULL;
  126. }
  127. return container_of(node, PktOut, qnode);
  128. }
  129. void pq_in_init(PktInQueue *pq, Seat * seat) // WINSCP
  130. {
  131. pq->pqb.ic = NULL;
  132. pq->pqb.seat = seat;
  133. pq->pqb.end.next = pq->pqb.end.prev = &pq->pqb.end;
  134. pq->after = pq_in_after;
  135. pq->pqb.total_size = 0;
  136. }
  137. void pq_out_init(PktOutQueue *pq, Seat * seat) // WINSCP
  138. {
  139. pq->pqb.ic = NULL;
  140. pq->pqb.seat = seat;
  141. pq->pqb.end.next = pq->pqb.end.prev = &pq->pqb.end;
  142. pq->after = pq_out_after;
  143. pq->pqb.total_size = 0;
  144. }
  145. void pq_in_clear(PktInQueue *pq)
  146. {
  147. PktIn *pkt;
  148. pq->pqb.ic = NULL;
  149. while ((pkt = pq_pop(pq)) != NULL) {
  150. /* No need to actually free these packets: pq_pop on a
  151. * PktInQueue will automatically move them to the free
  152. * queue. */
  153. }
  154. }
  155. void pq_out_clear(PktOutQueue *pq)
  156. {
  157. PktOut *pkt;
  158. pq->pqb.ic = NULL;
  159. while ((pkt = pq_pop(pq)) != NULL)
  160. ssh_free_pktout(pkt);
  161. }
  162. /*
  163. * Concatenate the contents of the two queues q1 and q2, and leave the
  164. * result in qdest. qdest must be either empty, or one of the input
  165. * queues.
  166. */
  167. void pq_base_concatenate(PacketQueueBase *qdest,
  168. PacketQueueBase *q1, PacketQueueBase *q2)
  169. {
  170. struct PacketQueueNode *head1, *tail1, *head2, *tail2;
  171. size_t total_size = q1->total_size + q2->total_size;
  172. /*
  173. * Extract the contents from both input queues, and empty them.
  174. */
  175. head1 = (q1->end.next == &q1->end ? NULL : q1->end.next);
  176. tail1 = (q1->end.prev == &q1->end ? NULL : q1->end.prev);
  177. head2 = (q2->end.next == &q2->end ? NULL : q2->end.next);
  178. tail2 = (q2->end.prev == &q2->end ? NULL : q2->end.prev);
  179. q1->end.next = q1->end.prev = &q1->end;
  180. q2->end.next = q2->end.prev = &q2->end;
  181. q1->total_size = q2->total_size = 0;
  182. /*
  183. * Link the two lists together, handling the case where one or
  184. * both is empty.
  185. */
  186. if (tail1)
  187. tail1->next = head2;
  188. else
  189. head1 = head2;
  190. if (head2)
  191. head2->prev = tail1;
  192. else
  193. tail2 = tail1;
  194. /*
  195. * Check the destination queue is currently empty. (If it was one
  196. * of the input queues, then it will be, because we emptied both
  197. * of those just a moment ago.)
  198. */
  199. assert(qdest->end.next == &qdest->end);
  200. assert(qdest->end.prev == &qdest->end);
  201. /*
  202. * If our concatenated list has anything in it, then put it in
  203. * dest.
  204. */
  205. if (!head1) {
  206. assert(!tail2);
  207. } else {
  208. assert(tail2);
  209. qdest->end.next = head1;
  210. qdest->end.prev = tail2;
  211. head1->prev = &qdest->end;
  212. tail2->next = &qdest->end;
  213. if (qdest->ic)
  214. queue_idempotent_callback(qdest->ic);
  215. }
  216. qdest->total_size = total_size;
  217. }
  218. /* ----------------------------------------------------------------------
  219. * Low-level functions for the packet structures themselves.
  220. */
  221. static void ssh_pkt_BinarySink_write(BinarySink *bs,
  222. const void *data, size_t len);
  223. PktOut *ssh_new_packet(void)
  224. {
  225. PktOut *pkt = snew(PktOut);
  226. BinarySink_INIT(pkt, ssh_pkt_BinarySink_write);
  227. pkt->data = NULL;
  228. pkt->length = 0;
  229. pkt->maxlen = 0;
  230. pkt->downstream_id = 0;
  231. pkt->additional_log_text = NULL;
  232. pkt->qnode.next = pkt->qnode.prev = NULL;
  233. pkt->qnode.on_free_queue = false;
  234. return pkt;
  235. }
  236. static void ssh_pkt_adddata(PktOut *pkt, const void *data, int len)
  237. {
  238. sgrowarrayn_nm(pkt->data, pkt->maxlen, pkt->length, len);
  239. memcpy(pkt->data + pkt->length, data, len);
  240. pkt->length += len;
  241. pkt->qnode.formal_size = pkt->length;
  242. }
  243. static void ssh_pkt_BinarySink_write(BinarySink *bs,
  244. const void *data, size_t len)
  245. {
  246. PktOut *pkt = BinarySink_DOWNCAST(bs, PktOut);
  247. ssh_pkt_adddata(pkt, data, len);
  248. }
  249. void ssh_free_pktout(PktOut *pkt)
  250. {
  251. sfree(pkt->data);
  252. sfree(pkt);
  253. }
  254. /* ----------------------------------------------------------------------
  255. * Implement zombiechan_new() and its trivial vtable.
  256. */
  257. static void zombiechan_free(Channel *chan);
  258. static size_t zombiechan_send(
  259. Channel *chan, bool is_stderr, const void *, size_t);
  260. static void zombiechan_set_input_wanted(Channel *chan, bool wanted);
  261. static void zombiechan_do_nothing(Channel *chan);
  262. static void zombiechan_open_failure(Channel *chan, const char *);
  263. static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof);
  264. static char *zombiechan_log_close_msg(Channel *chan) { return NULL; }
  265. static const ChannelVtable zombiechan_channelvt = {
  266. /*.free =*/ zombiechan_free,
  267. /*.open_confirmation =*/ zombiechan_do_nothing,
  268. /*.open_failed =*/ zombiechan_open_failure,
  269. /*.send =*/ zombiechan_send,
  270. /*.send_eof =*/ zombiechan_do_nothing,
  271. /*.set_input_wanted =*/ zombiechan_set_input_wanted,
  272. /*.log_close_msg =*/ zombiechan_log_close_msg,
  273. /*.want_close =*/ zombiechan_want_close,
  274. /*.rcvd_exit_status =*/ chan_no_exit_status,
  275. /*.rcvd_exit_signal =*/ chan_no_exit_signal,
  276. /*.rcvd_exit_signal_numeric =*/ chan_no_exit_signal_numeric,
  277. /*.run_shell =*/ chan_no_run_shell,
  278. /*.run_command =*/ chan_no_run_command,
  279. /*.run_subsystem =*/ chan_no_run_subsystem,
  280. /*.enable_x11_forwarding =*/ chan_no_enable_x11_forwarding,
  281. /*.enable_agent_forwarding =*/ chan_no_enable_agent_forwarding,
  282. /*.allocate_pty =*/ chan_no_allocate_pty,
  283. /*.set_env =*/ chan_no_set_env,
  284. /*.send_break =*/ chan_no_send_break,
  285. /*.send_signal =*/ chan_no_send_signal,
  286. /*.change_window_size =*/ chan_no_change_window_size,
  287. /*.request_response =*/ chan_no_request_response,
  288. };
  289. Channel *zombiechan_new(void)
  290. {
  291. Channel *chan = snew(Channel);
  292. chan->vt = &zombiechan_channelvt;
  293. chan->initial_fixed_window_size = 0;
  294. return chan;
  295. }
  296. static void zombiechan_free(Channel *chan)
  297. {
  298. assert(chan->vt == &zombiechan_channelvt);
  299. sfree(chan);
  300. }
  301. static void zombiechan_do_nothing(Channel *chan)
  302. {
  303. assert(chan->vt == &zombiechan_channelvt);
  304. }
  305. static void zombiechan_open_failure(Channel *chan, const char *errtext)
  306. {
  307. assert(chan->vt == &zombiechan_channelvt);
  308. }
  309. static size_t zombiechan_send(Channel *chan, bool is_stderr,
  310. const void *data, size_t length)
  311. {
  312. assert(chan->vt == &zombiechan_channelvt);
  313. return 0;
  314. }
  315. static void zombiechan_set_input_wanted(Channel *chan, bool enable)
  316. {
  317. assert(chan->vt == &zombiechan_channelvt);
  318. }
  319. static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof)
  320. {
  321. return true;
  322. }
  323. /* ----------------------------------------------------------------------
  324. * Common routines for handling SSH tty modes.
  325. */
  326. static unsigned real_ttymode_opcode(unsigned our_opcode, int ssh_version)
  327. {
  328. switch (our_opcode) {
  329. case TTYMODE_ISPEED:
  330. return ssh_version == 1 ? TTYMODE_ISPEED_SSH1 : TTYMODE_ISPEED_SSH2;
  331. case TTYMODE_OSPEED:
  332. return ssh_version == 1 ? TTYMODE_OSPEED_SSH1 : TTYMODE_OSPEED_SSH2;
  333. default:
  334. return our_opcode;
  335. }
  336. }
  337. static unsigned our_ttymode_opcode(unsigned real_opcode, int ssh_version)
  338. {
  339. if (ssh_version == 1) {
  340. switch (real_opcode) {
  341. case TTYMODE_ISPEED_SSH1:
  342. return TTYMODE_ISPEED;
  343. case TTYMODE_OSPEED_SSH1:
  344. return TTYMODE_OSPEED;
  345. default:
  346. return real_opcode;
  347. }
  348. } else {
  349. switch (real_opcode) {
  350. case TTYMODE_ISPEED_SSH2:
  351. return TTYMODE_ISPEED;
  352. case TTYMODE_OSPEED_SSH2:
  353. return TTYMODE_OSPEED;
  354. default:
  355. return real_opcode;
  356. }
  357. }
  358. }
  359. struct ssh_ttymodes get_ttymodes_from_conf(Seat *seat, Conf *conf)
  360. {
  361. struct ssh_ttymodes modes;
  362. size_t i;
  363. static const struct mode_name_type {
  364. const char *mode;
  365. int opcode;
  366. enum { TYPE_CHAR, TYPE_BOOL } type;
  367. } modes_names_types[] = {
  368. #define TTYMODE_CHAR(name, val, index) { #name, val, TYPE_CHAR },
  369. #define TTYMODE_FLAG(name, val, field, mask) { #name, val, TYPE_BOOL },
  370. #include "ttymode-list.h"
  371. #undef TTYMODE_CHAR
  372. #undef TTYMODE_FLAG
  373. };
  374. memset(&modes, 0, sizeof(modes));
  375. for (i = 0; i < lenof(modes_names_types); i++) {
  376. const struct mode_name_type *mode = &modes_names_types[i];
  377. const char *sval = conf_get_str_str(conf, CONF_ttymodes, mode->mode);
  378. char *to_free = NULL;
  379. if (!sval)
  380. sval = "N"; /* just in case */
  381. /*
  382. * sval[0] can be
  383. * - 'V', indicating that an explicit value follows it;
  384. * - 'A', indicating that we should pass the value through from
  385. * the local environment via get_ttymode; or
  386. * - 'N', indicating that we should explicitly not send this
  387. * mode.
  388. */
  389. if (sval[0] == 'A') {
  390. sval = to_free = seat_get_ttymode(seat, mode->mode);
  391. } else if (sval[0] == 'V') {
  392. sval++; /* skip the 'V' */
  393. } else {
  394. /* else 'N', or something from the future we don't understand */
  395. continue;
  396. }
  397. if (sval) {
  398. /*
  399. * Parse the string representation of the tty mode
  400. * into the integer value it will take on the wire.
  401. */
  402. unsigned ival = 0;
  403. switch (mode->type) {
  404. case TYPE_CHAR:
  405. if (*sval) {
  406. char *next = NULL;
  407. /* We know ctrlparse won't write to the string, so
  408. * casting away const is ugly but allowable. */
  409. ival = ctrlparse((char *)sval, &next);
  410. if (!next)
  411. ival = sval[0];
  412. } else {
  413. ival = 255; /* special value meaning "don't set" */
  414. }
  415. break;
  416. case TYPE_BOOL:
  417. if (stricmp(sval, "yes") == 0 ||
  418. stricmp(sval, "on") == 0 ||
  419. stricmp(sval, "true") == 0 ||
  420. stricmp(sval, "+") == 0)
  421. ival = 1; /* true */
  422. else if (stricmp(sval, "no") == 0 ||
  423. stricmp(sval, "off") == 0 ||
  424. stricmp(sval, "false") == 0 ||
  425. stricmp(sval, "-") == 0)
  426. ival = 0; /* false */
  427. else
  428. ival = (atoi(sval) != 0);
  429. break;
  430. default:
  431. unreachable("Bad mode->type");
  432. }
  433. modes.have_mode[mode->opcode] = true;
  434. modes.mode_val[mode->opcode] = ival;
  435. }
  436. sfree(to_free);
  437. }
  438. {
  439. unsigned ospeed, ispeed;
  440. /* Unpick the terminal-speed config string. */
  441. ospeed = ispeed = 38400; /* last-resort defaults */
  442. sscanf(conf_get_str(conf, CONF_termspeed), "%u,%u", &ospeed, &ispeed);
  443. /* Currently we unconditionally set these */
  444. modes.have_mode[TTYMODE_ISPEED] = true;
  445. modes.mode_val[TTYMODE_ISPEED] = ispeed;
  446. modes.have_mode[TTYMODE_OSPEED] = true;
  447. modes.mode_val[TTYMODE_OSPEED] = ospeed;
  448. }
  449. return modes;
  450. }
  451. struct ssh_ttymodes read_ttymodes_from_packet(
  452. BinarySource *bs, int ssh_version)
  453. {
  454. struct ssh_ttymodes modes;
  455. memset(&modes, 0, sizeof(modes));
  456. while (1) {
  457. unsigned real_opcode, our_opcode;
  458. real_opcode = get_byte(bs);
  459. if (real_opcode == TTYMODE_END_OF_LIST)
  460. break;
  461. if (real_opcode >= 160) {
  462. /*
  463. * RFC 4254 (and the SSH 1.5 spec): "Opcodes 160 to 255
  464. * are not yet defined, and cause parsing to stop (they
  465. * should only be used after any other data)."
  466. *
  467. * My interpretation of this is that if one of these
  468. * opcodes appears, it's not a parse _error_, but it is
  469. * something that we don't know how to parse even well
  470. * enough to step over it to find the next opcode, so we
  471. * stop parsing now and assume that the rest of the string
  472. * is composed entirely of things we don't understand and
  473. * (as usual for unsupported terminal modes) silently
  474. * ignore.
  475. */
  476. return modes;
  477. }
  478. our_opcode = our_ttymode_opcode(real_opcode, ssh_version);
  479. assert(our_opcode < TTYMODE_LIMIT);
  480. modes.have_mode[our_opcode] = true;
  481. if (ssh_version == 1 && real_opcode >= 1 && real_opcode <= 127)
  482. modes.mode_val[our_opcode] = get_byte(bs);
  483. else
  484. modes.mode_val[our_opcode] = get_uint32(bs);
  485. }
  486. return modes;
  487. }
  488. void write_ttymodes_to_packet(BinarySink *bs, int ssh_version,
  489. struct ssh_ttymodes modes)
  490. {
  491. unsigned i;
  492. for (i = 0; i < TTYMODE_LIMIT; i++) {
  493. if (modes.have_mode[i]) {
  494. unsigned val = modes.mode_val[i];
  495. unsigned opcode = real_ttymode_opcode(i, ssh_version);
  496. put_byte(bs, opcode);
  497. if (ssh_version == 1 && opcode >= 1 && opcode <= 127)
  498. put_byte(bs, val);
  499. else
  500. put_uint32(bs, val);
  501. }
  502. }
  503. put_byte(bs, TTYMODE_END_OF_LIST);
  504. }
  505. /* ----------------------------------------------------------------------
  506. * Routine for allocating a new channel ID, given a means of finding
  507. * the index field in a given channel structure.
  508. */
  509. unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset)
  510. {
  511. const unsigned CHANNEL_NUMBER_OFFSET = 256;
  512. search234_state ss;
  513. /*
  514. * First-fit allocation of channel numbers: we always pick the
  515. * lowest unused one.
  516. *
  517. * Every channel before that, and no channel after it, has an ID
  518. * exactly equal to its tree index plus CHANNEL_NUMBER_OFFSET. So
  519. * we can use the search234 system to identify the length of that
  520. * initial sequence, in a single log-time pass down the channels
  521. * tree.
  522. */
  523. search234_start(&ss, channels);
  524. while (ss.element) {
  525. unsigned localid = *(unsigned *)((char *)ss.element + localid_offset);
  526. if (localid == ss.index + CHANNEL_NUMBER_OFFSET)
  527. search234_step(&ss, +1);
  528. else
  529. search234_step(&ss, -1);
  530. }
  531. /*
  532. * Now ss.index gives exactly the number of channels in that
  533. * initial sequence. So adding CHANNEL_NUMBER_OFFSET to it must
  534. * give precisely the lowest unused channel number.
  535. */
  536. return ss.index + CHANNEL_NUMBER_OFFSET;
  537. }
  538. /* ----------------------------------------------------------------------
  539. * Functions for handling the comma-separated strings used to store
  540. * lists of protocol identifiers in SSH-2.
  541. */
  542. void add_to_commasep_pl(strbuf *buf, ptrlen data)
  543. {
  544. if (buf->len > 0)
  545. put_byte(buf, ',');
  546. put_datapl(buf, data);
  547. }
  548. void add_to_commasep(strbuf *buf, const char *data)
  549. {
  550. add_to_commasep_pl(buf, ptrlen_from_asciz(data));
  551. }
  552. bool get_commasep_word(ptrlen *list, ptrlen *word)
  553. {
  554. const char *comma;
  555. /*
  556. * Discard empty list elements, should there be any, because we
  557. * never want to return one as if it was a real string. (This
  558. * introduces a mild tolerance of badly formatted data in lists we
  559. * receive, but I think that's acceptable.)
  560. */
  561. while (list->len > 0 && *(const char *)list->ptr == ',') {
  562. list->ptr = (const char *)list->ptr + 1;
  563. list->len--;
  564. }
  565. if (!list->len)
  566. return false;
  567. comma = memchr(list->ptr, ',', list->len);
  568. if (!comma) {
  569. *word = *list;
  570. list->len = 0;
  571. } else {
  572. size_t wordlen = comma - (const char *)list->ptr;
  573. word->ptr = list->ptr;
  574. word->len = wordlen;
  575. list->ptr = (const char *)list->ptr + wordlen + 1;
  576. list->len -= wordlen + 1;
  577. }
  578. return true;
  579. }
  580. /* ----------------------------------------------------------------------
  581. * Functions for translating SSH packet type codes into their symbolic
  582. * string names.
  583. */
  584. #define TRANSLATE_UNIVERSAL(y, name, value) \
  585. if (type == value) return #name;
  586. #define TRANSLATE_KEX(y, name, value, ctx) \
  587. if (type == value && pkt_kctx == ctx) return #name;
  588. #define TRANSLATE_AUTH(y, name, value, ctx) \
  589. if (type == value && pkt_actx == ctx) return #name;
  590. const char *ssh1_pkt_type(int type)
  591. {
  592. SSH1_MESSAGE_TYPES(TRANSLATE_UNIVERSAL, y);
  593. return "unknown";
  594. }
  595. const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type)
  596. {
  597. SSH2_MESSAGE_TYPES(TRANSLATE_UNIVERSAL, TRANSLATE_KEX, TRANSLATE_AUTH, y);
  598. return "unknown";
  599. }
  600. #undef TRANSLATE_UNIVERSAL
  601. #undef TRANSLATE_KEX
  602. #undef TRANSLATE_AUTH
  603. /* ----------------------------------------------------------------------
  604. * Common helper function for clients and implementations of
  605. * PacketProtocolLayer.
  606. */
  607. void ssh_ppl_replace(PacketProtocolLayer *old, PacketProtocolLayer *new)
  608. {
  609. new->bpp = old->bpp;
  610. ssh_ppl_setup_queues(new, old->in_pq, old->out_pq);
  611. new->selfptr = old->selfptr;
  612. new->seat = old->seat;
  613. new->ssh = old->ssh;
  614. *new->selfptr = new;
  615. ssh_ppl_free(old);
  616. /* The new layer might need to be the first one that sends a
  617. * packet, so trigger a call to its main coroutine immediately. If
  618. * it doesn't need to go first, the worst that will do is return
  619. * straight away. */
  620. queue_idempotent_callback(&new->ic_process_queue);
  621. }
  622. void ssh_ppl_free(PacketProtocolLayer *ppl)
  623. {
  624. delete_callbacks_for_context(get_seat_callback_set(ppl->seat), ppl); // WINSCP
  625. ppl->vt->free(ppl);
  626. }
  627. static void ssh_ppl_ic_process_queue_callback(void *context)
  628. {
  629. PacketProtocolLayer *ppl = (PacketProtocolLayer *)context;
  630. ssh_ppl_process_queue(ppl);
  631. }
  632. void ssh_ppl_setup_queues(PacketProtocolLayer *ppl,
  633. PktInQueue *inq, PktOutQueue *outq)
  634. {
  635. ppl->in_pq = inq;
  636. ppl->out_pq = outq;
  637. ppl->in_pq->pqb.ic = &ppl->ic_process_queue;
  638. ppl->ic_process_queue.fn = ssh_ppl_ic_process_queue_callback;
  639. ppl->ic_process_queue.ctx = ppl;
  640. ppl->ic_process_queue.set = get_seat_callback_set(ppl->seat);
  641. /* If there's already something on the input queue, it will want
  642. * handling immediately. */
  643. if (pq_peek(ppl->in_pq))
  644. queue_idempotent_callback(&ppl->ic_process_queue);
  645. }
  646. void ssh_ppl_user_output_string_and_free(PacketProtocolLayer *ppl, char *text)
  647. {
  648. /* Messages sent via this function are from the SSH layer, not
  649. * from the server-side process, so they always have the stderr
  650. * flag set. */
  651. SeatOutputType stderrflag = (SeatOutputType)-1; // WINSCP
  652. seat_output(ppl->seat, stderrflag, text, strlen(text)); // WINSCP
  653. sfree(text);
  654. }
  655. size_t ssh_ppl_default_queued_data_size(PacketProtocolLayer *ppl)
  656. {
  657. return ppl->out_pq->pqb.total_size;
  658. }
  659. static void ssh_ppl_prompts_callback(void *ctx)
  660. {
  661. ssh_ppl_process_queue((PacketProtocolLayer *)ctx);
  662. }
  663. prompts_t *ssh_ppl_new_prompts(PacketProtocolLayer *ppl)
  664. {
  665. prompts_t *p = new_prompts();
  666. p->callback = ssh_ppl_prompts_callback;
  667. p->callback_ctx = ppl;
  668. return p;
  669. }
  670. /* ----------------------------------------------------------------------
  671. * Common helper functions for clients and implementations of
  672. * BinaryPacketProtocol.
  673. */
  674. static void ssh_bpp_input_raw_data_callback(void *context)
  675. {
  676. BinaryPacketProtocol *bpp = (BinaryPacketProtocol *)context;
  677. Ssh *ssh = bpp->ssh; /* in case bpp is about to get freed */
  678. ssh_bpp_handle_input(bpp);
  679. /* If we've now cleared enough backlog on the input connection, we
  680. * may need to unfreeze it. */
  681. ssh_conn_processed_data(ssh);
  682. }
  683. static void ssh_bpp_output_packet_callback(void *context)
  684. {
  685. BinaryPacketProtocol *bpp = (BinaryPacketProtocol *)context;
  686. ssh_bpp_handle_output(bpp);
  687. }
  688. void ssh_bpp_common_setup(BinaryPacketProtocol *bpp)
  689. {
  690. pq_in_init(&bpp->in_pq, get_log_seat(bpp->logctx)); // WINSCP
  691. pq_out_init(&bpp->out_pq, get_log_seat(bpp->logctx)); // WINSCP
  692. bpp->input_eof = false;
  693. bpp->ic_in_raw.fn = ssh_bpp_input_raw_data_callback;
  694. bpp->ic_in_raw.set = get_log_callback_set(bpp->logctx);
  695. bpp->ic_in_raw.ctx = bpp;
  696. bpp->ic_out_pq.fn = ssh_bpp_output_packet_callback;
  697. bpp->ic_out_pq.set = get_log_callback_set(bpp->logctx);
  698. bpp->ic_out_pq.ctx = bpp;
  699. bpp->out_pq.pqb.ic = &bpp->ic_out_pq;
  700. }
  701. void ssh_bpp_free(BinaryPacketProtocol *bpp)
  702. {
  703. // WINSCP
  704. delete_callbacks_for_context(get_log_callback_set(bpp->logctx), bpp);
  705. bpp->vt->free(bpp);
  706. }
  707. void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp,
  708. const char *msg, int category)
  709. {
  710. PktOut *pkt = ssh_bpp_new_pktout(bpp, SSH2_MSG_DISCONNECT);
  711. put_uint32(pkt, category);
  712. put_stringz(pkt, msg);
  713. put_stringz(pkt, "en"); /* language tag */
  714. pq_push(&bpp->out_pq, pkt);
  715. }
  716. #define BITMAP_UNIVERSAL(y, name, value) \
  717. | (value >= y && value < y+32 \
  718. ? 1UL << (value >= y && value < y+32 ? (value-y) : 0) \
  719. : 0)
  720. #define BITMAP_CONDITIONAL(y, name, value, ctx) \
  721. BITMAP_UNIVERSAL(y, name, value)
  722. #define SSH2_BITMAP_WORD(y) \
  723. (0 SSH2_MESSAGE_TYPES(BITMAP_UNIVERSAL, BITMAP_CONDITIONAL, \
  724. BITMAP_CONDITIONAL, (32*y)))
  725. bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
  726. {
  727. #pragma warn -osh
  728. static const unsigned valid_bitmap[] = {
  729. SSH2_BITMAP_WORD(0),
  730. SSH2_BITMAP_WORD(1),
  731. SSH2_BITMAP_WORD(2),
  732. SSH2_BITMAP_WORD(3),
  733. SSH2_BITMAP_WORD(4),
  734. SSH2_BITMAP_WORD(5),
  735. SSH2_BITMAP_WORD(6),
  736. SSH2_BITMAP_WORD(7),
  737. };
  738. #pragma warn +osh
  739. if (pktin->type < 0x100 &&
  740. !((valid_bitmap[pktin->type >> 5] >> (pktin->type & 0x1F)) & 1)) {
  741. PktOut *pkt = ssh_bpp_new_pktout(bpp, SSH2_MSG_UNIMPLEMENTED);
  742. put_uint32(pkt, pktin->sequence);
  743. pq_push(&bpp->out_pq, pkt);
  744. return true;
  745. }
  746. return false;
  747. }
  748. #undef BITMAP_UNIVERSAL
  749. #undef BITMAP_CONDITIONAL
  750. #undef SSH2_BITMAP_WORD
  751. /* ----------------------------------------------------------------------
  752. * Centralised component of SSH host key verification.
  753. *
  754. * verify_ssh_host_key is called from both the SSH-1 and SSH-2
  755. * transport layers, and does the initial work of checking whether the
  756. * host key is already known. If so, it returns success on its own
  757. * account; otherwise, it calls out to the Seat to give an interactive
  758. * prompt (the nature of which varies depending on the Seat itself).
  759. */
  760. SeatPromptResult verify_ssh_host_key(
  761. InteractionReadySeat iseat, Conf *conf, const char *host, int port,
  762. ssh_key *key, const char *keytype, char *keystr, const char *keydisp,
  763. char **fingerprints, int ca_count,
  764. void (*callback)(void *ctx, SeatPromptResult result), void *ctx)
  765. {
  766. /*
  767. * First, check if the Conf includes a manual specification of the
  768. * expected host key. If so, that completely supersedes everything
  769. * else, including the normal host key cache _and_ including
  770. * manual overrides: we return success or failure immediately,
  771. * entirely based on whether the key matches the Conf.
  772. */
  773. if (conf_get_str_nthstrkey(conf, CONF_ssh_manual_hostkeys, 0)) {
  774. if (fingerprints) {
  775. size_t i; // WINSCP
  776. for (i = 0; i < SSH_N_FPTYPES; i++) {
  777. /*
  778. * Each fingerprint string we've been given will have
  779. * things like 'ssh-rsa 2048' at the front of it. Strip
  780. * those off and narrow down to just the hash at the end
  781. * of the string.
  782. */
  783. const char *fingerprint = fingerprints[i];
  784. if (!fingerprint)
  785. continue;
  786. { // WINSCP
  787. const char *p = strrchr(fingerprint, ' ');
  788. fingerprint = p ? p+1 : fingerprint;
  789. if (conf_get_str_str_opt(conf, CONF_ssh_manual_hostkeys,
  790. fingerprint))
  791. return SPR_OK;
  792. } // WINSCP
  793. }
  794. }
  795. if (key) {
  796. /*
  797. * Construct the base64-encoded public key blob and see if
  798. * that's listed.
  799. */
  800. strbuf *binblob;
  801. char *base64blob;
  802. int atoms, i;
  803. binblob = strbuf_new();
  804. ssh_key_public_blob(key, BinarySink_UPCAST(binblob));
  805. atoms = (binblob->len + 2) / 3;
  806. base64blob = snewn(atoms * 4 + 1, char);
  807. for (i = 0; i < atoms; i++)
  808. base64_encode_atom(binblob->u + 3*i,
  809. binblob->len - 3*i, base64blob + 4*i);
  810. base64blob[atoms * 4] = '\0';
  811. strbuf_free(binblob);
  812. if (conf_get_str_str_opt(conf, CONF_ssh_manual_hostkeys,
  813. base64blob)) {
  814. sfree(base64blob);
  815. return SPR_OK;
  816. }
  817. sfree(base64blob);
  818. }
  819. return SPR_SW_ABORT("Host key not in manually configured list");
  820. }
  821. /*
  822. * Next, check the host key cache.
  823. */
  824. { // WINSCP
  825. int storage_status = 1; // WINSCP check_stored_host_key(host, port, keytype, keystr);
  826. if (storage_status == 0) /* matching key was found in the cache */
  827. return SPR_OK;
  828. /*
  829. * The key is either missing from the cache, or does not match.
  830. * Either way, fall back to an interactive prompt from the Seat.
  831. */
  832. SeatDialogText *text = seat_dialog_text_new();
  833. const SeatDialogPromptDescriptions *pds =
  834. seat_prompt_descriptions(iseat.seat);
  835. FingerprintType fptype_default =
  836. ssh2_pick_default_fingerprint(fingerprints);
  837. seat_dialog_text_append(
  838. text, SDT_TITLE, "%s Security Alert", appname);
  839. HelpCtx helpctx;
  840. if (key && ssh_key_alg(key)->is_certificate) {
  841. seat_dialog_text_append(
  842. text, SDT_SCARY_HEADING, "WARNING - POTENTIAL SECURITY BREACH!");
  843. seat_dialog_text_append(
  844. text, SDT_PARA, "This server presented a certified host key:");
  845. seat_dialog_text_append(
  846. text, SDT_DISPLAY, "%s (port %d)", host, port);
  847. if (ca_count) {
  848. seat_dialog_text_append(
  849. text, SDT_PARA, "which was signed by a different "
  850. "certification authority from the %s %s is configured to "
  851. "trust for this server.", ca_count > 1 ? "ones" : "one",
  852. appname);
  853. if (storage_status == 2) {
  854. seat_dialog_text_append(
  855. text, SDT_PARA, "ALSO, that key does not match the key "
  856. "%s had previously cached for this server.", appname);
  857. seat_dialog_text_append(
  858. text, SDT_PARA, "This means that either another "
  859. "certification authority is operating in this realm AND "
  860. "the server administrator has changed the host key, or "
  861. "you have actually connected to another computer "
  862. "pretending to be the server.");
  863. } else {
  864. seat_dialog_text_append(
  865. text, SDT_PARA, "This means that either another "
  866. "certification authority is operating in this realm, or "
  867. "you have actually connected to another computer "
  868. "pretending to be the server.");
  869. }
  870. } else {
  871. assert(storage_status == 2);
  872. seat_dialog_text_append(
  873. text, SDT_PARA, "which does not match the certified key %s "
  874. "had previously cached for this server.", appname);
  875. seat_dialog_text_append(
  876. text, SDT_PARA, "This means that either the server "
  877. "administrator has changed the host key, or you have actually "
  878. "connected to another computer pretending to be the server.");
  879. }
  880. seat_dialog_text_append(
  881. text, SDT_PARA, "The new %s key fingerprint is:", keytype);
  882. seat_dialog_text_append(
  883. text, SDT_DISPLAY, "%s", fingerprints[fptype_default]);
  884. helpctx = HELPCTX(errors_cert_mismatch);
  885. } else if (storage_status == 1) {
  886. seat_dialog_text_append(
  887. text, SDT_PARA, "The host key is not cached for this server:");
  888. seat_dialog_text_append(
  889. text, SDT_DISPLAY, "%s (port %d)", host, port);
  890. seat_dialog_text_append(
  891. text, SDT_PARA, "You have no guarantee that the server is the "
  892. "computer you think it is.");
  893. seat_dialog_text_append(
  894. text, SDT_PARA, "The server's %s key fingerprint is:", keytype);
  895. seat_dialog_text_append(
  896. text, SDT_DISPLAY, "%s", fingerprints[fptype_default]);
  897. helpctx = HELPCTX(errors_hostkey_absent);
  898. } else {
  899. seat_dialog_text_append(
  900. text, SDT_SCARY_HEADING, "WARNING - POTENTIAL SECURITY BREACH!");
  901. seat_dialog_text_append(
  902. text, SDT_PARA, "The host key does not match the one %s has "
  903. "cached for this server:", appname);
  904. seat_dialog_text_append(
  905. text, SDT_DISPLAY, "%s (port %d)", host, port);
  906. seat_dialog_text_append(
  907. text, SDT_PARA, "This means that either the server administrator "
  908. "has changed the host key, or you have actually connected to "
  909. "another computer pretending to be the server.");
  910. seat_dialog_text_append(
  911. text, SDT_PARA, "The new %s key fingerprint is:", keytype);
  912. seat_dialog_text_append(
  913. text, SDT_DISPLAY, "%s", fingerprints[fptype_default]);
  914. helpctx = HELPCTX(errors_hostkey_changed);
  915. }
  916. /* The above text is printed even in batch mode. Here's where we stop if
  917. * we can't present interactive prompts. */
  918. seat_dialog_text_append(
  919. text, SDT_BATCH_ABORT, "Connection abandoned.");
  920. if (storage_status == 1) {
  921. seat_dialog_text_append(
  922. text, SDT_PARA, "If you trust this host, %s to add the key to "
  923. "%s's cache and carry on connecting.",
  924. pds->hk_accept_action, appname);
  925. seat_dialog_text_append(
  926. text, SDT_PARA, "If you want to carry on connecting just once, "
  927. "without adding the key to the cache, %s.",
  928. pds->hk_connect_once_action);
  929. seat_dialog_text_append(
  930. text, SDT_PARA, "If you do not trust this host, %s to abandon the "
  931. "connection.", pds->hk_cancel_action);
  932. seat_dialog_text_append(
  933. text, SDT_PROMPT, "Store key in cache?");
  934. } else {
  935. seat_dialog_text_append(
  936. text, SDT_PARA, "If you were expecting this change and trust the "
  937. "new key, %s to update %s's cache and carry on connecting.",
  938. pds->hk_accept_action, appname);
  939. if (key && ssh_key_alg(key)->is_certificate) {
  940. seat_dialog_text_append(
  941. text, SDT_PARA, "(Storing this certified key in the cache "
  942. "will NOT cause its certification authority to be trusted "
  943. "for any other key or host.)");
  944. }
  945. seat_dialog_text_append(
  946. text, SDT_PARA, "If you want to carry on connecting but without "
  947. "updating the cache, %s.", pds->hk_connect_once_action);
  948. seat_dialog_text_append(
  949. text, SDT_PARA, "If you want to abandon the connection "
  950. "completely, %s to cancel. %s is the ONLY guaranteed safe choice.",
  951. pds->hk_cancel_action, pds->hk_cancel_action_Participle);
  952. seat_dialog_text_append(
  953. text, SDT_PROMPT, "Update cached key?");
  954. }
  955. seat_dialog_text_append(text, SDT_MORE_INFO_KEY,
  956. "Full text of host's public key");
  957. seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_BLOB, "%s", keydisp);
  958. if (fingerprints[SSH_FPTYPE_SHA256]) {
  959. seat_dialog_text_append(text, SDT_MORE_INFO_KEY, "SHA256 fingerprint");
  960. seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_SHORT, "%s",
  961. fingerprints[SSH_FPTYPE_SHA256]);
  962. }
  963. if (fingerprints[SSH_FPTYPE_MD5]) {
  964. seat_dialog_text_append(text, SDT_MORE_INFO_KEY, "MD5 fingerprint");
  965. seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_SHORT, "%s",
  966. fingerprints[SSH_FPTYPE_MD5]);
  967. }
  968. SeatPromptResult toret = seat_confirm_ssh_host_key(
  969. iseat, host, port, keytype, keystr, text, helpctx, callback, ctx);
  970. seat_dialog_text_free(text);
  971. return toret;
  972. } // WINSCP
  973. }
  974. /* ----------------------------------------------------------------------
  975. * Common functions shared between SSH-1 layers.
  976. */
  977. bool ssh1_common_get_specials(
  978. PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
  979. {
  980. /*
  981. * Don't bother offering IGNORE if we've decided the remote
  982. * won't cope with it, since we wouldn't bother sending it if
  983. * asked anyway.
  984. */
  985. if (!(ppl->remote_bugs & BUG_CHOKES_ON_SSH1_IGNORE)) {
  986. add_special(ctx, "IGNORE message", SS_NOP, 0);
  987. return true;
  988. }
  989. return false;
  990. }
  991. bool ssh1_common_filter_queue(PacketProtocolLayer *ppl)
  992. {
  993. PktIn *pktin;
  994. ptrlen msg;
  995. while ((pktin = pq_peek(ppl->in_pq)) != NULL) {
  996. switch (pktin->type) {
  997. case SSH1_MSG_DISCONNECT:
  998. msg = get_string(pktin);
  999. ssh_remote_error(ppl->ssh,
  1000. "Remote side sent disconnect message:\n\"%.*s\"",
  1001. PTRLEN_PRINTF(msg));
  1002. /* don't try to pop the queue, because we've been freed! */
  1003. return true; /* indicate that we've been freed */
  1004. case SSH1_MSG_DEBUG:
  1005. msg = get_string(pktin);
  1006. ppl_logevent("Remote debug message: %.*s", PTRLEN_PRINTF(msg));
  1007. pq_pop(ppl->in_pq);
  1008. break;
  1009. case SSH1_MSG_IGNORE:
  1010. /* Do nothing, because we're ignoring it! Duhh. */
  1011. pq_pop(ppl->in_pq);
  1012. break;
  1013. default:
  1014. return false;
  1015. }
  1016. }
  1017. return false;
  1018. }
  1019. void ssh1_compute_session_id(
  1020. unsigned char *session_id, const unsigned char *cookie,
  1021. RSAKey *hostkey, RSAKey *servkey)
  1022. {
  1023. ssh_hash *hash = ssh_hash_new(&ssh_md5);
  1024. size_t i; // WINSCP
  1025. for (i = (mp_get_nbits(hostkey->modulus) + 7) / 8; i-- ;)
  1026. put_byte(hash, mp_get_byte(hostkey->modulus, i));
  1027. for (i = (mp_get_nbits(servkey->modulus) + 7) / 8; i-- ;)
  1028. put_byte(hash, mp_get_byte(servkey->modulus, i));
  1029. put_data(hash, cookie, 8);
  1030. ssh_hash_final(hash, session_id);
  1031. }
  1032. /* ----------------------------------------------------------------------
  1033. * Wrapper function to handle the abort-connection modes of a
  1034. * SeatPromptResult without a lot of verbiage at every call site.
  1035. *
  1036. * Can become ssh_sw_abort or ssh_user_close, depending on the kind of
  1037. * negative SeatPromptResult.
  1038. */
  1039. void ssh_spr_close(Ssh *ssh, SeatPromptResult spr, const char *context)
  1040. {
  1041. if (spr.kind == SPRK_USER_ABORT) {
  1042. ssh_user_close(ssh, "User aborted at %s", context);
  1043. } else {
  1044. assert(spr.kind == SPRK_SW_ABORT);
  1045. { // WINSCP
  1046. char *err = spr_get_error_message(spr);
  1047. ssh_sw_abort(ssh, "%s", err);
  1048. sfree(err);
  1049. } // WINSCP
  1050. }
  1051. }