summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-12-13 19:33:57 +1100
committerDamien Miller <djm@mindrot.org>2005-12-13 19:33:57 +1100
commitd47c62a714c2c3e6a564aa498e3ef0445c9f9ea3 (patch)
treecfbc1602e7f27092ada0ff160f8985e1cb813c6d /channels.c
parent7746c391b105dd9b1a348b816ca0150bf701e1e2 (diff)
- markus@cvs.openbsd.org 2005/12/12 13:46:18
[channels.c channels.h session.c] make sure protocol messages for internal channels are ignored. allow adjust messages for non-open channels; with and ok djm@
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/channels.c b/channels.c
index b4fd89f96..e73dc247d 100644
--- a/channels.c
+++ b/channels.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: channels.c,v 1.228 2005/12/06 22:38:27 reyk Exp $"); 42RCSID("$OpenBSD: channels.c,v 1.229 2005/12/12 13:46:18 markus Exp $");
43 43
44#include "ssh.h" 44#include "ssh.h"
45#include "ssh1.h" 45#include "ssh1.h"
@@ -142,23 +142,51 @@ static void port_open_helper(Channel *c, char *rtype);
142/* -- channel core */ 142/* -- channel core */
143 143
144Channel * 144Channel *
145channel_lookup(int id) 145channel_by_id(int id)
146{ 146{
147 Channel *c; 147 Channel *c;
148 148
149 if (id < 0 || (u_int)id >= channels_alloc) { 149 if (id < 0 || (u_int)id >= channels_alloc) {
150 logit("channel_lookup: %d: bad id", id); 150 logit("channel_by_id: %d: bad id", id);
151 return NULL; 151 return NULL;
152 } 152 }
153 c = channels[id]; 153 c = channels[id];
154 if (c == NULL) { 154 if (c == NULL) {
155 logit("channel_lookup: %d: bad id: channel free", id); 155 logit("channel_by_id: %d: bad id: channel free", id);
156 return NULL; 156 return NULL;
157 } 157 }
158 return c; 158 return c;
159} 159}
160 160
161/* 161/*
162 * Returns the channel if it is allowed to receive protocol messages.
163 * Private channels, like listening sockets, may not receive messages.
164 */
165Channel *
166channel_lookup(int id)
167{
168 Channel *c;
169
170 if ((c = channel_by_id(id)) == NULL)
171 return (NULL);
172
173 switch(c->type) {
174 case SSH_CHANNEL_X11_OPEN:
175 case SSH_CHANNEL_LARVAL:
176 case SSH_CHANNEL_CONNECTING:
177 case SSH_CHANNEL_DYNAMIC:
178 case SSH_CHANNEL_OPENING:
179 case SSH_CHANNEL_OPEN:
180 case SSH_CHANNEL_INPUT_DRAINING:
181 case SSH_CHANNEL_OUTPUT_DRAINING:
182 return (c);
183 break;
184 }
185 logit("Non-public channel %d, type %d.", id, c->type);
186 return (NULL);
187}
188
189/*
162 * Register filedescriptors for a channel, used when allocating a channel or 190 * Register filedescriptors for a channel, used when allocating a channel or
163 * when the channel consumer/producer is ready, e.g. shell exec'd 191 * when the channel consumer/producer is ready, e.g. shell exec'd
164 */ 192 */
@@ -631,7 +659,7 @@ channel_register_confirm(int id, channel_callback_fn *fn, void *ctx)
631void 659void
632channel_register_cleanup(int id, channel_callback_fn *fn, int do_close) 660channel_register_cleanup(int id, channel_callback_fn *fn, int do_close)
633{ 661{
634 Channel *c = channel_lookup(id); 662 Channel *c = channel_by_id(id);
635 663
636 if (c == NULL) { 664 if (c == NULL) {
637 logit("channel_register_cleanup: %d: bad id", id); 665 logit("channel_register_cleanup: %d: bad id", id);
@@ -643,7 +671,7 @@ channel_register_cleanup(int id, channel_callback_fn *fn, int do_close)
643void 671void
644channel_cancel_cleanup(int id) 672channel_cancel_cleanup(int id)
645{ 673{
646 Channel *c = channel_lookup(id); 674 Channel *c = channel_by_id(id);
647 675
648 if (c == NULL) { 676 if (c == NULL) {
649 logit("channel_cancel_cleanup: %d: bad id", id); 677 logit("channel_cancel_cleanup: %d: bad id", id);
@@ -2183,9 +2211,8 @@ channel_input_window_adjust(int type, u_int32_t seq, void *ctxt)
2183 id = packet_get_int(); 2211 id = packet_get_int();
2184 c = channel_lookup(id); 2212 c = channel_lookup(id);
2185 2213
2186 if (c == NULL || c->type != SSH_CHANNEL_OPEN) { 2214 if (c == NULL) {
2187 logit("Received window adjust for " 2215 logit("Received window adjust for non-open channel %d.", id);
2188 "non-open channel %d.", id);
2189 return; 2216 return;
2190 } 2217 }
2191 adjust = packet_get_int(); 2218 adjust = packet_get_int();