diff options
Diffstat (limited to 'libssh')
-rw-r--r-- | libssh/client.c | 4 | ||||
-rw-r--r-- | libssh/keyfiles.c | 25 | ||||
-rw-r--r-- | libssh/log.c | 6 | ||||
-rw-r--r-- | libssh/options.c | 53 |
4 files changed, 29 insertions, 59 deletions
diff --git a/libssh/client.c b/libssh/client.c index cbc70e31..79c82497 100644 --- a/libssh/client.c +++ b/libssh/client.c @@ -33,8 +33,8 @@ #include "libssh/ssh2.h" #define set_status(opt,status) do {\ - if (opt->connect_status_function) \ - opt->connect_status_function(opt->connect_status_arg, status); \ + if (opt->callbacks && opt->callbacks->connect_status_function) \ + opt->callbacks->connect_status_function(opt->callbacks->userdata, status); \ } while (0) /** diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c index c651d4c1..e2dfaf76 100644 --- a/libssh/keyfiles.c +++ b/libssh/keyfiles.c @@ -586,9 +586,9 @@ static int pem_get_password(char *buf, int size, int rwflag, void *userdata) { ssh_log(session, SSH_LOG_RARE, "Trying to call external authentication function"); - if (session && session->options->auth_function) { - if ((*session->options->auth_function)("Passphrase for private key:", buf, size, 0, 0, - session->options->auth_userdata ? session->options->auth_userdata : NULL) < 0) { + if (session && session->options->callbacks->auth_function) { + if (session->options->callbacks->auth_function("Passphrase for private key:", buf, size, 0, 0, + session->options->callbacks->userdata) < 0) { return 0; } @@ -636,15 +636,14 @@ ssh_private_key privatekey_from_file(SSH_SESSION *session, const char *filename, ssh_log(session, SSH_LOG_RARE, "Trying to read %s, passphase=%s, authcb=%s", filename, passphrase ? "true" : "false", - session->options->auth_function ? "true" : "false"); + session->options->callbacks->auth_function ? "true" : "false"); switch (type) { case TYPE_DSS: if (passphrase == NULL) { - if (session->options->auth_function) { - auth_cb = session->options->auth_function; - if (session->options->auth_userdata) { - auth_ud = session->options->auth_userdata; - } + if (session->options->callbacks->auth_function) { + auth_cb = session->options->callbacks->auth_function; + auth_ud = session->options->callbacks->userdata; + #ifdef HAVE_LIBGCRYPT valid = read_dsa_privatekey(file, &dsa, auth_cb, auth_ud, "Passphrase for private key:"); @@ -681,11 +680,9 @@ ssh_private_key privatekey_from_file(SSH_SESSION *session, const char *filename, break; case TYPE_RSA: if (passphrase == NULL) { - if (session->options->auth_function) { - auth_cb = session->options->auth_function; - if (session->options->auth_userdata) { - auth_ud = session->options->auth_userdata; - } + if (session->options->callbacks->auth_function) { + auth_cb = session->options->callbacks->auth_function; + auth_ud = session->options->callbacks->userdata; #ifdef HAVE_LIBGCRYPT valid = read_rsa_privatekey(file, &rsa, auth_cb, auth_ud, "Passphrase for private key:"); diff --git a/libssh/log.c b/libssh/log.c index 4a3b275b..f2a4b8b9 100644 --- a/libssh/log.c +++ b/libssh/log.c @@ -55,9 +55,9 @@ void ssh_log(SSH_SESSION *session, int verbosity, const char *format, ...) { vsnprintf(buffer, sizeof(buffer), format, va); va_end(va); - if (session->options->log_function) { - session->options->log_function(session, verbosity, buffer, - session->options->log_userdata); + if (session->options->callbacks && session->options->callbacks->log_function) { + session->options->callbacks->log_function(session, verbosity, buffer, + session->options->callbacks->userdata); } else if (verbosity == SSH_LOG_FUNCTIONS) { if (session->log_indent > 255) { min = 255; diff --git a/libssh/options.c b/libssh/options.c index c97ba564..56f18400 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -154,15 +154,11 @@ SSH_OPTIONS *ssh_options_copy(SSH_OPTIONS *opt) { new->fd = opt->fd; new->port = opt->port; - new->auth_function = opt->auth_function; - new->auth_userdata = opt->auth_userdata; - new->connect_status_function = opt->connect_status_function; - new->connect_status_arg = opt->connect_status_arg; + new->callbacks = opt->callbacks; new->timeout = opt->timeout; new->timeout_usec = opt->timeout_usec; new->ssh2allowed = opt->ssh2allowed; new->ssh1allowed = opt->ssh1allowed; - new->log_function = opt->log_function; new->log_verbosity = opt->log_verbosity; return new; @@ -575,32 +571,6 @@ int ssh_options_set(ssh_options opt, enum ssh_options_e type, opt->log_verbosity = *x; } - case SSH_OPTIONS_AUTH_CALLBACK: - if (value == NULL) { - return -1; - } else { - opt->auth_function = (ssh_auth_callback) value; - } - break; - case SSH_OPTIONS_AUTH_USERDATA: - opt->auth_userdata = (void *) value; - break; - case SSH_OPTIONS_LOG_CALLBACK: - if (value == NULL) { - return -1; - } else { - opt->log_function = (ssh_log_callback) value; - } - break; - case SSH_OPTIONS_LOG_USERDATA: - opt->auth_userdata = (void *) value; - break; - case SSH_OPTIONS_STATUS_CALLBACK: - /* TODO */ - break; - case SSH_OPTIONS_STATUS_ARG: - /* TODO */ - break; case SSH_OPTIONS_CIPHERS_C_S: if (value == NULL) { return -1; @@ -955,12 +925,13 @@ int ssh_options_default_known_hosts_file(SSH_OPTIONS *opt) { */ int ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback)(void *arg, float status), void *arg) { - if (opt == NULL || callback == NULL) { + if (opt == NULL || callback == NULL || opt->callbacks==NULL) { return -1; } - opt->connect_status_function = callback; - opt->connect_status_arg = arg; + opt->callbacks->connect_status_function = callback; + if(arg) + opt->callbacks->userdata=arg; return 0; } @@ -1032,12 +1003,13 @@ int ssh_options_allow_ssh2(SSH_OPTIONS *opt, int allow) { */ int ssh_options_set_log_function(SSH_OPTIONS *opt, ssh_log_callback cb, void *userdata) { - if (opt == NULL || cb == NULL) { + if (opt == NULL || cb == NULL || opt->callbacks==NULL) { return -1; } - opt->log_function = cb; - opt->log_userdata = userdata; + opt->callbacks->log_function = cb; + if(userdata) + opt->callbacks->userdata = userdata; return 0; } @@ -1283,12 +1255,13 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv) { */ int ssh_options_set_auth_callback(SSH_OPTIONS *opt, ssh_auth_callback cb, void *userdata) { - if (opt == NULL || cb == NULL) { + if (opt == NULL || cb == NULL || opt->callbacks==NULL) { return -1; } - opt->auth_function = cb; - opt->auth_userdata = userdata; + opt->callbacks->auth_function = cb; + if(userdata != NULL) + opt->callbacks->userdata = userdata; return 0; } |