Allow use of SSH_DIR/ when expanding key paths
Этот коммит содержится в:
родитель
a479b30298
Коммит
27d25752e9
@ -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)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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] == '/') {
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user