Blame include/libssh/server.h

Packit Service 31306d
/* Public include file for server support */
Packit Service 31306d
/*
Packit Service 31306d
 * This file is part of the SSH Library
Packit Service 31306d
 *
Packit Service 31306d
 * Copyright (c) 2003-2008 by Aris Adamantiadis
Packit Service 31306d
 *
Packit Service 31306d
 * This library is free software; you can redistribute it and/or
Packit Service 31306d
 * modify it under the terms of the GNU Lesser General Public
Packit Service 31306d
 * License as published by the Free Software Foundation; either
Packit Service 31306d
 * version 2.1 of the License, or (at your option) any later version.
Packit Service 31306d
 *
Packit Service 31306d
 * This library is distributed in the hope that it will be useful,
Packit Service 31306d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 31306d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 31306d
 * Lesser General Public License for more details.
Packit Service 31306d
 *
Packit Service 31306d
 * You should have received a copy of the GNU Lesser General Public
Packit Service 31306d
 * License along with this library; if not, write to the Free Software
Packit Service 31306d
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @defgroup libssh_server The libssh server API
Packit Service 31306d
 *
Packit Service 31306d
 * @{
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
#ifndef SERVER_H
Packit Service 31306d
#define SERVER_H
Packit Service 31306d
Packit Service 31306d
#include "libssh/libssh.h"
Packit Service 31306d
#define SERVERBANNER CLIENTBANNER
Packit Service 31306d
Packit Service 31306d
#ifdef __cplusplus
Packit Service 31306d
extern "C" {
Packit Service 31306d
#endif
Packit Service 31306d
Packit Service 31306d
enum ssh_bind_options_e {
Packit Service 31306d
  SSH_BIND_OPTIONS_BINDADDR,
Packit Service 31306d
  SSH_BIND_OPTIONS_BINDPORT,
Packit Service 31306d
  SSH_BIND_OPTIONS_BINDPORT_STR,
Packit Service 31306d
  SSH_BIND_OPTIONS_HOSTKEY,
Packit Service 31306d
  SSH_BIND_OPTIONS_DSAKEY,
Packit Service 31306d
  SSH_BIND_OPTIONS_RSAKEY,
Packit Service 31306d
  SSH_BIND_OPTIONS_BANNER,
Packit Service 31306d
  SSH_BIND_OPTIONS_LOG_VERBOSITY,
Packit Service 31306d
  SSH_BIND_OPTIONS_LOG_VERBOSITY_STR,
Packit Service 31306d
  SSH_BIND_OPTIONS_ECDSAKEY,
Packit Service 31306d
  SSH_BIND_OPTIONS_IMPORT_KEY,
Packit Service 31306d
  SSH_BIND_OPTIONS_KEY_EXCHANGE,
Packit Service 31306d
  SSH_BIND_OPTIONS_CIPHERS_C_S,
Packit Service 31306d
  SSH_BIND_OPTIONS_CIPHERS_S_C,
Packit Service 31306d
  SSH_BIND_OPTIONS_HMAC_C_S,
Packit Service 31306d
  SSH_BIND_OPTIONS_HMAC_S_C,
Packit Service 31306d
  SSH_BIND_OPTIONS_CONFIG_DIR,
Packit Service 31306d
  SSH_BIND_OPTIONS_PUBKEY_ACCEPTED_KEY_TYPES,
Packit Service 31306d
  SSH_BIND_OPTIONS_HOSTKEY_ALGORITHMS,
Packit Service 31306d
  SSH_BIND_OPTIONS_PROCESS_CONFIG,
Packit Service 31306d
};
Packit Service 31306d
Packit Service 31306d
typedef struct ssh_bind_struct* ssh_bind;
Packit Service 31306d
Packit Service 31306d
/* Callback functions */
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Incoming connection callback. This callback is called when a ssh_bind
Packit Service 31306d
 *        has a new incoming connection.
Packit Service 31306d
 * @param sshbind Current sshbind session handler
Packit Service 31306d
 * @param userdata Userdata to be passed to the callback function.
Packit Service 31306d
 */
Packit Service 31306d
typedef void (*ssh_bind_incoming_connection_callback) (ssh_bind sshbind,
Packit Service 31306d
    void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief These are the callbacks exported by the ssh_bind structure.
Packit Service 31306d
 *
Packit Service 31306d
 * They are called by the server module when events appear on the network.
Packit Service 31306d
 */
Packit Service 31306d
struct ssh_bind_callbacks_struct {
Packit Service 31306d
  /** DON'T SET THIS use ssh_callbacks_init() instead. */
Packit Service 31306d
  size_t size;
Packit Service 31306d
  /** A new connection is available. */
Packit Service 31306d
  ssh_bind_incoming_connection_callback incoming_connection;
Packit Service 31306d
};
Packit Service 31306d
typedef struct ssh_bind_callbacks_struct *ssh_bind_callbacks;
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Creates a new SSH server bind.
Packit Service 31306d
 *
Packit Service 31306d
 * @return A newly allocated ssh_bind session pointer.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API ssh_bind ssh_bind_new(void);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind,
Packit Service 31306d
    enum ssh_bind_options_e type, const void *value);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_bind_options_parse_config(ssh_bind sshbind,
Packit Service 31306d
    const char *filename);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Start listening to the socket.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to use.
