annotate cli-chansession.c @ 296:6b41e2cbf071 dbclient-netcat-alike

A hack to make dbclient to tcp forwarding netcat style. eg ./dbclient -i testkey -L 1234:remotehost:remoteport tunnelhost will ssh to tunnelhost (using testkey, there's no way to ask for a password) and then tcpfwd to remotehost:remoteport on stdin/stdout. There's no way to give a cmdline password, so -i for a keyfile will have to do. Yet another reason for agent forwarding. The 1234 is a dummy var, I think it has to be a valid portnumber though.
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Mar 2006 16:16:41 +0000
parents 84925eceeb13
children d4f32c3443ac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
74
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
1 /*
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
2 * Dropbear SSH
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
3 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
4 * Copyright (c) 2002,2003 Matt Johnston
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
5 * Copyright (c) 2004 by Mihnea Stoenescu
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
6 * All rights reserved.
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
7 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
9 * of this software and associated documentation files (the "Software"), to deal
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
10 * in the Software without restriction, including without limitation the rights
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
12 * copies of the Software, and to permit persons to whom the Software is
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
13 * furnished to do so, subject to the following conditions:
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
14 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
15 * The above copyright notice and this permission notice shall be included in
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
16 * all copies or substantial portions of the Software.
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
17 *
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
24 * SOFTWARE. */
e3adf4cf5465 License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents: 61
diff changeset
25
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 #include "includes.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 #include "packet.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 #include "buffer.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 #include "session.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 #include "dbutil.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 #include "channel.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 #include "ssh.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 #include "runopts.h"
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
34 #include "termcodes.h"
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
35 #include "chansession.h"
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
36
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37 static void cli_closechansess(struct Channel *channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 static int cli_initchansess(struct Channel *channel);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
39 static void cli_chansessreq(struct Channel *channel);
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 static void start_channel_request(struct Channel *channel, unsigned char *type);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 static void send_chansess_pty_req(struct Channel *channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 static void send_chansess_shell_req(struct Channel *channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 static void cli_tty_setup();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47
107
Matt Johnston <matt@ucc.asn.au>
parents: 99
diff changeset
48 const struct ChanType clichansess = {
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 0, /* sepfds */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 "session", /* name */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 cli_initchansess, /* inithandler */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52 NULL, /* checkclosehandler */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
53 cli_chansessreq, /* reqhandler */
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 cli_closechansess, /* closehandler */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 };
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
57 static void cli_chansessreq(struct Channel *channel) {
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
58
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
59 unsigned char* type = NULL;
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
60 int wantreply;
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
61
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
62 TRACE(("enter cli_chansessreq"))
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
63
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
64 type = buf_getstring(ses.payload, NULL);
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
65 wantreply = buf_getbool(ses.payload);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
66
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
67 if (strcmp(type, "exit-status") != 0) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
68 TRACE(("unknown request '%s'", type))
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
69 send_msg_channel_failure(channel);
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
70 goto out;
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
71 }
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
72
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
73 /* We'll just trust what they tell us */
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
74 cli_ses.retval = buf_getint(ses.payload);
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
75 TRACE(("got exit-status of '%d'", cli_ses.retval))
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
76
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
77 out:
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
78 m_free(type);
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
79 }
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
80
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
81
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 /* If the main session goes, we close it up */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
83 static void cli_closechansess(struct Channel *UNUSED(channel)) {
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 /* This channel hasn't gone yet, so we have > 1 */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 if (ses.chancount > 1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 dropbear_log(LOG_INFO, "Waiting for other channels to close...");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 cli_tty_cleanup(); /* Restore tty modes etc */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94 static void start_channel_request(struct Channel *channel,
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 unsigned char *type) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 CHECKCLEARTOWRITE();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 buf_putint(ses.writepayload, channel->remotechan);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 buf_putstring(ses.writepayload, type, strlen(type));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 /* Taken from OpenSSH's sshtty.c:
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 * RCSID("OpenBSD: sshtty.c,v 1.5 2003/09/19 17:43:35 markus Exp "); */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107 static void cli_tty_setup() {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 struct termios tio;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
111 TRACE(("enter cli_pty_setup"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 if (cli_ses.tty_raw_mode == 1) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
114 TRACE(("leave cli_tty_setup: already in raw mode!"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 return;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 if (tcgetattr(STDIN_FILENO, &tio) == -1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 dropbear_exit("Failed to set raw TTY mode");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 /* make a copy */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 cli_ses.saved_tio = tio;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 tio.c_iflag |= IGNPAR;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 #ifdef IUCLC
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 tio.c_iflag &= ~IUCLC;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 #endif
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 #ifdef IEXTEN
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 tio.c_lflag &= ~IEXTEN;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 #endif
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 tio.c_oflag &= ~OPOST;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 tio.c_cc[VMIN] = 1;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 tio.c_cc[VTIME] = 0;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 if (tcsetattr(STDIN_FILENO, TCSADRAIN, &tio) == -1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 dropbear_exit("Failed to set raw TTY mode");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 cli_ses.tty_raw_mode = 1;
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
142 TRACE(("leave cli_tty_setup"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
145 void cli_tty_cleanup() {
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
147 TRACE(("enter cli_tty_cleanup"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 if (cli_ses.tty_raw_mode == 0) {
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
150 TRACE(("leave cli_tty_cleanup: not in raw mode"))
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
151 return;
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154 if (tcsetattr(STDIN_FILENO, TCSADRAIN, &cli_ses.saved_tio) == -1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 dropbear_log(LOG_WARNING, "Failed restoring TTY");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 } else {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 cli_ses.tty_raw_mode = 0;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
160 TRACE(("leave cli_tty_cleanup"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
163 static void put_termcodes() {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
164
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
165 TRACE(("enter put_termcodes"))
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
166
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
167 struct termios tio;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
168 unsigned int sshcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
169 const struct TermCode *termcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
170 unsigned int value;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
171 unsigned int mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
172
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
173 unsigned int bufpos1, bufpos2;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
174
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
175 if (tcgetattr(STDIN_FILENO, &tio) == -1) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
176 dropbear_log(LOG_WARNING, "Failed reading termmodes");
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
177 buf_putint(ses.writepayload, 1); /* Just the terminator */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
178 buf_putbyte(ses.writepayload, 0); /* TTY_OP_END */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
179 return;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
180 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
181
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
182 bufpos1 = ses.writepayload->pos;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
183 buf_putint(ses.writepayload, 0); /* A placeholder for the final length */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
184
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
185 /* As with Dropbear server, we ignore baud rates for now */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
186 for (sshcode = 1; sshcode < MAX_TERMCODE; sshcode++) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
187
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
188 termcode = &termcodes[sshcode];
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
189 mapcode = termcode->mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
190
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
191 switch (termcode->type) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
192
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
193 case TERMCODE_NONE:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
194 continue;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
195
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
196 case TERMCODE_CONTROLCHAR:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
197 value = tio.c_cc[mapcode];
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
198 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
199
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
200 case TERMCODE_INPUT:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
201 value = tio.c_iflag & mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
202 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
203
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
204 case TERMCODE_OUTPUT:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
205 value = tio.c_oflag & mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
206 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
207
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
208 case TERMCODE_LOCAL:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
209 value = tio.c_lflag & mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
210 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
211
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
212 case TERMCODE_CONTROL:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
213 value = tio.c_cflag & mapcode;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
214 break;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
215
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
216 default:
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
217 continue;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
218
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
219 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
220
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
221 /* If we reach here, we have something to say */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
222 buf_putbyte(ses.writepayload, sshcode);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
223 buf_putint(ses.writepayload, value);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
224 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
225
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
226 buf_putbyte(ses.writepayload, 0); /* THE END, aka TTY_OP_END */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
227
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
228 /* Put the string length at the start of the buffer */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
229 bufpos2 = ses.writepayload->pos;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
230
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
231 buf_setpos(ses.writepayload, bufpos1); /* Jump back */
61
3a4f0ef1e8c3 Write the correct termcodes length
Matt Johnston <matt@ucc.asn.au>
parents: 41
diff changeset
232 buf_putint(ses.writepayload, bufpos2 - bufpos1 - 4); /* len(termcodes) */
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
233 buf_setpos(ses.writepayload, bufpos2); /* Back where we were */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
234
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
235 TRACE(("leave put_termcodes"))
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
236 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
237
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
238 static void put_winsize() {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
239
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
240 struct winsize ws;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
241
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
242 if (ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) < 0) {
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
243 /* Some sane defaults */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
244 ws.ws_row = 25;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
245 ws.ws_col = 80;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
246 ws.ws_xpixel = 0;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
247 ws.ws_ypixel = 0;
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
248 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
249
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
250 buf_putint(ses.writepayload, ws.ws_col); /* Cols */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
251 buf_putint(ses.writepayload, ws.ws_row); /* Rows */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
252 buf_putint(ses.writepayload, ws.ws_xpixel); /* Width */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
253 buf_putint(ses.writepayload, ws.ws_ypixel); /* Height */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
254
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
255 }
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
256
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
257 static void sigwinch_handler(int UNUSED(unused)) {
41
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
258
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
259 cli_ses.winchange = 1;
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
260
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
261 }
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
262
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
263 void cli_chansess_winchange() {
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
264
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
265 unsigned int i;
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
266 struct Channel *channel = NULL;
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
267
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
268 for (i = 0; i < ses.chansize; i++) {
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
269 channel = ses.channels[i];
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
270 if (channel != NULL && channel->type == &clichansess) {
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
271 CHECKCLEARTOWRITE();
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
272 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST);
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
273 buf_putint(ses.writepayload, channel->remotechan);
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
274 buf_putstring(ses.writepayload, "window-change", 13);
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
275 buf_putbyte(ses.writepayload, 0); /* FALSE says the spec */
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
276 put_winsize();
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
277 encrypt_packet();
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
278 }
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
279 }
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
280 cli_ses.winchange = 0;
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
281 }
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
282
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 static void send_chansess_pty_req(struct Channel *channel) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 unsigned char* term = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
287 TRACE(("enter send_chansess_pty_req"))
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
288
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 start_channel_request(channel, "pty-req");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
291 /* Don't want replies */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
292 buf_putbyte(ses.writepayload, 0);
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
293
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
294 /* Get the terminal */
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 term = getenv("TERM");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 if (term == NULL) {
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
297 term = "vt100"; /* Seems a safe default */
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
298 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299 buf_putstring(ses.writepayload, term, strlen(term));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300
40
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
301 /* Window size */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
302 put_winsize();
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
303
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
304 /* Terminal mode encoding */
b4874d772210 - Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents: 39
diff changeset
305 put_termcodes();
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307 encrypt_packet();
41
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
308
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
309 /* Set up a window-change handler */
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
310 if (signal(SIGWINCH, sigwinch_handler) == SIG_ERR) {
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
311 dropbear_exit("signal error");
18eccbfb9641 added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents: 40
diff changeset
312 }
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
313 TRACE(("leave send_chansess_pty_req"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
316 static void send_chansess_shell_req(struct Channel *channel) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
317
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
318 unsigned char* reqtype = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
319
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
320 TRACE(("enter send_chansess_shell_req"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
322 if (cli_opts.cmd) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
323 reqtype = "exec";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
324 } else {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 reqtype = "shell";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
326 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
327
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
328 start_channel_request(channel, reqtype);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
329
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
330 /* XXX TODO */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
331 buf_putbyte(ses.writepayload, 0); /* Don't want replies */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
332 if (cli_opts.cmd) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
333 buf_putstring(ses.writepayload, cli_opts.cmd, strlen(cli_opts.cmd));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
334 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
335
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
336 encrypt_packet();
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
337 TRACE(("leave send_chansess_shell_req"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
339
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
340 static int cli_initchansess(struct Channel *channel) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
341
93
5dda5a4d475c Don't leave the stdin FD non-blocking on exit - busybox doesn't like it.
Matt Johnston <matt@ucc.asn.au>
parents: 74
diff changeset
342
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
343 channel->writefd = STDOUT_FILENO;
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
344 setnonblocking(STDOUT_FILENO);
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
345
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
346 channel->readfd = STDIN_FILENO;
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
347 setnonblocking(STDIN_FILENO);
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
348
107
Matt Johnston <matt@ucc.asn.au>
parents: 99
diff changeset
349 channel->errfd = STDERR_FILENO;
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
350 setnonblocking(STDERR_FILENO);
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
351
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
352 channel->extrabuf = cbuf_new(RECV_MAXWINDOW);
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354 if (cli_opts.wantpty) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355 send_chansess_pty_req(channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358 send_chansess_shell_req(channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
360 if (cli_opts.wantpty) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361 cli_tty_setup();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
362 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
364 return 0; /* Success */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
365
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
366 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
367
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
368 void cli_send_chansess_request() {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369
296
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
370 unsigned int port = 0;
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
371 unsigned char* addr = NULL;
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
372 unsigned char* ipstring = "127.0.0.1";
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
373 unsigned char* portstring = "22";
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
374
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
375 /* hack hack */
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
376 static const struct ChanType cli_chan_tcphack = {
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
377 0, /* sepfds */
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
378 "direct-tcpip",
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
379 NULL,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
380 NULL,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
381 NULL,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
382 cli_closechansess
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
383 };
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
384
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
385 TRACE(("enter cli_send_chansess_request"))
296
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
386 if (send_msg_channel_open_init(STDIN_FILENO, &cli_chan_tcphack)
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
387 == DROPBEAR_FAILURE) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 dropbear_exit("Couldn't open initial channel");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390
296
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
391 if (cli_opts.localfwds == NULL) {
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
392 dropbear_exit("You need to give a \"-L ignored:host:port\" option with this hacked up dbclient.");
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
393 }
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
394
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
395 addr = cli_opts.localfwds->connectaddr;
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
396 port = cli_opts.localfwds->connectport;
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
397
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
398 buf_putstring(ses.writepayload, addr, strlen(addr));
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
399 buf_putint(ses.writepayload, port);
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
400
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
401 /* originator ip */
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
402 buf_putstring(ses.writepayload, ipstring, strlen(ipstring));
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
403 /* originator port */
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
404 buf_putint(ses.writepayload, atol(portstring));
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
405
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 encrypt_packet();
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
407 TRACE(("leave cli_send_chansess_request"))
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
408
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409 }
296
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
410
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
411 #if 0
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
412 while (cli_opts.localfwds != NULL) {
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
413 ret = cli_localtcp(cli_opts.localfwds->listenport,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
414 cli_opts.localfwds->connectaddr,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
415 cli_opts.localfwds->connectport);
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
416 if (ret == DROPBEAR_FAILURE) {
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
417 dropbear_log(LOG_WARNING, "Failed local port forward %d:%s:%d",
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
418 cli_opts.localfwds->listenport,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
419 cli_opts.localfwds->connectaddr,
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
420 cli_opts.localfwds->connectport);
6b41e2cbf071 A hack to make dbclient to tcp forwarding netcat style.
Matt Johnston <matt@ucc.asn.au>
parents: 253
diff changeset
421 #endif