diff options
Diffstat (limited to 'libssh')
-rw-r--r-- | libssh/auth.c | 24 | ||||
-rw-r--r-- | libssh/keyfiles.c | 24 | ||||
-rw-r--r-- | libssh/options.c | 2 |
3 files changed, 27 insertions, 23 deletions
diff --git a/libssh/auth.c b/libssh/auth.c index d03f8f1..c79d164 100644 --- a/libssh/auth.c +++ b/libssh/auth.c @@ -757,12 +757,12 @@ error: } #ifdef _MSC_VER -static const char privKey_1[] = "%s/.ssh/identity"; -static const char pubKey_1[] = "%s/.ssh/identity.pub"; -static const char privKey_2[] = "%s/.ssh/id_dsa"; -static const char pubKey_2[] = "%s/.ssh/id_dsa.pub"; -static const char privKey_3[] = "%s/.ssh/id_rsa"; -static const char pubKey_3[] = "%s/.ssh/id_rsa.pub"; +static const char privKey_1[] = "SSH_DIR/identity"; +static const char pubKey_1[] = "SSH_DIR/identity.pub"; +static const char privKey_2[] = "SSH_DIR/id_dsa"; +static const char pubKey_2[] = "SSH_DIR/id_dsa.pub"; +static const char privKey_3[] = "SSH_DIR/id_rsa"; +static const char pubKey_3[] = "SSH_DIR/id_rsa.pub"; /** Used different var to allow const char[] declaration */ static struct ssh_keys_struct keytab[] = { { privKey_1, pubKey_1}, @@ -774,16 +774,16 @@ static struct ssh_keys_struct keytab[] = { /* This requires GCC extensions */ static struct ssh_keys_struct keytab[] = { { - .privatekey = "identity", - .publickey = "identity.pub" + .privatekey = "SSH_DIR/identity", + .publickey = "SSH_DIR/identity.pub" }, { - .privatekey = "id_dsa", - .publickey = "id_dsa.pub", + .privatekey = "SSH_DIR/id_dsa", + .publickey = "SSH_DIR/id_dsa.pub", }, { - .privatekey = "id_rsa", - .publickey = "id_rsa.pub", + .privatekey = "SSH_DIR/id_rsa", + .publickey = "SSH_DIR/id_rsa.pub", }, { .privatekey = NULL, diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c index 2fe6e8a..5e7fe4f 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; } diff --git a/libssh/options.c b/libssh/options.c index 868ffa4..46d822f 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -159,7 +159,7 @@ static int ssh_options_set_algo(ssh_session session, int algo, return 0; } -static char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir) { +char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir) { char *new; if (value[0] == '~' && value[1] == '/') { |