]> andersk Git - openssh.git/blobdiff - sshpty.c
- (stevesk) [Makefile.in ssh-rand-helper.c]
[openssh.git] / sshpty.c
index 6f97f38ed8da69b7c72bccb018df2837e16aab88..71c48b5730248bac2a8dc54ff44f6395f220df42 100644 (file)
--- a/sshpty.c
+++ b/sshpty.c
@@ -12,7 +12,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sshpty.c,v 1.2 2001/07/18 21:10:43 markus Exp $");
+RCSID("$OpenBSD: sshpty.c,v 1.4 2001/12/19 07:18:56 deraadt Exp $");
 
 #ifdef HAVE_UTIL_H
 # include <util.h>
@@ -156,12 +156,42 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
        *ttyfd = open(name, O_RDWR | O_NOCTTY);
        if (*ttyfd < 0) {
                error("Could not open pty slave side %.100s: %.100s",
-                     name, strerror(errno));
+                   name, strerror(errno));
                close(*ptyfd);
                return 0;
        }
        return 1;
 #else /* HAVE_DEV_PTS_AND_PTC */
+#ifdef _CRAY
+       char buf[64];
+       int i;
+       int highpty;
+
+#ifdef _SC_CRAY_NPTY
+       highpty = sysconf(_SC_CRAY_NPTY);
+       if (highpty == -1)
+               highpty = 128;
+#else
+       highpty = 128;
+#endif
+
+       for (i = 0; i < highpty; i++) {
+               snprintf(buf, sizeof(buf), "/dev/pty/%03d", i);
+               *ptyfd = open(buf, O_RDWR|O_NOCTTY);
+               if (*ptyfd < 0)
+                       continue;
+               snprintf(namebuf, namebuflen, "/dev/ttyp%03d", i);
+               /* Open the slave side. */
+               *ttyfd = open(namebuf, O_RDWR|O_NOCTTY);
+               if (*ttyfd < 0) {
+                       error("%.100s: %.100s", namebuf, strerror(errno));
+                       close(*ptyfd);
+                       return 0;
+               }
+               return 1;
+       }
+       return 0;
+#else
        /* BSD-style pty code. */
        char buf[64];
        int i;
@@ -196,6 +226,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
                return 1;
        }
        return 0;
+#endif /* CRAY */
 #endif /* HAVE_DEV_PTS_AND_PTC */
 #endif /* HAVE_DEV_PTMX */
 #endif /* HAVE__GETPTY */
@@ -223,6 +254,30 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
        void *old;
 #endif /* USE_VHANGUP */
 
+#ifdef _CRAY
+       if (setsid() < 0)
+               error("setsid: %.100s", strerror(errno));
+
+       fd = open(ttyname, O_RDWR|O_NOCTTY);
+       if (fd != -1) {
+               mysignal(SIGHUP, SIG_IGN);
+               ioctl(fd, TCVHUP, (char *)NULL);
+               mysignal(SIGHUP, SIG_DFL);
+               setpgid(0, 0);
+               close(fd);
+       } else {
+               error("Failed to disconnect from controlling tty.");
+       }
+
+       debug("Setting controlling tty using TCSETCTTY.");
+       ioctl(*ttyfd, TCSETCTTY, NULL);
+       fd = open("/dev/tty", O_RDWR);
+       if (fd < 0)
+               error("%.100s: %.100s", ttyname, strerror(errno));
+       close(*ttyfd);
+               *ttyfd = fd;
+#else /* _CRAY */
+
        /* First disconnect from the old controlling tty. */
 #ifdef TIOCNOTTY
        fd = open(_PATH_TTY, O_RDWR | O_NOCTTY);
@@ -254,9 +309,9 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
                error("SETPGRP %s",strerror(errno));
 #endif /* HAVE_NEWS4 */
 #ifdef USE_VHANGUP
-       old = signal(SIGHUP, SIG_IGN);
+       old = mysignal(SIGHUP, SIG_IGN);
        vhangup();
-       signal(SIGHUP, old);
+       mysignal(SIGHUP, old);
 #endif /* USE_VHANGUP */
        fd = open(ttyname, O_RDWR);
        if (fd < 0) {
@@ -273,17 +328,18 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
        fd = open(_PATH_TTY, O_WRONLY);
        if (fd < 0)
                error("open /dev/tty failed - could not set controlling tty: %.100s",
-                     strerror(errno));
+                   strerror(errno));
        else {
                close(fd);
        }
+#endif /* _CRAY */
 }
 
 /* Changes the window size associated with the pty. */
 
 void
 pty_change_window_size(int ptyfd, int row, int col,
-                      int xpixel, int ypixel)
+       int xpixel, int ypixel)
 {
        struct winsize w;
        w.ws_row = row;
@@ -313,7 +369,8 @@ pty_setowner(struct passwd *pw, const char *ttyname)
 
        /*
         * Change owner and mode of the tty as required.
-        * Warn but continue if filesystem is read-only and the uids match.
+        * Warn but continue if filesystem is read-only and the uids match/
+        * tty is owned by root.
         */
        if (stat(ttyname, &st))
                fatal("stat(%.100s) failed: %.100s", ttyname,
@@ -321,15 +378,15 @@ pty_setowner(struct passwd *pw, const char *ttyname)
 
        if (st.st_uid != pw->pw_uid || st.st_gid != gid) {
                if (chown(ttyname, pw->pw_uid, gid) < 0) {
-                       if (errno == EROFS && 
+                       if (errno == EROFS &&
                           (st.st_uid == pw->pw_uid || st.st_uid == 0))
                                error("chown(%.100s, %d, %d) failed: %.100s",
-                                     ttyname, pw->pw_uid, gid,
-                                     strerror(errno));
+                                   ttyname, pw->pw_uid, gid,
+                                   strerror(errno));
                        else
                                fatal("chown(%.100s, %d, %d) failed: %.100s",
-                                     ttyname, pw->pw_uid, gid,
-                                     strerror(errno));
+                                   ttyname, pw->pw_uid, gid,
+                                   strerror(errno));
                }
        }
 
@@ -338,10 +395,10 @@ pty_setowner(struct passwd *pw, const char *ttyname)
                        if (errno == EROFS &&
                            (st.st_mode & (S_IRGRP | S_IROTH)) == 0)
                                error("chmod(%.100s, 0%o) failed: %.100s",
-                                     ttyname, mode, strerror(errno));
+                                   ttyname, mode, strerror(errno));
                        else
                                fatal("chmod(%.100s, 0%o) failed: %.100s",
-                                     ttyname, mode, strerror(errno));
+                                   ttyname, mode, strerror(errno));
                }
        }
 }
This page took 0.045674 seconds and 4 git commands to generate.