Mercurial > dropbear
annotate common-channel.c @ 1165:a96cf3627a58
Only clear channel_signal_pending after handling all channels,
from Andrzej Szombierski
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 17 Nov 2015 20:53:30 +0800 |
parents | aaf576b27a10 |
children | b0f351edf370 |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
107 | 2 * Dropbear SSH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
107 | 4 * Copyright (c) 2002-2004 Matt Johnston |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 /* Handle the multiplexed channels, such as sessions, x11, agent connections */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "session.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "packet.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "ssh.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "buffer.h" |
107 | 32 #include "circbuffer.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 #include "channel.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 #include "ssh.h" |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
36 #include "listener.h" |
449
3e6c536bc023
Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
37 #include "runopts.h" |
1032
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
1025
diff
changeset
|
38 #include "netio.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 static void send_msg_channel_open_failure(unsigned int remotechan, int reason, |
1098
f95b6e87cd0c
Turn send_msg_channel_open_failure()'s text and lang into const char *
Gaël PORTAY <gael.portay@gmail.com>
parents:
1097
diff
changeset
|
41 const char *text, const char *lang); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 static void send_msg_channel_open_confirmation(struct Channel* channel, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 unsigned int recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 unsigned int recvmaxpacket); |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
45 static void writechannel(struct Channel* channel, int fd, circbuffer *cbuf, |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
46 const unsigned char *moredata, unsigned int *morelen); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 static void send_msg_channel_window_adjust(struct Channel *channel, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 unsigned int incr); |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
49 static void send_msg_channel_data(struct Channel *channel, int isextended); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 static void send_msg_channel_eof(struct Channel *channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 static void send_msg_channel_close(struct Channel *channel); |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
52 static void remove_channel(struct Channel *channel); |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
53 static unsigned int write_pending(struct Channel * channel); |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
54 static void check_close(struct Channel *channel); |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
55 static void close_chan_fd(struct Channel *channel, int fd, int how); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 #define FD_UNINIT (-2) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 #define FD_CLOSED (-1) |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 |
375 | 60 #define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL) |
61 #define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel)) | |
62 | |
906
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
63 /* allow space for: |
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
64 * 1 byte byte SSH_MSG_CHANNEL_DATA |
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
65 * 4 bytes uint32 recipient channel |
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
66 * 4 bytes string data |
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
67 */ |
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
68 #define RECV_MAX_CHANNEL_DATA_LEN (RECV_MAX_PAYLOAD_LEN-(1+4+4)) |
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
69 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 /* Initialise all the channels */ |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
71 void chaninitialise(const struct ChanType *chantypes[]) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 /* may as well create space for a single channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 ses.channels = (struct Channel**)m_malloc(sizeof(struct Channel*)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 ses.chansize = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 ses.channels[0] = NULL; |
37 | 77 ses.chancount = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 ses.chantypes = chantypes; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
81 #ifdef USING_LISTENERS |
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
82 listeners_initialise(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 /* Clean up channels, freeing allocated memory */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 void chancleanup() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
92 TRACE(("enter chancleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 if (ses.channels[i] != NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
95 TRACE(("channel %d closing", i)) |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
96 remove_channel(ses.channels[i]); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 m_free(ses.channels); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
100 TRACE(("leave chancleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
103 static void |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
104 chan_initwritebuf(struct Channel *channel) |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
105 { |
709
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
106 dropbear_assert(channel->writebuf->size == 0 && channel->recvwindow == 0); |
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
107 cbuf_free(channel->writebuf); |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
108 channel->writebuf = cbuf_new(opts.recv_window); |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
109 channel->recvwindow = opts.recv_window; |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
110 } |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
111 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 /* Create a new channel entry, send a reply confirm or failure */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 /* If remotechan, transwindow and transmaxpacket are not know (for a new |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 * outgoing connection, with them to be filled on confirmation), they should |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 * all be set to 0 */ |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
116 static struct Channel* newchannel(unsigned int remotechan, |
7 | 117 const struct ChanType *type, |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 unsigned int transwindow, unsigned int transmaxpacket) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 struct Channel * newchan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 unsigned int i, j; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
123 TRACE(("enter newchannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 /* first see if we can use existing channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 if (ses.channels[i] == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 break; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 /* otherwise extend the list */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 if (i == ses.chansize) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 if (ses.chansize >= MAX_CHANNELS) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
135 TRACE(("leave newchannel: max chans reached")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 return NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 /* extend the channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 ses.channels = (struct Channel**)m_realloc(ses.channels, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 (ses.chansize+CHAN_EXTEND_SIZE)*sizeof(struct Channel*)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 ses.chansize += CHAN_EXTEND_SIZE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 /* set the new channels to null */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 for (j = i; j < ses.chansize; j++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 ses.channels[j] = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 newchan = (struct Channel*)m_malloc(sizeof(struct Channel)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 newchan->type = type; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 newchan->index = i; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
155 newchan->sent_close = newchan->recv_close = 0; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
156 newchan->sent_eof = newchan->recv_eof = 0; |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
157 newchan->close_handler_done = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 newchan->remotechan = remotechan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 newchan->transwindow = transwindow; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 newchan->transmaxpacket = transmaxpacket; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 newchan->typedata = NULL; |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
164 newchan->writefd = FD_UNINIT; |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
165 newchan->readfd = FD_UNINIT; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */ |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
167 newchan->await_open = 0; |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
168 newchan->flushing = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 |
709
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
170 newchan->writebuf = cbuf_new(0); /* resized later by chan_initwritebuf */ |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
171 newchan->recvwindow = 0; |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
172 |
107 | 173 newchan->extrabuf = NULL; /* The user code can set it up */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
174 newchan->recvdonelen = 0; |
906
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
175 newchan->recvmaxpacket = RECV_MAX_CHANNEL_DATA_LEN; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
177 newchan->prio = DROPBEAR_CHANNEL_PRIO_EARLY; /* inithandler sets it */ |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
178 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 ses.channels[i] = newchan; |
37 | 180 ses.chancount++; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
181 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
182 TRACE(("leave newchannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 return newchan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
185 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
187 /* Returns the channel structure corresponding to the channel in the current |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
188 * data packet (ses.payload must be positioned appropriately). |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
189 * A valid channel is always returns, it will fail fatally with an unknown |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
190 * channel */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
191 static struct Channel* getchannel_msg(const char* kind) { |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
192 |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
193 unsigned int chan; |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
194 |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
195 chan = buf_getint(ses.payload); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 if (chan >= ses.chansize || ses.channels[chan] == NULL) { |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
197 if (kind) { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
198 dropbear_exit("%s for unknown channel %d", kind, chan); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
199 } else { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
200 dropbear_exit("Unknown channel %d", chan); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
201 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
202 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
203 return ses.channels[chan]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
206 struct Channel* getchannel() { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
207 return getchannel_msg(NULL); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
208 } |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
209 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 /* Iterate through the channels, performing IO if available */ |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
211 void channelio(fd_set *readfds, fd_set *writefds) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
213 /* Listeners such as TCP, X11, agent-auth */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
214 struct Channel *channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
215 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
216 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
217 /* foreach channel */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
218 for (i = 0; i < ses.chansize; i++) { |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
219 /* Close checking only needs to occur for channels that had IO events */ |
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
220 int do_check_close = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 channel = ses.channels[i]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 if (channel == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 /* only process in-use channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
228 /* read data and send it over the wire */ |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
229 if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) { |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
230 TRACE(("send normal readfd")) |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
231 send_msg_channel_data(channel, 0); |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
232 do_check_close = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
235 /* read stderr data and send it over the wire */ |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
236 if (ERRFD_IS_READ(channel) && channel->errfd >= 0 |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
237 && FD_ISSET(channel->errfd, readfds)) { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
238 TRACE(("send normal errfd")) |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
239 send_msg_channel_data(channel, 1); |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
240 do_check_close = 1; |
395
dc37bd8563e8
disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents:
394
diff
changeset
|
241 } |
dc37bd8563e8
disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents:
394
diff
changeset
|
242 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 /* write to program/pipe stdin */ |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
244 if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) { |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
245 writechannel(channel, channel->writefd, channel->writebuf, NULL, NULL); |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
246 do_check_close = 1; |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
247 } |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
248 |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
249 /* stderr for client mode */ |
375 | 250 if (ERRFD_IS_WRITE(channel) |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
251 && channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) { |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
252 writechannel(channel, channel->errfd, channel->extrabuf, NULL, NULL); |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
253 do_check_close = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 } |
955
36eacc322e00
Make sure the check_close() handler runs when a server child process exits
Matt Johnston <matt@ucc.asn.au>
parents:
944
diff
changeset
|
255 |
36eacc322e00
Make sure the check_close() handler runs when a server child process exits
Matt Johnston <matt@ucc.asn.au>
parents:
944
diff
changeset
|
256 if (ses.channel_signal_pending) { |
36eacc322e00
Make sure the check_close() handler runs when a server child process exits
Matt Johnston <matt@ucc.asn.au>
parents:
944
diff
changeset
|
257 /* SIGCHLD can change channel state for server sessions */ |
36eacc322e00
Make sure the check_close() handler runs when a server child process exits
Matt Johnston <matt@ucc.asn.au>
parents:
944
diff
changeset
|
258 do_check_close = 1; |
36eacc322e00
Make sure the check_close() handler runs when a server child process exits
Matt Johnston <matt@ucc.asn.au>
parents:
944
diff
changeset
|
259 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
261 /* handle any channel closing etc */ |
936
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
262 if (do_check_close) { |
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
263 check_close(channel); |
d93a6bcf616f
Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents:
906
diff
changeset
|
264 } |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
265 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
266 |
1165
a96cf3627a58
Only clear channel_signal_pending after handling all channels,
Matt Johnston <matt@ucc.asn.au>
parents:
1122
diff
changeset
|
267 ses.channel_signal_pending = 0; |
a96cf3627a58
Only clear channel_signal_pending after handling all channels,
Matt Johnston <matt@ucc.asn.au>
parents:
1122
diff
changeset
|
268 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
269 #ifdef USING_LISTENERS |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
270 handle_listeners(readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
271 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
272 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
273 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
274 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
275 /* Returns true if there is data remaining to be written to stdin or |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
276 * stderr of a channel's endpoint. */ |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
277 static unsigned int write_pending(struct Channel * channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
278 |
709
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
279 if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
280 return 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
281 } else if (channel->errfd >= 0 && channel->extrabuf && |
375 | 282 cbuf_getused(channel->extrabuf) > 0) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
283 return 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
284 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
285 return 0; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
286 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
287 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
288 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
289 /* EOF/close handling */ |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
290 static void check_close(struct Channel *channel) { |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
291 int close_allowed = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
292 |
731
9a5438271556
Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents:
722
diff
changeset
|
293 TRACE2(("check_close: writefd %d, readfd %d, errfd %d, sent_close %d, recv_close %d", |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
294 channel->writefd, channel->readfd, |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
295 channel->errfd, channel->sent_close, channel->recv_close)) |
731
9a5438271556
Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents:
722
diff
changeset
|
296 TRACE2(("writebuf size %d extrabuf size %d", |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
297 channel->writebuf ? cbuf_getused(channel->writebuf) : 0, |
375 | 298 channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0)) |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
299 |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
300 if (!channel->flushing |
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
301 && !channel->close_handler_done |
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
302 && channel->type->check_close |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
303 && channel->type->check_close(channel)) |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
304 { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
305 channel->flushing = 1; |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
306 } |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
307 |
504
950c38b854a1
Don't use // style comments
Matt Johnston <matt@ucc.asn.au>
parents:
495
diff
changeset
|
308 /* if a type-specific check_close is defined we will only exit |
950c38b854a1
Don't use // style comments
Matt Johnston <matt@ucc.asn.au>
parents:
495
diff
changeset
|
309 once that has been triggered. this is only used for a server "session" |
950c38b854a1
Don't use // style comments
Matt Johnston <matt@ucc.asn.au>
parents:
495
diff
changeset
|
310 channel, to ensure that the shell has exited (and the exit status |
950c38b854a1
Don't use // style comments
Matt Johnston <matt@ucc.asn.au>
parents:
495
diff
changeset
|
311 retrieved) before we close things up. */ |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
312 if (!channel->type->check_close |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
313 || channel->close_handler_done |
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
314 || channel->type->check_close(channel)) { |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
315 close_allowed = 1; |
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
316 } |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
317 |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
318 if (channel->recv_close && !write_pending(channel) && close_allowed) { |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
319 if (!channel->sent_close) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
320 TRACE(("Sending MSG_CHANNEL_CLOSE in response to same.")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
321 send_msg_channel_close(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
322 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
323 remove_channel(channel); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
324 return; |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
325 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
326 |
815
35183e8a7851
Improve EOF handling for half-close. Patch from Catalin Patulea
Matt Johnston <matt@ucc.asn.au>
parents:
770
diff
changeset
|
327 if ((channel->recv_eof && !write_pending(channel)) |
35183e8a7851
Improve EOF handling for half-close. Patch from Catalin Patulea
Matt Johnston <matt@ucc.asn.au>
parents:
770
diff
changeset
|
328 /* have a server "session" and child has exited */ |
35183e8a7851
Improve EOF handling for half-close. Patch from Catalin Patulea
Matt Johnston <matt@ucc.asn.au>
parents:
770
diff
changeset
|
329 || (channel->type->check_close && close_allowed)) { |
364 | 330 close_chan_fd(channel, channel->writefd, SHUT_WR); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
331 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
332 |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
333 /* Special handling for flushing read data after an exit. We |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
334 read regardless of whether the select FD was set, |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
335 and if there isn't data available, the channel will get closed. */ |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
336 if (channel->flushing) { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
337 TRACE(("might send data, flushing")) |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
338 if (channel->readfd >= 0 && channel->transwindow > 0) { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
339 TRACE(("send data readfd")) |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
340 send_msg_channel_data(channel, 0); |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
341 } |
439
ab370c629d36
Fix a stupid bug s/readfd/errfd/ affecting channel close on child exit
Matt Johnston <matt@ucc.asn.au>
parents:
433
diff
changeset
|
342 if (ERRFD_IS_READ(channel) && channel->errfd >= 0 |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
343 && channel->transwindow > 0) { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
344 TRACE(("send data errfd")) |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
345 send_msg_channel_data(channel, 1); |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
346 } |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
347 } |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
348 |
375 | 349 /* If we're not going to send any more data, send EOF */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
350 if (!channel->sent_eof |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
351 && channel->readfd == FD_CLOSED |
375 | 352 && (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)) { |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
353 send_msg_channel_eof(channel); |
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
354 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
355 |
375 | 356 /* And if we can't receive any more data from them either, close up */ |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
357 if (channel->readfd == FD_CLOSED |
815
35183e8a7851
Improve EOF handling for half-close. Patch from Catalin Patulea
Matt Johnston <matt@ucc.asn.au>
parents:
770
diff
changeset
|
358 && channel->writefd == FD_CLOSED |
423
b2b67cfcd66e
- Fix bug in child-exit handling where the wrong pid was being matched.
Matt Johnston <matt@ucc.asn.au>
parents:
416
diff
changeset
|
359 && (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED) |
467
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
360 && !channel->sent_close |
0871a0b89f7c
Don't return until the shell has quit. This will ensure that an exit status
Matt Johnston <matt@ucc.asn.au>
parents:
449
diff
changeset
|
361 && close_allowed |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
362 && !write_pending(channel)) { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
363 TRACE(("sending close, readfd is closed")) |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
364 send_msg_channel_close(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
365 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
366 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
367 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
368 /* Check whether a deferred (EINPROGRESS) connect() was successful, and |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
369 * if so, set up the channel properly. Otherwise, the channel is cleaned up, so |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
370 * it is important that the channel reference isn't used after a call to this |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
371 * function */ |
1025 | 372 void channel_connect_done(int result, int sock, void* user_data, const char* UNUSED(errstring)) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
373 |
1025 | 374 struct Channel *channel = user_data; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
375 |
1025 | 376 TRACE(("enter channel_connect_done")) |
377 | |
378 if (result == DROPBEAR_SUCCESS) | |
379 { | |
380 channel->readfd = channel->writefd = sock; | |
381 channel->conn_pending = NULL; | |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
382 chan_initwritebuf(channel); |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
383 send_msg_channel_open_confirmation(channel, channel->recvwindow, |
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
384 channel->recvmaxpacket); |
1025 | 385 TRACE(("leave channel_connect_done: success")) |
386 } | |
387 else | |
388 { | |
389 send_msg_channel_open_failure(channel->remotechan, | |
390 SSH_OPEN_CONNECT_FAILED, "", ""); | |
391 remove_channel(channel); | |
392 TRACE(("leave check_in_progress: fail")) | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
393 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
394 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
395 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
396 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
397 /* Send the close message and set the channel as closed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
398 static void send_msg_channel_close(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
399 |
1038
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
970
diff
changeset
|
400 TRACE(("enter send_msg_channel_close %p", (void*)channel)) |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
401 if (channel->type->closehandler |
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
402 && !channel->close_handler_done) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
403 channel->type->closehandler(channel); |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
404 channel->close_handler_done = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
405 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
406 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
407 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
408 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
409 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
410 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
411 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
412 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
413 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
414 channel->sent_eof = 1; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
415 channel->sent_close = 1; |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
416 close_chan_fd(channel, channel->readfd, SHUT_RD); |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
417 close_chan_fd(channel, channel->errfd, SHUT_RDWR); |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
418 close_chan_fd(channel, channel->writefd, SHUT_WR); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
419 TRACE(("leave send_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
420 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
421 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
422 /* call this when trans/eof channels are closed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
423 static void send_msg_channel_eof(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
424 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
425 TRACE(("enter send_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
426 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
427 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
428 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_EOF); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
429 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
430 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
431 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
432 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
433 channel->sent_eof = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
434 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
435 TRACE(("leave send_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
436 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
437 |
1079 | 438 #ifndef HAVE_WRITEV |
439 static void writechannel_fallback(struct Channel* channel, int fd, circbuffer *cbuf, | |
440 const unsigned char *UNUSED(moredata), unsigned int *morelen) { | |
441 | |
442 unsigned char *circ_p1, *circ_p2; | |
443 unsigned int circ_len1, circ_len2; | |
444 ssize_t written; | |
445 | |
446 if (morelen) { | |
447 /* fallback doesn't consume moredata */ | |
448 *morelen = 0; | |
449 } | |
450 | |
451 /* Write the first portion of the circular buffer */ | |
452 cbuf_readptrs(cbuf, &circ_p1, &circ_len1, &circ_p2, &circ_len2); | |
453 written = write(fd, circ_p1, circ_len1); | |
454 if (written < 0) { | |
455 if (errno != EINTR && errno != EAGAIN) { | |
456 TRACE(("channel IO write error fd %d %s", fd, strerror(errno))) | |
457 close_chan_fd(channel, fd, SHUT_WR); | |
458 } | |
459 } else { | |
460 cbuf_incrread(cbuf, written); | |
461 channel->recvdonelen += written; | |
462 } | |
463 } | |
464 #endif /* !HAVE_WRITEV */ | |
465 | |
466 #ifdef HAVE_WRITEV | |
467 static void writechannel_writev(struct Channel* channel, int fd, circbuffer *cbuf, | |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
468 const unsigned char *moredata, unsigned int *morelen) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
469 |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
470 struct iovec iov[3]; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
471 unsigned char *circ_p1, *circ_p2; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
472 unsigned int circ_len1, circ_len2; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
473 int io_count = 0; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
474 |
1079 | 475 ssize_t written; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
476 |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
477 cbuf_readptrs(cbuf, &circ_p1, &circ_len1, &circ_p2, &circ_len2); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
478 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
479 if (circ_len1 > 0) { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
480 TRACE(("circ1 %d", circ_len1)) |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
481 iov[io_count].iov_base = circ_p1; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
482 iov[io_count].iov_len = circ_len1; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
483 io_count++; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
484 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
485 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
486 if (circ_len2 > 0) { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
487 TRACE(("circ2 %d", circ_len2)) |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
488 iov[io_count].iov_base = circ_p2; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
489 iov[io_count].iov_len = circ_len2; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
490 io_count++; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
491 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
492 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
493 if (morelen) { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
494 assert(moredata); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
495 TRACE(("more %d", *morelen)) |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
496 iov[io_count].iov_base = (void*)moredata; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
497 iov[io_count].iov_len = *morelen; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
498 io_count++; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
499 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
500 |
1075
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
501 if (io_count == 0) { |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
502 /* writechannel may sometimes be called twice in a main loop iteration. |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
503 From common_recv_msg_channel_data() then channelio(). |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
504 The second call may not have any data to write, so we just return. */ |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
505 TRACE(("leave writechannel, no data")) |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
506 return; |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
507 } |
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
508 |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
509 if (morelen) { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
510 /* Default return value, none consumed */ |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
511 *morelen = 0; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
512 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
513 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
514 written = writev(fd, iov, io_count); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
515 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
516 if (written < 0) { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
517 if (errno != EINTR && errno != EAGAIN) { |
1075
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
518 TRACE(("channel IO write error fd %d %s", fd, strerror(errno))) |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
519 close_chan_fd(channel, fd, SHUT_WR); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
520 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
521 } else { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
522 int cbuf_written = MIN(circ_len1+circ_len2, (unsigned int)written); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
523 cbuf_incrread(cbuf, cbuf_written); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
524 if (morelen) { |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
525 *morelen = written - cbuf_written; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
526 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
527 channel->recvdonelen += written; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
528 } |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
529 |
1079 | 530 } |
531 #endif /* HAVE_WRITEV */ | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
532 |
1079 | 533 /* Called to write data out to the local side of the channel. |
534 Writes the circular buffer contents and also the "moredata" buffer | |
535 if not null. Will ignore EAGAIN */ | |
536 static void writechannel(struct Channel* channel, int fd, circbuffer *cbuf, | |
537 const unsigned char *moredata, unsigned int *morelen) { | |
538 TRACE(("enter writechannel fd %d", fd)) | |
539 #ifdef HAVE_WRITEV | |
540 writechannel_writev(channel, fd, cbuf, moredata, morelen); | |
541 #else | |
542 writechannel_fallback(channel, fd, cbuf, moredata, morelen); | |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
543 #endif |
107 | 544 |
545 /* Window adjust handling */ | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
546 if (channel->recvdonelen >= RECV_WINDOWEXTEND) { |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
547 send_msg_channel_window_adjust(channel, channel->recvdonelen); |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
548 channel->recvwindow += channel->recvdonelen; |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
549 channel->recvdonelen = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
550 } |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
551 |
449
3e6c536bc023
Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
552 dropbear_assert(channel->recvwindow <= opts.recv_window); |
709
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
553 dropbear_assert(channel->recvwindow <= cbuf_getavail(channel->writebuf)); |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
554 dropbear_assert(channel->extrabuf == NULL || |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
555 channel->recvwindow <= cbuf_getavail(channel->extrabuf)); |
107 | 556 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
557 TRACE(("leave writechannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
558 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
559 |
1079 | 560 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
561 /* Set the file descriptors for the main select in session.c |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
562 * This avoid channels which don't have any window available, are closed, etc*/ |
1074
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1072
diff
changeset
|
563 void setchannelfds(fd_set *readfds, fd_set *writefds, int allow_reads) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
564 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
565 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
566 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
567 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
568 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
569 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
570 channel = ses.channels[i]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
571 if (channel == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
572 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
573 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
574 |
896
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
815
diff
changeset
|
575 /* Stuff to put over the wire. |
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
815
diff
changeset
|
576 Avoid queueing data to send if we're in the middle of a |
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
815
diff
changeset
|
577 key re-exchange (!dataallowed), but still read from the |
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
815
diff
changeset
|
578 FD if there's the possibility of "~."" to kill an |
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
815
diff
changeset
|
579 interactive session (the read_mangler) */ |
a1a97e98b0c1
Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents:
815
diff
changeset
|
580 if (channel->transwindow > 0 |
1074
10f198d4a308
Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents:
1072
diff
changeset
|
581 && ((ses.dataallowed && allow_reads) || channel->read_mangler)) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
582 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
583 if (channel->readfd >= 0) { |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
584 FD_SET(channel->readfd, readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
585 } |
107 | 586 |
375 | 587 if (ERRFD_IS_READ(channel) && channel->errfd >= 0) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
588 FD_SET(channel->errfd, readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
589 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
590 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
591 |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
592 /* Stuff from the wire */ |
1025 | 593 if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
594 FD_SET(channel->writefd, writefds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
595 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
596 |
433
c216212001fc
Fix for -pedantic -ansi compilation, change // to /**/, plus some signedness
Matt Johnston <matt@ucc.asn.au>
parents:
423
diff
changeset
|
597 if (ERRFD_IS_WRITE(channel) && channel->errfd >= 0 |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
598 && cbuf_getused(channel->extrabuf) > 0) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
599 FD_SET(channel->errfd, writefds); |
107 | 600 } |
601 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
602 } /* foreach channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
603 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
604 #ifdef USING_LISTENERS |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
605 set_listener_fds(readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
606 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
607 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
608 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
609 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
610 /* handle the channel EOF event, by closing the channel filedescriptor. The |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
611 * channel isn't closed yet, it is left until the incoming (from the program |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
612 * etc) FD is also EOF */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
613 void recv_msg_channel_eof() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
614 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
615 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
616 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
617 TRACE(("enter recv_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
618 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
619 channel = getchannel_msg("EOF"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
620 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
621 channel->recv_eof = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
622 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
623 check_close(channel); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
624 TRACE(("leave recv_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
625 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
626 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
627 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
628 /* Handle channel closure(), respond in kind and close the channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
629 void recv_msg_channel_close() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
630 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
631 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
632 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
633 TRACE(("enter recv_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
634 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
635 channel = getchannel_msg("Close"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
636 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
637 channel->recv_eof = 1; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
638 channel->recv_close = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
639 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
640 check_close(channel); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
641 TRACE(("leave recv_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
642 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
643 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
644 /* Remove a channel entry, this is only executed after both sides have sent |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
645 * channel close */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
646 static void remove_channel(struct Channel * channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
647 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
648 TRACE(("enter remove_channel")) |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
649 TRACE(("channel index is %d", channel->index)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
650 |
709
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
651 cbuf_free(channel->writebuf); |
abd99ecd7ec2
use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents:
707
diff
changeset
|
652 channel->writebuf = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
653 |
107 | 654 if (channel->extrabuf) { |
655 cbuf_free(channel->extrabuf); | |
656 channel->extrabuf = NULL; | |
657 } | |
658 | |
659 | |
938
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
660 if (IS_DROPBEAR_SERVER || (channel->writefd != STDOUT_FILENO)) { |
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
661 /* close the FDs in case they haven't been done |
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
662 * yet (they might have been shutdown etc) */ |
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
663 TRACE(("CLOSE writefd %d", channel->writefd)) |
1039
d0e6dd5af46e
Use m_close() which will avoid close(-1)
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
664 m_close(channel->writefd); |
938
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
665 TRACE(("CLOSE readfd %d", channel->readfd)) |
1039
d0e6dd5af46e
Use m_close() which will avoid close(-1)
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
666 m_close(channel->readfd); |
938
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
667 TRACE(("CLOSE errfd %d", channel->errfd)) |
1039
d0e6dd5af46e
Use m_close() which will avoid close(-1)
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
668 m_close(channel->errfd); |
938
c88dce72f6d2
Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents:
937
diff
changeset
|
669 } |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
670 |
770
7577a3afc42d
run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
731
diff
changeset
|
671 if (!channel->close_handler_done |
7577a3afc42d
run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
731
diff
changeset
|
672 && channel->type->closehandler) { |
7577a3afc42d
run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
731
diff
changeset
|
673 channel->type->closehandler(channel); |
7577a3afc42d
run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
731
diff
changeset
|
674 channel->close_handler_done = 1; |
7577a3afc42d
run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
731
diff
changeset
|
675 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
676 |
1025 | 677 if (channel->conn_pending) { |
678 cancel_connect(channel->conn_pending); | |
679 } | |
680 | |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
681 ses.channels[channel->index] = NULL; |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
682 m_free(channel); |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
683 ses.chancount--; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
684 |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
685 update_channel_prio(); |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
686 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
687 TRACE(("leave remove_channel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
688 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
689 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
690 /* Handle channel specific requests, passing off to corresponding handlers |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
691 * such as chansession or x11fwd */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
692 void recv_msg_channel_request() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
693 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
694 struct Channel *channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
695 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
696 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
697 |
1038
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
970
diff
changeset
|
698 TRACE(("enter recv_msg_channel_request %p", (void*)channel)) |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
699 |
495
cd02449b709c
Don't send anything in response to a SSH_MSG_CHANNEL_REQUEST if we have
Matt Johnston <matt@ucc.asn.au>
parents:
467
diff
changeset
|
700 if (channel->sent_close) { |
cd02449b709c
Don't send anything in response to a SSH_MSG_CHANNEL_REQUEST if we have
Matt Johnston <matt@ucc.asn.au>
parents:
467
diff
changeset
|
701 TRACE(("leave recv_msg_channel_request: already closed channel")) |
cd02449b709c
Don't send anything in response to a SSH_MSG_CHANNEL_REQUEST if we have
Matt Johnston <matt@ucc.asn.au>
parents:
467
diff
changeset
|
702 return; |
cd02449b709c
Don't send anything in response to a SSH_MSG_CHANNEL_REQUEST if we have
Matt Johnston <matt@ucc.asn.au>
parents:
467
diff
changeset
|
703 } |
cd02449b709c
Don't send anything in response to a SSH_MSG_CHANNEL_REQUEST if we have
Matt Johnston <matt@ucc.asn.au>
parents:
467
diff
changeset
|
704 |
652
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
705 if (channel->type->reqhandler |
17962b2a6b8f
- Make sure we don't use channel-specific data after it has been freed
Matt Johnston <matt@ucc.asn.au>
parents:
594
diff
changeset
|
706 && !channel->close_handler_done) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
707 channel->type->reqhandler(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
708 } else { |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
709 int wantreply; |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
710 buf_eatstring(ses.payload); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
711 wantreply = buf_getbool(ses.payload); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
712 if (wantreply) { |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
713 send_msg_channel_failure(channel); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
714 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
715 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
716 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
717 TRACE(("leave recv_msg_channel_request")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
718 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
719 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
720 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
721 /* Reads data from the server's program/shell/etc, and puts it in a |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
722 * channel_data packet to send. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
723 * chan is the remote channel, isextended is 0 if it is normal data, 1 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
724 * if it is extended data. if it is extended, then the type is in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
725 * exttype */ |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
726 static void send_msg_channel_data(struct Channel *channel, int isextended) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
727 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
728 int len; |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
729 size_t maxlen, size_pos; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
730 int fd; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
731 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
732 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
733 |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
734 TRACE(("enter send_msg_channel_data")) |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
735 dropbear_assert(!channel->sent_close); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
736 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
737 if (isextended) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
738 fd = channel->errfd; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
739 } else { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
740 fd = channel->readfd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
741 } |
375 | 742 TRACE(("enter send_msg_channel_data isextended %d fd %d", isextended, fd)) |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
743 dropbear_assert(fd >= 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
744 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
745 maxlen = MIN(channel->transwindow, channel->transmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
746 /* -(1+4+4) is SSH_MSG_CHANNEL_DATA, channel number, string length, and |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
747 * exttype if is extended */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
748 maxlen = MIN(maxlen, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
749 ses.writepayload->size - 1 - 4 - 4 - (isextended ? 4 : 0)); |
770
7577a3afc42d
run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents:
731
diff
changeset
|
750 TRACE(("maxlen %zd", maxlen)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
751 if (maxlen == 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:
156
diff
changeset
|
752 TRACE(("leave send_msg_channel_data: no window")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
753 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
754 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
755 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
756 buf_putbyte(ses.writepayload, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
757 isextended ? SSH_MSG_CHANNEL_EXTENDED_DATA : SSH_MSG_CHANNEL_DATA); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
758 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
759 if (isextended) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
760 buf_putint(ses.writepayload, SSH_EXTENDED_DATA_STDERR); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
761 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
762 /* a dummy size first ...*/ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
763 size_pos = ses.writepayload->pos; |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
764 buf_putint(ses.writepayload, 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
765 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
766 /* read the data */ |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
767 len = read(fd, buf_getwriteptr(ses.writepayload, maxlen), maxlen); |
722
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
768 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
769 if (len <= 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
770 if (len == 0 || errno != EINTR) { |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
771 /* This will also get hit in the case of EAGAIN. The only |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
772 time we expect to receive EAGAIN is when we're flushing a FD, |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
773 in which case it can be treated the same as EOF */ |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
774 close_chan_fd(channel, fd, SHUT_RD); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
775 } |
722
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
776 buf_setpos(ses.writepayload, 0); |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
777 buf_setlen(ses.writepayload, 0); |
423
b2b67cfcd66e
- Fix bug in child-exit handling where the wrong pid was being matched.
Matt Johnston <matt@ucc.asn.au>
parents:
416
diff
changeset
|
778 TRACE(("leave send_msg_channel_data: len %d read err %d or EOF for fd %d", |
b2b67cfcd66e
- Fix bug in child-exit handling where the wrong pid was being matched.
Matt Johnston <matt@ucc.asn.au>
parents:
416
diff
changeset
|
779 len, errno, fd)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
780 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
781 } |
673
c519b78b6d1a
- Don't sent SSH_MSG_UNIMPLEMENTED if we don't have ENABLE_SVR_REMOTETCPFWD
Matt Johnston <matt@ucc.asn.au>
parents:
652
diff
changeset
|
782 |
722
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
783 if (channel->read_mangler) { |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
784 channel->read_mangler(channel, buf_getwriteptr(ses.writepayload, len), &len); |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
785 if (len == 0) { |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
786 buf_setpos(ses.writepayload, 0); |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
787 buf_setlen(ses.writepayload, 0); |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
788 return; |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
789 } |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
790 } |
4a274f47eabd
Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents:
709
diff
changeset
|
791 |
673
c519b78b6d1a
- Don't sent SSH_MSG_UNIMPLEMENTED if we don't have ENABLE_SVR_REMOTETCPFWD
Matt Johnston <matt@ucc.asn.au>
parents:
652
diff
changeset
|
792 TRACE(("send_msg_channel_data: len %d fd %d", len, fd)) |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
793 buf_incrwritepos(ses.writepayload, len); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
794 /* ... real size here */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
795 buf_setpos(ses.writepayload, size_pos); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
796 buf_putint(ses.writepayload, len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
797 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
798 channel->transwindow -= len; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
799 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
800 encrypt_packet(); |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
801 |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
802 /* If we receive less data than we requested when flushing, we've |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
803 reached the equivalent of EOF */ |
433
c216212001fc
Fix for -pedantic -ansi compilation, change // to /**/, plus some signedness
Matt Johnston <matt@ucc.asn.au>
parents:
423
diff
changeset
|
804 if (channel->flushing && len < (ssize_t)maxlen) |
416
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
805 { |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
806 TRACE(("closing from channel, flushing out.")) |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
807 close_chan_fd(channel, fd, SHUT_RD); |
a01c0c8e543a
Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents:
415
diff
changeset
|
808 } |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
809 TRACE(("leave send_msg_channel_data")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
810 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
811 |
107 | 812 /* We receive channel data */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
813 void recv_msg_channel_data() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
814 |
107 | 815 struct Channel *channel; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
816 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
817 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
818 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
819 common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf); |
107 | 820 } |
821 | |
822 /* Shared for data and stderr data - when we receive data, put it in a buffer | |
823 * for writing to the local file descriptor */ | |
824 void common_recv_msg_channel_data(struct Channel *channel, int fd, | |
825 circbuffer * cbuf) { | |
826 | |
827 unsigned int datalen; | |
828 unsigned int maxdata; | |
829 unsigned int buflen; | |
830 unsigned int len; | |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
831 unsigned int consumed; |
107 | 832 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
833 TRACE(("enter recv_msg_channel_data")) |
107 | 834 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
835 if (channel->recv_eof) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
513
diff
changeset
|
836 dropbear_exit("Received data after eof"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
837 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
838 |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
839 if (fd < 0 || !cbuf) { |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
840 /* If we have encountered failed write, the far side might still |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
841 * be sending data without having yet received our close notification. |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
842 * We just drop the data. */ |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
843 return; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
844 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
845 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
846 datalen = buf_getint(ses.payload); |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
847 TRACE(("length %d", datalen)) |
107 | 848 |
849 maxdata = cbuf_getavail(cbuf); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
850 |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
851 /* Whilst the spec says we "MAY ignore data past the end" this could |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
852 * lead to corrupted file transfers etc (chunks missed etc). It's better to |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
853 * just die horribly */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
854 if (datalen > maxdata) { |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
855 dropbear_exit("Oversized packet"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
856 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
857 |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
858 dropbear_assert(channel->recvwindow >= datalen); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
859 channel->recvwindow -= datalen; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
860 dropbear_assert(channel->recvwindow <= opts.recv_window); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
861 |
1075
cc6116cc0b5c
Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents:
1074
diff
changeset
|
862 /* Attempt to write the data immediately without having to put it in the circular buffer */ |
1054
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
863 consumed = datalen; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
864 writechannel(channel, fd, cbuf, buf_getptr(ses.payload, datalen), &consumed); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
865 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
866 datalen -= consumed; |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
867 buf_incrpos(ses.payload, consumed); |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
868 |
c71df09bc610
Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents:
1049
diff
changeset
|
869 |
107 | 870 /* We may have to run throught twice, if the buffer wraps around. Can't |
871 * just "leave it for next time" like with writechannel, since this | |
872 * is payload data */ | |
873 len = datalen; | |
874 while (len > 0) { | |
875 buflen = cbuf_writelen(cbuf); | |
876 buflen = MIN(buflen, len); | |
877 | |
878 memcpy(cbuf_writeptr(cbuf, buflen), | |
879 buf_getptr(ses.payload, buflen), buflen); | |
880 cbuf_incrwrite(cbuf, buflen); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
881 buf_incrpos(ses.payload, buflen); |
107 | 882 len -= buflen; |
883 } | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
884 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
885 TRACE(("leave recv_msg_channel_data")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
886 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
887 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
888 /* Increment the outgoing data window for a channel - the remote end limits |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
889 * the amount of data which may be transmitted, this window is decremented |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
890 * as data is sent, and incremented upon receiving window-adjust messages */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
891 void recv_msg_channel_window_adjust() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
892 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
893 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
894 unsigned int incr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
895 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
896 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
897 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
898 incr = 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:
156
diff
changeset
|
899 TRACE(("received window increment %d", incr)) |
448
9c61e7af0156
Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents:
439
diff
changeset
|
900 incr = MIN(incr, TRANS_MAX_WIN_INCR); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
901 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
902 channel->transwindow += incr; |
448
9c61e7af0156
Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents:
439
diff
changeset
|
903 channel->transwindow = MIN(channel->transwindow, TRANS_MAX_WINDOW); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
904 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
905 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
906 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
907 /* Increment the incoming data window for a channel, and let the remote |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
908 * end know */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
909 static void send_msg_channel_window_adjust(struct Channel* channel, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
910 unsigned int incr) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
911 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
912 TRACE(("sending window adjust %d", incr)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
913 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
914 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
915 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_WINDOW_ADJUST); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
916 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
917 buf_putint(ses.writepayload, incr); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
918 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
919 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
920 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
921 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
922 /* Handle a new channel request, performing any channel-type-specific setup */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
923 void recv_msg_channel_open() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
924 |
1094
c45d65392c1a
Fix pointer differ in signess warnings [-Werror=pointer-sign]
Gaël PORTAY <gael.portay@gmail.com>
parents:
1079
diff
changeset
|
925 char *type; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
926 unsigned int typelen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
927 unsigned int remotechan, transwindow, transmaxpacket; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
928 struct Channel *channel; |
7 | 929 const struct ChanType **cp; |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
930 const struct ChanType *chantype; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
931 unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
932 int ret; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
933 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
934 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
935 TRACE(("enter recv_msg_channel_open")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
936 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
937 /* get the packet contents */ |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1098
diff
changeset
|
938 type = buf_getstring(ses.payload, &typelen); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
939 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
940 remotechan = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
941 transwindow = buf_getint(ses.payload); |
448
9c61e7af0156
Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents:
439
diff
changeset
|
942 transwindow = MIN(transwindow, TRANS_MAX_WINDOW); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
943 transmaxpacket = buf_getint(ses.payload); |
448
9c61e7af0156
Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents:
439
diff
changeset
|
944 transmaxpacket = MIN(transmaxpacket, TRANS_MAX_PAYLOAD_LEN); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
945 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
946 /* figure what type of packet it is */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
947 if (typelen > MAX_NAME_LEN) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
948 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
949 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
950 |
7 | 951 /* Get the channel type. Client and server style invokation will set up a |
952 * different list for ses.chantypes at startup. We just iterate through | |
953 * this list and find the matching name */ | |
954 for (cp = &ses.chantypes[0], chantype = (*cp); | |
955 chantype != NULL; | |
956 cp++, chantype = (*cp)) { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
957 if (strcmp(type, chantype->name) == 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
958 break; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
959 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
960 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
961 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
962 if (chantype == NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
963 TRACE(("No matching type for '%s'", type)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
964 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
965 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
966 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
967 TRACE(("matched type '%s'", type)) |
7 | 968 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
969 /* create the channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
970 channel = newchannel(remotechan, chantype, transwindow, transmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
971 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
972 if (channel == NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
973 TRACE(("newchannel returned NULL")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
974 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
975 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
976 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
977 if (channel->type->inithandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
978 ret = channel->type->inithandler(channel); |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
979 if (ret == SSH_OPEN_IN_PROGRESS) { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
980 /* We'll send the confirmation later */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
981 goto cleanup; |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
982 } |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
983 if (ret > 0) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
984 errtype = ret; |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
985 remove_channel(channel); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
986 TRACE(("inithandler returned failure %d", ret)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
987 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
988 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
989 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
990 |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
991 if (channel->prio == DROPBEAR_CHANNEL_PRIO_EARLY) { |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
992 channel->prio = DROPBEAR_CHANNEL_PRIO_BULK; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
993 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
994 |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
995 chan_initwritebuf(channel); |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
996 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
997 /* success */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
998 send_msg_channel_open_confirmation(channel, channel->recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
999 channel->recvmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1000 goto cleanup; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1001 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1002 failure: |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1003 TRACE(("recv_msg_channel_open failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1004 send_msg_channel_open_failure(remotechan, errtype, "", ""); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1005 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1006 cleanup: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1007 m_free(type); |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1008 |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1009 update_channel_prio(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1010 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1011 TRACE(("leave recv_msg_channel_open")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1012 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1013 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1014 /* Send a failure message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1015 void send_msg_channel_failure(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1016 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1017 TRACE(("enter send_msg_channel_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1018 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1019 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1020 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1021 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1022 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1023 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:
156
diff
changeset
|
1024 TRACE(("leave send_msg_channel_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1025 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1026 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1027 /* Send a success message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1028 void send_msg_channel_success(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1029 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1030 TRACE(("enter send_msg_channel_success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1031 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1032 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1033 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_SUCCESS); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1034 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1035 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1036 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:
156
diff
changeset
|
1037 TRACE(("leave send_msg_channel_success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1038 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1039 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1040 /* Send a channel open failure message, with a corresponding reason |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1041 * code (usually resource shortage or unknown chan type) */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1042 static void send_msg_channel_open_failure(unsigned int remotechan, |
1098
f95b6e87cd0c
Turn send_msg_channel_open_failure()'s text and lang into const char *
Gaël PORTAY <gael.portay@gmail.com>
parents:
1097
diff
changeset
|
1043 int reason, const char *text, const char *lang) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1044 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1045 TRACE(("enter send_msg_channel_open_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1046 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1047 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1048 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1049 buf_putint(ses.writepayload, remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1050 buf_putint(ses.writepayload, reason); |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1098
diff
changeset
|
1051 buf_putstring(ses.writepayload, text, strlen(text)); |
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1098
diff
changeset
|
1052 buf_putstring(ses.writepayload, lang, strlen(lang)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1053 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1054 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:
156
diff
changeset
|
1055 TRACE(("leave send_msg_channel_open_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1056 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1057 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1058 /* Confirm a channel open, and let the remote end know what number we've |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1059 * allocated and the receive parameters */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1060 static void send_msg_channel_open_confirmation(struct Channel* channel, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1061 unsigned int recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1062 unsigned int recvmaxpacket) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1063 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1064 TRACE(("enter send_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1065 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1066 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1067 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN_CONFIRMATION); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1068 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1069 buf_putint(ses.writepayload, channel->index); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1070 buf_putint(ses.writepayload, recvwindow); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1071 buf_putint(ses.writepayload, recvmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1072 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1073 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:
156
diff
changeset
|
1074 TRACE(("leave send_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1075 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1076 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1077 /* close a fd, how is SHUT_RD or SHUT_WR */ |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1078 static void close_chan_fd(struct Channel *channel, int fd, int how) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1079 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1080 int closein = 0, closeout = 0; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1081 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1082 if (channel->type->sepfds) { |
375 | 1083 TRACE(("SHUTDOWN(%d, %d)", fd, how)) |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1084 shutdown(fd, how); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1085 if (how == 0) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1086 closeout = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1087 } else { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1088 closein = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1089 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1090 } else { |
375 | 1091 TRACE(("CLOSE some fd %d", fd)) |
1039
d0e6dd5af46e
Use m_close() which will avoid close(-1)
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
1092 m_close(fd); |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1093 closein = closeout = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1094 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1095 |
375 | 1096 if (closeout && (fd == channel->readfd)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1097 channel->readfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1098 } |
375 | 1099 if (closeout && ERRFD_IS_READ(channel) && (fd == channel->errfd)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1100 channel->errfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1101 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1102 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1103 if (closein && fd == channel->writefd) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1104 channel->writefd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1105 } |
375 | 1106 if (closein && ERRFD_IS_WRITE(channel) && (fd == channel->errfd)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1107 channel->errfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1108 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1109 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1110 /* if we called shutdown on it and all references are gone, then we |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1111 * need to close() it to stop it lingering */ |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1112 if (channel->type->sepfds && channel->readfd == FD_CLOSED |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1113 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) { |
375 | 1114 TRACE(("CLOSE (finally) of %d", fd)) |
1039
d0e6dd5af46e
Use m_close() which will avoid close(-1)
Matt Johnston <matt@ucc.asn.au>
parents:
1038
diff
changeset
|
1115 m_close(fd); |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1116 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1117 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1118 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
1119 |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
1120 #if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1121 /* Create a new channel, and start the open request. This is intended |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1122 * for X11, agent, tcp forwarding, and should be filled with channel-specific |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1123 * options, with the calling function calling encrypt_packet() after |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1124 * completion. It is mandatory for the caller to encrypt_packet() if |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1125 * a channel is returned. NULL is returned on failure. */ |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
1126 int send_msg_channel_open_init(int fd, const struct ChanType *type) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1127 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1128 struct Channel* chan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1129 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1130 TRACE(("enter send_msg_channel_open_init()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1131 chan = newchannel(0, type, 0, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1132 if (!chan) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1133 TRACE(("leave send_msg_channel_open_init() - FAILED in newchannel()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1134 return DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1135 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1136 |
707
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
1137 /* Outbound opened channels don't make use of in-progress connections, |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
1138 * we can set it up straight away */ |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
1139 chan_initwritebuf(chan); |
564e7f87ecc3
Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents:
673
diff
changeset
|
1140 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1141 /* set fd non-blocking */ |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
1142 setnonblocking(fd); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1143 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
1144 chan->writefd = chan->readfd = fd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1145 ses.maxfd = MAX(ses.maxfd, fd); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1146 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1147 chan->await_open = 1; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1148 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1149 /* now open the channel connection */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1150 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1151 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1152 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN); |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1098
diff
changeset
|
1153 buf_putstring(ses.writepayload, type->name, strlen(type->name)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1154 buf_putint(ses.writepayload, chan->index); |
449
3e6c536bc023
Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents:
448
diff
changeset
|
1155 buf_putint(ses.writepayload, opts.recv_window); |
906
4696755c4cac
A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents:
896
diff
changeset
|
1156 buf_putint(ses.writepayload, RECV_MAX_CHANNEL_DATA_LEN); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1157 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1158 TRACE(("leave send_msg_channel_open_init()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1159 return DROPBEAR_SUCCESS; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1160 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1161 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1162 /* Confirmation that our channel open request (for forwardings) was |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1163 * successful*/ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1164 void recv_msg_channel_open_confirmation() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1165 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1166 struct Channel * channel; |
37 | 1167 int ret; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1168 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1169 TRACE(("enter recv_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1170 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
1171 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1172 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1173 if (!channel->await_open) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
513
diff
changeset
|
1174 dropbear_exit("Unexpected channel reply"); |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1175 } |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1176 channel->await_open = 0; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1177 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1178 channel->remotechan = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1179 channel->transwindow = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1180 channel->transmaxpacket = buf_getint(ses.payload); |
13
db2c8e6fb284
Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents:
9
diff
changeset
|
1181 |
187
c44df7123b0a
compile fix when TRACE debugging is enabled
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
1182 TRACE(("new chan remote %d local %d", |
c44df7123b0a
compile fix when TRACE debugging is enabled
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
1183 channel->remotechan, channel->index)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1184 |
37 | 1185 /* Run the inithandler callback */ |
1186 if (channel->type->inithandler) { | |
1187 ret = channel->type->inithandler(channel); | |
1188 if (ret > 0) { | |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
1189 remove_channel(channel); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1190 TRACE(("inithandler returned failure %d", ret)) |
944
2e402a09e21e
Avoid use-after-free when channel inithandler fails. Thanks to Coverity
Matt Johnston <matt@ucc.asn.au>
parents:
941
diff
changeset
|
1191 return; |
37 | 1192 } |
1193 } | |
1194 | |
941
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1195 if (channel->prio == DROPBEAR_CHANNEL_PRIO_EARLY) { |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1196 channel->prio = DROPBEAR_CHANNEL_PRIO_BULK; |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1197 } |
5daedffd0769
Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents:
938
diff
changeset
|
1198 update_channel_prio(); |
13
db2c8e6fb284
Fixed stupid agentfwd error (using the listening FD, not the accepted on. gah)
Matt Johnston <matt@ucc.asn.au>
parents:
9
diff
changeset
|
1199 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1200 TRACE(("leave recv_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1201 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1202 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1203 /* Notification that our channel open request failed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1204 void recv_msg_channel_open_failure() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1205 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1206 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1207 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
1208 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1209 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1210 if (!channel->await_open) { |
594
a98a2138364a
Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents:
513
diff
changeset
|
1211 dropbear_exit("Unexpected channel reply"); |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1212 } |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1213 channel->await_open = 0; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1214 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
1215 remove_channel(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1216 } |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
1217 #endif /* USING_LISTENERS */ |
937
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1218 |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1219 void send_msg_request_success() { |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1220 CHECKCLEARTOWRITE(); |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1221 buf_putbyte(ses.writepayload, SSH_MSG_REQUEST_SUCCESS); |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1222 encrypt_packet(); |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1223 } |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1224 |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1225 void send_msg_request_failure() { |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1226 CHECKCLEARTOWRITE(); |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1227 buf_putbyte(ses.writepayload, SSH_MSG_REQUEST_FAILURE); |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1228 encrypt_packet(); |
4ad38e223ccd
Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents:
936
diff
changeset
|
1229 } |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1230 |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1231 struct Channel* get_any_ready_channel() { |
1038
d3925ed45a85
Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents:
970
diff
changeset
|
1232 size_t i; |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1233 if (ses.chancount == 0) { |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1234 return NULL; |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1235 } |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1236 for (i = 0; i < ses.chansize; i++) { |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1237 struct Channel *chan = ses.channels[i]; |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1238 if (chan |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1239 && !(chan->sent_eof || chan->recv_eof) |
1025 | 1240 && !(chan->await_open)) { |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1241 return chan; |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1242 } |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1243 } |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1244 return NULL; |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1245 } |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1246 |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1247 void start_send_channel_request(struct Channel *channel, |
1097
93e29b0ef8dc
Turn start_send_channel_request()'s type argument into char *
Gaël PORTAY <gael.portay@gmail.com>
parents:
1094
diff
changeset
|
1248 char *type) { |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1249 |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1250 CHECKCLEARTOWRITE(); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1251 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_REQUEST); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1252 buf_putint(ses.writepayload, channel->remotechan); |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1253 |
1122
aaf576b27a10
Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents:
1098
diff
changeset
|
1254 buf_putstring(ses.writepayload, type, strlen(type)); |
970
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1255 |
0bb16232e7c4
Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents:
955
diff
changeset
|
1256 } |