Packit Service 31306d
 *
Packit Service 31306d
 * @return 0 on success, < 0 on error.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_bind_listen(ssh_bind ssh_bind_o);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the callback for this bind.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] sshbind   The bind to set the callback on.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] callbacks An already set up ssh_bind_callbacks instance.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] userdata  A pointer to private data to pass to the callbacks.
Packit Service 31306d
 *
Packit Service 31306d
 * @return              SSH_OK on success, SSH_ERROR if an error occured.
Packit Service 31306d
 *
Packit Service 31306d
 * @code
Packit Service 31306d
 *     struct ssh_callbacks_struct cb = {
Packit Service 31306d
 *         .userdata = data,
Packit Service 31306d
 *         .auth_function = my_auth_function
Packit Service 31306d
 *     };
Packit Service 31306d
 *     ssh_callbacks_init(&cb;;
Packit Service 31306d
 *     ssh_bind_set_callbacks(session, &cb;;
Packit Service 31306d
 * @endcode
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_bind_set_callbacks(ssh_bind sshbind, ssh_bind_callbacks callbacks,
Packit Service 31306d
    void *userdata);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief  Set the session to blocking/nonblocking mode.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to use.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  blocking     Zero for nonblocking mode.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API void ssh_bind_set_blocking(ssh_bind ssh_bind_o, int blocking);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Recover the file descriptor from the session.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to get the fd from.
Packit Service 31306d
 *
Packit Service 31306d
 * @return The file descriptor.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API socket_t ssh_bind_get_fd(ssh_bind ssh_bind_o);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the file descriptor for a session.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to set the fd.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  fd           The file descriptssh_bind B
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API void ssh_bind_set_fd(ssh_bind ssh_bind_o, socket_t fd);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Allow the file descriptor to accept new sessions.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to use.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Accept an incoming ssh connection and initialize the session.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to accept a connection.
Packit Service 31306d
 * @param  session			A preallocated ssh session
Packit Service 31306d
 * @see ssh_new
Packit Service 31306d
 * @return SSH_OK when a connection is established
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Accept an incoming ssh connection on the given file descriptor
Packit Service 31306d
 *        and initialize the session.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to accept a connection.
Packit Service 31306d
 * @param  session        A preallocated ssh session
Packit Service 31306d
 * @param  fd             A file descriptor of an already established TCP
Packit Service 31306d
 *                          inbound connection
Packit Service 31306d
 * @see ssh_new
Packit Service 31306d
 * @see ssh_bind_accept
Packit Service 31306d
 * @return SSH_OK when a connection is established
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_bind_accept_fd(ssh_bind ssh_bind_o, ssh_session session,
Packit Service 31306d
        socket_t fd);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API ssh_gssapi_creds ssh_gssapi_get_creds(ssh_session session);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Handles the key exchange and set up encryption
Packit Service 31306d
 *
Packit Service 31306d
 * @param  session			A connected ssh session
Packit Service 31306d
 * @see ssh_bind_accept
Packit Service 31306d
 * @return SSH_OK if the key exchange was successful
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_handle_key_exchange(ssh_session session);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Initialize the set of key exchange, hostkey, ciphers, MACs, and
Packit Service 31306d
 *        compression algorithms for the given ssh_session.
Packit Service 31306d
 *
Packit Service 31306d
 * The selection of algorithms and keys used are determined by the
Packit Service 31306d
 * options that are currently set in the given ssh_session structure.
Packit Service 31306d
 * May only be called before the initial key exchange has begun.
Packit Service 31306d
 *
Packit Service 31306d
 * @param session  The session structure to initialize.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_handle_key_exchange
Packit Service 31306d
 * @see ssh_options_set
Packit Service 31306d
 *
Packit Service 31306d
 * @return SSH_OK if initialization succeeds.
Packit Service 31306d
 */
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_server_init_kex(ssh_session session);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Free a ssh servers bind.
Packit Service 31306d
 *
Packit Service 31306d
 * @param  ssh_bind_o     The ssh server bind to free.
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind_o);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Set the acceptable authentication methods to be sent to the client.
Packit Service 31306d
 *
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in]  session  The server session
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in]  auth_methods The authentication methods we will support, which
Packit Service 31306d
 *                          can be bitwise-or'd.
Packit Service 31306d
 *
Packit Service 31306d
 *                          Supported methods are:
Packit Service 31306d
 *
Packit Service 31306d
 *                          SSH_AUTH_METHOD_PASSWORD
Packit Service 31306d
 *                          SSH_AUTH_METHOD_PUBLICKEY
Packit Service 31306d
 *                          SSH_AUTH_METHOD_HOSTBASED
Packit Service 31306d
 *                          SSH_AUTH_METHOD_INTERACTIVE
