aboutsummaryrefslogtreecommitdiff
path: root/libssh/keyfiles.c
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2009-10-17 18:10:42 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2009-10-17 18:10:42 +0200
commit27d25752e93c19d3e6584915bd64b72e43f3afc0 (patch)
tree71a2bdb816c7f885a3d4a21e264f9f7d1bb49fa3 /libssh/keyfiles.c
parenta479b302983aae2878af0cb50eac141ede6cd942 (diff)
downloadlibssh-27d25752e93c19d3e6584915bd64b72e43f3afc0.tar.gz
libssh-27d25752e93c19d3e6584915bd64b72e43f3afc0.tar.xz
libssh-27d25752e93c19d3e6584915bd64b72e43f3afc0.zip
Allow use of SSH_DIR/ when expanding key paths
Diffstat (limited to 'libssh/keyfiles.c')
-rw-r--r--libssh/keyfiles.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index 2fe6e8aa..5e7fe4f2 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -940,12 +940,12 @@ 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) {
- char public[256] = {0};
- char private[256] = {0};
+ char *public;
+ char *private;
const char *priv;
const char *pub;
char *new;
- ssh_string pubkey;
+ ssh_string pubkey=NULL;
pub = keytab.publickey;
if (pub == NULL) {
@@ -963,19 +963,21 @@ ssh_string try_publickey_from_file(ssh_session session, struct ssh_keys_struct k
}
/* are them readable ? */
- snprintf(public, sizeof(public), "%s/%s", session->sshdir, pub);
- snprintf(private, sizeof(private), "%s/%s", session->sshdir, priv);
+ public=dir_expand_dup(session,pub,1);
+ private=dir_expand_dup(session,priv,1);
+ //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;
+ goto error;
}
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);
- return NULL;
+ goto error;
}
ssh_log(session, SSH_LOG_PACKET, "Success opening public and private key");
@@ -990,18 +992,20 @@ ssh_string try_publickey_from_file(ssh_session session, struct ssh_keys_struct k
"Wasn't able to open public key file %s: %s",
public,
ssh_get_error(session));
- return NULL;
+ goto error;
}
new = realloc(*privkeyfile, strlen(private) + 1);
if (new == NULL) {
string_free(pubkey);
- return NULL;
+ goto error;
}
strcpy(new, private);
*privkeyfile = new;
-
+error:
+ SAFE_FREE(public);
+ SAFE_FREE(private);
return pubkey;
}