turn on keep alives
[unix-history] / usr / src / libexec / rshd / rshd.c
index 6ccdb7c..f88ad8e 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rshd.c     4.12 83/02/10";
+static char sccsid[] = "@(#)rshd.c     4.15 83/05/03";
 #endif
 
 #include <sys/ioctl.h>
 #endif
 
 #include <sys/ioctl.h>
@@ -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)");
        }
        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)");
        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);
        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) {
                        continue;
                }
                if (fork() == 0) {
+                       signal(SIGCHLD, SIG_IGN);
                        close(f);
                        doit(g, &from);
                }
                        close(f);
                        doit(g, &from);
                }
@@ -160,10 +159,8 @@ doit(f, fromp)
        for (;;) {
                char c;
                if (read(f, &c, 1) != 1) {
        for (;;) {
                char c;
                if (read(f, &c, 1) != 1) {
-                       int how = 1+1;
-
                        perror("rshd: read");
                        perror("rshd: read");
-                       shutdown(f, &how);
+                       shutdown(f, 1+1);
                        exit(1);
                }
                if (c == 0)
                        exit(1);
                }
                if (c == 0)
@@ -211,7 +208,7 @@ doit(f, fromp)
                error("No remote directory.\n");
                exit(1);
        }
                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);
        }
                error("Permission denied.\n");
                exit(1);
        }
@@ -243,6 +240,7 @@ doit(f, fromp)
                                                killpg(pid, sig);
                                }
                                if (ready & (1<<pv[0])) {
                                                killpg(pid, sig);
                                }
                                if (ready & (1<<pv[0])) {
+                                       errno = 0;
                                        cc = read(pv[0], buf, sizeof (buf));
                                        if (cc <= 0) {
                                                shutdown(s, 1+1);
                                        cc = read(pv[0], buf, sizeof (buf));
                                        if (cc <= 0) {
                                                shutdown(s, 1+1);
@@ -261,8 +259,8 @@ doit(f, fromp)
                pwd->pw_shell = "/bin/sh";
        (void) close(f);
        initgroups(pwd->pw_name, pwd->pw_gid);
                pwd->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) 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);
        environ = envinit;
        strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
        strncat(shell, pwd->pw_shell, sizeof(shell)-7);