sshcommon.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 "ssh.h"
  9. #include "sshchan.h"
  10. /* ----------------------------------------------------------------------
  11. * Implementation of PacketQueue.
  12. */
  13. void pq_base_push(PacketQueueBase *pqb, PacketQueueNode *node)
  14. {
  15. assert(!node->next);
  16. assert(!node->prev);
  17. node->next = &pqb->end;
  18. node->prev = pqb->end.prev;
  19. node->next->prev = node;
  20. node->prev->next = node;
  21. }
  22. void pq_base_push_front(PacketQueueBase *pqb, PacketQueueNode *node)
  23. {
  24. assert(!node->next);
  25. assert(!node->prev);
  26. node->prev = &pqb->end;
  27. node->next = pqb->end.next;
  28. node->next->prev = node;
  29. node->prev->next = node;
  30. }
  31. static PktIn *pq_in_get(PacketQueueBase *pqb, int pop)
  32. {
  33. PacketQueueNode *node = pqb->end.next;
  34. if (node == &pqb->end)
  35. return NULL;
  36. if (pop) {
  37. node->next->prev = node->prev;
  38. node->prev->next = node->next;
  39. node->prev = node->next = NULL;
  40. }
  41. return FROMFIELD(node, PktIn, qnode);
  42. }
  43. static PktOut *pq_out_get(PacketQueueBase *pqb, int pop)
  44. {
  45. PacketQueueNode *node = pqb->end.next;
  46. if (node == &pqb->end)
  47. return NULL;
  48. if (pop) {
  49. node->next->prev = node->prev;
  50. node->prev->next = node->next;
  51. node->prev = node->next = NULL;
  52. }
  53. return FROMFIELD(node, PktOut, qnode);
  54. }
  55. void pq_in_init(PktInQueue *pq)
  56. {
  57. pq->pqb.end.next = pq->pqb.end.prev = &pq->pqb.end;
  58. pq->get = pq_in_get;
  59. }
  60. void pq_out_init(PktOutQueue *pq)
  61. {
  62. pq->pqb.end.next = pq->pqb.end.prev = &pq->pqb.end;
  63. pq->get = pq_out_get;
  64. }
  65. void pq_in_clear(PktInQueue *pq)
  66. {
  67. PktIn *pkt;
  68. while ((pkt = pq_pop(pq)) != NULL)
  69. ssh_unref_packet(pkt);
  70. }
  71. void pq_out_clear(PktOutQueue *pq)
  72. {
  73. PktOut *pkt;
  74. while ((pkt = pq_pop(pq)) != NULL)
  75. ssh_free_pktout(pkt);
  76. }
  77. /*
  78. * Concatenate the contents of the two queues q1 and q2, and leave the
  79. * result in qdest. qdest must be either empty, or one of the input
  80. * queues.
  81. */
  82. void pq_base_concatenate(PacketQueueBase *qdest,
  83. PacketQueueBase *q1, PacketQueueBase *q2)
  84. {
  85. struct PacketQueueNode *head1, *tail1, *head2, *tail2;
  86. /*
  87. * Extract the contents from both input queues, and empty them.
  88. */
  89. head1 = (q1->end.next == &q1->end ? NULL : q1->end.next);
  90. tail1 = (q1->end.prev == &q1->end ? NULL : q1->end.prev);
  91. head2 = (q2->end.next == &q2->end ? NULL : q2->end.next);
  92. tail2 = (q2->end.prev == &q2->end ? NULL : q2->end.prev);
  93. q1->end.next = q1->end.prev = &q1->end;
  94. q2->end.next = q2->end.prev = &q2->end;
  95. /*
  96. * Link the two lists together, handling the case where one or
  97. * both is empty.
  98. */
  99. if (tail1)
  100. tail1->next = head2;
  101. else
  102. head1 = head2;
  103. if (head2)
  104. head2->prev = tail1;
  105. else
  106. tail2 = tail1;
  107. /*
  108. * Check the destination queue is currently empty. (If it was one
  109. * of the input queues, then it will be, because we emptied both
  110. * of those just a moment ago.)
  111. */
  112. assert(qdest->end.next == &qdest->end);
  113. assert(qdest->end.prev == &qdest->end);
  114. /*
  115. * If our concatenated list has anything in it, then put it in
  116. * dest.
  117. */
  118. if (!head1) {
  119. assert(!tail2);
  120. } else {
  121. assert(tail2);
  122. qdest->end.next = head1;
  123. qdest->end.prev = tail2;
  124. head1->prev = &qdest->end;
  125. tail2->next = &qdest->end;
  126. }
  127. }
  128. /* ----------------------------------------------------------------------
  129. * Low-level functions for the packet structures themselves.
  130. */
  131. static void ssh_pkt_BinarySink_write(BinarySink *bs,
  132. const void *data, size_t len);
  133. PktOut *ssh_new_packet(void)
  134. {
  135. PktOut *pkt = snew(PktOut);
  136. BinarySink_INIT(pkt, ssh_pkt_BinarySink_write);
  137. pkt->data = NULL;
  138. pkt->length = 0;
  139. pkt->maxlen = 0;
  140. pkt->downstream_id = 0;
  141. pkt->additional_log_text = NULL;
  142. pkt->qnode.next = pkt->qnode.prev = NULL;
  143. return pkt;
  144. }
  145. static void ssh_pkt_ensure(PktOut *pkt, int length)
  146. {
  147. if (pkt->maxlen < length) {
  148. pkt->maxlen = length + 256;
  149. pkt->data = sresize(pkt->data, pkt->maxlen, unsigned char);
  150. }
  151. }
  152. static void ssh_pkt_adddata(PktOut *pkt, const void *data, int len)
  153. {
  154. pkt->length += len;
  155. ssh_pkt_ensure(pkt, pkt->length);
  156. memcpy(pkt->data + pkt->length - len, data, len);
  157. }
  158. static void ssh_pkt_BinarySink_write(BinarySink *bs,
  159. const void *data, size_t len)
  160. {
  161. PktOut *pkt = BinarySink_DOWNCAST(bs, PktOut);
  162. ssh_pkt_adddata(pkt, data, len);
  163. }
  164. void ssh_unref_packet(PktIn *pkt)
  165. {
  166. if (--pkt->refcount <= 0)
  167. sfree(pkt);
  168. }
  169. void ssh_free_pktout(PktOut *pkt)
  170. {
  171. sfree(pkt->data);
  172. sfree(pkt);
  173. }
  174. /* ----------------------------------------------------------------------
  175. * Implement zombiechan_new() and its trivial vtable.
  176. */
  177. static void zombiechan_free(Channel *chan);
  178. static int zombiechan_send(Channel *chan, int is_stderr, const void *, int);
  179. static void zombiechan_set_input_wanted(Channel *chan, int wanted);
  180. static void zombiechan_do_nothing(Channel *chan);
  181. static void zombiechan_open_failure(Channel *chan, const char *);
  182. static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof);
  183. static char *zombiechan_log_close_msg(Channel *chan) { return NULL; }
  184. static const struct ChannelVtable zombiechan_channelvt = {
  185. zombiechan_free,
  186. zombiechan_do_nothing, /* open_confirmation */
  187. zombiechan_open_failure,
  188. zombiechan_send,
  189. zombiechan_do_nothing, /* send_eof */
  190. zombiechan_set_input_wanted,
  191. zombiechan_log_close_msg,
  192. zombiechan_want_close,
  193. };
  194. Channel *zombiechan_new(void)
  195. {
  196. Channel *chan = snew(Channel);
  197. chan->vt = &zombiechan_channelvt;
  198. chan->initial_fixed_window_size = 0;
  199. return chan;
  200. }
  201. static void zombiechan_free(Channel *chan)
  202. {
  203. assert(chan->vt == &zombiechan_channelvt);
  204. sfree(chan);
  205. }
  206. static void zombiechan_do_nothing(Channel *chan)
  207. {
  208. assert(chan->vt == &zombiechan_channelvt);
  209. }
  210. static void zombiechan_open_failure(Channel *chan, const char *errtext)
  211. {
  212. assert(chan->vt == &zombiechan_channelvt);
  213. }
  214. static int zombiechan_send(Channel *chan, int is_stderr,
  215. const void *data, int length)
  216. {
  217. assert(chan->vt == &zombiechan_channelvt);
  218. return 0;
  219. }
  220. static void zombiechan_set_input_wanted(Channel *chan, int enable)
  221. {
  222. assert(chan->vt == &zombiechan_channelvt);
  223. }
  224. static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof)
  225. {
  226. return TRUE;
  227. }
  228. /* ----------------------------------------------------------------------
  229. * Centralised standard methods for other channel implementations to
  230. * borrow.
  231. */
  232. void chan_remotely_opened_confirmation(Channel *chan)
  233. {
  234. assert(0 && "this channel type should never receive OPEN_CONFIRMATION");
  235. }
  236. void chan_remotely_opened_failure(Channel *chan, const char *errtext)
  237. {
  238. assert(0 && "this channel type should never receive OPEN_FAILURE");
  239. }
  240. int chan_no_eager_close(Channel *chan, int sent_local_eof, int rcvd_remote_eof)
  241. {
  242. return FALSE; /* default: never proactively ask for a close */
  243. }
  244. /* ----------------------------------------------------------------------
  245. * Common routine to marshal tty modes into an SSH packet.
  246. */
  247. void write_ttymodes_to_packet_from_conf(
  248. BinarySink *bs, Frontend *frontend, Conf *conf,
  249. int ssh_version, int ospeed, int ispeed)
  250. {
  251. int i;
  252. /*
  253. * Codes for terminal modes.
  254. * Most of these are the same in SSH-1 and SSH-2.
  255. * This list is derived from RFC 4254 and
  256. * SSH-1 RFC-1.2.31.
  257. */
  258. static const struct ssh_ttymode {
  259. const char *mode;
  260. int opcode;
  261. enum { TTY_OP_CHAR, TTY_OP_BOOL } type;
  262. } ssh_ttymodes[] = {
  263. /* "V" prefix discarded for special characters relative to SSH specs */
  264. { "INTR", 1, TTY_OP_CHAR },
  265. { "QUIT", 2, TTY_OP_CHAR },
  266. { "ERASE", 3, TTY_OP_CHAR },
  267. { "KILL", 4, TTY_OP_CHAR },
  268. { "EOF", 5, TTY_OP_CHAR },
  269. { "EOL", 6, TTY_OP_CHAR },
  270. { "EOL2", 7, TTY_OP_CHAR },
  271. { "START", 8, TTY_OP_CHAR },
  272. { "STOP", 9, TTY_OP_CHAR },
  273. { "SUSP", 10, TTY_OP_CHAR },
  274. { "DSUSP", 11, TTY_OP_CHAR },
  275. { "REPRINT", 12, TTY_OP_CHAR },
  276. { "WERASE", 13, TTY_OP_CHAR },
  277. { "LNEXT", 14, TTY_OP_CHAR },
  278. { "FLUSH", 15, TTY_OP_CHAR },
  279. { "SWTCH", 16, TTY_OP_CHAR },
  280. { "STATUS", 17, TTY_OP_CHAR },
  281. { "DISCARD", 18, TTY_OP_CHAR },
  282. { "IGNPAR", 30, TTY_OP_BOOL },
  283. { "PARMRK", 31, TTY_OP_BOOL },
  284. { "INPCK", 32, TTY_OP_BOOL },
  285. { "ISTRIP", 33, TTY_OP_BOOL },
  286. { "INLCR", 34, TTY_OP_BOOL },
  287. { "IGNCR", 35, TTY_OP_BOOL },
  288. { "ICRNL", 36, TTY_OP_BOOL },
  289. { "IUCLC", 37, TTY_OP_BOOL },
  290. { "IXON", 38, TTY_OP_BOOL },
  291. { "IXANY", 39, TTY_OP_BOOL },
  292. { "IXOFF", 40, TTY_OP_BOOL },
  293. { "IMAXBEL", 41, TTY_OP_BOOL },
  294. { "IUTF8", 42, TTY_OP_BOOL },
  295. { "ISIG", 50, TTY_OP_BOOL },
  296. { "ICANON", 51, TTY_OP_BOOL },
  297. { "XCASE", 52, TTY_OP_BOOL },
  298. { "ECHO", 53, TTY_OP_BOOL },
  299. { "ECHOE", 54, TTY_OP_BOOL },
  300. { "ECHOK", 55, TTY_OP_BOOL },
  301. { "ECHONL", 56, TTY_OP_BOOL },
  302. { "NOFLSH", 57, TTY_OP_BOOL },
  303. { "TOSTOP", 58, TTY_OP_BOOL },
  304. { "IEXTEN", 59, TTY_OP_BOOL },
  305. { "ECHOCTL", 60, TTY_OP_BOOL },
  306. { "ECHOKE", 61, TTY_OP_BOOL },
  307. { "PENDIN", 62, TTY_OP_BOOL }, /* XXX is this a real mode? */
  308. { "OPOST", 70, TTY_OP_BOOL },
  309. { "OLCUC", 71, TTY_OP_BOOL },
  310. { "ONLCR", 72, TTY_OP_BOOL },
  311. { "OCRNL", 73, TTY_OP_BOOL },
  312. { "ONOCR", 74, TTY_OP_BOOL },
  313. { "ONLRET", 75, TTY_OP_BOOL },
  314. { "CS7", 90, TTY_OP_BOOL },
  315. { "CS8", 91, TTY_OP_BOOL },
  316. { "PARENB", 92, TTY_OP_BOOL },
  317. { "PARODD", 93, TTY_OP_BOOL }
  318. };
  319. /* Miscellaneous other tty-related constants. */
  320. enum {
  321. /* The opcodes for ISPEED/OSPEED differ between SSH-1 and SSH-2. */
  322. SSH1_TTY_OP_ISPEED = 192,
  323. SSH1_TTY_OP_OSPEED = 193,
  324. SSH2_TTY_OP_ISPEED = 128,
  325. SSH2_TTY_OP_OSPEED = 129,
  326. SSH_TTY_OP_END = 0
  327. };
  328. for (i = 0; i < lenof(ssh_ttymodes); i++) {
  329. const struct ssh_ttymode *mode = ssh_ttymodes + i;
  330. const char *sval = conf_get_str_str(conf, CONF_ttymodes, mode->mode);
  331. char *to_free = NULL;
  332. /* Every mode known to the current version of the code should be
  333. * mentioned; this was ensured when settings were loaded. */
  334. /*
  335. * sval[0] can be
  336. * - 'V', indicating that an explicit value follows it;
  337. * - 'A', indicating that we should pass the value through from
  338. * the local environment via get_ttymode; or
  339. * - 'N', indicating that we should explicitly not send this
  340. * mode.
  341. */
  342. if (sval[0] == 'A') {
  343. sval = to_free = get_ttymode(frontend, mode->mode);
  344. } else if (sval[0] == 'V') {
  345. sval++; /* skip the 'V' */
  346. } else {
  347. /* else 'N', or something from the future we don't understand */
  348. continue;
  349. }
  350. if (sval) {
  351. /*
  352. * Parse the string representation of the tty mode
  353. * into the integer value it will take on the wire.
  354. */
  355. unsigned ival = 0;
  356. switch (mode->type) {
  357. case TTY_OP_CHAR:
  358. if (*sval) {
  359. char *next = NULL;
  360. /* We know ctrlparse won't write to the string, so
  361. * casting away const is ugly but allowable. */
  362. ival = ctrlparse((char *)sval, &next);
  363. if (!next)
  364. ival = sval[0];
  365. } else {
  366. ival = 255; /* special value meaning "don't set" */
  367. }
  368. break;
  369. case TTY_OP_BOOL:
  370. if (stricmp(sval, "yes") == 0 ||
  371. stricmp(sval, "on") == 0 ||
  372. stricmp(sval, "true") == 0 ||
  373. stricmp(sval, "+") == 0)
  374. ival = 1; /* true */
  375. else if (stricmp(sval, "no") == 0 ||
  376. stricmp(sval, "off") == 0 ||
  377. stricmp(sval, "false") == 0 ||
  378. stricmp(sval, "-") == 0)
  379. ival = 0; /* false */
  380. else
  381. ival = (atoi(sval) != 0);
  382. break;
  383. default:
  384. assert(0 && "Bad mode->type");
  385. }
  386. /*
  387. * And write it into the output packet. The parameter
  388. * value is formatted as a byte in SSH-1, but a uint32
  389. * in SSH-2.
  390. */
  391. put_byte(bs, mode->opcode);
  392. if (ssh_version == 1)
  393. put_byte(bs, ival);
  394. else
  395. put_uint32(bs, ival);
  396. }
  397. sfree(to_free);
  398. }
  399. /*
  400. * Finish off with the terminal speeds (which are formatted as
  401. * uint32 in both protocol versions) and the end marker.
  402. */
  403. put_byte(bs, ssh_version == 1 ? SSH1_TTY_OP_ISPEED : SSH2_TTY_OP_ISPEED);
  404. put_uint32(bs, ispeed);
  405. put_byte(bs, ssh_version == 1 ? SSH1_TTY_OP_OSPEED : SSH2_TTY_OP_OSPEED);
  406. put_uint32(bs, ospeed);
  407. put_byte(bs, SSH_TTY_OP_END);
  408. }
  409. /* ----------------------------------------------------------------------
  410. * Routine for allocating a new channel ID, given a means of finding
  411. * the index field in a given channel structure.
  412. */
  413. unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset)
  414. {
  415. const unsigned CHANNEL_NUMBER_OFFSET = 256;
  416. search234_state ss;
  417. /*
  418. * First-fit allocation of channel numbers: we always pick the
  419. * lowest unused one.
  420. *
  421. * Every channel before that, and no channel after it, has an ID
  422. * exactly equal to its tree index plus CHANNEL_NUMBER_OFFSET. So
  423. * we can use the search234 system to identify the length of that
  424. * initial sequence, in a single log-time pass down the channels
  425. * tree.
  426. */
  427. search234_start(&ss, channels);
  428. while (ss.element) {
  429. unsigned localid = *(unsigned *)((char *)ss.element + localid_offset);
  430. if (localid == ss.index + CHANNEL_NUMBER_OFFSET)
  431. search234_step(&ss, +1);
  432. else
  433. search234_step(&ss, -1);
  434. }
  435. /*
  436. * Now ss.index gives exactly the number of channels in that
  437. * initial sequence. So adding CHANNEL_NUMBER_OFFSET to it must
  438. * give precisely the lowest unused channel number.
  439. */
  440. return ss.index + CHANNEL_NUMBER_OFFSET;
  441. }
  442. /* ----------------------------------------------------------------------
  443. * Functions for handling the comma-separated strings used to store
  444. * lists of protocol identifiers in SSH-2.
  445. */
  446. int first_in_commasep_string(char const *needle, char const *haystack,
  447. int haylen)
  448. {
  449. int needlen;
  450. if (!needle || !haystack) /* protect against null pointers */
  451. return 0;
  452. needlen = strlen(needle);
  453. if (haylen >= needlen && /* haystack is long enough */
  454. !memcmp(needle, haystack, needlen) && /* initial match */
  455. (haylen == needlen || haystack[needlen] == ',')
  456. /* either , or EOS follows */
  457. )
  458. return 1;
  459. return 0;
  460. }
  461. int in_commasep_string(char const *needle, char const *haystack, int haylen)
  462. {
  463. char *p;
  464. if (!needle || !haystack) /* protect against null pointers */
  465. return FALSE;
  466. /*
  467. * Is it at the start of the string?
  468. */
  469. if (first_in_commasep_string(needle, haystack, haylen))
  470. return TRUE;
  471. /*
  472. * If not, search for the next comma and resume after that.
  473. * If no comma found, terminate.
  474. */
  475. p = memchr(haystack, ',', haylen);
  476. if (!p)
  477. return FALSE;
  478. /* + 1 to skip over comma */
  479. return in_commasep_string(needle, p + 1, haylen - (p + 1 - haystack));
  480. }
  481. void add_to_commasep(strbuf *buf, const char *data)
  482. {
  483. if (buf->len > 0)
  484. put_byte(buf, ',');
  485. put_data(buf, data, strlen(data));
  486. }
  487. /* ----------------------------------------------------------------------
  488. * Functions for translating SSH packet type codes into their symbolic
  489. * string names.
  490. */
  491. #define translate(x) if (type == x) return #x
  492. #define translatek(x,ctx) if (type == x && (pkt_kctx == ctx)) return #x
  493. #define translatea(x,ctx) if (type == x && (pkt_actx == ctx)) return #x
  494. const char *ssh1_pkt_type(int type)
  495. {
  496. translate(SSH1_MSG_DISCONNECT);
  497. translate(SSH1_SMSG_PUBLIC_KEY);
  498. translate(SSH1_CMSG_SESSION_KEY);
  499. translate(SSH1_CMSG_USER);
  500. translate(SSH1_CMSG_AUTH_RSA);
  501. translate(SSH1_SMSG_AUTH_RSA_CHALLENGE);
  502. translate(SSH1_CMSG_AUTH_RSA_RESPONSE);
  503. translate(SSH1_CMSG_AUTH_PASSWORD);
  504. translate(SSH1_CMSG_REQUEST_PTY);
  505. translate(SSH1_CMSG_WINDOW_SIZE);
  506. translate(SSH1_CMSG_EXEC_SHELL);
  507. translate(SSH1_CMSG_EXEC_CMD);
  508. translate(SSH1_SMSG_SUCCESS);
  509. translate(SSH1_SMSG_FAILURE);
  510. translate(SSH1_CMSG_STDIN_DATA);
  511. translate(SSH1_SMSG_STDOUT_DATA);
  512. translate(SSH1_SMSG_STDERR_DATA);
  513. translate(SSH1_CMSG_EOF);
  514. translate(SSH1_SMSG_EXIT_STATUS);
  515. translate(SSH1_MSG_CHANNEL_OPEN_CONFIRMATION);
  516. translate(SSH1_MSG_CHANNEL_OPEN_FAILURE);
  517. translate(SSH1_MSG_CHANNEL_DATA);
  518. translate(SSH1_MSG_CHANNEL_CLOSE);
  519. translate(SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION);
  520. translate(SSH1_SMSG_X11_OPEN);
  521. translate(SSH1_CMSG_PORT_FORWARD_REQUEST);
  522. translate(SSH1_MSG_PORT_OPEN);
  523. translate(SSH1_CMSG_AGENT_REQUEST_FORWARDING);
  524. translate(SSH1_SMSG_AGENT_OPEN);
  525. translate(SSH1_MSG_IGNORE);
  526. translate(SSH1_CMSG_EXIT_CONFIRMATION);
  527. translate(SSH1_CMSG_X11_REQUEST_FORWARDING);
  528. translate(SSH1_CMSG_AUTH_RHOSTS_RSA);
  529. translate(SSH1_MSG_DEBUG);
  530. translate(SSH1_CMSG_REQUEST_COMPRESSION);
  531. translate(SSH1_CMSG_AUTH_TIS);
  532. translate(SSH1_SMSG_AUTH_TIS_CHALLENGE);
  533. translate(SSH1_CMSG_AUTH_TIS_RESPONSE);
  534. translate(SSH1_CMSG_AUTH_CCARD);
  535. translate(SSH1_SMSG_AUTH_CCARD_CHALLENGE);
  536. translate(SSH1_CMSG_AUTH_CCARD_RESPONSE);
  537. return "unknown";
  538. }
  539. const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type)
  540. {
  541. translatea(SSH2_MSG_USERAUTH_GSSAPI_RESPONSE,SSH2_PKTCTX_GSSAPI);
  542. translatea(SSH2_MSG_USERAUTH_GSSAPI_TOKEN,SSH2_PKTCTX_GSSAPI);
  543. translatea(SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE,SSH2_PKTCTX_GSSAPI);
  544. translatea(SSH2_MSG_USERAUTH_GSSAPI_ERROR,SSH2_PKTCTX_GSSAPI);
  545. translatea(SSH2_MSG_USERAUTH_GSSAPI_ERRTOK,SSH2_PKTCTX_GSSAPI);
  546. translatea(SSH2_MSG_USERAUTH_GSSAPI_MIC, SSH2_PKTCTX_GSSAPI);
  547. translate(SSH2_MSG_DISCONNECT);
  548. translate(SSH2_MSG_IGNORE);
  549. translate(SSH2_MSG_UNIMPLEMENTED);
  550. translate(SSH2_MSG_DEBUG);
  551. translate(SSH2_MSG_SERVICE_REQUEST);
  552. translate(SSH2_MSG_SERVICE_ACCEPT);
  553. translate(SSH2_MSG_KEXINIT);
  554. translate(SSH2_MSG_NEWKEYS);
  555. translatek(SSH2_MSG_KEXDH_INIT, SSH2_PKTCTX_DHGROUP);
  556. translatek(SSH2_MSG_KEXDH_REPLY, SSH2_PKTCTX_DHGROUP);
  557. translatek(SSH2_MSG_KEX_DH_GEX_REQUEST_OLD, SSH2_PKTCTX_DHGEX);
  558. translatek(SSH2_MSG_KEX_DH_GEX_REQUEST, SSH2_PKTCTX_DHGEX);
  559. translatek(SSH2_MSG_KEX_DH_GEX_GROUP, SSH2_PKTCTX_DHGEX);
  560. translatek(SSH2_MSG_KEX_DH_GEX_INIT, SSH2_PKTCTX_DHGEX);
  561. translatek(SSH2_MSG_KEX_DH_GEX_REPLY, SSH2_PKTCTX_DHGEX);
  562. translatek(SSH2_MSG_KEXRSA_PUBKEY, SSH2_PKTCTX_RSAKEX);
  563. translatek(SSH2_MSG_KEXRSA_SECRET, SSH2_PKTCTX_RSAKEX);
  564. translatek(SSH2_MSG_KEXRSA_DONE, SSH2_PKTCTX_RSAKEX);
  565. translatek(SSH2_MSG_KEX_ECDH_INIT, SSH2_PKTCTX_ECDHKEX);
  566. translatek(SSH2_MSG_KEX_ECDH_REPLY, SSH2_PKTCTX_ECDHKEX);
  567. translatek(SSH2_MSG_KEXGSS_INIT, SSH2_PKTCTX_GSSKEX);
  568. translatek(SSH2_MSG_KEXGSS_CONTINUE, SSH2_PKTCTX_GSSKEX);
  569. translatek(SSH2_MSG_KEXGSS_COMPLETE, SSH2_PKTCTX_GSSKEX);
  570. translatek(SSH2_MSG_KEXGSS_HOSTKEY, SSH2_PKTCTX_GSSKEX);
  571. translatek(SSH2_MSG_KEXGSS_ERROR, SSH2_PKTCTX_GSSKEX);
  572. translatek(SSH2_MSG_KEXGSS_GROUPREQ, SSH2_PKTCTX_GSSKEX);
  573. translatek(SSH2_MSG_KEXGSS_GROUP, SSH2_PKTCTX_GSSKEX);
  574. translate(SSH2_MSG_USERAUTH_REQUEST);
  575. translate(SSH2_MSG_USERAUTH_FAILURE);
  576. translate(SSH2_MSG_USERAUTH_SUCCESS);
  577. translate(SSH2_MSG_USERAUTH_BANNER);
  578. translatea(SSH2_MSG_USERAUTH_PK_OK, SSH2_PKTCTX_PUBLICKEY);
  579. translatea(SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ, SSH2_PKTCTX_PASSWORD);
  580. translatea(SSH2_MSG_USERAUTH_INFO_REQUEST, SSH2_PKTCTX_KBDINTER);
  581. translatea(SSH2_MSG_USERAUTH_INFO_RESPONSE, SSH2_PKTCTX_KBDINTER);
  582. translate(SSH2_MSG_GLOBAL_REQUEST);
  583. translate(SSH2_MSG_REQUEST_SUCCESS);
  584. translate(SSH2_MSG_REQUEST_FAILURE);
  585. translate(SSH2_MSG_CHANNEL_OPEN);
  586. translate(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
  587. translate(SSH2_MSG_CHANNEL_OPEN_FAILURE);
  588. translate(SSH2_MSG_CHANNEL_WINDOW_ADJUST);
  589. translate(SSH2_MSG_CHANNEL_DATA);
  590. translate(SSH2_MSG_CHANNEL_EXTENDED_DATA);
  591. translate(SSH2_MSG_CHANNEL_EOF);
  592. translate(SSH2_MSG_CHANNEL_CLOSE);
  593. translate(SSH2_MSG_CHANNEL_REQUEST);
  594. translate(SSH2_MSG_CHANNEL_SUCCESS);
  595. translate(SSH2_MSG_CHANNEL_FAILURE);
  596. return "unknown";
  597. }
  598. #undef translate
  599. #undef translatec