aboutsummaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-01-21 20:55:56 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-01-21 20:55:56 +0000
commit3769f7ce09d3189a2ea7af6c547c185ef65497bb (patch)
treecc4bb2d87b27a82c93e46d0abc3f9ab8a3f3a232 /loginutils
parentff52df891c6367f894a629d818da41e58b3dd483 (diff)
downloadbusybox-w32-3769f7ce09d3189a2ea7af6c547c185ef65497bb.tar.gz
busybox-w32-3769f7ce09d3189a2ea7af6c547c185ef65497bb.tar.bz2
busybox-w32-3769f7ce09d3189a2ea7af6c547c185ef65497bb.zip
run telnet from inetd, present login prompt if login is configured,
patch from Bastian Blank git-svn-id: svn://busybox.net/trunk/busybox@6407 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'loginutils')
-rw-r--r--loginutils/getty.c138
-rw-r--r--loginutils/login.c20
2 files changed, 11 insertions, 147 deletions
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 0f0778caf..1b9c6ac4d 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -73,8 +73,6 @@ extern void updwtmp(const char *filename, const struct utmp *ut);
73#include <time.h> 73#include <time.h>
74#endif 74#endif
75 75
76#define LOGIN " login: " /* login prompt */
77
78/* Some shorthands for control characters. */ 76/* Some shorthands for control characters. */
79 77
80#define CTL(x) (x ^ 0100) /* Assumes ASCII dialect */ 78#define CTL(x) (x ^ 0100) /* Assumes ASCII dialect */
@@ -752,142 +750,10 @@ static void auto_baud(struct termio *tp)
752/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */ 750/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
753static void do_prompt(struct options *op, struct termio *tp) 751static void do_prompt(struct options *op, struct termio *tp)
754{ 752{
755#ifdef ISSUE
756 FILE *fd;
757 int oflag;
758 int c;
759 struct utsname uts;
760
761 (void) uname(&uts);
762#endif
763
764 (void) write(1, "\r\n", 2); /* start a new line */
765#ifdef ISSUE /* optional: show /etc/issue */ 753#ifdef ISSUE /* optional: show /etc/issue */
766 if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) { 754 print_login_issue(op->issue, op->tty);
767 oflag = tp->c_oflag; /* save current setting */
768 tp->c_oflag |= (ONLCR | OPOST); /* map NL in output to CR-NL */
769 (void) ioctl(0, TCSETAW, tp);
770
771
772 while ((c = getc(fd)) != EOF) {
773 if (c == '\\') {
774 c = getc(fd);
775
776 switch (c) {
777 case 's':
778 (void) printf("%s", uts.sysname);
779 break;
780
781 case 'n':
782 (void) printf("%s", uts.nodename);
783 break;
784
785 case 'r':
786 (void) printf("%s", uts.release);
787 break;
788
789 case 'v':
790 (void) printf("%s", uts.version);
791 break;
792
793 case 'm':
794 (void) printf("%s", uts.machine);
795 break;
796
797 case 'o':
798 {
799 char domainname[256];
800
801 getdomainname(domainname, sizeof(domainname));
802 domainname[sizeof(domainname) - 1] = '\0';
803 printf("%s", domainname);
804 }
805 break;
806
807 case 'd':
808 case 't':
809 {
810 char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
811 "Fri", "Sat"
812 };
813 char *month[] = { "Jan", "Feb", "Mar", "Apr", "May",
814 "Jun", "Jul", "Aug", "Sep", "Oct",
815 "Nov", "Dec"
816 };
817 time_t now;
818 struct tm *tm;
819
820 (void) time(&now);
821 tm = localtime(&now);
822
823 if (c == 'd')
824 (void) printf("%s %s %d %d",
825 weekday[tm->tm_wday],
826 month[tm->tm_mon], tm->tm_mday,
827 tm->tm_year <
828 70 ? tm->tm_year +
829 2000 : tm->tm_year + 1900);
830 else
831 (void) printf("%02d:%02d:%02d", tm->tm_hour,
832 tm->tm_min, tm->tm_sec);
833
834 break;
835 }
836
837 case 'l':
838 (void) printf("%s", op->tty);
839 break;
840
841 case 'b':
842 {
843 int i;
844
845 for (i = 0; speedtab[i].speed; i++) {
846 if (speedtab[i].code == (tp->c_cflag & CBAUD)) {
847 printf("%ld", speedtab[i].speed);
848 break;
849 }
850 }
851 break;
852 }
853 case 'u':
854 case 'U':
855 {
856 int users = 0;
857 struct utmp *ut;
858
859 setutent();
860 while ((ut = getutent()))
861 if (ut->ut_type == USER_PROCESS)
862 users++;
863 endutent();
864 printf("%d ", users);
865 if (c == 'U')
866 printf((users == 1) ? "user" : "users");
867 break;
868 }
869 default:
870 (void) putchar(c);
871 }
872 } else
873 (void) putchar(c);
874 }
875 fflush(stdout);
876
877 tp->c_oflag = oflag; /* restore settings */
878 (void) ioctl(0, TCSETAW, tp); /* wait till output is gone */
879 (void) fclose(fd);
880 }
881#endif
882#ifdef __linux__
883 {
884 char hn[MAXHOSTNAMELEN + 1];
885
886 (void) gethostname(hn, MAXHOSTNAMELEN);
887 write(1, hn, strlen(hn));
888 }
889#endif 755#endif
890 (void) write(1, LOGIN, sizeof(LOGIN) - 1); /* always show login prompt */ 756 print_login_prompt();
891} 757}
892 758
893/* next_speed - select next baud rate */ 759/* next_speed - select next baud rate */
diff --git a/loginutils/login.c b/loginutils/login.c
index 4a7f13ae8..c1ea165c8 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -253,20 +253,18 @@ static int login_prompt ( char *buf_name )
253 int i; 253 int i;
254 254
255 for(i=0; i<EMPTY_USERNAME_COUNT; i++) { 255 for(i=0; i<EMPTY_USERNAME_COUNT; i++) {
256 gethostname ( buf, sizeof( buf )); 256 print_login_prompt();
257 printf ( "\n%s login: ", buf ); 257
258 fflush ( stdout ); 258 if ( !fgets ( buf, sizeof( buf ) - 1, stdin ))
259 return 0;
259 260
260 if ( !fgets ( buf, sizeof( buf ) - 1, stdin ))
261 return 0;
262
263 if ( !strchr ( buf, '\n' )) 261 if ( !strchr ( buf, '\n' ))
264 return 0; 262 return 0;
265 263
266 for ( sp = buf; isspace ( *sp ); sp++ ) { } 264 for ( sp = buf; isspace ( *sp ); sp++ ) { }
267 for ( ep = sp; isgraph ( *ep ); ep++ ) { } 265 for ( ep = sp; isgraph ( *ep ); ep++ ) { }
268 266
269 *ep = 0; 267 *ep = 0;
270 safe_strncpy(buf_name, sp, USERNAME_SIZE); 268 safe_strncpy(buf_name, sp, USERNAME_SIZE);
271 if(buf_name[0]) 269 if(buf_name[0])
272 return 1; 270 return 1;