- FILE *f;
- char buf[1024]; /* Must not be larger than host, user, dummy below. */
-
- /* Open the .rhosts file. */
- f = fopen(filename, "r");
- if (!f)
- return 0; /* Cannot read the .rhosts - deny access. */
-
- /* Go through the file, checking every entry. */
- 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;
- int negated;
-
- for (cp = buf; *cp == ' ' || *cp == '\t'; cp++)
- ;
- if (*cp == '#' || *cp == '\n' || !*cp)
- continue;
-
- /* NO_PLUS is supported at least on OSF/1. We skip it (we don't ever
- support the plus syntax). */
- if (strncmp(cp, "NO_PLUS", 7) == 0)
- continue;
-
- /* This should be safe because each buffer is as big as the whole
- string, and thus cannot be overwritten. */
- switch (sscanf(buf, "%s %s %s", hostbuf, userbuf, dummy))
- {
- case 0:
- packet_send_debug("Found empty line in %.100s.", filename);
- continue; /* Empty line? */
- case 1:
- /* Host name only. */
- strlcpy(userbuf, server_user, sizeof(userbuf));
- break;
- case 2:
- /* Got both host and user name. */
- break;
- case 3:
- packet_send_debug("Found garbage in %.100s.", filename);
- continue; /* Extra garbage */
- default:
- continue; /* Weird... */
- }
-
- host = hostbuf;
- user = userbuf;
- negated = 0;
-
- /* Process negated host names, or positive netgroups. */
- if (host[0] == '-')
- {
- negated = 1;
- host++;
- }
- else
- if (host[0] == '+')
- host++;
-
- if (user[0] == '-')
- {
- negated = 1;
- user++;
- }
- else
- if (user[0] == '+')
- user++;
-
- /* Check for empty host/user names (particularly '+'). */
- if (!host[0] || !user[0])
- {
- /* We come here if either was '+' or '-'. */
- packet_send_debug("Ignoring wild host/user names in %.100s.",
+ FILE *f;
+ char buf[1024]; /* Must not be larger than host, user, dummy below. */
+
+ /* Open the .rhosts file, deny if unreadable */
+ f = fopen(filename, "r");
+ if (!f)
+ 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;
+ int negated;
+
+ for (cp = buf; *cp == ' ' || *cp == '\t'; cp++)
+ ;
+ if (*cp == '#' || *cp == '\n' || !*cp)
+ continue;
+
+ /*
+ * NO_PLUS is supported at least on OSF/1. We skip it (we
+ * don't ever support the plus syntax).
+ */
+ if (strncmp(cp, "NO_PLUS", 7) == 0)
+ continue;
+
+ /*
+ * This should be safe because each buffer is as big as the
+ * whole string, and thus cannot be overwritten.
+ */
+ switch (sscanf(buf, "%1023s %1023s %1023s", hostbuf, userbuf,
+ dummy)) {
+ case 0:
+ auth_debug_add("Found empty line in %.100s.", filename);
+ continue;
+ case 1:
+ /* Host name only. */
+ strlcpy(userbuf, server_user, sizeof(userbuf));
+ break;
+ case 2:
+ /* Got both host and user name. */
+ break;
+ case 3:
+ auth_debug_add("Found garbage in %.100s.", filename);
+ continue;
+ default:
+ /* Weird... */
+ continue;
+ }
+
+ host = hostbuf;
+ user = userbuf;
+ negated = 0;
+
+ /* Process negated host names, or positive netgroups. */
+ if (host[0] == '-') {
+ negated = 1;
+ host++;
+ } else if (host[0] == '+')
+ host++;
+
+ if (user[0] == '-') {
+ negated = 1;
+ user++;
+ } else if (user[0] == '+')
+ user++;
+
+ /* Check for empty host/user names (particularly '+'). */
+ if (!host[0] || !user[0]) {
+ /* We come here if either was '+' or '-'. */
+ auth_debug_add("Ignoring wild host/user names in %.100s.",