include/libssh/libssh.h

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

Generated on Sun Aug 23 08:55:35 2009 for libssh by  doxygen 1.4.7