From 06db584e9de9d904a09300f09feed7f82026d241 Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Fri, 13 Jun 2008 14:51:28 +1000 Subject: - 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@ --- auth-rhosts.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'auth-rhosts.c') 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 * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -26,6 +26,7 @@ #include #include #include +#include #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; -- cgit v1.2.3 From d9526a5e96e4515afec28df42b13d08bd02f754a Mon Sep 17 00:00:00 2001 From: Darren Tucker Date: Sat, 14 Jun 2008 09:01:24 +1000 Subject: - dtucker@cvs.openbsd.org 2008/06/13 14:18:51 [auth2-pubkey.c auth-rhosts.c] Include unistd.h for close(), prevents warnings in -portable --- ChangeLog | 5 ++++- auth-rhosts.c | 3 ++- auth2-pubkey.c | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'auth-rhosts.c') diff --git a/ChangeLog b/ChangeLog index 362febe67..8b18aea38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,9 @@ applying additional restrictions to non-pubkey authentications in the case where pubkey fails but another method subsequently succeeds. bz #1472, found by Colin Watson, ok markus@ djm@ + - dtucker@cvs.openbsd.org 2008/06/13 14:18:51 + [auth2-pubkey.c auth-rhosts.c] + Include unistd.h for close(), prevents warnings in -portable 20080612 - (dtucker) OpenBSD CVS Sync @@ -4347,4 +4350,4 @@ OpenServer 6 and add osr5bigcrypt support so when someone migrates passwords between UnixWare and OpenServer they will still work. OK dtucker@ -$Id: ChangeLog,v 1.5005 2008/06/13 22:59:49 dtucker Exp $ +$Id: ChangeLog,v 1.5006 2008/06/13 23:01:24 dtucker Exp $ diff --git a/auth-rhosts.c b/auth-rhosts.c index bbddfb6df..5c1296701 100644 --- a/auth-rhosts.c +++ b/auth-rhosts.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth-rhosts.c,v 1.42 2008/06/13 04:40:22 djm Exp $ */ +/* $OpenBSD: auth-rhosts.c,v 1.43 2008/06/13 14:18:51 dtucker Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -27,6 +27,7 @@ #include #include #include +#include #include "packet.h" #include "buffer.h" diff --git a/auth2-pubkey.c b/auth2-pubkey.c index 7f7ddd8cf..306515000 100644 --- a/auth2-pubkey.c +++ b/auth2-pubkey.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auth2-pubkey.c,v 1.16 2008/06/13 04:40:22 djm Exp $ */ +/* $OpenBSD: auth2-pubkey.c,v 1.17 2008/06/13 14:18:51 dtucker Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * @@ -32,6 +32,7 @@ #include #include #include +#include #include "xmalloc.h" #include "ssh.h" -- cgit v1.2.3