Mercurial > dropbear
annotate common-channel.c @ 402:173a5f89666c channel-fix
propagate from branch 'au.asn.ucc.matt.dropbear' (head b1dd3b94e60a07a176dba2b035ac79968595990a)
to branch 'au.asn.ucc.matt.dropbear.channel-fix' (head fc77c3dea87a7c0f374e738d055f0b455495cbc3)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 03 Feb 2007 08:22:58 +0000 |
parents | a707e6148060 a7eb64b9966a |
children | 8b9aba1d5fa4 |
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 |
375 | 59 #define ERRFD_IS_READ(channel) ((channel)->extrabuf == NULL) |
60 #define ERRFD_IS_WRITE(channel) (!ERRFD_IS_READ(channel)) | |
61 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 /* Initialise all the channels */ |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
63 void chaninitialise(const struct ChanType *chantypes[]) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 /* may as well create space for a single channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 ses.channels = (struct Channel**)m_malloc(sizeof(struct Channel*)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 ses.chansize = 1; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 ses.channels[0] = NULL; |
37 | 69 ses.chancount = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 ses.chantypes = chantypes; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
73 #ifdef USING_LISTENERS |
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
74 listeners_initialise(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 /* Clean up channels, freeing allocated memory */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 void chancleanup() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
84 TRACE(("enter chancleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 if (ses.channels[i] != NULL) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
87 TRACE(("channel %d closing", i)) |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
88 remove_channel(ses.channels[i]); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 m_free(ses.channels); |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
92 TRACE(("leave chancleanup")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 /* 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
|
96 /* 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
|
97 * 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
|
98 * all be set to 0 */ |
7 | 99 struct Channel* newchannel(unsigned int remotechan, |
100 const struct ChanType *type, | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 unsigned int transwindow, unsigned int transmaxpacket) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 struct Channel * newchan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 unsigned int i, j; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 |
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
|
106 TRACE(("enter newchannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 /* first see if we can use existing channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 if (ses.channels[i] == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 break; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 /* otherwise extend the list */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 if (i == ses.chansize) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 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
|
118 TRACE(("leave newchannel: max chans reached")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 return NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 /* extend the channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 ses.channels = (struct Channel**)m_realloc(ses.channels, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 (ses.chansize+CHAN_EXTEND_SIZE)*sizeof(struct Channel*)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 ses.chansize += CHAN_EXTEND_SIZE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 /* set the new channels to null */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 for (j = i; j < ses.chansize; j++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 ses.channels[j] = NULL; |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 newchan = (struct Channel*)m_malloc(sizeof(struct Channel)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 newchan->type = type; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 newchan->index = i; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
138 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
|
139 newchan->sent_eof = newchan->recv_eof = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 newchan->remotechan = remotechan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 newchan->transwindow = transwindow; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 newchan->transmaxpacket = transmaxpacket; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 newchan->typedata = NULL; |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
146 newchan->writefd = FD_UNINIT; |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
147 newchan->readfd = FD_UNINIT; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 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
|
149 newchan->initconn = 0; |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
150 newchan->await_open = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 |
107 | 152 newchan->writebuf = cbuf_new(RECV_MAXWINDOW); |
153 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
|
154 newchan->recvwindow = RECV_MAXWINDOW; |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
155 newchan->recvdonelen = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 newchan->recvmaxpacket = RECV_MAXPACKET; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 ses.channels[i] = newchan; |
37 | 159 ses.chancount++; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 |
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
|
161 TRACE(("leave newchannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 return newchan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
166 /* 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
|
167 * 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
|
168 * 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
|
169 * channel */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
170 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
|
171 |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
172 unsigned int chan; |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
173 |
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
174 chan = buf_getint(ses.payload); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
175 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
|
176 if (kind) { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
177 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
|
178 } else { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
179 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
|
180 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
181 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 return ses.channels[chan]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
185 struct Channel* getchannel() { |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
186 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
|
187 } |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
188 |
376
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
189 /* In order to tell if a writefd is closed, we put it in the readfd FD_SET. |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
190 We then just try reading a single byte from it. It'll give EAGAIN or something |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
191 if the socket is still alive (but the FD probably shouldn't be set anyway?)*/ |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
192 static void check_closed_writefd(struct Channel* channel, int fd) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
193 char c; |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
194 int ret; |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
195 TRACE(("enter check_closed_writefd fd %d", fd)) |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
196 if (fd < 0) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
197 TRACE(("leave check_closed_writefd.")) |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
198 return; |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
199 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
200 |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
201 /* Read something. doing read(fd,x,0) seems to become a NOP on some platforms */ |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
202 ret = read(fd, &c, 1); |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
203 TRACE(("ret %d errno %d", ret, errno)) |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
204 if (ret > 0 || (ret < 0 && (errno == EINTR || errno == EAGAIN))) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
205 TRACE(("leave check_closed_writefd")) |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
206 return; |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
207 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
208 close_chan_fd(channel, fd, SHUT_WR); |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
209 TRACE(("leave check_closed_writefd after closing %d", fd)) |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
210 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
211 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 /* 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
|
213 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
|
214 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
215 struct Channel *channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
216 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
217 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
218 /* foreach channel */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
219 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 channel = ses.channels[i]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 if (channel == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 /* only process in-use channels */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
227 /* 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
|
228 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
|
229 send_msg_channel_data(channel, 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
230 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
232 /* read stderr data and send it over the wire */ |
375 | 233 if (ERRFD_IS_READ(channel) && |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
234 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
|
235 send_msg_channel_data(channel, 1); |
395
dc37bd8563e8
disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents:
394
diff
changeset
|
236 } |
dc37bd8563e8
disapproval of revision '5fdf69ca60d1683cdd9f4c2595134bed26394834'
Matt Johnston <matt@ucc.asn.au>
parents:
394
diff
changeset
|
237 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 /* 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
|
239 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
|
240 if (channel->initconn) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
241 /* 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
|
242 check_in_progress(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 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
|
244 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
|
245 } |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
246 writechannel(channel, channel->writefd, channel->writebuf); |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
247 } |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
248 |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
249 /* stderr for client mode */ |
375 | 250 if (ERRFD_IS_WRITE(channel) |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
251 && channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) { |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
252 writechannel(channel, channel->errfd, channel->extrabuf); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
253 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 |
376
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
255 /* Check writefds for close, even if we don't have anything |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
256 to write into them. */ |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
257 if (channel->writefd >= 0) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
258 check_closed_writefd(channel, channel->writefd); |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
259 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
260 if (ERRFD_IS_WRITE(channel) && channel->errfd >= 0) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
261 check_closed_writefd(channel, channel->errfd); |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
262 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
263 |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
264 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
265 /* 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
|
266 check_close(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
267 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
268 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
269 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
270 /* 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
|
271 #ifdef USING_LISTENERS |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
272 handle_listeners(readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
273 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
274 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
275 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
276 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
277 /* 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
|
278 * 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
|
279 static unsigned int write_pending(struct Channel * channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
280 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
281 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
|
282 return 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
283 } else if (channel->errfd >= 0 && channel->extrabuf && |
375 | 284 cbuf_getused(channel->extrabuf) > 0) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
285 return 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
286 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
287 return 0; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
288 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
289 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
291 /* EOF/close handling */ |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
292 static void check_close(struct Channel *channel) { |
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 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
|
295 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
|
296 channel->errfd, channel->sent_close, channel->recv_close)) |
375 | 297 TRACE(("writebuf size %d extrabuf size %d", |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
298 cbuf_getused(channel->writebuf), |
375 | 299 channel->extrabuf ? cbuf_getused(channel->extrabuf) : 0)) |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
300 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
301 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
|
302 if (! channel->sent_close) { |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
303 TRACE(("Sending MSG_CHANNEL_CLOSE in response to same.")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
304 send_msg_channel_close(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
305 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
306 remove_channel(channel); |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
307 return; |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
308 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
309 |
364 | 310 if (channel->recv_eof && !write_pending(channel)) { |
311 close_chan_fd(channel, channel->writefd, SHUT_WR); | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
312 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
313 |
375 | 314 /* If we're not going to send any more data, send EOF */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
315 if (!channel->sent_eof |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
316 && channel->readfd == FD_CLOSED |
375 | 317 && (ERRFD_IS_WRITE(channel) || channel->errfd == FD_CLOSED)) { |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
318 send_msg_channel_eof(channel); |
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
319 } |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
320 |
375 | 321 /* And if we can't receive any more data from them either, close up */ |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
322 if (!channel->sent_close |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
323 && channel->writefd == FD_CLOSED |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
324 && channel->readfd == FD_CLOSED |
375 | 325 && channel->errfd == FD_CLOSED) { |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
326 send_msg_channel_close(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
327 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
328 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
329 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
330 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
331 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
332 /* 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
|
333 * 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
|
334 * 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
|
335 * function */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
336 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
|
337 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
338 int val; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
339 socklen_t vallen = sizeof(val); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
340 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
341 TRACE(("enter check_in_progress")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
342 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
343 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
|
344 || 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
|
345 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
|
346 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
|
347 close(channel->writefd); |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
348 delete_channel(channel); |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
349 TRACE(("leave check_in_progress: fail")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
350 } 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
|
351 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
|
352 channel->recvmaxpacket); |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
353 channel->readfd = channel->writefd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
354 channel->initconn = 0; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
355 TRACE(("leave check_in_progress: success")) |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
359 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
360 /* 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
|
361 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
|
362 |
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
|
363 TRACE(("enter send_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
364 if (channel->type->closehandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
365 channel->type->closehandler(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
366 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
367 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
368 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
369 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
370 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
371 buf_putint(ses.writepayload, channel->remotechan); |
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 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
374 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
375 channel->sent_eof = 1; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
376 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
|
377 TRACE(("leave send_msg_channel_close")) |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
380 /* call this when trans/eof channels are closed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
381 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
|
382 |
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
|
383 TRACE(("enter send_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
384 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
385 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
386 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_EOF); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
387 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
388 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
389 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
390 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
391 channel->sent_eof = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
392 |
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
|
393 TRACE(("leave send_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
394 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
395 |
107 | 396 /* 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
|
397 * 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
|
398 * possible */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
399 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
|
400 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
401 int len, maxlen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
402 |
375 | 403 TRACE(("enter writechannel fd %d", fd)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
404 |
107 | 405 maxlen = cbuf_readlen(cbuf); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
406 |
107 | 407 /* Write the data out */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
408 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
|
409 if (len <= 0) { |
375 | 410 TRACE(("errno %d len %d", errno, len)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
411 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
|
412 close_chan_fd(channel, fd, SHUT_WR); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
413 } |
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
|
414 TRACE(("leave writechannel: len <= 0")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
415 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
416 } |
375 | 417 TRACE(("writechannel wrote %d", len)) |
107 | 418 |
419 cbuf_incrread(cbuf, len); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
420 channel->recvdonelen += len; |
107 | 421 |
422 /* Window adjust handling */ | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
423 if (channel->recvdonelen >= RECV_WINDOWEXTEND) { |
107 | 424 /* Set it back to max window */ |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
425 send_msg_channel_window_adjust(channel, channel->recvdonelen); |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
426 channel->recvwindow += channel->recvdonelen; |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
427 channel->recvdonelen = 0; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
428 } |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
429 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
430 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
|
431 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
|
432 dropbear_assert(channel->extrabuf == NULL || |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
433 channel->recvwindow <= cbuf_getavail(channel->extrabuf)); |
107 | 434 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
435 TRACE(("leave writechannel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
436 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
437 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
438 /* 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
|
439 * 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
|
440 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
|
441 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
442 unsigned int i; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
443 struct Channel * channel; |
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 for (i = 0; i < ses.chansize; i++) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
446 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
447 channel = ses.channels[i]; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
448 if (channel == NULL) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
449 continue; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
450 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
451 |
107 | 452 /* Stuff to put over the wire */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
453 if (channel->transwindow > 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
454 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
455 if (channel->readfd >= 0) { |
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
456 FD_SET(channel->readfd, readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
457 } |
107 | 458 |
375 | 459 if (ERRFD_IS_READ(channel) && channel->errfd >= 0) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
460 FD_SET(channel->errfd, readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
461 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
462 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
463 |
397
2908122e9eed
disapproval of revision '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
Matt Johnston <matt@ucc.asn.au>
parents:
396
diff
changeset
|
464 /* 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
|
465 if ((channel->writefd >= 0 && cbuf_getused(channel->writebuf) > 0 ) |
107 | 466 || channel->initconn) { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
467 FD_SET(channel->writefd, writefds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
468 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
469 |
375 | 470 if (ERRFD_IS_WRITE(channel) != NULL && channel->errfd >= 0 |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
471 && 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
|
472 FD_SET(channel->errfd, writefds); |
107 | 473 } |
474 | |
376
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
475 /* We also set the writefds for reading, so that we will be notified of close */ |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
476 if (channel->writefd >= 0) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
477 FD_SET(channel->writefd, readfds); |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
478 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
479 if (ERRFD_IS_WRITE(channel) && channel->errfd >= 0) { |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
480 FD_SET(channel->errfd, readfds); |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
481 } |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
482 |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
483 |
4f2dbd1c3685
Add some code for testing whether a writefd is closed (by read()ing from it)
Matt Johnston <matt@ucc.asn.au>
parents:
375
diff
changeset
|
484 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
485 } /* foreach channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
486 |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
487 #ifdef USING_LISTENERS |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
488 set_listener_fds(readfds); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
489 #endif |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
490 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
491 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
492 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
493 /* 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
|
494 * 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
|
495 * etc) FD is also EOF */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
496 void recv_msg_channel_eof() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
497 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
498 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
499 |
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
|
500 TRACE(("enter recv_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
501 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
502 channel = getchannel_msg("EOF"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
503 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
504 channel->recv_eof = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
505 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
506 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
|
507 TRACE(("leave recv_msg_channel_eof")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
508 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
509 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
510 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
511 /* 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
|
512 void recv_msg_channel_close() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
513 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
514 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
515 |
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
|
516 TRACE(("enter recv_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
517 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
518 channel = getchannel_msg("Close"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
519 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
520 channel->recv_eof = 1; |
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
521 channel->recv_close = 1; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
522 |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
523 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
|
524 TRACE(("leave recv_msg_channel_close")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
525 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
526 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
527 /* 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
|
528 * channel close */ |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
529 static void remove_channel(struct Channel * channel) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
530 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
531 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
|
532 TRACE(("channel index is %d", channel->index)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
533 |
107 | 534 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
|
535 channel->writebuf = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
536 |
107 | 537 if (channel->extrabuf) { |
538 cbuf_free(channel->extrabuf); | |
539 channel->extrabuf = NULL; | |
540 } | |
541 | |
542 | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
543 /* 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
|
544 * yet (they might have been shutdown etc) */ |
375 | 545 TRACE(("CLOSE writefd %d", channel->writefd)) |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
546 close(channel->writefd); |
375 | 547 TRACE(("CLOSE readfd %d", channel->readfd)) |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
548 close(channel->readfd); |
375 | 549 TRACE(("CLOSE errfd %d", channel->errfd)) |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
550 close(channel->errfd); |
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
551 |
70
b0316ce64e4b
Merging in the changes from 0.41-0.43 main Dropbear tree
Matt Johnston <matt@ucc.asn.au>
parents:
62
diff
changeset
|
552 channel->typedata = NULL; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
553 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
554 delete_channel(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
555 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
556 TRACE(("leave remove_channel")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
557 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
558 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
559 /* 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
|
560 static void delete_channel(struct Channel *channel) { |
4
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 ses.channels[channel->index] = NULL; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
563 m_free(channel); |
37 | 564 ses.chancount--; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
565 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
566 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
567 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
568 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
569 /* 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
|
570 * such as chansession or x11fwd */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
571 void recv_msg_channel_request() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
572 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
573 struct Channel *channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
574 |
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
|
575 TRACE(("enter recv_msg_channel_request")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
576 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
577 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
578 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
579 if (channel->type->reqhandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
580 channel->type->reqhandler(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
581 } else { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
582 send_msg_channel_failure(channel); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
583 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
584 |
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
|
585 TRACE(("leave recv_msg_channel_request")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
586 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
587 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
588 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
589 /* 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
|
590 * channel_data packet to send. |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
591 * 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
|
592 * 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
|
593 * exttype */ |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
594 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
|
595 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
596 int len; |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
597 size_t maxlen, size_pos; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
598 int fd; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
599 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
600 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
601 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
602 dropbear_assert(!channel->sent_close); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
603 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
604 if (isextended) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
605 fd = channel->errfd; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
606 } else { |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
607 fd = channel->readfd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
608 } |
375 | 609 TRACE(("enter send_msg_channel_data isextended %d fd %d", isextended, fd)) |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
610 dropbear_assert(fd >= 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
611 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
612 maxlen = MIN(channel->transwindow, channel->transmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
613 /* -(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
|
614 * exttype if is extended */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
615 maxlen = MIN(maxlen, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
616 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
|
617 TRACE(("maxlen %d", maxlen)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
618 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
|
619 TRACE(("leave send_msg_channel_data: no window")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
620 return; |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
623 buf_putbyte(ses.writepayload, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
624 isextended ? SSH_MSG_CHANNEL_EXTENDED_DATA : SSH_MSG_CHANNEL_DATA); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
625 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
626 if (isextended) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
627 buf_putint(ses.writepayload, SSH_EXTENDED_DATA_STDERR); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
628 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
629 /* 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
|
630 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
|
631 buf_putint(ses.writepayload, 0); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
632 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
633 /* 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
|
634 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
|
635 if (len <= 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
636 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
|
637 close_chan_fd(channel, fd, SHUT_RD); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
638 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
639 ses.writepayload->len = ses.writepayload->pos = 0; |
375 | 640 TRACE(("leave send_msg_channel_data: len %d read err or EOF for fd %d", |
641 len, channel->index)); | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
642 return; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
643 } |
362
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
644 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
|
645 /* ... real size here */ |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
646 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
|
647 buf_putint(ses.writepayload, len); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
648 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
649 channel->transwindow -= len; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
650 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
651 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
|
652 TRACE(("leave send_msg_channel_data")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
653 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
654 |
107 | 655 /* We receive channel data */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
656 void recv_msg_channel_data() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
657 |
107 | 658 struct Channel *channel; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
659 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
660 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
661 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
662 common_recv_msg_channel_data(channel, channel->writefd, channel->writebuf); |
107 | 663 } |
664 | |
665 /* Shared for data and stderr data - when we receive data, put it in a buffer | |
666 * for writing to the local file descriptor */ | |
667 void common_recv_msg_channel_data(struct Channel *channel, int fd, | |
668 circbuffer * cbuf) { | |
669 | |
670 unsigned int datalen; | |
671 unsigned int maxdata; | |
672 unsigned int buflen; | |
673 unsigned int len; | |
674 | |
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
|
675 TRACE(("enter recv_msg_channel_data")) |
107 | 676 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
677 if (channel->recv_eof) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
678 dropbear_exit("received data after eof"); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
679 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
680 |
107 | 681 if (fd < 0) { |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
682 /* If we have encountered failed write, the far side might still |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
683 * be sending data without having yet received our close notification. |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
684 * We just drop the data. */ |
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
685 return; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
686 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
687 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
688 datalen = buf_getint(ses.payload); |
365
49fcc9875045
Remove accidentally removed block (making sure to close the channel).
Matt Johnston <matt@ucc.asn.au>
parents:
364
diff
changeset
|
689 TRACE(("length %d", datalen)) |
107 | 690 |
691 maxdata = cbuf_getavail(cbuf); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
692 |
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
693 /* 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
|
694 * 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
|
695 * just die horribly */ |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
696 if (datalen > maxdata) { |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
697 dropbear_exit("Oversized packet"); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
698 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
699 |
107 | 700 /* We may have to run throught twice, if the buffer wraps around. Can't |
701 * just "leave it for next time" like with writechannel, since this | |
702 * is payload data */ | |
703 len = datalen; | |
704 while (len > 0) { | |
705 buflen = cbuf_writelen(cbuf); | |
706 buflen = MIN(buflen, len); | |
707 | |
708 memcpy(cbuf_writeptr(cbuf, buflen), | |
709 buf_getptr(ses.payload, buflen), buflen); | |
710 cbuf_incrwrite(cbuf, buflen); | |
108
10f4d3319780
- added circular buffering for channels
Matt Johnston <matt@ucc.asn.au>
parents:
107
diff
changeset
|
711 buf_incrpos(ses.payload, buflen); |
107 | 712 len -= buflen; |
713 } | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
714 |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
715 dropbear_assert(channel->recvwindow >= datalen); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
716 channel->recvwindow -= datalen; |
241
c5d3ef11155f
* use own assertions which should get logged properly
Matt Johnston <matt@ucc.asn.au>
parents:
221
diff
changeset
|
717 dropbear_assert(channel->recvwindow <= RECV_MAXWINDOW); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
718 |
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
|
719 TRACE(("leave recv_msg_channel_data")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
720 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
721 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
722 /* 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
|
723 * 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
|
724 * 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
|
725 void recv_msg_channel_window_adjust() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
726 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
727 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
728 unsigned int incr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
729 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
730 channel = getchannel(); |
4
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 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
|
733 TRACE(("received window increment %d", incr)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
734 incr = MIN(incr, MAX_TRANS_WIN_INCR); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
735 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
736 channel->transwindow += incr; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
737 channel->transwindow = MIN(channel->transwindow, MAX_TRANS_WINDOW); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
738 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
739 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
740 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
741 /* 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
|
742 * end know */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
743 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
|
744 unsigned int incr) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
745 |
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
|
746 TRACE(("sending window adjust %d", incr)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
747 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
748 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
749 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_WINDOW_ADJUST); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
750 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
751 buf_putint(ses.writepayload, incr); |
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 encrypt_packet(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
754 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
755 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
756 /* 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
|
757 void recv_msg_channel_open() { |
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 unsigned char *type; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
760 unsigned int typelen; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
761 unsigned int remotechan, transwindow, transmaxpacket; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
762 struct Channel *channel; |
7 | 763 const struct ChanType **cp; |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
764 const struct ChanType *chantype; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
765 unsigned int errtype = SSH_OPEN_UNKNOWN_CHANNEL_TYPE; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
766 int ret; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
767 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
768 |
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
|
769 TRACE(("enter recv_msg_channel_open")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
770 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
771 /* get the packet contents */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
772 type = buf_getstring(ses.payload, &typelen); |
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 remotechan = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
775 transwindow = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
776 transwindow = MIN(transwindow, MAX_TRANS_WINDOW); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
777 transmaxpacket = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
778 transmaxpacket = MIN(transmaxpacket, MAX_TRANS_PAYLOAD_LEN); |
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 /* figure what type of packet it is */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
781 if (typelen > MAX_NAME_LEN) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
782 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
783 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
784 |
7 | 785 /* Get the channel type. Client and server style invokation will set up a |
786 * different list for ses.chantypes at startup. We just iterate through | |
787 * this list and find the matching name */ | |
788 for (cp = &ses.chantypes[0], chantype = (*cp); | |
789 chantype != NULL; | |
790 cp++, chantype = (*cp)) { | |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
791 if (strcmp(type, chantype->name) == 0) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
792 break; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
793 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
794 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
795 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
796 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
|
797 TRACE(("No matching type for '%s'", type)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
798 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
799 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
800 |
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
|
801 TRACE(("matched type '%s'", type)) |
7 | 802 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
803 /* create the channel */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
804 channel = newchannel(remotechan, chantype, transwindow, transmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
805 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
806 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
|
807 TRACE(("newchannel returned NULL")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
808 goto failure; |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
811 if (channel->type->inithandler) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
812 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
|
813 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
|
814 /* 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
|
815 goto cleanup; |
1c7bf9cec6c8
Rearranged some more bits, marked some areas that need work.
Matt Johnston <matt@ucc.asn.au>
parents:
359
diff
changeset
|
816 } |
6
ab00ef513e97
Sorted out the first channel init issues.
Matt Johnston <matt@ucc.asn.au>
parents:
4
diff
changeset
|
817 if (ret > 0) { |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
818 errtype = ret; |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
819 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
|
820 TRACE(("inithandler returned failure %d", ret)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
821 goto failure; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
822 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
823 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
824 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
825 /* success */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
826 send_msg_channel_open_confirmation(channel, channel->recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
827 channel->recvmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
828 goto cleanup; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
829 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
830 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
|
831 TRACE(("recv_msg_channel_open failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
832 send_msg_channel_open_failure(remotechan, errtype, "", ""); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
833 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
834 cleanup: |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
835 m_free(type); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
836 |
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
|
837 TRACE(("leave recv_msg_channel_open")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
838 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
839 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
840 /* Send a failure message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
841 void send_msg_channel_failure(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
842 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
843 TRACE(("enter send_msg_channel_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
844 CHECKCLEARTOWRITE(); |
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 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_FAILURE); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
847 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
848 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
849 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
|
850 TRACE(("leave send_msg_channel_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
851 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
852 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
853 /* Send a success message */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
854 void send_msg_channel_success(struct Channel *channel) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
855 |
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
|
856 TRACE(("enter send_msg_channel_success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
857 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
858 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
859 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_SUCCESS); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
860 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
861 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
862 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
|
863 TRACE(("leave send_msg_channel_success")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
864 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
865 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
866 /* 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
|
867 * code (usually resource shortage or unknown chan type) */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
868 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
|
869 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
|
870 |
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
|
871 TRACE(("enter send_msg_channel_open_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
872 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
873 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
874 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
|
875 buf_putint(ses.writepayload, remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
876 buf_putint(ses.writepayload, reason); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
877 buf_putstring(ses.writepayload, text, strlen((char*)text)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
878 buf_putstring(ses.writepayload, lang, strlen((char*)lang)); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
879 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
880 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
|
881 TRACE(("leave send_msg_channel_open_failure")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
882 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
883 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
884 /* 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
|
885 * allocated and the receive parameters */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
886 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
|
887 unsigned int recvwindow, |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
888 unsigned int recvmaxpacket) { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
889 |
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
|
890 TRACE(("enter send_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
891 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
892 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
893 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
|
894 buf_putint(ses.writepayload, channel->remotechan); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
895 buf_putint(ses.writepayload, channel->index); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
896 buf_putint(ses.writepayload, recvwindow); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
897 buf_putint(ses.writepayload, recvmaxpacket); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
898 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
899 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
|
900 TRACE(("leave send_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
901 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
902 |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
903 /* 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
|
904 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
|
905 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
906 int closein = 0, closeout = 0; |
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 (channel->type->sepfds) { |
375 | 909 TRACE(("SHUTDOWN(%d, %d)", fd, how)) |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
910 shutdown(fd, how); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
911 if (how == 0) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
912 closeout = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
913 } else { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
914 closein = 1; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
915 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
916 } else { |
375 | 917 TRACE(("CLOSE some fd %d", fd)) |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
918 close(fd); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
919 closein = closeout = 1; |
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 |
375 | 922 if (closeout && (fd == channel->readfd)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
923 channel->readfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
924 } |
375 | 925 if (closeout && ERRFD_IS_READ(channel) && (fd == channel->errfd)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
926 channel->errfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
927 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
928 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
929 if (closein && fd == channel->writefd) { |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
930 channel->writefd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
931 } |
375 | 932 if (closein && ERRFD_IS_WRITE(channel) && (fd == channel->errfd)) { |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
933 channel->errfd = FD_CLOSED; |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
934 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
935 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
936 /* 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
|
937 * 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
|
938 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
|
939 && channel->writefd == FD_CLOSED && channel->errfd == FD_CLOSED) { |
375 | 940 TRACE(("CLOSE (finally) of %d", fd)) |
363
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
941 close(fd); |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
942 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
943 } |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
944 |
6ba2894ec8d5
Rearranged (and hopefully simplified) channel close/eof handling
Matt Johnston <matt@ucc.asn.au>
parents:
362
diff
changeset
|
945 |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
946 #if defined(USING_LISTENERS) || defined(DROPBEAR_CLIENT) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
947 /* 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
|
948 * 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
|
949 * 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
|
950 * 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
|
951 * DROPBEAR_SUCCESS is returned */ |
9
7f77962de998
- Reworked non-channel fd handling to listener.c
Matt Johnston <matt@ucc.asn.au>
parents:
7
diff
changeset
|
952 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
|
953 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
954 struct Channel* chan; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
955 |
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
|
956 TRACE(("enter send_msg_channel_open_init()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
957 chan = newchannel(0, type, 0, 0); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
958 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
|
959 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
|
960 return DROPBEAR_FAILURE; |
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 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
963 /* set fd non-blocking */ |
109
2e9d1f29c50f
merge of 50be59810e462f9f44f55e421227d6aa0b31982b
Matt Johnston <matt@ucc.asn.au>
parents:
108
diff
changeset
|
964 setnonblocking(fd); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
965 |
253
84925eceeb13
* rename infd/outfd to writefd/readfd, to avoid confusion
Matt Johnston <matt@ucc.asn.au>
parents:
243
diff
changeset
|
966 chan->writefd = chan->readfd = fd; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
967 ses.maxfd = MAX(ses.maxfd, fd); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
968 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
969 chan->await_open = 1; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
970 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
971 /* now open the channel connection */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
972 CHECKCLEARTOWRITE(); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
973 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
974 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
|
975 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
|
976 buf_putint(ses.writepayload, chan->index); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
977 buf_putint(ses.writepayload, RECV_MAXWINDOW); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
978 buf_putint(ses.writepayload, RECV_MAXPACKET); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
979 |
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
|
980 TRACE(("leave send_msg_channel_open_init()")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
981 return DROPBEAR_SUCCESS; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
982 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
983 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
984 /* 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
|
985 * successful*/ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
986 void recv_msg_channel_open_confirmation() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
987 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
988 struct Channel * channel; |
37 | 989 int ret; |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
990 |
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
|
991 TRACE(("enter recv_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
992 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
993 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
994 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
995 if (!channel->await_open) { |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
996 dropbear_exit("unexpected channel reply"); |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
997 } |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
998 channel->await_open = 0; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
999 |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1000 channel->remotechan = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1001 channel->transwindow = buf_getint(ses.payload); |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1002 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
|
1003 |
187
c44df7123b0a
compile fix when TRACE debugging is enabled
Matt Johnston <matt@ucc.asn.au>
parents:
179
diff
changeset
|
1004 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
|
1005 channel->remotechan, channel->index)) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1006 |
37 | 1007 /* Run the inithandler callback */ |
1008 if (channel->type->inithandler) { | |
1009 ret = channel->type->inithandler(channel); | |
1010 if (ret > 0) { | |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
1011 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
|
1012 TRACE(("inithandler returned failure %d", ret)) |
37 | 1013 } |
1014 } | |
1015 | |
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
|
1016 |
165
0cfba3034be5
Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
Matt Johnston <matt@ucc.asn.au>
parents:
156
diff
changeset
|
1017 TRACE(("leave recv_msg_channel_open_confirmation")) |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1018 } |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1019 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1020 /* Notification that our channel open request failed */ |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1021 void recv_msg_channel_open_failure() { |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1022 |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1023 struct Channel * channel; |
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1024 |
179
161557a9dde8
* fix longstanding bug with connections being closed on failure to
Matt Johnston <matt@ucc.asn.au>
parents:
165
diff
changeset
|
1025 channel = getchannel(); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1026 |
243
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1027 if (!channel->await_open) { |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1028 dropbear_exit("unexpected channel reply"); |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1029 } |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1030 channel->await_open = 0; |
0056419cf0f4
* ensure that we only handle open confirmation/failure
Matt Johnston <matt@ucc.asn.au>
parents:
241
diff
changeset
|
1031 |
359
78518751cb82
just shuffle some variables names about, a brief comment
Matt Johnston <matt@ucc.asn.au>
parents:
332
diff
changeset
|
1032 remove_channel(channel); |
4
fe6bca95afa7
Makefile.in contains updated files required
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1033 } |
156
8c2b3506f112
Rearrange preprocessor parts so that compilation with various options
Matt Johnston <matt@ucc.asn.au>
parents:
109
diff
changeset
|
1034 #endif /* USING_LISTENERS */ |