summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-10-04 10:10:19 +0200
committerAndreas Schneider <mail@cynapses.org>2009-10-04 10:10:19 +0200
commit7a37f9faf788897ce7bf44a65f828d4980d19c77 (patch)
tree996667786a79c153aeff19931a58f4bfcc987597
parent149a2b4a18a70fd41aef9cdfdb4b7b277187a95f (diff)
downloadlibssh-7a37f9faf788897ce7bf44a65f828d4980d19c77.tar.gz
libssh-7a37f9faf788897ce7bf44a65f828d4980d19c77.tar.xz
libssh-7a37f9faf788897ce7bf44a65f828d4980d19c77.zip
Fixed ssh_options_copy().
-rw-r--r--include/libssh/libssh.h2
-rw-r--r--libssh/options.c99
2 files changed, 40 insertions, 61 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index f4cb55b..e794893 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -383,7 +383,7 @@ LIBSSH_API int ssh_message_type(ssh_message msg);
LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
LIBSSH_API ssh_session ssh_new(void);
-LIBSSH_API ssh_options ssh_options_copy(ssh_options opt);
+LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
LIBSSH_API int ssh_options_getopt(ssh_options options, int *argcptr, char **argv);
LIBSSH_API int ssh_options_parse_config(ssh_options opt, const char *filename);
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
diff --git a/libssh/options.c b/libssh/options.c
index 475cba0..591aaee 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -40,7 +40,7 @@
#endif
/**
- * @brief Duplicate an option structure.
+ * @brief Duplicate the options of a session structure.
*
* If you make several sessions with the same options this is useful. You
* cannot use twice the same option structure in ssh_session_connect.
@@ -51,92 +51,71 @@
*
* @see ssh_session_connect()
*/
-#if 0
-ssh_session ssh_session_copy(ssh_options opt) {
- ssh_session new = NULL;
+int ssh_options_copy(ssh_session src, ssh_session *dest) {
+ ssh_session new;
int i;
- if (session == NULL) {
- return NULL;
+ if (src == NULL || dest == NULL || *dest == NULL) {
+ return -1;
}
- new = ssh_session_new();
- if (new == NULL) {
- return NULL;
- }
+ new = *dest;
- if (session->username) {
- new->username = strdup(session->username);
+ if (src->username) {
+ new->username = strdup(src->username);
if (new->username == NULL) {
- goto err;
+ return -1;
}
}
- if (session->host) {
- new->host = strdup(session->host);
+
+ if (src->host) {
+ new->host = strdup(src->host);
if (new->host == NULL) {
- goto err;
- }
- }
- if (session->bindaddr) {
- new->bindaddr = strdup(session->bindaddr);
- if (new->bindaddr == NULL) {
- goto err;
+ return -1;
}
}
- if (session->identity) {
- new->identity=strdup(session->identity);
+
+ if (src->identity) {
+ new->identity = strdup(src->identity);
if (new->identity == NULL) {
- return NULL;
+ return -1;
}
}
- if (session->sshdir) {
- new->ssh_dir = strdup(session->sshdir);
+
+ if (src->sshdir) {
+ new->sshdir = strdup(src->sshdir);
if (new->sshdir == NULL) {
- goto err;
+ return -1;
}
}
- if (session->knownhosts) {
- new->knownhosts = strdup(session->knownhosts);
+
+ if (src->knownhosts) {
+ new->knownhosts = strdup(src->knownhosts);
if (new->knownhosts == NULL) {
- goto err;
- }
- }
- if (session->dsakey) {
- new->dsakey = strdup(session->dsakey);
- if (new->dsakey == NULL) {
- goto err;
- }
- }
- if (session->rsakey) {
- new->rsakey = strdup(session->rsakey);
- if (new->rsakey == NULL) {
- goto err;
+ return -1;
}
}
+
for (i = 0; i < 10; ++i) {
- if (session->wanted_methods[i]) {
- new->wanted_methods[i] = strdup(session->wanted_methods[i]);
+ if (src->wanted_methods[i]) {
+ new->wanted_methods[i] = strdup(src->wanted_methods[i]);
if (new->wanted_methods[i] == NULL) {
- goto err;
+ return -1;
}
}
}
- new->fd = session->fd;
- new->port = session->port;
- new->callbacks = session->callbacks;
- new->timeout = session->timeout;
- new->timeout_usec = session->timeout_usec;
- new->ssh2 = session->ssh2;
- new->ssh1 = session->ssh1;
- new->log_verbosity = session->log_verbosity;
-
- return new;
-err:
- ssh_session_free(new);
- return NULL;
+ new->fd = src->fd;
+ new->port = src->port;
+ new->callbacks = src->callbacks;
+ new->timeout = src->timeout;
+ new->timeout_usec = src->timeout_usec;
+ new->ssh2 = src->ssh2;
+ new->ssh1 = src->ssh1;
+ new->log_verbosity = src->log_verbosity;
+
+ return 0;
}
-#endif
#ifndef _WIN32
static char *get_username_from_uid(ssh_session session, uid_t uid){