[openssh-commits] [openssh] 01/01: upstream: allow ssh_config SetEnv to override $TERM, which is otherwise
git+noreply at mindrot.org
git+noreply at mindrot.org
Fri Jun 4 15:05:09 AEST 2021
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit f64f8c00d158acc1359b8a096835849b23aa2e86
Author: djm at openbsd.org <djm at openbsd.org>
Date: Fri Jun 4 05:02:40 2021 +0000
upstream: allow ssh_config SetEnv to override $TERM, which is otherwise
handled specially by the protocol. Useful in ~/.ssh/config to set TERM to
something generic (e.g. "xterm" instead of "xterm-256color") for destinations
that lack terminfo entries. feedback and ok dtucker@
OpenBSD-Commit-ID: 38b1ef4d5bc159c7d9d589d05e3017433e2d5758
---
misc.c | 17 ++++++++++++++++-
misc.h | 4 +++-
mux.c | 12 +++++++-----
ssh.c | 9 ++++++---
4 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/misc.c b/misc.c
index 36f26ccb..78fb1e00 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.164 2021/04/03 06:18:40 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.165 2021/06/04 05:02:40 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@@ -2671,3 +2671,18 @@ subprocess(const char *tag, const char *command,
*child = f;
return pid;
}
+
+const char *
+lookup_env_in_list(const char *env, char * const *envs, size_t nenvs)
+{
+ size_t i, envlen;
+
+ envlen = strlen(env);
+ for (i = 0; i < nenvs; i++) {
+ if (strncmp(envs[i], env, envlen) == 0 &&
+ envs[i][envlen] == '=') {
+ return envs[i] + envlen + 1;
+ }
+ }
+ return NULL;
+}
diff --git a/misc.h b/misc.h
index 58914bd7..6c765e91 100644
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.95 2021/04/03 06:18:40 djm Exp $ */
+/* $OpenBSD: misc.h,v 1.96 2021/06/04 05:02:40 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
@@ -175,6 +175,8 @@ void mktemp_proto(char *, size_t);
void child_set_env(char ***envp, u_int *envsizep, const char *name,
const char *value);
+const char *lookup_env_in_list(const char *env,
+ char * const *envs, size_t nenvs);
int argv_split(const char *, int *, char ***);
char *argv_assemble(int, char **argv);
diff --git a/mux.c b/mux.c
index 9454bfed..e15207af 100644
--- a/mux.c
+++ b/mux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mux.c,v 1.88 2021/05/19 01:24:05 djm Exp $ */
+/* $OpenBSD: mux.c,v 1.89 2021/06/04 05:02:40 djm Exp $ */
/*
* Copyright (c) 2002-2008 Damien Miller <djm at openbsd.org>
*
@@ -1866,7 +1866,7 @@ mux_client_request_session(int fd)
{
struct sshbuf *m;
char *e;
- const char *term;
+ const char *term = NULL;
u_int echar, rid, sid, esid, exitval, type, exitval_seen;
extern char **environ;
int r, i, rawmode;
@@ -1883,8 +1883,10 @@ mux_client_request_session(int fd)
if (stdin_null_flag && stdfd_devnull(1, 0, 0) == -1)
fatal_f("stdfd_devnull failed");
- if ((term = getenv("TERM")) == NULL)
- term = "";
+ if ((term = lookup_env_in_list("TERM", options.setenv,
+ options.num_setenv)) == NULL || *term == '\0')
+ term = getenv("TERM");
+
echar = 0xffffffff;
if (options.escape_char != SSH_ESCAPECHAR_NONE)
echar = (u_int)options.escape_char;
@@ -1899,7 +1901,7 @@ mux_client_request_session(int fd)
(r = sshbuf_put_u32(m, options.forward_agent)) != 0 ||
(r = sshbuf_put_u32(m, subsystem_flag)) != 0 ||
(r = sshbuf_put_u32(m, echar)) != 0 ||
- (r = sshbuf_put_cstring(m, term)) != 0 ||
+ (r = sshbuf_put_cstring(m, term == NULL ? "" : term)) != 0 ||
(r = sshbuf_put_stringb(m, command)) != 0)
fatal_fr(r, "request");
diff --git a/ssh.c b/ssh.c
index 6243db76..d0fe45ff 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.557 2021/05/19 01:24:05 djm Exp $ */
+/* $OpenBSD: ssh.c,v 1.558 2021/06/04 05:02:40 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -2018,7 +2018,7 @@ static void
ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg)
{
extern char **environ;
- const char *display;
+ const char *display, *term;
int r, interactive = tty_flag;
char *proto = NULL, *data = NULL;
@@ -2053,7 +2053,10 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg)
ssh_packet_set_interactive(ssh, interactive,
options.ip_qos_interactive, options.ip_qos_bulk);
- client_session2_setup(ssh, id, tty_flag, subsystem_flag, getenv("TERM"),
+ if ((term = lookup_env_in_list("TERM", options.setenv,
+ options.num_setenv)) == NULL || *term == '\0')
+ term = getenv("TERM");
+ client_session2_setup(ssh, id, tty_flag, subsystem_flag, term,
NULL, fileno(stdin), command, environ);
}
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list