libssh 0.5.2

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 struct ssh_session_struct {
00065     struct error_struct error;
00066     struct ssh_socket_struct *socket;
00067     char *serverbanner;
00068     char *clientbanner;
00069     int protoversion;
00070     int server;
00071     int client;
00072     int openssh;
00073     uint32_t send_seq;
00074     uint32_t recv_seq;
00075 /* status flags */
00076     int closed;
00077     int closed_by_except;
00078 
00079     int connected;
00080     /* !=0 when the user got a session handle */
00081     int alive;
00082     /* two previous are deprecated */
00083     /* int auth_service_asked; */
00084 
00085     /* session flags (SSH_SESSION_FLAG_*) */
00086     int flags;
00087 
00088     ssh_string banner; /* that's the issue banner from
00089                        the server */
00090     char *discon_msg; /* disconnect message from
00091                          the remote host */
00092     ssh_buffer in_buffer;
00093     PACKET in_packet;
00094     ssh_buffer out_buffer;
00095 
00096     /* the states are used by the nonblocking stuff to remember */
00097     /* where it was before being interrupted */
00098     enum ssh_pending_call_e pending_call_state;
00099     enum ssh_session_state_e session_state;
00100     int packet_state;
00101     enum ssh_dh_state_e dh_handshake_state;
00102     enum ssh_auth_service_state_e auth_service_state;
00103     enum ssh_auth_state_e auth_state;
00104     enum ssh_channel_request_state_e global_req_state;
00105     ssh_string dh_server_signature; /* information used by dh_handshake. */
00106     KEX server_kex;
00107     KEX client_kex;
00108     ssh_buffer in_hashbuf;
00109     ssh_buffer out_hashbuf;
00110     struct ssh_crypto_struct *current_crypto;
00111     struct ssh_crypto_struct *next_crypto;  /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
00112 
00113     struct ssh_list *channels; /* linked list of channels */
00114     int maxchannel;
00115     int exec_channel_opened; /* version 1 only. more
00116                                 info in channels1.c */
00117     ssh_agent agent; /* ssh agent */
00118 
00119 /* keyb interactive data */
00120     struct ssh_kbdint_struct *kbdint;
00121     int version; /* 1 or 2 */
00122     /* server host keys */
00123     ssh_private_key rsa_key;
00124     ssh_private_key dsa_key;
00125     /* auths accepted by server */
00126     int auth_methods;
00127     int hostkeys; /* contains type of host key wanted by client, in server impl */
00128     struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
00129     int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg, void *userdata);
00130     void *ssh_message_callback_data;
00131     int log_verbosity; /*cached copy of the option structure */
00132     int log_indent; /* indentation level in enter_function logs */
00133 
00134     void (*ssh_connection_callback)( struct ssh_session_struct *session);
00135     ssh_callbacks callbacks; /* Callbacks to user functions */
00136     struct ssh_packet_callbacks_struct default_packet_callbacks;
00137     struct ssh_list *packet_callbacks;
00138     struct ssh_socket_callbacks_struct socket_callbacks;
00139     ssh_poll_ctx default_poll_ctx;
00140     /* options */
00141 #ifdef WITH_PCAP
00142     ssh_pcap_context pcap_ctx; /* pcap debugging context */
00143 #endif
00144     char *username;
00145     char *host;
00146     char *bindaddr; /* bind the client to an ip addr */
00147     char *xbanner; /* TODO: looks like it is not needed */
00148     struct ssh_list *identity;
00149     char *sshdir;
00150     char *knownhosts;
00151     char *wanted_methods[10];
00152     char compressionlevel;
00153     unsigned long timeout; /* seconds */
00154     unsigned long timeout_usec;
00155     unsigned int port;
00156     socket_t fd;
00157     int ssh2;
00158     int ssh1;
00159     int StrictHostKeyChecking;
00160     char *ProxyCommand;
00161 };
00162 
00168 typedef int (*ssh_termination_function)(void *user);
00169 int ssh_handle_packets(ssh_session session, int timeout);
00170 int ssh_handle_packets_termination(ssh_session session, int timeout,
00171     ssh_termination_function fct, void *user);
00172 void ssh_socket_exception_callback(int code, int errno_code, void *user);
00173 
00174 #endif /* SESSION_H_ */