1 module libssh.c_bindings.server; 2 3 import libssh.c_bindings.libssh; 4 5 enum ssh_bind_options_e { 6 SSH_BIND_OPTIONS_BINDADDR, 7 SSH_BIND_OPTIONS_BINDPORT, 8 SSH_BIND_OPTIONS_BINDPORT_STR, 9 SSH_BIND_OPTIONS_HOSTKEY, 10 SSH_BIND_OPTIONS_DSAKEY, 11 SSH_BIND_OPTIONS_RSAKEY, 12 SSH_BIND_OPTIONS_BANNER, 13 SSH_BIND_OPTIONS_LOG_VERBOSITY, 14 SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, 15 SSH_BIND_OPTIONS_ECDSAKEY 16 }; 17 18 struct ssh_bind_struct { } 19 alias ssh_bind = ssh_bind_struct*; 20 21 /* Callback functions */ 22 23 /** 24 * @brief Incoming connection callback. This callback is called when a ssh_bind 25 * has a new incoming connection. 26 * @param sshbind Current sshbind session handler 27 * @param userdata Userdata to be passed to the callback function. 28 */ 29 alias ssh_bind_incoming_connection_callback = extern(C) void function(ssh_bind sshbind, 30 void *userdata); 31 32 /** 33 * @brief These are the callbacks exported by the ssh_bind structure. 34 * 35 * They are called by the server module when events appear on the network. 36 */ 37 struct ssh_bind_callbacks_struct { 38 /** DON'T SET THIS use ssh_callbacks_init() instead. */ 39 size_t size; 40 /** A new connection is available. */ 41 ssh_bind_incoming_connection_callback incoming_connection; 42 }; 43 alias ssh_bind_callbacks = ssh_bind_callbacks_struct*; 44 45 extern(C) { 46 /** 47 * @brief Creates a new SSH server bind. 48 * 49 * @return A newly allocated ssh_bind session pointer. 50 */ 51 ssh_bind ssh_bind_new(); 52 53 int ssh_bind_options_set(ssh_bind sshbind, 54 ssh_bind_options_e type, const void *value); 55 56 /** 57 * @brief Start listening to the socket. 58 * 59 * @param ssh_bind_o The ssh server bind to use. 60 * 61 * @return 0 on success, < 0 on error. 62 */ 63 int ssh_bind_listen(ssh_bind ssh_bind_o); 64 65 /** 66 * @brief Set the callback for this bind. 67 * 68 * @param[in] sshbind The bind to set the callback on. 69 * 70 * @param[in] callbacks An already set up ssh_bind_callbacks instance. 71 * 72 * @param[in] userdata A pointer to private data to pass to the callbacks. 73 * 74 * @return SSH_OK on success, SSH_ERROR if an error occured. 75 * 76 * @code 77 * struct ssh_callbacks_struct cb = { 78 * .userdata = data, 79 * .auth_function = my_auth_function 80 * }; 81 * ssh_callbacks_init(&cb); 82 * ssh_bind_set_callbacks(session, &cb); 83 * @endcode 84 */ 85 int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks, 86 void *userdata); 87 88 /** 89 * @brief Set the session to blocking/nonblocking mode. 90 * 91 * @param ssh_bind_o The ssh server bind to use. 92 * 93 * @param blocking Zero for nonblocking mode. 94 */ 95 void ssh_bind_set_blocking(ssh_bind ssh_bind_o, int blocking); 96 97 /** 98 * @brief Recover the file descriptor from the session. 99 * 100 * @param ssh_bind_o The ssh server bind to get the fd from. 101 * 102 * @return The file descriptor. 103 */ 104 socket_t ssh_bind_get_fd(ssh_bind ssh_bind_o); 105 106 /** 107 * @brief Set the file descriptor for a session. 108 * 109 * @param ssh_bind_o The ssh server bind to set the fd. 110 * 111 * @param fd The file descriptssh_bind B 112 */ 113 void ssh_bind_set_fd(ssh_bind ssh_bind_o, socket_t fd); 114 115 /** 116 * @brief Allow the file descriptor to accept new sessions. 117 * 118 * @param ssh_bind_o The ssh server bind to use. 119 */ 120 void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o); 121 122 /** 123 * @brief Accept an incoming ssh connection and initialize the session. 124 * 125 * @param ssh_bind_o The ssh server bind to accept a connection. 126 * @param session A preallocated ssh session 127 * @see ssh_new 128 * @return SSH_OK when a connection is established 129 */ 130 int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session); 131 132 /** 133 * @brief Accept an incoming ssh connection on the given file descriptor 134 * and initialize the session. 135 * 136 * @param ssh_bind_o The ssh server bind to accept a connection. 137 * @param session A preallocated ssh session 138 * @param fd A file descriptor of an already established TCP 139 * inbound connection 140 * @see ssh_new 141 * @see ssh_bind_accept 142 * @return SSH_OK when a connection is established 143 */ 144 int ssh_bind_accept_fd(ssh_bind ssh_bind_o, ssh_session session, 145 socket_t fd); 146 147 ssh_gssapi_creds ssh_gssapi_get_creds(ssh_session session); 148 149 /** 150 * @brief Handles the key exchange and set up encryption 151 * 152 * @param session A connected ssh session 153 * @see ssh_bind_accept 154 * @return SSH_OK if the key exchange was successful 155 */ 156 int ssh_handle_key_exchange(ssh_session session); 157 158 /** 159 * @brief Free a ssh servers bind. 160 * 161 * @param ssh_bind_o The ssh server bind to free. 162 */ 163 void ssh_bind_free(ssh_bind ssh_bind_o); 164 165 void ssh_set_auth_methods(ssh_session session, int auth_methods); 166 167 /********************************************************** 168 * SERVER MESSAGING 169 **********************************************************/ 170 171 /** 172 * @brief Reply with a standard reject message. 173 * 174 * Use this function if you don't know what to respond or if you want to reject 175 * a request. 176 * 177 * @param[in] msg The message to use for the reply. 178 * 179 * @return 0 on success, -1 on error. 180 * 181 * @see ssh_message_get() 182 */ 183 int ssh_message_reply_default(ssh_message msg); 184 185 /** 186 * @brief Get the name of the authenticated user. 187 * 188 * @param[in] msg The message to get the username from. 189 * 190 * @return The username or NULL if an error occured. 191 * 192 * @see ssh_message_get() 193 * @see ssh_message_type() 194 */ 195 const(char) *ssh_message_auth_user(ssh_message msg); 196 197 /** 198 * @brief Get the password of the authenticated user. 199 * 200 * @param[in] msg The message to get the password from. 201 * 202 * @return The username or NULL if an error occured. 203 * 204 * @see ssh_message_get() 205 * @see ssh_message_type() 206 */ 207 const(char) *ssh_message_auth_password(ssh_message msg); 208 209 /** 210 * @brief Get the publickey of the authenticated user. 211 * 212 * If you need the key for later user you should duplicate it. 213 * 214 * @param[in] msg The message to get the public key from. 215 * 216 * @return The public key or NULL. 217 * 218 * @see ssh_key_dup() 219 * @see ssh_key_cmp() 220 * @see ssh_message_get() 221 * @see ssh_message_type() 222 */ 223 ssh_key ssh_message_auth_pubkey(ssh_message msg); 224 225 int ssh_message_auth_kbdint_is_response(ssh_message msg); 226 enum ssh_publickey_state_e ssh_message_auth_publickey_state(ssh_message msg); 227 int ssh_message_auth_reply_success(ssh_message msg,int partial); 228 int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pubkey); 229 int ssh_message_auth_reply_pk_ok_simple(ssh_message msg); 230 231 int ssh_message_auth_set_methods(ssh_message msg, int methods); 232 233 int ssh_message_auth_interactive_request(ssh_message msg, 234 const char *name, const char *instruction, 235 uint num_prompts, const char **prompts, char *echo); 236 237 int ssh_message_service_reply_success(ssh_message msg); 238 const(char) *ssh_message_service_service(ssh_message msg); 239 240 int ssh_message_global_request_reply_success(ssh_message msg, 241 ushort bound_port); 242 243 alias ssh_bind_message_callback_type = extern(C) int function(ssh_session session, ssh_message msg, void *data); 244 void ssh_set_message_callback(ssh_session session, 245 ssh_bind_message_callback_type ssh_bind_message_callback, 246 void *data); 247 int ssh_execute_message_callbacks(ssh_session session); 248 249 const(char) *ssh_message_channel_request_open_originator(ssh_message msg); 250 int ssh_message_channel_request_open_originator_port(ssh_message msg); 251 const(char) *ssh_message_channel_request_open_destination(ssh_message msg); 252 int ssh_message_channel_request_open_destination_port(ssh_message msg); 253 254 ssh_channel ssh_message_channel_request_channel(ssh_message msg); 255 256 const(char) *ssh_message_channel_request_pty_term(ssh_message msg); 257 int ssh_message_channel_request_pty_width(ssh_message msg); 258 int ssh_message_channel_request_pty_height(ssh_message msg); 259 int ssh_message_channel_request_pty_pxwidth(ssh_message msg); 260 int ssh_message_channel_request_pty_pxheight(ssh_message msg); 261 262 const(char) *ssh_message_channel_request_env_name(ssh_message msg); 263 const(char) *ssh_message_channel_request_env_value(ssh_message msg); 264 265 const(char) *ssh_message_channel_request_command(ssh_message msg); 266 267 const(char) *ssh_message_channel_request_subsystem(ssh_message msg); 268 269 int ssh_message_channel_request_x11_single_connection(ssh_message msg); 270 const(char) *ssh_message_channel_request_x11_auth_protocol(ssh_message msg); 271 const(char) *ssh_message_channel_request_x11_auth_cookie(ssh_message msg); 272 int ssh_message_channel_request_x11_screen_number(ssh_message msg); 273 274 const(char) *ssh_message_global_request_address(ssh_message msg); 275 int ssh_message_global_request_port(ssh_message msg); 276 277 int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost, 278 int remoteport, const char *sourcehost, int localport); 279 // int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port); // Dublicated in libssh.d 280 281 int ssh_channel_request_send_exit_status(ssh_channel channel, 282 int exit_status); 283 int ssh_channel_request_send_exit_signal(ssh_channel channel, 284 const char *signum, 285 int core, 286 const char *errmsg, 287 const char *lang); 288 int ssh_channel_write_stderr(ssh_channel channel, 289 const void *data, 290 uint len); 291 292 int ssh_send_keepalive(ssh_session session); 293 294 /* deprecated functions */ 295 deprecated int ssh_accept(ssh_session session); 296 deprecated int channel_write_stderr(ssh_channel channel, 297 const void *data, uint len); 298 }