aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libssh/auth.c12
-rw-r--r--libssh/keyfiles.c21
-rw-r--r--libssh/misc.c15
-rw-r--r--libssh/options.c12
4 files changed, 36 insertions, 24 deletions
diff --git a/libssh/auth.c b/libssh/auth.c
index 59fd889a..d03f8f14 100644
--- a/libssh/auth.c
+++ b/libssh/auth.c
@@ -774,16 +774,16 @@ static struct ssh_keys_struct keytab[] = {
/* This requires GCC extensions */
static struct ssh_keys_struct keytab[] = {
{
- .privatekey = "%s/.ssh/identity",
- .publickey = "%s/.ssh/identity.pub"
+ .privatekey = "identity",
+ .publickey = "identity.pub"
},
{
- .privatekey = "%s/.ssh/id_dsa",
- .publickey = "%s/.ssh/id_dsa.pub",
+ .privatekey = "id_dsa",
+ .publickey = "id_dsa.pub",
},
{
- .privatekey = "%s/.ssh/id_rsa",
- .publickey = "%s/.ssh/id_rsa.pub",
+ .privatekey = "id_rsa",
+ .publickey = "id_rsa.pub",
},
{
.privatekey = NULL,
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);
diff --git a/libssh/misc.c b/libssh/misc.c
index 690de3a8..bae780b2 100644
--- a/libssh/misc.c
+++ b/libssh/misc.c
@@ -71,9 +71,16 @@
#ifdef _WIN32
char *ssh_get_user_home_dir(void) {
- static char szPath[MAX_PATH] = {0};
+ char tmp[MAX_PATH] = {0};
+ char szPath = NULL;
- if (SHGetSpecialFolderPathA(NULL, szPath, CSIDL_PROFILE, TRUE)) {
+ if (SHGetSpecialFolderPathA(NULL, tmp, CSIDL_PROFILE, TRUE)) {
+ szPath = malloc(strlen(szPath) + 1);
+ if (home == NULL) {
+ return NULL;
+ }
+
+ strcpy(szPath, tmp);
return szPath;
}
@@ -90,7 +97,7 @@ char *ssh_get_user_home_dir(void) {
}
#else /* _WIN32 */
char *ssh_get_user_home_dir(void) {
- static char szPath[PATH_MAX] = {0};
+ char *szPath = NULL;
struct passwd *pwd = NULL;
pwd = getpwuid(getuid());
@@ -98,7 +105,7 @@ char *ssh_get_user_home_dir(void) {
return NULL;
}
- snprintf(szPath, PATH_MAX - 1, "%s", pwd->pw_dir);
+ szPath = strdup(pwd->pw_dir);
return szPath;
}
diff --git a/libssh/options.c b/libssh/options.c
index 08b78f72..d5069813 100644
--- a/libssh/options.c
+++ b/libssh/options.c
@@ -163,15 +163,23 @@ static char *dir_expand_dup(ssh_session session, const char *value, int allowssh
char *new;
if (value[0] == '~' && value[1] == '/') {
- const char *homedir = ssh_get_user_home_dir();
- size_t lv = strlen(value + 1), lh = strlen(homedir);
+ char *homedir = ssh_get_user_home_dir();
+ size_t lv, lh;
+
+ if (homedir == NULL) {
+ return NULL;
+ }
+ lv = strlen(value + 1);
+ lh = strlen(homedir);
new = malloc(lv + lh + 1);
if (new == NULL) {
ssh_set_error_oom(session);
+ SAFE_FREE(homedir);
return NULL;
}
memcpy(new, homedir, lh);
+ SAFE_FREE(homedir);
memcpy(new + lh, value + 1, lv + 1);
return new;
}