diff options
author | Darren Tucker <dtucker@zip.com.au> | 2008-06-13 06:51:28 +0200 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2008-06-13 06:51:28 +0200 |
commit | 06db584e9de9d904a09300f09feed7f82026d241 (patch) | |
tree | bc1fbff35a49da3ceabd0637ae18265e15e4fa80 /auth-rhosts.c | |
parent | - dtucker@cvs.openbsd.org 2008/06/13 01:38:23 (diff) | |
download | openssh-06db584e9de9d904a09300f09feed7f82026d241.tar.xz openssh-06db584e9de9d904a09300f09feed7f82026d241.zip |
- djm@cvs.openbsd.org 2008/06/13 04:40:22
[auth2-pubkey.c auth-rhosts.c]
refuse to read ~/.shosts or ~/.ssh/authorized_keys that are not
regular files; report from Solar Designer via Colin Watson in bz#1471
ok dtucker@ deraadt@
Diffstat (limited to 'auth-rhosts.c')
-rw-r--r-- | auth-rhosts.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/auth-rhosts.c b/auth-rhosts.c index cd0a7967a..bbddfb6df 100644 --- a/auth-rhosts.c +++ b/auth-rhosts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth-rhosts.c,v 1.41 2006/08/03 03:34:41 deraadt Exp $ */ +/* $OpenBSD: auth-rhosts.c,v 1.42 2008/06/13 04:40:22 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -26,6 +26,7 @@ #include <stdio.h> #include <string.h> #include <stdarg.h> +#include <fcntl.h> #include "packet.h" #include "buffer.h" @@ -37,6 +38,7 @@ #include "key.h" #include "hostfile.h" #include "auth.h" +#include "misc.h" /* import */ extern ServerOptions options; @@ -55,12 +57,27 @@ check_rhosts_file(const char *filename, const char *hostname, { FILE *f; char buf[1024]; /* Must not be larger than host, user, dummy below. */ + int fd; + struct stat st; /* Open the .rhosts file, deny if unreadable */ - f = fopen(filename, "r"); - if (!f) + if ((fd = open(filename, O_RDONLY|O_NONBLOCK)) == -1) return 0; - + if (fstat(fd, &st) == -1) { + close(fd); + return 0; + } + if (!S_ISREG(st.st_mode)) { + logit("User %s hosts file %s is not a regular file", + server_user, filename); + close(fd); + return 0; + } + unset_nonblock(fd); + if ((f = fdopen(fd, "r")) == NULL) { + close(fd); + return 0; + } while (fgets(buf, sizeof(buf), f)) { /* All three must be at least as big as buf to avoid overflows. */ char hostbuf[1024], userbuf[1024], dummy[1024], *host, *user, *cp; |