diff options
Diffstat (limited to 'libexec/rshd/rshd.c')
-rw-r--r-- | libexec/rshd/rshd.c | 79 |
1 files changed, 26 insertions, 53 deletions
diff --git a/libexec/rshd/rshd.c b/libexec/rshd/rshd.c index 1f3278a..cd2f57c 100644 --- a/libexec/rshd/rshd.c +++ b/libexec/rshd/rshd.c @@ -42,7 +42,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)rshd.c 8.2 (Berkeley) 4/6/94"; #endif static const char rcsid[] = - "$Id: rshd.c,v 1.21 1998/05/05 00:28:51 rnordier Exp $"; + "$Id: rshd.c,v 1.22 1998/12/01 23:27:24 dg Exp $"; #endif /* not lint */ /* @@ -80,7 +80,6 @@ static const char rcsid[] = #endif int keepalive = 1; -int check_all; int log_success; /* If TRUE, log all successful accesses */ int sent_null; int no_delay; @@ -122,7 +121,7 @@ main(argc, argv) while ((ch = getopt(argc, argv, OPTIONS)) != -1) switch (ch) { case 'a': - check_all = 1; + /* ignored for compatability */ break; case 'l': __check_rhosts_file = 0; @@ -214,10 +213,9 @@ doit(fromp) fd_set ready, readfrom; int cc, nfd, pv[2], pid, s; int one = 1; - char *hostname, *errorstr, *errorhost; + char *hostname, *errorstr; char *cp, sig, buf[BUFSIZ]; char cmdbuf[NCARGS+1], locuser[16], remuser[16]; - char remotehost[2 * MAXHOSTNAMELEN + 1]; char fromhost[2 * MAXHOSTNAMELEN + 1]; #ifdef LOGIN_CAP login_cap_t *lc; @@ -296,6 +294,7 @@ doit(fromp) (void) alarm(60); port = 0; + s = 0; /* not set or used if port == 0 */ for (;;) { char c; if ((cc = read(STDIN_FILENO, &c, 1)) != 1) { @@ -304,7 +303,7 @@ doit(fromp) shutdown(0, 1+1); exit(1); } - if (c== 0) + if (c == 0) break; port = port * 10 + c - '0'; } @@ -349,64 +348,38 @@ doit(fromp) dup2(f, 2); #endif errorstr = NULL; + strncpy(fromhost, inet_ntoa(fromp->sin_addr), + sizeof(fromhost) - 1); + hostname = fromhost; hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof (struct in_addr), fromp->sin_family); if (hp) { /* - * If name returned by gethostbyaddr is in our domain, - * attempt to verify that we haven't been fooled by someone - * in a remote net; look up the name and check that this - * address corresponds to the name. + * OK, it looks like a DNS name is attached.. Lets see if + * it looks like we can use it. If it doesn't check out, + * ditch it and use the IP address for logging instead. + * Note that iruserok() does it's own hostname checking!! */ strncpy(fromhost, hp->h_name, sizeof(fromhost) - 1); fromhost[sizeof(fromhost) - 1] = 0; - hostname = fromhost; -#ifdef KERBEROS - if (!use_kerberos) -#endif - if (check_all || local_domain(hp->h_name)) { - strncpy(remotehost, hp->h_name, sizeof(remotehost) - 1); - remotehost[sizeof(remotehost) - 1] = 0; - errorhost = remotehost; - hp = gethostbyname(remotehost); - if (hp == NULL) { - syslog(LOG_INFO, - "couldn't look up address for %s", - remotehost); - errorstr = - "Couldn't look up address for your host (%s)\n"; + hp = gethostbyname(fromhost); + if (hp == NULL) { + strncpy(fromhost, inet_ntoa(fromp->sin_addr), + sizeof(fromhost) - 1); + } else for (; ; hp->h_addr_list++) { + if (hp->h_addr_list[0] == NULL) { + /* End of list - ditch it */ strncpy(fromhost, inet_ntoa(fromp->sin_addr), sizeof(fromhost) - 1); - fromhost[sizeof(fromhost) - 1] = 0; - hostname = fromhost; - } else for (; ; hp->h_addr_list++) { - if (hp->h_addr_list[0] == NULL) { - syslog(LOG_NOTICE, - "host addr %s not listed for host %s", - inet_ntoa(fromp->sin_addr), - hp->h_name); - errorstr = - "Host address mismatch for %s\n"; - strncpy(fromhost, inet_ntoa(fromp->sin_addr), - sizeof(fromhost) - 1); - fromhost[sizeof(fromhost) - 1] = 0; - hostname = fromhost; - break; - } - if (!bcmp(hp->h_addr_list[0], - (caddr_t)&fromp->sin_addr, - sizeof(fromp->sin_addr))) { - hostname = remotehost; - break; - } + break; } + if (!bcmp(hp->h_addr_list[0], + (caddr_t)&fromp->sin_addr, + sizeof(fromp->sin_addr))) + break; /* OK! */ } - } else { - strncpy(fromhost, inet_ntoa(fromp->sin_addr), - sizeof(fromhost) - 1); - fromhost[sizeof(fromhost) - 1] = 0; - errorhost = hostname = fromhost; } + fromhost[sizeof(fromhost) - 1] = 0; #ifdef KERBEROS if (use_kerberos) { @@ -515,7 +488,7 @@ doit(fromp) fail: if (errorstr == NULL) errorstr = "Login incorrect.\n"; - error(errorstr, errorhost); + error(errorstr, hostname); exit(1); } |