annotate cli-chansession.c @ 39:0883c0906870

tty raw mode support works mostly adding cli-{chansession,runopts}.c which were missing
author Matt Johnston <matt@ucc.asn.au>
date Fri, 30 Jul 2004 12:29:53 +0000
parents
children b4874d772210
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 #include "includes.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 #include "packet.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 #include "buffer.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
4 #include "session.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
5 #include "dbutil.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
6 #include "channel.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 #include "ssh.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 #include "runopts.h"
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 static void cli_closechansess(struct Channel *channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 static int cli_initchansess(struct Channel *channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 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
14
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 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
16 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
17
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18 static void cli_tty_setup();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 static void cli_tty_cleanup();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 static const struct ChanType clichansess = {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22 0, /* sepfds */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 "session", /* name */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 cli_initchansess, /* inithandler */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 NULL, /* checkclosehandler */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 NULL, /* reqhandler */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 cli_closechansess, /* closehandler */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 };
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
30 /* If the main session goes, we close it up */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 static void cli_closechansess(struct Channel *channel) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 /* 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
34 if (ses.chancount > 1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 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
36 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
37
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 cli_tty_cleanup(); /* Restore tty modes etc */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
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
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 static void start_channel_request(struct Channel *channel,
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 unsigned char *type) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 CHECKCLEARTOWRITE();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 buf_putint(ses.writepayload, channel->remotechan);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
48
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 buf_putstring(ses.writepayload, type, strlen(type));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
53
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
54 /* Taken from OpenSSH's sshtty.c:
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
55 * 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
56 static void cli_tty_setup() {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 struct termios tio;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 TRACE(("enter cli_pty_setup"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 if (cli_ses.tty_raw_mode == 1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 TRACE(("leave cli_tty_setup: already in raw mode!"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 return;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 if (tcgetattr(STDIN_FILENO, &tio) == -1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 dropbear_exit("Failed to set raw TTY mode");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 /* make a copy */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 cli_ses.saved_tio = tio;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74 tio.c_iflag |= IGNPAR;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 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
76 #ifdef IUCLC
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 tio.c_iflag &= ~IUCLC;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 #endif
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 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
80 #ifdef IEXTEN
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81 tio.c_lflag &= ~IEXTEN;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 #endif
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 tio.c_oflag &= ~OPOST;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 tio.c_cc[VMIN] = 1;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 tio.c_cc[VTIME] = 0;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 if (tcsetattr(STDIN_FILENO, TCSADRAIN, &tio) == -1) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 dropbear_exit("Failed to set raw TTY mode");
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_ses.tty_raw_mode = 1;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 TRACE(("leave cli_tty_setup"));
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 cli_tty_cleanup() {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 TRACE(("enter cli_tty_cleanup"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 if (cli_ses.tty_raw_mode == 0) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99 TRACE(("leave cli_tty_cleanup: not in raw mode"));
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
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
102 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
103 dropbear_log(LOG_WARNING, "Failed restoring TTY");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 } else {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 cli_ses.tty_raw_mode = 0;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
107
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 TRACE(("leave cli_tty_cleanup"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 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
112
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 unsigned char* termmodes = "\0";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 unsigned char* term = NULL;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 int termc = 80, termr = 25, termw = 0, termh = 0; /* XXX TODO matt */
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 TRACE(("enter send_chansess_pty_req"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 start_channel_request(channel, "pty-req");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 term = getenv("TERM");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 if (term == NULL) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 term = "vt100";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 }
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 /* XXX TODO */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 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
127 buf_putstring(ses.writepayload, term, strlen(term));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 buf_putint(ses.writepayload, termc); /* Cols */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 buf_putint(ses.writepayload, termr); /* Rows */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 buf_putint(ses.writepayload, termw); /* Width */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 buf_putint(ses.writepayload, termh); /* Height */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 buf_putstring(ses.writepayload, termmodes, 1); /* XXX TODO */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 //m_free(termmodes);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 encrypt_packet();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 TRACE(("leave send_chansess_pty_req"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 }
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 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
141
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 unsigned char* reqtype = NULL;
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 TRACE(("enter send_chansess_shell_req"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 if (cli_opts.cmd) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147 reqtype = "exec";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 } else {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 reqtype = "shell";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 start_channel_request(channel, reqtype);
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 /* XXX TODO */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 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
156 if (cli_opts.cmd) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
157 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
158 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
160 encrypt_packet();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
161 TRACE(("leave send_chansess_shell_req"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
163
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
164 static int cli_initchansess(struct Channel *channel) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
165
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166 channel->infd = STDOUT_FILENO;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
167 //channel->outfd = STDIN_FILENO;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
168 //channel->errfd = STDERR_FILENO;
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 if (cli_opts.wantpty) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171 send_chansess_pty_req(channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 cli_opts.cmd = "df";
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 send_chansess_shell_req(channel);
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 if (cli_opts.wantpty) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178 cli_tty_setup();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 return 0; /* Success */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 void cli_send_chansess_request() {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 TRACE(("enter cli_send_chansess_request"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 if (send_msg_channel_open_init(STDIN_FILENO, &clichansess)
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 == DROPBEAR_FAILURE) {
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 dropbear_exit("Couldn't open initial channel");
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 }
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 /* No special channel request data */
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 encrypt_packet();
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196 TRACE(("leave cli_send_chansess_request"));
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197
0883c0906870 tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 }