Mercurial > dropbear
annotate common-channel.c @ 363:6ba2894ec8d5 channel-fix
Rearranged (and hopefully simplified) channel close/eof handling
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 07 Oct 2006 17:48:55 +0000 |
parents | 1c7bf9cec6c8 |
children | 90cb290836de |
rev | line source |
---|---|
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* |
107 | 2 * Dropbear SSH |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * |
107 | 4 * Copyright (c) 2002-2004 Matt Johnston |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * All rights reserved. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * Permission is hereby granted, free of charge, to any person obtaining a copy |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * of this software and associated documentation files (the "Software"), to deal |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * in the Software without restriction, including without limitation the rights |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 * copies of the Software, and to permit persons to whom the Software is |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 * furnished to do so, subject to the following conditions: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 * The above copyright notice and this permission notice shall be included in |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 * all copies or substantial portions of the Software. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 * |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 * SOFTWARE. */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 /* Handle the multiplexed channels, such as sessions, x11, agent connections */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 #include "includes.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 #include "session.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 #include "packet.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 #include "ssh.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 #include "buffer.h" |
107 | 32 #include "circbuffer.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 #include "dbutil.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 #include "channel.h" |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 #include "ssh.h" |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
36 #include "listener.h" |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 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
|
39 const unsigned char *text, const unsigned char *lang); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 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
|
41 unsigned int recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 unsigned int recvmaxpacket); |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
43 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
|
44 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
|
45 unsigned int incr); |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 static void delete_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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 /* Initialise all the channels */ |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
60 void chaninitialise(const struct ChanType *chantypes[]) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 /* 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
|
63 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
|
64 ses.chansize = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 ses.channels[0] = NULL; |
37 | 66 ses.chancount = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 ses.chantypes = chantypes; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
70 #ifdef USING_LISTENERS |
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
71 listeners_initialise(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 /* Clean up channels, freeing allocated memory */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 void chancleanup() { |
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 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 |
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
|
81 TRACE(("enter chancleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 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
|
84 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
|
85 remove_channel(ses.channels[i]); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 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
|
89 TRACE(("leave chancleanup")) |
4
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 /* 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
|
93 /* 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
|
94 * 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
|
95 * all be set to 0 */ |
7 | 96 struct Channel* newchannel(unsigned int remotechan, |
97 const struct ChanType *type, | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 unsigned int transwindow, unsigned int transmaxpacket) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 struct Channel * newchan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 unsigned int i, j; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 |
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
|
103 TRACE(("enter newchannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 /* first see if we can use existing channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 if (ses.channels[i] == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 break; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 } |
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 /* otherwise extend the list */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 if (i == ses.chansize) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 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
|
115 TRACE(("leave newchannel: max chans reached")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 return NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 /* extend the channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 ses.channels = (struct Channel**)m_realloc(ses.channels, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 (ses.chansize+CHAN_EXTEND_SIZE)*sizeof(struct Channel*)); |
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 ses.chansize += CHAN_EXTEND_SIZE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 /* set the new channels to null */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 for (j = i; j < ses.chansize; j++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 ses.channels[j] = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 newchan = (struct Channel*)m_malloc(sizeof(struct Channel)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 newchan->type = type; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 newchan->index = i; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
135 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
|
136 newchan->sent_eof = newchan->recv_eof = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 newchan->remotechan = remotechan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 newchan->transwindow = transwindow; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 newchan->transmaxpacket = transmaxpacket; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 newchan->typedata = NULL; |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
143 newchan->writefd = FD_UNINIT; |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
144 newchan->readfd = FD_UNINIT; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 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
|
146 newchan->initconn = 0; |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
147 newchan->await_open = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 |
107 | 149 newchan->writebuf = cbuf_new(RECV_MAXWINDOW); |
150 newchan->extrabuf = NULL; /* The user code can set it up */ | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 newchan->recvwindow = RECV_MAXWINDOW; |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
152 newchan->recvdonelen = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 newchan->recvmaxpacket = RECV_MAXPACKET; |
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 ses.channels[i] = newchan; |
37 | 156 ses.chancount++; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 |
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
|
158 TRACE(("leave newchannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 return newchan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
163 /* 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
|
164 * 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
|
165 * 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
|
166 * channel */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
167 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
|
168 |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
169 unsigned int chan; |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
170 |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
171 chan = buf_getint(ses.payload); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 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
|
173 if (kind) { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
174 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
|
175 } else { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
176 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
|
177 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 return ses.channels[chan]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
180 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
181 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
182 struct Channel* getchannel() { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
183 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
|
184 } |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
185 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 /* 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
|
187 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
|
188 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
189 struct Channel *channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
190 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
192 /* foreach channel */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
194 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 channel = ses.channels[i]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 if (channel == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 /* only process in-use channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
198 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
199 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
201 /* 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
|
202 if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
203 send_msg_channel_data(channel, 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
206 /* read stderr data and send it over the wire */ |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
207 if (channel->extrabuf == NULL && |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
208 channel->errfd >= 0 && FD_ISSET(channel->errfd, readfds)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
209 send_msg_channel_data(channel, 1); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
211 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 /* 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
|
213 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
|
214 if (channel->initconn) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
215 /* 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
|
216 check_in_progress(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
217 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
|
218 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
|
219 } |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
220 writechannel(channel, channel->writefd, channel->writebuf); |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
221 } |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
222 |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
223 /* stderr for client mode */ |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
224 if (channel->extrabuf != NULL |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
225 && 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
|
226 writechannel(channel, channel->errfd, channel->extrabuf); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
229 /* 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
|
230 check_close(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
232 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
234 /* 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
|
235 #ifdef USING_LISTENERS |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
236 handle_listeners(readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
240 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
241 /* 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
|
242 * 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
|
243 static unsigned int write_pending(struct Channel * channel) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
244 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
245 if (channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
246 return 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
247 } else if (channel->errfd >= 0 && channel->extrabuf && |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
248 cbuf_getused(channel->writebuf) > 0) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
249 return 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
250 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
251 return 0; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
252 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
253 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
254 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
255 /* EOF/close handling */ |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
256 static void check_close(struct Channel *channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
258 TRACE(("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
|
259 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
|
260 channel->errfd, channel->sent_close, channel->recv_close)) |
300
baea1d43e7eb
Some cleanups/fixes for various TRACE statements
Matt Johnston <matt@ucc.asn.au>
parents:
278
diff
changeset
|
261 TRACE(("writebuf size %d extrabuf ptr 0x%x extrabuf size %d", |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
262 cbuf_getused(channel->writebuf), |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
263 channel->writebuf, |
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
|
264 channel->writebuf ? 0 : cbuf_getused(channel->extrabuf))) |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
265 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
266 if (!channel->sent_close |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
267 && channel->writefd == FD_CLOSED |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
268 && (channel->errfd == FD_CLOSED || channel->extrabuf == NULL)) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
269 send_msg_channel_close(channel); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
270 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
271 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
272 if (channel->recv_close && !write_pending(channel)) { |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
273 if (! channel->sent_close) { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
274 TRACE(("Sending MSG_CHANNEL_CLOSE in response to same.")) |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
275 send_msg_channel_close(channel); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
276 } |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
277 remove_channel(channel); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
278 return; |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
279 } |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
280 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
281 #if 0 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
282 // The only use of check_close is "return channel->writefd == -1;" for a server |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
283 // chansession. Should be able to handle that with just the general |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
284 // socket close handling...? |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
285 if (channel->type->check_close) { |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
286 if (channel->type->check_close(channel)) { |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
287 close_write_fd(channel); |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
288 close_read_fd(channel, channel->readfd); |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
289 close_read_fd(channel, channel->errfd); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 } |
331
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
291 } |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
292 #endif |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
293 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
294 if (!channel->sent_eof |
331
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
295 && channel->readfd == FD_CLOSED |
332
6f90e5fd42cc
fix accidentally changed == vs != operators
Matt Johnston <matt@ucc.asn.au>
parents:
331
diff
changeset
|
296 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { |
331
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
297 send_msg_channel_eof(channel); |
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
298 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
299 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
300 if (!channel->sent_close |
331
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
301 && channel->writefd == FD_CLOSED |
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
302 && channel->readfd == FD_CLOSED |
332
6f90e5fd42cc
fix accidentally changed == vs != operators
Matt Johnston <matt@ucc.asn.au>
parents:
331
diff
changeset
|
303 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { |
331
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
304 send_msg_channel_close(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
305 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
306 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
307 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
308 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
309 /* 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
|
310 * 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
|
311 * 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
|
312 * function */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
313 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
|
314 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
315 int val; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
316 socklen_t vallen = sizeof(val); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
317 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
318 TRACE(("enter check_in_progress")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
319 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
320 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
|
321 || 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
|
322 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
|
323 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
|
324 close(channel->writefd); |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
325 delete_channel(channel); |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
326 TRACE(("leave check_in_progress: fail")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
327 } else { |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
328 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
|
329 channel->recvmaxpacket); |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
330 channel->readfd = channel->writefd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
331 channel->initconn = 0; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
332 TRACE(("leave check_in_progress: success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
333 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
334 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
335 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
336 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
337 /* 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
|
338 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
|
339 |
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
|
340 TRACE(("enter send_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
341 if (channel->type->closehandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
342 channel->type->closehandler(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
343 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
344 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
345 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
346 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
347 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
348 buf_putint(ses.writepayload, channel->remotechan); |
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 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
351 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
352 /* XXX is setting sent_eof required? */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
353 channel->sent_eof = 1; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
354 channel->sent_close = 1; |
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
|
355 TRACE(("leave send_msg_channel_close")) |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
358 /* call this when trans/eof channels are closed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
359 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
|
360 |
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
|
361 TRACE(("enter send_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
362 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
363 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
364 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_EOF); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
365 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
366 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
367 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
368 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
369 channel->sent_eof = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
370 |
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
|
371 TRACE(("leave send_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
372 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
373 |
107 | 374 /* 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
|
375 * 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
|
376 * possible */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
377 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
|
378 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
379 int len, maxlen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
380 |
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
|
381 TRACE(("enter writechannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
382 |
107 | 383 maxlen = cbuf_readlen(cbuf); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
384 |
107 | 385 /* Write the data out */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
386 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
|
387 if (len <= 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
388 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
|
389 close_chan_fd(channel, fd, SHUT_WR); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
390 } |
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
|
391 TRACE(("leave writechannel: len <= 0")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
392 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
393 } |
107 | 394 |
395 cbuf_incrread(cbuf, len); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
396 channel->recvdonelen += len; |
107 | 397 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
398 /* We're closing out */ |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
399 if (channel->recv_eof && cbuf_getused(cbuf) == 0) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
400 TRACE(("leave writechannel")) |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
401 close_chan_fd(channel, fd, SHUT_WR); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
402 return; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
403 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
404 |
107 | 405 /* Window adjust handling */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
406 if (channel->recvdonelen >= RECV_WINDOWEXTEND) { |
107 | 407 /* Set it back to max window */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
408 send_msg_channel_window_adjust(channel, channel->recvdonelen); |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
409 channel->recvwindow += channel->recvdonelen; |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
410 channel->recvdonelen = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
411 } |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
412 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
413 dropbear_assert(channel->recvwindow <= RECV_MAXWINDOW); |
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
414 dropbear_assert(channel->recvwindow <= cbuf_getavail(channel->writebuf)); |
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
415 dropbear_assert(channel->extrabuf == NULL || |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
416 channel->recvwindow <= cbuf_getavail(channel->extrabuf)); |
107 | 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 writechannel")) |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
421 /* 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
|
422 * 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
|
423 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
|
424 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
425 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
426 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
427 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
428 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
429 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
430 channel = ses.channels[i]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
431 if (channel == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
432 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
433 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
434 |
107 | 435 /* Stuff to put over the wire */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
436 if (channel->transwindow > 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
437 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
438 if (channel->readfd >= 0) { |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
439 FD_SET(channel->readfd, readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
440 } |
107 | 441 |
442 if (channel->extrabuf == NULL && channel->errfd >= 0) { | |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
443 FD_SET(channel->errfd, readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
444 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
445 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
446 |
331
d6b8815a9b5e
progress towards exiting on writefd closure rather than
Matt Johnston <matt@ucc.asn.au>
parents:
330
diff
changeset
|
447 /* Stuff from the wire */ |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
448 if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 ) |
107 | 449 || channel->initconn) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
450 FD_SET(channel->writefd, writefds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
451 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
452 |
107 | 453 if (channel->extrabuf != NULL && channel->errfd >= 0 |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
454 && 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
|
455 FD_SET(channel->errfd, writefds); |
107 | 456 } |
457 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
458 } /* foreach channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
459 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
460 #ifdef USING_LISTENERS |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
461 set_listener_fds(readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
462 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
463 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
464 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
465 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
466 /* 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
|
467 * 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
|
468 * etc) FD is also EOF */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
469 void recv_msg_channel_eof() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
470 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
471 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
472 |
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
|
473 TRACE(("enter recv_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
474 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
475 channel = getchannel_msg("EOF"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
476 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
477 channel->recv_eof = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
478 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
479 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
|
480 TRACE(("leave recv_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
481 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
482 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
483 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
484 /* 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
|
485 void recv_msg_channel_close() { |
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 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
488 |
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
|
489 TRACE(("enter recv_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
490 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
491 channel = getchannel_msg("Close"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
492 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
493 /* XXX eof required? */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
494 channel->recv_eof = 1; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
495 channel->recv_close = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
496 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
497 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
|
498 TRACE(("leave recv_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
499 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
500 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
501 /* 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
|
502 * channel close */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
503 static void remove_channel(struct Channel * channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
504 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
505 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
|
506 TRACE(("channel index is %d", channel->index)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
507 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
508 /* XXX shuold we assert for sent_closed and recv_closed? |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
509 * but we also cleanup manually, maybe we need a flag. */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
510 |
107 | 511 cbuf_free(channel->writebuf); |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
512 channel->writebuf = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
513 |
107 | 514 if (channel->extrabuf) { |
515 cbuf_free(channel->extrabuf); | |
516 channel->extrabuf = NULL; | |
517 } | |
518 | |
519 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
520 /* 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
|
521 * yet (they might have been shutdown etc) */ |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
522 close(channel->writefd); |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
523 close(channel->readfd); |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
524 close(channel->errfd); |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
525 |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
526 channel->typedata = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
527 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
528 delete_channel(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
529 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
530 TRACE(("leave remove_channel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
531 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
532 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
533 /* Remove a channel entry */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
534 static void delete_channel(struct Channel *channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
535 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
536 ses.channels[channel->index] = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
537 m_free(channel); |
37 | 538 ses.chancount--; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
539 |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
543 /* 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
|
544 * such as chansession or x11fwd */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
545 void recv_msg_channel_request() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
546 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
547 struct Channel *channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
548 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
549 TRACE(("enter recv_msg_channel_request")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
550 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
551 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
552 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
553 if (channel->type->reqhandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
554 channel->type->reqhandler(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
555 } else { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
556 send_msg_channel_failure(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
557 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
558 |
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
|
559 TRACE(("leave recv_msg_channel_request")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
560 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
561 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
562 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
563 /* 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
|
564 * channel_data packet to send. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
565 * 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
|
566 * 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
|
567 * exttype */ |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
568 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
|
569 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
570 int len; |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
571 size_t maxlen, size_pos; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
572 int fd; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
573 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
574 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
575 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
576 dropbear_assert(!channel->sent_close); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
577 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
578 if (isextended) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
579 fd = channel->errfd; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
580 } else { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
581 fd = channel->readfd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
582 } |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
583 dropbear_assert(fd >= 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
584 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
585 maxlen = MIN(channel->transwindow, channel->transmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
586 /* -(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
|
587 * exttype if is extended */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
588 maxlen = MIN(maxlen, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
589 ses.writepayload->size - 1 - 4 - 4 - (isextended ? 4 : 0)); |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
590 TRACE(("maxlen %d", maxlen)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
591 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
|
592 TRACE(("leave send_msg_channel_data: no window")) |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
593 return; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
594 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
595 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
596 buf_putbyte(ses.writepayload, |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
597 isextended ? SSH_MSG_CHANNEL_EXTENDED_DATA : SSH_MSG_CHANNEL_DATA); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
598 buf_putint(ses.writepayload, channel->remotechan); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
599 if (isextended) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
600 buf_putint(ses.writepayload, SSH_EXTENDED_DATA_STDERR); |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
601 } |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
602 /* 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
|
603 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
|
604 buf_putint(ses.writepayload, 0); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
605 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
606 /* 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
|
607 len = read(fd, buf_getwriteptr(ses.writepayload, maxlen), maxlen); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
608 if (len <= 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
609 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
|
610 close_chan_fd(channel, fd, SHUT_RD); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
611 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
612 ses.writepayload->len = ses.writepayload->pos = 0; |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
613 TRACE(("leave send_msg_channel_data: read err or EOF for fd %d", |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
614 channel->index)); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
615 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
616 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
617 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
|
618 /* ... real size here */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
619 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
|
620 buf_putint(ses.writepayload, len); |
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 channel->transwindow -= len; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
623 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
624 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
|
625 TRACE(("leave send_msg_channel_data")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
626 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
627 |
107 | 628 /* We receive channel data */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
629 void recv_msg_channel_data() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
630 |
107 | 631 struct Channel *channel; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
632 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
633 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
634 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
635 common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf); |
107 | 636 } |
637 | |
638 /* Shared for data and stderr data - when we receive data, put it in a buffer | |
639 * for writing to the local file descriptor */ | |
640 void common_recv_msg_channel_data(struct Channel *channel, int fd, | |
641 circbuffer * cbuf) { | |
642 | |
643 unsigned int datalen; | |
644 unsigned int maxdata; | |
645 unsigned int buflen; | |
646 unsigned int len; | |
647 | |
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
|
648 TRACE(("enter recv_msg_channel_data")) |
107 | 649 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
650 if (channel->recv_eof) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
651 dropbear_exit("received data after eof"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
652 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
653 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
654 /* XXX this is getting hit by people - maybe should be |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
655 * made less fatal (or just fixed). |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
656 * |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
657 * The most likely explanation is that the socket is being closed (due to |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
658 * write failure etc) but the far end doesn't know yet, so keeps sending |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
659 * packets. We already know that the channel number that was given was |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
660 * valid, so probably should skip out here. Maybe |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
661 * assert(channel->sent_close), thuogh only if the close-on-failure code is |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
662 * doing that */ |
107 | 663 if (fd < 0) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
664 dropbear_exit("received data with bad writefd"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
665 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
666 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
667 datalen = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
668 |
107 | 669 |
670 maxdata = cbuf_getavail(cbuf); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
671 |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
672 /* 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
|
673 * 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
|
674 * just die horribly */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
675 if (datalen > maxdata) { |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
676 dropbear_exit("Oversized packet"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
677 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
678 |
107 | 679 /* We may have to run throught twice, if the buffer wraps around. Can't |
680 * just "leave it for next time" like with writechannel, since this | |
681 * is payload data */ | |
682 len = datalen; | |
683 while (len > 0) { | |
684 buflen = cbuf_writelen(cbuf); | |
685 buflen = MIN(buflen, len); | |
686 | |
687 memcpy(cbuf_writeptr(cbuf, buflen), | |
688 buf_getptr(ses.payload, buflen), buflen); | |
689 cbuf_incrwrite(cbuf, buflen); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
690 buf_incrpos(ses.payload, buflen); |
107 | 691 len -= buflen; |
692 } | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
693 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
694 dropbear_assert(channel->recvwindow >= datalen); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
695 channel->recvwindow -= datalen; |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
696 dropbear_assert(channel->recvwindow <= RECV_MAXWINDOW); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
697 |
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
|
698 TRACE(("leave recv_msg_channel_data")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
699 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
700 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
701 /* 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
|
702 * 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
|
703 * 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
|
704 void recv_msg_channel_window_adjust() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
705 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
706 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
707 unsigned int incr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
708 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
709 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
710 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
711 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
|
712 TRACE(("received window increment %d", incr)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
713 incr = MIN(incr, MAX_TRANS_WIN_INCR); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
714 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
715 channel->transwindow += incr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
716 channel->transwindow = MIN(channel->transwindow, MAX_TRANS_WINDOW); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
717 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
718 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
719 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
720 /* 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
|
721 * end know */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
722 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
|
723 unsigned int incr) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
724 |
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
|
725 TRACE(("sending window adjust %d", incr)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
726 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
727 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
728 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
|
729 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
730 buf_putint(ses.writepayload, incr); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
731 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
732 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
733 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
734 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
735 /* 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
|
736 void recv_msg_channel_open() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
737 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
738 unsigned char *type; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
739 unsigned int typelen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
740 unsigned int remotechan, transwindow, transmaxpacket; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
741 struct Channel *channel; |
7 | 742 const struct ChanType **cp; |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
743 const struct ChanType *chantype; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
744 unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
745 int ret; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
746 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
747 |
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
|
748 TRACE(("enter recv_msg_channel_open")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
749 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
750 /* get the packet contents */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
751 type = buf_getstring(ses.payload, &typelen); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
752 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
753 remotechan = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
754 transwindow = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
755 transwindow = MIN(transwindow, MAX_TRANS_WINDOW); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
756 transmaxpacket = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
757 transmaxpacket = MIN(transmaxpacket, MAX_TRANS_PAYLOAD_LEN); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
758 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
759 /* figure what type of packet it is */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
760 if (typelen > MAX_NAME_LEN) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
761 goto failure; |
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 |
7 | 764 /* Get the channel type. Client and server style invokation will set up a |
765 * different list for ses.chantypes at startup. We just iterate through | |
766 * this list and find the matching name */ | |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
767 /* XXX fugly */ |
7 | 768 for (cp = &ses.chantypes[0], chantype = (*cp); |
769 chantype != NULL; | |
770 cp++, chantype = (*cp)) { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
771 if (strcmp(type, chantype->name) == 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
772 break; |
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 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
775 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
776 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
|
777 TRACE(("No matching type for '%s'", type)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
778 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
779 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
780 |
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
|
781 TRACE(("matched type '%s'", type)) |
7 | 782 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
783 /* create the channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
784 channel = newchannel(remotechan, chantype, transwindow, transmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
785 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
786 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
|
787 TRACE(("newchannel returned NULL")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
788 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
789 } |
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 if (channel->type->inithandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
792 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
|
793 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
|
794 /* 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
|
795 goto cleanup; |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
796 } |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
797 if (ret > 0) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
798 errtype = ret; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
799 delete_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
|
800 TRACE(("inithandler returned failure %d", ret)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
801 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
802 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
803 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
804 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
805 /* success */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
806 send_msg_channel_open_confirmation(channel, channel->recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
807 channel->recvmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
808 goto cleanup; |
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 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
|
811 TRACE(("recv_msg_channel_open failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
812 send_msg_channel_open_failure(remotechan, errtype, "", ""); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
813 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
814 cleanup: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
815 m_free(type); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
816 |
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
|
817 TRACE(("leave recv_msg_channel_open")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
818 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
819 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
820 /* Send a failure message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
821 void send_msg_channel_failure(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
822 |
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
|
823 TRACE(("enter send_msg_channel_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
824 CHECKCLEARTOWRITE(); |
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 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
827 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
828 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
829 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
|
830 TRACE(("leave send_msg_channel_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
831 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
832 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
833 /* Send a success message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
834 void send_msg_channel_success(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
835 |
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
|
836 TRACE(("enter send_msg_channel_success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
837 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
838 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
839 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_SUCCESS); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
840 buf_putint(ses.writepayload, channel->remotechan); |
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 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
|
843 TRACE(("leave send_msg_channel_success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
844 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
845 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
846 /* 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
|
847 * code (usually resource shortage or unknown chan type) */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
848 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
|
849 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
|
850 |
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
|
851 TRACE(("enter send_msg_channel_open_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
852 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
853 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
854 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
|
855 buf_putint(ses.writepayload, remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
856 buf_putint(ses.writepayload, reason); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
857 buf_putstring(ses.writepayload, text, strlen((char*)text)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
858 buf_putstring(ses.writepayload, lang, strlen((char*)lang)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
859 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
860 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
|
861 TRACE(("leave send_msg_channel_open_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
862 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
863 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
864 /* 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
|
865 * allocated and the receive parameters */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
866 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
|
867 unsigned int recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
868 unsigned int recvmaxpacket) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
869 |
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
|
870 TRACE(("enter send_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
871 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
872 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
873 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
|
874 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
875 buf_putint(ses.writepayload, channel->index); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
876 buf_putint(ses.writepayload, recvwindow); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
877 buf_putint(ses.writepayload, recvmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
878 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
879 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
|
880 TRACE(("leave send_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
881 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
882 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
883 /* 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
|
884 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
|
885 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
886 int closein = 0, closeout = 0; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
887 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
888 if (channel->type->sepfds) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
889 TRACE(("shutdown((%d), %d)", fd, how)) |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
890 shutdown(fd, how); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
891 if (how == 0) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
892 closeout = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
893 } else { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
894 closein = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
895 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
896 } else { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
897 close(fd); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
898 closein = closeout = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
899 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
900 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
901 if (closeout && fd == channel->readfd) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
902 channel->readfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
903 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
904 if (closeout && (channel->extrabuf == NULL) && (fd == channel->errfd)) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
905 channel->errfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
906 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
907 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
908 if (closein && fd == channel->writefd) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
909 channel->writefd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
910 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
911 if (closein && (channel->extrabuf != NULL) && (fd == channel->errfd)) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
912 channel->errfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
913 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
914 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
915 /* 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
|
916 * 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
|
917 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
|
918 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
919 close(fd); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
920 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
921 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
922 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
923 |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
924 #if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
925 /* 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
|
926 * 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
|
927 * 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
|
928 * 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
|
929 * DROPBEAR_SUCCESS is returned */ |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
930 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
|
931 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
932 struct Channel* chan; |
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_init()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
935 chan = newchannel(0, type, 0, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
936 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
|
937 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
|
938 return DROPBEAR_FAILURE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
939 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
940 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
941 /* set fd non-blocking */ |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
942 setnonblocking(fd); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
943 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
944 chan->writefd = chan->readfd = fd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
945 ses.maxfd = MAX(ses.maxfd, fd); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
946 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
947 chan->await_open = 1; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
948 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
949 /* now open the channel connection */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
950 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
951 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
952 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
|
953 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
|
954 buf_putint(ses.writepayload, chan->index); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
955 buf_putint(ses.writepayload, RECV_MAXWINDOW); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
956 buf_putint(ses.writepayload, RECV_MAXPACKET); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
957 |
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
|
958 TRACE(("leave send_msg_channel_open_init()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
959 return DROPBEAR_SUCCESS; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
960 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
961 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
962 /* 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
|
963 * successful*/ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
964 void recv_msg_channel_open_confirmation() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
965 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
966 struct Channel * channel; |
37 | 967 int ret; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
968 |
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
|
969 TRACE(("enter recv_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
970 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
971 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
972 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
973 if (!channel->await_open) { |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
974 dropbear_exit("unexpected channel reply"); |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
975 } |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
976 channel->await_open = 0; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
977 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
978 channel->remotechan = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
979 channel->transwindow = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
980 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
|
981 |
187
c44df7123b0a
compile fix when TRACE debugging is enabled
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
982 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
|
983 channel->remotechan, channel->index)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
984 |
37 | 985 /* Run the inithandler callback */ |
986 if (channel->type->inithandler) { | |
987 ret = channel->type->inithandler(channel); | |
988 if (ret > 0) { | |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
989 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
|
990 TRACE(("inithandler returned failure %d", ret)) |
37 | 991 } |
992 } | |
993 | |
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
|
994 |
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
|
995 TRACE(("leave recv_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
996 } |
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 /* Notification that our channel open request failed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
999 void recv_msg_channel_open_failure() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1000 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1001 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1002 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
1003 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1004 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1005 if (!channel->await_open) { |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1006 dropbear_exit("unexpected channel reply"); |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1007 } |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1008 channel->await_open = 0; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1009 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
1010 remove_channel(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1011 } |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
1012 #endif /* USING_LISTENERS */ |