summaryrefslogtreecommitdiffhomepage
path: root/cli-kex.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2004-08-24 07:22:36 +0000
committerMatt Johnston <matt@ucc.asn.au>2004-08-24 07:22:36 +0000
commit857dfdeb9e54a219991f55b26bd9c88401830e56 (patch)
treef3ba8734016ded6d2f7b79ee0f823bb16e4228a3 /cli-kex.c
parent70b7c24cb078df45882711372f7663b4822a02d6 (diff)
Fix if the first write fails
--HG-- extra : convert_revision : 5a12aa1aa66c9cfd5d0097acea235cd3cd7658ab
Diffstat (limited to 'cli-kex.c')
-rw-r--r--cli-kex.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/cli-kex.c b/cli-kex.c
index 90c8d29..c8949ef 100644
--- a/cli-kex.c
+++ b/cli-kex.c
@@ -164,13 +164,16 @@ static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen) {
snprintf(filename, len+18, "%s/.ssh/known_hosts", pw->pw_dir);
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) {
+ fseek(hostsfile, 0, SEEK_SET);
+ } else {
+ /* We mightn't have been able to open it if it was read-only */
+ if (errno == EACCES || errno == EROFS) {
+ TRACE(("trying readonly: %s", strerror(errno)));
+ readonly = 1;
+ hostsfile = fopen(filename, "r");
+ }
}
if (hostsfile == NULL) {