summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2006-03-15 12:06:23 +1100
committerDamien Miller <djm@mindrot.org>2006-03-15 12:06:23 +1100
commit8275fade44b56aed722ea91bc4586f48babece80 (patch)
tree008fc19e661c19854303ee25c8e5d12347546893
parent306d118f72670f0da447f28b7eec576dcb4a6e38 (diff)
- 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@
-rw-r--r--ChangeLog7
-rw-r--r--authfile.c4
-rw-r--r--authfile.h3
-rw-r--r--ssh-add.c17
4 files changed, 23 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index c72eeed4..d41b4cb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 $
diff --git a/authfile.c b/authfile.c
index f97cf182..0656262d 100644
--- a/authfile.c
+++ b/authfile.c
@@ -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;
diff --git a/authfile.h b/authfile.h
index 7f92701e..a16caa7a 100644
--- a/authfile.h
+++ b/authfile.h
@@ -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
diff --git a/ssh-add.c b/ssh-add.c
index 8bfc401e..59933012 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -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)