X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/021570d6060e8cc9dba46e682dec09373dc4176b..2b597a6b92b8169b04e02434db1e663cd1f80384:/usr/src/libexec/rshd/rshd.c?ds=inline diff --git a/usr/src/libexec/rshd/rshd.c b/usr/src/libexec/rshd/rshd.c index c734c309d3..f88ad8eac8 100644 --- a/usr/src/libexec/rshd/rshd.c +++ b/usr/src/libexec/rshd/rshd.c @@ -1,5 +1,5 @@ #ifndef lint -static char sccsid[] = "@(#)rshd.c 4.10 83/01/22"; +static char sccsid[] = "@(#)rshd.c 4.15 83/05/03"; #endif #include @@ -81,10 +81,8 @@ main(argc, argv) } if (options & SO_DEBUG && setsockopt(f, SOL_SOCKET, SO_DEBUG, 0, 0) < 0) perror("rshd: setsockopt (SO_DEBUG)"); -#ifdef notdef if (setsockopt(f, SOL_SOCKET, SO_KEEPALIVE, 0, 0) < 0) perror("rshd: setsockopt (SO_KEEPALIVE)"); -#endif if (bind(f, (caddr_t)&sin, sizeof (sin), 0) < 0) { perror("rshd: bind"); exit(1); @@ -102,6 +100,7 @@ main(argc, argv) continue; } if (fork() == 0) { + signal(SIGCHLD, SIG_IGN); close(f); doit(g, &from); } @@ -131,7 +130,7 @@ doit(f, fromp) char cmdbuf[NCARGS+1], *cp; char locuser[16], remuser[16]; struct passwd *pwd; - int s; + int s, backoff; struct hostent *hp; short port; int pv[2], pid, ready, readfrom, cc; @@ -141,7 +140,7 @@ doit(f, fromp) (void) signal(SIGINT, SIG_DFL); (void) signal(SIGQUIT, SIG_DFL); (void) signal(SIGTERM, SIG_DFL); -#ifndef DEBUG +#ifdef DEBUG { int t = open("/dev/tty", 2); if (t >= 0) { ioctl(t, TIOCNOTTY, (char *)0); @@ -149,37 +148,46 @@ doit(f, fromp) } } #endif - dup2(f, 0); - dup2(f, 1); - dup2(f, 2); fromp->sin_port = ntohs((u_short)fromp->sin_port); if (fromp->sin_family != AF_INET || - fromp->sin_port >= IPPORT_RESERVED) + fromp->sin_port >= IPPORT_RESERVED) { + fprintf(stderr, "rshd: malformed from address\n"); exit(1); + } (void) alarm(60); port = 0; for (;;) { char c; - if (read(f, &c, 1) != 1) + if (read(f, &c, 1) != 1) { + perror("rshd: read"); + shutdown(f, 1+1); exit(1); + } if (c == 0) break; port = port * 10 + c - '0'; } (void) alarm(0); if (port != 0) { - int lport = IPPORT_RESERVED - 1; + int lport = IPPORT_RESERVED - 1, retryshift; s = rresvport(&lport); - if (s < 0) + if (s < 0) { + perror("rshd: can't get stderr port"); + exit(1); + } + if (port >= IPPORT_RESERVED) { + fprintf(stderr, "rshd: 2nd port not reserved\n"); exit(1); - if (port >= IPPORT_RESERVED) - goto protofail; - (void) alarm(60); + } fromp->sin_port = htons((u_short)port); - if (connect(s, fromp, sizeof (*fromp), 0) < 0) + if (connect(s, fromp, sizeof (*fromp), 0) < 0) { + perror("rshd: connect"); exit(1); - (void) alarm(0); + } } + dup2(f, 0); + dup2(f, 1); + dup2(f, 2); hp = gethostbyaddr(&fromp->sin_addr, sizeof (struct in_addr), fromp->sin_family); if (hp == 0) { @@ -200,7 +208,7 @@ doit(f, fromp) error("No remote directory.\n"); exit(1); } - if (ruserok(hp->h_name, remuser, locuser) < 0) { + if (ruserok(hp->h_name, pwd->pw_uid == 0, remuser, locuser) < 0) { error("Permission denied.\n"); exit(1); } @@ -232,6 +240,7 @@ doit(f, fromp) killpg(pid, sig); } if (ready & (1<pw_shell = "/bin/sh"; (void) close(f); initgroups(pwd->pw_name, pwd->pw_gid); - (void) setuid(pwd->pw_uid); (void) setgid(pwd->pw_gid); + (void) setuid(pwd->pw_uid); environ = envinit; strncat(homedir, pwd->pw_dir, sizeof(homedir)-6); strncat(shell, pwd->pw_shell, sizeof(shell)-7);