|
Lines 17-22
Link Here
|
| 17 |
#include <sys/types.h> |
17 |
#include <sys/types.h> |
| 18 |
#include <sys/stat.h> |
18 |
#include <sys/stat.h> |
| 19 |
|
19 |
|
|
|
20 |
#include <fcntl.h> |
| 20 |
#include <netgroup.h> |
21 |
#include <netgroup.h> |
| 21 |
#include <pwd.h> |
22 |
#include <pwd.h> |
| 22 |
#include <stdio.h> |
23 |
#include <stdio.h> |
|
Lines 33-38
Link Here
|
| 33 |
#include "key.h" |
34 |
#include "key.h" |
| 34 |
#include "hostfile.h" |
35 |
#include "hostfile.h" |
| 35 |
#include "auth.h" |
36 |
#include "auth.h" |
|
|
37 |
#include "misc.h" |
| 36 |
|
38 |
|
| 37 |
/* import */ |
39 |
/* import */ |
| 38 |
extern ServerOptions options; |
40 |
extern ServerOptions options; |
|
Lines 51-62
check_rhosts_file(const char *filename,
Link Here
|
| 51 |
{ |
53 |
{ |
| 52 |
FILE *f; |
54 |
FILE *f; |
| 53 |
char buf[1024]; /* Must not be larger than host, user, dummy below. */ |
55 |
char buf[1024]; /* Must not be larger than host, user, dummy below. */ |
|
|
56 |
int fd; |
| 57 |
struct stat st; |
| 54 |
|
58 |
|
| 55 |
/* Open the .rhosts file, deny if unreadable */ |
59 |
/* Open the .rhosts file, deny if unreadable */ |
| 56 |
f = fopen(filename, "r"); |
60 |
if ((fd = open(filename, O_RDONLY|O_NONBLOCK)) == -1) |
| 57 |
if (!f) |
|
|
| 58 |
return 0; |
61 |
return 0; |
| 59 |
|
62 |
if (fstat(fd, &st) == -1) { |
|
|
63 |
close(fd); |
| 64 |
return 0; |
| 65 |
} |
| 66 |
if (!S_ISREG(st.st_mode)) { |
| 67 |
logit("User %s hosts file %s is not a regular file", |
| 68 |
server_user, filename); |
| 69 |
close(fd); |
| 70 |
restore_uid(); |
| 71 |
return 0; |
| 72 |
} |
| 73 |
unset_nonblock(fd); |
| 74 |
if ((f = fdopen(fd, "r")) == NULL) { |
| 75 |
close(fd); |
| 76 |
return 0; |
| 77 |
} |
| 60 |
while (fgets(buf, sizeof(buf), f)) { |
78 |
while (fgets(buf, sizeof(buf), f)) { |
| 61 |
/* All three must be at least as big as buf to avoid overflows. */ |
79 |
/* All three must be at least as big as buf to avoid overflows. */ |
| 62 |
char hostbuf[1024], userbuf[1024], dummy[1024], *host, *user, *cp; |
80 |
char hostbuf[1024], userbuf[1024], dummy[1024], *host, *user, *cp; |