summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 c72eeed41..d41b4cb46 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -224,6 +224,11 @@
224 [misc.c ssh_config.5 sshd_config.5] 224 [misc.c ssh_config.5 sshd_config.5]
225 Allow config directives to contain whitespace by surrounding them by double 225 Allow config directives to contain whitespace by surrounding them by double
226 quotes. mindrot #482, man page help from jmc@, ok djm@ 226 quotes. mindrot #482, man page help from jmc@, ok djm@
227 - dtucker@cvs.openbsd.org 2006/03/13 10:26:52
228 [authfile.c authfile.h ssh-add.c]
229 Make ssh-add check file permissions before attempting to load private
230 key files multiple times; it will fail anyway and this prevents confusing
231 multiple prompts and warnings. mindrot #1138, ok djm@
227 232
22820060313 23320060313
229 - (dtucker) [configure.ac] Bug #1171: Don't use printf("%lld", longlong) 234 - (dtucker) [configure.ac] Bug #1171: Don't use printf("%lld", longlong)
@@ -4125,4 +4130,4 @@
4125 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 4130 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
4126 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 4131 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
4127 4132
4128$Id: ChangeLog,v 1.4203 2006/03/15 01:05:59 djm Exp $ 4133$Id: ChangeLog,v 1.4204 2006/03/15 01:06:23 djm Exp $
diff --git a/authfile.c b/authfile.c
index f97cf1820..0656262d0 100644
--- a/authfile.c
+++ b/authfile.c
@@ -36,7 +36,7 @@
36 */ 36 */
37 37
38#include "includes.h" 38#include "includes.h"
39RCSID("$OpenBSD: authfile.c,v 1.62 2006/02/20 17:19:54 stevesk Exp $"); 39RCSID("$OpenBSD: authfile.c,v 1.63 2006/03/13 10:26:52 dtucker Exp $");
40 40
41#include <sys/types.h> 41#include <sys/types.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
@@ -510,7 +510,7 @@ key_load_private_pem(int fd, int type, const char *passphrase,
510 return prv; 510 return prv;
511} 511}
512 512
513static int 513int
514key_perm_ok(int fd, const char *filename) 514key_perm_ok(int fd, const char *filename)
515{ 515{
516 struct stat st; 516 struct stat st;
diff --git a/authfile.h b/authfile.h
index 7f92701ec..a16caa7a8 100644
--- a/authfile.h
+++ b/authfile.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfile.h,v 1.10 2002/05/23 19:24:30 markus Exp $ */ 1/* $OpenBSD: authfile.h,v 1.11 2006/03/13 10:26:52 dtucker Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -21,5 +21,6 @@ Key *key_load_public_type(int, const char *, char **);
21Key *key_load_private(const char *, const char *, char **); 21Key *key_load_private(const char *, const char *, char **);
22Key *key_load_private_type(int, const char *, const char *, char **); 22Key *key_load_private_type(int, const char *, const char *, char **);
23Key *key_load_private_pem(int, int, const char *, char **); 23Key *key_load_private_pem(int, int, const char *, char **);
24int key_perm_ok(int, const char *);
24 25
25#endif 26#endif
diff --git a/ssh-add.c b/ssh-add.c
index 8bfc401e8..59933012d 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: ssh-add.c,v 1.75 2006/02/20 17:19:54 stevesk Exp $"); 38RCSID("$OpenBSD: ssh-add.c,v 1.76 2006/03/13 10:26:52 dtucker Exp $");
39 39
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/stat.h> 41#include <sys/stat.h>
@@ -127,16 +127,25 @@ delete_all(AuthenticationConnection *ac)
127static int 127static int
128add_file(AuthenticationConnection *ac, const char *filename) 128add_file(AuthenticationConnection *ac, const char *filename)
129{ 129{
130 struct stat st;
131 Key *private; 130 Key *private;
132 char *comment = NULL; 131 char *comment = NULL;
133 char msg[1024]; 132 char msg[1024];
134 int ret = -1; 133 int fd, perms_ok, ret = -1;
135 134
136 if (stat(filename, &st) < 0) { 135 if ((fd = open(filename, 0)) < 0) {
137 perror(filename); 136 perror(filename);
138 return -1; 137 return -1;
139 } 138 }
139
140 /*
141 * Since we'll try to load a keyfile multiple times, permission errors
142 * will occur multiple times, so check perms first and bail if wrong.
143 */
144 perms_ok = key_perm_ok(fd, filename);
145 close(fd);
146 if (!perms_ok)
147 return -1;
148
140 /* At first, try empty passphrase */ 149 /* At first, try empty passphrase */
141 private = key_load_private(filename, "", &comment); 150 private = key_load_private(filename, "", &comment);
142 if (comment == NULL) 151 if (comment == NULL)