diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:10:50 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:10:50 +0000 |
commit | a459a8b4dbc9b391b6080fcdc0a38ca32a3f6a4c (patch) | |
tree | 9c7a11bee8a26b88d48e5dd3999c1a54420a5f4b | |
parent | 4d203e8420b0be0a3cd327f0ab9dc688fed54026 (diff) | |
download | libssh-a459a8b4dbc9b391b6080fcdc0a38ca32a3f6a4c.tar.gz libssh-a459a8b4dbc9b391b6080fcdc0a38ca32a3f6a4c.tar.xz libssh-a459a8b4dbc9b391b6080fcdc0a38ca32a3f6a4c.zip |
Improve ssh_options_set_identity().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@357 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r-- | include/libssh/libssh.h | 2 | ||||
-rw-r--r-- | libssh/options.c | 38 |
2 files changed, 29 insertions, 11 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 2928ddf5..f1152ec5 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -314,12 +314,12 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv); int ssh_options_set_host(SSH_OPTIONS *opt, const char *host); int ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd); int ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port); -void ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity); void ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback) (void *arg, float status), void *arg); void ssh_options_set_timeout(SSH_OPTIONS *opt, long seconds, long usec); int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir); int ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir); +int ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity); void ssh_options_allow_ssh1(SSH_OPTIONS *opt, int allow); void ssh_options_allow_ssh2(SSH_OPTIONS *opt, int allow); void ssh_options_set_dsa_server_key(SSH_OPTIONS *opt, const char *dsakey); diff --git a/libssh/options.c b/libssh/options.c index 71dc7496..6f8e9077 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -412,17 +412,35 @@ int ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir){ return 0; } -/** the identity file is used authenticate with public key. - * \brief set the identity file name - * \param opt options structure - * \param identity path to the file including its name. "%s" will be substitued - * with the user home directory - * \see ssh_options_set_user_home_dir() +/** + * @brief Set the identity file name. + * + * The identity file is used authenticate with public key. + * + * @param opt The options structure to use. + * + * @param identity The path to the file including its name. "%s" will be + * substitued with the user home directory. + * + * @return 0 on success, < 0 on error. + * + * @see ssh_options_set_user_home_dir() */ -void ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity){ - char buffer[1024]; - snprintf(buffer,1024,identity,ssh_get_user_home_dir()); - opt->identity=strdup(buffer); +int ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity){ + char buffer[1024] = {0}; + + if (opt == NULL || identity == NULL) { + return -1; + } + + snprintf(buffer, 1024, identity, ssh_get_user_home_dir()); + SAFE_FREE(opt->identity); + opt->identity = strdup(buffer); + if (opt->identity == NULL) { + return -1; + } + + return 0; } /** \warning I don't remember what these functions are supposed |