sshppl.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Abstraction of the various layers of SSH packet-level protocol,
  3. * general enough to take in all three of the main SSH-2 layers and
  4. * both of the SSH-1 phases.
  5. */
  6. #ifndef PUTTY_SSHPPL_H
  7. #define PUTTY_SSHPPL_H
  8. typedef void (*packet_handler_fn_t)(PacketProtocolLayer *ppl, PktIn *pktin);
  9. struct PacketProtocolLayerVtable {
  10. void (*free)(PacketProtocolLayer *);
  11. void (*process_queue)(PacketProtocolLayer *ppl);
  12. int (*get_specials)(
  13. PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
  14. void (*special_cmd)(
  15. PacketProtocolLayer *ppl, SessionSpecialCode code, int arg);
  16. int (*want_user_input)(PacketProtocolLayer *ppl);
  17. void (*got_user_input)(PacketProtocolLayer *ppl);
  18. void (*reconfigure)(PacketProtocolLayer *ppl, Conf *conf);
  19. /* Protocol-level name of this layer. */
  20. const char *name;
  21. };
  22. struct PacketProtocolLayer {
  23. const struct PacketProtocolLayerVtable *vt;
  24. /* Link to the underlying SSH BPP. */
  25. BinaryPacketProtocol *bpp;
  26. /* Queue from which the layer receives its input packets, and one
  27. * to put its output packets on. */
  28. PktInQueue *in_pq;
  29. PktOutQueue *out_pq;
  30. /* Idempotent callback that in_pq will be linked to, causing a
  31. * call to the process_queue method. in_pq points to this, so it
  32. * will be automatically triggered by pushing things on the
  33. * layer's input queue, but it can also be triggered on purpose. */
  34. IdempotentCallback ic_process_queue;
  35. /* Owner's pointer to this layer. Permits a layer to unilaterally
  36. * abdicate in favour of a replacement, by overwriting this
  37. * pointer and then freeing itself. */
  38. PacketProtocolLayer **selfptr;
  39. /* Bufchain of keyboard input from the user, for login prompts and
  40. * similar. */
  41. bufchain *user_input;
  42. /* Logging and error-reporting facilities. */
  43. LogContext *logctx;
  44. Seat *seat; /* for dialog boxes, session output etc */
  45. Ssh *ssh; /* for session termination + assorted connection-layer ops */
  46. /* Known bugs in the remote implementation. */
  47. unsigned remote_bugs;
  48. };
  49. #define ssh_ppl_process_queue(ppl) ((ppl)->vt->process_queue(ppl))
  50. #define ssh_ppl_get_specials(ppl, add, ctx) \
  51. ((ppl)->vt->get_specials(ppl, add, ctx))
  52. #define ssh_ppl_special_cmd(ppl, code, arg) \
  53. ((ppl)->vt->special_cmd(ppl, code, arg))
  54. #define ssh_ppl_want_user_input(ppl) ((ppl)->vt->want_user_input(ppl))
  55. #define ssh_ppl_got_user_input(ppl) ((ppl)->vt->got_user_input(ppl))
  56. #define ssh_ppl_reconfigure(ppl, conf) ((ppl)->vt->reconfigure(ppl, conf))
  57. /* ssh_ppl_free is more than just a macro wrapper on the vtable; it
  58. * does centralised parts of the freeing too. */
  59. void ssh_ppl_free(PacketProtocolLayer *ppl);
  60. /* Helper routine to point a PPL at its input and output queues. Also
  61. * sets up the IdempotentCallback on the input queue to trigger a call
  62. * to process_queue whenever packets are added to it. */
  63. void ssh_ppl_setup_queues(PacketProtocolLayer *ppl,
  64. PktInQueue *inq, PktOutQueue *outq);
  65. /* Routine a PPL can call to abdicate in favour of a replacement, by
  66. * overwriting ppl->selfptr. Has the side effect of freeing 'old', so
  67. * if 'old' actually called this (which is likely) then it should
  68. * avoid dereferencing itself on return from this function! */
  69. void ssh_ppl_replace(PacketProtocolLayer *old, PacketProtocolLayer *new);
  70. PacketProtocolLayer *ssh1_login_new(
  71. Conf *conf, const char *host, int port,
  72. PacketProtocolLayer *successor_layer);
  73. PacketProtocolLayer *ssh1_connection_new(
  74. Ssh *ssh, Conf *conf, ConnectionLayer **cl_out);
  75. struct DataTransferStats;
  76. struct ssh_connection_shared_gss_state;
  77. PacketProtocolLayer *ssh2_transport_new(
  78. Conf *conf, const char *host, int port, const char *fullhostname,
  79. const char *client_greeting, const char *server_greeting,
  80. struct ssh_connection_shared_gss_state *shgss,
  81. struct DataTransferStats *stats,
  82. PacketProtocolLayer *higher_layer);
  83. PacketProtocolLayer *ssh2_userauth_new(
  84. PacketProtocolLayer *successor_layer,
  85. const char *hostname, const char *fullhostname,
  86. Filename *keyfile, int tryagent,
  87. const char *default_username, int change_username,
  88. int try_ki_auth,
  89. int try_gssapi_auth, int try_gssapi_kex_auth,
  90. int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss);
  91. PacketProtocolLayer *ssh2_connection_new(
  92. Ssh *ssh, ssh_sharing_state *connshare, int is_simple,
  93. Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out);
  94. /* Can't put this in the userauth constructor without having a
  95. * dependency loop at setup time (transport and userauth can't _both_
  96. * be constructed second and given a pointer to the other). */
  97. void ssh2_userauth_set_transport_layer(PacketProtocolLayer *userauth,
  98. PacketProtocolLayer *transport);
  99. /* Convenience macro for protocol layers to send formatted strings to
  100. * the Event Log. Assumes a function parameter called 'ppl' is in
  101. * scope, and takes a double pair of parens because it passes a whole
  102. * argument list to dupprintf. */
  103. #define ppl_logevent(params) ( \
  104. logevent_and_free((ppl)->logctx, dupprintf params))
  105. /* Convenience macro for protocol layers to send formatted strings to
  106. * the terminal. Also expects 'ppl' to be in scope and takes double
  107. * parens. */
  108. #define ppl_printf(params) \
  109. ssh_ppl_user_output_string_and_free(ppl, dupprintf params)
  110. void ssh_ppl_user_output_string_and_free(PacketProtocolLayer *ppl, char *text);
  111. /* Methods for userauth to communicate back to the transport layer */
  112. ptrlen ssh2_transport_get_session_id(PacketProtocolLayer *ssh2_transport_ptr);
  113. void ssh2_transport_notify_auth_done(PacketProtocolLayer *ssh2_transport_ptr);
  114. /* Methods for ssh1login to pass protocol flags to ssh1connection */
  115. void ssh1_connection_set_local_protoflags(PacketProtocolLayer *ppl, int flags);
  116. /* Shared get_specials method between the two ssh1 layers */
  117. int ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *);
  118. #endif /* PUTTY_SSHPPL_H */