[authfile.c authfile.h ssh-add.c]
     Make ssh-add check file permissions before attempting to load private
     key files multiple times; it will fail anyway and this prevents confusing
     multiple prompts and warnings.  mindrot #1138, ok djm@
This commit is contained in:
Damien Miller 2006-03-15 12:06:23 +11:00
parent 306d118f72
commit 8275fade44
4 changed files with 23 additions and 8 deletions

View File

@ -224,6 +224,11 @@
[misc.c ssh_config.5 sshd_config.5]
Allow config directives to contain whitespace by surrounding them by double
quotes. mindrot #482, man page help from jmc@, ok djm@
- dtucker@cvs.openbsd.org 2006/03/13 10:26:52
[authfile.c authfile.h ssh-add.c]
Make ssh-add check file permissions before attempting to load private
key files multiple times; it will fail anyway and this prevents confusing
multiple prompts and warnings. mindrot #1138, ok djm@
20060313
- (dtucker) [configure.ac] Bug #1171: Don't use printf("%lld", longlong)
@ -4125,4 +4130,4 @@
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
$Id: ChangeLog,v 1.4203 2006/03/15 01:05:59 djm Exp $
$Id: ChangeLog,v 1.4204 2006/03/15 01:06:23 djm Exp $

View File

@ -36,7 +36,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: authfile.c,v 1.62 2006/02/20 17:19:54 stevesk Exp $");
RCSID("$OpenBSD: authfile.c,v 1.63 2006/03/13 10:26:52 dtucker Exp $");
#include <sys/types.h>
#include <sys/stat.h>
@ -510,7 +510,7 @@ key_load_private_pem(int fd, int type, const char *passphrase,
return prv;
}
static int
int
key_perm_ok(int fd, const char *filename)
{
struct stat st;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: authfile.h,v 1.10 2002/05/23 19:24:30 markus Exp $ */
/* $OpenBSD: authfile.h,v 1.11 2006/03/13 10:26:52 dtucker Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@ -21,5 +21,6 @@ Key *key_load_public_type(int, const char *, char **);
Key *key_load_private(const char *, const char *, char **);
Key *key_load_private_type(int, const char *, const char *, char **);
Key *key_load_private_pem(int, int, const char *, char **);
int key_perm_ok(int, const char *);
#endif

View File

@ -35,7 +35,7 @@
*/
#include "includes.h"
RCSID("$OpenBSD: ssh-add.c,v 1.75 2006/02/20 17:19:54 stevesk Exp $");
RCSID("$OpenBSD: ssh-add.c,v 1.76 2006/03/13 10:26:52 dtucker Exp $");
#include <sys/types.h>
#include <sys/stat.h>
@ -127,16 +127,25 @@ delete_all(AuthenticationConnection *ac)
static int
add_file(AuthenticationConnection *ac, const char *filename)
{
struct stat st;
Key *private;
char *comment = NULL;
char msg[1024];
int ret = -1;
int fd, perms_ok, ret = -1;
if (stat(filename, &st) < 0) {
if ((fd = open(filename, 0)) < 0) {
perror(filename);
return -1;
}
/*
* Since we'll try to load a keyfile multiple times, permission errors
* will occur multiple times, so check perms first and bail if wrong.
*/
perms_ok = key_perm_ok(fd, filename);
close(fd);
if (!perms_ok)
return -1;
/* At first, try empty passphrase */
private = key_load_private(filename, "", &comment);
if (comment == NULL)