server.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. typedef struct AuthPolicy AuthPolicy;
  2. struct SshServerConfig {
  3. const char *application_name;
  4. const char *session_starting_dir;
  5. RSAKey *rsa_kex_key;
  6. /*
  7. * In all of these ptrlens, setting the 'ptr' member to NULL means
  8. * that we're not overriding the default configuration.
  9. */
  10. ptrlen banner; /* default here is 'no banner' */
  11. ptrlen kex_override[NKEXLIST];
  12. bool exit_signal_numeric; /* mimic an old server bug */
  13. unsigned long ssh1_cipher_mask;
  14. bool ssh1_allow_compression;
  15. bool bare_connection;
  16. bool stunt_pretend_to_accept_any_pubkey;
  17. bool stunt_open_unconditional_agent_socket;
  18. bool stunt_allow_trivial_ki_auth;
  19. bool stunt_return_success_to_pubkey_offer;
  20. bool stunt_close_after_banner;
  21. };
  22. Plug *ssh_server_plug(
  23. Conf *conf, const SshServerConfig *ssc,
  24. ssh_key *const *hostkeys, int nhostkeys,
  25. RSAKey *hostkey1, AuthPolicy *authpolicy, LogPolicy *logpolicy,
  26. const SftpServerVtable *sftpserver_vt);
  27. void ssh_server_start(Plug *plug, Socket *socket);
  28. void server_instance_terminated(LogPolicy *logpolicy);
  29. void platform_logevent(const char *msg);
  30. #define AUTHMETHODS(X) \
  31. X(NONE) \
  32. X(PASSWORD) \
  33. X(PUBLICKEY) \
  34. X(KBDINT) \
  35. X(TIS) \
  36. X(CRYPTOCARD) \
  37. /* end of list */
  38. #define AUTHMETHOD_BIT_INDEX(name) AUTHMETHOD_BIT_INDEX_##name,
  39. enum { AUTHMETHODS(AUTHMETHOD_BIT_INDEX) AUTHMETHOD_BIT_INDEX_dummy };
  40. #define AUTHMETHOD_BIT_VALUE(name) \
  41. AUTHMETHOD_##name = 1 << AUTHMETHOD_BIT_INDEX_##name,
  42. enum { AUTHMETHODS(AUTHMETHOD_BIT_VALUE) AUTHMETHOD_BIT_VALUE_dummy };
  43. typedef struct AuthKbdInt AuthKbdInt;
  44. typedef struct AuthKbdIntPrompt AuthKbdIntPrompt;
  45. struct AuthKbdInt {
  46. char *title, *instruction; /* both need freeing */
  47. int nprompts;
  48. AuthKbdIntPrompt *prompts; /* the array itself needs freeing */
  49. };
  50. struct AuthKbdIntPrompt {
  51. char *prompt; /* needs freeing */
  52. bool echo;
  53. };
  54. unsigned auth_methods(AuthPolicy *);
  55. bool auth_none(AuthPolicy *, ptrlen username);
  56. int auth_password(AuthPolicy *, ptrlen username, ptrlen password,
  57. ptrlen *opt_new_password);
  58. /* auth_password returns 1 for 'accepted', 0 for 'rejected', and 2 for
  59. * 'ok but now you need to change your password' */
  60. bool auth_publickey(AuthPolicy *, ptrlen username, ptrlen public_blob);
  61. /* auth_publickey_ssh1 must return the whole public key given the modulus,
  62. * because the SSH-1 client never transmits the exponent over the wire.
  63. * The key remains owned by the AuthPolicy. */
  64. AuthKbdInt *auth_kbdint_prompts(AuthPolicy *, ptrlen username);
  65. /* auth_kbdint_prompts returns NULL to trigger auth failure */
  66. int auth_kbdint_responses(AuthPolicy *, const ptrlen *responses);
  67. /* auth_kbdint_responses returns >0 for success, <0 for failure, and 0
  68. * to indicate that we haven't decided yet and further prompts are
  69. * coming */
  70. /* The very similar SSH-1 TIS and CryptoCard methods are combined into
  71. * a single API for AuthPolicy, which takes a method argument */
  72. char *auth_ssh1int_challenge(AuthPolicy *, unsigned method, ptrlen username);
  73. bool auth_ssh1int_response(AuthPolicy *, ptrlen response);
  74. RSAKey *auth_publickey_ssh1(
  75. AuthPolicy *ap, ptrlen username, mp_int *rsa_modulus);
  76. /* auth_successful returns false if further authentication is needed */
  77. bool auth_successful(AuthPolicy *, ptrlen username, unsigned method);
  78. PacketProtocolLayer *ssh2_userauth_server_new(
  79. PacketProtocolLayer *successor_layer, AuthPolicy *authpolicy,
  80. const SshServerConfig *ssc);
  81. void ssh2_userauth_server_set_transport_layer(
  82. PacketProtocolLayer *userauth, PacketProtocolLayer *transport);
  83. void ssh2connection_server_configure(
  84. PacketProtocolLayer *ppl, const SftpServerVtable *sftpserver_vt,
  85. const SshServerConfig *ssc);
  86. void ssh1connection_server_configure(
  87. PacketProtocolLayer *ppl, const SshServerConfig *ssc);
  88. PacketProtocolLayer *ssh1_login_server_new(
  89. PacketProtocolLayer *successor_layer, RSAKey *hostkey,
  90. AuthPolicy *authpolicy, const SshServerConfig *ssc);
  91. Channel *sesschan_new(SshChannel *c, LogContext *logctx,
  92. const SftpServerVtable *sftpserver_vt,
  93. const SshServerConfig *ssc);
  94. Backend *pty_backend_create(
  95. Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd,
  96. struct ssh_ttymodes ttymodes, bool pipes_instead_of_pty, const char *dir,
  97. const char *const *env_vars_to_unset);
  98. int pty_backend_exit_signum(Backend *be);
  99. ptrlen pty_backend_exit_signame(Backend *be, char **aux_msg);
  100. /*
  101. * Establish a listening X server. Return value is the _number_ of
  102. * Sockets that it established pointing at the given Plug. (0
  103. * indicates complete failure.) The socket pointers themselves are
  104. * written into sockets[], up to a possible total of MAX_X11_SOCKETS.
  105. *
  106. * The supplied Conf has necessary environment variables written into
  107. * it. (And is also used to open the port listeners, though that
  108. * shouldn't affect anything.)
  109. */
  110. #define MAX_X11_SOCKETS 2
  111. int platform_make_x11_server(Plug *plug, const char *progname, int mindisp,
  112. const char *screen_number_suffix,
  113. ptrlen authproto, ptrlen authdata,
  114. Socket **sockets, Conf *conf);
  115. Conf *make_ssh_server_conf(void);
  116. /* Provided by Unix front end programs to unix/sftpserver.c */
  117. void make_unix_sftp_filehandle_key(void *data, size_t size);
  118. typedef struct agentfwd agentfwd;
  119. agentfwd *agentfwd_new(ConnectionLayer *cl, char **socketname_out);
  120. void agentfwd_free(agentfwd *agent);