Mercurial > dropbear
annotate cli-session.c @ 76:95f4bc4bcd58
- It'll be called 0.44test1
- Debian stuff
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 14 Aug 2004 18:03:36 +0000 |
parents | e3adf4cf5465 |
children | 0247fbd9379d |
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:
68
diff
changeset
|
1 /* |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
68
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:
68
diff
changeset
|
3 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
68
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:
68
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:
68
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:
68
diff
changeset
|
7 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
68
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:
68
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:
68
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:
68
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:
68
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:
68
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:
68
diff
changeset
|
14 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
68
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:
68
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:
68
diff
changeset
|
17 * |
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
68
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:
68
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:
68
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:
68
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:
68
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:
68
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:
68
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:
68
diff
changeset
|
25 |
26 | 26 #include "includes.h" |
27 #include "session.h" | |
28 #include "dbutil.h" | |
29 #include "kex.h" | |
30 #include "ssh.h" | |
31 #include "packet.h" | |
64 | 32 #include "tcpfwd.h" |
26 | 33 #include "channel.h" |
34 #include "random.h" | |
33 | 35 #include "service.h" |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
36 #include "runopts.h" |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
37 #include "chansession.h" |
26 | 38 |
39 static void cli_remoteclosed(); | |
40 static void cli_sessionloop(); | |
33 | 41 static void cli_session_init(); |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
42 static void cli_finished(); |
26 | 43 |
44 struct clientsession cli_ses; /* GLOBAL */ | |
45 | |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
46 /* Sorted in decreasing frequency will be more efficient - data and window |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
47 * should be first */ |
26 | 48 static const packettype cli_packettypes[] = { |
74
e3adf4cf5465
License boilerplate etc, add Mihnea as an author to some of the files
Matt Johnston <matt@ucc.asn.au>
parents:
68
diff
changeset
|
49 /* TYPE, FUNCTION */ |
26 | 50 {SSH_MSG_CHANNEL_DATA, recv_msg_channel_data}, |
51 {SSH_MSG_CHANNEL_WINDOW_ADJUST, recv_msg_channel_window_adjust}, | |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
52 {SSH_MSG_USERAUTH_FAILURE, recv_msg_userauth_failure}, /* client */ |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
53 {SSH_MSG_USERAUTH_SUCCESS, recv_msg_userauth_success}, /* client */ |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
54 {SSH_MSG_KEXINIT, recv_msg_kexinit}, |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
55 {SSH_MSG_KEXDH_REPLY, recv_msg_kexdh_reply}, /* client */ |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
56 {SSH_MSG_NEWKEYS, recv_msg_newkeys}, |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
57 {SSH_MSG_SERVICE_ACCEPT, recv_msg_service_accept}, /* client */ |
26 | 58 {SSH_MSG_CHANNEL_REQUEST, recv_msg_channel_request}, |
59 {SSH_MSG_CHANNEL_OPEN, recv_msg_channel_open}, | |
60 {SSH_MSG_CHANNEL_EOF, recv_msg_channel_eof}, | |
61 {SSH_MSG_CHANNEL_CLOSE, recv_msg_channel_close}, | |
62 {SSH_MSG_CHANNEL_OPEN_CONFIRMATION, recv_msg_channel_open_confirmation}, | |
63 {SSH_MSG_CHANNEL_OPEN_FAILURE, recv_msg_channel_open_failure}, | |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
64 {SSH_MSG_USERAUTH_BANNER, recv_msg_userauth_banner}, /* client */ |
68
eee77ac31ccc
cleaning up the pubkey defines
Matt Johnston <matt@ucc.asn.au>
parents:
65
diff
changeset
|
65 #ifdef ENABLE_CLI_PUBKEY_AUTH |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
66 {SSH_MSG_USERAUTH_PK_OK, recv_msg_userauth_pk_ok}, /* client */ |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
67 #endif |
26 | 68 {0, 0} /* End */ |
69 }; | |
70 | |
71 static const struct ChanType *cli_chantypes[] = { | |
64 | 72 #ifdef ENABLE_CLI_REMOTETCPFWD |
73 &cli_chan_tcpremote, | |
74 #endif | |
26 | 75 NULL /* Null termination */ |
76 }; | |
33 | 77 |
26 | 78 void cli_session(int sock, char* remotehost) { |
79 | |
80 crypto_init(); | |
81 common_session_init(sock, remotehost); | |
82 | |
83 chaninitialise(cli_chantypes); | |
84 | |
85 | |
33 | 86 /* Set up cli_ses vars */ |
87 cli_session_init(); | |
26 | 88 |
89 /* Ready to go */ | |
90 sessinitdone = 1; | |
91 | |
92 /* Exchange identification */ | |
93 session_identification(); | |
94 | |
95 seedrandom(); | |
96 | |
97 send_msg_kexinit(); | |
98 | |
99 /* XXX here we do stuff differently */ | |
100 | |
101 session_loop(cli_sessionloop); | |
102 | |
103 /* Not reached */ | |
104 | |
33 | 105 } |
26 | 106 |
33 | 107 static void cli_session_init() { |
108 | |
109 cli_ses.state = STATE_NOTHING; | |
110 cli_ses.kex_state = KEX_NOTHING; | |
111 | |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
37
diff
changeset
|
112 cli_ses.tty_raw_mode = 0; |
41
18eccbfb9641
added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
113 cli_ses.winchange = 0; |
39
0883c0906870
tty raw mode support works mostly
Matt Johnston <matt@ucc.asn.au>
parents:
37
diff
changeset
|
114 |
47 | 115 /* Auth */ |
116 cli_ses.lastpubkey = NULL; | |
117 cli_ses.lastauthtype = NULL; | |
118 | |
33 | 119 /* For printing "remote host closed" for the user */ |
120 ses.remoteclosed = cli_remoteclosed; | |
121 ses.buf_match_algo = cli_buf_match_algo; | |
122 | |
123 /* packet handlers */ | |
124 ses.packettypes = cli_packettypes; | |
35
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
125 |
0ad5fb979f42
set the isserver flag (oops)
Matt Johnston <matt@ucc.asn.au>
parents:
34
diff
changeset
|
126 ses.isserver = 0; |
26 | 127 } |
128 | |
33 | 129 /* This function drives the progress of the session - it initiates KEX, |
130 * service, userauth and channel requests */ | |
26 | 131 static void cli_sessionloop() { |
132 | |
33 | 133 TRACE(("enter cli_sessionloop")); |
134 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
135 if (ses.lastpacket == SSH_MSG_KEXINIT && cli_ses.kex_state == KEX_NOTHING) { |
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
136 cli_ses.kex_state = KEXINIT_RCVD; |
33 | 137 } |
138 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
139 if (cli_ses.kex_state == KEXINIT_RCVD) { |
33 | 140 |
141 /* We initiate the KEXDH. If DH wasn't the correct type, the KEXINIT | |
142 * negotiation would have failed. */ | |
143 send_msg_kexdh_init(); | |
144 cli_ses.kex_state = KEXDH_INIT_SENT; | |
145 TRACE(("leave cli_sessionloop: done with KEXINIT_RCVD")); | |
146 return; | |
147 } | |
148 | |
149 /* A KEX has finished, so we should go back to our KEX_NOTHING state */ | |
150 if (cli_ses.kex_state != KEX_NOTHING && ses.kexstate.recvkexinit == 0 | |
151 && ses.kexstate.sentkexinit == 0) { | |
152 cli_ses.kex_state = KEX_NOTHING; | |
153 } | |
154 | |
155 /* We shouldn't do anything else if a KEX is in progress */ | |
156 if (cli_ses.kex_state != KEX_NOTHING) { | |
157 TRACE(("leave cli_sessionloop: kex_state != KEX_NOTHING")); | |
158 return; | |
159 } | |
160 | |
161 /* We should exit if we haven't donefirstkex: we shouldn't reach here | |
162 * in normal operation */ | |
163 if (ses.kexstate.donefirstkex == 0) { | |
164 TRACE(("XXX XXX might be bad! leave cli_sessionloop: haven't donefirstkex")); | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
165 return; |
33 | 166 } |
167 | |
26 | 168 switch (cli_ses.state) { |
169 | |
33 | 170 case STATE_NOTHING: |
171 /* We've got the transport layer sorted, we now need to request | |
172 * userauth */ | |
173 send_msg_service_request(SSH_SERVICE_USERAUTH); | |
174 cli_ses.state = SERVICE_AUTH_REQ_SENT; | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
175 TRACE(("leave cli_sessionloop: sent userauth service req")); |
33 | 176 return; |
26 | 177 |
33 | 178 /* userauth code */ |
179 case SERVICE_AUTH_ACCEPT_RCVD: | |
180 cli_auth_getmethods(); | |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
181 cli_ses.state = USERAUTH_REQ_SENT; |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
182 TRACE(("leave cli_sessionloop: sent userauth methods req")); |
33 | 183 return; |
184 | |
185 case USERAUTH_FAIL_RCVD: | |
186 cli_auth_try(); | |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
187 cli_ses.state = USERAUTH_REQ_SENT; |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
188 TRACE(("leave cli_sessionloop: cli_auth_try")); |
33 | 189 return; |
190 | |
47 | 191 /* |
37 | 192 case USERAUTH_SUCCESS_RCVD: |
193 send_msg_service_request(SSH_SERVICE_CONNECTION); | |
194 cli_ses.state = SERVICE_CONN_REQ_SENT; | |
195 TRACE(("leave cli_sessionloop: sent ssh-connection service req")); | |
196 return; | |
197 | |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
198 case SERVICE_CONN_ACCEPT_RCVD: |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
199 cli_send_chansess_request(); |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
200 TRACE(("leave cli_sessionloop: cli_send_chansess_request")); |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
201 cli_ses.state = SESSION_RUNNING; |
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
202 return; |
47 | 203 */ |
45
9ee8996a375f
Pubkey auth is mostly there for the client. Something strange with
Matt Johnston <matt@ucc.asn.au>
parents:
43
diff
changeset
|
204 |
37 | 205 case USERAUTH_SUCCESS_RCVD: |
64 | 206 #ifdef ENABLE_CLI_LOCALTCPFWD |
207 setup_localtcp(); | |
208 #endif | |
65
02e4a7f614f8
Oops, forgot to call the actual code.
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
209 #ifdef ENABLE_CLI_REMOTETCPFWD |
02e4a7f614f8
Oops, forgot to call the actual code.
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
210 setup_remotetcp(); |
02e4a7f614f8
Oops, forgot to call the actual code.
Matt Johnston <matt@ucc.asn.au>
parents:
64
diff
changeset
|
211 #endif |
37 | 212 cli_send_chansess_request(); |
213 TRACE(("leave cli_sessionloop: cli_send_chansess_request")); | |
214 cli_ses.state = SESSION_RUNNING; | |
215 return; | |
216 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
217 case SESSION_RUNNING: |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
218 if (ses.chancount < 1) { |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
219 cli_finished(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
220 } |
41
18eccbfb9641
added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
221 |
18eccbfb9641
added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
222 if (cli_ses.winchange) { |
18eccbfb9641
added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
223 cli_chansess_winchange(); |
18eccbfb9641
added window-size change handling
Matt Johnston <matt@ucc.asn.au>
parents:
40
diff
changeset
|
224 } |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
225 return; |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
226 |
33 | 227 /* XXX more here needed */ |
228 | |
229 | |
230 default: | |
231 break; | |
26 | 232 } |
233 | |
34
e2a1eaa19f22
Client mostly works up to password auth
Matt Johnston <matt@ucc.asn.au>
parents:
33
diff
changeset
|
234 TRACE(("leave cli_sessionloop: fell out")); |
26 | 235 |
236 } | |
237 | |
40
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
238 void cli_session_cleanup() { |
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 if (!sessinitdone) { |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
241 return; |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
242 } |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
243 cli_tty_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
244 |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
245 } |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
246 |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
247 static void cli_finished() { |
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 cli_session_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
250 common_session_cleanup(); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
251 fprintf(stderr, "Connection to %s@%s:%s closed.\n", cli_opts.username, |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
252 cli_opts.remotehost, cli_opts.remoteport); |
b4874d772210
- Added terminal mode handling etc for the client, and window change
Matt Johnston <matt@ucc.asn.au>
parents:
39
diff
changeset
|
253 exit(EXIT_SUCCESS); |
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 |
26 | 257 /* called when the remote side closes the connection */ |
258 static void cli_remoteclosed() { | |
259 | |
260 /* XXX TODO perhaps print a friendlier message if we get this but have | |
261 * already sent/received disconnect message(s) ??? */ | |
262 close(ses.sock); | |
263 ses.sock = -1; | |
33 | 264 dropbear_exit("remote closed the connection"); |
26 | 265 } |
43 | 266 |
267 /* Operates in-place turning dirty (untrusted potentially containing control | |
268 * characters) text into clean text. */ | |
269 void cleantext(unsigned char* dirtytext) { | |
270 | |
271 unsigned int i, j; | |
47 | 272 unsigned char c; |
43 | 273 |
274 j = 0; | |
275 for (i = 0; dirtytext[i] != '\0'; i++) { | |
276 | |
277 c = dirtytext[i]; | |
278 /* We can ignore '\r's */ | |
279 if ( (c >= ' ' && c <= '~') || c == '\n' || c == '\t') { | |
280 dirtytext[j] = c; | |
281 j++; | |
282 } | |
283 } | |
284 /* Null terminate */ | |
285 dirtytext[j] = '\0'; | |
286 } |