comparison cli-kex.c @ 106:e13f8a712a1c

Fix if the first write fails
author Matt Johnston <matt@ucc.asn.au>
date Tue, 24 Aug 2004 07:22:36 +0000
parents 29a5c7c62350
children 0cfba3034be5
comparison
equal deleted inserted replaced
105:68b84c20ca1e 106:e13f8a712a1c
162 } 162 }
163 } 163 }
164 164
165 snprintf(filename, len+18, "%s/.ssh/known_hosts", pw->pw_dir); 165 snprintf(filename, len+18, "%s/.ssh/known_hosts", pw->pw_dir);
166 hostsfile = fopen(filename, "a+"); 166 hostsfile = fopen(filename, "a+");
167 fseek(hostsfile, 0, SEEK_SET);
168 167
169 /* We mightn't have been able to open it if it was read-only */ 168 if (hostsfile != NULL) {
170 if (hostsfile == NULL && (errno == EACCES || errno == EROFS)) { 169 fseek(hostsfile, 0, SEEK_SET);
171 TRACE(("trying readonly: %s", strerror(errno))); 170 } else {
172 readonly = 1; 171 /* We mightn't have been able to open it if it was read-only */
173 hostsfile = fopen(filename, "r"); 172 if (errno == EACCES || errno == EROFS) {
173 TRACE(("trying readonly: %s", strerror(errno)));
174 readonly = 1;
175 hostsfile = fopen(filename, "r");
176 }
174 } 177 }
175 178
176 if (hostsfile == NULL) { 179 if (hostsfile == NULL) {
177 TRACE(("hostsfile didn't open: %s", strerror(errno))); 180 TRACE(("hostsfile didn't open: %s", strerror(errno)));
178 ask_to_confirm(keyblob, keybloblen); 181 ask_to_confirm(keyblob, keybloblen);