diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:04:56 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-02 12:04:56 +0000 |
commit | 5ba2acde0aa899db94cdf18bf0a0d32071e58405 (patch) | |
tree | cde6ff890c19ac82ec7157a0b11283ec0021bdc2 /libssh/options.c | |
parent | 9ea6ea581d655d81d40efc7c678e8e1f036d533d (diff) | |
download | libssh-5ba2acde0aa899db94cdf18bf0a0d32071e58405.tar.gz libssh-5ba2acde0aa899db94cdf18bf0a0d32071e58405.tar.xz libssh-5ba2acde0aa899db94cdf18bf0a0d32071e58405.zip |
Improve ssh_options_set_known_hosts_file().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@355 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/options.c')
-rw-r--r-- | libssh/options.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/libssh/options.c b/libssh/options.c index 8c31888..fca875e 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -386,17 +386,35 @@ int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir) { return 0; } -/** the known hosts file is used to certify remote hosts are genuine. - * \brief set the known hosts file name - * \param opt options structure - * \param dir 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 known hosts file name. + * + * The known hosts file is used to certify remote hosts are genuine. + * + * @param opt The options structure to use. + * + * @param dir 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_known_hosts_file(SSH_OPTIONS *opt, const char *dir){ - char buffer[1024]; - snprintf(buffer,1024,dir,ssh_get_user_home_dir()); - opt->known_hosts_file=strdup(buffer); +int ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir){ + char buffer[1024] = {0}; + + if (opt == NULL || dir == NULL) { + return -1; + } + + snprintf(buffer, 1024, dir, ssh_get_user_home_dir()); + SAFE_FREE(opt->known_hosts_file); + opt->known_hosts_file = strdup(buffer); + if (opt->known_hosts_file == NULL) { + return -1; + } + + return 0; } /** the identity file is used authenticate with public key. |