gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29847 - msh/src


From: gnunet
Subject: [GNUnet-SVN] r29847 - msh/src
Date: Fri, 4 Oct 2013 18:41:07 +0200

Author: harsha
Date: 2013-10-04 18:41:06 +0200 (Fri, 04 Oct 2013)
New Revision: 29847

Added:
   msh/src/msh_waiter.c
   msh/src/ttymodes.c
   msh/src/ttymodes.h
Modified:
   msh/src/mtypes.h
Log:
- towards reverse remote shell crazyness...


Added: msh/src/msh_waiter.c
===================================================================
--- msh/src/msh_waiter.c                                (rev 0)
+++ msh/src/msh_waiter.c        2013-10-04 16:41:06 UTC (rev 29847)
@@ -0,0 +1,284 @@
+#include "common.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <termios.h>
+
+#define LOG(kind,...)                           \
+  GNUNET_log (kind, __VA_ARGS__)
+
+#define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
+
+#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
+
+#define TIMEOUT(secs) \
+  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, secs);
+
+#define DEFAULT_TIMEOUT TIMEOUT(30)
+
+#define PROG_NAME "msh-waiter"
+
+unsigned int port;
+
+static struct GNUNET_CONFIGURATION_Handle *cfg;
+
+static struct GNUNET_NETWORK_Handle *lsock;
+
+static struct GNUNET_NETWORK_Handle *conn;
+
+static struct GNUNET_MessageHeader *msg;
+
+static struct GNUNET_CONNECTION_TransmitHandle *handle_tx;
+
+static int in_receive;
+
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  if (NULL != handle_tx)
+    GNUNET_CONNECTION_notify_transmit_ready_cancel (handle_tx);
+  if (NULL != conn)
+  {
+    if (in_receive)
+      GNUNET_CONNECTION_receive_cancel (conn);
+    GNUNET_CONNECTION_destroy (conn);
+  }
+  if (NULL != lsock)
+    GNUNET_NETWORK_socket_close (lsock);
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_destroy (cfg);
+  GNUNET_free_non_null (msg);
+}
+
+void
+enter_raw_mode(int quiet)
+{
+       struct termios tio;
+
+       if (tcgetattr(fileno(stdin), &tio) == -1) {
+               if (!quiet)
+                       perror("tcgetattr");
+               return;
+       }
+       _saved_tio = tio;
+       tio.c_iflag |= IGNPAR;
+       tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
+#ifdef IUCLC
+       tio.c_iflag &= ~IUCLC;
+#endif
+       tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
+#ifdef IEXTEN
+       tio.c_lflag &= ~IEXTEN;
+#endif
+       tio.c_oflag &= ~OPOST;
+       tio.c_cc[VMIN] = 1;
+       tio.c_cc[VTIME] = 0;
+       if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1) {
+               if (!quiet)
+                       perror("tcsetattr");
+       } else
+               _in_raw_mode = 1;
+}
+
+
+/**
+ * Callback function for data received from the network.  Note that
+ * both "available" and "err" would be 0 if the read simply timed out.
+ *
+ * @param cls closure
+ * @param buf pointer to received data
+ * @param available number of bytes availabe in "buf",
+ *        possibly 0 (on errors)
+ * @param addr address of the sender
+ * @param addrlen size of addr
+ * @param errCode value of errno (on errors receiving)
+ */
+static void
+receive (void *cls, const void *buf, size_t available,
+         const struct sockaddr * addr, socklen_t addrlen, int errCode)
+{
+  GNUNET_break (0);
+}
+
+
+/**
+ * Transmit the global msg
+ *
+ * @param cls closure
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to buf
+ */
+static size_t
+do_tx (void *cls, size_t size, void *buf)
+{
+  size_t nb;
+  
+  handle_tx = NULL;
+  if ((NULL == buf) || (0 == size))
+  {
+    LOG_ERROR ("Failure in connectivity\n");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  GNUNET_assert (NULL != msg);
+  nb = ntohs (msg->size);
+  GNUNET_assert (nb <= size);
+  (void) memcpy (buf, msg, nb);
+  GNUNET_free (msg);
+  msg = NULL;
+  if (!in_receive)
+    GNUNET_CONNECTION_receive (conn, GNUNET_SERVER_MAX_MESSAGE_SIZE,
+                               GNUNET_TIME_UNIT_FOREVER_REL,
+                               &receive, NULL);
+}
+
+
+static void
+accept_lsock (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct termios tio;
+  struct winsize ws;
+  struct MSH_MSG_PtyMode *tmsg;
+  char *cp;
+  uint16_t *ts;
+  size_t size;
+  unsigned int count;
+  int baud;
+
+  conn = GNUNET_CONNECTION_create_from_accept (NULL, NULL, lsock);
+  GNUNET_NETWORK_socket_close (lsock);
+  lsock = NULL;
+  if (NULL == conn)
+  {
+    LOG_ERROR ("Failed to create incoming connection");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
+    memset(&ws, 0, sizeof(ws));
+  cp = getenv ("TERM");  
+  /* count terminal settings */
+  count = 0;
+
+#define TTYCHAR(NAME,OP)                        \
+  count++;
+#define TTYMODE(NAME,FIELD,OP)                  \
+  count++;
+#include "ttymodes.h"
+#undef TTYCHAR
+#undef TTYMODE
+
+  size = sizeof (struct MSH_MSG_PtyMode) + 
+      (sizeof (uint16_t) * 2) + ((NULL != cp) ? strlen(cp) : 0) + 1;
+  if (-1 == tcgetattr (0, &tio))
+  {
+    GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "tcgetattr");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  tmsg = GNUNET_malloc (size);
+  tmsg->header.type = htons (MSH_MTYPE_PTY_MODE);
+  tmsg->header.size = htons (size);
+  tmsg->ws_row = htons (ws.ws_row);
+  tmsg->ws_col = htons (ws.ws_col);
+  tmsg->ws_xpixel = htons (ws.ws_xpixel);
+  tmsg->ws_ypixel = htons (ws.ws_ypixel);
+  tmsg->ospeed = htonl (speed_to_baud (cfgetospeed (&tio)));
+  tmsg->ispeed = htonl (speed_to_baud (cfgetispeed (&tio)));
+  tmsg->nsettings = htons (count);
+
+  ts = &tmsg->nsettings;
+  ts++;
+#define TTYCHAR(NAME,OP)                        \
+    *(ts++) = htons (OP);                       \
+    *(ts++) = htons (tio.cc[NAME]);
+
+#define TTYMODE(NAME, FIELD, OP)                \
+    *(ts++) = htons (OP);                       \
+    *(ts++) = htons ((tio.FIELD & NAME) != 0);
+#include "ttymodes.h"
+#undef TTYCHAR
+#undef TTYMODE
+
+  if (NULL != cp)
+    (void) memcpy ((void *)ts, cp, strlen (cp));
+  enter_raw_mode (1)
+
+  hanlde_tx = GNUNET_CONNECTION_notify_transmit_ready (conn, size, 
DEFAULT_TIMEOUT,
+                                                &do_tx, NULL);
+  if (NULL == handle_tx)
+  {
+    LOG_ERROR ("Failed to transmit PTY mode\n");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls, 
+     char *const *args, 
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
+{
+  struct sockaddr_in laddr;
+  int ret;
+
+  cfg = GNUNET_CONFIGURATION_dup (c);  
+  lsock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
+  memset (&laddr, 0, sizeof (laddr));
+  laddr.sin_addr = INADDR_ANY;
+  laddr.sin_port = htons (port);
+  ret = GNUNET_NETWORK_socket_bind (lsock, &laddr, sizeof (laddr), 0);
+  if (GNUNET_SYSERR == ret)
+    goto err_ret;
+  ret = GNUNET_NETWORK_socket_listen (lsock, 1);
+  if (GNUNET_SYSERR == ret)
+    goto err_ret;
+
+  GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+                                 lsock, accept_lsock, NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+                                &do_shutdown, NULL);
+ err_ret:
+  GNUNET_NETWORK_socket_close (lsock);
+  GNUNET_CONFIGURATION_destroy (cfg);
+  return;
+}
+
+int main (int argc, char * const *argv)
+{
+  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+    {'l', "listen", NULL, gettext_noop ("listen port"),
+     GNUNET_YES, &GNUNET_GETOPT_set_uint, &port},
+    GNUNET_GETOPT_OPTION_END
+  };
+  int ret;
+  
+  if (!isatty(0))
+  {
+    fprintf (stderr, "Not running with a tty.  Exiting\n");
+    return 1;
+  }
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+  if (GNUNET_OK != (ret = 
+      GNUNET_PROGRAM_run (argc, argv, PROG_NAME,
+                         gettext_noop
+                         ("waiter program for providing TTY supported "
+                           "interaction with the master process spawned from 
MSHD"),
+                         options, &run, NULL)))
+    {
+      GNUNET_free ((void *) argv);
+      return ret;
+    }
+  GNUNET_free ((void *) argv);
+  return ret;
+}

Modified: msh/src/mtypes.h
===================================================================
--- msh/src/mtypes.h    2013-10-04 16:22:28 UTC (rev 29846)
+++ msh/src/mtypes.h    2013-10-04 16:41:06 UTC (rev 29847)
@@ -251,4 +251,24 @@
 };
 
 
+struct MSH_MSG_PtyMode
+{
+  /**
+   * header; set type to MSH_MTYPE_PTY_MODE
+   */
+  struct GNUNET_MessageHeader header;
+
+  uint16_t ws_row GNUNET_PACKED;
+  uint16_t ws_col GNUNET_PACKED;
+  uint16_t ws_xpixel GNUNET_PACKED;
+  uint16_t ws_ypixel GNUNET_PACKED;
+  uint16_t ospeed GNUNET_PACKED;
+  uint16_t ispeed GNUNET_PACKED;
+  uint16_t nsettings GNUNET_PACKED;
+  /* Followed by nsettings uint16_t = uint16_t.  See ttymodes.h for the
+     settings that are to be included */
+  /* Followed by the TERM var string (NULL-terminated) */
+}
+
+
 #endif  /* MTYPES_H_ */

Added: msh/src/ttymodes.c
===================================================================
--- msh/src/ttymodes.c                          (rev 0)
+++ msh/src/ttymodes.c  2013-10-04 16:41:06 UTC (rev 29847)
@@ -0,0 +1,484 @@
+/* $OpenBSD: ttymodes.c,v 1.29 2008/11/02 00:16:16 stevesk Exp $ */
+/*
+ * Author: Tatu Ylonen <address@hidden>
+ * Copyright (c) 1995 Tatu Ylonen <address@hidden>, Espoo, Finland
+ *                    All rights reserved
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose.  Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ */
+
+/*
+ * SSH2 tty modes support by Kevin Steves.
+ * Copyright (c) 2001 Kevin Steves.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Encoding and decoding of terminal modes in a portable way.
+ * Much of the format is defined in ttymodes.h; it is included multiple times
+ * into this file with the appropriate macro definitions to generate the
+ * suitable code.
+ */
+
+#include "common.h"
+
+#include <termios.h>
+
+#define TTY_OP_END             0
+
+/*
+ * uint32 (u_int) follows speed in SSH1 and SSH2
+ */
+#define TTY_OP_ISPEED_PROTO1   192
+#define TTY_OP_OSPEED_PROTO1   193
+#define TTY_OP_ISPEED_PROTO2   128
+#define TTY_OP_OSPEED_PROTO2   129
+
+/*
+ * Converts POSIX speed_t to a baud rate.  The values of the
+ * constants for speed_t are not themselves portable.
+ */
+static int
+speed_to_baud(speed_t speed)
+{
+       switch (speed) {
+       case B0:
+               return 0;
+       case B50:
+               return 50;
+       case B75:
+               return 75;
+       case B110:
+               return 110;
+       case B134:
+               return 134;
+       case B150:
+               return 150;
+       case B200:
+               return 200;
+       case B300:
+               return 300;
+       case B600:
+               return 600;
+       case B1200:
+               return 1200;
+       case B1800:
+               return 1800;
+       case B2400:
+               return 2400;
+       case B4800:
+               return 4800;
+       case B9600:
+               return 9600;
+
+#ifdef B19200
+       case B19200:
+               return 19200;
+#else /* B19200 */
+#ifdef EXTA
+       case EXTA:
+               return 19200;
+#endif /* EXTA */
+#endif /* B19200 */
+
+#ifdef B38400
+       case B38400:
+               return 38400;
+#else /* B38400 */
+#ifdef EXTB
+       case EXTB:
+               return 38400;
+#endif /* EXTB */
+#endif /* B38400 */
+
+#ifdef B7200
+       case B7200:
+               return 7200;
+#endif /* B7200 */
+#ifdef B14400
+       case B14400:
+               return 14400;
+#endif /* B14400 */
+#ifdef B28800
+       case B28800:
+               return 28800;
+#endif /* B28800 */
+#ifdef B57600
+       case B57600:
+               return 57600;
+#endif /* B57600 */
+#ifdef B76800
+       case B76800:
+               return 76800;
+#endif /* B76800 */
+#ifdef B115200
+       case B115200:
+               return 115200;
+#endif /* B115200 */
+#ifdef B230400
+       case B230400:
+               return 230400;
+#endif /* B230400 */
+       default:
+               return 9600;
+       }
+}
+
+/*
+ * Converts a numeric baud rate to a POSIX speed_t.
+ */
+static speed_t
+baud_to_speed(int baud)
+{
+       switch (baud) {
+       case 0:
+               return B0;
+       case 50:
+               return B50;
+       case 75:
+               return B75;
+       case 110:
+               return B110;
+       case 134:
+               return B134;
+       case 150:
+               return B150;
+       case 200:
+               return B200;
+       case 300:
+               return B300;
+       case 600:
+               return B600;
+       case 1200:
+               return B1200;
+       case 1800:
+               return B1800;
+       case 2400:
+               return B2400;
+       case 4800:
+               return B4800;
+       case 9600:
+               return B9600;
+
+#ifdef B19200
+       case 19200:
+               return B19200;
+#else /* B19200 */
+#ifdef EXTA
+       case 19200:
+               return EXTA;
+#endif /* EXTA */
+#endif /* B19200 */
+
+#ifdef B38400
+       case 38400:
+               return B38400;
+#else /* B38400 */
+#ifdef EXTB
+       case 38400:
+               return EXTB;
+#endif /* EXTB */
+#endif /* B38400 */
+
+#ifdef B7200
+       case 7200:
+               return B7200;
+#endif /* B7200 */
+#ifdef B14400
+       case 14400:
+               return B14400;
+#endif /* B14400 */
+#ifdef B28800
+       case 28800:
+               return B28800;
+#endif /* B28800 */
+#ifdef B57600
+       case 57600:
+               return B57600;
+#endif /* B57600 */
+#ifdef B76800
+       case 76800:
+               return B76800;
+#endif /* B76800 */
+#ifdef B115200
+       case 115200:
+               return B115200;
+#endif /* B115200 */
+#ifdef B230400
+       case 230400:
+               return B230400;
+#endif /* B230400 */
+       default:
+               return B9600;
+       }
+}
+
+/*
+ * 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;
+}
+
+#ifdef 0                        /* begin code ignore */
+
+/*
+ * Encodes terminal modes for the terminal referenced by fd
+ * or tiop in a portable manner, and appends the modes to a packet
+ * being constructed.
+ */
+void
+tty_make_modes(int fd, struct termios *tiop)
+{
+       struct termios tio;
+       int baud;
+       Buffer buf;
+       int tty_op_ospeed, tty_op_ispeed;
+       void (*put_arg)(Buffer *, u_int);
+
+       buffer_init(&buf);
+       if (compat20) {
+               tty_op_ospeed = TTY_OP_OSPEED_PROTO2;
+               tty_op_ispeed = TTY_OP_ISPEED_PROTO2;
+               put_arg = buffer_put_int;
+       } else {
+               tty_op_ospeed = TTY_OP_OSPEED_PROTO1;
+               tty_op_ispeed = TTY_OP_ISPEED_PROTO1;
+               put_arg = (void (*)(Buffer *, u_int)) buffer_put_char;
+       }
+
+       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));
+                       goto end;
+               }
+       } else
+               tio = *tiop;
+
+       /* Store input and output baud rates. */
+       baud = speed_to_baud(cfgetospeed(&tio));
+       buffer_put_char(&buf, tty_op_ospeed);
+       buffer_put_int(&buf, baud);
+       baud = speed_to_baud(cfgetispeed(&tio));
+       buffer_put_char(&buf, tty_op_ispeed);
+       buffer_put_int(&buf, baud);
+
+       /* Store values of mode flags. */
+#define TTYCHAR(NAME, OP) \
+       buffer_put_char(&buf, OP); \
+       put_arg(&buf, special_char_encode(tio.c_cc[NAME]));
+
+#define TTYMODE(NAME, FIELD, OP) \
+       buffer_put_char(&buf, OP); \
+       put_arg(&buf, ((tio.FIELD & NAME) != 0));
+
+#include "ttymodes.h"
+
+#undef TTYCHAR
+#undef TTYMODE
+
+end:
+       /* Mark end of mode data. */
+       buffer_put_char(&buf, TTY_OP_END);
+       if (compat20)
+               packet_put_string(buffer_ptr(&buf), buffer_len(&buf));
+       else
+               packet_put_raw(buffer_ptr(&buf), buffer_len(&buf));
+       buffer_free(&buf);
+}
+
+/*
+ * Decodes terminal modes for the terminal referenced by fd in a portable
+ * manner from a packet being read.
+ */
+void
+tty_parse_modes(int fd, int *n_bytes_ptr)
+{
+       struct termios tio;
+       int opcode, baud;
+       int n_bytes = 0;
+       int failure = 0;
+       u_int (*get_arg)(void);
+       int arg_size;
+
+       if (compat20) {
+               *n_bytes_ptr = packet_get_int();
+               if (*n_bytes_ptr == 0)
+                       return;
+               get_arg = packet_get_int;
+               arg_size = 4;
+       } else {
+               get_arg = packet_get_char;
+               arg_size = 1;
+       }
+
+       /*
+        * Get old attributes for the terminal.  We will modify these
+        * flags. I am hoping that if there are any machine-specific
+        * modes, they will initially have reasonable values.
+        */
+       if (tcgetattr(fd, &tio) == -1) {
+               logit("tcgetattr: %.100s", strerror(errno));
+               failure = -1;
+       }
+
+       for (;;) {
+               n_bytes += 1;
+               opcode = packet_get_char();
+               switch (opcode) {
+               case TTY_OP_END:
+                       goto set;
+
+               /* XXX: future conflict possible */
+               case TTY_OP_ISPEED_PROTO1:
+               case TTY_OP_ISPEED_PROTO2:
+                       n_bytes += 4;
+                       baud = packet_get_int();
+                       if (failure != -1 &&
+                           cfsetispeed(&tio, baud_to_speed(baud)) == -1)
+                               error("cfsetispeed failed for %d", baud);
+                       break;
+
+               /* XXX: future conflict possible */
+               case TTY_OP_OSPEED_PROTO1:
+               case TTY_OP_OSPEED_PROTO2:
+                       n_bytes += 4;
+                       baud = packet_get_int();
+                       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()); \
+         break;
+#define TTYMODE(NAME, FIELD, OP) \
+       case OP: \
+         n_bytes += arg_size; \
+         if (get_arg()) \
+           tio.FIELD |= NAME; \
+         else \
+           tio.FIELD &= ~NAME; \
+         break;
+
+#include "ttymodes.h"
+
+#undef TTYCHAR
+#undef TTYMODE
+
+               default:
+                       debug("Ignoring unsupported tty mode opcode %d (0x%x)",
+                           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.
+                                */
+                               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;
+                               } 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.
+                                        */
+                                       logit("parse_tty_modes: unknown opcode 
%d",
+                                           opcode);
+                                       goto set;
+                               }
+                       } else {
+                               /*
+                                * SSH2:
+                                * Opcodes 1 to 159 are defined to have
+                                * a uint32 argument.
+                                * Opcodes 160 to 255 are undefined and
+                                * cause parsing to stop.
+                                */
+                               if (opcode > 0 && opcode < 160) {
+                                       n_bytes += 4;
+                                       (void) packet_get_int();
+                                       break;
+                               } else {
+                                       logit("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",
+                   *n_bytes_ptr, n_bytes);
+               return;         /* Don't process bytes passed */
+       }
+       if (failure == -1)
+               return;         /* Packet parsed ok but tcgetattr() failed */
+
+       /* Set the new modes for the terminal. */
+       if (tcsetattr(fd, TCSANOW, &tio) == -1)
+               logit("Setting tty modes failed: %.100s", strerror(errno));
+}
+
+#endif  /* begin code ignore */

