]> andersk Git - gssapi-openssh.git/blobdiff - openssh/ttymodes.c
The man2html from jbasney on pkilab2 works whereas the standard one doesn't.
[gssapi-openssh.git] / openssh / ttymodes.c
index 6f51b8a70836618782570d5680fc80b663f4d709..c0bb0b1f898cf7db1d62923a18eda4584c7eec1d 100644 (file)
@@ -1,4 +1,3 @@
-/* $OpenBSD: ttymodes.c,v 1.29 2008/11/02 00:16:16 stevesk Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  */
 
 #include "includes.h"
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <string.h>
-#include <termios.h>
-#include <stdarg.h>
+RCSID("$OpenBSD: ttymodes.c,v 1.14 2001/06/24 17:18:31 markus Exp $");
 
 #include "packet.h"
 #include "log.h"
 #include "ssh1.h"
 #include "compat.h"
 #include "buffer.h"
+#include "bufaux.h"
 
 #define TTY_OP_END             0
 /*
@@ -246,32 +240,6 @@ baud_to_speed(int baud)
        }
 }
 
-/*
- * Encode a special character into SSH line format.
- */
-static u_int
-special_char_encode(cc_t c)
-{
-#ifdef _POSIX_VDISABLE
-       if (c == _POSIX_VDISABLE)
-               return 255;
-#endif /* _POSIX_VDISABLE */
-       return c;
-}
-
-/*
- * Decode a special character from SSH line format.
- */
-static cc_t
-special_char_decode(u_int c)
-{
-#ifdef _POSIX_VDISABLE
-       if (c == 255)
-               return _POSIX_VDISABLE;
-#endif /* _POSIX_VDISABLE */
-       return c;
-}
-
 /*
  * Encodes terminal modes for the terminal referenced by fd
  * or tiop in a portable manner, and appends the modes to a packet
@@ -298,12 +266,8 @@ tty_make_modes(int fd, struct termios *tiop)
        }
 
        if (tiop == NULL) {
-               if (fd == -1) {
-                       debug("tty_make_modes: no fd or tio");
-                       goto end;
-               }
                if (tcgetattr(fd, &tio) == -1) {
-                       logit("tcgetattr: %.100s", strerror(errno));
+                       log("tcgetattr: %.100s", strerror(errno));
                        goto end;
                }
        } else
@@ -311,18 +275,22 @@ tty_make_modes(int fd, struct termios *tiop)
 
        /* Store input and output baud rates. */
        baud = speed_to_baud(cfgetospeed(&tio));
+       debug3("tty_make_modes: ospeed %d", baud);
        buffer_put_char(&buf, tty_op_ospeed);
        buffer_put_int(&buf, baud);
        baud = speed_to_baud(cfgetispeed(&tio));
+       debug3("tty_make_modes: ispeed %d", baud);
        buffer_put_char(&buf, tty_op_ispeed);
        buffer_put_int(&buf, baud);
 
        /* Store values of mode flags. */
 #define TTYCHAR(NAME, OP) \
+       debug3("tty_make_modes: %d %d", OP, tio.c_cc[NAME]); \
        buffer_put_char(&buf, OP); \
-       put_arg(&buf, special_char_encode(tio.c_cc[NAME]));
+       put_arg(&buf, tio.c_cc[NAME]);
 
 #define TTYMODE(NAME, FIELD, OP) \
+       debug3("tty_make_modes: %d %d", OP, ((tio.FIELD & NAME) != 0)); \
        buffer_put_char(&buf, OP); \
        put_arg(&buf, ((tio.FIELD & NAME) != 0));
 
@@ -339,6 +307,7 @@ end:
        else
                packet_put_raw(buffer_ptr(&buf), buffer_len(&buf));
        buffer_free(&buf);
+       return;
 }
 
 /*
@@ -353,10 +322,11 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
        int n_bytes = 0;
        int failure = 0;
        u_int (*get_arg)(void);
-       int arg_size;
+       int arg, arg_size;
 
        if (compat20) {
                *n_bytes_ptr = packet_get_int();
+               debug3("tty_parse_modes: SSH2 n_bytes %d", *n_bytes_ptr);
                if (*n_bytes_ptr == 0)
                        return;
                get_arg = packet_get_int;
@@ -372,7 +342,7 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
         * modes, they will initially have reasonable values.
         */
        if (tcgetattr(fd, &tio) == -1) {
-               logit("tcgetattr: %.100s", strerror(errno));
+               log("tcgetattr: %.100s", strerror(errno));
                failure = -1;
        }
 
