summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--channels.c29
-rw-r--r--channels.h3
-rw-r--r--nchan.c52
-rw-r--r--session.c9
4 files changed, 64 insertions, 29 deletions
diff --git a/channels.c b/channels.c
index e90f7fea9..bd68177b7 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.385 2018/10/04 00:10:11 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,25 @@ 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 */
803const char *
804channel_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
802/* 821/*
803 * Returns a message describing the currently open forwarded connections, 822 * Returns a message describing the currently open forwarded connections,
804 * suitable for sending to the client. The message contains crlf pairs for 823 * suitable for sending to the client. The message contains crlf pairs for
@@ -845,13 +864,16 @@ channel_open_message(struct ssh *ssh)
845 case SSH_CHANNEL_MUX_PROXY: 864 case SSH_CHANNEL_MUX_PROXY:
846 case SSH_CHANNEL_MUX_CLIENT: 865 case SSH_CHANNEL_MUX_CLIENT:
847 if ((r = sshbuf_putf(buf, " #%d %.300s " 866 if ((r = sshbuf_putf(buf, " #%d %.300s "
848 "(t%d %s%u i%u/%zu o%u/%zu fd %d/%d cc %d)\r\n", 867 "(t%d %s%u i%u/%zu o%u/%zu "
868 "fd %d/%d/%d [%s] sock %d cc %d)\r\n",
849 c->self, c->remote_name, 869 c->self, c->remote_name,
850 c->type, 870 c->type,
851 c->have_remote_id ? "r" : "nr", c->remote_id, 871 c->have_remote_id ? "r" : "nr", c->remote_id,
852 c->istate, sshbuf_len(c->input), 872 c->istate, sshbuf_len(c->input),
853 c->ostate, sshbuf_len(c->output), 873 c->ostate, sshbuf_len(c->output),
854 c->rfd, c->wfd, c->ctl_chan)) != 0) 874 c->rfd, c->wfd, c->efd,
875 channel_format_extended_usage(c),
876 c->sock, c->ctl_chan)) != 0)
855 fatal("%s: sshbuf_putf: %s", 877 fatal("%s: sshbuf_putf: %s",
856 __func__, ssh_err(r)); 878 __func__, ssh_err(r));
857 continue; 879 continue;
@@ -2352,6 +2374,7 @@ channel_garbage_collect(struct ssh *ssh, Channel *c)
2352 if (c->detach_user != NULL) { 2374 if (c->detach_user != NULL) {
2353 if (!chan_is_dead(ssh, c, c->detach_close)) 2375 if (!chan_is_dead(ssh, c, c->detach_close))
2354 return; 2376 return;
2377
2355 debug2("channel %d: gc: notify user", c->self); 2378 debug2("channel %d: gc: notify user", c->self);
2356 c->detach_user(ssh, c->self, NULL); 2379 c->detach_user(ssh, c->self, NULL);
2357 /* if we still have a callback */ 2380 /* if we still have a callback */
diff --git a/channels.h b/channels.h
index 1aeafe94e..aa2a87c10 100644
--- a/channels.h
+++ b/channels.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.h,v 1.131 2018/06/06 18:22:41 djm Exp $ */ 1/* $OpenBSD: channels.h,v 1.132 2018/10/04 00:10:11 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -285,6 +285,7 @@ void channel_output_poll(struct ssh *);
285int channel_not_very_much_buffered_data(struct ssh *); 285int channel_not_very_much_buffered_data(struct ssh *);
286void channel_close_all(struct ssh *); 286void channel_close_all(struct ssh *);
287int channel_still_open(struct ssh *); 287int channel_still_open(struct ssh *);
288const char *channel_format_extended_usage(const Channel *);
288char *channel_open_message(struct ssh *); 289char *channel_open_message(struct ssh *);
289int channel_find_open(struct ssh *); 290int channel_find_open(struct ssh *);
290 291
diff --git a/nchan.c b/nchan.c
index 24929556d..da7a9d6d6 100644
--- a/nchan.c
+++ b/nchan.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: nchan.c,v 1.67 2017/09/12 06:35:32 djm Exp $ */ 1/* $OpenBSD: nchan.c,v 1.68 2018/10/04 00:10:11 djm Exp $ */
2/* 2/*
3 * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved. 3 * Copyright (c) 1999, 2000, 2001, 2002 Markus Friedl. All rights reserved.
4 * 4 *
@@ -373,17 +373,23 @@ chan_shutdown_write(struct ssh *ssh, Channel *c)
373 if (c->type == SSH_CHANNEL_LARVAL) 373 if (c->type == SSH_CHANNEL_LARVAL)
374 return; 374 return;
375 /* shutdown failure is allowed if write failed already */ 375 /* shutdown failure is allowed if write failed already */
376 debug2("channel %d: close_write", c->self); 376 debug2("channel %d: %s (i%d o%d sock %d wfd %d efd %d [%s])",
377 c->self, __func__, c->istate, c->ostate, c->sock, c->wfd, c->efd,
378 channel_format_extended_usage(c));
377 if (c->sock != -1) { 379 if (c->sock != -1) {
378 if (shutdown(c->sock, SHUT_WR) < 0) 380 if (shutdown(c->sock, SHUT_WR) < 0) {
379 debug2("channel %d: chan_shutdown_write: " 381 debug2("channel %d: %s: shutdown() failed for "
380 "shutdown() failed for fd %d: %.100s", 382 "fd %d [i%d o%d]: %.100s", c->self, __func__,
381 c->self, c->sock, strerror(errno)); 383 c->sock, c->istate, c->ostate,
384 strerror(errno));
385 }
382 } else { 386 } else {
383 if (channel_close_fd(ssh, &c->wfd) < 0) 387 if (channel_close_fd(ssh, &c->wfd) < 0) {
384 logit("channel %d: chan_shutdown_write: " 388 logit("channel %d: %s: close() failed for "
385 "close() failed for fd %d: %.100s", 389 "fd %d [i%d o%d]: %.100s",
386 c->self, c->wfd, strerror(errno)); 390 c->self, __func__, c->wfd, c->istate, c->ostate,
391 strerror(errno));
392 }
387 } 393 }
388} 394}
389 395
@@ -392,23 +398,27 @@ chan_shutdown_read(struct ssh *ssh, Channel *c)
392{ 398{
393 if (c->type == SSH_CHANNEL_LARVAL) 399 if (c->type == SSH_CHANNEL_LARVAL)
394 return; 400 return;
395 debug2("channel %d: close_read", c->self); 401 debug2("channel %d: %s (i%d o%d sock %d wfd %d efd %d [%s])",
402 c->self, __func__, c->istate, c->ostate, c->sock, c->rfd, c->efd,
403 channel_format_extended_usage(c));
396 if (c->sock != -1) { 404 if (c->sock != -1) {
397 /* 405 /*
398 * shutdown(sock, SHUT_READ) may return ENOTCONN if the 406 * shutdown(sock, SHUT_READ) may return ENOTCONN if the
399 * write side has been closed already. (bug on Linux) 407 * write side has been closed already. (bug on Linux)
400 * HP-UX may return ENOTCONN also. 408 * HP-UX may return ENOTCONN also.
401 */ 409 */
402 if (shutdown(c->sock, SHUT_RD) < 0 410 if (shutdown(c->sock, SHUT_RD) < 0 && errno != ENOTCONN) {
403 && errno != ENOTCONN) 411 error("channel %d: %s: shutdown() failed for "
404 error("channel %d: chan_shutdown_read: " 412 "fd %d [i%d o%d]: %.100s",
405 "shutdown() failed for fd %d [i%d o%d]: %.100s", 413 c->self, __func__, c->sock, c->istate, c->ostate,
406 c->self, c->sock, c->istate, c->ostate, 414 strerror(errno));
407 strerror(errno)); 415 }
408 } else { 416 } else {
409 if (channel_close_fd(ssh, &c->rfd) < 0) 417 if (channel_close_fd(ssh, &c->rfd) < 0) {
410 logit("channel %d: chan_shutdown_read: " 418 logit("channel %d: %s: close() failed for "
411 "close() failed for fd %d: %.100s", 419 "fd %d [i%d o%d]: %.100s",
412 c->self, c->rfd, strerror(errno)); 420 c->self, __func__, c->rfd, c->istate, c->ostate,
421 strerror(errno));
422 }
413 } 423 }
414} 424}
diff --git a/session.c b/session.c
index c5ca0556e..2d0958d11 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.306 2018/10/02 12:40:07 djm Exp $ */ 1/* $OpenBSD: session.c,v 1.307 2018/10/04 00:10:11 djm Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -2262,13 +2262,13 @@ void
2262session_pty_cleanup2(Session *s) 2262session_pty_cleanup2(Session *s)
2263{ 2263{
2264 if (s == NULL) { 2264 if (s == NULL) {
2265 error("session_pty_cleanup: no session"); 2265 error("%s: no session", __func__);
2266 return; 2266 return;
2267 } 2267 }
2268 if (s->ttyfd == -1) 2268 if (s->ttyfd == -1)
2269 return; 2269 return;
2270 2270
2271 debug("session_pty_cleanup: session %d release %s", s->self, s->tty); 2271 debug("%s: session %d release %s", __func__, s->self, s->tty);
2272 2272
2273 /* Record that the user has logged out. */ 2273 /* Record that the user has logged out. */
2274 if (s->pid != 0) 2274 if (s->pid != 0)
@@ -2479,7 +2479,8 @@ session_close_by_channel(struct ssh *ssh, int id, void *arg)
2479 } 2479 }
2480 debug("%s: channel %d child %ld", __func__, id, (long)s->pid); 2480 debug("%s: channel %d child %ld", __func__, id, (long)s->pid);
2481 if (s->pid != 0) { 2481 if (s->pid != 0) {
2482 debug("%s: channel %d: has child", __func__, id); 2482 debug("%s: channel %d: has child, ttyfd %d",
2483 __func__, id, s->ttyfd);
2483 /* 2484 /*
2484 * delay detach of session, but release pty, since 2485 * delay detach of session, but release pty, since
2485 * the fd's to the child are already closed 2486 * the fd's to the child are already closed