Packit Service 31306d
 *                          SSH_AUTH_METHOD_GSSAPI_MIC
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API void ssh_set_auth_methods(ssh_session session, int auth_methods);
Packit Service 31306d
Packit Service 31306d
/**********************************************************
Packit Service 31306d
 * SERVER MESSAGING
Packit Service 31306d
 **********************************************************/
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Reply with a standard reject message.
Packit Service 31306d
 *
Packit Service 31306d
 * Use this function if you don't know what to respond or if you want to reject
Packit Service 31306d
 * a request.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] msg       The message to use for the reply.
Packit Service 31306d
 *
Packit Service 31306d
 * @return              0 on success, -1 on error.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_message_get()
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API int ssh_message_reply_default(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Get the name of the authenticated user.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] msg       The message to get the username from.
Packit Service 31306d
 *
Packit Service 31306d
 * @return              The username or NULL if an error occured.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_message_get()
Packit Service 31306d
 * @see ssh_message_type()
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API const char *ssh_message_auth_user(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Get the password of the authenticated user.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] msg       The message to get the password from.
Packit Service 31306d
 *
Packit Service 31306d
 * @return              The username or NULL if an error occured.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_message_get()
Packit Service 31306d
 * @see ssh_message_type()
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API const char *ssh_message_auth_password(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
/**
Packit Service 31306d
 * @brief Get the publickey of the authenticated user.
Packit Service 31306d
 *
Packit Service 31306d
 * If you need the key for later user you should duplicate it.
Packit Service 31306d
 *
Packit Service 31306d
 * @param[in] msg       The message to get the public key from.
Packit Service 31306d
 *
Packit Service 31306d
 * @return              The public key or NULL.
Packit Service 31306d
 *
Packit Service 31306d
 * @see ssh_key_dup()
Packit Service 31306d
 * @see ssh_key_cmp()
Packit Service 31306d
 * @see ssh_message_get()
Packit Service 31306d
 * @see ssh_message_type()
Packit Service 31306d
 */
Packit Service 31306d
LIBSSH_API ssh_key ssh_message_auth_pubkey(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_message_auth_kbdint_is_response(ssh_message msg);
Packit Service 31306d
LIBSSH_API enum ssh_publickey_state_e ssh_message_auth_publickey_state(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_auth_reply_success(ssh_message msg,int partial);
Packit Service 31306d
LIBSSH_API int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pubkey);
Packit Service 31306d
LIBSSH_API int ssh_message_auth_reply_pk_ok_simple(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_message_auth_set_methods(ssh_message msg, int methods);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_message_auth_interactive_request(ssh_message msg,
Packit Service 31306d
                    const char *name, const char *instruction,
Packit Service 31306d
                    unsigned int num_prompts, const char **prompts, char *echo);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_message_service_reply_success(ssh_message msg);
Packit Service 31306d
LIBSSH_API const char *ssh_message_service_service(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_message_global_request_reply_success(ssh_message msg,
Packit Service 31306d
                                                        uint16_t bound_port);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API void ssh_set_message_callback(ssh_session session,
Packit Service 31306d
    int(*ssh_bind_message_callback)(ssh_session session, ssh_message msg, void *data),
Packit Service 31306d
    void *data);
Packit Service 31306d
LIBSSH_API int ssh_execute_message_callbacks(ssh_session session);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_open_originator(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_open_originator_port(ssh_message msg);
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_open_destination(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_open_destination_port(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API ssh_channel ssh_message_channel_request_channel(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_pty_term(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_pty_width(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_pty_height(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_pty_pxwidth(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_pty_pxheight(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_env_name(ssh_message msg);
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_env_value(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_command(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_subsystem(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_x11_single_connection(ssh_message msg);
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_x11_auth_protocol(ssh_message msg);
Packit Service 31306d
LIBSSH_API const char *ssh_message_channel_request_x11_auth_cookie(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_channel_request_x11_screen_number(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API const char *ssh_message_global_request_address(ssh_message msg);
Packit Service 31306d
LIBSSH_API int ssh_message_global_request_port(ssh_message msg);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost,
Packit Service 31306d
    int remoteport, const char *sourcehost, int localport);
Packit Service 31306d
LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, 
Packit Service 31306d
                                        const char *orig_addr, int orig_port);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_channel_request_send_exit_status(ssh_channel channel,
Packit Service 31306d
                                                int exit_status);
Packit Service 31306d
LIBSSH_API int ssh_channel_request_send_exit_signal(ssh_channel channel,
Packit Service 31306d
                                                const char *signum,
Packit Service 31306d
                                                int core,
Packit Service 31306d
                                                const char *errmsg,
Packit Service 31306d
                                                const char *lang);
Packit Service 31306d
Packit Service 31306d
LIBSSH_API int ssh_send_keepalive(ssh_session session);
Packit Service 31306d
Packit Service 31306d
/* deprecated functions */
Packit Service 31306d
SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session);
Packit Service 31306d
SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel,
Packit Service 31306d
        const void *data, uint32_t len);
Packit Service 31306d
Packit Service 31306d
#ifdef __cplusplus
Packit Service 31306d
}
Packit Service 31306d
#endif /* __cplusplus */
Packit Service 31306d
Packit Service 31306d
#endif /* SERVER_H */
Packit Service 31306d
Packit Service 31306d
/** @} */