summaryrefslogtreecommitdiff
path: root/ssh-vulnkey.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-vulnkey.c')
-rw-r--r--ssh-vulnkey.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/ssh-vulnkey.c b/ssh-vulnkey.c
index 9b64953b6..9616ecfe8 100644
--- a/ssh-vulnkey.c
+++ b/ssh-vulnkey.c
@@ -27,6 +27,7 @@
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/stat.h> 28#include <sys/stat.h>
29 29
30#include <errno.h>
30#include <string.h> 31#include <string.h>
31#include <stdio.h> 32#include <stdio.h>
32#include <fcntl.h> 33#include <fcntl.h>
@@ -135,7 +136,9 @@ do_filename(const char *filename, int quiet_open)
135 */ 136 */
136 137
137 if (strcmp(filename, "-") != 0) { 138 if (strcmp(filename, "-") != 0) {
139 int save_errno;
138 f = fopen(filename, "r"); 140 f = fopen(filename, "r");
141 save_errno = errno;
139 if (!f) { 142 if (!f) {
140 char pubfile[MAXPATHLEN]; 143 char pubfile[MAXPATHLEN];
141 if (strlcpy(pubfile, filename, sizeof pubfile) < 144 if (strlcpy(pubfile, filename, sizeof pubfile) <
@@ -144,6 +147,7 @@ do_filename(const char *filename, int quiet_open)
144 sizeof(pubfile)) 147 sizeof(pubfile))
145 f = fopen(pubfile, "r"); 148 f = fopen(pubfile, "r");
146 } 149 }
150 errno = save_errno; /* earlier errno is more useful */
147 if (!f) { 151 if (!f) {
148 if (!quiet_open) 152 if (!quiet_open)
149 perror(filename); 153 perror(filename);
@@ -237,16 +241,16 @@ do_filename(const char *filename, int quiet_open)
237} 241}
238 242
239int 243int
240do_host(void) 244do_host(int quiet_open)
241{ 245{
242 int i; 246 int i;
243 struct stat st; 247 struct stat st;
244 int ret = 1; 248 int ret = 1;
245 249
246 for (i = 0; default_host_files[i]; i++) { 250 for (i = 0; default_host_files[i]; i++) {
247 if (stat(default_host_files[i], &st) < 0) 251 if (stat(default_host_files[i], &st) < 0 && errno == ENOENT)
248 continue; 252 continue;
249 if (!do_filename(default_host_files[i], 1)) 253 if (!do_filename(default_host_files[i], quiet_open))
250 ret = 0; 254 ret = 0;
251 } 255 }
252 256
@@ -263,7 +267,7 @@ do_user(const char *dir)
263 267
264 for (i = 0; default_files[i]; i++) { 268 for (i = 0; default_files[i]; i++) {
265 snprintf(buf, sizeof(buf), "%s/%s", dir, default_files[i]); 269 snprintf(buf, sizeof(buf), "%s/%s", dir, default_files[i]);
266 if (stat(buf, &st) < 0) 270 if (stat(buf, &st) < 0 && errno == ENOENT)
267 continue; 271 continue;
268 if (!do_filename(buf, 0)) 272 if (!do_filename(buf, 0))
269 ret = 0; 273 ret = 0;
@@ -313,7 +317,7 @@ main(int argc, char **argv)
313 if (all_users) { 317 if (all_users) {
314 struct passwd *pw; 318 struct passwd *pw;
315 319
316 if (!do_host()) 320 if (!do_host(0))
317 ret = 0; 321 ret = 0;
318 322
319 while ((pw = getpwent()) != NULL) { 323 while ((pw = getpwent()) != NULL) {
@@ -325,7 +329,7 @@ main(int argc, char **argv)
325 } else if (optind == argc) { 329 } else if (optind == argc) {
326 struct passwd *pw; 330 struct passwd *pw;
327 331
328 if (!do_host()) 332 if (!do_host(1))
329 ret = 0; 333 ret = 0;
330 334
331 if ((pw = getpwuid(getuid())) == NULL) 335 if ((pw = getpwuid(getuid())) == NULL)