diff options
Diffstat (limited to 'channels.c')
-rw-r--r-- | channels.c | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/channels.c b/channels.c index e90f7fea9..c85d46abd 100644 --- a/channels.c +++ b/channels.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: channels.c,v 1.384 2018/07/27 12:03:17 markus Exp $ */ | 1 | /* $OpenBSD: channels.c,v 1.386 2018/10/04 01:04:52 djm 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 |
@@ -799,6 +799,41 @@ channel_find_open(struct ssh *ssh) | |||
799 | return -1; | 799 | return -1; |
800 | } | 800 | } |
801 | 801 | ||
802 | /* Returns the state of the channel's extended usage flag */ | ||
803 | const char * | ||
804 | channel_format_extended_usage(const Channel *c) | ||
805 | { | ||
806 | if (c->efd == -1) | ||
807 | return "closed"; | ||
808 | |||
809 | switch (c->extended_usage) { | ||
810 | case CHAN_EXTENDED_WRITE: | ||
811 | return "write"; | ||
812 | case CHAN_EXTENDED_READ: | ||
813 | return "read"; | ||
814 | case CHAN_EXTENDED_IGNORE: | ||
815 | return "ignore"; | ||
816 | default: | ||
817 | return "UNKNOWN"; | ||
818 | } | ||
819 | } | ||
820 | |||
821 | static char * | ||
822 | channel_format_status(const Channel *c) | ||
823 | { | ||
824 | char *ret = NULL; | ||
825 | |||
826 | xasprintf(&ret, "t%d %s%u i%u/%zu o%u/%zu e[%s]/%zu " | ||
827 | "fd %d/%d/%d sock %d cc %d", | ||
828 | c->type, | ||
829 | c->have_remote_id ? "r" : "nr", c->remote_id, | ||
830 | c->istate, sshbuf_len(c->input), | ||
831 | c->ostate, sshbuf_len(c->output), | ||
832 | channel_format_extended_usage(c), sshbuf_len(c->extended), | ||
833 | c->rfd, c->wfd, c->efd, c->sock, c->ctl_chan); | ||
834 | return ret; | ||
835 | } | ||
836 | |||
802 | /* | 837 | /* |
803 | * Returns a message describing the currently open forwarded connections, | 838 | * Returns a message describing the currently open forwarded connections, |
804 | * suitable for sending to the client. The message contains crlf pairs for | 839 | * suitable for sending to the client. The message contains crlf pairs for |
@@ -811,7 +846,7 @@ channel_open_message(struct ssh *ssh) | |||
811 | Channel *c; | 846 | Channel *c; |
812 | u_int i; | 847 | u_int i; |
813 | int r; | 848 | int r; |
814 | char *ret; | 849 | char *cp, *ret; |
815 | 850 | ||
816 | if ((buf = sshbuf_new()) == NULL) | 851 | if ((buf = sshbuf_new()) == NULL) |
817 | fatal("%s: sshbuf_new", __func__); | 852 | fatal("%s: sshbuf_new", __func__); |
@@ -844,16 +879,14 @@ channel_open_message(struct ssh *ssh) | |||
844 | case SSH_CHANNEL_X11_OPEN: | 879 | case SSH_CHANNEL_X11_OPEN: |
845 | case SSH_CHANNEL_MUX_PROXY: | 880 | case SSH_CHANNEL_MUX_PROXY: |
846 | case SSH_CHANNEL_MUX_CLIENT: | 881 | case SSH_CHANNEL_MUX_CLIENT: |
847 | if ((r = sshbuf_putf(buf, " #%d %.300s " | 882 | cp = channel_format_status(c); |
848 | "(t%d %s%u i%u/%zu o%u/%zu fd %d/%d cc %d)\r\n", | 883 | if ((r = sshbuf_putf(buf, " #%d %.300s (%s)\r\n", |
849 | c->self, c->remote_name, | 884 | c->self, c->remote_name, cp)) != 0) { |
850 | c->type, | 885 | free(cp); |
851 | c->have_remote_id ? "r" : "nr", c->remote_id, | ||
852 | c->istate, sshbuf_len(c->input), | ||
853 | c->ostate, sshbuf_len(c->output), | ||
854 | c->rfd, c->wfd, c->ctl_chan)) != 0) | ||
855 | fatal("%s: sshbuf_putf: %s", | 886 | fatal("%s: sshbuf_putf: %s", |
856 | __func__, ssh_err(r)); | 887 | __func__, ssh_err(r)); |
888 | } | ||
889 | free(cp); | ||
857 | continue; | 890 | continue; |
858 | default: | 891 | default: |
859 | fatal("%s: bad channel type %d", __func__, c->type); | 892 | fatal("%s: bad channel type %d", __func__, c->type); |
@@ -2352,6 +2385,7 @@ channel_garbage_collect(struct ssh *ssh, Channel *c) | |||
2352 | if (c->detach_user != NULL) { | 2385 | if (c->detach_user != NULL) { |
2353 | if (!chan_is_dead(ssh, c, c->detach_close)) | 2386 | if (!chan_is_dead(ssh, c, c->detach_close)) |
2354 | return; | 2387 | return; |
2388 | |||
2355 | debug2("channel %d: gc: notify user", c->self); | 2389 | debug2("channel %d: gc: notify user", c->self); |
2356 | c->detach_user(ssh, c->self, NULL); | 2390 | c->detach_user(ssh, c->self, NULL); |
2357 | /* if we still have a callback */ | 2391 | /* if we still have a callback */ |