clientloop.c (113908) | clientloop.c (124208) |
---|---|
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" | 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 $"); | 62RCSID("$OpenBSD: clientloop.c,v 1.112 2003/06/28 16:23:06 deraadt 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) | 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)); | 398 atomicio(vwrite, fileno(stdout), buffer_ptr(bout), buffer_len(bout)); |
399 if (buffer_len(berr) > 0) | 399 if (buffer_len(berr) > 0) |
400 atomicio(write, fileno(stderr), buffer_ptr(berr), buffer_len(berr)); | 400 atomicio(vwrite, 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')) { | 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."); | 493 logit("Invalid command."); |
494 goto out; 495 } 496 if (s[1] == 'L') 497 local = 1; 498 if (!local && !compat20) { | 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."); | 499 logit("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) { | 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."); | 510 logit("Bad forwarding specification."); |
511 goto out; 512 } 513 if ((fwd_port = a2port(sfwd_port)) == 0 || 514 (fwd_host_port = a2port(sfwd_host_port)) == 0) { | 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)."); | 515 logit("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) { | 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."); | 521 logit("Port forwarding failed."); |
522 goto out; 523 } 524 } else 525 channel_request_remote_forwarding(fwd_port, buf, 526 fwd_host_port); | 522 goto out; 523 } 524 } else 525 channel_request_remote_forwarding(fwd_port, buf, 526 fwd_host_port); |
527 log("Forwarding port."); | 527 logit("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 | 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 'B': 578 if (compat20) { 579 snprintf(string, sizeof string, 580 "%cB\r\n", escape_char); 581 buffer_append(berr, string, 582 strlen(string)); 583 channel_request_start(session_ident, 584 "break", 0); 585 packet_put_int(1000); 586 packet_send(); 587 } 588 continue; 589 |
|
577 case 'R': 578 if (compat20) { 579 if (datafellows & SSH_BUG_NOREKEY) | 590 case 'R': 591 if (compat20) { 592 if (datafellows & SSH_BUG_NOREKEY) |
580 log("Server does not support re-keying"); | 593 logit("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\ | 594 else 595 need_rekeying = 1; 596 } 597 continue; 598 599 case '&': 600 /* 601 * Detach the program (continue to serve connections, --- 42 unchanged lines hidden (view full) --- 644 } 645 continue; 646 647 case '?': 648 snprintf(string, sizeof string, 649"%c?\r\n\ 650Supported escape sequences:\r\n\ 651%c. - terminate connection\r\n\ |
652%cB - send a BREAK to the remote system\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, | 653%cC - open a command line\r\n\ 654%cR - Request rekey (SSH protocol 2 only)\r\n\ 655%c^Z - suspend ssh\r\n\ 656%c# - list forwarded connections\r\n\ 657%c& - background ssh (when waiting for connections to terminate)\r\n\ 658%c? - this message\r\n\ 659%c%c - send the escape character by typing it twice\r\n\ 660(Note that escapes are only recognized immediately after newline.)\r\n", 661 escape_char, escape_char, escape_char, escape_char, 662 escape_char, escape_char, escape_char, escape_char, |
649 escape_char, escape_char); | 663 escape_char, 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); | 664 buffer_append(berr, string, strlen(string)); 665 continue; 666 667 case '#': 668 snprintf(string, sizeof string, "%c#\r\n", escape_char); 669 buffer_append(berr, string, strlen(string)); 670 s = channel_open_message(); 671 buffer_append(berr, s, strlen(s)); --- 305 unchanged lines hidden (view full) --- 977 &max_fd2, &nalloc, rekeying); 978 979 if (quit_pending) 980 break; 981 982 /* Do channel operations unless rekeying in progress. */ 983 if (!rekeying) { 984 channel_after_select(readset, writeset); |
971 972 if (need_rekeying) { 973 debug("user requests rekeying"); | 985 if (need_rekeying || packet_need_rekeying()) { 986 debug("need 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, | 987 xxx_kex->done = 0; 988 kex_send_kexinit(xxx_kex); 989 need_rekeying = 0; 990 } 991 } 992 993 /* Buffer input from the connection. */ 994 client_process_net_input(readset); --- 159 unchanged lines hidden (view full) --- 1154 if (sock < 0) { 1155 xfree(originator_address); 1156 xfree(listen_address); 1157 return NULL; 1158 } 1159 c = channel_new("forwarded-tcpip", 1160 SSH_CHANNEL_CONNECTING, sock, sock, -1, 1161 CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0, |
1149 xstrdup(originator_address), 1); | 1162 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, | 1163 xfree(originator_address); 1164 xfree(listen_address); 1165 return c; 1166} 1167 1168static Channel * 1169client_request_x11(const char *request_type, int rchan) 1170{ --- 19 unchanged lines hidden (view full) --- 1190 debug("client_request_x11: request from %s %d", originator, 1191 originator_port); 1192 xfree(originator); 1193 sock = x11_connect_display(); 1194 if (sock < 0) 1195 return NULL; 1196 c = channel_new("x11", 1197 SSH_CHANNEL_X11_OPEN, sock, sock, -1, |
1185 CHAN_TCP_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT, 0, 1186 xstrdup("x11"), 1); | 1198 CHAN_TCP_WINDOW_DEFAULT, CHAN_X11_PACKET_DEFAULT, 0, "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, | 1199 c->force_drain = 1; 1200 return c; 1201} 1202 1203static Channel * 1204client_request_agent(const char *request_type, int rchan) 1205{ 1206 Channel *c = NULL; --- 5 unchanged lines hidden (view full) --- 1212 return NULL; 1213 } 1214 sock = ssh_get_authentication_socket(); 1215 if (sock < 0) 1216 return NULL; 1217 c = channel_new("authentication agent connection", 1218 SSH_CHANNEL_OPEN, sock, sock, -1, 1219 CHAN_X11_WINDOW_DEFAULT, CHAN_TCP_WINDOW_DEFAULT, 0, |
1208 xstrdup("authentication agent connection"), 1); | 1220 "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 --- | 1221 c->force_drain = 1; 1222 return c; 1223} 1224 1225/* XXXX move to generic input handler */ 1226static void 1227client_input_channel_open(int type, u_int32_t seq, void *ctxt) 1228{ --- 161 unchanged lines hidden --- |