From 0e34348d0bc0b1522f75d6212a53d6d1d1367980 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Fri, 6 Jan 2023 02:42:34 +0000 Subject: upstream: Add channel_set_xtype() This sets an "extended" channel type after channel creation (e.g. "session:subsystem:sftp") that will be used for setting channel inactivity timeouts. ok markus dtucker OpenBSD-Commit-ID: 42564aa92345045b4a74300528f960416a15d4ca --- channels.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'channels.c') diff --git a/channels.c b/channels.c index 9332d603..7bc6c7e4 100644 --- a/channels.c +++ b/channels.c @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.c,v 1.424 2023/01/06 02:41:49 djm Exp $ */ +/* $OpenBSD: channels.c,v 1.425 2023/01/06 02:42:34 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -296,6 +296,24 @@ channel_lookup(struct ssh *ssh, int id) return NULL; } +/* + * Sets "extended type" of a channel; used by session layer to add additional + * information about channel types (e.g. shell, login, subsystem) that can then + * be used to select timeouts. + */ +void +channel_set_xtype(struct ssh *ssh, int id, const char *xctype) +{ + Channel *c; + + if ((c = channel_by_id(ssh, id)) == NULL) + fatal_f("missing channel %d", id); + if (c->xctype != NULL) + free(c->xctype); + c->xctype = xstrdup(xctype); + debug2_f("labeled channel %d as %s", id, xctype); +} + /* * Register filedescriptors for a channel, used when allocating a channel or * when the channel consumer/producer is ready, e.g. shell exec'd @@ -656,6 +674,8 @@ channel_free(struct ssh *ssh, Channel *c) c->path = NULL; free(c->listening_addr); c->listening_addr = NULL; + free(c->xctype); + c->xctype = NULL; while ((cc = TAILQ_FIRST(&c->status_confirms)) != NULL) { if (cc->abandon_cb != NULL) cc->abandon_cb(ssh, c, cc->ctx); @@ -871,9 +891,9 @@ channel_format_status(const Channel *c) { char *ret = NULL; - xasprintf(&ret, "t%d %s%u i%u/%zu o%u/%zu e[%s]/%zu " + xasprintf(&ret, "t%d [%s] %s%u i%u/%zu o%u/%zu e[%s]/%zu " "fd %d/%d/%d sock %d cc %d io 0x%02x/0x%02x", - c->type, + c->type, c->xctype != NULL ? c->xctype : c->ctype, c->have_remote_id ? "r" : "nr", c->remote_id, c->istate, sshbuf_len(c->input), c->ostate, sshbuf_len(c->output), -- cgit v1.2.1