diff options
Diffstat (limited to 'authfile.c')
-rw-r--r-- | authfile.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/authfile.c b/authfile.c index d28ae0d38..af4190eeb 100644 --- a/authfile.c +++ b/authfile.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: authfile.c,v 1.124 2017/04/30 23:10:43 djm Exp $ */ | 1 | /* $OpenBSD: authfile.c,v 1.125 2017/05/30 08:49:32 markus Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000, 2013 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -316,50 +316,48 @@ sshkey_try_load_public(struct sshkey *k, const char *filename, char **commentp) | |||
316 | return SSH_ERR_INVALID_FORMAT; | 316 | return SSH_ERR_INVALID_FORMAT; |
317 | } | 317 | } |
318 | 318 | ||
319 | /* load public key from ssh v1 private or any pubkey file */ | 319 | /* load public key from any pubkey file */ |
320 | int | 320 | int |
321 | sshkey_load_public(const char *filename, struct sshkey **keyp, char **commentp) | 321 | sshkey_load_public(const char *filename, struct sshkey **keyp, char **commentp) |
322 | { | 322 | { |
323 | struct sshkey *pub = NULL; | 323 | struct sshkey *pub = NULL; |
324 | char file[PATH_MAX]; | 324 | char *file = NULL; |
325 | int r, fd; | 325 | int r; |
326 | 326 | ||
327 | if (keyp != NULL) | 327 | if (keyp != NULL) |
328 | *keyp = NULL; | 328 | *keyp = NULL; |
329 | if (commentp != NULL) | 329 | if (commentp != NULL) |
330 | *commentp = NULL; | 330 | *commentp = NULL; |
331 | 331 | ||
332 | /* XXX should load file once and attempt to parse each format */ | ||
333 | |||
334 | if ((fd = open(filename, O_RDONLY)) < 0) | ||
335 | goto skip; | ||
336 | close(fd); | ||
337 | |||
338 | /* try ssh2 public key */ | ||
339 | if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) | 332 | if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) |
340 | return SSH_ERR_ALLOC_FAIL; | 333 | return SSH_ERR_ALLOC_FAIL; |
341 | if ((r = sshkey_try_load_public(pub, filename, commentp)) == 0) { | 334 | if ((r = sshkey_try_load_public(pub, filename, commentp)) == 0) { |
342 | if (keyp != NULL) | 335 | if (keyp != NULL) { |
343 | *keyp = pub; | 336 | *keyp = pub; |
344 | return 0; | 337 | pub = NULL; |
338 | } | ||
339 | r = 0; | ||
340 | goto out; | ||
345 | } | 341 | } |
346 | sshkey_free(pub); | 342 | sshkey_free(pub); |
347 | 343 | ||
348 | |||
349 | skip: | ||
350 | /* try .pub suffix */ | 344 | /* try .pub suffix */ |
351 | if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) | 345 | if (asprintf(&file, "%s.pub", filename) == -1) |
352 | return SSH_ERR_ALLOC_FAIL; | 346 | return SSH_ERR_ALLOC_FAIL; |
353 | r = SSH_ERR_ALLOC_FAIL; /* in case strlcpy or strlcat fail */ | 347 | if ((pub = sshkey_new(KEY_UNSPEC)) == NULL) { |
354 | if ((strlcpy(file, filename, sizeof file) < sizeof(file)) && | 348 | r = SSH_ERR_ALLOC_FAIL; |
355 | (strlcat(file, ".pub", sizeof file) < sizeof(file)) && | 349 | goto out; |
356 | (r = sshkey_try_load_public(pub, file, commentp)) == 0) { | 350 | } |
357 | if (keyp != NULL) | 351 | if ((r = sshkey_try_load_public(pub, file, commentp)) == 0) { |
352 | if (keyp != NULL) { | ||
358 | *keyp = pub; | 353 | *keyp = pub; |
359 | return 0; | 354 | pub = NULL; |
355 | } | ||
356 | r = 0; | ||
360 | } | 357 | } |
358 | out: | ||
359 | free(file); | ||
361 | sshkey_free(pub); | 360 | sshkey_free(pub); |
362 | |||
363 | return r; | 361 | return r; |
364 | } | 362 | } |
365 | 363 | ||