diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 2 | ||||
-rw-r--r-- | lib/libssh.c | 106 | ||||
-rw-r--r-- | lib/libssh.h | 123 | ||||
-rw-r--r-- | lib/socket.h | 7 |
4 files changed, 7 insertions, 231 deletions
diff --git a/lib/Makefile b/lib/Makefile index 1634e5e5..a9aae66f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -2,6 +2,6 @@ src := bitops.c checksum.c ip.c lists.c md5.c net.c patmatch.c printf.c sha1.c s obj := $(src-o-files) $(all-client) -src := bitops.c checksum.c event.c idm.c ip.c libssh.c lists.c md5.c mempool.c net.c patmatch.c printf.c resource.c sha1.c sha256.c sha512.c slab.c slists.c tbf.c xmalloc.c +src := bitops.c checksum.c event.c idm.c ip.c lists.c md5.c mempool.c net.c patmatch.c printf.c resource.c sha1.c sha256.c sha512.c slab.c slists.c tbf.c xmalloc.c obj := $(src-o-files) $(all-daemon) diff --git a/lib/libssh.c b/lib/libssh.c deleted file mode 100644 index 9449ab30..00000000 --- a/lib/libssh.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * BIRD -- Mockup of SSH Library for loading LibSSH using dlopen - * - * (c) 2015 CZ.NIC - * - * This file was part of SSH Library: http://www.libssh.org/ - * (c) 2003-2009 by Aris Adamantiadis (SSH Library) - * - * Can be freely distributed and used under the terms of the GNU GPL. - */ - -#include <dlfcn.h> -#include "nest/bird.h" -#include "lib/libssh.h" - -#define FILENAME_OF_SHARED_OBJECT_LIBSSH "libssh.so" - -struct ssh_function { - void **fn; - const char *name; -}; - -ssh_session (*ssh_new)(void); -void (*ssh_set_blocking)(ssh_session session, int blocking); -int (*ssh_options_set)(ssh_session session, enum ssh_options_e type, const void *value); -int (*ssh_connect)(ssh_session session); -socket_t (*ssh_get_fd)(ssh_session session); -int (*ssh_is_server_known)(ssh_session session); -int (*ssh_userauth_publickey_auto)(ssh_session session, const char *username, const char *passphrase); -const char * (*ssh_get_error)(void *error); -int (*ssh_get_error_code)(void *error); -void (*ssh_disconnect)(ssh_session session); -void (*ssh_free)(ssh_session session); - -ssh_channel (*ssh_channel_new)(ssh_session session); -int (*ssh_channel_is_open)(ssh_channel channel); -int (*ssh_channel_close)(ssh_channel channel); -void (*ssh_channel_free)(ssh_channel channel); -int (*ssh_channel_open_session)(ssh_channel channel); -int (*ssh_channel_request_subsystem)(ssh_channel channel, const char *subsystem); -int (*ssh_channel_read_nonblocking)(ssh_channel channel, void *dest, uint32_t count, int is_stderr); -int (*ssh_channel_is_eof)(ssh_channel channel); -int (*ssh_channel_select)(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct timeval * timeout); -int (*ssh_channel_write)(ssh_channel channel, const void *data, uint32_t len); - -#define SSH_FN(x) { .fn = (void **) &x, .name = #x } -static struct ssh_function all_ssh_fn[] = { - SSH_FN(ssh_new), - SSH_FN(ssh_set_blocking), - SSH_FN(ssh_options_set), - SSH_FN(ssh_connect), - SSH_FN(ssh_get_fd), - SSH_FN(ssh_is_server_known), - SSH_FN(ssh_userauth_publickey_auto), - SSH_FN(ssh_get_error), - SSH_FN(ssh_get_error_code), - SSH_FN(ssh_disconnect), - SSH_FN(ssh_free), - SSH_FN(ssh_channel_new), - SSH_FN(ssh_channel_is_open), - SSH_FN(ssh_channel_close), - SSH_FN(ssh_channel_free), - SSH_FN(ssh_channel_open_session), - SSH_FN(ssh_channel_request_subsystem), - SSH_FN(ssh_channel_read_nonblocking), - SSH_FN(ssh_channel_is_eof), - SSH_FN(ssh_channel_select), - SSH_FN(ssh_channel_write), -}; -#undef SSH_FN - -static void *libssh; - -/** - * load_libssh - Prepare all ssh_* functions - * - * Initialize for use all ssh_* functions. Returns normally NULL. - * If an error occurs then returns static string with the error description. - */ -const char * -load_libssh(void) -{ - char *err_buf; - - libssh = dlopen(FILENAME_OF_SHARED_OBJECT_LIBSSH, RTLD_LAZY); - if (!libssh) - { - /* This would be probably often repeated problem */ - char *help_msg = "You have to install libssh library."; - err_buf = mb_alloc(&root_pool, 512); /* FIXME: free memory */ - bsnprintf(err_buf, 512, "%s. %s", dlerror(), help_msg); - return err_buf; - } - - dlerror(); /* Clear any existing error */ - - for (int i = 0; i < sizeof(all_ssh_fn)/sizeof(all_ssh_fn[0]); i++) - { - *all_ssh_fn[i].fn = (void *) dlsym(libssh, all_ssh_fn[i].name); - err_buf = dlerror(); - if (err_buf) - return err_buf; - } - - return NULL; -} diff --git a/lib/libssh.h b/lib/libssh.h deleted file mode 100644 index 74e11e59..00000000 --- a/lib/libssh.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * BIRD -- Mockup headers of SSH Library for loading LibSSH using dlopen - * - * (c) 2015 CZ.NIC - * - * This file was part of SSH Library: http://www.libssh.org/ - * (c) 2003-2009 by Aris Adamantiadis (SSH Library) - * - * Can be freely distributed and used under the terms of the GNU GPL. - */ - -#ifndef _BIRD_LIBSSH_H_ -#define _BIRD_LIBSSH_H_ - -#include <unistd.h> -#include <inttypes.h> - -typedef struct ssh_session_struct* ssh_session; -typedef struct ssh_channel_struct* ssh_channel; - -/* Error return codes */ -#define SSH_OK 0 /* No error */ -#define SSH_ERROR -1 /* Error of some kind */ -#define SSH_AGAIN -2 /* The nonblocking call must be repeated */ -#define SSH_EOF -127 /* We have already a eof */ - -enum ssh_server_known_e { - SSH_SERVER_ERROR=-1, - SSH_SERVER_NOT_KNOWN=0, - SSH_SERVER_KNOWN_OK, - SSH_SERVER_KNOWN_CHANGED, - SSH_SERVER_FOUND_OTHER, - SSH_SERVER_FILE_NOT_FOUND -}; - -enum ssh_auth_e { - SSH_AUTH_SUCCESS=0, - SSH_AUTH_DENIED, - SSH_AUTH_PARTIAL, - SSH_AUTH_INFO, - SSH_AUTH_AGAIN, - SSH_AUTH_ERROR=-1 -}; - -enum ssh_error_types_e { - SSH_NO_ERROR=0, - SSH_REQUEST_DENIED, - SSH_FATAL, - SSH_EINTR -}; - -enum ssh_options_e { - SSH_OPTIONS_HOST, - SSH_OPTIONS_PORT, - SSH_OPTIONS_PORT_STR, - SSH_OPTIONS_FD, - SSH_OPTIONS_USER, - SSH_OPTIONS_SSH_DIR, - SSH_OPTIONS_IDENTITY, - SSH_OPTIONS_ADD_IDENTITY, - SSH_OPTIONS_KNOWNHOSTS, - SSH_OPTIONS_TIMEOUT, - SSH_OPTIONS_TIMEOUT_USEC, - SSH_OPTIONS_SSH1, - SSH_OPTIONS_SSH2, - SSH_OPTIONS_LOG_VERBOSITY, - SSH_OPTIONS_LOG_VERBOSITY_STR, - SSH_OPTIONS_CIPHERS_C_S, - SSH_OPTIONS_CIPHERS_S_C, - SSH_OPTIONS_COMPRESSION_C_S, - SSH_OPTIONS_COMPRESSION_S_C, - SSH_OPTIONS_PROXYCOMMAND, - SSH_OPTIONS_BINDADDR, - SSH_OPTIONS_STRICTHOSTKEYCHECK, - SSH_OPTIONS_COMPRESSION, - SSH_OPTIONS_COMPRESSION_LEVEL, - SSH_OPTIONS_KEY_EXCHANGE, - SSH_OPTIONS_HOSTKEYS, - SSH_OPTIONS_GSSAPI_SERVER_IDENTITY, - SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY, - SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS, - SSH_OPTIONS_HMAC_C_S, - SSH_OPTIONS_HMAC_S_C, -}; - -enum { - SSH_LOG_NOLOG=0, /* No logging at all */ - SSH_LOG_WARNING, /* Only warnings */ - SSH_LOG_PROTOCOL, /* High level protocol information */ - SSH_LOG_PACKET, /* Lower level protocol informations, packet level */ - SSH_LOG_FUNCTIONS /* Every function path */ -}; - -#ifndef socket_t -typedef int socket_t; -#endif - -extern ssh_session (*ssh_new)(void); -extern void (*ssh_set_blocking)(ssh_session session, int blocking); -extern int (*ssh_options_set)(ssh_session session, enum ssh_options_e type, const void *value); -extern int (*ssh_connect)(ssh_session session); -extern socket_t (*ssh_get_fd)(ssh_session session); -extern int (*ssh_is_server_known)(ssh_session session); -extern int (*ssh_userauth_publickey_auto)(ssh_session session, const char *username, const char *passphrase); -extern const char * (*ssh_get_error)(void *error); -extern int (*ssh_get_error_code)(void *error); -extern void (*ssh_disconnect)(ssh_session session); -extern void (*ssh_free)(ssh_session session); - -extern ssh_channel (*ssh_channel_new)(ssh_session session); -extern int (*ssh_channel_is_open)(ssh_channel channel); -extern int (*ssh_channel_close)(ssh_channel channel); -extern void (*ssh_channel_free)(ssh_channel channel); -extern int (*ssh_channel_open_session)(ssh_channel channel); -extern int (*ssh_channel_request_subsystem)(ssh_channel channel, const char *subsystem); -extern int (*ssh_channel_read_nonblocking)(ssh_channel channel, void *dest, uint32_t count, int is_stderr); -extern int (*ssh_channel_is_eof)(ssh_channel channel); -extern int (*ssh_channel_select)(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct timeval * timeout); -extern int (*ssh_channel_write)(ssh_channel channel, const void *data, uint32_t len); - -const char *load_libssh(void); - -#endif /* _BIRD_LIBSSH_H_ */ diff --git a/lib/socket.h b/lib/socket.h index ce06a19c..99bac6f8 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -12,8 +12,12 @@ #include <errno.h> #include "lib/resource.h" -#include "lib/libssh.h" +#ifdef HAVE_LIBSSH +#define LIBSSH_LEGACY_0_4 +#include <libssh/libssh.h> +#endif +#ifdef HAVE_LIBSSH struct ssh_sock { const char *username; /* (Required) SSH user name */ const char *server_hostkey_path; /* (Optional) Filepath to the SSH public key of remote side, can be knownhost file */ @@ -30,6 +34,7 @@ struct ssh_sock { #define SK_SSH_SUBSYSTEM 5 /* Internal */ #define SK_SSH_ESTABLISHED 6 /* Final state */ }; +#endif typedef struct birdsock { resource r; |