telnetd: naive and broken approach to automatically set TERM

Andreas Oberritter obi at opendreambox.org
Fri Mar 23 15:01:23 UTC 2012


I tried this, based on the patch before, but failed. When I
log into telnet, TERM is always set to linux. Can you please
give me some advice on how to set an environment variable for
the login shell?

Regards,
Andreas
---
 networking/telnetd.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/networking/telnetd.c b/networking/telnetd.c
index d42cffb..e98f0c4 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -180,6 +180,13 @@ remove_iacs(struct tsession *ts, int *pnum_totty)
 				ws.ws_col = (ptr[3] << 8) | ptr[4];
 				ws.ws_row = (ptr[5] << 8) | ptr[6];
 				ioctl(ts->ptyfd, TIOCSWINSZ, (char *)&ws);
+			} else if (ptr[2] == TELOPT_TTYPE) {
+				char term[plen];
+				if (plen < 1 || ptr[3] != TELQUAL_IS)
+					break;
+				memcpy(term, &ptr[4], plen - 1);
+				term[plen - 1] = '\0';
+				xsetenv("TERM", term);
 			} else {
 #if DEBUG
 				fprintf(stderr, "Ignoring IAC SB %s,%s\r\n",
@@ -317,7 +324,9 @@ make_new_session(
 			/* This requires telnetd.ctrlSQ.patch (incomplete) */
 			/*IAC, DO, TELOPT_LFLOW,*/
 			IAC, WILL, TELOPT_ECHO,
-			IAC, WILL, TELOPT_SGA
+			IAC, WILL, TELOPT_SGA,
+			IAC, DO, TELOPT_TTYPE,
+			IAC, SB, TELOPT_TTYPE, TELQUAL_SEND, IAC, SE,
 		};
 		/* This confuses iac_safe_write(), it will try to duplicate
 		 * each IAC... */
-- 
1.7.7



More information about the busybox mailing list