Added: msh/src/ttymodes.h
===================================================================
--- msh/src/ttymodes.h                          (rev 0)
+++ msh/src/ttymodes.h  2013-10-04 16:41:06 UTC (rev 29847)
@@ -0,0 +1,175 @@
+/* $OpenBSD: ttymodes.h,v 1.14 2006/03/25 22:22:43 djm Exp $ */
+
+/*
+ * Author: Tatu Ylonen <address@hidden>
+ * Copyright (c) 1995 Tatu Ylonen <address@hidden>, Espoo, Finland
+ *                    All rights reserved
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose.  Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ */
+
+/*
+ * SSH2 tty modes support by Kevin Steves.
+ * Copyright (c) 2001 Kevin Steves.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * SSH1:
+ * The tty mode description is a stream of bytes.  The stream consists of
+ * opcode-arguments pairs.  It is terminated by opcode TTY_OP_END (0).
+ * Opcodes 1-127 have one-byte arguments.  Opcodes 128-159 have integer
+ * arguments.  Opcodes 160-255 are not yet defined, and cause parsing to
+ * stop (they should only be used after any other data).
+ *
+ * SSH2:
+ * Differences between SSH1 and SSH2 terminal mode encoding include:
+ * 1. Encoded terminal modes are represented as a string, and a stream
+ *    of bytes within that string.
+ * 2. Opcode arguments are uint32 (1-159); 160-255 remain undefined.
+ * 3. The values for TTY_OP_ISPEED and TTY_OP_OSPEED are different;
+ *    128 and 129 vs. 192 and 193 respectively.
+ *
+ * The client puts in the stream any modes it knows about, and the
+ * server ignores any modes it does not know about.  This allows some degree
+ * of machine-independence, at least between systems that use a posix-like
+ * tty interface.  The protocol can support other systems as well, but might
+ * require reimplementing as mode names would likely be different.
+ */
+
+/*
+ * Some constants and prototypes are defined in packet.h; this file
+ * is only intended for including from ttymodes.c.
+ */
+
+/* termios macro */
+/* name, op */
+TTYCHAR(VINTR, 1)
+TTYCHAR(VQUIT, 2)
+TTYCHAR(VERASE, 3)
+#if defined(VKILL)
+TTYCHAR(VKILL, 4)
+#endif /* VKILL */
+TTYCHAR(VEOF, 5)
+#if defined(VEOL)
+TTYCHAR(VEOL, 6)
+#endif /* VEOL */
+#ifdef VEOL2
+TTYCHAR(VEOL2, 7)
+#endif /* VEOL2 */
+TTYCHAR(VSTART, 8)
+TTYCHAR(VSTOP, 9)
+#if defined(VSUSP)
+TTYCHAR(VSUSP, 10)
+#endif /* VSUSP */
+#if defined(VDSUSP)
+TTYCHAR(VDSUSP, 11)
+#endif /* VDSUSP */
+#if defined(VREPRINT)
+TTYCHAR(VREPRINT, 12)
+#endif /* VREPRINT */
+#if defined(VWERASE)
+TTYCHAR(VWERASE, 13)
+#endif /* VWERASE */
+#if defined(VLNEXT)
+TTYCHAR(VLNEXT, 14)
+#endif /* VLNEXT */
+#if defined(VFLUSH)
+TTYCHAR(VFLUSH, 15)
+#endif /* VFLUSH */
+#ifdef VSWTCH
+TTYCHAR(VSWTCH, 16)
+#endif /* VSWTCH */
+#if defined(VSTATUS)
+TTYCHAR(VSTATUS, 17)
+#endif /* VSTATUS */
+#ifdef VDISCARD
+TTYCHAR(VDISCARD, 18)
+#endif /* VDISCARD */
+
+/* name, field, op */
+TTYMODE(IGNPAR,        c_iflag, 30)
+TTYMODE(PARMRK,        c_iflag, 31)
+TTYMODE(INPCK, c_iflag, 32)
+TTYMODE(ISTRIP,        c_iflag, 33)
+TTYMODE(INLCR, c_iflag, 34)
+TTYMODE(IGNCR, c_iflag, 35)
+TTYMODE(ICRNL, c_iflag, 36)
+#if defined(IUCLC)
+TTYMODE(IUCLC, c_iflag, 37)
+#endif
+TTYMODE(IXON,  c_iflag, 38)
+TTYMODE(IXANY, c_iflag, 39)
+TTYMODE(IXOFF, c_iflag, 40)
+#ifdef IMAXBEL
+TTYMODE(IMAXBEL,c_iflag, 41)
+#endif /* IMAXBEL */
+
+TTYMODE(ISIG,  c_lflag, 50)
+TTYMODE(ICANON,        c_lflag, 51)
+#ifdef XCASE
+TTYMODE(XCASE, c_lflag, 52)
+#endif
+TTYMODE(ECHO,  c_lflag, 53)
+TTYMODE(ECHOE, c_lflag, 54)
+TTYMODE(ECHOK, c_lflag, 55)
+TTYMODE(ECHONL,        c_lflag, 56)
+TTYMODE(NOFLSH,        c_lflag, 57)
+TTYMODE(TOSTOP,        c_lflag, 58)
+#ifdef IEXTEN
+TTYMODE(IEXTEN, c_lflag, 59)
+#endif /* IEXTEN */
+#if defined(ECHOCTL)
+TTYMODE(ECHOCTL,c_lflag, 60)
+#endif /* ECHOCTL */
+#ifdef ECHOKE
+TTYMODE(ECHOKE,        c_lflag, 61)
+#endif /* ECHOKE */
+#if defined(PENDIN)
+TTYMODE(PENDIN,        c_lflag, 62)
+#endif /* PENDIN */
+
+TTYMODE(OPOST, c_oflag, 70)
+#if defined(OLCUC)
+TTYMODE(OLCUC, c_oflag, 71)
+#endif
+#ifdef ONLCR
+TTYMODE(ONLCR, c_oflag, 72)
+#endif
+#ifdef OCRNL
+TTYMODE(OCRNL, c_oflag, 73)
+#endif
+#ifdef ONOCR
+TTYMODE(ONOCR, c_oflag, 74)
+#endif
+#ifdef ONLRET
+TTYMODE(ONLRET,        c_oflag, 75)
+#endif
+
+TTYMODE(CS7,   c_cflag, 90)
+TTYMODE(CS8,   c_cflag, 91)
+TTYMODE(PARENB,        c_cflag, 92)
+TTYMODE(PARODD,        c_cflag, 93)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]