5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
11 * Created: Sat Sep 23 12:23:57 1995 ylo
13 * The main loop for the interactive session (client side).
15 * SSH2 support added by Markus Friedl.
19 RCSID("$OpenBSD: clientloop.c,v 1.29 2000/07/16 08:27:21 markus Exp $");
32 /* Flag indicating that stdin should be redirected from /dev/null. */
33 extern int stdin_null_flag;
36 * Name of the host we are connecting to. This is the name given on the
37 * command line, or the HostName specified for the user-supplied name in a
43 * Flag to indicate that we have received a window change signal which has
44 * not yet been processed. This will cause a message indicating the new
45 * window size to be sent to the server a little later. This is volatile
46 * because this is updated in a signal handler.
48 static volatile int received_window_change_signal = 0;
50 /* Terminal modes, as saved by enter_raw_mode. */
51 static struct termios saved_tio;
54 * Flag indicating whether we are in raw mode. This is used by
55 * enter_raw_mode and leave_raw_mode.
57 static int in_raw_mode = 0;
59 /* Flag indicating whether the user\'s terminal is in non-blocking mode. */
60 static int in_non_blocking_mode = 0;
62 /* Common data for the client loop code. */
63 static int escape_pending; /* Last character was the escape character */
64 static int last_was_cr; /* Last character was a newline. */
65 static int exit_status; /* Used to store the exit status of the command. */
66 static int stdin_eof; /* EOF has been encountered on standard error. */
67 static Buffer stdin_buffer; /* Buffer for stdin data. */
68 static Buffer stdout_buffer; /* Buffer for stdout data. */
69 static Buffer stderr_buffer; /* Buffer for stderr data. */
70 static unsigned int buffer_high;/* Soft max buffer size. */
71 static int max_fd; /* Maximum file descriptor number in select(). */
72 static int connection_in; /* Connection to server (input). */
73 static int connection_out; /* Connection to server (output). */
74 static unsigned long stdin_bytes, stdout_bytes, stderr_bytes;
75 static int quit_pending; /* Set to non-zero to quit the client loop. */
76 static int escape_char; /* Escape character. */
79 void client_init_dispatch(void);
80 int session_ident = -1;
82 /* Returns the user\'s terminal to normal mode if it had been put in raw mode. */
90 if (tcsetattr(fileno(stdin), TCSADRAIN, &saved_tio) < 0)
93 fatal_remove_cleanup((void (*) (void *)) leave_raw_mode, NULL);
96 /* Puts the user\'s terminal in raw mode. */
103 if (tcgetattr(fileno(stdin), &tio) < 0)
106 tio.c_iflag |= IGNPAR;
107 tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
108 tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
110 tio.c_lflag &= ~IEXTEN;
112 tio.c_oflag &= ~OPOST;
115 if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) < 0)
119 fatal_add_cleanup((void (*) (void *)) leave_raw_mode, NULL);
122 /* Restores stdin to blocking mode. */
127 if (in_non_blocking_mode) {
128 (void) fcntl(fileno(stdin), F_SETFL, 0);
129 in_non_blocking_mode = 0;
130 fatal_remove_cleanup((void (*) (void *)) leave_non_blocking, NULL);
134 /* Puts stdin terminal in non-blocking mode. */
139 in_non_blocking_mode = 1;
140 (void) fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
141 fatal_add_cleanup((void (*) (void *)) leave_non_blocking, NULL);
145 * Signal handler for the window change signal (SIGWINCH). This just sets a
146 * flag indicating that the window has changed.
150 window_change_handler(int sig)
152 received_window_change_signal = 1;
153 signal(SIGWINCH, window_change_handler);
157 * Signal handler for signals that cause the program to terminate. These
158 * signals must be trapped to restore terminal modes.
162 signal_handler(int sig)
166 if (in_non_blocking_mode)
167 leave_non_blocking();
168 channel_stop_listening();
170 fatal("Killed by signal %d.", sig);
174 * Returns current time in seconds from Jan 1, 1970 with the maximum
175 * available resolution.
182 gettimeofday(&tv, NULL);
183 return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
187 * This is called when the interactive is entered. This checks if there is
188 * an EOF coming on stdin. We must check this explicitly, as select() does
189 * not appear to wake up when redirecting from /dev/null.
193 client_check_initial_eof_on_stdin()
199 * If standard input is to be "redirected from /dev/null", we simply
200 * mark that we have seen an EOF and send an EOF message to the
201 * server. Otherwise, we try to read a single character; it appears
202 * that for some files, such /dev/null, select() never wakes up for
203 * read for this descriptor, which means that we never get EOF. This
204 * way we will get the EOF if stdin comes from /dev/null or similar.
206 if (stdin_null_flag) {
207 /* Fake EOF on stdin. */
208 debug("Sending eof.");
210 packet_start(SSH_CMSG_EOF);
213 enter_non_blocking();
215 /* Check for immediate EOF on stdin. */
216 len = read(fileno(stdin), buf, 1);
218 /* EOF. Record that we have seen it and send EOF to server. */
219 debug("Sending eof.");
221 packet_start(SSH_CMSG_EOF);
223 } else if (len > 0) {
225 * Got data. We must store the data in the buffer,
226 * and also process it as an escape character if
229 if ((unsigned char) buf[0] == escape_char)
232 buffer_append(&stdin_buffer, buf, 1);
236 leave_non_blocking();
242 * Make packets from buffered stdin data, and buffer them for sending to the
247 client_make_packets_from_stdin_data()
251 /* Send buffered stdin data to the server. */
252 while (buffer_len(&stdin_buffer) > 0 &&
253 packet_not_very_much_data_to_write()) {
254 len = buffer_len(&stdin_buffer);
255 /* Keep the packets at reasonable size. */
256 if (len > packet_get_maxsize())
257 len = packet_get_maxsize();
258 packet_start(SSH_CMSG_STDIN_DATA);
259 packet_put_string(buffer_ptr(&stdin_buffer), len);
261 buffer_consume(&stdin_buffer, len);
262 /* If we have a pending EOF, send it now. */
263 if (stdin_eof && buffer_len(&stdin_buffer) == 0) {
264 packet_start(SSH_CMSG_EOF);
271 * Checks if the client window has changed, and sends a packet about it to
272 * the server if so. The actual change is detected elsewhere (by a software
273 * interrupt on Unix); this just checks the flag and sends a message if
278 client_check_window_change()
282 if (! received_window_change_signal)
285 received_window_change_signal = 0;
287 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0)
290 debug("client_check_window_change: changed");
293 channel_request_start(session_ident, "window-change", 0);
294 packet_put_int(ws.ws_col);
295 packet_put_int(ws.ws_row);
296 packet_put_int(ws.ws_xpixel);
297 packet_put_int(ws.ws_ypixel);
300 packet_start(SSH_CMSG_WINDOW_SIZE);
301 packet_put_int(ws.ws_row);
302 packet_put_int(ws.ws_col);
303 packet_put_int(ws.ws_xpixel);
304 packet_put_int(ws.ws_ypixel);
310 * Waits until the client can do something (some data becomes available on
311 * one of the file descriptors).
315 client_wait_until_can_do_something(fd_set * readset, fd_set * writeset)
317 /*debug("client_wait_until_can_do_something"); */
319 /* Initialize select masks. */
324 /* Read from the connection, unless our buffers are full. */
325 if (buffer_len(&stdout_buffer) < buffer_high &&
326 buffer_len(&stderr_buffer) < buffer_high &&
327 channel_not_very_much_buffered_data())
328 FD_SET(connection_in, readset);
330 * Read from stdin, unless we have seen EOF or have very much
331 * buffered data to send to the server.
333 if (!stdin_eof && packet_not_very_much_data_to_write())
334 FD_SET(fileno(stdin), readset);
336 /* Select stdout/stderr if have data in buffer. */
337 if (buffer_len(&stdout_buffer) > 0)
338 FD_SET(fileno(stdout), writeset);
339 if (buffer_len(&stderr_buffer) > 0)
340 FD_SET(fileno(stderr), writeset);
342 FD_SET(connection_in, readset);
345 /* Add any selections by the channel mechanism. */
346 channel_prepare_select(readset, writeset);
348 /* Select server connection if have data to write to the server. */
349 if (packet_have_data_to_write())
350 FD_SET(connection_out, writeset);
353 /* Update maximum file descriptor number, if appropriate. */
354 if (channel_max_fd() > max_fd)
355 max_fd = channel_max_fd();
358 * Wait for something to happen. This will suspend the process until
359 * some selected descriptor can be read, written, or has some other
360 * event pending. Note: if you want to implement SSH_MSG_IGNORE
361 * messages to fool traffic analysis, this might be the place to do
362 * it: just have a random timeout for the select, and send a random
363 * SSH_MSG_IGNORE packet when the timeout expires.
366 if (select(max_fd + 1, readset, writeset, NULL, NULL) < 0) {
368 /* Some systems fail to clear these automatically. */
373 /* Note: we might still have data in the buffers. */
374 snprintf(buf, sizeof buf, "select: %s\r\n", strerror(errno));
375 buffer_append(&stderr_buffer, buf, strlen(buf));
376 stderr_bytes += strlen(buf);
382 client_suspend_self()
384 struct winsize oldws, newws;
386 /* Flush stdout and stderr buffers. */
387 if (buffer_len(&stdout_buffer) > 0)
388 atomicio(write, fileno(stdout), buffer_ptr(&stdout_buffer),
389 buffer_len(&stdout_buffer));
390 if (buffer_len(&stderr_buffer) > 0)
391 atomicio(write, fileno(stderr), buffer_ptr(&stderr_buffer),
392 buffer_len(&stderr_buffer));
397 * Free (and clear) the buffer to reduce the amount of data that gets
400 buffer_free(&stdin_buffer);
401 buffer_free(&stdout_buffer);
402 buffer_free(&stderr_buffer);
404 /* Save old window size. */
405 ioctl(fileno(stdin), TIOCGWINSZ, &oldws);
407 /* Send the suspend signal to the program itself. */
408 kill(getpid(), SIGTSTP);
410 /* Check if the window size has changed. */
411 if (ioctl(fileno(stdin), TIOCGWINSZ, &newws) >= 0 &&
412 (oldws.ws_row != newws.ws_row ||
413 oldws.ws_col != newws.ws_col ||
414 oldws.ws_xpixel != newws.ws_xpixel ||
415 oldws.ws_ypixel != newws.ws_ypixel))
416 received_window_change_signal = 1;
418 /* OK, we have been continued by the user. Reinitialize buffers. */
419 buffer_init(&stdin_buffer);
420 buffer_init(&stdout_buffer);
421 buffer_init(&stderr_buffer);
427 client_process_net_input(fd_set * readset)
433 * Read input from the server, and add any such data to the buffer of
434 * the packet subsystem.
436 if (FD_ISSET(connection_in, readset)) {
437 /* Read as much as possible. */
438 len = read(connection_in, buf, sizeof(buf));
439 /*debug("read connection_in len %d", len); XXX */
441 /* Received EOF. The remote host has closed the connection. */
442 snprintf(buf, sizeof buf, "Connection to %.300s closed by remote host.\r\n",
444 buffer_append(&stderr_buffer, buf, strlen(buf));
445 stderr_bytes += strlen(buf);
450 * There is a kernel bug on Solaris that causes select to
451 * sometimes wake up even though there is no data available.
453 if (len < 0 && errno == EAGAIN)
457 /* An error has encountered. Perhaps there is a network problem. */
458 snprintf(buf, sizeof buf, "Read from remote host %.300s: %.100s\r\n",
459 host, strerror(errno));
460 buffer_append(&stderr_buffer, buf, strlen(buf));
461 stderr_bytes += strlen(buf);
465 packet_process_incoming(buf, len);
470 client_process_input(fd_set * readset)
476 /* Read input from stdin. */
477 if (FD_ISSET(fileno(stdin), readset)) {
478 /* Read as much as possible. */
479 len = read(fileno(stdin), buf, sizeof(buf));
482 * Received EOF or error. They are treated
483 * similarly, except that an error message is printed
484 * if it was an error condition.
487 snprintf(buf, sizeof buf, "read: %.100s\r\n", strerror(errno));
488 buffer_append(&stderr_buffer, buf, strlen(buf));
489 stderr_bytes += strlen(buf);
491 /* Mark that we have seen EOF. */
494 * Send an EOF message to the server unless there is
495 * data in the buffer. If there is data in the
496 * buffer, no message will be sent now. Code
497 * elsewhere will send the EOF when the buffer
498 * becomes empty if stdin_eof is set.
500 if (buffer_len(&stdin_buffer) == 0) {
501 packet_start(SSH_CMSG_EOF);
504 } else if (escape_char == -1) {
506 * Normal successful read, and no escape character.
507 * Just append the data to buffer.
509 buffer_append(&stdin_buffer, buf, len);
513 * Normal, successful read. But we have an escape character
514 * and have to process the characters one by one.
517 for (i = 0; i < len; i++) {
519 /* Get one character at a time. */
522 if (escape_pending) {
523 /* We have previously seen an escape character. */
524 /* Clear the flag now. */
526 /* Process the escaped character. */
529 /* Terminate the connection. */
530 snprintf(buf, sizeof buf, "%c.\r\n", escape_char);
531 buffer_append(&stderr_buffer, buf, strlen(buf));
532 stderr_bytes += strlen(buf);
537 /* Suspend the program. */
538 /* Print a message to that effect to the user. */
539 snprintf(buf, sizeof buf, "%c^Z\r\n", escape_char);
540 buffer_append(&stderr_buffer, buf, strlen(buf));
541 stderr_bytes += strlen(buf);
543 /* Restore terminal modes and suspend. */
544 client_suspend_self();
546 /* We have been continued. */
551 * Detach the program (continue to serve connections,
552 * but put in background and no more new connections).
556 * Sending SSH_CMSG_EOF alone does not always appear
557 * to be enough. So we try to send an EOF character
560 packet_start(SSH_CMSG_STDIN_DATA);
561 packet_put_string("\004", 1);
565 if (buffer_len(&stdin_buffer) == 0) {
566 packet_start(SSH_CMSG_EOF);
570 /* Restore tty modes. */
573 /* Stop listening for new connections. */
574 channel_stop_listening();
576 printf("%c& [backgrounded]\n", escape_char);
578 /* Fork into background. */
581 error("fork: %.100s", strerror(errno));
584 if (pid != 0) { /* This is the parent. */
585 /* The parent just exits. */
588 /* The child continues serving connections. */
592 snprintf(buf, sizeof buf,
594 Supported escape sequences:\r\n\
595 ~. - terminate connection\r\n\
596 ~^Z - suspend ssh\r\n\
597 ~# - list forwarded connections\r\n\
598 ~& - background ssh (when waiting for connections to terminate)\r\n\
599 ~? - this message\r\n\
600 ~~ - send the escape character by typing it twice\r\n\
601 (Note that escapes are only recognized immediately after newline.)\r\n",
603 buffer_append(&stderr_buffer, buf, strlen(buf));
607 snprintf(buf, sizeof buf, "%c#\r\n", escape_char);
608 buffer_append(&stderr_buffer, buf, strlen(buf));
609 s = channel_open_message();
610 buffer_append(&stderr_buffer, s, strlen(s));
615 if (ch != escape_char) {
617 * Escape character followed by non-special character.
618 * Append both to the input buffer.
620 buf[0] = escape_char;
622 buffer_append(&stdin_buffer, buf, 2);
627 * Note that escape character typed twice
628 * falls through here; the latter gets processed
629 * as a normal character below.
635 * The previous character was not an escape char. Check if this
638 if (last_was_cr && ch == escape_char) {
639 /* It is. Set the flag and continue to next character. */
646 * Normal character. Record whether it was a newline,
647 * and append it to the buffer.
649 last_was_cr = (ch == '\r' || ch == '\n');
651 buffer_append(&stdin_buffer, buf, 1);
660 client_process_output(fd_set * writeset)
665 /* Write buffered output to stdout. */
666 if (FD_ISSET(fileno(stdout), writeset)) {
667 /* Write as much data as possible. */
668 len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
669 buffer_len(&stdout_buffer));
675 * An error or EOF was encountered. Put an
676 * error message to stderr buffer.
678 snprintf(buf, sizeof buf, "write stdout: %.50s\r\n", strerror(errno));
679 buffer_append(&stderr_buffer, buf, strlen(buf));
680 stderr_bytes += strlen(buf);
685 /* Consume printed data from the buffer. */
686 buffer_consume(&stdout_buffer, len);
688 /* Write buffered output to stderr. */
689 if (FD_ISSET(fileno(stderr), writeset)) {
690 /* Write as much data as possible. */
691 len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
692 buffer_len(&stderr_buffer));
697 /* EOF or error, but can't even print error message. */
702 /* Consume printed characters from the buffer. */
703 buffer_consume(&stderr_buffer, len);
708 * Get packets from the connection input buffer, and process them as long as
709 * there are packets available.
711 * Any unknown packets received during the actual
712 * session cause the session to terminate. This is
713 * intended to make debugging easier since no
714 * confirmations are sent. Any compatible protocol
715 * extensions must be negotiated during the
720 client_process_buffered_input_packets()
722 dispatch_run(DISPATCH_NONBLOCK, &quit_pending);
726 * Implements the interactive session with the server. This is called after
727 * the user has been authenticated, and a command has been started on the
728 * remote host. If escape_char != -1, it is the character used as an escape
729 * character for terminating or suspending the session.
733 client_loop(int have_pty, int escape_char_arg)
735 extern Options options;
736 double start_time, total_time;
740 debug("Entering interactive session.");
742 start_time = get_current_time();
744 /* Initialize variables. */
749 buffer_high = 64 * 1024;
750 connection_in = packet_get_connection_in();
751 connection_out = packet_get_connection_out();
752 max_fd = connection_in;
753 if (connection_out > max_fd)
754 max_fd = connection_out;
759 escape_char = escape_char_arg;
761 /* Initialize buffers. */
762 buffer_init(&stdin_buffer);
763 buffer_init(&stdout_buffer);
764 buffer_init(&stderr_buffer);
766 client_init_dispatch();
768 /* Set signal handlers to restore non-blocking mode. */
769 signal(SIGINT, signal_handler);
770 signal(SIGQUIT, signal_handler);
771 signal(SIGTERM, signal_handler);
772 signal(SIGPIPE, SIG_IGN);
774 signal(SIGWINCH, window_change_handler);
779 /* Check if we should immediately send eof on stdin. */
781 client_check_initial_eof_on_stdin();
783 /* Main loop of the client for the interactive session mode. */
784 while (!quit_pending) {
785 fd_set readset, writeset;
787 /* Process buffered packets sent by the server. */
788 client_process_buffered_input_packets();
790 if (compat20 && !channel_still_open()) {
791 debug("!channel_still_open.");
796 * Make packets of buffered stdin data, and buffer them for
797 * sending to the server.
800 client_make_packets_from_stdin_data();
803 * Make packets from buffered channel data, and buffer them
804 * for sending to the server.
806 if (packet_not_very_much_data_to_write())
807 channel_output_poll();
810 * Check if the window size has changed, and buffer a message
811 * about it to the server if so.
813 client_check_window_change();
819 * Wait until we have something to do (something becomes
820 * available on one of the descriptors).
822 client_wait_until_can_do_something(&readset, &writeset);
827 /* Do channel operations. */
828 channel_after_select(&readset, &writeset);
830 /* Buffer input from the connection. */
831 client_process_net_input(&readset);
837 /* Buffer data from stdin */
838 client_process_input(&readset);
840 * Process output to stdout and stderr. Output to
841 * the connection is processed elsewhere (above).
843 client_process_output(&writeset);
846 /* Send as much buffered packet data as possible to the sender. */
847 if (FD_ISSET(connection_out, &writeset))
851 /* Terminate the session. */
853 /* Stop watching for window change. */
855 signal(SIGWINCH, SIG_DFL);
857 /* Stop listening for connections. */
858 channel_stop_listening();
861 * In interactive mode (with pseudo tty) display a message indicating
862 * that the connection has been closed.
864 if (have_pty && options.log_level != SYSLOG_LEVEL_QUIET) {
865 snprintf(buf, sizeof buf, "Connection to %.64s closed.\r\n", host);
866 buffer_append(&stderr_buffer, buf, strlen(buf));
867 stderr_bytes += strlen(buf);
869 /* Output any buffered data for stdout. */
870 while (buffer_len(&stdout_buffer) > 0) {
871 len = write(fileno(stdout), buffer_ptr(&stdout_buffer),
872 buffer_len(&stdout_buffer));
874 error("Write failed flushing stdout buffer.");
877 buffer_consume(&stdout_buffer, len);
880 /* Output any buffered data for stderr. */
881 while (buffer_len(&stderr_buffer) > 0) {
882 len = write(fileno(stderr), buffer_ptr(&stderr_buffer),
883 buffer_len(&stderr_buffer));
885 error("Write failed flushing stderr buffer.");
888 buffer_consume(&stderr_buffer, len);
894 /* Clear and free any buffers. */
895 memset(buf, 0, sizeof(buf));
896 buffer_free(&stdin_buffer);
897 buffer_free(&stdout_buffer);
898 buffer_free(&stderr_buffer);
900 /* Report bytes transferred, and transfer rates. */
901 total_time = get_current_time() - start_time;
902 debug("Transferred: stdin %lu, stdout %lu, stderr %lu bytes in %.1f seconds",
903 stdin_bytes, stdout_bytes, stderr_bytes, total_time);
905 debug("Bytes per second: stdin %.1f, stdout %.1f, stderr %.1f",
906 stdin_bytes / total_time, stdout_bytes / total_time,
907 stderr_bytes / total_time);
909 /* Return the exit status of the program. */
910 debug("Exit status %d", exit_status);
917 client_input_stdout_data(int type, int plen)
919 unsigned int data_len;
920 char *data = packet_get_string(&data_len);
921 packet_integrity_check(plen, 4 + data_len, type);
922 buffer_append(&stdout_buffer, data, data_len);
923 stdout_bytes += data_len;
924 memset(data, 0, data_len);
928 client_input_stderr_data(int type, int plen)
930 unsigned int data_len;
931 char *data = packet_get_string(&data_len);
932 packet_integrity_check(plen, 4 + data_len, type);
933 buffer_append(&stderr_buffer, data, data_len);
934 stdout_bytes += data_len;
935 memset(data, 0, data_len);
939 client_input_exit_status(int type, int plen)
941 packet_integrity_check(plen, 4, type);
942 exit_status = packet_get_int();
943 /* Acknowledge the exit. */
944 packet_start(SSH_CMSG_EXIT_CONFIRMATION);
947 * Must wait for packet to be sent since we are
951 /* Flag that we want to exit. */
955 /* XXXX move to generic input handler */
957 client_input_channel_open(int type, int plen)
967 ctype = packet_get_string(&len);
968 rchan = packet_get_int();
969 rwindow = packet_get_int();
970 rmaxpack = packet_get_int();
972 debug("client_input_channel_open: ctype %s rchan %d win %d max %d",
973 ctype, rchan, rwindow, rmaxpack);
975 if (strcmp(ctype, "x11") == 0) {
979 originator = packet_get_string(NULL);
980 if (datafellows & SSH_BUG_X11FWD) {
981 debug("buggy server: x11 request w/o originator_port");
984 originator_port = packet_get_int();
987 /* XXX check permission */
989 /* XXX move to channels.c */
990 sock = x11_connect_display();
992 id = channel_new("x11", SSH_CHANNEL_X11_OPEN,
993 sock, sock, -1, 4*1024, 32*1024, 0,
995 c = channel_lookup(id);
998 /* XXX duplicate : */
1000 debug("confirm %s", ctype);
1001 c->remote_id = rchan;
1002 c->remote_window = rwindow;
1003 c->remote_maxpacket = rmaxpack;
1005 packet_start(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION);
1006 packet_put_int(c->remote_id);
1007 packet_put_int(c->self);
1008 packet_put_int(c->local_window);
1009 packet_put_int(c->local_maxpacket);
1012 debug("failure %s", ctype);
1013 packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE);
1014 packet_put_int(rchan);
1015 packet_put_int(SSH2_OPEN_ADMINISTRATIVELY_PROHIBITED);
1016 packet_put_cstring("bla bla");
1017 packet_put_cstring("");
1024 client_init_dispatch_20()
1026 dispatch_init(&dispatch_protocol_error);
1027 dispatch_set(SSH2_MSG_CHANNEL_CLOSE, &channel_input_oclose);
1028 dispatch_set(SSH2_MSG_CHANNEL_DATA, &channel_input_data);
1029 dispatch_set(SSH2_MSG_CHANNEL_EOF, &channel_input_ieof);
1030 dispatch_set(SSH2_MSG_CHANNEL_EXTENDED_DATA, &channel_input_extended_data);
1031 dispatch_set(SSH2_MSG_CHANNEL_OPEN, &client_input_channel_open);
1032 dispatch_set(SSH2_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation);
1033 dispatch_set(SSH2_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure);
1034 dispatch_set(SSH2_MSG_CHANNEL_REQUEST, &channel_input_channel_request);
1035 dispatch_set(SSH2_MSG_CHANNEL_WINDOW_ADJUST, &channel_input_window_adjust);
1038 client_init_dispatch_13()
1040 dispatch_init(NULL);
1041 dispatch_set(SSH_MSG_CHANNEL_CLOSE, &channel_input_close);
1042 dispatch_set(SSH_MSG_CHANNEL_CLOSE_CONFIRMATION, &channel_input_close_confirmation);
1043 dispatch_set(SSH_MSG_CHANNEL_DATA, &channel_input_data);
1044 dispatch_set(SSH_MSG_CHANNEL_OPEN_CONFIRMATION, &channel_input_open_confirmation);
1045 dispatch_set(SSH_MSG_CHANNEL_OPEN_FAILURE, &channel_input_open_failure);
1046 dispatch_set(SSH_MSG_PORT_OPEN, &channel_input_port_open);
1047 dispatch_set(SSH_SMSG_AGENT_OPEN, &auth_input_open_request);
1048 dispatch_set(SSH_SMSG_EXITSTATUS, &client_input_exit_status);
1049 dispatch_set(SSH_SMSG_STDERR_DATA, &client_input_stderr_data);
1050 dispatch_set(SSH_SMSG_STDOUT_DATA, &client_input_stdout_data);
1051 dispatch_set(SSH_SMSG_X11_OPEN, &x11_input_open);
1054 client_init_dispatch_15()
1056 client_init_dispatch_13();
1057 dispatch_set(SSH_MSG_CHANNEL_CLOSE, &channel_input_ieof);
1058 dispatch_set(SSH_MSG_CHANNEL_CLOSE_CONFIRMATION, & channel_input_oclose);
1061 client_init_dispatch()
1064 client_init_dispatch_20();
1066 client_init_dispatch_13();
1068 client_init_dispatch_15();
1072 client_input_channel_req(int id, void *arg)
1080 rtype = packet_get_string(&len);
1081 reply = packet_get_char();
1083 debug("client_input_channel_req: rtype %s reply %d", rtype, reply);
1085 c = channel_lookup(id);
1087 fatal("session_input_channel_req: channel %d: bad channel", id);
1089 if (session_ident == -1) {
1090 error("client_input_channel_req: no channel %d", id);
1091 } else if (id != session_ident) {
1092 error("client_input_channel_req: bad channel %d != %d",
1094 } else if (strcmp(rtype, "exit-status") == 0) {
1096 exit_status = packet_get_int();
1100 packet_start(success ?
1101 SSH2_MSG_CHANNEL_SUCCESS : SSH2_MSG_CHANNEL_FAILURE);
1102 packet_put_int(c->remote_id);
1109 client_set_session_ident(int id)
1111 debug("client_set_session_ident: id %d", id);
1113 channel_register_callback(id, SSH2_MSG_CHANNEL_REQUEST,
1114 client_input_channel_req, (void *)0);