comparison common-channel.c @ 179:161557a9dde8

* fix longstanding bug with connections being closed on failure to connect to auth socket (server) * differentiate between get_byte and get_bool * get rid of some // comments * general tidying
author Matt Johnston <matt@ucc.asn.au>
date Sun, 13 Mar 2005 13:58:14 +0000
parents 0cfba3034be5
children c44df7123b0a
comparison
equal deleted inserted replaced
178:058cc7892636 179:161557a9dde8
160 TRACE(("leave newchannel")) 160 TRACE(("leave newchannel"))
161 161
162 return newchan; 162 return newchan;
163 } 163 }
164 164
165 /* Get the channel structure corresponding to a channel number */ 165 /* Returns the channel structure corresponding to the channel in the current
166 struct Channel* getchannel(unsigned int chan) { 166 * data packet (ses.payload must be positioned appropriately) */
167 struct Channel* getchannel() {
168
169 unsigned int chan;
170
171 chan = buf_getint(ses.payload);
167 if (chan >= ses.chansize || ses.channels[chan] == NULL) { 172 if (chan >= ses.chansize || ses.channels[chan] == NULL) {
168 return NULL; 173 return NULL;
169 } 174 }
170 return ses.channels[chan]; 175 return ses.channels[chan];
171 } 176 }
472 /* handle the channel EOF event, by closing the channel filedescriptor. The 477 /* handle the channel EOF event, by closing the channel filedescriptor. The
473 * channel isn't closed yet, it is left until the incoming (from the program 478 * channel isn't closed yet, it is left until the incoming (from the program
474 * etc) FD is also EOF */ 479 * etc) FD is also EOF */
475 void recv_msg_channel_eof() { 480 void recv_msg_channel_eof() {
476 481
477 unsigned int chan;
478 struct Channel * channel; 482 struct Channel * channel;
479 483
480 TRACE(("enter recv_msg_channel_eof")) 484 TRACE(("enter recv_msg_channel_eof"))
481 485
482 chan = buf_getint(ses.payload); 486 channel = getchannel();
483 channel = getchannel(chan);
484
485 if (channel == NULL) { 487 if (channel == NULL) {
486 dropbear_exit("EOF for unknown channel"); 488 dropbear_exit("EOF for unknown channel");
487 } 489 }
488 490
489 channel->recveof = 1; 491 channel->recveof = 1;
498 500
499 501
500 /* Handle channel closure(), respond in kind and close the channels */ 502 /* Handle channel closure(), respond in kind and close the channels */
501 void recv_msg_channel_close() { 503 void recv_msg_channel_close() {
502 504
503 unsigned int chan;
504 struct Channel * channel; 505 struct Channel * channel;
505 506
506 TRACE(("enter recv_msg_channel_close")) 507 TRACE(("enter recv_msg_channel_close"))
507 508
508 chan = buf_getint(ses.payload); 509 channel = getchannel();
509 TRACE(("close channel = %d", chan))
510 channel = getchannel(chan);
511
512 if (channel == NULL) { 510 if (channel == NULL) {
513 /* disconnect ? */ 511 /* disconnect ? */
514 dropbear_exit("Close for unknown channel"); 512 dropbear_exit("Close for unknown channel");
515 } 513 }
516 514
565 563
566 /* Handle channel specific requests, passing off to corresponding handlers 564 /* Handle channel specific requests, passing off to corresponding handlers
567 * such as chansession or x11fwd */ 565 * such as chansession or x11fwd */
568 void recv_msg_channel_request() { 566 void recv_msg_channel_request() {
569 567
570 unsigned int chan;
571 struct Channel *channel; 568 struct Channel *channel;
572 569
573 TRACE(("enter recv_msg_channel_request")) 570 TRACE(("enter recv_msg_channel_request"))
574 571
575 chan = buf_getint(ses.payload); 572 channel = getchannel();
576 channel = getchannel(chan);
577
578 if (channel == NULL) { 573 if (channel == NULL) {
579 /* disconnect ? */ 574 /* disconnect ? */
580 dropbear_exit("Unknown channel"); 575 dropbear_exit("Unknown channel");
581 } 576 }
582 577
664 } 659 }
665 660
666 /* We receive channel data */ 661 /* We receive channel data */
667 void recv_msg_channel_data() { 662 void recv_msg_channel_data() {
668 663
669 unsigned int chan;
670 struct Channel *channel; 664 struct Channel *channel;
671 665
672 chan = buf_getint(ses.payload); 666 channel = getchannel();
673 channel = getchannel(chan);
674
675 if (channel == NULL) { 667 if (channel == NULL) {
676 dropbear_exit("Unknown channel"); 668 dropbear_exit("Unknown channel");
677 } 669 }
678 670
679 common_recv_msg_channel_data(channel, channel->infd, channel->writebuf); 671 common_recv_msg_channel_data(channel, channel->infd, channel->writebuf);
736 /* Increment the outgoing data window for a channel - the remote end limits 728 /* Increment the outgoing data window for a channel - the remote end limits
737 * the amount of data which may be transmitted, this window is decremented 729 * the amount of data which may be transmitted, this window is decremented
738 * as data is sent, and incremented upon receiving window-adjust messages */ 730 * as data is sent, and incremented upon receiving window-adjust messages */
739 void recv_msg_channel_window_adjust() { 731 void recv_msg_channel_window_adjust() {
740 732
741 unsigned int chan;
742 struct Channel * channel; 733 struct Channel * channel;
743 unsigned int incr; 734 unsigned int incr;
744 735
745 chan = buf_getint(ses.payload); 736 channel = getchannel();
746 channel = getchannel(chan);
747
748 if (channel == NULL) { 737 if (channel == NULL) {
749 dropbear_exit("Unknown channel"); 738 dropbear_exit("Unknown channel");
750 } 739 }
751 740
752 incr = buf_getint(ses.payload); 741 incr = buf_getint(ses.payload);
959 948
960 /* Confirmation that our channel open request (for forwardings) was 949 /* Confirmation that our channel open request (for forwardings) was
961 * successful*/ 950 * successful*/
962 void recv_msg_channel_open_confirmation() { 951 void recv_msg_channel_open_confirmation() {
963 952
964 unsigned int chan;
965 struct Channel * channel; 953 struct Channel * channel;
966 int ret; 954 int ret;
967 955
968 TRACE(("enter recv_msg_channel_open_confirmation")) 956 TRACE(("enter recv_msg_channel_open_confirmation"))
969 chan = buf_getint(ses.payload); 957
970 958 channel = getchannel();
971 channel = getchannel(chan);
972 if (channel == NULL) { 959 if (channel == NULL) {
973 dropbear_exit("Unknown channel"); 960 dropbear_exit("Unknown channel");
974 } 961 }
975 962
976 channel->remotechan = buf_getint(ses.payload); 963 channel->remotechan = buf_getint(ses.payload);
993 } 980 }
994 981
995 /* Notification that our channel open request failed */ 982 /* Notification that our channel open request failed */
996 void recv_msg_channel_open_failure() { 983 void recv_msg_channel_open_failure() {
997 984
998 unsigned int chan;
999 struct Channel * channel; 985 struct Channel * channel;
1000 chan = buf_getbyte(ses.payload); 986
1001 987 channel = getchannel();
1002 channel = getchannel(chan);
1003 if (channel == NULL) { 988 if (channel == NULL) {
1004 dropbear_exit("Unknown channel"); 989 dropbear_exit("Unknown channel");
1005 } 990 }
1006 991
1007 removechannel(channel); 992 removechannel(channel);