]> andersk Git - openssh.git/commitdiff
- dtucker@cvs.openbsd.org 2006/03/13 10:26:52
authordjm <djm>
Wed, 15 Mar 2006 01:06:23 +0000 (01:06 +0000)
committerdjm <djm>
Wed, 15 Mar 2006 01:06:23 +0000 (01:06 +0000)
     [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@

ChangeLog
authfile.c
authfile.h
ssh-add.c

index cbf2cc716a1deacfb1955df5a033908b576d4f77..aba7d850bef5d85f1c108004ea142eb92380b6c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
      [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)
index f97cf1820df6b7ca6695b31e4e3fe2b6d175cf3c..0656262d00710086ff153df6f94d61caead0fb60 100644 (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;
index 7f92701ec055200a776f127ae6fcd6bf89fcfb4c..a16caa7a8fc6db11883c1b5c73896702c9dbe181 100644 (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
index 8bfc401e8dae3ea230dcae76e9997fe33c93a337..59933012d050b0d3d4b6f611f63dac30b38e520a 100644 (file)
--- 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)
This page took 0.043824 seconds and 5 git commands to generate.