diff options
author | Matt Johnston <matt@ucc.asn.au> | 2004-08-16 14:46:13 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2004-08-16 14:46:13 +0000 |
commit | 029ae3505828c78eb98f29ba3a6dbec063fba71d (patch) | |
tree | 8b90580087b37a5c3c867d27c3163aa5f9db106d /cli-kex.c | |
parent | fdfc95df8b1d5c7c889e56a1028671a77f6cff5a (diff) |
create known_hosts properly
--HG--
extra : convert_revision : 3f808121bb4c3b4e0ce32db12525c63d692f1dbd
Diffstat (limited to 'cli-kex.c')
-rw-r--r-- | cli-kex.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -147,21 +147,27 @@ static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) { /* Check that ~/.ssh exists - easiest way is just to mkdir */ if (mkdir(filename, S_IRWXU) != 0) { if (errno != EEXIST) { + dropbear_log(LOG_INFO, "Warning: failed creating ~/.ssh: %s", + strerror(errno)); + TRACE(("mkdir didn't work: %s", strerror(errno))); ask_to_confirm(keyblob, keybloblen); goto out; /* only get here on success */ } } snprintf(filename, len+18, "%s/.ssh/known_hosts", pw->pw_dir); - hostsfile = fopen(filename, "r+"); + hostsfile = fopen(filename, "a+"); + fseek(hostsfile, 0, SEEK_SET); /* We mightn't have been able to open it if it was read-only */ if (hostsfile == NULL && (errno == EACCES || errno == EROFS)) { + TRACE(("trying readonly: %s", strerror(errno))); readonly = 1; hostsfile = fopen(filename, "r"); } if (hostsfile == NULL) { + TRACE(("hostsfile didn't open: %s", strerror(errno))); ask_to_confirm(keyblob, keybloblen); goto out; /* We only get here on success */ } @@ -228,11 +234,12 @@ static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) { /* If we get here, they said yes */ if (readonly) { + TRACE(("readonly")); goto out; } /* put the new entry in the file */ - fseek(hostsfile, 0, SEEK_END); + fseek(hostsfile, 0, SEEK_END); /* In case it wasn't opened append */ buf_setpos(line, 0); buf_setlen(line, 0); buf_putbytes(line, ses.remotehost, hostlen); |