annotate common-channel.c @ 823:cb3cfcea1c8d

Fix debian installation of manpages
author Matt Johnston <matt@ucc.asn.au>
date Fri, 04 Oct 2013 21:49:32 +0800
parents 35183e8a7851
children a1a97e98b0c1
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"
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 #include "ssh.h"
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
36 #include "listener.h"
449
3e6c536bc023 Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents: 448
diff changeset
37 #include "runopts.h"
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,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 const unsigned char *text, const unsigned char *lang);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 static void send_msg_channel_open_confirmation(struct Channel* channel,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 unsigned int recvwindow,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 unsigned int recvmaxpacket);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
44 static void writechannel(struct Channel* channel, int fd, circbuffer *cbuf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 static void send_msg_channel_window_adjust(struct Channel *channel,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 unsigned int incr);
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
47 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
48 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
49 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
50 static void remove_channel(struct Channel *channel);
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
51 static void check_in_progress(struct Channel *channel);
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
52 static unsigned int write_pending(struct Channel * channel);
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
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
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62 /* Initialise all the channels */
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
63 void chaninitialise(const struct ChanType *chantypes[]) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 /* 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
66 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
67 ses.chansize = 1;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 ses.channels[0] = NULL;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
69 ses.chancount = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
70
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
71 ses.chantypes = chantypes;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
72
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
73 #ifdef USING_LISTENERS
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
74 listeners_initialise();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
76
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
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
79 /* Clean up channels, freeing allocated memory */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 void chancleanup() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
81
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
82 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83
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
84 TRACE(("enter chancleanup"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 for (i = 0; i < ses.chansize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 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
87 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
88 remove_channel(ses.channels[i]);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 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
92 TRACE(("leave chancleanup"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
93 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
94
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
95 static void
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
96 chan_initwritebuf(struct Channel *channel)
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
97 {
709
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
98 dropbear_assert(channel->writebuf->size == 0 && channel->recvwindow == 0);
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
99 cbuf_free(channel->writebuf);
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
100 channel->writebuf = cbuf_new(opts.recv_window);
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
101 channel->recvwindow = opts.recv_window;
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
102 }
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
103
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104 /* 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
105 /* 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
106 * 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
107 * 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
108 static struct Channel* newchannel(unsigned int remotechan,
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
109 const struct ChanType *type,
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110 unsigned int transwindow, unsigned int transmaxpacket) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112 struct Channel * newchan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
113 unsigned int i, j;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114
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
115 TRACE(("enter newchannel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117 /* first see if we can use existing channels */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118 for (i = 0; i < ses.chansize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 if (ses.channels[i] == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 break;
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 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
123
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 /* otherwise extend the list */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 if (i == ses.chansize) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
126 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
127 TRACE(("leave newchannel: max chans reached"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
128 return NULL;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
129 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131 /* extend the channels */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
132 ses.channels = (struct Channel**)m_realloc(ses.channels,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
133 (ses.chansize+CHAN_EXTEND_SIZE)*sizeof(struct Channel*));
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 ses.chansize += CHAN_EXTEND_SIZE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137 /* set the new channels to null */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 for (j = i; j < ses.chansize; j++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 ses.channels[j] = NULL;
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 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 newchan = (struct Channel*)m_malloc(sizeof(struct Channel));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 newchan->type = type;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 newchan->index = i;
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
147 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
148 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
149 newchan->close_handler_done = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 newchan->remotechan = remotechan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 newchan->transwindow = transwindow;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
153 newchan->transmaxpacket = transmaxpacket;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
154
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
155 newchan->typedata = NULL;
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
156 newchan->writefd = FD_UNINIT;
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
157 newchan->readfd = FD_UNINIT;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
159 newchan->initconn = 0;
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
160 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
161 newchan->flushing = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
162
709
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
163 newchan->writebuf = cbuf_new(0); /* resized later by chan_initwritebuf */
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
164 newchan->recvwindow = 0;
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
165
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
166 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
167 newchan->recvdonelen = 0;
448
9c61e7af0156 Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents: 439
diff changeset
168 newchan->recvmaxpacket = RECV_MAX_PAYLOAD_LEN;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
169
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
170 ses.channels[i] = newchan;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
171 ses.chancount++;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
172
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
173 TRACE(("leave newchannel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 return newchan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
178 /* 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
179 * 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
180 * 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
181 * channel */
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
182 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
183
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
184 unsigned int chan;
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
185
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
186 chan = buf_getint(ses.payload);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 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
188 if (kind) {
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
189 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
190 } else {
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
191 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
192 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 return ses.channels[chan];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
196
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
197 struct Channel* getchannel() {
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
198 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
199 }
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
200
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201 /* Iterate through the channels, performing IO if available */
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
202 void channelio(fd_set *readfds, fd_set *writefds) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
203
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++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 channel = ses.channels[i];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 if (channel == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
212 /* only process in-use channels */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
213 continue;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
214 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
215
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
216 /* 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
217 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
218 TRACE(("send normal readfd"))
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
219 send_msg_channel_data(channel, 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
220 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
221
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
222 /* 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
223 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
224 && 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
225 TRACE(("send normal errfd"))
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
226 send_msg_channel_data(channel, 1);
395
dc37bd8563e8 disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents: 394
diff changeset
227 }
dc37bd8563e8 disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents: 394
diff changeset
228
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
229 /* 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
230 if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
231 if (channel->initconn) {
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
232 /* XXX should this go somewhere cleaner? */
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
233 check_in_progress(channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 continue; /* Important not to use the channel after
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
235 check_in_progress(), as it may be NULL */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
236 }
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
237 writechannel(channel, channel->writefd, channel->writebuf);
108
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
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
240 /* stderr for client mode */
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
241 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
242 && channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) {
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
243 writechannel(channel, channel->errfd, channel->extrabuf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
245
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
246 /* handle any channel closing etc */
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
247 check_close(channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
248
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
249 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
251 /* Listeners such as TCP, X11, agent-auth */
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
252 #ifdef USING_LISTENERS
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
253 handle_listeners(readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
258 /* 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
259 * stderr of a channel's endpoint. */
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
260 static unsigned int write_pending(struct Channel * channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
261
709
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
262 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
263 return 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
264 } else if (channel->errfd >= 0 && channel->extrabuf &&
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
265 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
266 return 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
267 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
268 return 0;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
269 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
270
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
271
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
272 /* EOF/close handling */
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
273 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
274 int close_allowed = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
275
731
9a5438271556 Move the more verbose TRACE() statements into TRACE2()
Matt Johnston <matt@ucc.asn.au>
parents: 722
diff changeset
276 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
277 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
278 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
279 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
280 channel->writebuf ? cbuf_getused(channel->writebuf) : 0,
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
281 channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0))
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
282
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
283 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
284 && !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
285 && 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
286 && 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
287 {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
288 channel->flushing = 1;
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
289 }
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
290
504
950c38b854a1 Don't use // style comments
Matt Johnston <matt@ucc.asn.au>
parents: 495
diff changeset
291 /* 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
292 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
293 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
294 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
295 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
296 || 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
297 || 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
298 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
299 }
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
300
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
301 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
302 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
303 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
304 send_msg_channel_close(channel);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305 }
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
306 remove_channel(channel);
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
307 return;
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
308 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
309
815
35183e8a7851 Improve EOF handling for half-close. Patch from Catalin Patulea
Matt Johnston <matt@ucc.asn.au>
parents: 770
diff changeset
310 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
311 /* 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
312 || (channel->type->check_close && close_allowed)) {
364
90cb290836de Passes most test cases now
Matt Johnston <matt@ucc.asn.au>
parents: 363
diff changeset
313 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
314 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
315
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
316 /* 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
317 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
318 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
319 if (channel->flushing) {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
320 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
321 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
322 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
323 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
324 }
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
325 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
326 && 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 errfd"))
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, 1);
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
329 }
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
330 }
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
331
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
332 /* 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
333 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
334 && channel->readfd == FD_CLOSED
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
335 && (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)) {
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
336 send_msg_channel_eof(channel);
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
337 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
338
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
339 /* 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
340 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
341 && 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
342 && (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
343 && !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
344 && close_allowed
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
345 && !write_pending(channel)) {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
346 TRACE(("sending close, readfd is closed"))
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
347 send_msg_channel_close(channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
348 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
349 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
350
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
351 /* 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
352 * 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
353 * 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
354 * function */
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
355 static void check_in_progress(struct Channel *channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
356
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
357 int val;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
358 socklen_t vallen = sizeof(val);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
359
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
360 TRACE(("enter check_in_progress"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
361
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
362 if (getsockopt(channel->writefd, SOL_SOCKET, SO_ERROR, &val, &vallen)
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
363 || val != 0) {
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
364 send_msg_channel_open_failure(channel->remotechan,
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
365 SSH_OPEN_CONNECT_FAILED, "", "");
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
366 close(channel->writefd);
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
367 remove_channel(channel);
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
368 TRACE(("leave check_in_progress: fail"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
369 } else {
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
370 chan_initwritebuf(channel);
70
b0316ce64e4b Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents: 62
diff changeset
371 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
372 channel->recvmaxpacket);
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
373 channel->readfd = channel->writefd;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
374 channel->initconn = 0;
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
375 TRACE(("leave check_in_progress: success"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
376 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
377 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
378
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
379
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
380 /* 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
381 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
382
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
383 TRACE(("enter send_msg_channel_close %p", channel))
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
384 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
385 && !channel->close_handler_done) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
386 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
387 channel->close_handler_done = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
388 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
389
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
390 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
391
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
392 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
393 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
394
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
395 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
396
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
397 channel->sent_eof = 1;
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
398 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
399 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
400 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
401 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
402 TRACE(("leave send_msg_channel_close"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
403 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
404
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
405 /* call this when trans/eof channels are closed */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
406 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
407
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
408 TRACE(("enter send_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
409 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
410
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
411 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_EOF);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
412 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
413
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
414 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
415
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
416 channel->sent_eof = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
417
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
418 TRACE(("leave send_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
419 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
420
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
421 /* Called to write data out to the local side of the channel.
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
422 * Only called when we know we can write to a channel, writes as much as
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
423 * possible */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
424 static void writechannel(struct Channel* channel, int fd, circbuffer *cbuf) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
425
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
426 int len, maxlen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
427
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
428 TRACE(("enter writechannel fd %d", fd))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
429
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
430 maxlen = cbuf_readlen(cbuf);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
431
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
432 /* Write the data out */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
433 len = write(fd, cbuf_readptr(cbuf, maxlen), maxlen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
434 if (len <= 0) {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
435 TRACE(("errno %d len %d", errno, len))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
436 if (len < 0 && errno != EINTR) {
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
437 close_chan_fd(channel, fd, SHUT_WR);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
438 }
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
439 TRACE(("leave writechannel: len <= 0"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
440 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
441 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
442 TRACE(("writechannel wrote %d", len))
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
443
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
444 cbuf_incrread(cbuf, len);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
445 channel->recvdonelen += len;
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
446
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
447 /* Window adjust handling */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
448 if (channel->recvdonelen >= RECV_WINDOWEXTEND) {
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
449 /* Set it back to max window */
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
450 send_msg_channel_window_adjust(channel, channel->recvdonelen);
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
451 channel->recvwindow += channel->recvdonelen;
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
452 channel->recvdonelen = 0;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
453 }
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
454
449
3e6c536bc023 Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents: 448
diff changeset
455 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
456 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
457 dropbear_assert(channel->extrabuf == NULL ||
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
458 channel->recvwindow <= cbuf_getavail(channel->extrabuf));
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
459
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
460 TRACE(("leave writechannel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
461 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
462
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
463 /* 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
464 * This avoid channels which don't have any window available, are closed, etc*/
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
465 void setchannelfds(fd_set *readfds, fd_set *writefds) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
466
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
467 unsigned int i;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
468 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
469
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
470 for (i = 0; i < ses.chansize; i++) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
471
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
472 channel = ses.channels[i];
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
473 if (channel == NULL) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
474 continue;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
475 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
476
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
477 /* Stuff to put over the wire */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
478 if (channel->transwindow > 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
479
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
480 if (channel->readfd >= 0) {
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
481 FD_SET(channel->readfd, readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
482 }
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
483
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
484 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
485 FD_SET(channel->errfd, readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
486 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
487 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
488
397
2908122e9eed disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents: 396
diff changeset
489 /* Stuff from the wire */
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
490 if (channel->initconn
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
491 ||(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
492 FD_SET(channel->writefd, writefds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
493 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
494
433
c216212001fc Fix for -pedantic -ansi compilation, change // to /**/, plus some signedness
Matt Johnston <matt@ucc.asn.au>
parents: 423
diff changeset
495 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
496 && 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
497 FD_SET(channel->errfd, writefds);
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
498 }
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
499
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
500 } /* foreach channel */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
501
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
502 #ifdef USING_LISTENERS
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
503 set_listener_fds(readfds);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
504 #endif
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
505
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
506 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
507
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
508 /* 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
509 * 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
510 * etc) FD is also EOF */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
511 void recv_msg_channel_eof() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
512
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
513 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
514
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
515 TRACE(("enter recv_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
516
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
517 channel = getchannel_msg("EOF");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
518
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
519 channel->recv_eof = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
520
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
521 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
522 TRACE(("leave recv_msg_channel_eof"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
523 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
524
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
525
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
526 /* 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
527 void recv_msg_channel_close() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
528
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
529 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
530
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
531 TRACE(("enter recv_msg_channel_close"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
532
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
533 channel = getchannel_msg("Close");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
534
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
535 channel->recv_eof = 1;
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
536 channel->recv_close = 1;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
537
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
538 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
539 TRACE(("leave recv_msg_channel_close"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
540 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
541
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
542 /* 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
543 * channel close */
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
544 static void remove_channel(struct Channel * channel) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
545
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
546 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
547 TRACE(("channel index is %d", channel->index))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
548
709
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
549 cbuf_free(channel->writebuf);
abd99ecd7ec2 use an empty writebuf rather than a NULL one
Matt Johnston <matt@ucc.asn.au>
parents: 707
diff changeset
550 channel->writebuf = NULL;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
551
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
552 if (channel->extrabuf) {
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
553 cbuf_free(channel->extrabuf);
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
554 channel->extrabuf = NULL;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
555 }
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
556
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
557
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
558 /* close the FDs in case they haven't been done
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
559 * yet (they might have been shutdown etc) */
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
560 TRACE(("CLOSE writefd %d", channel->writefd))
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
561 close(channel->writefd);
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
562 TRACE(("CLOSE readfd %d", channel->readfd))
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
563 close(channel->readfd);
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
564 TRACE(("CLOSE errfd %d", channel->errfd))
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
565 close(channel->errfd);
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
566
770
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
567 if (!channel->close_handler_done
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
568 && channel->type->closehandler) {
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
569 channel->type->closehandler(channel);
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
570 channel->close_handler_done = 1;
7577a3afc42d run closehandlers on cleanup
Matt Johnston <matt@ucc.asn.au>
parents: 731
diff changeset
571 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
572
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
573 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
574 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
575 ses.chancount--;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
576
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
577 TRACE(("leave remove_channel"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
578 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
579
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
580 /* 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
581 * such as chansession or x11fwd */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
582 void recv_msg_channel_request() {
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 struct Channel *channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
585
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
586 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
587
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
588 TRACE(("enter recv_msg_channel_request %p", channel))
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
589
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
590 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
591 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
592 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
593 }
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
594
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
595 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
596 && !channel->close_handler_done) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
597 channel->type->reqhandler(channel);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
598 } else {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
599 send_msg_channel_failure(channel);
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
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
602 TRACE(("leave recv_msg_channel_request"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
603
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
604 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
605
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
606 /* 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
607 * channel_data packet to send.
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
608 * 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
609 * 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
610 * exttype */
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
611 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
612
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
613 int len;
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
614 size_t maxlen, size_pos;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
615 int fd;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
616
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
617 CHECKCLEARTOWRITE();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
618
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
619 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
620 dropbear_assert(!channel->sent_close);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
621
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
622 if (isextended) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
623 fd = channel->errfd;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
624 } else {
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
625 fd = channel->readfd;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
626 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
627 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
628 dropbear_assert(fd >= 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
629
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
630 maxlen = MIN(channel->transwindow, channel->transmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
631 /* -(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
632 * exttype if is extended */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
633 maxlen = MIN(maxlen,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
634 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
635 TRACE(("maxlen %zd", maxlen))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
636 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
637 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
638 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
639 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
640
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
641 buf_putbyte(ses.writepayload,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
642 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
643 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
644 if (isextended) {
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
645 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
646 }
362
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
647 /* 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
648 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
649 buf_putint(ses.writepayload, 0);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
650
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
651 /* 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
652 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
653
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
654 if (len <= 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
655 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
656 /* 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
657 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
658 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
659 close_chan_fd(channel, fd, SHUT_RD);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
660 }
722
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
661 buf_setpos(ses.writepayload, 0);
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
662 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
663 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
664 len, errno, fd))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
665 return;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
666 }
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
667
722
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
668 if (channel->read_mangler) {
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
669 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
670 if (len == 0) {
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
671 buf_setpos(ses.writepayload, 0);
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
672 buf_setlen(ses.writepayload, 0);
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
673 return;
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
674 }
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
675 }
4a274f47eabd Add ~. and ~^Z handling to exit/suspend dbclient
Matt Johnston <matt@ucc.asn.au>
parents: 709
diff changeset
676
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
677 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
678 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
679 /* ... real size here */
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
680 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
681 buf_putint(ses.writepayload, len);
4
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 channel->transwindow -= len;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
684
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
685 encrypt_packet();
416
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
686
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
687 /* 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
688 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
689 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
690 {
a01c0c8e543a Improve behaviour when flushing out after a process has exited.
Matt Johnston <matt@ucc.asn.au>
parents: 415
diff changeset
691 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
692 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
693 }
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
694 TRACE(("leave send_msg_channel_data"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
695 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
696
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
697 /* We receive channel data */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
698 void recv_msg_channel_data() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
699
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
700 struct Channel *channel;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
701
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
702 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
703
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
704 common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf);
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
705 }
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
706
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
707 /* 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
708 * for writing to the local file descriptor */
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
709 void common_recv_msg_channel_data(struct Channel *channel, int fd,
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
710 circbuffer * cbuf) {
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
711
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
712 unsigned int datalen;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
713 unsigned int maxdata;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
714 unsigned int buflen;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
715 unsigned int len;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
716
165
0cfba3034be5 Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents: 156
diff changeset
717 TRACE(("enter recv_msg_channel_data"))
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
718
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
719 if (channel->recv_eof) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 513
diff changeset
720 dropbear_exit("Received data after eof");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
721 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
722
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
723 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
724 /* 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
725 * 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
726 * 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
727 return;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
728 }
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 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
731 TRACE(("length %d", datalen))
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
732
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
733 maxdata = cbuf_getavail(cbuf);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
734
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
735 /* 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
736 * 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
737 * just die horribly */
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
738 if (datalen > maxdata) {
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
739 dropbear_exit("Oversized packet");
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
740 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
741
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
742 /* We may have to run throught twice, if the buffer wraps around. Can't
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
743 * just "leave it for next time" like with writechannel, since this
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
744 * is payload data */
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
745 len = datalen;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
746 while (len > 0) {
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
747 buflen = cbuf_writelen(cbuf);
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
748 buflen = MIN(buflen, len);
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
749
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
750 memcpy(cbuf_writeptr(cbuf, buflen),
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
751 buf_getptr(ses.payload, buflen), buflen);
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
752 cbuf_incrwrite(cbuf, buflen);
108
10f4d3319780 - added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents: 107
diff changeset
753 buf_incrpos(ses.payload, buflen);
107
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
754 len -= buflen;
Matt Johnston <matt@ucc.asn.au>
parents: 70
diff changeset
755 }
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
756
241
c5d3ef11155f * use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents: 221
diff changeset
757 dropbear_assert(channel->recvwindow >= datalen);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
758 channel->recvwindow -= datalen;
449
3e6c536bc023 Add -W <windowsize> argument and document it.
Matt Johnston <matt@ucc.asn.au>
parents: 448
diff changeset
759 dropbear_assert(channel->recvwindow <= opts.recv_window);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
760
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
761 TRACE(("leave recv_msg_channel_data"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
762 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
763
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
764 /* 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
765 * 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
766 * 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
767 void recv_msg_channel_window_adjust() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
768
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
769 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
770 unsigned int incr;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
771
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
772 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
773
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
774 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
775 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
776 incr = MIN(incr, TRANS_MAX_WIN_INCR);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
777
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
778 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
779 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
780
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
781 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
782
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
783 /* 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
784 * end know */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
785 static void send_msg_channel_window_adjust(struct Channel* channel,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
786 unsigned int incr) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
787
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
788 TRACE(("sending window adjust %d", incr))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
789 CHECKCLEARTOWRITE();
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 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
792 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
793 buf_putint(ses.writepayload, incr);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
794
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
795 encrypt_packet();
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
796 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
797
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
798 /* 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
799 void recv_msg_channel_open() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
800
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
801 unsigned char *type;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
802 unsigned int typelen;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
803 unsigned int remotechan, transwindow, transmaxpacket;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
804 struct Channel *channel;
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
805 const struct ChanType **cp;
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
806 const struct ChanType *chantype;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
807 unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
808 int ret;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
809
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
810
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
811 TRACE(("enter recv_msg_channel_open"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
812
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
813 /* get the packet contents */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
814 type = buf_getstring(ses.payload, &typelen);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
815
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
816 remotechan = buf_getint(ses.payload);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
817 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
818 transwindow = MIN(transwindow, TRANS_MAX_WINDOW);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
819 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
820 transmaxpacket = MIN(transmaxpacket, TRANS_MAX_PAYLOAD_LEN);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
821
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
822 /* figure what type of packet it is */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
823 if (typelen > MAX_NAME_LEN) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
824 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
825 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
826
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
827 /* 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
828 * 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
829 * this list and find the matching name */
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
830 for (cp = &ses.chantypes[0], chantype = (*cp);
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
831 chantype != NULL;
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
832 cp++, chantype = (*cp)) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
833 if (strcmp(type, chantype->name) == 0) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
834 break;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
835 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
836 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
837
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
838 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
839 TRACE(("No matching type for '%s'", type))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
840 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
841 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
842
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
843 TRACE(("matched type '%s'", type))
7
425ed5c20157 Chantype handling is sorted
Matt Johnston <matt@ucc.asn.au>
parents: 6
diff changeset
844
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
845 /* create the channel */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
846 channel = newchannel(remotechan, chantype, transwindow, transmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
847
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
848 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
849 TRACE(("newchannel returned NULL"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
850 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
851 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
852
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
853 if (channel->type->inithandler) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
854 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
855 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
856 /* 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
857 goto cleanup;
1c7bf9cec6c8 Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents: 359
diff changeset
858 }
6
ab00ef513e97 Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents: 4
diff changeset
859 if (ret > 0) {
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
860 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
861 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
862 TRACE(("inithandler returned failure %d", ret))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
863 goto failure;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
864 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
865 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
866
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
867 chan_initwritebuf(channel);
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
868
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
869 /* success */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
870 send_msg_channel_open_confirmation(channel, channel->recvwindow,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
871 channel->recvmaxpacket);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
872 goto cleanup;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
873
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
874 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
875 TRACE(("recv_msg_channel_open failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
876 send_msg_channel_open_failure(remotechan, errtype, "", "");
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
877
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
878 cleanup:
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
879 m_free(type);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
880
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
881 TRACE(("leave recv_msg_channel_open"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
882 }
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 /* Send a failure message */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
885 void send_msg_channel_failure(struct Channel *channel) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
886
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
887 TRACE(("enter send_msg_channel_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
888 CHECKCLEARTOWRITE();
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 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_FAILURE);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
891 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
892
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
893 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
894 TRACE(("leave send_msg_channel_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
895 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
896
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
897 /* Send a success message */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
898 void send_msg_channel_success(struct Channel *channel) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
899
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
900 TRACE(("enter send_msg_channel_success"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
901 CHECKCLEARTOWRITE();
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 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_SUCCESS);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
904 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
905
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
906 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
907 TRACE(("leave send_msg_channel_success"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
908 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
909
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
910 /* 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
911 * code (usually resource shortage or unknown chan type) */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
912 static void send_msg_channel_open_failure(unsigned int remotechan,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
913 int reason, const unsigned char *text, const unsigned char *lang) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
914
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
915 TRACE(("enter send_msg_channel_open_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
916 CHECKCLEARTOWRITE();
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 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
919 buf_putint(ses.writepayload, remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
920 buf_putint(ses.writepayload, reason);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
921 buf_putstring(ses.writepayload, text, strlen((char*)text));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
922 buf_putstring(ses.writepayload, lang, strlen((char*)lang));
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
923
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
924 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
925 TRACE(("leave send_msg_channel_open_failure"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
926 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
927
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
928 /* 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
929 * allocated and the receive parameters */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
930 static void send_msg_channel_open_confirmation(struct Channel* channel,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
931 unsigned int recvwindow,
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
932 unsigned int recvmaxpacket) {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
933
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
934 TRACE(("enter send_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
935 CHECKCLEARTOWRITE();
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 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
938 buf_putint(ses.writepayload, channel->remotechan);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
939 buf_putint(ses.writepayload, channel->index);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
940 buf_putint(ses.writepayload, recvwindow);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
941 buf_putint(ses.writepayload, recvmaxpacket);
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 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
944 TRACE(("leave send_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
945 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
946
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
947 /* 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
948 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
949
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
950 int closein = 0, closeout = 0;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
951
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
952 if (channel->type->sepfds) {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
953 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
954 shutdown(fd, how);
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
955 if (how == 0) {
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
956 closeout = 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
957 } else {
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
958 closein = 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
959 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
960 } else {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
961 TRACE(("CLOSE some fd %d", fd))
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
962 close(fd);
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
963 closein = closeout = 1;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
964 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
965
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
966 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
967 channel->readfd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
968 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
969 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
970 channel->errfd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
971 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
972
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
973 if (closein && fd == channel->writefd) {
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
974 channel->writefd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
975 }
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
976 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
977 channel->errfd = FD_CLOSED;
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
978 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
979
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
980 /* 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
981 * 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
982 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
983 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) {
375
8d149b812669 - Add some extra tracing.
Matt Johnston <matt@ucc.asn.au>
parents: 365
diff changeset
984 TRACE(("CLOSE (finally) of %d", fd))
363
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
985 close(fd);
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
986 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
987 }
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
988
6ba2894ec8d5 Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents: 362
diff changeset
989
156
8c2b3506f112 Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
990 #if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT)
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
991 /* 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
992 * 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
993 * 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
994 * completion. It is mandatory for the caller to encrypt_packet() if
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
995 * DROPBEAR_SUCCESS is returned */
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
996 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
997
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
998 struct Channel* chan;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
999
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
1000 TRACE(("enter send_msg_channel_open_init()"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1001 chan = newchannel(0, type, 0, 0);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1002 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
1003 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
1004 return DROPBEAR_FAILURE;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1005 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1006
707
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
1007 /* 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
1008 * 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
1009 chan_initwritebuf(chan);
564e7f87ecc3 Fix memory leak when direct TCP connections time out on connection.
Matt Johnston <matt@ucc.asn.au>
parents: 673
diff changeset
1010
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1011 /* set fd non-blocking */
109
2e9d1f29c50f merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents: 108
diff changeset
1012 setnonblocking(fd);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1013
253
84925eceeb13 * rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents: 243
diff changeset
1014 chan->writefd = chan->readfd = fd;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1015 ses.maxfd = MAX(ses.maxfd, fd);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1016
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1017 chan->await_open = 1;
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1018
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1019 /* now open the channel connection */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1020 CHECKCLEARTOWRITE();
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 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN);
9
7f77962de998 - Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents: 7
diff changeset
1023 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
1024 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
1025 buf_putint(ses.writepayload, opts.recv_window);
448
9c61e7af0156 Rearrange the channel buffer sizes into three neat use-editable values in
Matt Johnston <matt@ucc.asn.au>
parents: 439
diff changeset
1026 buf_putint(ses.writepayload, RECV_MAX_PAYLOAD_LEN);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1027
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
1028 TRACE(("leave send_msg_channel_open_init()"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1029 return DROPBEAR_SUCCESS;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1030 }
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 /* 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
1033 * successful*/
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1034 void recv_msg_channel_open_confirmation() {
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 struct Channel * channel;
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1037 int ret;
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1038
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
1039 TRACE(("enter recv_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1040
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
1041 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1042
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1043 if (!channel->await_open) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 513
diff changeset
1044 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
1045 }
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1046 channel->await_open = 0;
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1047
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1048 channel->remotechan = buf_getint(ses.payload);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1049 channel->transwindow = buf_getint(ses.payload);
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1050 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
1051
187
c44df7123b0a compile fix when TRACE debugging is enabled
Matt Johnston <matt@ucc.asn.au>
parents: 179
diff changeset
1052 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
1053 channel->remotechan, channel->index))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1054
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1055 /* Run the inithandler callback */
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1056 if (channel->type->inithandler) {
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1057 ret = channel->type->inithandler(channel);
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1058 if (ret > 0) {
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
1059 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
1060 TRACE(("inithandler returned failure %d", ret))
37
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1061 }
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1062 }
0913e2ee3545 we're nearly there yet
Matt Johnston <matt@ucc.asn.au>
parents: 13
diff changeset
1063
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
1064
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
1065 TRACE(("leave recv_msg_channel_open_confirmation"))
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1066 }
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1067
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1068 /* Notification that our channel open request failed */
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1069 void recv_msg_channel_open_failure() {
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1070
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1071 struct Channel * channel;
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1072
179
161557a9dde8 * fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents: 165
diff changeset
1073 channel = getchannel();
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1074
243
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1075 if (!channel->await_open) {
594
a98a2138364a Improve capitalisation for all logged strings
Matt Johnston <matt@ucc.asn.au>
parents: 513
diff changeset
1076 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
1077 }
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1078 channel->await_open = 0;
0056419cf0f4 * ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents: 241
diff changeset
1079
359
78518751cb82 just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents: 332
diff changeset
1080 remove_channel(channel);
4
fe6bca95afa7 Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1081 }
156
8c2b3506f112 Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents: 109
diff changeset
1082 #endif /* USING_LISTENERS */