Source-Changes-HG archive

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

[src/netbsd-1-5]: src/crypto/dist/ssh Pullup 1.2 [itojun]:



details:   https://anonhg.NetBSD.org/src/rev/9c67435c4072
branches:  netbsd-1-5
changeset: 490222:9c67435c4072
user:      tv <tv%NetBSD.org@localhost>
date:      Tue Nov 14 03:30:00 2000 +0000

description:
Pullup 1.2 [itojun]:
correct validation on X11 forwarding.  from markus@openbsd

diffstat:

 crypto/dist/ssh/clientloop.c |  1192 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 1192 insertions(+), 0 deletions(-)

diffs (truncated from 1196 to 300 lines):

diff -r e66d138de4d5 -r 9c67435c4072 crypto/dist/ssh/clientloop.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/crypto/dist/ssh/clientloop.c      Tue Nov 14 03:30:00 2000 +0000
@@ -0,0 +1,1192 @@
+/*     $NetBSD: clientloop.c,v 1.1.1.1.2.2 2000/11/14 03:30:00 tv Exp $        */
+
+/*
+ * Author: Tatu Ylonen <ylo%cs.hut.fi@localhost>
+ * Copyright (c) 1995 Tatu Ylonen <ylo%cs.hut.fi@localhost>, Espoo, Finland
+ *                    All rights reserved
+ * The main loop for the interactive session (client side).
+ *
+ * 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".
+ *
+ *
+ * Copyright (c) 1999 Theo de Raadt.  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.
+ *
+ *
+ * SSH2 support added by Markus Friedl.
+ * Copyright (c) 1999,2000 Markus Friedl.  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.
+ */
+
+/* from OpenBSD: clientloop.c,v 1.37 2000/09/26 19:59:58 markus Exp */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: clientloop.c,v 1.1.1.1.2.2 2000/11/14 03:30:00 tv Exp $");
+#endif
+
+#include "includes.h"
+
+#include "xmalloc.h"
+#include "ssh.h"
+#include "packet.h"
+#include "buffer.h"
+#include "readconf.h"
+
+#include "ssh2.h"
+#include "compat.h"
+#include "channels.h"
+#include "dispatch.h"
+
+#include "client.h"
+
+#include "buffer.h"
+#include "bufaux.h"
+
+extern Options options;
+
+/* Flag indicating that stdin should be redirected from /dev/null. */
+extern int stdin_null_flag;
+
+/*
+ * Name of the host we are connecting to.  This is the name given on the
+ * command line, or the HostName specified for the user-supplied name in a
+ * configuration file.
+ */
+extern char *host;
+
+/*
+ * Flag to indicate that we have received a window change signal which has
+ * not yet been processed.  This will cause a message indicating the new
+ * window size to be sent to the server a little later.  This is volatile
+ * because this is updated in a signal handler.
+ */
+static volatile int received_window_change_signal = 0;
+
+/* Terminal modes, as saved by enter_raw_mode. */
+static struct termios saved_tio;
+
+/*
+ * Flag indicating whether we are in raw mode.  This is used by
+ * enter_raw_mode and leave_raw_mode.
+ */
+static int in_raw_mode = 0;
+
+/* Flag indicating whether the user\'s terminal is in non-blocking mode. */
+static int in_non_blocking_mode = 0;
+
+/* Common data for the client loop code. */
+static int quit_pending;       /* Set to non-zero to quit the client loop. */
+static int escape_char;                /* Escape character. */
+static int escape_pending;     /* Last character was the escape character */
+static int last_was_cr;                /* Last character was a newline. */
+static int exit_status;                /* Used to store the exit status of the command. */
+static int stdin_eof;          /* EOF has been encountered on standard error. */
+static Buffer stdin_buffer;    /* Buffer for stdin data. */
+static Buffer stdout_buffer;   /* Buffer for stdout data. */
+static Buffer stderr_buffer;   /* Buffer for stderr data. */
+static unsigned long stdin_bytes, stdout_bytes, stderr_bytes;
+static unsigned int buffer_high;/* Soft max buffer size. */
+static int max_fd;             /* Maximum file descriptor number in select(). */
+static int connection_in;      /* Connection to server (input). */
+static int connection_out;     /* Connection to server (output). */
+
+
+void   client_init_dispatch(void);
+int    session_ident = -1;
+
+/* Returns the user\'s terminal to normal mode if it had been put in raw mode. */
+
+static void
+leave_raw_mode(void)
+{
+       if (!in_raw_mode)
+               return;
+       in_raw_mode = 0;
+       if (tcsetattr(fileno(stdin), TCSADRAIN, &saved_tio) < 0)
+               perror("tcsetattr");
+
+       fatal_remove_cleanup((void (*) (void *)) leave_raw_mode, NULL);
+}
+
+/* Puts the user\'s terminal in raw mode. */
+
+static void
+enter_raw_mode(void)
+{
+       struct termios tio;
+
+       if (tcgetattr(fileno(stdin), &tio) < 0)
+               perror("tcgetattr");
+       saved_tio = tio;
+       tio.c_iflag |= IGNPAR;
+       tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
+       tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
+#ifdef IEXTEN
+       tio.c_lflag &= ~IEXTEN;
+#endif                         /* IEXTEN */
+       tio.c_oflag &= ~OPOST;
+       tio.c_cc[VMIN] = 1;
+       tio.c_cc[VTIME] = 0;
+       if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) < 0)
+               perror("tcsetattr");
+       in_raw_mode = 1;
+
+       fatal_add_cleanup((void (*) (void *)) leave_raw_mode, NULL);
+}
+
+/* Restores stdin to blocking mode. */
+
+static void
+leave_non_blocking(void)
+{
+       if (in_non_blocking_mode) {
+               (void) fcntl(fileno(stdin), F_SETFL, 0);
+               in_non_blocking_mode = 0;
+               fatal_remove_cleanup((void (*) (void *)) leave_non_blocking, NULL);
+       }
+}
+
+/* Puts stdin terminal in non-blocking mode. */
+
+static void
+enter_non_blocking(void)
+{
+       in_non_blocking_mode = 1;
+       (void) fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
+       fatal_add_cleanup((void (*) (void *)) leave_non_blocking, NULL);
+}
+
+/*
+ * Signal handler for the window change signal (SIGWINCH).  This just sets a
+ * flag indicating that the window has changed.
+ */
+
+static void
+window_change_handler(int sig)
+{
+       received_window_change_signal = 1;
+       signal(SIGWINCH, window_change_handler);
+}
+
+/*
+ * Signal handler for signals that cause the program to terminate.  These
+ * signals must be trapped to restore terminal modes.
+ */
+
+static void
+signal_handler(int sig)
+{
+       if (in_raw_mode)
+               leave_raw_mode();
+       if (in_non_blocking_mode)
+               leave_non_blocking();
+       channel_stop_listening();
+       packet_close();
+       fatal("Killed by signal %d.", sig);
+}
+
+/*
+ * Returns current time in seconds from Jan 1, 1970 with the maximum
+ * available resolution.
+ */
+
+static double
+get_current_time(void)
+{
+       struct timeval tv;
+       gettimeofday(&tv, NULL);
+       return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
+}
+
+/*
+ * This is called when the interactive is entered.  This checks if there is
+ * an EOF coming on stdin.  We must check this explicitly, as select() does
+ * not appear to wake up when redirecting from /dev/null.
+ */
+
+static void
+client_check_initial_eof_on_stdin(void)
+{
+       int len;
+       char buf[1];
+
+       /*
+        * If standard input is to be "redirected from /dev/null", we simply
+        * mark that we have seen an EOF and send an EOF message to the
+        * server. Otherwise, we try to read a single character; it appears
+        * that for some files, such /dev/null, select() never wakes up for
+        * read for this descriptor, which means that we never get EOF.  This
+        * way we will get the EOF if stdin comes from /dev/null or similar.
+        */
+       if (stdin_null_flag) {
+               /* Fake EOF on stdin. */
+               debug("Sending eof.");
+               stdin_eof = 1;
+               packet_start(SSH_CMSG_EOF);
+               packet_send();
+       } else {
+               enter_non_blocking();
+
+               /* Check for immediate EOF on stdin. */
+               len = read(fileno(stdin), buf, 1);
+               if (len == 0) {
+                       /* EOF.  Record that we have seen it and send EOF to server. */
+                       debug("Sending eof.");
+                       stdin_eof = 1;
+                       packet_start(SSH_CMSG_EOF);
+                       packet_send();
+               } else if (len > 0) {
+                       /*
+                        * Got data.  We must store the data in the buffer,
+                        * and also process it as an escape character if
+                        * appropriate.
+                        */
+                       if ((unsigned char) buf[0] == escape_char)
+                               escape_pending = 1;
+                       else {
+                               buffer_append(&stdin_buffer, buf, 1);
+                               stdin_bytes += 1;
+                       }
+               }
+               leave_non_blocking();
+       }
+}



Home | Main Index | Thread Index | Old Index