aboutsummaryrefslogtreecommitdiff
path: root/networking/telnet.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-02-22 12:25:47 +0000
committerEric Andersen <andersen@codepoet.org>2004-02-22 12:25:47 +0000
commit539ffc91296dd3f38a94b70821dc61c4c413dfa1 (patch)
treedd6d10c8d38362531d384f701e86a2d89926c592 /networking/telnet.c
parentdf2c56529c9784e47b4024369577ef2f3d2b73c3 (diff)
downloadbusybox-w32-539ffc91296dd3f38a94b70821dc61c4c413dfa1.tar.gz
busybox-w32-539ffc91296dd3f38a94b70821dc61c4c413dfa1.tar.bz2
busybox-w32-539ffc91296dd3f38a94b70821dc61c4c413dfa1.zip
Fernando Silveira writes:
Hi, Well, I made this patch a long time ago (08/2002) because it was a need of a project, but had no time to send it to you. It adds support to `autologin' option of the telnet protocol. It has been used since made with busybox 0.60.3 at production and I had no problems with it. I have ported it to the HEAD revision of the CVS server (20040211) and I hope you enjoy and apply it to the official sources. :) Thanks a lot!
Diffstat (limited to 'networking/telnet.c')
-rw-r--r--networking/telnet.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/networking/telnet.c b/networking/telnet.c
index 1b71bf26a..574fe8dab 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -28,6 +28,8 @@
28 * Modified 2000/06/13 for inclusion into BusyBox by Erik Andersen <andersen@codepoet.org> 28 * Modified 2000/06/13 for inclusion into BusyBox by Erik Andersen <andersen@codepoet.org>
29 * Modified 2001/05/07 to add ability to pass TTYPE to remote host by Jim McQuillan 29 * Modified 2001/05/07 to add ability to pass TTYPE to remote host by Jim McQuillan
30 * <jam@ltsp.org> 30 * <jam@ltsp.org>
31 * Modified 2004/02/11 to add ability to pass the USER variable to remote host
32 * by Fernando Silveira <swrh@gmx.net>
31 * 33 *
32 */ 34 */
33 35
@@ -129,6 +131,10 @@ static int one = 1;
129static char *ttype; 131static char *ttype;
130#endif 132#endif
131 133
134#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
135static char *autologin;
136#endif
137
132#ifdef CONFIG_FEATURE_AUTOWIDTH 138#ifdef CONFIG_FEATURE_AUTOWIDTH
133static int win_width, win_height; 139static int win_width, win_height;
134#endif 140#endif
@@ -355,6 +361,34 @@ static void putiac_subopt(byte c, char *str)
355} 361}
356#endif 362#endif
357 363
364#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
365static void putiac_subopt_autologin(void)
366{
367 int len = strlen(autologin) + 6; // (2 + 1 + 1 + strlen + 2)
368 char *user = "USER";
369
370 if (G.iaclen + len > IACBUFSIZE)
371 iacflush();
372
373 putiac(IAC);
374 putiac(SB);
375 putiac(TELOPT_NEW_ENVIRON);
376 putiac(TELQUAL_IS);
377 putiac(NEW_ENV_VAR);
378
379 while(*user)
380 putiac(*user++);
381
382 putiac(NEW_ENV_VALUE);
383
384 while(*autologin)
385 putiac(*autologin++);
386
387 putiac(IAC);
388 putiac(SE);
389}
390#endif
391
358#ifdef CONFIG_FEATURE_AUTOWIDTH 392#ifdef CONFIG_FEATURE_AUTOWIDTH
359static void putiac_naws(byte c, int x, int y) 393static void putiac_naws(byte c, int x, int y)
360{ 394{
@@ -495,6 +529,20 @@ static inline void to_ttype(void)
495} 529}
496#endif 530#endif
497 531
532#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
533static inline void to_new_environ(void)
534{
535 /* Tell server we will (or will not) do AUTOLOGIN */
536
537 if (autologin)
538 putiac2(WILL, TELOPT_NEW_ENVIRON);
539 else
540 putiac2(WONT, TELOPT_NEW_ENVIRON);
541
542 return;
543}
544#endif
545
498#ifdef CONFIG_FEATURE_AUTOWIDTH 546#ifdef CONFIG_FEATURE_AUTOWIDTH
499static inline void to_naws(void) 547static inline void to_naws(void)
500{ 548{
@@ -513,6 +561,9 @@ static void telopt(byte c)
513#ifdef CONFIG_FEATURE_TELNET_TTYPE 561#ifdef CONFIG_FEATURE_TELNET_TTYPE
514 case TELOPT_TTYPE: to_ttype();break; 562 case TELOPT_TTYPE: to_ttype();break;
515#endif 563#endif
564#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
565 case TELOPT_NEW_ENVIRON: to_new_environ(); break;
566#endif
516#ifdef CONFIG_FEATURE_AUTOWIDTH 567#ifdef CONFIG_FEATURE_AUTOWIDTH
517 case TELOPT_NAWS: to_naws(); 568 case TELOPT_NAWS: to_naws();
518 putiac_naws(c, win_width, win_height); 569 putiac_naws(c, win_width, win_height);
@@ -540,6 +591,11 @@ static int subneg(byte c)
540 if (c == TELOPT_TTYPE) 591 if (c == TELOPT_TTYPE)
541 putiac_subopt(TELOPT_TTYPE,ttype); 592 putiac_subopt(TELOPT_TTYPE,ttype);
542#endif 593#endif
594#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
595 else
596 if (c == TELOPT_NEW_ENVIRON)
597 putiac_subopt_autologin();
598#endif
543 break; 599 break;
544 case TS_SUB2: 600 case TS_SUB2:
545 if (c == SE) 601 if (c == SE)
@@ -579,6 +635,10 @@ extern int telnet_main(int argc, char** argv)
579 int maxfd; 635 int maxfd;
580#endif 636#endif
581 637
638#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
639 int opt;
640#endif
641
582#ifdef CONFIG_FEATURE_AUTOWIDTH 642#ifdef CONFIG_FEATURE_AUTOWIDTH
583 get_terminal_width_height(0, &win_width, &win_height); 643 get_terminal_width_height(0, &win_width, &win_height);
584#endif 644#endif
@@ -598,8 +658,33 @@ extern int telnet_main(int argc, char** argv)
598 if (argc < 2) 658 if (argc < 2)
599 bb_show_usage(); 659 bb_show_usage();
600 660
661#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
662 autologin = NULL;
663 while ((opt = getopt(argc, argv, "al:")) != EOF) {
664 switch (opt) {
665 case 'l':
666 autologin = bb_xstrdup(optarg);
667 break;
668 case 'a':
669 autologin = getenv("USER");
670 break;
671 case '?':
672 bb_show_usage();
673 break;
674 }
675 }
676 if (optind < argc) {
677 bb_lookup_host(&s_in, argv[optind++]);
678 s_in.sin_port = bb_lookup_port((optind < argc) ? argv[optind++] :
679 "telnet", "tcp", 23);
680 if (optind < argc)
681 bb_show_usage();
682 } else
683 bb_show_usage();
684#else
601 bb_lookup_host(&s_in, argv[1]); 685 bb_lookup_host(&s_in, argv[1]);
602 s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23); 686 s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23);
687#endif
603 688
604 G.netfd = xconnect(&s_in); 689 G.netfd = xconnect(&s_in);
605 690