Deleted Added
sdiff udiff text old ( 113908 ) new ( 124208 )
full compact
1/*
2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved
5 * The main loop for the interactive session (client side).
6 *
7 * As far as I am concerned, the code I have written for this software
8 * can be used freely for any purpose. Any derived versions of this

--- 45 unchanged lines hidden (view full) ---

54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 */
60
61#include "includes.h"
62RCSID("$OpenBSD: clientloop.c,v 1.107 2003/04/01 10:22:21 markus Exp $");
63
64#include "ssh.h"
65#include "ssh1.h"
66#include "ssh2.h"
67#include "xmalloc.h"
68#include "packet.h"
69#include "buffer.h"
70#include "compat.h"

--- 319 unchanged lines hidden (view full) ---

390
391static void
392client_suspend_self(Buffer *bin, Buffer *bout, Buffer *berr)
393{
394 struct winsize oldws, newws;
395
396 /* Flush stdout and stderr buffers. */
397 if (buffer_len(bout) > 0)
398 atomicio(write, fileno(stdout), buffer_ptr(bout), buffer_len(bout));
399 if (buffer_len(berr) > 0)
400 atomicio(write, fileno(stderr), buffer_ptr(berr), buffer_len(berr));
401
402 leave_raw_mode();
403
404 /*
405 * Free (and clear) the buffer to reduce the amount of data that gets
406 * written to swap.
407 */
408 buffer_free(bin);

--- 76 unchanged lines hidden (view full) ---

485 cmd = s = read_passphrase("\r\nssh> ", RP_ECHO);
486 if (s == NULL)
487 goto out;
488 while (*s && isspace(*s))
489 s++;
490 if (*s == 0)
491 goto out;
492 if (strlen(s) < 2 || s[0] != '-' || !(s[1] == 'L' || s[1] == 'R')) {
493 log("Invalid command.");
494 goto out;
495 }
496 if (s[1] == 'L')
497 local = 1;
498 if (!local && !compat20) {
499 log("Not supported for SSH protocol version 1.");
500 goto out;
501 }
502 s += 2;
503 while (*s && isspace(*s))
504 s++;
505
506 if (sscanf(s, "%5[0-9]:%255[^:]:%5[0-9]",
507 sfwd_port, buf, sfwd_host_port) != 3 &&
508 sscanf(s, "%5[0-9]/%255[^/]/%5[0-9]",
509 sfwd_port, buf, sfwd_host_port) != 3) {
510 log("Bad forwarding specification.");
511 goto out;
512 }
513 if ((fwd_port = a2port(sfwd_port)) == 0 ||
514 (fwd_host_port = a2port(sfwd_host_port)) == 0) {
515 log("Bad forwarding port(s).");
516 goto out;
517 }
518 if (local) {
519 if (channel_setup_local_fwd_listener(fwd_port, buf,
520 fwd_host_port, options.gateway_ports) < 0) {
521 log("Port forwarding failed.");
522 goto out;
523 }
524 } else
525 channel_request_remote_forwarding(fwd_port, buf,
526 fwd_host_port);
527 log("Forwarding port.");
528out:
529 signal(SIGINT, handler);
530 enter_raw_mode();
531 if (cmd)
532 xfree(cmd);
533}
534
535/* process the characters one by one */

--- 33 unchanged lines hidden (view full) ---

569 buffer_append(berr, string, strlen(string));
570
571 /* Restore terminal modes and suspend. */
572 client_suspend_self(bin, bout, berr);
573
574 /* We have been continued. */
575 continue;
576
577 case 'R':
578 if (compat20) {
579 if (datafellows & SSH_BUG_NOREKEY)
580 log("Server does not support re-keying");
581 else
582 need_rekeying = 1;
583 }
584 continue;
585
586 case '&':
587 /*
588 * Detach the program (continue to serve connections,

--- 42 unchanged lines hidden (view full) ---

631 }
632 continue;
633
634 case '?':
635 snprintf(string, sizeof string,
636"%c?\r\n\
637Supported escape sequences:\r\n\
638%c. - terminate connection\r\n\
639%cC - open a command line\r\n\
640%cR - Request rekey (SSH protocol 2 only)\r\n\
641%c^Z - suspend ssh\r\n\
642%c# - list forwarded connections\r\n\
643%c& - background ssh (when waiting for connections to terminate)\r\n\
644%c? - this message\r\n\
645%c%c - send the escape character by typing it twice\r\n\
646(Note that escapes are only recognized immediately after newline.)\r\n",
647 escape_char, escape_char, escape_char, escape_char,
648 escape_char, escape_char, escape_char, escape_char,
649 escape_char, escape_char);
650 buffer_append(berr, string, strlen(string));
651 continue;
652
653 case '#':
654 snprintf(string, sizeof string, "%c#\r\n", escape_char);
655 buffer_append(berr, string, strlen(string));
656 s = channel_open_message();
657 buffer_append(berr, s, strlen(s));

--- 305 unchanged lines hidden (view full) ---

963 &max_fd2, &nalloc, rekeying);
964
965 if (quit_pending)
966 break;
967
968 /* Do channel operations unless rekeying in progress. */
969 if (!rekeying) {
970 channel_after_select(readset, writeset);
971
972 if (need_rekeying) {
973 debug("user requests rekeying");
974 xxx_kex->done = 0;
975 kex_send_kexinit(xxx_kex);
976 need_rekeying = 0;
977 }
978 }
979
980 /* Buffer input from the connection. */
981 client_process_net_input(readset);

--- 159 unchanged lines hidden (view full) ---

1141 if (sock < 0) {
1142 xfree(originator_address);
1143 xfree(listen_address);
1144 return NULL;
1145 }
1146 c = channel_new("forwarded-tcpip",
1147 SSH_CHANNEL_CONNECTING, sock, sock, -1,
1148 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0,
1149 xstrdup(originator_address), 1);
1150 xfree(originator_address);
1151 xfree(listen_address);
1152 return c;
1153}
1154
1155static Channel *
1156client_request_x11(const char *request_type, int rchan)
1157{

--- 19 unchanged lines hidden (view full) ---

1177 debug("client_request_x11: request from %s %d", originator,
1178 originator_port);
1179 xfree(originator);
1180 sock = x11_connect_display();
1181 if (sock < 0)
1182 return NULL;
1183 c = channel_new("x11",
1184 SSH_CHANNEL_X11_OPEN, sock, sock, -1,
1185 CHAN_TCP_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT, 0,
1186 xstrdup("x11"), 1);
1187 c->force_drain = 1;
1188 return c;
1189}
1190
1191static Channel *
1192client_request_agent(const char *request_type, int rchan)
1193{
1194 Channel *c = NULL;

--- 5 unchanged lines hidden (view full) ---

1200 return NULL;
1201 }
1202 sock = ssh_get_authentication_socket();
1203 if (sock < 0)
1204 return NULL;
1205 c = channel_new("authentication agent connection",
1206 SSH_CHANNEL_OPEN, sock, sock, -1,
1207 CHAN_X11_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0,
1208 xstrdup("authentication agent connection"), 1);
1209 c->force_drain = 1;
1210 return c;
1211}
1212
1213/* XXXX move to generic input handler */
1214static void
1215client_input_channel_open(int type, u_int32_t seq, void *ctxt)
1216{

--- 161 unchanged lines hidden ---