]> andersk Git - openssh.git/blobdiff - sshpty.c
- markus@cvs.openbsd.org 2002/12/13 15:20:52
[openssh.git] / sshpty.c
index 71c48b5730248bac2a8dc54ff44f6395f220df42..28d0e310c4732a050ffdb80b252e75bd11fd24f7 100644 (file)
--- a/sshpty.c
+++ b/sshpty.c
@@ -12,7 +12,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: sshpty.c,v 1.4 2001/12/19 07:18:56 deraadt Exp $");
+RCSID("$OpenBSD: sshpty.c,v 1.7 2002/06/24 17:57:20 deraadt Exp $");
 
 #ifdef HAVE_UTIL_H
 # include <util.h>
@@ -162,10 +162,10 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
        }
        return 1;
 #else /* HAVE_DEV_PTS_AND_PTC */
-#ifdef _CRAY
+#ifdef _UNICOS
        char buf[64];
-       int i;
-       int highpty;
+       int i;
+       int highpty;
 
 #ifdef _SC_CRAY_NPTY
        highpty = sysconf(_SC_CRAY_NPTY);
@@ -199,6 +199,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
        const char *ptyminors = "0123456789abcdef";
        int num_minors = strlen(ptyminors);
        int num_ptys = strlen(ptymajors) * num_minors;
+       struct termios tio;
 
        for (i = 0; i < num_ptys; i++) {
                snprintf(buf, sizeof buf, "/dev/pty%c%c", ptymajors[i / num_minors],
@@ -223,6 +224,19 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
                        close(*ptyfd);
                        return 0;
                }
+               /* set tty modes to a sane state for broken clients */
+               if (tcgetattr(*ptyfd, &tio) < 0)
+                       log("Getting tty modes for pty failed: %.100s", strerror(errno));
+               else {
+                       tio.c_lflag |= (ECHO | ISIG | ICANON);
+                       tio.c_oflag |= (OPOST | ONLCR);
+                       tio.c_iflag |= ICRNL;
+
+                       /* Set the new modes for the terminal. */
+                       if (tcsetattr(*ptyfd, TCSANOW, &tio) < 0)
+                               log("Setting tty modes for pty failed: %.100s", strerror(errno));
+               }
+
                return 1;
        }
        return 0;
@@ -254,7 +268,7 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
        void *old;
 #endif /* USE_VHANGUP */
 
-#ifdef _CRAY
+#ifdef _UNICOS
        if (setsid() < 0)
                error("setsid: %.100s", strerror(errno));
 
@@ -275,8 +289,8 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
        if (fd < 0)
                error("%.100s: %.100s", ttyname, strerror(errno));
        close(*ttyfd);
-               *ttyfd = fd;
-#else /* _CRAY */
+       *ttyfd = fd;
+#else /* _UNICOS */
 
        /* First disconnect from the old controlling tty. */
 #ifdef TIOCNOTTY
@@ -329,10 +343,9 @@ pty_make_controlling_tty(int *ttyfd, const char *ttyname)
        if (fd < 0)
                error("open /dev/tty failed - could not set controlling tty: %.100s",
                    strerror(errno));
-       else {
+       else 
                close(fd);
-       }
-#endif /* _CRAY */
+#endif /* _UNICOS */
 }
 
 /* Changes the window size associated with the pty. */
@@ -342,6 +355,7 @@ pty_change_window_size(int ptyfd, int row, int col,
        int xpixel, int ypixel)
 {
        struct winsize w;
+
        w.ws_row = row;
        w.ws_col = col;
        w.ws_xpixel = xpixel;
@@ -379,13 +393,13 @@ 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 &&
-                          (st.st_uid == pw->pw_uid || st.st_uid == 0))
-                               error("chown(%.100s, %d, %d) failed: %.100s",
-                                   ttyname, pw->pw_uid, gid,
+                           (st.st_uid == pw->pw_uid || st.st_uid == 0))
+                               error("chown(%.100s, %u, %u) failed: %.100s",
+                                   ttyname, (u_int)pw->pw_uid, (u_int)gid,
                                    strerror(errno));
                        else
-                               fatal("chown(%.100s, %d, %d) failed: %.100s",
-                                   ttyname, pw->pw_uid, gid,
+                               fatal("chown(%.100s, %u, %u) failed: %.100s",
+                                   ttyname, (u_int)pw->pw_uid, (u_int)gid,
                                    strerror(errno));
                }
        }
This page took 0.292616 seconds and 4 git commands to generate.