include/libssh/libssh.h

00001 /*
00002 Copyright 2003,04 Aris Adamantiadis
00003 
00004 This file is part of the SSH Library
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 #ifndef _LIBSSH_H
00022 #define _LIBSSH_H
00023 #include <unistd.h>
00024 #include <sys/select.h> /* for fd_set * */
00025 #include <inttypes.h>
00026 
00027 #define LIBSSH_VERSION "libssh-0.2"
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 typedef struct string_struct STRING;
00034 typedef struct buffer_struct BUFFER;
00035 typedef struct public_key_struct PUBLIC_KEY;
00036 typedef struct private_key_struct PRIVATE_KEY;
00037 typedef struct ssh_options_struct SSH_OPTIONS;
00038 typedef struct channel_struct CHANNEL;
00039 typedef struct ssh_session SSH_SESSION;
00040 typedef struct ssh_kbdint SSH_KBDINT;
00041 
00042 /* integer values */
00043 typedef uint32_t u32;
00044 typedef uint16_t u16;
00045 typedef uint64_t u64;
00046 typedef uint8_t u8;
00047 
00048 /* the offsets of methods */
00049 #define SSH_KEX 0
00050 #define SSH_HOSTKEYS 1
00051 #define SSH_CRYPT_C_S 2
00052 #define SSH_CRYPT_S_C 3
00053 #define SSH_MAC_C_S 4
00054 #define SSH_MAC_S_C 5
00055 #define SSH_COMP_C_S 6
00056 #define SSH_COMP_S_C 7
00057 #define SSH_LANG_C_S 8
00058 #define SSH_LANG_S_C 9
00059 
00060 #define SSH_CRYPT 2
00061 #define SSH_MAC 3
00062 #define SSH_COMP 4
00063 #define SSH_LANG 5
00064 
00065 #define SSH_AUTH_SUCCESS 0
00066 #define SSH_AUTH_DENIED 1
00067 #define SSH_AUTH_PARTIAL 2
00068 #define SSH_AUTH_INFO 3
00069 #define SSH_AUTH_ERROR -1
00070 
00071 /* status flags */
00072 
00073 #define SSH_CLOSED (1<<0)
00074 #define SSH_READ_PENDING (1<<1)
00075 #define SSH_CLOSED_ERROR (1<<2)
00076 
00077 #define SSH_SERVER_ERROR -1
00078 #define SSH_SERVER_NOT_KNOWN 0
00079 #define SSH_SERVER_KNOWN_OK 1
00080 #define SSH_SERVER_KNOWN_CHANGED 2
00081 #define SSH_SERVER_FOUND_OTHER 3
00082 
00083 #ifndef MD5_DIGEST_LEN
00084     #define MD5_DIGEST_LEN 16
00085 #endif
00086 /* errors */
00087 
00088 #define SSH_NO_ERROR 0
00089 #define SSH_REQUEST_DENIED 1
00090 #define SSH_FATAL 2
00091 #define SSH_EINTR 3
00092 
00093 /* error return codes */
00094 #define SSH_OK 0     /* No error */
00095 #define SSH_ERROR -1 /* error of some kind */
00096 #define SSH_AGAIN 1  /* the nonblocking call must be repeated */
00097 
00098 char *ssh_get_error(void *error); 
00099 int ssh_get_error_code(void *error);
00100 void ssh_say(int priority,char *format,...);
00101 void ssh_set_verbosity(int num);
00102 
00103  /* There is a verbosity level */
00104  /* 3 : packet level */
00105  /* 2 : protocol level */
00106  /* 1 : functions level */
00107  /* 0 : important messages only */
00108  /* -1 : no messages */
00109 
00110 /* session.c */
00111 SSH_SESSION *ssh_new();
00112 void ssh_set_options(SSH_SESSION *session, SSH_OPTIONS *options);
00113 int ssh_get_fd(SSH_SESSION *session);
00114 void ssh_silent_disconnect(SSH_SESSION *session);
00115 int ssh_get_version(SSH_SESSION *session);
00116 void ssh_set_fd_toread(SSH_SESSION *session);
00117 void ssh_set_fd_towrite(SSH_SESSION *session);
00118 void ssh_set_fd_except(SSH_SESSION *session);
00119 
00120 
00121 /* client.c */
00122 int ssh_connect(SSH_SESSION *session);
00123 void ssh_disconnect(SSH_SESSION *session);
00124 int ssh_service_request(SSH_SESSION *session,char *service);
00125 char *ssh_get_issue_banner(SSH_SESSION *session);
00126 /* get copyright informations */
00127 const char *ssh_copyright();
00128 /* string.h */
00129 
00130 /* You can use these functions, they won't change */
00131 /* makestring returns a newly allocated string from a char * ptr */
00132 STRING *string_from_char(char *what);
00133 /* it returns the string len in host byte orders. str->size is big endian warning ! */
00134 int string_len(STRING *str);
00135 STRING *string_new(unsigned int size);
00136 /* string_fill copies the data in the string. it does NOT check for boundary so allocate enough place with string_new */
00137 void string_fill(STRING *str,void *data,int len);
00138 /* returns a newly allocated char array with the str string and a final nul caracter */
00139 char *string_to_char(STRING *str);
00140 STRING *string_copy(STRING *str);
00141 /* burns the data inside a string */
00142 void string_burn(STRING *str);
00143 void *string_data(STRING *str);
00144 
00145 /* deprecated */
00146 void ssh_crypto_init();
00147 
00148 /* useful for debug */
00149 void ssh_print_hexa(char *descr,unsigned char *what, int len);
00150 int ssh_get_random(void *where,int len,int strong);
00151 
00152 /* this one can be called by the client to see the hash of the public key before accepting it */
00153 int ssh_get_pubkey_hash(SSH_SESSION *session,unsigned char hash[MD5_DIGEST_LEN]);
00154 STRING *ssh_get_pubkey(SSH_SESSION *session);
00155 
00156 /* in connect.c */
00157 int ssh_fd_poll(SSH_SESSION *session,int *write, int *except);
00158 int ssh_select(CHANNEL **channels,CHANNEL **outchannels, int maxfd, fd_set *readfds, struct timeval *timeout);
00159 
00160 void publickey_free(PUBLIC_KEY *key);
00161 
00162 /* in keyfiles.c */
00163 
00164 PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,int type,char *passphrase);
00165 STRING *publickey_to_string(PUBLIC_KEY *key);
00166 PUBLIC_KEY *publickey_from_privatekey(PRIVATE_KEY *prv);
00167 void private_key_free(PRIVATE_KEY *prv);
00168 STRING *publickey_from_file(SSH_SESSION *session, char *filename,int *_type);
00169 STRING *publickey_from_next_file(SSH_SESSION *session,char **pub_keys_path,char **keys_path,
00170                             char **privkeyfile,int *type,int *count);
00171 int ssh_is_server_known(SSH_SESSION *session);
00172 int ssh_write_knownhost(SSH_SESSION *session);
00173 
00174 /* in channels.c */
00175 
00176 CHANNEL *channel_new(SSH_SESSION *session);
00177 int channel_open_forward(CHANNEL *channel,char *remotehost, int remoteport, char *sourcehost, int localport);
00178 int channel_open_session(CHANNEL *channel);
00179 void channel_free(CHANNEL *channel);
00180 int channel_request_pty(CHANNEL *channel);
00181 int channel_request_pty_size(CHANNEL *channel, char *term,int cols, int rows);
00182 int channel_change_pty_size(CHANNEL *channel,int cols,int rows);
00183 int channel_request_shell(CHANNEL *channel);
00184 int channel_request_subsystem(CHANNEL *channel, char *system);
00185 int channel_request_env(CHANNEL *channel,char *name, char *value);
00186 int channel_request_exec(CHANNEL *channel, char *cmd);
00187 int channel_request_sftp(CHANNEL *channel);
00188 int channel_write(CHANNEL *channel,void *data,int len);
00189 int channel_send_eof(CHANNEL *channel);
00190 int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr);
00191 int channel_poll(CHANNEL *channel, int is_stderr);
00192 int channel_close(CHANNEL *channel);
00193 int channel_read_nonblocking(CHANNEL *channel, char *dest, int len, int is_stderr);
00194 int channel_is_open(CHANNEL *channel);
00195 int channel_is_closed(CHANNEL *channel);
00196 int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptchans, struct 
00197         timeval * timeout);
00198 /* in options.c */
00199 
00200 SSH_OPTIONS *ssh_options_new();
00201 SSH_OPTIONS *ssh_options_copy(SSH_OPTIONS *opt);
00202 int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list);
00203 void ssh_options_set_username(SSH_OPTIONS *opt,char *username);
00204 void ssh_options_set_port(SSH_OPTIONS *opt, unsigned int port);
00205 int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv);
00206 void ssh_options_set_host(SSH_OPTIONS *opt, const char *host);
00207 void ssh_options_set_fd(SSH_OPTIONS *opt, int fd);
00208 void ssh_options_set_bind(SSH_OPTIONS *opt, char *bindaddr,int port);
00209 void ssh_options_set_identity(SSH_OPTIONS *opt, char *identity);
00210 void ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback)
00211         (void *arg, float status), void *arg);
00212 void ssh_options_set_timeout(SSH_OPTIONS *opt, long seconds, long usec);
00213 void ssh_options_set_ssh_dir(SSH_OPTIONS *opt, char *dir);
00214 void ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, char *dir);
00215 void ssh_options_allow_ssh1(SSH_OPTIONS *opt, int allow);
00216 void ssh_options_allow_ssh2(SSH_OPTIONS *opt, int allow);
00217 void ssh_options_set_dsa_server_key(SSH_OPTIONS *opt, char *dsakey);
00218 void ssh_options_set_rsa_server_key(SSH_OPTIONS *opt, char *rsakey);
00219 
00220 
00221 /* buffer.c */
00222 
00225 BUFFER *buffer_new();
00226 void buffer_free(BUFFER *buffer);
00227 /* buffer_get returns a pointer to the begining of the buffer. no position is taken into account */
00228 void *buffer_get(BUFFER *buffer);
00229 /* same here */
00230 int buffer_get_len(BUFFER *buffer);
00231 
00232 
00233 /* in auth.c */
00234 /* these functions returns AUTH_ERROR is some serious error has happened,
00235   AUTH_SUCCESS if success,
00236   AUTH_PARTIAL if partial success,
00237   AUTH_DENIED if refused */
00238 int ssh_userauth_none(SSH_SESSION *session,char *username);
00239 int ssh_userauth_password(SSH_SESSION *session,char *username,char *password);
00240 int ssh_userauth_offer_pubkey(SSH_SESSION *session, char *username,int type, STRING *publickey);
00241 int ssh_userauth_pubkey(SSH_SESSION *session, char *username, STRING *publickey, PRIVATE_KEY *privatekey);
00242 int ssh_userauth_autopubkey(SSH_SESSION *session);
00243 int ssh_userauth_kbdint(SSH_SESSION *session, char *user, char *submethods);
00244 int ssh_userauth_kbdint_getnprompts(SSH_SESSION *session);
00245 char *ssh_userauth_kbdint_getname(SSH_SESSION *session);
00246 char *ssh_userauth_kbdint_getinstruction(SSH_SESSION *session);
00247 char *ssh_userauth_kbdint_getprompt(SSH_SESSION *session, int i, char *echo);
00248 void ssh_userauth_kbdint_setanswer(SSH_SESSION *session, unsigned int i, char *answer);
00249 
00250 
00251 /* init.c */
00252 int ssh_finalize();
00253 #ifdef __cplusplus
00254 } ;
00255 #endif
00256 #endif /* _LIBSSH_H */

Generated on Fri Jul 27 21:14:24 2007 for libssh by  doxygen 1.5.2-20070719