]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: allow ssh_config SetEnv to override $TERM, which is otherwise
authordjm@openbsd.org <djm@openbsd.org>
Fri, 4 Jun 2021 05:02:40 +0000 (05:02 +0000)
committerDamien Miller <djm@mindrot.org>
Fri, 4 Jun 2021 05:04:52 +0000 (15:04 +1000)
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
misc.h
mux.c
ssh.c

diff --git a/misc.c b/misc.c
index 36f26ccb6ec70f6ebdf8e076778e0325c8c4a30b..78fb1e000a1f5b748ced3e8784efa94dc5cc7d44 100644 (file)
--- 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 58914bd7f128716fa495c8c765e89858e84b9ae4..6c765e9182d0b2c5053547fa4947c8bdc5465182 100644 (file)
--- 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@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 9454bfeddef5d734020dcf5caaa35c041e0dfee0..e15207afbef053a45f5b1d2204ffe20618468813 100644 (file)
--- 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@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 6243db76ec0a2e4dbb862be7bc904b9863015d97..d0fe45ffdc7cba22765884033a3e1aa43232eed8 100644 (file)
--- 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@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@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);
 }