@@ -388,8 +358,8 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
                case TTY_OP_ISPEED_PROTO2:
                        n_bytes += 4;
                        baud = packet_get_int();
-                       if (failure != -1 &&
-                           cfsetispeed(&tio, baud_to_speed(baud)) == -1)
+                       debug3("tty_parse_modes: ispeed %d", baud);
+                       if (failure != -1 && cfsetispeed(&tio, baud_to_speed(baud)) == -1)
                                error("cfsetispeed failed for %d", baud);
                        break;
 
@@ -398,23 +368,25 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
                case TTY_OP_OSPEED_PROTO2:
                        n_bytes += 4;
                        baud = packet_get_int();
-                       if (failure != -1 &&
-                           cfsetospeed(&tio, baud_to_speed(baud)) == -1)
+                       debug3("tty_parse_modes: ospeed %d", baud);
+                       if (failure != -1 && cfsetospeed(&tio, baud_to_speed(baud)) == -1)
                                error("cfsetospeed failed for %d", baud);
                        break;
 
 #define TTYCHAR(NAME, OP) \
        case OP: \
          n_bytes += arg_size; \
-         tio.c_cc[NAME] = special_char_decode(get_arg()); \
+         tio.c_cc[NAME] = get_arg(); \
+         debug3("tty_parse_modes: %d %d", OP, tio.c_cc[NAME]); \
          break;
 #define TTYMODE(NAME, FIELD, OP) \
        case OP: \
          n_bytes += arg_size; \
-         if (get_arg()) \
+         if ((arg = get_arg())) \
            tio.FIELD |= NAME; \
          else \
            tio.FIELD &= ~NAME; \
+         debug3("tty_parse_modes: %d %d", OP, arg); \
          break;
 
 #include "ttymodes.h"
@@ -424,35 +396,35 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
 
                default:
                        debug("Ignoring unsupported tty mode opcode %d (0x%x)",
-                           opcode, opcode);
+                             opcode, opcode);
                        if (!compat20) {
                                /*
                                 * SSH1:
                                 * Opcodes 1 to 127 are defined to have
                                 * a one-byte argument.
-                                * Opcodes 128 to 159 are defined to have
-                                * an integer argument.
-                                */
+                                * Opcodes 128 to 159 are defined to have
+                                * an integer argument.
+                                */
                                if (opcode > 0 && opcode < 128) {
                                        n_bytes += 1;
                                        (void) packet_get_char();
                                        break;
                                } else if (opcode >= 128 && opcode < 160) {
-                                       n_bytes += 4;
-                                       (void) packet_get_int();
-                                       break;
+                                       n_bytes += 4;
+                                       (void) packet_get_int();
+                                       break;
                                } else {
                                        /*
                                         * It is a truly undefined opcode (160 to 255).
                                         * We have no idea about its arguments.  So we
-                                        * must stop parsing.  Note that some data
-                                        * may be left in the packet; hopefully there
-                                        * is nothing more coming after the mode data.
+                                        * must stop parsing.  Note that some data may be
+                                        * left in the packet; hopefully there is nothing
+                                        * more coming after the mode data.
                                         */
-                                       logit("parse_tty_modes: unknown opcode %d",
-                                           opcode);
+                                       log("parse_tty_modes: unknown opcode %d", opcode);
+                                       packet_integrity_check(0, 1, SSH_CMSG_REQUEST_PTY);
                                        goto set;
-                               }
+                               }
                        } else {
                                /*
                                 * SSH2:
@@ -466,18 +438,17 @@ tty_parse_modes(int fd, int *n_bytes_ptr)
                                        (void) packet_get_int();
                                        break;
                                } else {
-                                       logit("parse_tty_modes: unknown opcode %d",
-                                           opcode);
+                                       log("parse_tty_modes: unknown opcode %d", opcode);
                                        goto set;
                                }
-                       }
+                       }
                }
        }
 
 set:
        if (*n_bytes_ptr != n_bytes) {
                *n_bytes_ptr = n_bytes;
-               logit("parse_tty_modes: n_bytes_ptr != n_bytes: %d %d",
+               log("parse_tty_modes: n_bytes_ptr != n_bytes: %d %d",
                    *n_bytes_ptr, n_bytes);
                return;         /* Don't process bytes passed */
        }
@@ -486,5 +457,6 @@ set:
 
        /* Set the new modes for the terminal. */
        if (tcsetattr(fd, TCSANOW, &tio) == -1)
-               logit("Setting tty modes failed: %.100s", strerror(errno));
+               log("Setting tty modes failed: %.100s", strerror(errno));
+       return;
 }
This page took 0.08789 seconds and 4 git commands to generate.