annotate common-channel.c @ 1553:cc256c6dca96

bump debian changelog
author Matt Johnston <matt@ucc.asn.au>
date Tue, 27 Feb 2018 22:14:46 +0800
parents 06d52bcb8094
children 5916af64acd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 /*
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
2 * Dropbear SSH
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 *
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
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
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
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"
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
35 #include "listener.h"
449
3e6c536bc023 Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents: 448
diff changeset
36 #include "runopts.h"
1032
0da8ba489c23 Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents: 1025
diff changeset
37 #include "netio.h"
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 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
40 const char *text, const char *lang);
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
41 static void send_msg_channel_open_confirmation(const struct Channel* channel,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 unsigned int recvwindow,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 unsigned int recvmaxpacket);
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
44 static int writechannel(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
45 const unsigned char *moredata, unsigned int *morelen);
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
46 static void send_msg_channel_window_adjust(const struct Channel *channel,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47 unsigned int incr);
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
48 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
49 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
50 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
51 static void remove_channel(struct Channel *channel);
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
52 static unsigned int write_pending(const struct Channel * channel);
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
53 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
54 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
55
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
56 #define FD_UNINIT (-2)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
57 #define FD_CLOSED (-1)
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
59 #define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL)
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
60 #define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel))
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
61
906
4696755c4cac A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents: 896
diff changeset
62 /* 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
63 * 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
64 * 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
65 * 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
66 */
4696755c4cac A few fixes for cases where compression increases payload sizes, and
Matt Johnston <matt@ucc.asn.au>
parents: 896
diff changeset
67 #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
68
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69 /* Initialise all the channels */
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
70 void chaninitialise(const struct ChanType *chantypes[]) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72 /* 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
73 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
74 ses.chansize = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 ses.channels[0] = NULL;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
76 ses.chancount = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78 ses.chantypes = chantypes;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1192
diff changeset
80 #if DROPBEAR_LISTENERS
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
81 listeners_initialise();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83
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 /* Clean up channels, freeing allocated memory */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 void chancleanup() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90
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
91 TRACE(("enter chancleanup"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 for (i = 0; i < ses.chansize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 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
94 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
95 remove_channel(ses.channels[i]);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 }
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 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
99 TRACE(("leave chancleanup"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 }
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 /* 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
103 /* 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
104 * 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
105 * 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
106 static struct Channel* newchannel(unsigned int remotechan,
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
107 const struct ChanType *type,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 unsigned int transwindow, unsigned int transmaxpacket) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 struct Channel * newchan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 unsigned int i, j;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
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
113 TRACE(("enter newchannel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115 /* first see if we can use existing channels */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 for (i = 0; i < ses.chansize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 if (ses.channels[i] == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 break;
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 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
122 /* otherwise extend the list */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123 if (i == ses.chansize) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 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
125 TRACE(("leave newchannel: max chans reached"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 return NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
127 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 /* extend the channels */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 ses.channels = (struct Channel**)m_realloc(ses.channels,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 (ses.chansize+CHAN_EXTEND_SIZE)*sizeof(struct Channel*));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 ses.chansize += CHAN_EXTEND_SIZE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 /* set the new channels to null */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 for (j = i; j < ses.chansize; j++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 ses.channels[j] = NULL;
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
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 newchan = (struct Channel*)m_malloc(sizeof(struct Channel));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 newchan->type = type;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 newchan->index = i;
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
145 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
146 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
147 newchan->close_handler_done = 0;
4
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 newchan->remotechan = remotechan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 newchan->transwindow = transwindow;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 newchan->transmaxpacket = transmaxpacket;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 newchan->typedata = NULL;
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
154 newchan->writefd = FD_UNINIT;
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
155 newchan->readfd = FD_UNINIT;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 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
157 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
158 newchan->flushing = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
160 newchan->writebuf = cbuf_new(opts.recv_window);
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
161 newchan->recvwindow = opts.recv_window;
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
162
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
163 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
164 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
165 newchan->recvmaxpacket = RECV_MAX_CHANNEL_DATA_LEN;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
166
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
167 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
168
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169 ses.channels[i] = newchan;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
170 ses.chancount++;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
171
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
172 TRACE(("leave newchannel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174 return newchan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
177 /* 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
178 * 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
179 * 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
180 * channel */
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
181 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
182
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
183 unsigned int chan;
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
184
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
185 chan = buf_getint(ses.payload);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 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
187 if (kind) {
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
188 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
189 } else {
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
190 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
191 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 return ses.channels[chan];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
196 struct Channel* getchannel() {
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
197 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
198 }
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
199
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
200 /* Iterate through the channels, performing IO if available */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
201 void channelio(const fd_set *readfds, const fd_set *writefds) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
202
936
d93a6bcf616f Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents: 906
diff changeset
203 /* Listeners such as TCP, X11, agent-auth */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 struct Channel *channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
207 /* foreach channel */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 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
209 /* 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
210 int do_check_close = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 channel = ses.channels[i];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 if (channel == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 /* only process in-use channels */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215 continue;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
216 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
217
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
218 /* 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
219 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
220 TRACE(("send normal readfd"))
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
221 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
222 do_check_close = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
224
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
225 /* 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
226 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
227 && 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
228 TRACE(("send normal errfd"))
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
229 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
230 do_check_close = 1;
395
dc37bd8563e8 disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents: 394
diff changeset
231 }
dc37bd8563e8 disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents: 394
diff changeset
232
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
233 /* 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
234 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
235 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
236 do_check_close = 1;
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
237 }
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
238
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
239 /* stderr for client mode */
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
240 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
241 && 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
242 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
243 do_check_close = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244 }
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
245
36eacc322e00 Make sure the check_close() handler runs when a server child process exits
Matt Johnston <matt@ucc.asn.au>
parents: 944
diff changeset
246 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
247 /* 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
248 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
249 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
251 /* 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
252 if (do_check_close) {
d93a6bcf616f Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents: 906
diff changeset
253 check_close(channel);
d93a6bcf616f Improve handling lots of concurrent forwarded connections. Increase
Matt Johnston <matt@ucc.asn.au>
parents: 906
diff changeset
254 }
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
255 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1192
diff changeset
257 #if DROPBEAR_LISTENERS
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
258 handle_listeners(readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
262
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
263 /* 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
264 * stderr of a channel's endpoint. */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
265 static unsigned int write_pending(const struct Channel * channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
266
709
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
267 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
268 return 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
269 } else if (channel->errfd >= 0 && channel->extrabuf &&
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
270 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
271 return 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
272 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
273 return 0;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
274 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
276
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
277 /* EOF/close handling */
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
278 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
279 int close_allowed = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
280
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 722
diff changeset
281 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
282 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
283 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
284 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
285 channel->writebuf ? cbuf_getused(channel->writebuf) : 0,
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
286 channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0))
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
287
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
288 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
289 && !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
290 && 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
291 && 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
292 {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
293 channel->flushing = 1;
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
294 }
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
295
504
950c38b854a1 Don't use // style comments
Matt Johnston <matt@ucc.asn.au>
parents: 495
diff changeset
296 /* 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
297 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
298 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
299 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
300 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
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(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
303 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
304 }
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
305
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
306 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
307 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
308 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
309 send_msg_channel_close(channel);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 }
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
311 remove_channel(channel);
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
312 return;
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
313 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
314
815
35183e8a7851 Improve EOF handling for half-close. Patch from Catalin Patulea
Matt Johnston <matt@ucc.asn.au>
parents: 770
diff changeset
315 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
316 /* 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
317 || (channel->type->check_close && close_allowed)) {
364
90cb290836de Passes most test cases now
Matt Johnston <matt@ucc.asn.au>
parents: 363
diff changeset
318 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
319 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
320
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
321 /* 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
322 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
323 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
324 if (channel->flushing) {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
325 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
326 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
327 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
328 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
329 }
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
330 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
331 && channel->transwindow > 0) {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
332 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
333 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
334 }
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
335 }
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
336
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
337 /* 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
338 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
339 && channel->readfd == FD_CLOSED
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
340 && (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)) {
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
341 send_msg_channel_eof(channel);
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
342 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
343
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
344 /* 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
345 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
346 && 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
347 && (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
348 && !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
349 && close_allowed
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
350 && !write_pending(channel)) {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
351 TRACE(("sending close, readfd is closed"))
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
352 send_msg_channel_close(channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
353 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
354 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
355
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356 /* 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
357 * 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
358 * 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
359 * function */
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
360 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
361
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
362 struct Channel *channel = user_data;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
364 TRACE(("enter channel_connect_done"))
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
365
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
366 if (result == DROPBEAR_SUCCESS)
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
367 {
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
368 channel->readfd = channel->writefd = sock;
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
369 channel->conn_pending = NULL;
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
370 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
371 channel->recvmaxpacket);
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
372 TRACE(("leave channel_connect_done: success"))
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
373 }
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
374 else
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
375 {
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
376 send_msg_channel_open_failure(channel->remotechan,
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
377 SSH_OPEN_CONNECT_FAILED, "", "");
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
378 remove_channel(channel);
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
379 TRACE(("leave check_in_progress: fail"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
381 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
382
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
383
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
384 /* 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
385 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
386
1038
d3925ed45a85 Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents: 970
diff changeset
387 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
388 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
389 && !channel->close_handler_done) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 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
391 channel->close_handler_done = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 }
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 CHECKCLEARTOWRITE();
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 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
397 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
398
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
399 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
400
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
401 channel->sent_eof = 1;
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
402 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
403 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
404 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
405 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
406 TRACE(("leave send_msg_channel_close"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
407 }
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 /* call this when trans/eof channels are closed */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410 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
411
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
412 TRACE(("enter send_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_EOF);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
416 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
418 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
420 channel->sent_eof = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
421
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
422 TRACE(("leave send_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
424
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
425 #ifndef HAVE_WRITEV
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
426 static int writechannel_fallback(struct Channel* channel, int fd, circbuffer *cbuf,
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
427 const unsigned char *UNUSED(moredata), unsigned int *morelen) {
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
428
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
429 unsigned char *circ_p1, *circ_p2;
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
430 unsigned int circ_len1, circ_len2;
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
431 ssize_t written;
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
432
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
433 if (morelen) {
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
434 /* fallback doesn't consume moredata */
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
435 *morelen = 0;
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
436 }
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
437
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
438 /* Write the first portion of the circular buffer */
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
439 cbuf_readptrs(cbuf, &circ_p1, &circ_len1, &circ_p2, &circ_len2);
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
440 written = write(fd, circ_p1, circ_len1);
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
441 if (written < 0) {
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
442 if (errno != EINTR && errno != EAGAIN) {
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
443 TRACE(("channel IO write error fd %d %s", fd, strerror(errno)))
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
444 close_chan_fd(channel, fd, SHUT_WR);
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
445 return DROPBEAR_FAILURE;
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
446 }
1192
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
447 } else {
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
448 cbuf_incrread(cbuf, written);
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
449 channel->recvdonelen += written;
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
450 }
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
451 return DROPBEAR_SUCCESS;
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
452 }
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
453 #endif /* !HAVE_WRITEV */
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
454
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
455 #ifdef HAVE_WRITEV
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
456 static int 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
457 const unsigned char *moredata, unsigned int *morelen) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
458
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
459 struct iovec iov[3];
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
460 unsigned char *circ_p1, *circ_p2;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
461 unsigned int circ_len1, circ_len2;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
462 int io_count = 0;
1192
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
463
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
464 ssize_t written;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
465
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
466 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
467
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
468 if (circ_len1 > 0) {
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
469 TRACE(("circ1 %d", circ_len1))
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
470 iov[io_count].iov_base = circ_p1;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
471 iov[io_count].iov_len = circ_len1;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
472 io_count++;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
473 }
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
474
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
475 if (circ_len2 > 0) {
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
476 TRACE(("circ2 %d", circ_len2))
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
477 iov[io_count].iov_base = circ_p2;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
478 iov[io_count].iov_len = circ_len2;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
479 io_count++;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
480 }
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
481
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
482 if (morelen) {
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
483 assert(moredata);
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
484 TRACE(("more %d", *morelen))
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
485 iov[io_count].iov_base = (void*)moredata;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
486 iov[io_count].iov_len = *morelen;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
487 io_count++;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
488 }
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
489
1075
cc6116cc0b5c Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents: 1074
diff changeset
490 if (io_count == 0) {
cc6116cc0b5c Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents: 1074
diff changeset
491 /* 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
492 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
493 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
494 TRACE(("leave writechannel, no data"))
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
495 return DROPBEAR_SUCCESS;
1075
cc6116cc0b5c Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents: 1074
diff changeset
496 }
cc6116cc0b5c Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents: 1074
diff changeset
497
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
498 if (morelen) {
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
499 /* Default return value, none consumed */
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
500 *morelen = 0;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
501 }
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
502
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
503 written = writev(fd, iov, io_count);
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
504
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
505 if (written < 0) {
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
506 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
507 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
508 close_chan_fd(channel, fd, SHUT_WR);
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
509 return DROPBEAR_FAILURE;
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
510 }
1192
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
511 } else {
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
512 int cbuf_written = MIN(circ_len1+circ_len2, (unsigned int)written);
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
513 cbuf_incrread(cbuf, cbuf_written);
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
514 if (morelen) {
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
515 *morelen = written - cbuf_written;
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
516 }
af940cefdba1 Fix "Avoid queueing into circbuffer when the channel is about to close"
Matt Johnston <matt@ucc.asn.au>
parents: 1191
diff changeset
517 channel->recvdonelen += written;
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
518 }
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
519 return DROPBEAR_SUCCESS;
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
520 }
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
521 #endif /* HAVE_WRITEV */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
522
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
523 /* Called to write data out to the local side of the channel.
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
524 Writes the circular buffer contents and also the "moredata" buffer
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
525 if not null. Will ignore EAGAIN.
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
526 Returns DROPBEAR_FAILURE if writing to fd had an error and the channel is being closed, DROPBEAR_SUCCESS otherwise */
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
527 static int writechannel(struct Channel* channel, int fd, circbuffer *cbuf,
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
528 const unsigned char *moredata, unsigned int *morelen) {
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
529 int ret = DROPBEAR_SUCCESS;
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
530 TRACE(("enter writechannel fd %d", fd))
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
531 #ifdef HAVE_WRITEV
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
532 ret = writechannel_writev(channel, fd, cbuf, moredata, morelen);
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
533 #else
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
534 ret = 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
535 #endif
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
536
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
537 /* Window adjust handling */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
538 if (channel->recvdonelen >= RECV_WINDOWEXTEND) {
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
539 send_msg_channel_window_adjust(channel, channel->recvdonelen);
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
540 channel->recvwindow += channel->recvdonelen;
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
541 channel->recvdonelen = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
542 }
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
543
449
3e6c536bc023 Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents: 448
diff changeset
544 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
545 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
546 dropbear_assert(channel->extrabuf == NULL ||
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
547 channel->recvwindow <= cbuf_getavail(channel->extrabuf));
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
548
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
549 TRACE(("leave writechannel"))
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
550 return ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
552
1079
acf444bcb115 Fix no-writev fallback
Matt Johnston <matt@ucc.asn.au>
parents: 1075
diff changeset
553
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
554 /* 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
555 * 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
556 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
557
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
558 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
559 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
560
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
561 for (i = 0; i < ses.chansize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
562
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
563 channel = ses.channels[i];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
564 if (channel == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
565 continue;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
566 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
567
896
a1a97e98b0c1 Read (and enqueue) packets from interactive input even when
Matt Johnston <matt@ucc.asn.au>
parents: 815
diff changeset
568 /* 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
569 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
570 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
571 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
572 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
573 if (channel->transwindow > 0
1074
10f198d4a308 Make main socket nonblocking. Limit writequeue size.
Matt Johnston <matt@ucc.asn.au>
parents: 1072
diff changeset
574 && ((ses.dataallowed && allow_reads) || channel->read_mangler)) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
575
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
576 if (channel->readfd >= 0) {
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
577 FD_SET(channel->readfd, readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 }
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
579
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
580 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
581 FD_SET(channel->errfd, readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
583 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
584
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
585 /* Stuff from the wire */
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
586 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
587 FD_SET(channel->writefd, writefds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
588 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
589
433
c216212001fc Fix for -pedantic -ansi compilation, change // to /**/, plus some signedness
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
590 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
591 && 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
592 FD_SET(channel->errfd, writefds);
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
593 }
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
594
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
595 } /* foreach channel */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
596
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1192
diff changeset
597 #if DROPBEAR_LISTENERS
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
598 set_listener_fds(readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
599 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
600
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
601 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
602
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
603 /* 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
604 * 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
605 * etc) FD is also EOF */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
606 void recv_msg_channel_eof() {
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 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
609
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
610 TRACE(("enter recv_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
611
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
612 channel = getchannel_msg("EOF");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
613
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
614 channel->recv_eof = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
615
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
616 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
617 TRACE(("leave recv_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
618 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
619
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
620
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
621 /* 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
622 void recv_msg_channel_close() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
623
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
624 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
625
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
626 TRACE(("enter recv_msg_channel_close"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
627
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
628 channel = getchannel_msg("Close");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
629
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
630 channel->recv_eof = 1;
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
631 channel->recv_close = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
632
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
633 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
634 TRACE(("leave recv_msg_channel_close"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
635 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
636
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
637 /* 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
638 * channel close */
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
639 static void remove_channel(struct Channel * channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
640
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
641 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
642 TRACE(("channel index is %d", channel->index))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
643
709
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
644 cbuf_free(channel->writebuf);
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
645 channel->writebuf = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
646
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
647 if (channel->extrabuf) {
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
648 cbuf_free(channel->extrabuf);
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
649 channel->extrabuf = NULL;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
650 }
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
651
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
652
938
c88dce72f6d2 Make sure client exit messages don't get lost
Matt Johnston <matt@ucc.asn.au>
parents: 937
diff changeset
653 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
654 /* 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
655 * 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
656 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
657 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
658 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
659 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
660 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
661 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
662 }
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
663
770
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
664 if (!channel->close_handler_done
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
665 && channel->type->closehandler) {
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
666 channel->type->closehandler(channel);
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
667 channel->close_handler_done = 1;
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
668 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
669
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
670 if (channel->conn_pending) {
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
671 cancel_connect(channel->conn_pending);
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
672 }
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
673
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
674 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
675 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
676 ses.chancount--;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
677
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
678 update_channel_prio();
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
679
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
680 TRACE(("leave remove_channel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
681 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
682
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
683 /* 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
684 * such as chansession or x11fwd */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
685 void recv_msg_channel_request() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
686
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
687 struct Channel *channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
688
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
689 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
690
1038
d3925ed45a85 Fix for old compilers, variable declarations at beginning of functions
Thorsten Horstmann <thorsten.horstmann@web.de>
parents: 970
diff changeset
691 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
692
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
693 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
694 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
695 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
696 }
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
697
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
698 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
699 && !channel->close_handler_done) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
700 channel->type->reqhandler(channel);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
701 } 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
702 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
703 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
704 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
705 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
706 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
707 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
708 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
709
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
710 TRACE(("leave recv_msg_channel_request"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
711
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
712 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
713
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
714 /* 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
715 * channel_data packet to send.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
716 * 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
717 * 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
718 * exttype */
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
719 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
720
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
721 int len;
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
722 size_t maxlen, size_pos;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
723 int fd;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
724
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
725 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
726
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
727 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
728 dropbear_assert(!channel->sent_close);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
729
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
730 if (isextended) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
731 fd = channel->errfd;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
732 } else {
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
733 fd = channel->readfd;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
734 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
735 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
736 dropbear_assert(fd >= 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
737
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
738 maxlen = MIN(channel->transwindow, channel->transmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
739 /* -(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
740 * exttype if is extended */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
741 maxlen = MIN(maxlen,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
742 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
743 TRACE(("maxlen %zd", maxlen))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
744 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
745 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
746 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
747 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
748
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
749 buf_putbyte(ses.writepayload,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
750 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
751 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
752 if (isextended) {
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
753 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
754 }
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
755 /* 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
756 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
757 buf_putint(ses.writepayload, 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
758
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
759 /* 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
760 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
761
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
762 if (len <= 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
763 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
764 /* 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
765 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
766 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
767 close_chan_fd(channel, fd, SHUT_RD);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
768 }
722
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
769 buf_setpos(ses.writepayload, 0);
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
770 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
771 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
772 len, errno, fd))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
773 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
774 }
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
775
722
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
776 if (channel->read_mangler) {
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
777 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
778 if (len == 0) {
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
779 buf_setpos(ses.writepayload, 0);
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
780 buf_setlen(ses.writepayload, 0);
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
781 return;
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
782 }
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
783 }
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
784
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
785 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
786 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
787 /* ... real size here */
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
788 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
789 buf_putint(ses.writepayload, len);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
790
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
791 channel->transwindow -= len;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
792
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
793 encrypt_packet();
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
794
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
795 /* 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
796 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
797 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
798 {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
799 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
800 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
801 }
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
802 TRACE(("leave send_msg_channel_data"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
803 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
804
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
805 /* We receive channel data */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
806 void recv_msg_channel_data() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
807
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
808 struct Channel *channel;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
809
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
810 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
811
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
812 common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf);
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
813 }
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
814
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
815 /* Shared for data and stderr data - when we receive data, put it in a buffer
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
816 * for writing to the local file descriptor */
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
817 void common_recv_msg_channel_data(struct Channel *channel, int fd,
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
818 circbuffer * cbuf) {
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
819
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
820 unsigned int datalen;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
821 unsigned int maxdata;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
822 unsigned int buflen;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
823 unsigned int len;
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
824 unsigned int consumed;
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
825 int res;
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
826
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
827 TRACE(("enter recv_msg_channel_data"))
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
828
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
829 if (channel->recv_eof) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 513
diff changeset
830 dropbear_exit("Received data after eof");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
831 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
832
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
833 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
834 /* 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
835 * 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
836 * 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
837 return;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
838 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
839
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
840 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
841 TRACE(("length %d", datalen))
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
842
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
843 maxdata = cbuf_getavail(cbuf);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
844
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
845 /* 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
846 * 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
847 * just die horribly */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
848 if (datalen > maxdata) {
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
849 dropbear_exit("Oversized packet");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
850 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
851
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
852 dropbear_assert(channel->recvwindow >= datalen);
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
853 channel->recvwindow -= datalen;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
854 dropbear_assert(channel->recvwindow <= opts.recv_window);
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
855
1075
cc6116cc0b5c Avoid channel writev() when there is nothing to write
Matt Johnston <matt@ucc.asn.au>
parents: 1074
diff changeset
856 /* 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
857 consumed = datalen;
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
858 res = writechannel(channel, fd, cbuf, buf_getptr(ses.payload, datalen), &consumed);
1054
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
859
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
860 datalen -= consumed;
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
861 buf_incrpos(ses.payload, consumed);
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
862
c71df09bc610 Avoid copying data into circular buffer
Matt Johnston <matt@ucc.asn.au>
parents: 1049
diff changeset
863
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
864 /* We may have to run throught twice, if the buffer wraps around. Can't
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
865 * just "leave it for next time" like with writechannel, since this
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
866 * is payload data.
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
867 * If the writechannel() failed then remaining data is discarded */
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
868 if (res == DROPBEAR_SUCCESS) {
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
869 len = datalen;
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
870 while (len > 0) {
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
871 buflen = cbuf_writelen(cbuf);
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
872 buflen = MIN(buflen, len);
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
873
1168
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
874 memcpy(cbuf_writeptr(cbuf, buflen),
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
875 buf_getptr(ses.payload, buflen), buflen);
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
876 cbuf_incrwrite(cbuf, buflen);
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
877 buf_incrpos(ses.payload, buflen);
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
878 len -= buflen;
509cf5df51c6 Avoid queueing into circbuffer when the channel is about to close
Matt Johnston <matt@ucc.asn.au>
parents: 1166
diff changeset
879 }
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
880 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
881
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
882 TRACE(("leave recv_msg_channel_data"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
883 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
884
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
885 /* 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
886 * 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
887 * 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
888 void recv_msg_channel_window_adjust() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
889
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
890 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
891 unsigned int incr;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
892
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
893 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
894
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
895 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
896 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
897 incr = MIN(incr, TRANS_MAX_WIN_INCR);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
898
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
899 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
900 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
901
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
902 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
903
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
904 /* 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
905 * end know */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
906 static void send_msg_channel_window_adjust(const struct Channel* channel,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
907 unsigned int incr) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
908
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
909 TRACE(("sending window adjust %d", incr))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
910 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
911
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
912 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
913 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
914 buf_putint(ses.writepayload, incr);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
915
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
916 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
917 }
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 /* 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
920 void recv_msg_channel_open() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
921
1094
c45d65392c1a Fix pointer differ in signess warnings [-Werror=pointer-sign]
Gaël PORTAY <gael.portay@gmail.com>
parents: 1079
diff changeset
922 char *type;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
923 unsigned int typelen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
924 unsigned int remotechan, transwindow, transmaxpacket;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
925 struct Channel *channel;
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
926 const struct ChanType **cp;
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
927 const struct ChanType *chantype;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
928 unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
929 int ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
930
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
931
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
932 TRACE(("enter recv_msg_channel_open"))
4
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 /* get the packet contents */
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1098
diff changeset
935 type = buf_getstring(ses.payload, &typelen);
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 remotechan = buf_getint(ses.payload);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
938 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
939 transwindow = MIN(transwindow, TRANS_MAX_WINDOW);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
940 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
941 transmaxpacket = MIN(transmaxpacket, TRANS_MAX_PAYLOAD_LEN);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
942
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
943 /* figure what type of packet it is */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
944 if (typelen > MAX_NAME_LEN) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
945 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
946 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
947
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
948 /* Get the channel type. Client and server style invokation will set up a
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
949 * different list for ses.chantypes at startup. We just iterate through
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
950 * this list and find the matching name */
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
951 for (cp = &ses.chantypes[0], chantype = (*cp);
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
952 chantype != NULL;
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
953 cp++, chantype = (*cp)) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
954 if (strcmp(type, chantype->name) == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
955 break;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
956 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
957 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
958
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
959 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
960 TRACE(("No matching type for '%s'", type))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
961 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
962 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
963
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
964 TRACE(("matched type '%s'", type))
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
965
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
966 /* create the channel */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
967 channel = newchannel(remotechan, chantype, transwindow, transmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
968
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
969 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
970 TRACE(("newchannel returned NULL"))
1166
b0f351edf370 Send SSH_OPEN_RESOURCE_SHORTAGE response when too many channels open
Matt Johnston <matt@ucc.asn.au>
parents: 1165
diff changeset
971 errtype = SSH_OPEN_RESOURCE_SHORTAGE;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
972 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
973 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
974
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
975 if (channel->type->inithandler) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
976 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
977 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
978 /* 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
979 goto cleanup;
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
980 }
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
981 if (ret > 0) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
982 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
983 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
984 TRACE(("inithandler returned failure %d", ret))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
985 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
986 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
987 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
988
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
989 if (channel->prio == DROPBEAR_CHANNEL_PRIO_EARLY) {
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
990 channel->prio = DROPBEAR_CHANNEL_PRIO_BULK;
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
991 }
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
992
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
993 /* success */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
994 send_msg_channel_open_confirmation(channel, channel->recvwindow,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
995 channel->recvmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
996 goto cleanup;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
997
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
998 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
999 TRACE(("recv_msg_channel_open failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1000 send_msg_channel_open_failure(remotechan, errtype, "", "");
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 cleanup:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1003 m_free(type);
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
1004
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
1005 update_channel_prio();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1006
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
1007 TRACE(("leave recv_msg_channel_open"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1008 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1009
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1010 /* Send a failure message */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
1011 void send_msg_channel_failure(const struct Channel *channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1012
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
1013 TRACE(("enter send_msg_channel_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1014 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1015
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1016 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1017 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1018
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1019 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
1020 TRACE(("leave send_msg_channel_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1021 }
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 /* Send a success message */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
1024 void send_msg_channel_success(const struct Channel *channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1025
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
1026 TRACE(("enter send_msg_channel_success"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1027 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1028
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1029 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_SUCCESS);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1030 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1031
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1032 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
1033 TRACE(("leave send_msg_channel_success"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1034 }
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 /* 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
1037 * code (usually resource shortage or unknown chan type) */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1038 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
1039 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
1040
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
1041 TRACE(("enter send_msg_channel_open_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1042 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1043
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1044 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
1045 buf_putint(ses.writepayload, remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1046 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
1047 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
1048 buf_putstring(ses.writepayload, lang, strlen(lang));
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1049
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1050 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
1051 TRACE(("leave send_msg_channel_open_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1052 }
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 /* 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
1055 * allocated and the receive parameters */
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
1056 static void send_msg_channel_open_confirmation(const struct Channel* channel,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1057 unsigned int recvwindow,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1058 unsigned int recvmaxpacket) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1059
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
1060 TRACE(("enter send_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1061 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1062
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1063 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
1064 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1065 buf_putint(ses.writepayload, channel->index);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1066 buf_putint(ses.writepayload, recvwindow);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1067 buf_putint(ses.writepayload, recvmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1068
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1069 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
1070 TRACE(("leave send_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1071 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1072
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1073 /* 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
1074 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
1075
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1076 int closein = 0, closeout = 0;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1077
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1078 if (channel->type->sepfds) {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
1079 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
1080 shutdown(fd, how);
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1081 if (how == 0) {
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1082 closeout = 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1083 } else {
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1084 closein = 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1085 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1086 } else {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
1087 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
1088 m_close(fd);
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1089 closein = closeout = 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1090 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1091
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
1092 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
1093 channel->readfd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1094 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
1095 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
1096 channel->errfd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1097 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1098
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1099 if (closein && fd == channel->writefd) {
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1100 channel->writefd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1101 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
1102 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
1103 channel->errfd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1104 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1105
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1106 /* 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
1107 * 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
1108 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
1109 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
1110 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
1111 m_close(fd);
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1112 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1113 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1114
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
1115
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1192
diff changeset
1116 #if (DROPBEAR_LISTENERS) || (DROPBEAR_CLIENT)
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1117 /* 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
1118 * 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
1119 * 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
1120 * 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
1121 * 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
1122 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
1123
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1124 struct Channel* chan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1125
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
1126 TRACE(("enter send_msg_channel_open_init()"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1127 chan = newchannel(0, type, 0, 0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1128 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
1129 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
1130 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1131 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1132
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
1133 /* 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
1134 * 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
1135
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1136 /* set fd non-blocking */
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
1137 setnonblocking(fd);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1138
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
1139 chan->writefd = chan->readfd = fd;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1140 ses.maxfd = MAX(ses.maxfd, fd);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1141
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1142 chan->await_open = 1;
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1143
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1144 /* now open the channel connection */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1145 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1146
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1147 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
1148 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
1149 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
1150 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
1151 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
1152
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
1153 TRACE(("leave send_msg_channel_open_init()"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1154 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1155 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1156
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1157 /* 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
1158 * successful*/
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1159 void recv_msg_channel_open_confirmation() {
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 struct Channel * channel;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1162 int ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1163
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
1164 TRACE(("enter recv_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1165
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
1166 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1167
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1168 if (!channel->await_open) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 513
diff changeset
1169 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
1170 }
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1171 channel->await_open = 0;
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1172
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1173 channel->remotechan = buf_getint(ses.payload);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1174 channel->transwindow = buf_getint(ses.payload);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1175 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
1176
187
c44df7123b0a compile fix when TRACE debugging is enabled
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
1177 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
1178 channel->remotechan, channel->index))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1179
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1180 /* Run the inithandler callback */
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1181 if (channel->type->inithandler) {
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1182 ret = channel->type->inithandler(channel);
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1183 if (ret > 0) {
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
1184 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
1185 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
1186 return;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1187 }
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1188 }
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1189
941
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
1190 if (channel->prio == DROPBEAR_CHANNEL_PRIO_EARLY) {
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
1191 channel->prio = DROPBEAR_CHANNEL_PRIO_BULK;
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
1192 }
5daedffd0769 Set tcp priority as follows:
Matt Johnston <matt@ucc.asn.au>
parents: 938
diff changeset
1193 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
1194
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
1195 TRACE(("leave recv_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1196 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1197
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1198 /* Notification that our channel open request failed */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1199 void recv_msg_channel_open_failure() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1200
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1201 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1202
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
1203 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1204
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1205 if (!channel->await_open) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 513
diff changeset
1206 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
1207 }
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1208 channel->await_open = 0;
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1209
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
1210 remove_channel(channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1211 }
1295
750ec4ec4cbe Convert #ifdef to #if, other build changes
Matt Johnston <matt@ucc.asn.au>
parents: 1192
diff changeset
1212 #endif /* DROPBEAR_LISTENERS */
937
4ad38e223ccd Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents: 936
diff changeset
1213
4ad38e223ccd Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents: 936
diff changeset
1214 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
1215 CHECKCLEARTOWRITE();
4ad38e223ccd Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents: 936
diff changeset
1216 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
1217 encrypt_packet();
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
4ad38e223ccd Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents: 936
diff changeset
1220 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
1221 CHECKCLEARTOWRITE();
4ad38e223ccd Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents: 936
diff changeset
1222 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
1223 encrypt_packet();
4ad38e223ccd Send a failure response if a client receives a global request
Matt Johnston <matt@ucc.asn.au>
parents: 936
diff changeset
1224 }
970
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1225
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1226 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
1227 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
1228 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
1229 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
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 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
1232 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
1233 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
1234 && !(chan->sent_eof || chan->recv_eof)
1025
02baa0b334e8 async connections working
Matt Johnston <matt@ucc.asn.au>
parents: 970
diff changeset
1235 && !(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
1236 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
1237 }
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1238 }
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1239 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
1240 }
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1241
1459
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
1242 void start_send_channel_request(const struct Channel *channel,
06d52bcb8094 Pointer parameter could be declared as pointing to const
Francois Perrad <francois.perrad@gadz.org>
parents: 1325
diff changeset
1243 const 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
1244
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1245 CHECKCLEARTOWRITE();
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1246 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
1247 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
1248
1122
aaf576b27a10 Merge pull request #13 from gazoo74/fix-warnings
Matt Johnston <matt@ucc.asn.au>
parents: 1098
diff changeset
1249 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
1250
0bb16232e7c4 Make keepalive handling more robust, this should now match what OpenSSH does
Matt Johnston <matt@ucc.asn.au>
parents: 955
diff changeset
1251 }