diff options
Diffstat (limited to 'auth-rhosts.c')
-rw-r--r-- | auth-rhosts.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/auth-rhosts.c b/auth-rhosts.c index cd0a7967a..5c1296701 100644 --- a/auth-rhosts.c +++ b/auth-rhosts.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: auth-rhosts.c,v 1.41 2006/08/03 03:34:41 deraadt Exp $ */ | 1 | /* $OpenBSD: auth-rhosts.c,v 1.43 2008/06/13 14:18:51 dtucker Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -26,6 +26,8 @@ | |||
26 | #include <stdio.h> | 26 | #include <stdio.h> |
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <stdarg.h> | 28 | #include <stdarg.h> |
29 | #include <fcntl.h> | ||
30 | #include <unistd.h> | ||
29 | 31 | ||
30 | #include "packet.h" | 32 | #include "packet.h" |
31 | #include "buffer.h" | 33 | #include "buffer.h" |
@@ -37,6 +39,7 @@ | |||
37 | #include "key.h" | 39 | #include "key.h" |
38 | #include "hostfile.h" | 40 | #include "hostfile.h" |
39 | #include "auth.h" | 41 | #include "auth.h" |
42 | #include "misc.h" | ||
40 | 43 | ||
41 | /* import */ | 44 | /* import */ |
42 | extern ServerOptions options; | 45 | extern ServerOptions options; |
@@ -55,12 +58,27 @@ check_rhosts_file(const char *filename, const char *hostname, | |||
55 | { | 58 | { |
56 | FILE *f; | 59 | FILE *f; |
57 | char buf[1024]; /* Must not be larger than host, user, dummy below. */ | 60 | char buf[1024]; /* Must not be larger than host, user, dummy below. */ |
61 | int fd; | ||
62 | struct stat st; | ||
58 | 63 | ||
59 | /* Open the .rhosts file, deny if unreadable */ | 64 | /* Open the .rhosts file, deny if unreadable */ |
60 | f = fopen(filename, "r"); | 65 | if ((fd = open(filename, O_RDONLY|O_NONBLOCK)) == -1) |
61 | if (!f) | ||
62 | return 0; | 66 | return 0; |
63 | 67 | if (fstat(fd, &st) == -1) { | |
68 | close(fd); | ||
69 | return 0; | ||
70 | } | ||
71 | if (!S_ISREG(st.st_mode)) { | ||
72 | logit("User %s hosts file %s is not a regular file", | ||
73 | server_user, filename); | ||
74 | close(fd); | ||
75 | return 0; | ||
76 | } | ||
77 | unset_nonblock(fd); | ||
78 | if ((f = fdopen(fd, "r")) == NULL) { | ||
79 | close(fd); | ||
80 | return 0; | ||
81 | } | ||
64 | while (fgets(buf, sizeof(buf), f)) { | 82 | while (fgets(buf, sizeof(buf), f)) { |
65 | /* All three must be at least as big as buf to avoid overflows. */ | 83 | /* All three must be at least as big as buf to avoid overflows. */ |
66 | char hostbuf[1024], userbuf[1024], dummy[1024], *host, *user, *cp; | 84 | char hostbuf[1024], userbuf[1024], dummy[1024], *host, *user, *cp; |