Look at HOME before /etc/passwd when looking for ~/.ssh/known_hosts

file, so people can workaround broken /etc/passwds.  Print
the full path in error messages.

--HG--
extra : convert_revision : d777688369ee21011625a3f1fe79ddbe3d5b5c93
This commit is contained in:
Matt Johnston 2006-06-07 13:41:19 +00:00
parent ba7513fdf3
commit 32af5c267e

View File

@ -152,15 +152,14 @@ static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) {
buffer * line = NULL; buffer * line = NULL;
int ret; int ret;
pw = getpwuid(getuid()); homedir = getenv("HOME");
if (pw) if (!homedir) {
pw = getpwuid(getuid());
if (pw) {
homedir = pw->pw_dir; homedir = pw->pw_dir;
} }
pw = NULL; pw = NULL;
if (!homedir)
homedir = getenv("HOME");
} }
if (homedir) { if (homedir) {
@ -172,8 +171,8 @@ static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) {
/* Check that ~/.ssh exists - easiest way is just to mkdir */ /* Check that ~/.ssh exists - easiest way is just to mkdir */
if (mkdir(filename, S_IRWXU) != 0) { if (mkdir(filename, S_IRWXU) != 0) {
if (errno != EEXIST) { if (errno != EEXIST) {
dropbear_log(LOG_INFO, "Warning: failed creating ~/.ssh: %s", dropbear_log(LOG_INFO, "Warning: failed creating %s/.ssh: %s",
strerror(errno)); homedir, strerror(errno));
TRACE(("mkdir didn't work: %s", strerror(errno))) TRACE(("mkdir didn't work: %s", strerror(errno)))
ask_to_confirm(keyblob, keybloblen); ask_to_confirm(keyblob, keybloblen);
goto out; /* only get here on success */ goto out; /* only get here on success */
@ -197,7 +196,8 @@ static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) {
if (hostsfile == NULL) { if (hostsfile == NULL) {
TRACE(("hostsfile didn't open: %s", strerror(errno))) TRACE(("hostsfile didn't open: %s", strerror(errno)))
dropbear_log(LOG_WARNING, "Failed to open ~/.ssh/known_hosts"); dropbear_log(LOG_WARNING, "Failed to open %s/.ssh/known_hosts",
homedir);
ask_to_confirm(keyblob, keybloblen); ask_to_confirm(keyblob, keybloblen);
goto out; /* We only get here on success */ goto out; /* We only get here on success */
} }