summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2023-01-06 02:42:34 +0000
committerDamien Miller <djm@mindrot.org>2023-01-06 16:21:40 +1100
commit0e34348d0bc0b1522f75d6212a53d6d1d1367980 (patch)
treeefe7bc30096318567802833b18f5d0333d30c321
parentceedf09b2977f3a756c759a6e7eb8f8e9db86a18 (diff)
downloadopenssh-git-0e34348d0bc0b1522f75d6212a53d6d1d1367980.tar.gz
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
-rw-r--r--channels.c26
-rw-r--r--channels.h6
-rw-r--r--session.c13
3 files changed, 38 insertions, 7 deletions
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 <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -297,6 +297,24 @@ channel_lookup(struct ssh *ssh, int id)
}
/*
+ * 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),
diff --git a/channels.h b/channels.h
index bcffa6cf..b8daaea3 100644
--- a/channels.h
+++ b/channels.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.h,v 1.145 2023/01/06 02:39:59 djm Exp $ */
+/* $OpenBSD: channels.h,v 1.146 2023/01/06 02:42:34 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -175,7 +175,8 @@ struct Channel {
int extended_usage;
int single_connection;
- char *ctype; /* type */
+ char *ctype; /* const type - NB. not freed on channel_free */
+ char *xctype; /* extended type */
/* callback */
channel_open_fn *open_confirm;
@@ -282,6 +283,7 @@ void channel_free(struct ssh *, Channel *);
void channel_free_all(struct ssh *);
void channel_stop_listening(struct ssh *);
void channel_force_close(struct ssh *, Channel *, int);
+void channel_set_xtype(struct ssh *, int, const char *);
void channel_send_open(struct ssh *, int);
void channel_request_start(struct ssh *, int, char *, int);
diff --git a/session.c b/session.c
index 5b5711cf..f30d7ac5 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.332 2023/01/06 02:41:49 djm Exp $ */
+/* $OpenBSD: session.c,v 1.333 2023/01/06 02:42:34 djm Exp $ */
/*
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
* All rights reserved
@@ -1955,7 +1955,7 @@ session_subsystem_req(struct ssh *ssh, Session *s)
{
struct stat st;
int r, success = 0;
- char *prog, *cmd;
+ char *prog, *cmd, *type;
u_int i;
if ((r = sshpkt_get_cstring(ssh, &s->subsys, NULL)) != 0 ||
@@ -1978,6 +1978,10 @@ session_subsystem_req(struct ssh *ssh, Session *s)
s->is_subsystem = SUBSYSTEM_EXT;
debug("subsystem: exec() %s", cmd);
}
+ xasprintf(&type, "session:subsystem:%s",
+ options.subsystem_name[i]);
+ channel_set_xtype(ssh, s->chanid, type);
+ free(type);
success = do_exec(ssh, s, cmd) == 0;
break;
}
@@ -2033,6 +2037,9 @@ session_shell_req(struct ssh *ssh, Session *s)
if ((r = sshpkt_get_end(ssh)) != 0)
sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
+
+ channel_set_xtype(ssh, s->chanid, "session:shell");
+
return do_exec(ssh, s, NULL) == 0;
}
@@ -2047,6 +2054,8 @@ session_exec_req(struct ssh *ssh, Session *s)
(r = sshpkt_get_end(ssh)) != 0)
sshpkt_fatal(ssh, r, "%s: parse packet", __func__);
+ channel_set_xtype(ssh, s->chanid, "session:command");
+
success = do_exec(ssh, s, command) == 0;
free(command);
return success;