include/libssh/session.h

00001 /*
00002  * This file is part of the SSH Library
00003  *
00004  * Copyright (c) 2009 by Aris Adamantiadis
00005  *
00006  * The SSH Library is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2.1 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * The SSH Library is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with the SSH Library; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019  * MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef SESSION_H_
00023 #define SESSION_H_
00024 #include "libssh/priv.h"
00025 #include "libssh/packet.h"
00026 #include "libssh/pcap.h"
00027 #include "libssh/auth.h"
00028 #include "libssh/channels.h"
00029 #include "libssh/poll.h"
00030 typedef struct ssh_kbdint_struct* ssh_kbdint;
00031 
00032 /* These are the different states a SSH session can be into its life */
00033 enum ssh_session_state_e {
00034   SSH_SESSION_STATE_NONE=0,
00035   SSH_SESSION_STATE_CONNECTING,
00036   SSH_SESSION_STATE_SOCKET_CONNECTED,
00037   SSH_SESSION_STATE_BANNER_RECEIVED,
00038   SSH_SESSION_STATE_INITIAL_KEX,
00039   SSH_SESSION_STATE_KEXINIT_RECEIVED,
00040   SSH_SESSION_STATE_DH,
00041   SSH_SESSION_STATE_AUTHENTICATING,
00042   SSH_SESSION_STATE_AUTHENTICATED,
00043   SSH_SESSION_STATE_ERROR,
00044   SSH_SESSION_STATE_DISCONNECTED
00045 };
00046 
00047 enum ssh_dh_state_e {
00048   DH_STATE_INIT=0,
00049   DH_STATE_INIT_SENT,
00050   DH_STATE_NEWKEYS_SENT,
00051   DH_STATE_FINISHED
00052 };
00053 
00054 enum ssh_pending_call_e {
00055   SSH_PENDING_CALL_NONE = 0,
00056   SSH_PENDING_CALL_CONNECT,
00057   SSH_PENDING_CALL_AUTH_NONE,
00058   SSH_PENDING_CALL_AUTH_PASSWORD
00059 };
00060 
00061 /* libssh calls may block an undefined amount of time */
00062 #define SSH_SESSION_FLAG_BLOCKING 1
00063 
00064 /* members that are common to ssh_session and ssh_bind */
00065 struct ssh_common_struct {
00066     struct error_struct error;
00067     ssh_callbacks callbacks; /* Callbacks to user functions */
00068     int log_verbosity; /* verbosity of the log functions */
00069     int log_indent; /* indentation level in enter_function logs */
00070 };
00071 
00072 struct ssh_session_struct {
00073     struct ssh_common_struct common;
00074     struct ssh_socket_struct *socket;
00075     char *serverbanner;
00076     char *clientbanner;
00077     int protoversion;
00078     int server;
00079     int client;
00080     int openssh;
00081     uint32_t send_seq;
00082     uint32_t recv_seq;
00083 /* status flags */
00084     int closed;
00085     int closed_by_except;
00086 
00087     int connected;
00088     /* !=0 when the user got a session handle */
00089     int alive;
00090     /* two previous are deprecated */
00091     /* int auth_service_asked; */
00092 
00093     /* session flags (SSH_SESSION_FLAG_*) */
00094     int flags;
00095 
00096     ssh_string banner; /* that's the issue banner from
00097                        the server */
00098     char *discon_msg; /* disconnect message from
00099                          the remote host */
00100     ssh_buffer in_buffer;
00101     PACKET in_packet;
00102     ssh_buffer out_buffer;
00103 
00104     /* the states are used by the nonblocking stuff to remember */
00105     /* where it was before being interrupted */
00106     enum ssh_pending_call_e pending_call_state;
00107     enum ssh_session_state_e session_state;
00108     int packet_state;
00109     enum ssh_dh_state_e dh_handshake_state;
00110     enum ssh_auth_service_state_e auth_service_state;
00111     enum ssh_auth_state_e auth_state;
00112     enum ssh_channel_request_state_e global_req_state;
00113     ssh_string dh_server_signature; /* information used by dh_handshake. */
00114     KEX server_kex;
00115     KEX client_kex;
00116     ssh_buffer in_hashbuf;
00117     ssh_buffer out_hashbuf;
00118     struct ssh_crypto_struct *current_crypto;
00119     struct ssh_crypto_struct *next_crypto;  /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
00120 
00121     struct ssh_list *channels; /* linked list of channels */
00122     int maxchannel;
00123     int exec_channel_opened; /* version 1 only. more
00124                                 info in channels1.c */
00125     ssh_agent agent; /* ssh agent */
00126 
00127 /* keyb interactive data */
00128     struct ssh_kbdint_struct *kbdint;
00129     int version; /* 1 or 2 */
00130     /* server host keys */
00131     ssh_private_key rsa_key;
00132     ssh_private_key dsa_key;
00133     /* auths accepted by server */
00134     int auth_methods;
00135     int hostkeys; /* contains type of host key wanted by client, in server impl */
00136     struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
00137     int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg, void *userdata);
00138     void *ssh_message_callback_data;
00139 
00140     void (*ssh_connection_callback)( struct ssh_session_struct *session);
00141     struct ssh_packet_callbacks_struct default_packet_callbacks;
00142     struct ssh_list *packet_callbacks;
00143     struct ssh_socket_callbacks_struct socket_callbacks;
00144     ssh_poll_ctx default_poll_ctx;
00145     /* options */
00146 #ifdef WITH_PCAP
00147     ssh_pcap_context pcap_ctx; /* pcap debugging context */
00148 #endif
00149     char *username;
00150     char *host;
00151     char *bindaddr; /* bind the client to an ip addr */
00152     char *xbanner; /* TODO: looks like it is not needed */
00153     struct ssh_list *identity;
00154     char *sshdir;
00155     char *knownhosts;
00156     char *wanted_methods[10];
00157     char compressionlevel;
00158     unsigned long timeout; /* seconds */
00159     unsigned long timeout_usec;
00160     unsigned int port;
00161     socket_t fd;
00162     int ssh2;
00163     int ssh1;
00164     int StrictHostKeyChecking;
00165     char *ProxyCommand;
00166 };
00167 
00173 typedef int (*ssh_termination_function)(void *user);
00174 int ssh_handle_packets(ssh_session session, int timeout);
00175 int ssh_handle_packets_termination(ssh_session session, int timeout,
00176     ssh_termination_function fct, void *user);
00177 void ssh_socket_exception_callback(int code, int errno_code, void *user);
00178 
00179 #endif /* SESSION_H_ */

Generated on 19 Dec 2014 for libssh by  doxygen 1.4.7