summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
authormarkus@openbsd.org <markus@openbsd.org>2015-01-19 20:07:45 +0000
committerDamien Miller <djm@mindrot.org>2015-01-20 09:14:16 +1100
commit3fdc88a0def4f86aa88a5846ac079dc964c0546a (patch)
treed26470c8ffb49bb4417af2b729d933d6ce3f75f8 /channels.c
parent091c302829210c41e7f57c3f094c7b9c054306f0 (diff)
upstream commit
move dispatch to struct ssh; ok djm@
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c63
1 files changed, 37 insertions, 26 deletions
diff --git a/channels.c b/channels.c
index 6db92cbac..29a62f70a 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.338 2014/12/11 08:20:09 djm Exp $ */ 1/* $OpenBSD: channels.c,v 1.339 2015/01/19 20:07:45 markus Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2343,7 +2343,7 @@ channel_output_poll(void)
2343/* -- protocol input */ 2343/* -- protocol input */
2344 2344
2345/* ARGSUSED */ 2345/* ARGSUSED */
2346void 2346int
2347channel_input_data(int type, u_int32_t seq, void *ctxt) 2347channel_input_data(int type, u_int32_t seq, void *ctxt)
2348{ 2348{
2349 int id; 2349 int id;
@@ -2360,7 +2360,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
2360 /* Ignore any data for non-open channels (might happen on close) */ 2360 /* Ignore any data for non-open channels (might happen on close) */
2361 if (c->type != SSH_CHANNEL_OPEN && 2361 if (c->type != SSH_CHANNEL_OPEN &&
2362 c->type != SSH_CHANNEL_X11_OPEN) 2362 c->type != SSH_CHANNEL_X11_OPEN)
2363 return; 2363 return 0;
2364 2364
2365 /* Get the data. */ 2365 /* Get the data. */
2366 data = packet_get_string_ptr(&data_len); 2366 data = packet_get_string_ptr(&data_len);
@@ -2380,7 +2380,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
2380 c->local_window -= win_len; 2380 c->local_window -= win_len;
2381 c->local_consumed += win_len; 2381 c->local_consumed += win_len;
2382 } 2382 }
2383 return; 2383 return 0;
2384 } 2384 }
2385 2385
2386 if (compat20) { 2386 if (compat20) {
@@ -2391,7 +2391,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
2391 if (win_len > c->local_window) { 2391 if (win_len > c->local_window) {
2392 logit("channel %d: rcvd too much data %d, win %d", 2392 logit("channel %d: rcvd too much data %d, win %d",
2393 c->self, win_len, c->local_window); 2393 c->self, win_len, c->local_window);
2394 return; 2394 return 0;
2395 } 2395 }
2396 c->local_window -= win_len; 2396 c->local_window -= win_len;
2397 } 2397 }
@@ -2400,10 +2400,11 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
2400 else 2400 else
2401 buffer_append(&c->output, data, data_len); 2401 buffer_append(&c->output, data, data_len);
2402 packet_check_eom(); 2402 packet_check_eom();
2403 return 0;
2403} 2404}
2404 2405
2405/* ARGSUSED */ 2406/* ARGSUSED */
2406void 2407int
2407channel_input_extended_data(int type, u_int32_t seq, void *ctxt) 2408channel_input_extended_data(int type, u_int32_t seq, void *ctxt)
2408{ 2409{
2409 int id; 2410 int id;
@@ -2419,7 +2420,7 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt)
2419 packet_disconnect("Received extended_data for bad channel %d.", id); 2420 packet_disconnect("Received extended_data for bad channel %d.", id);
2420 if (c->type != SSH_CHANNEL_OPEN) { 2421 if (c->type != SSH_CHANNEL_OPEN) {
2421 logit("channel %d: ext data for non open", id); 2422 logit("channel %d: ext data for non open", id);
2422 return; 2423 return 0;
2423 } 2424 }
2424 if (c->flags & CHAN_EOF_RCVD) { 2425 if (c->flags & CHAN_EOF_RCVD) {
2425 if (datafellows & SSH_BUG_EXTEOF) 2426 if (datafellows & SSH_BUG_EXTEOF)
@@ -2433,7 +2434,7 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt)
2433 c->extended_usage != CHAN_EXTENDED_WRITE || 2434 c->extended_usage != CHAN_EXTENDED_WRITE ||
2434 tcode != SSH2_EXTENDED_DATA_STDERR) { 2435 tcode != SSH2_EXTENDED_DATA_STDERR) {
2435 logit("channel %d: bad ext data", c->self); 2436 logit("channel %d: bad ext data", c->self);
2436 return; 2437 return 0;
2437 } 2438 }
2438 data = packet_get_string(&data_len); 2439 data = packet_get_string(&data_len);
2439 packet_check_eom(); 2440 packet_check_eom();
@@ -2441,16 +2442,17 @@ channel_input_extended_data(int type, u_int32_t seq, void *ctxt)
2441 logit("channel %d: rcvd too much extended_data %d, win %d", 2442 logit("channel %d: rcvd too much extended_data %d, win %d",
2442 c->self, data_len, c->local_window); 2443 c->self, data_len, c->local_window);
2443 free(data); 2444 free(data);
2444 return; 2445 return 0;
2445 } 2446 }
2446 debug2("channel %d: rcvd ext data %d", c->self, data_len); 2447 debug2("channel %d: rcvd ext data %d", c->self, data_len);
2447 c->local_window -= data_len; 2448 c->local_window -= data_len;
2448 buffer_append(&c->extended, data, data_len); 2449 buffer_append(&c->extended, data, data_len);
2449 free(data); 2450 free(data);
2451 return 0;
2450} 2452}
2451 2453
2452/* ARGSUSED */ 2454/* ARGSUSED */
2453void 2455int
2454channel_input_ieof(int type, u_int32_t seq, void *ctxt) 2456channel_input_ieof(int type, u_int32_t seq, void *ctxt)
2455{ 2457{
2456 int id; 2458 int id;
@@ -2470,11 +2472,11 @@ channel_input_ieof(int type, u_int32_t seq, void *ctxt)
2470 if (buffer_len(&c->input) == 0) 2472 if (buffer_len(&c->input) == 0)
2471 chan_ibuf_empty(c); 2473 chan_ibuf_empty(c);
2472 } 2474 }
2473 2475 return 0;
2474} 2476}
2475 2477
2476/* ARGSUSED */ 2478/* ARGSUSED */
2477void 2479int
2478channel_input_close(int type, u_int32_t seq, void *ctxt) 2480channel_input_close(int type, u_int32_t seq, void *ctxt)
2479{ 2481{
2480 int id; 2482 int id;
@@ -2509,11 +2511,12 @@ channel_input_close(int type, u_int32_t seq, void *ctxt)
2509 buffer_clear(&c->input); 2511 buffer_clear(&c->input);
2510 c->type = SSH_CHANNEL_OUTPUT_DRAINING; 2512 c->type = SSH_CHANNEL_OUTPUT_DRAINING;
2511 } 2513 }
2514 return 0;
2512} 2515}
2513 2516
2514/* proto version 1.5 overloads CLOSE_CONFIRMATION with OCLOSE */ 2517/* proto version 1.5 overloads CLOSE_CONFIRMATION with OCLOSE */
2515/* ARGSUSED */ 2518/* ARGSUSED */
2516void 2519int
2517channel_input_oclose(int type, u_int32_t seq, void *ctxt) 2520channel_input_oclose(int type, u_int32_t seq, void *ctxt)
2518{ 2521{
2519 int id = packet_get_int(); 2522 int id = packet_get_int();
@@ -2523,10 +2526,11 @@ channel_input_oclose(int type, u_int32_t seq, void *ctxt)
2523 if (c == NULL) 2526 if (c == NULL)
2524 packet_disconnect("Received oclose for nonexistent channel %d.", id); 2527 packet_disconnect("Received oclose for nonexistent channel %d.", id);
2525 chan_rcvd_oclose(c); 2528 chan_rcvd_oclose(c);
2529 return 0;
2526} 2530}
2527 2531
2528/* ARGSUSED */ 2532/* ARGSUSED */
2529void 2533int
2530channel_input_close_confirmation(int type, u_int32_t seq, void *ctxt) 2534channel_input_close_confirmation(int type, u_int32_t seq, void *ctxt)
2531{ 2535{
2532 int id = packet_get_int(); 2536 int id = packet_get_int();
@@ -2540,10 +2544,11 @@ channel_input_close_confirmation(int type, u_int32_t seq, void *ctxt)
2540 packet_disconnect("Received close confirmation for " 2544 packet_disconnect("Received close confirmation for "
2541 "non-closed channel %d (type %d).", id, c->type); 2545 "non-closed channel %d (type %d).", id, c->type);
2542 channel_free(c); 2546 channel_free(c);
2547 return 0;
2543} 2548}
2544 2549
2545/* ARGSUSED */ 2550/* ARGSUSED */
2546void 2551int
2547channel_input_open_confirmation(int type, u_int32_t seq, void *ctxt) 2552channel_input_open_confirmation(int type, u_int32_t seq, void *ctxt)
2548{ 2553{
2549 int id, remote_id; 2554 int id, remote_id;
@@ -2572,6 +2577,7 @@ channel_input_open_confirmation(int type, u_int32_t seq, void *ctxt)
2572 c->remote_window, c->remote_maxpacket); 2577 c->remote_window, c->remote_maxpacket);
2573 } 2578 }
2574 packet_check_eom(); 2579 packet_check_eom();
2580 return 0;
2575} 2581}
2576 2582
2577static char * 2583static char *
@@ -2591,7 +2597,7 @@ reason2txt(int reason)
2591} 2597}
2592 2598
2593/* ARGSUSED */ 2599/* ARGSUSED */
2594void 2600int
2595channel_input_open_failure(int type, u_int32_t seq, void *ctxt) 2601channel_input_open_failure(int type, u_int32_t seq, void *ctxt)
2596{ 2602{
2597 int id, reason; 2603 int id, reason;
@@ -2623,10 +2629,11 @@ channel_input_open_failure(int type, u_int32_t seq, void *ctxt)
2623 packet_check_eom(); 2629 packet_check_eom();
2624 /* Schedule the channel for cleanup/deletion. */ 2630 /* Schedule the channel for cleanup/deletion. */
2625 chan_mark_dead(c); 2631 chan_mark_dead(c);
2632 return 0;
2626} 2633}
2627 2634
2628/* ARGSUSED */ 2635/* ARGSUSED */
2629void 2636int
2630channel_input_window_adjust(int type, u_int32_t seq, void *ctxt) 2637channel_input_window_adjust(int type, u_int32_t seq, void *ctxt)
2631{ 2638{
2632 Channel *c; 2639 Channel *c;
@@ -2634,7 +2641,7 @@ channel_input_window_adjust(int type, u_int32_t seq, void *ctxt)
2634 u_int adjust; 2641 u_int adjust;
2635 2642
2636 if (!compat20) 2643 if (!compat20)
2637 return; 2644 return 0;
2638 2645
2639 /* Get the channel number and verify it. */ 2646 /* Get the channel number and verify it. */
2640 id = packet_get_int(); 2647 id = packet_get_int();
@@ -2642,16 +2649,17 @@ channel_input_window_adjust(int type, u_int32_t seq, void *ctxt)
2642 2649
2643 if (c == NULL) { 2650 if (c == NULL) {
2644 logit("Received window adjust for non-open channel %d.", id); 2651 logit("Received window adjust for non-open channel %d.", id);
2645 return; 2652 return 0;
2646 } 2653 }
2647 adjust = packet_get_int(); 2654 adjust = packet_get_int();
2648 packet_check_eom(); 2655 packet_check_eom();
2649 debug2("channel %d: rcvd adjust %u", id, adjust); 2656 debug2("channel %d: rcvd adjust %u", id, adjust);
2650 c->remote_window += adjust; 2657 c->remote_window += adjust;
2658 return 0;
2651} 2659}
2652 2660
2653/* ARGSUSED */ 2661/* ARGSUSED */
2654void 2662int
2655channel_input_port_open(int type, u_int32_t seq, void *ctxt) 2663channel_input_port_open(int type, u_int32_t seq, void *ctxt)
2656{ 2664{
2657 Channel *c = NULL; 2665 Channel *c = NULL;
@@ -2679,10 +2687,11 @@ channel_input_port_open(int type, u_int32_t seq, void *ctxt)
2679 packet_send(); 2687 packet_send();
2680 } else 2688 } else
2681 c->remote_id = remote_id; 2689 c->remote_id = remote_id;
2690 return 0;
2682} 2691}
2683 2692
2684/* ARGSUSED */ 2693/* ARGSUSED */
2685void 2694int
2686channel_input_status_confirm(int type, u_int32_t seq, void *ctxt) 2695channel_input_status_confirm(int type, u_int32_t seq, void *ctxt)
2687{ 2696{
2688 Channel *c; 2697 Channel *c;
@@ -2699,15 +2708,15 @@ channel_input_status_confirm(int type, u_int32_t seq, void *ctxt)
2699 2708
2700 if ((c = channel_lookup(id)) == NULL) { 2709 if ((c = channel_lookup(id)) == NULL) {
2701 logit("channel_input_status_confirm: %d: unknown", id); 2710 logit("channel_input_status_confirm: %d: unknown", id);
2702 return; 2711 return 0;
2703 } 2712 }
2704 ;
2705 if ((cc = TAILQ_FIRST(&c->status_confirms)) == NULL) 2713 if ((cc = TAILQ_FIRST(&c->status_confirms)) == NULL)
2706 return; 2714 return 0;
2707 cc->cb(type, c, cc->ctx); 2715 cc->cb(type, c, cc->ctx);
2708 TAILQ_REMOVE(&c->status_confirms, cc, entry); 2716 TAILQ_REMOVE(&c->status_confirms, cc, entry);
2709 explicit_bzero(cc, sizeof(*cc)); 2717 explicit_bzero(cc, sizeof(*cc));
2710 free(cc); 2718 free(cc);
2719 return 0;
2711} 2720}
2712 2721
2713/* -- tcp forwarding */ 2722/* -- tcp forwarding */
@@ -4095,7 +4104,7 @@ x11_connect_display(void)
4095 */ 4104 */
4096 4105
4097/* ARGSUSED */ 4106/* ARGSUSED */
4098void 4107int
4099x11_input_open(int type, u_int32_t seq, void *ctxt) 4108x11_input_open(int type, u_int32_t seq, void *ctxt)
4100{ 4109{
4101 Channel *c = NULL; 4110 Channel *c = NULL;
@@ -4135,11 +4144,12 @@ x11_input_open(int type, u_int32_t seq, void *ctxt)
4135 packet_put_int(c->self); 4144 packet_put_int(c->self);
4136 } 4145 }
4137 packet_send(); 4146 packet_send();
4147 return 0;
4138} 4148}
4139 4149
4140/* dummy protocol handler that denies SSH-1 requests (agent/x11) */ 4150/* dummy protocol handler that denies SSH-1 requests (agent/x11) */
4141/* ARGSUSED */ 4151/* ARGSUSED */
4142void 4152int
4143deny_input_open(int type, u_int32_t seq, void *ctxt) 4153deny_input_open(int type, u_int32_t seq, void *ctxt)
4144{ 4154{
4145 int rchan = packet_get_int(); 4155 int rchan = packet_get_int();
@@ -4159,6 +4169,7 @@ deny_input_open(int type, u_int32_t seq, void *ctxt)
4159 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE); 4169 packet_start(SSH_MSG_CHANNEL_OPEN_FAILURE);
4160 packet_put_int(rchan); 4170 packet_put_int(rchan);
4161 packet_send(); 4171 packet_send();
4172 return 0;
4162} 4173}
4163 4174
4164/* 4175/*