aboutsummaryrefslogtreecommitdiff
path: root/loginutils
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-01-21 20:55:56 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-01-21 20:55:56 +0000
commit9e5d6c002ca589fb2e767fc8bafd6ceddaa12d39 (patch)
treecc4bb2d87b27a82c93e46d0abc3f9ab8a3f3a232 /loginutils
parent4c51202b9dfe3df38e0a50bef9b66bd4cae39277 (diff)
downloadbusybox-9e5d6c002ca589fb2e767fc8bafd6ceddaa12d39.tar.gz
run telnet from inetd, present login prompt if login is configured,
patch from Bastian Blank
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);
#include <time.h>
#endif
-#define LOGIN " login: " /* login prompt */
-
/* Some shorthands for control characters. */
#define CTL(x) (x ^ 0100) /* Assumes ASCII dialect */
@@ -752,142 +750,10 @@ static void auto_baud(struct termio *tp)
/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
static void do_prompt(struct options *op, struct termio *tp)
{
-#ifdef ISSUE
- FILE *fd;
- int oflag;
- int c;
- struct utsname uts;
-
- (void) uname(&uts);
-#endif
-
- (void) write(1, "\r\n", 2); /* start a new line */
#ifdef ISSUE /* optional: show /etc/issue */
- if ((op->flags & F_ISSUE) && (fd = fopen(op->issue, "r"))) {
- oflag = tp->c_oflag; /* save current setting */
- tp->c_oflag |= (ONLCR | OPOST); /* map NL in output to CR-NL */
- (void) ioctl(0, TCSETAW, tp);
-
-
- while ((c = getc(fd)) != EOF) {
- if (c == '\\') {
- c = getc(fd);
-
- switch (c) {
- case 's':
- (void) printf("%s", uts.sysname);
- break;
-
- case 'n':
- (void) printf("%s", uts.nodename);
- break;
-
- case 'r':
- (void) printf("%s", uts.release);
- break;
-
- case 'v':
- (void) printf("%s", uts.version);
- break;
-
- case 'm':
- (void) printf("%s", uts.machine);
- break;
-
- case 'o':
- {
- char domainname[256];
-
- getdomainname(domainname, sizeof(domainname));
- domainname[sizeof(domainname) - 1] = '\0';
- printf("%s", domainname);
- }
- break;
-
- case 'd':
- case 't':
- {
- char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu",
- "Fri", "Sat"
- };
- char *month[] = { "Jan", "Feb", "Mar", "Apr", "May",
- "Jun", "Jul", "Aug", "Sep", "Oct",
- "Nov", "Dec"
- };
- time_t now;
- struct tm *tm;
-
- (void) time(&now);
- tm = localtime(&now);
-
- if (c == 'd')
- (void) printf("%s %s %d %d",
- weekday[tm->tm_wday],
- month[tm->tm_mon], tm->tm_mday,
- tm->tm_year <
- 70 ? tm->tm_year +
- 2000 : tm->tm_year + 1900);
- else
- (void) printf("%02d:%02d:%02d", tm->tm_hour,
- tm->tm_min, tm->tm_sec);
-
- break;
- }
-
- case 'l':
- (void) printf("%s", op->tty);
- break;
-
- case 'b':
- {
- int i;
-
- for (i = 0; speedtab[i].speed; i++) {
- if (speedtab[i].code == (tp->c_cflag & CBAUD)) {
- printf("%ld", speedtab[i].speed);
- break;
- }
- }
- break;
- }
- case 'u':
- case 'U':
- {
- int users = 0;
- struct utmp *ut;
-
- setutent();
- while ((ut = getutent()))
- if (ut->ut_type == USER_PROCESS)
- users++;
- endutent();
- printf("%d ", users);
- if (c == 'U')
- printf((users == 1) ? "user" : "users");
- break;
- }
- default:
- (void) putchar(c);
- }
- } else
- (void) putchar(c);
- }
- fflush(stdout);
-
- tp->c_oflag = oflag; /* restore settings */
- (void) ioctl(0, TCSETAW, tp); /* wait till output is gone */
- (void) fclose(fd);
- }
-#endif
-#ifdef __linux__
- {
- char hn[MAXHOSTNAMELEN + 1];
-
- (void) gethostname(hn, MAXHOSTNAMELEN);
- write(1, hn, strlen(hn));
- }
+ print_login_issue(op->issue, op->tty);
#endif
- (void) write(1, LOGIN, sizeof(LOGIN) - 1); /* always show login prompt */
+ print_login_prompt();
}
/* 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 )
int i;
for(i=0; i<EMPTY_USERNAME_COUNT; i++) {
- gethostname ( buf, sizeof( buf ));
- printf ( "\n%s login: ", buf );
- fflush ( stdout );
+ print_login_prompt();
+
+ if ( !fgets ( buf, sizeof( buf ) - 1, stdin ))
+ return 0;
- if ( !fgets ( buf, sizeof( buf ) - 1, stdin ))
- return 0;
-
if ( !strchr ( buf, '\n' ))
- return 0;
-
- for ( sp = buf; isspace ( *sp ); sp++ ) { }
- for ( ep = sp; isgraph ( *ep ); ep++ ) { }
+ return 0;
+
+ for ( sp = buf; isspace ( *sp ); sp++ ) { }
+ for ( ep = sp; isgraph ( *ep ); ep++ ) { }
- *ep = 0;
+ *ep = 0;
safe_strncpy(buf_name, sp, USERNAME_SIZE);
if(buf_name[0])
return 1;