diff -uNr busybox-0.60.3.old/Config.h busybox-0.60.3/Config.h --- busybox-0.60.3.old/Config.h Sat Apr 6 01:22:15 2002 +++ busybox-0.60.3/Config.h Wed Feb 11 13:12:12 2004 @@ -405,6 +405,9 @@ // Support for TELNET to pass TERM type to remote host. Adds 384 bytes. #define BB_FEATURE_TELNET_TTYPE // +// Support for TELNET to pass USER variable to remote host and do an AUTOLOGIN. +#define BB_FEATURE_TELNET_AUTOLOGIN +// // Support for devfs. //#define BB_FEATURE_DEVFS // diff -uNr busybox-0.60.3.old/telnet.c busybox-0.60.3/telnet.c --- busybox-0.60.3.old/telnet.c Sat Apr 27 00:53:55 2002 +++ busybox-0.60.3/telnet.c Wed Feb 11 13:11:29 2004 @@ -28,6 +28,8 @@ * Modified 2000/06/13 for inclusion in BusyBox by Erik Andersen * Modified 2001/05/07 to add ability to pass TTYPE to remote host by Jim McQuillan * + * Modified 2002/08/03 to add ability to pass the USER variable to remote host + * with the -a and -l arguments by Fernando Silveira * */ @@ -144,6 +146,10 @@ static char *ttype; #endif +#ifdef BB_FEATURE_TELNET_AUTOLOGIN +static char *autologin; +#endif + #ifdef BB_FEATURE_AUTOWIDTH static int win_width, win_height; #endif @@ -370,6 +376,34 @@ } #endif +#ifdef BB_FEATURE_TELNET_AUTOLOGIN +static void putiac_subopt_autologin() +{ + int len = strlen(autologin) + 6; // ( 2 + 1 + 1 + strlen + 2 ) + char *user = "USER"; + + if (G.iaclen + len > IACBUFSIZE) + iacflush(); + + putiac(IAC); + putiac(SB); + putiac(TELOPT_NEW_ENVIRON); + putiac(TELQUAL_IS); + putiac(NEW_ENV_VAR); + + while(*user) + putiac(*user++); + + putiac(NEW_ENV_VALUE); + + while(*autologin) + putiac(*autologin++); + + putiac(IAC); + putiac(SE); +} +#endif + #ifdef BB_FEATURE_AUTOWIDTH static void putiac_naws(byte c, int x, int y) { @@ -510,6 +544,20 @@ } #endif +#ifdef BB_FEATURE_TELNET_AUTOLOGIN +static inline void to_new_environ(void) +{ + /* Tell server we will (or won't) do AUTOLOGIN */ + + if (autologin) + putiac2(WILL, TELOPT_NEW_ENVIRON); + else + putiac2(WONT, TELOPT_NEW_ENVIRON); + + return; +} +#endif + #ifdef BB_FEATURE_AUTOWIDTH static inline void to_naws(void) { @@ -528,6 +576,9 @@ #ifdef BB_FEATURE_TELNET_TTYPE case TELOPT_TTYPE: to_ttype(); break; #endif +#ifdef BB_FEATURE_TELNET_AUTOLOGIN + case TELOPT_NEW_ENVIRON: to_new_environ(); break; +#endif #ifdef BB_FEATURE_AUTOWIDTH case TELOPT_NAWS: to_naws(); putiac_naws(c, win_width, win_height); @@ -555,6 +606,11 @@ if (c == TELOPT_TTYPE) putiac_subopt(TELOPT_TTYPE,ttype); #endif +#ifdef BB_FEATURE_TELNET_AUTOLOGIN + else + if (c == TELOPT_NEW_ENVIRON) + putiac_subopt_autologin(); +#endif break; case TS_SUB2: if (c == SE) @@ -594,6 +650,9 @@ fd_set readfds; int maxfd; #endif +#ifdef BB_FEATURE_TELNET_AUTOLOGIN + int opt; +#endif #ifdef BB_FEATURE_AUTOWIDTH struct winsize winp; @@ -616,9 +675,34 @@ cfmakeraw(&G.termios_raw); if (argc < 2) show_usage(); +#ifdef BB_FEATURE_TELNET_AUTOLOGIN + autologin = NULL; + port = 0; + while ((opt = getopt(argc, argv, "al:")) != EOF) { + switch (opt) { + case 'l': + autologin = xstrdup(optarg); + break; + case 'a': + autologin = getenv("USER"); + break; + case '?': + show_usage(); + break; + } + } + if (optind < argc) { + host = getserver(argv[optind++]); + port = (optind < argc)? getport(argv[optind++]): 23; + if (optind < argc) + show_usage(); + } else + show_usage(); +#else port = (argc > 2)? getport(argv[2]): 23; host = getserver(argv[1]); +#endif G.netfd = remote_connect(host, port); diff -uNr busybox-0.60.3.old/usage.h busybox-0.60.3/usage.h --- busybox-0.60.3.old/usage.h Fri Apr 26 22:31:31 2002 +++ busybox-0.60.3/usage.h Wed Feb 11 13:11:08 2004 @@ -1562,10 +1562,17 @@ "Hello\n" #define telnet_trivial_usage \ - "HOST [PORT]" + "[-a] [-l USER] HOST [PORT]" #define telnet_full_usage \ "Telnet is used to establish interactive communication with another\n"\ - "computer over a network using the TELNET protocol." + "computer over a network using the TELNET protocol.\n\n" \ + "Options:\n" \ + "\t-a\t\tAttempt an automatic login with the USER variable.\n" \ + "\t-l USER\t\tAttempt an automatic login with the USER argument.\n" \ + "\tHOST\t\tThe official name, alias or the IP address of the\n" \ + "\t\t\tremote host.\n" \ + "\tPORT\t\tThe remote port number to connect to. If it is not\n" \ + "\t\t\tspecified, the default telnet (23) port is used.\n" #define test_trivial_usage \ "EXPRESSION\n or [ EXPRESSION ]"