diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-02-22 12:25:47 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-02-22 12:25:47 +0000 |
commit | 539ffc91296dd3f38a94b70821dc61c4c413dfa1 (patch) | |
tree | dd6d10c8d38362531d384f701e86a2d89926c592 | |
parent | df2c56529c9784e47b4024369577ef2f3d2b73c3 (diff) | |
download | busybox-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!
-rw-r--r-- | include/usage.h | 15 | ||||
-rw-r--r-- | networking/Config.in | 10 | ||||
-rw-r--r-- | networking/telnet.c | 85 |
3 files changed, 110 insertions, 0 deletions
diff --git a/include/usage.h b/include/usage.h index 59e81c2d3..56650d565 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2415,11 +2415,26 @@ | |||
2415 | "$ cat /tmp/foo\n" \ | 2415 | "$ cat /tmp/foo\n" \ |
2416 | "Hello\n" | 2416 | "Hello\n" |
2417 | 2417 | ||
2418 | #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN | ||
2419 | #define telnet_trivial_usage \ | ||
2420 | "[-a] [-l USER] HOST [PORT]" | ||
2421 | #define telnet_full_usage \ | ||
2422 | "Telnet is used to establish interactive communication with another\n" \ | ||
2423 | "computer over a network using the TELNET protocol.\n\n" \ | ||
2424 | "Options:\n" \ | ||
2425 | "\t-a\t\tAttempt an automatic login with the USER variable.\n" \ | ||
2426 | "\t-l USER\t\tAttempt an automatic login with the USER argument.\n" \ | ||
2427 | "\tHOST\t\tThe official name, alias or the IP address of the\n" \ | ||
2428 | "\t\t\tremote host.\n" \ | ||
2429 | "\tPORT\t\tThe remote port number to connect to. If it is not\n" \ | ||
2430 | "\t\t\tspecified, the default telnet (23) port is used.\n" | ||
2431 | #else | ||
2418 | #define telnet_trivial_usage \ | 2432 | #define telnet_trivial_usage \ |
2419 | "HOST [PORT]" | 2433 | "HOST [PORT]" |
2420 | #define telnet_full_usage \ | 2434 | #define telnet_full_usage \ |
2421 | "Telnet is used to establish interactive communication with another\n"\ | 2435 | "Telnet is used to establish interactive communication with another\n"\ |
2422 | "computer over a network using the TELNET protocol." | 2436 | "computer over a network using the TELNET protocol." |
2437 | #endif | ||
2423 | 2438 | ||
2424 | #ifdef CONFIG_FEATURE_TELNETD_INETD | 2439 | #ifdef CONFIG_FEATURE_TELNETD_INETD |
2425 | #define telnetd_trivial_usage \ | 2440 | #define telnetd_trivial_usage \ |
diff --git a/networking/Config.in b/networking/Config.in index f250e78cc..d2916e7cd 100644 --- a/networking/Config.in +++ b/networking/Config.in | |||
@@ -479,6 +479,16 @@ config CONFIG_FEATURE_TELNET_TTYPE | |||
479 | remote host you are connecting to. This is useful to make sure that | 479 | remote host you are connecting to. This is useful to make sure that |
480 | things like ANSI colors and other control sequences behave. | 480 | things like ANSI colors and other control sequences behave. |
481 | 481 | ||
482 | config CONFIG_FEATURE_TELNET_AUTOLOGIN | ||
483 | bool " Pass USER type to remote host" | ||
484 | default y | ||
485 | depends on CONFIG_TELNET | ||
486 | help | ||
487 | Setting this option will forward the USER environment variable to the | ||
488 | remote host you are connecting to. This is useful when you need to | ||
489 | log into a machine without telling the username (autologin). This | ||
490 | option enables `-a' and `-l USER' arguments. | ||
491 | |||
482 | config CONFIG_TELNETD | 492 | config CONFIG_TELNETD |
483 | bool "telnetd" | 493 | bool "telnetd" |
484 | default n | 494 | default n |
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; | |||
129 | static char *ttype; | 131 | static char *ttype; |
130 | #endif | 132 | #endif |
131 | 133 | ||
134 | #ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN | ||
135 | static char *autologin; | ||
136 | #endif | ||
137 | |||
132 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 138 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
133 | static int win_width, win_height; | 139 | static 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 | ||
365 | static 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 |
359 | static void putiac_naws(byte c, int x, int y) | 393 | static 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 | ||
533 | static 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 |
499 | static inline void to_naws(void) | 547 | static 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 | ||