aboutsummaryrefslogtreecommitdiff
path: root/libssh/keyfiles.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-10-15 14:53:11 +0200
committerAndreas Schneider <mail@cynapses.org>2009-10-15 14:53:11 +0200
commitcbf012c33722737c255d08c7f81a3ee5c6c19052 (patch)
treeff94b8a3aaa3c239dcfe85715b4eba5034a5b9d6 /libssh/keyfiles.c
parentc360ed1d9ad4ee0a65dd80494605c55802c30ba3 (diff)
downloadlibssh-cbf012c33722737c255d08c7f81a3ee5c6c19052.tar.gz
libssh-cbf012c33722737c255d08c7f81a3ee5c6c19052.tar.xz
libssh-cbf012c33722737c255d08c7f81a3ee5c6c19052.zip
Fixed ssh_get_home_dir and ssh dir to be more portable on UNIX systems.
Thanks to Pino Toscano.
Diffstat (limited to 'libssh/keyfiles.c')
-rw-r--r--libssh/keyfiles.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index ac10c457..1fff4443 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -940,8 +940,6 @@ ssh_string publickey_from_file(ssh_session session, const char *filename,
ssh_string try_publickey_from_file(ssh_session session, struct ssh_keys_struct keytab,
char **privkeyfile, int *type) {
- static char *home = NULL;
-
char public[256] = {0};
char private[256] = {0};
const char *priv;
@@ -949,14 +947,6 @@ ssh_string try_publickey_from_file(ssh_session session, struct ssh_keys_struct k
char *new;
ssh_string pubkey;
- if (home == NULL) {
- home = ssh_get_user_home_dir();
- if (home == NULL) {
- ssh_set_error(session,SSH_FATAL,"User home dir impossible to guess");
- return NULL;
- }
- }
-
pub = keytab.publickey;
if (pub == NULL) {
return NULL;
@@ -966,15 +956,22 @@ ssh_string try_publickey_from_file(ssh_session session, struct ssh_keys_struct k
return NULL;
}
+ if (session->sshdir == NULL) {
+ if (ssh_options_set(session, SSH_OPTIONS_SSH_DIR, NULL) < 0) {
+ return NULL;
+ }
+ }
+
/* are them readable ? */
- snprintf(public, sizeof(public), pub, home);
+ snprintf(public, sizeof(public), "%s/%s", session->sshdir, pub);
+ snprintf(private, sizeof(private), "%s/%s", session->sshdir, priv);
+
ssh_log(session, SSH_LOG_PACKET, "Trying to open publickey %s", public);
if (!ssh_file_readaccess_ok(public)) {
ssh_log(session, SSH_LOG_PACKET, "Failed to open publickey %s", public);
return NULL;
}
- snprintf(private, sizeof(private), priv, home);
ssh_log(session, SSH_LOG_PACKET, "Trying to open privatekey %s", private);
if (!ssh_file_readaccess_ok(private)) {
ssh_log(session, SSH_LOG_PACKET, "Failed to open privatekey %s", private);