[PATCH] Allow the TERM env variable to be overwritten by .ssh/config

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 



I run urxvt, but I have some hosts that have an older terminal info
database that don't support the "rxvt-unicode-256color" string that my
terminal exports.  Many applications just fail to open when faced with
an unknown TERM string, which is a huge pain.

This patch allows me to specify what TERM should be for each host in
my .ssh/config.  This allows me to override TERM differently on each
host depending on their level of support for my TERM variable (either
rxvt-unicode, rxvt, or xterm).

There are a number of posts referencing this lack of feature on the
Internet along with some workarounds, but I think this is cleaner.
---
 readconf.c |  8 +++++++-
 readconf.h |  2 ++
 ssh.c      | 11 +++++++++--
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/readconf.c b/readconf.c
index dc884c9..db85a25 100644
--- a/readconf.c
+++ b/readconf.c
@@ -129,7 +129,7 @@ typedef enum {
 	oPasswordAuthentication, oRSAAuthentication,
 	oChallengeResponseAuthentication, oXAuthLocation,
 	oIdentityFile, oHostName, oPort, oCipher, oRemoteForward, oLocalForward,
-	oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand,
+	oUser, oEscapeChar, oRhostsRSAAuthentication, oProxyCommand, oTerm,
 	oGlobalKnownHostsFile, oUserKnownHostsFile, oConnectionAttempts,
 	oBatchMode, oCheckHostIP, oStrictHostKeyChecking, oCompression,
 	oCompressionLevel, oTCPKeepAlive, oNumberOfPasswordPrompts,
@@ -196,6 +196,7 @@ static struct {
 	{ "hostname", oHostName },
 	{ "hostkeyalias", oHostKeyAlias },
 	{ "proxycommand", oProxyCommand },
+	{ "term", oTerm },
 	{ "port", oPort },
 	{ "cipher", oCipher },
 	{ "ciphers", oCiphers },
@@ -994,6 +995,10 @@ parse_command:
 			*charptr = xstrdup(s + len);
 		return 0;
 
+	case oTerm:
+		charptr = &options->term;
+		goto parse_string;
+
 	case oPort:
 		intptr = &options->port;
 parse_int:
@@ -1568,6 +1573,7 @@ initialize_options(Options * options)
 	options->canonicalize_max_dots = -1;
 	options->canonicalize_fallback_local = -1;
 	options->canonicalize_hostname = -1;
+	options->term = NULL;
 }
 
 /*
diff --git a/readconf.h b/readconf.h
index 75e3f8f..883bfed 100644
--- a/readconf.h
+++ b/readconf.h
@@ -104,6 +104,8 @@ typedef struct {
 	int    identity_file_userprovided[SSH_MAX_IDENTITY_FILES];
 	Key    *identity_keys[SSH_MAX_IDENTITY_FILES];
 
+	char   *term;	/* TERM to send to the server, or NULL if getenv("TERM") is used */
+
 	/* Local TCP/IP forward requests. */
 	int     num_local_forwards;
 	Forward *local_forwards;
diff --git a/ssh.c b/ssh.c
index 1e6cb90..c19ed46 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1439,7 +1439,10 @@ ssh_session(void)
 
 		/* Store TERM in the packet.  There is no limit on the
 		   length of the string. */
-		cp = getenv("TERM");
+		cp = options.term;
+		fprintf(stderr, "stored term: '%s'\n", cp);
+		if (!cp)
+			cp = getenv("TERM");
 		if (!cp)
 			cp = "";
 		packet_put_cstring(cp);
@@ -1568,6 +1571,7 @@ ssh_session2_setup(int id, int success, void *arg)
 {
 	extern char **environ;
 	const char *display;
+	char *term;
 	int interactive = tty_flag;
 
 	if (!success)
@@ -1601,7 +1605,10 @@ ssh_session2_setup(int id, int success, void *arg)
 	packet_set_interactive(interactive,
 	    options.ip_qos_interactive, options.ip_qos_bulk);
 
-	client_session2_setup(id, tty_flag, subsystem_flag, getenv("TERM"),
+	term = options.term;
+	if (!term)
+		term = getenv("TERM");
+	client_session2_setup(id, tty_flag, subsystem_flag, term,
 	    NULL, fileno(stdin), &command, environ);
 }
 
-- 
1.8.5.5

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev




[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux