aboutsummaryrefslogtreecommitdiff
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
parenta479b302983aae2878af0cb50eac141ede6cd942 (diff)
downloadlibssh-27d25752e93c19d3e6584915bd64b72e43f3afc0.tar.gz
libssh-27d25752e93c19d3e6584915bd64b72e43f3afc0.tar.xz
libssh-27d25752e93c19d3e6584915bd64b72e43f3afc0.zip
Allow use of SSH_DIR/ when expanding key paths
-rw-r--r--include/libssh/priv.h4
-rw-r--r--libssh/auth.c24
-rw-r--r--libssh/keyfiles.c24
-rw-r--r--libssh/options.c2
4 files changed, 31 insertions, 23 deletions
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index 764b022..7605fd5 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -215,6 +215,10 @@ int match_hostname(const char *host, const char *pattern, unsigned int len);
#define leave_function() (void)session
#endif
+/* options.c */
+
+char *dir_expand_dup(ssh_session session, const char *value, int allowsshdir);
+
/** Free memory space */
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
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] == '/') {