]> andersk Git - openssh.git/blobdiff - auth-rhosts.c
- djm@cvs.openbsd.org 2010/01/30 02:54:53
[openssh.git] / auth-rhosts.c
index 0988935636b88033d8c68289c702cf4ab518abef..5c12967016b4d62720e2aadfa10505c9c3f310a2 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenBSD: auth-rhosts.c,v 1.43 2008/06/13 14:18:51 dtucker Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
 #ifdef HAVE_NETGROUP_H
 # include <netgroup.h>
 #endif
+#include <pwd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include "packet.h"
+#include "buffer.h"
 #include "uidswap.h"
 #include "pathnames.h"
 #include "log.h"
 #include "servconf.h"
 #include "canohost.h"
+#include "key.h"
+#include "hostfile.h"
 #include "auth.h"
+#include "misc.h"
 
 /* import */
 extern ServerOptions options;
@@ -47,12 +58,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;
This page took 0.04042 seconds and 4 git commands to generate.