2002-06-05 02:15:46 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/* agetty.c - another getty program for Linux. By W. Z. Venema 1989
|
2006-07-12 13:26:04 +05:30
|
|
|
* Ported to Linux by Peter Orbaek <poe@daimi.aau.dk>
|
|
|
|
* This program is freely distributable. The entire man-page used to
|
|
|
|
* be here. Now read the real man-page agetty.8 instead.
|
|
|
|
*
|
|
|
|
* option added by Eric Rasmussen <ear@usfirst.org> - 12/28/95
|
|
|
|
*
|
2008-03-17 14:59:43 +05:30
|
|
|
* 1999-02-22 Arkadiusz Mickiewicz <misiek@misiek.eu.org>
|
2006-07-12 13:26:04 +05:30
|
|
|
* - added Native Language Support
|
2008-03-17 14:59:43 +05:30
|
|
|
*
|
2006-07-12 13:26:04 +05:30
|
|
|
* 1999-05-05 Thorsten Kranzkowski <dl8bcu@gmx.net>
|
|
|
|
* - enable hardware flow control before displaying /etc/issue
|
|
|
|
*
|
2010-08-16 23:44:46 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2006-07-12 13:26:04 +05:30
|
|
|
*/
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2006-09-19 19:20:55 +05:30
|
|
|
#include <syslog.h>
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
#if ENABLE_FEATURE_UTMP
|
2010-04-06 01:40:38 +05:30
|
|
|
# include <utmp.h> /* LOGIN_PROCESS */
|
2005-07-01 06:59:44 +05:30
|
|
|
#endif
|
|
|
|
|
2009-07-05 07:04:12 +05:30
|
|
|
#ifndef IUCLC
|
|
|
|
# define IUCLC 0
|
|
|
|
#endif
|
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/*
|
|
|
|
* Some heuristics to find out what environment we are in: if it is not
|
|
|
|
* System V, assume it is SunOS 4.
|
|
|
|
*/
|
2005-09-29 17:01:26 +05:30
|
|
|
#ifdef LOGIN_PROCESS /* defined in System V utmp.h */
|
2006-10-23 07:41:22 +05:30
|
|
|
#include <sys/utsname.h>
|
2007-12-05 00:16:01 +05:30
|
|
|
#else /* if !sysV style, wtmp/utmp code is off */
|
|
|
|
#undef ENABLE_FEATURE_UTMP
|
|
|
|
#undef ENABLE_FEATURE_WTMP
|
|
|
|
#define ENABLE_FEATURE_UTMP 0
|
|
|
|
#define ENABLE_FEATURE_WTMP 0
|
2006-11-07 07:22:10 +05:30
|
|
|
#endif /* LOGIN_PROCESS */
|
2006-10-23 07:41:22 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/*
|
|
|
|
* Things you may want to modify.
|
|
|
|
*
|
|
|
|
* You may disagree with the default line-editing etc. characters defined
|
|
|
|
* below. Note, however, that DEL cannot be used for interrupt generation
|
|
|
|
* and for line editing at the same time.
|
|
|
|
*/
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2006-10-23 15:47:34 +05:30
|
|
|
/* I doubt there are systems which still need this */
|
|
|
|
#undef HANDLE_ALLCAPS
|
2007-12-04 15:18:40 +05:30
|
|
|
#undef ANCIENT_BS_KILL_CHARS
|
2006-10-23 15:47:34 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
#define _PATH_LOGIN "/bin/login"
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/* If ISSUE is not defined, getty will never display the contents of the
|
|
|
|
* /etc/issue file. You will not want to spit out large "issue" files at the
|
|
|
|
* wrong baud rate.
|
|
|
|
*/
|
2005-09-29 17:01:26 +05:30
|
|
|
#define ISSUE "/etc/issue" /* displayed before the login prompt */
|
2005-07-27 11:35:38 +05:30
|
|
|
|
2002-06-05 02:15:46 +05:30
|
|
|
/* Some shorthands for control characters. */
|
2008-03-17 14:25:44 +05:30
|
|
|
#define CTL(x) ((x) ^ 0100) /* Assumes ASCII dialect */
|
2005-09-29 17:01:26 +05:30
|
|
|
#define CR CTL('M') /* carriage return */
|
|
|
|
#define NL CTL('J') /* line feed */
|
|
|
|
#define BS CTL('H') /* back space */
|
|
|
|
#define DEL CTL('?') /* delete */
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Defaults for line-editing etc. characters; you may want to change this. */
|
2005-09-29 17:01:26 +05:30
|
|
|
#define DEF_ERASE DEL /* default erase character */
|
|
|
|
#define DEF_INTR CTL('C') /* default interrupt character */
|
|
|
|
#define DEF_QUIT CTL('\\') /* default quit char */
|
|
|
|
#define DEF_KILL CTL('U') /* default kill char */
|
|
|
|
#define DEF_EOF CTL('D') /* default EOF char */
|
|
|
|
#define DEF_EOL '\n'
|
|
|
|
#define DEF_SWITCH 0 /* default switch char */
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/*
|
|
|
|
* When multiple baud rates are specified on the command line, the first one
|
|
|
|
* we will try is the first one specified.
|
|
|
|
*/
|
2005-09-29 17:01:26 +05:30
|
|
|
#define MAX_SPEED 10 /* max. nr. of baud rates */
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Storage for command-line options. */
|
2002-06-05 02:15:46 +05:30
|
|
|
struct options {
|
2005-09-29 17:01:26 +05:30
|
|
|
int flags; /* toggle switches, see below */
|
2006-10-08 18:19:22 +05:30
|
|
|
unsigned timeout; /* time-out period */
|
2007-12-04 15:18:40 +05:30
|
|
|
const char *login; /* login program */
|
|
|
|
const char *tty; /* name of tty */
|
|
|
|
const char *initstring; /* modem init string */
|
|
|
|
const char *issue; /* alternative issue file */
|
2005-09-29 17:01:26 +05:30
|
|
|
int numspeed; /* number of baud rates to try */
|
|
|
|
int speeds[MAX_SPEED]; /* baud rates to be tried */
|
2002-06-05 02:15:46 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
/* Storage for things detected while the login name was read. */
|
2005-07-01 06:59:44 +05:30
|
|
|
struct chardata {
|
2006-10-23 15:47:34 +05:30
|
|
|
unsigned char erase; /* erase character */
|
|
|
|
unsigned char kill; /* kill character */
|
|
|
|
unsigned char eol; /* end-of-line character */
|
|
|
|
unsigned char parity; /* what parity did we see */
|
2008-03-17 14:25:44 +05:30
|
|
|
/* (parity & 1): saw odd parity char with 7th bit set */
|
|
|
|
/* (parity & 2): saw even parity char with 7th bit set */
|
|
|
|
/* parity == 0: probably 7-bit, space parity? */
|
|
|
|
/* parity == 1: probably 7-bit, odd parity? */
|
|
|
|
/* parity == 2: probably 7-bit, even parity? */
|
|
|
|
/* parity == 3: definitely 8 bit, no parity! */
|
|
|
|
/* Hmm... with any value of "parity" 8 bit, no parity is possible */
|
2006-10-23 15:47:34 +05:30
|
|
|
#ifdef HANDLE_ALLCAPS
|
|
|
|
unsigned char capslock; /* upper case without lower case */
|
|
|
|
#endif
|
2002-06-05 02:15:46 +05:30
|
|
|
};
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
|
2002-06-05 02:15:46 +05:30
|
|
|
/* Initial values for the above. */
|
2006-10-23 07:40:45 +05:30
|
|
|
static const struct chardata init_chardata = {
|
2005-09-29 17:01:26 +05:30
|
|
|
DEF_ERASE, /* default erase character */
|
|
|
|
DEF_KILL, /* default kill character */
|
|
|
|
13, /* default eol char */
|
|
|
|
0, /* space parity */
|
2006-10-23 15:47:34 +05:30
|
|
|
#ifdef HANDLE_ALLCAPS
|
2005-09-29 17:01:26 +05:30
|
|
|
0, /* no capslock */
|
2002-06-05 02:15:46 +05:30
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
static const char opt_string[] ALIGN1 = "I:LH:f:hil:mt:wn";
|
|
|
|
#define F_INITSTRING (1 << 0) /* -I initstring is set */
|
|
|
|
#define F_LOCAL (1 << 1) /* -L force local */
|
2007-12-05 00:16:01 +05:30
|
|
|
#define F_FAKEHOST (1 << 2) /* -H fake hostname */
|
2007-12-04 15:18:40 +05:30
|
|
|
#define F_CUSTISSUE (1 << 3) /* -f give alternative issue file */
|
|
|
|
#define F_RTSCTS (1 << 4) /* -h enable RTS/CTS flow control */
|
|
|
|
#define F_ISSUE (1 << 5) /* -i display /etc/issue */
|
|
|
|
#define F_LOGIN (1 << 6) /* -l non-default login program */
|
|
|
|
#define F_PARSE (1 << 7) /* -m process modem status messages */
|
|
|
|
#define F_TIMEOUT (1 << 8) /* -t time out */
|
|
|
|
#define F_WAITCRLF (1 << 9) /* -w wait for CR or LF */
|
2007-12-05 00:16:01 +05:30
|
|
|
#define F_NOPROMPT (1 << 10) /* -n don't ask for login name */
|
2007-12-04 15:18:40 +05:30
|
|
|
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
#define line_buf bb_common_bufsiz1
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* The following is used for understandable diagnostics. */
|
2002-06-05 02:15:46 +05:30
|
|
|
#ifdef DEBUGGING
|
2006-10-23 15:47:34 +05:30
|
|
|
static FILE *dbf;
|
2008-03-17 14:25:44 +05:30
|
|
|
#define DEBUGTERM "/dev/ttyp0"
|
|
|
|
#define debug(...) do { fprintf(dbf, __VA_ARGS__); fflush(dbf); } while (0)
|
2002-06-05 02:15:46 +05:30
|
|
|
#else
|
2008-03-17 14:25:44 +05:30
|
|
|
#define debug(...) ((void)0)
|
2002-06-05 02:15:46 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-03-17 14:25:44 +05:30
|
|
|
/* bcode - convert speed string to speed code; return <= 0 on failure */
|
2006-06-16 22:07:07 +05:30
|
|
|
static int bcode(const char *s)
|
|
|
|
{
|
2008-03-17 14:25:44 +05:30
|
|
|
int value = bb_strtou(s, NULL, 10); /* yes, int is intended! */
|
|
|
|
if (value < 0) /* bad terminating char, overflow, etc */
|
|
|
|
return value;
|
|
|
|
return tty_value_to_baud(value);
|
2006-06-16 22:07:07 +05:30
|
|
|
}
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2006-06-16 22:07:07 +05:30
|
|
|
/* parse_speeds - parse alternate baud rates */
|
|
|
|
static void parse_speeds(struct options *op, char *arg)
|
|
|
|
{
|
|
|
|
char *cp;
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* NB: at least one iteration is always done */
|
2006-06-16 22:07:07 +05:30
|
|
|
debug("entered parse_speeds\n");
|
2007-12-04 15:18:40 +05:30
|
|
|
while ((cp = strsep(&arg, ",")) != NULL) {
|
2007-11-06 08:35:54 +05:30
|
|
|
op->speeds[op->numspeed] = bcode(cp);
|
2009-04-09 12:38:04 +05:30
|
|
|
if (op->speeds[op->numspeed] < 0)
|
2006-09-07 21:50:03 +05:30
|
|
|
bb_error_msg_and_die("bad speed: %s", cp);
|
2009-04-12 18:35:40 +05:30
|
|
|
/* note: arg "0" turns into speed B0 */
|
2007-11-06 08:35:54 +05:30
|
|
|
op->numspeed++;
|
2006-06-16 22:07:07 +05:30
|
|
|
if (op->numspeed > MAX_SPEED)
|
2006-09-07 21:50:03 +05:30
|
|
|
bb_error_msg_and_die("too many alternate speeds");
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
2007-12-04 15:18:40 +05:30
|
|
|
debug("exiting parse_speeds\n");
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
2006-09-07 21:50:03 +05:30
|
|
|
/* parse_args - parse command-line arguments */
|
2007-12-05 00:16:01 +05:30
|
|
|
static void parse_args(char **argv, struct options *op, char **fakehost_p)
|
2002-06-05 02:15:46 +05:30
|
|
|
{
|
2005-09-29 17:01:26 +05:30
|
|
|
char *ts;
|
|
|
|
|
2008-03-17 14:25:44 +05:30
|
|
|
opt_complementary = "-2:t+"; /* at least 2 args; -t N */
|
2007-08-18 21:02:12 +05:30
|
|
|
op->flags = getopt32(argv, opt_string,
|
2007-12-05 00:16:01 +05:30
|
|
|
&(op->initstring), fakehost_p, &(op->issue),
|
2008-03-17 14:25:44 +05:30
|
|
|
&(op->login), &op->timeout);
|
2007-12-04 15:18:40 +05:30
|
|
|
argv += optind;
|
2006-10-23 07:40:45 +05:30
|
|
|
if (op->flags & F_INITSTRING) {
|
2005-09-29 17:01:26 +05:30
|
|
|
const char *p = op->initstring;
|
|
|
|
char *q;
|
|
|
|
|
2007-12-05 00:16:01 +05:30
|
|
|
op->initstring = q = xstrdup(p);
|
2005-09-29 17:01:26 +05:30
|
|
|
/* copy optarg into op->initstring decoding \ddd
|
|
|
|
octal codes into chars */
|
|
|
|
while (*p) {
|
|
|
|
if (*p == '\\') {
|
|
|
|
p++;
|
|
|
|
*q++ = bb_process_escape_sequence(&p);
|
|
|
|
} else {
|
|
|
|
*q++ = *p++;
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
}
|
2005-09-29 17:01:26 +05:30
|
|
|
*q = '\0';
|
|
|
|
}
|
2008-03-17 14:25:44 +05:30
|
|
|
op->flags ^= F_ISSUE; /* invert flag "show /etc/issue" */
|
2007-12-04 15:18:40 +05:30
|
|
|
debug("after getopt\n");
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* we loosen up a bit and accept both "baudrate tty" and "tty baudrate" */
|
2007-12-04 15:18:40 +05:30
|
|
|
op->tty = argv[0]; /* tty name */
|
|
|
|
ts = argv[1]; /* baud rate(s) */
|
2007-01-20 02:49:35 +05:30
|
|
|
if (isdigit(argv[0][0])) {
|
2002-06-05 02:15:46 +05:30
|
|
|
/* a number first, assume it's a speed (BSD style) */
|
2007-12-04 15:18:40 +05:30
|
|
|
op->tty = ts; /* tty name is in argv[1] */
|
|
|
|
ts = argv[0]; /* baud rate(s) */
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
2007-12-04 15:18:40 +05:30
|
|
|
parse_speeds(op, ts);
|
2010-09-01 15:01:43 +05:30
|
|
|
applet_name = xasprintf("getty: %s", op->tty);
|
2008-03-17 14:25:44 +05:30
|
|
|
|
2006-10-23 07:41:22 +05:30
|
|
|
if (argv[2])
|
2008-03-17 14:25:44 +05:30
|
|
|
xsetenv("TERM", argv[2]);
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
debug("exiting parse_args\n");
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* open_tty - set up tty as standard { input, output, error } */
|
2007-12-04 15:18:40 +05:30
|
|
|
static void open_tty(const char *tty)
|
2002-06-05 02:15:46 +05:30
|
|
|
{
|
|
|
|
/* Set up new standard input, unless we are given an already opened port. */
|
2006-12-17 05:19:13 +05:30
|
|
|
if (NOT_LONE_DASH(tty)) {
|
2008-03-17 14:25:44 +05:30
|
|
|
// struct stat st;
|
|
|
|
// int cur_dir_fd;
|
|
|
|
// int fd;
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Sanity checks... */
|
2008-03-17 14:25:44 +05:30
|
|
|
// cur_dir_fd = xopen(".", O_DIRECTORY | O_NONBLOCK);
|
|
|
|
// xchdir("/dev");
|
|
|
|
// xstat(tty, &st);
|
2009-07-05 08:20:36 +05:30
|
|
|
// if (!S_ISCHR(st.st_mode))
|
2010-09-01 15:01:43 +05:30
|
|
|
// bb_error_msg_and_die("not a character device");
|
2008-03-17 14:25:44 +05:30
|
|
|
|
|
|
|
if (tty[0] != '/')
|
|
|
|
tty = xasprintf("/dev/%s", tty); /* will leak it */
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Open the tty as standard input. */
|
|
|
|
debug("open(2)\n");
|
2008-03-17 14:25:44 +05:30
|
|
|
close(0);
|
|
|
|
/*fd =*/ xopen(tty, O_RDWR | O_NONBLOCK); /* uses fd 0 */
|
2007-12-04 15:18:40 +05:30
|
|
|
|
2008-03-17 14:25:44 +05:30
|
|
|
// /* Restore current directory */
|
|
|
|
// fchdir(cur_dir_fd);
|
2007-12-04 15:18:40 +05:30
|
|
|
|
|
|
|
/* Open the tty as standard input, continued */
|
2008-03-17 14:25:44 +05:30
|
|
|
// xmove_fd(fd, 0);
|
|
|
|
// /* fd is >= cur_dir_fd, and cur_dir_fd gets closed too here: */
|
|
|
|
// while (fd > 2)
|
|
|
|
// close(fd--);
|
|
|
|
|
|
|
|
/* Set proper protections and ownership. */
|
2007-12-04 15:18:40 +05:30
|
|
|
fchown(0, 0, 0); /* 0:0 */
|
2008-03-17 14:25:44 +05:30
|
|
|
fchmod(0, 0620); /* crw--w---- */
|
2002-06-05 02:15:46 +05:30
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Standard input should already be connected to an open port. Make
|
|
|
|
* sure it is open for read/write.
|
|
|
|
*/
|
2007-08-19 19:12:08 +05:30
|
|
|
if ((fcntl(0, F_GETFL) & O_RDWR) != O_RDWR)
|
2007-01-28 03:51:12 +05:30
|
|
|
bb_error_msg_and_die("stdin is not open for read/write");
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/* termios_init - initialize termios settings */
|
|
|
|
static void termios_init(struct termios *tp, int speed, struct options *op)
|
2002-06-05 02:15:46 +05:30
|
|
|
{
|
2009-04-12 18:35:40 +05:30
|
|
|
speed_t ispeed, ospeed;
|
2002-06-05 02:15:46 +05:30
|
|
|
/*
|
2006-11-07 07:22:10 +05:30
|
|
|
* Initial termios settings: 8-bit characters, raw-mode, blocking i/o.
|
2002-06-05 02:15:46 +05:30
|
|
|
* Special characters are set after we have read the login name; all
|
|
|
|
* reads will be done in raw mode anyway. Errors will be dealt with
|
2006-10-23 15:47:34 +05:30
|
|
|
* later on.
|
2002-06-05 02:15:46 +05:30
|
|
|
*/
|
|
|
|
/* flush input and output queues, important for modems! */
|
2010-05-27 19:07:32 +05:30
|
|
|
tcflush(0, TCIOFLUSH);
|
2009-04-12 18:35:40 +05:30
|
|
|
ispeed = ospeed = speed;
|
|
|
|
if (speed == B0) {
|
|
|
|
/* Speed was specified as "0" on command line.
|
|
|
|
* Just leave it unchanged */
|
|
|
|
ispeed = cfgetispeed(tp);
|
|
|
|
ospeed = cfgetospeed(tp);
|
|
|
|
}
|
|
|
|
tp->c_cflag = CS8 | HUPCL | CREAD;
|
2008-03-17 14:25:44 +05:30
|
|
|
if (op->flags & F_LOCAL)
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_cflag |= CLOCAL;
|
2009-04-12 18:35:40 +05:30
|
|
|
cfsetispeed(tp, ispeed);
|
|
|
|
cfsetospeed(tp, ospeed);
|
2002-06-05 02:15:46 +05:30
|
|
|
|
2010-05-27 19:07:32 +05:30
|
|
|
tp->c_iflag = tp->c_lflag = 0;
|
2006-08-25 01:30:44 +05:30
|
|
|
tp->c_oflag = OPOST | ONLCR;
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_cc[VMIN] = 1;
|
|
|
|
tp->c_cc[VTIME] = 0;
|
2010-05-27 19:07:32 +05:30
|
|
|
#ifdef __linux__
|
|
|
|
tp->c_line = 0;
|
|
|
|
#endif
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Optionally enable hardware flow control */
|
2007-12-04 15:18:40 +05:30
|
|
|
#ifdef CRTSCTS
|
2002-06-05 02:15:46 +05:30
|
|
|
if (op->flags & F_RTSCTS)
|
|
|
|
tp->c_cflag |= CRTSCTS;
|
|
|
|
#endif
|
|
|
|
|
2008-11-05 18:50:58 +05:30
|
|
|
tcsetattr_stdin_TCSANOW(tp);
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
debug("term_io 2\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* auto_baud - extract baud rate from modem status message */
|
2006-11-07 07:22:10 +05:30
|
|
|
static void auto_baud(char *buf, unsigned size_buf, struct termios *tp)
|
2002-06-05 02:15:46 +05:30
|
|
|
{
|
|
|
|
int speed;
|
|
|
|
int vmin;
|
|
|
|
unsigned iflag;
|
|
|
|
char *bp;
|
|
|
|
int nread;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This works only if the modem produces its status code AFTER raising
|
|
|
|
* the DCD line, and if the computer is fast enough to set the proper
|
|
|
|
* baud rate before the message has gone by. We expect a message of the
|
|
|
|
* following format:
|
2004-03-15 13:59:22 +05:30
|
|
|
*
|
2002-06-05 02:15:46 +05:30
|
|
|
* <junk><number><junk>
|
2004-03-15 13:59:22 +05:30
|
|
|
*
|
2002-06-05 02:15:46 +05:30
|
|
|
* The number is interpreted as the baud rate of the incoming call. If the
|
|
|
|
* modem does not tell us the baud rate within one second, we will keep
|
|
|
|
* using the current baud rate. It is advisable to enable BREAK
|
|
|
|
* processing (comma-separated list of baud rates) if the processing of
|
|
|
|
* modem status messages is enabled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use 7-bit characters, don't block if input queue is empty. Errors will
|
2006-10-23 15:47:34 +05:30
|
|
|
* be dealt with later on.
|
2002-06-05 02:15:46 +05:30
|
|
|
*/
|
|
|
|
iflag = tp->c_iflag;
|
2005-09-29 17:01:26 +05:30
|
|
|
tp->c_iflag |= ISTRIP; /* enable 8th-bit stripping */
|
2002-06-05 02:15:46 +05:30
|
|
|
vmin = tp->c_cc[VMIN];
|
2007-12-04 15:18:40 +05:30
|
|
|
tp->c_cc[VMIN] = 0; /* don't block if queue empty */
|
2008-11-05 18:50:58 +05:30
|
|
|
tcsetattr_stdin_TCSANOW(tp);
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for a while, then read everything the modem has said so far and
|
|
|
|
* try to extract the speed of the dial-in call.
|
|
|
|
*/
|
2006-10-23 07:41:22 +05:30
|
|
|
sleep(1);
|
2008-05-19 15:18:17 +05:30
|
|
|
nread = safe_read(STDIN_FILENO, buf, size_buf - 1);
|
2006-10-23 07:40:45 +05:30
|
|
|
if (nread > 0) {
|
2002-06-05 02:15:46 +05:30
|
|
|
buf[nread] = '\0';
|
|
|
|
for (bp = buf; bp < buf + nread; bp++) {
|
2007-12-04 15:18:40 +05:30
|
|
|
if (isdigit(*bp)) {
|
2006-10-08 18:19:22 +05:30
|
|
|
speed = bcode(bp);
|
2010-05-27 19:07:32 +05:30
|
|
|
if (speed > 0)
|
|
|
|
cfsetspeed(tp, speed);
|
2002-06-05 02:15:46 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Restore terminal settings. Errors will be dealt with later on. */
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_iflag = iflag;
|
|
|
|
tp->c_cc[VMIN] = vmin;
|
2008-11-05 18:50:58 +05:30
|
|
|
tcsetattr_stdin_TCSANOW(tp);
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
2006-06-16 22:07:07 +05:30
|
|
|
/* do_prompt - show login prompt, optionally preceded by /etc/issue contents */
|
2008-03-17 14:30:54 +05:30
|
|
|
static void do_prompt(struct options *op)
|
2006-06-16 22:07:07 +05:30
|
|
|
{
|
2006-10-23 15:47:34 +05:30
|
|
|
#ifdef ISSUE
|
2006-06-16 22:07:07 +05:30
|
|
|
print_login_issue(op->issue, op->tty);
|
|
|
|
#endif
|
|
|
|
print_login_prompt();
|
|
|
|
}
|
|
|
|
|
2006-10-23 15:47:34 +05:30
|
|
|
#ifdef HANDLE_ALLCAPS
|
2007-12-04 15:18:40 +05:30
|
|
|
/* all_is_upcase - string contains upper case without lower case */
|
2006-06-16 22:07:07 +05:30
|
|
|
/* returns 1 if true, 0 if false */
|
2007-12-04 15:18:40 +05:30
|
|
|
static int all_is_upcase(const char *s)
|
2006-06-16 22:07:07 +05:30
|
|
|
{
|
2006-10-23 07:40:45 +05:30
|
|
|
while (*s)
|
|
|
|
if (islower(*s++))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
2006-06-16 22:07:07 +05:30
|
|
|
}
|
2006-10-23 15:47:34 +05:30
|
|
|
#endif
|
2006-06-16 22:07:07 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* get_logname - get user name, establish parity, speed, erase, kill, eol;
|
|
|
|
* return NULL on BREAK, logname on success */
|
2006-10-24 04:13:02 +05:30
|
|
|
static char *get_logname(char *logname, unsigned size_logname,
|
2008-03-17 14:30:54 +05:30
|
|
|
struct options *op, struct chardata *cp)
|
2002-06-05 02:15:46 +05:30
|
|
|
{
|
|
|
|
char *bp;
|
2005-10-15 15:53:55 +05:30
|
|
|
char c; /* input character, full eight bits */
|
|
|
|
char ascval; /* low 7 bits of input character */
|
|
|
|
int bits; /* # of "1" bits per character */
|
|
|
|
int mask; /* mask with 1 bit up */
|
2008-03-17 14:25:44 +05:30
|
|
|
static const char erase[][3] = {/* backspace-space-backspace */
|
2005-09-29 17:01:26 +05:30
|
|
|
"\010\040\010", /* space parity */
|
|
|
|
"\010\040\010", /* odd parity */
|
|
|
|
"\210\240\210", /* even parity */
|
2008-03-17 14:25:44 +05:30
|
|
|
"\010\040\010", /* 8 bit no parity */
|
2002-06-05 02:15:46 +05:30
|
|
|
};
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* NB: *cp is pre-initialized with init_chardata */
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Flush pending input (esp. after parsing or switching the baud rate). */
|
2006-10-23 07:41:22 +05:30
|
|
|
sleep(1);
|
2010-05-27 19:07:32 +05:30
|
|
|
tcflush(0, TCIOFLUSH);
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Prompt for and read a login name. */
|
2006-10-24 04:13:02 +05:30
|
|
|
logname[0] = '\0';
|
|
|
|
while (!logname[0]) {
|
2002-06-05 02:15:46 +05:30
|
|
|
/* Write issue file and prompt, with "parity" bit == 0. */
|
2008-03-17 14:30:54 +05:30
|
|
|
do_prompt(op);
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Read name, watch for break, parity, erase, kill, end-of-line. */
|
2006-10-23 07:40:45 +05:30
|
|
|
bp = logname;
|
2006-10-24 04:13:02 +05:30
|
|
|
cp->eol = '\0';
|
|
|
|
while (cp->eol == '\0') {
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Do not report trivial EINTR/EIO errors. */
|
2010-05-23 00:47:46 +05:30
|
|
|
errno = EINTR; /* make read of 0 bytes be silent too */
|
2008-05-19 15:18:17 +05:30
|
|
|
if (read(STDIN_FILENO, &c, 1) < 1) {
|
2002-06-05 02:15:46 +05:30
|
|
|
if (errno == EINTR || errno == EIO)
|
2008-05-19 14:59:47 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
2010-09-01 15:01:43 +05:30
|
|
|
bb_perror_msg_and_die(bb_msg_read_error);
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* BREAK. If we have speeds to try,
|
|
|
|
* return NULL (will switch speeds and return here) */
|
2006-10-24 04:13:02 +05:30
|
|
|
if (c == '\0' && op->numspeed > 1)
|
2002-06-05 02:15:46 +05:30
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Do parity bit handling. */
|
2008-03-17 14:25:44 +05:30
|
|
|
if (!(op->flags & F_LOCAL) && (c & 0x80)) { /* "parity" bit on? */
|
2006-10-24 04:13:02 +05:30
|
|
|
bits = 1;
|
|
|
|
mask = 1;
|
2008-03-17 14:25:44 +05:30
|
|
|
while (mask & 0x7f) {
|
|
|
|
if (mask & c)
|
2005-09-29 17:01:26 +05:30
|
|
|
bits++; /* count "1" bits */
|
2006-10-24 04:13:02 +05:30
|
|
|
mask <<= 1;
|
|
|
|
}
|
2006-10-23 15:47:34 +05:30
|
|
|
/* ... |= 2 - even, 1 - odd */
|
|
|
|
cp->parity |= 2 - (bits & 1);
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
2006-10-24 04:13:02 +05:30
|
|
|
/* Do erase, kill and end-of-line processing. */
|
2008-03-17 14:25:44 +05:30
|
|
|
ascval = c & 0x7f;
|
2002-06-05 02:15:46 +05:30
|
|
|
switch (ascval) {
|
|
|
|
case CR:
|
|
|
|
case NL:
|
2006-10-24 04:13:02 +05:30
|
|
|
*bp = '\0'; /* terminate logname */
|
2005-09-29 17:01:26 +05:30
|
|
|
cp->eol = ascval; /* set end-of-line char */
|
2002-06-05 02:15:46 +05:30
|
|
|
break;
|
|
|
|
case BS:
|
|
|
|
case DEL:
|
2007-12-04 15:18:40 +05:30
|
|
|
#ifdef ANCIENT_BS_KILL_CHARS
|
2002-06-05 02:15:46 +05:30
|
|
|
case '#':
|
2007-12-04 15:18:40 +05:30
|
|
|
#endif
|
2005-09-29 17:01:26 +05:30
|
|
|
cp->erase = ascval; /* set erase character */
|
2002-06-05 02:15:46 +05:30
|
|
|
if (bp > logname) {
|
2008-05-19 15:18:17 +05:30
|
|
|
full_write(STDOUT_FILENO, erase[cp->parity], 3);
|
2002-06-05 02:15:46 +05:30
|
|
|
bp--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CTL('U'):
|
2007-12-04 15:18:40 +05:30
|
|
|
#ifdef ANCIENT_BS_KILL_CHARS
|
2002-06-05 02:15:46 +05:30
|
|
|
case '@':
|
2007-12-04 15:18:40 +05:30
|
|
|
#endif
|
2005-09-29 17:01:26 +05:30
|
|
|
cp->kill = ascval; /* set kill character */
|
2002-06-05 02:15:46 +05:30
|
|
|
while (bp > logname) {
|
2008-05-19 15:18:17 +05:30
|
|
|
full_write(STDOUT_FILENO, erase[cp->parity], 3);
|
2002-06-05 02:15:46 +05:30
|
|
|
bp--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CTL('D'):
|
2008-05-19 14:59:47 +05:30
|
|
|
exit(EXIT_SUCCESS);
|
2002-06-05 02:15:46 +05:30
|
|
|
default:
|
2009-11-18 16:04:43 +05:30
|
|
|
if (ascval < ' ') {
|
2006-10-24 04:13:02 +05:30
|
|
|
/* ignore garbage characters */
|
2008-05-16 03:00:45 +05:30
|
|
|
} else if ((int)(bp - logname) >= size_logname - 1) {
|
2010-09-01 15:01:43 +05:30
|
|
|
bb_error_msg_and_die("input overrun");
|
2002-06-05 02:15:46 +05:30
|
|
|
} else {
|
2008-05-19 15:18:17 +05:30
|
|
|
full_write(STDOUT_FILENO, &c, 1); /* echo the character */
|
2005-09-29 17:01:26 +05:30
|
|
|
*bp++ = ascval; /* and store it */
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Handle names with upper case and no lower case. */
|
|
|
|
|
2006-10-23 15:47:34 +05:30
|
|
|
#ifdef HANDLE_ALLCAPS
|
2007-12-04 15:18:40 +05:30
|
|
|
cp->capslock = all_is_upcase(logname);
|
2006-10-23 07:40:45 +05:30
|
|
|
if (cp->capslock) {
|
2002-06-05 02:15:46 +05:30
|
|
|
for (bp = logname; *bp; bp++)
|
|
|
|
if (isupper(*bp))
|
2005-09-29 17:01:26 +05:30
|
|
|
*bp = tolower(*bp); /* map name to lower case */
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
2006-10-23 15:47:34 +05:30
|
|
|
#endif
|
2006-10-23 07:40:45 +05:30
|
|
|
return logname;
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/* termios_final - set the final tty mode bits */
|
|
|
|
static void termios_final(struct options *op, struct termios *tp, struct chardata *cp)
|
2002-06-05 02:15:46 +05:30
|
|
|
{
|
|
|
|
/* General terminal-independent stuff. */
|
2005-09-29 17:01:26 +05:30
|
|
|
tp->c_iflag |= IXON | IXOFF; /* 2-way flow control */
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_lflag |= ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHOKE;
|
|
|
|
/* no longer| ECHOCTL | ECHOPRT */
|
|
|
|
tp->c_oflag |= OPOST;
|
|
|
|
/* tp->c_cflag = 0; */
|
2005-09-29 17:01:26 +05:30
|
|
|
tp->c_cc[VINTR] = DEF_INTR; /* default interrupt */
|
|
|
|
tp->c_cc[VQUIT] = DEF_QUIT; /* default quit */
|
|
|
|
tp->c_cc[VEOF] = DEF_EOF; /* default EOF character */
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_cc[VEOL] = DEF_EOL;
|
2010-05-27 19:07:32 +05:30
|
|
|
#ifdef VSWTC
|
2005-09-29 17:01:26 +05:30
|
|
|
tp->c_cc[VSWTC] = DEF_SWITCH; /* default switch character */
|
2010-05-27 19:07:32 +05:30
|
|
|
#endif
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Account for special characters seen in input. */
|
|
|
|
if (cp->eol == CR) {
|
2005-09-29 17:01:26 +05:30
|
|
|
tp->c_iflag |= ICRNL; /* map CR in input to NL */
|
|
|
|
tp->c_oflag |= ONLCR; /* map NL in output to CR-NL */
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
2005-09-29 17:01:26 +05:30
|
|
|
tp->c_cc[VERASE] = cp->erase; /* set erase character */
|
|
|
|
tp->c_cc[VKILL] = cp->kill; /* set kill character */
|
2002-06-05 02:15:46 +05:30
|
|
|
|
|
|
|
/* Account for the presence or absence of parity bits in input. */
|
|
|
|
switch (cp->parity) {
|
2005-09-29 17:01:26 +05:30
|
|
|
case 0: /* space (always 0) parity */
|
2008-03-17 14:25:44 +05:30
|
|
|
// I bet most people go here - they use only 7-bit chars in usernames....
|
2002-06-05 02:15:46 +05:30
|
|
|
break;
|
2005-09-29 17:01:26 +05:30
|
|
|
case 1: /* odd parity */
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_cflag |= PARODD;
|
|
|
|
/* FALLTHROUGH */
|
2005-09-29 17:01:26 +05:30
|
|
|
case 2: /* even parity */
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_cflag |= PARENB;
|
|
|
|
tp->c_iflag |= INPCK | ISTRIP;
|
|
|
|
/* FALLTHROUGH */
|
2005-09-29 17:01:26 +05:30
|
|
|
case (1 | 2): /* no parity bit */
|
2002-06-05 02:15:46 +05:30
|
|
|
tp->c_cflag &= ~CSIZE;
|
|
|
|
tp->c_cflag |= CS7;
|
2008-03-17 14:25:44 +05:30
|
|
|
// FIXME: wtf? case 3: we saw both even and odd 8-bit bytes -
|
|
|
|
// it's probably some umlauts etc, but definitely NOT 7-bit!!!
|
|
|
|
// Entire parity detection madness here just begs for deletion...
|
2002-06-05 02:15:46 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-28 03:51:12 +05:30
|
|
|
/* Account for upper case without lower case. */
|
2006-10-23 15:47:34 +05:30
|
|
|
#ifdef HANDLE_ALLCAPS
|
2002-06-05 02:15:46 +05:30
|
|
|
if (cp->capslock) {
|
|
|
|
tp->c_iflag |= IUCLC;
|
|
|
|
tp->c_lflag |= XCASE;
|
|
|
|
tp->c_oflag |= OLCUC;
|
|
|
|
}
|
2006-10-23 15:47:34 +05:30
|
|
|
#endif
|
2002-06-05 02:15:46 +05:30
|
|
|
/* Optionally enable hardware flow control */
|
2008-11-05 18:50:58 +05:30
|
|
|
#ifdef CRTSCTS
|
2002-06-05 02:15:46 +05:30
|
|
|
if (op->flags & F_RTSCTS)
|
|
|
|
tp->c_cflag |= CRTSCTS;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Finally, make the new settings effective */
|
2010-05-27 19:07:32 +05:30
|
|
|
if (tcsetattr_stdin_TCSANOW(tp) < 0)
|
2010-09-01 15:01:43 +05:30
|
|
|
bb_perror_msg_and_die("tcsetattr");
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int getty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int getty_main(int argc UNUSED_PARAM, char **argv)
|
2006-06-16 22:07:07 +05:30
|
|
|
{
|
2007-12-04 15:18:40 +05:30
|
|
|
int n;
|
2010-04-06 01:40:38 +05:30
|
|
|
pid_t pid;
|
2007-12-05 00:16:01 +05:30
|
|
|
char *fakehost = NULL; /* Fake hostname for ut_host */
|
2007-12-04 15:18:40 +05:30
|
|
|
char *logname; /* login name, given to /bin/login */
|
2006-11-07 07:22:10 +05:30
|
|
|
/* Merging these into "struct local" may _seem_ to reduce
|
|
|
|
* parameter passing, but today's gcc will inline
|
|
|
|
* statics which are called once anyway, so don't do that */
|
2006-06-16 22:07:07 +05:30
|
|
|
struct chardata chardata; /* set by get_logname() */
|
2007-12-04 15:18:40 +05:30
|
|
|
struct termios termios; /* terminal mode bits */
|
|
|
|
struct options options;
|
|
|
|
|
2008-03-17 14:25:44 +05:30
|
|
|
chardata = init_chardata;
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
memset(&options, 0, sizeof(options));
|
|
|
|
options.login = _PATH_LOGIN; /* default login program */
|
|
|
|
options.tty = "tty1"; /* default tty line */
|
|
|
|
options.initstring = ""; /* modem init string */
|
2006-06-16 22:07:07 +05:30
|
|
|
#ifdef ISSUE
|
2007-12-04 15:18:40 +05:30
|
|
|
options.issue = ISSUE; /* default issue file */
|
2006-06-16 22:07:07 +05:30
|
|
|
#endif
|
2005-09-29 17:01:26 +05:30
|
|
|
|
2008-03-17 14:25:44 +05:30
|
|
|
/* Parse command-line arguments. */
|
|
|
|
parse_args(argv, &options, &fakehost);
|
|
|
|
|
2006-10-23 07:40:45 +05:30
|
|
|
logmode = LOGMODE_NONE;
|
2007-12-04 15:18:40 +05:30
|
|
|
|
|
|
|
/* Create new session, lose controlling tty, if any */
|
|
|
|
/* docs/ctty.htm says:
|
|
|
|
* "This is allowed only when the current process
|
|
|
|
* is not a process group leader" - is this a problem? */
|
2006-09-07 21:50:03 +05:30
|
|
|
setsid();
|
2008-03-17 14:25:44 +05:30
|
|
|
/* close stdio, and stray descriptors, just in case */
|
2007-12-04 15:18:40 +05:30
|
|
|
n = xopen(bb_dev_null, O_RDWR);
|
2008-03-17 14:25:44 +05:30
|
|
|
/* dup2(n, 0); - no, we need to handle "getty - 9600" too */
|
|
|
|
xdup2(n, 1);
|
|
|
|
xdup2(n, 2);
|
2007-12-04 15:18:40 +05:30
|
|
|
while (n > 2)
|
|
|
|
close(n--);
|
2008-03-17 14:25:44 +05:30
|
|
|
|
|
|
|
/* Logging. We want special flavor of error_msg_and_die */
|
2006-10-23 07:40:45 +05:30
|
|
|
die_sleep = 10;
|
|
|
|
msg_eol = "\r\n";
|
2008-03-17 14:25:44 +05:30
|
|
|
/* most likely will internally use fd #3 in CLOEXEC mode: */
|
2006-10-04 02:30:43 +05:30
|
|
|
openlog(applet_name, LOG_PID, LOG_AUTH);
|
2006-09-07 21:50:03 +05:30
|
|
|
logmode = LOGMODE_BOTH;
|
|
|
|
|
2006-06-16 22:07:07 +05:30
|
|
|
#ifdef DEBUGGING
|
2008-07-22 04:35:26 +05:30
|
|
|
dbf = xfopen_for_write(DEBUGTERM);
|
2008-03-17 14:30:54 +05:30
|
|
|
for (n = 1; argv[n]; n++) {
|
2007-12-04 15:18:40 +05:30
|
|
|
debug(argv[n]);
|
|
|
|
debug("\n");
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|
|
|
|
#endif
|
2005-09-29 17:01:26 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Open the tty as standard input, if it is not "-" */
|
2008-03-17 14:25:44 +05:30
|
|
|
/* If it's not "-" and not taken yet, it will become our ctty */
|
|
|
|
debug("calling open_tty\n");
|
2007-12-04 15:18:40 +05:30
|
|
|
open_tty(options.tty);
|
|
|
|
ndelay_off(0);
|
2008-03-17 14:25:44 +05:30
|
|
|
debug("duping\n");
|
2007-12-04 15:18:40 +05:30
|
|
|
xdup2(0, 1);
|
|
|
|
xdup2(0, 2);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following ioctl will fail if stdin is not a tty, but also when
|
|
|
|
* there is noise on the modem control lines. In the latter case, the
|
|
|
|
* common course of action is (1) fix your cables (2) give the modem more
|
|
|
|
* time to properly reset after hanging up. SunOS users can achieve (2)
|
|
|
|
* by patching the SunOS kernel variable "zsadtrlow" to a larger value;
|
|
|
|
* 5 seconds seems to be a good value.
|
|
|
|
*/
|
2010-05-27 19:07:32 +05:30
|
|
|
if (tcgetattr(0, &termios) < 0)
|
2010-09-01 15:01:43 +05:30
|
|
|
bb_perror_msg_and_die("tcgetattr");
|
2006-06-16 22:07:07 +05:30
|
|
|
|
2010-04-06 01:40:38 +05:30
|
|
|
pid = getpid();
|
2006-06-16 22:07:07 +05:30
|
|
|
#ifdef __linux__
|
2008-03-17 14:25:44 +05:30
|
|
|
// FIXME: do we need this? Otherwise "-" case seems to be broken...
|
2007-12-04 15:18:40 +05:30
|
|
|
// /* Forcibly make fd 0 our controlling tty, even if another session
|
|
|
|
// * has it as a ctty. (Another session loses ctty). */
|
|
|
|
// ioctl(0, TIOCSCTTY, (void*)1);
|
2008-03-17 14:25:44 +05:30
|
|
|
/* Make ourself a foreground process group within our session */
|
2010-04-06 01:40:38 +05:30
|
|
|
tcsetpgrp(0, pid);
|
2008-03-17 14:25:44 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Update the utmp file. This tty is ours now! */
|
2010-04-06 01:40:38 +05:30
|
|
|
update_utmp(pid, LOGIN_PROCESS, options.tty, "LOGIN", fakehost);
|
2007-12-04 15:18:40 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/* Initialize the termios settings (raw mode, eight-bit, blocking i/o). */
|
|
|
|
debug("calling termios_init\n");
|
2007-12-04 15:18:40 +05:30
|
|
|
termios_init(&termios, options.speeds[0], &options);
|
2006-06-16 22:07:07 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Write the modem init string and DON'T flush the buffers */
|
2006-06-16 22:07:07 +05:30
|
|
|
if (options.flags & F_INITSTRING) {
|
|
|
|
debug("writing init string\n");
|
2010-06-07 17:44:26 +05:30
|
|
|
full_write1_str(options.initstring);
|
2006-06-16 22:07:07 +05:30
|
|
|
}
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Optionally detect the baud rate from the modem status message */
|
2006-06-16 22:07:07 +05:30
|
|
|
debug("before autobaud\n");
|
|
|
|
if (options.flags & F_PARSE)
|
2007-12-04 15:18:40 +05:30
|
|
|
auto_baud(line_buf, sizeof(line_buf), &termios);
|
2006-06-16 22:07:07 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Set the optional timer */
|
2008-03-17 14:25:44 +05:30
|
|
|
alarm(options.timeout); /* if 0, alarm is not set */
|
2006-06-16 22:07:07 +05:30
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
/* Optionally wait for CR or LF before writing /etc/issue */
|
2006-06-16 22:07:07 +05:30
|
|
|
if (options.flags & F_WAITCRLF) {
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
debug("waiting for cr-lf\n");
|
2008-05-19 15:18:17 +05:30
|
|
|
while (safe_read(STDIN_FILENO, &ch, 1) == 1) {
|
2008-03-17 14:25:44 +05:30
|
|
|
debug("read %x\n", (unsigned char)ch);
|
2006-06-16 22:07:07 +05:30
|
|
|
ch &= 0x7f; /* strip "parity bit" */
|
|
|
|
if (ch == '\n' || ch == '\r')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-04 15:18:40 +05:30
|
|
|
logname = NULL;
|
2006-06-16 22:07:07 +05:30
|
|
|
if (!(options.flags & F_NOPROMPT)) {
|
2007-12-04 15:18:40 +05:30
|
|
|
/* NB:termios_init already set line speed
|
|
|
|
* to options.speeds[0] */
|
|
|
|
int baud_index = 0;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/* Read the login name. */
|
|
|
|
debug("reading login name\n");
|
|
|
|
logname = get_logname(line_buf, sizeof(line_buf),
|
2008-03-17 14:30:54 +05:30
|
|
|
&options, &chardata);
|
2007-12-04 15:18:40 +05:30
|
|
|
if (logname)
|
|
|
|
break;
|
|
|
|
/* we are here only if options.numspeed > 1 */
|
|
|
|
baud_index = (baud_index + 1) % options.numspeed;
|
2009-04-12 18:35:40 +05:30
|
|
|
cfsetispeed(&termios, options.speeds[baud_index]);
|
|
|
|
cfsetospeed(&termios, options.speeds[baud_index]);
|
2008-11-05 18:50:58 +05:30
|
|
|
tcsetattr_stdin_TCSANOW(&termios);
|
2007-12-04 15:18:40 +05:30
|
|
|
}
|
2006-06-16 22:07:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable timer. */
|
2008-03-17 14:25:44 +05:30
|
|
|
alarm(0);
|
2006-06-16 22:07:07 +05:30
|
|
|
|
2006-11-07 07:22:10 +05:30
|
|
|
/* Finalize the termios settings. */
|
|
|
|
termios_final(&options, &termios, &chardata);
|
2006-06-16 22:07:07 +05:30
|
|
|
|
|
|
|
/* Now the newline character should be properly written. */
|
2008-05-19 15:18:17 +05:30
|
|
|
full_write(STDOUT_FILENO, "\n", 1);
|
2006-06-16 22:07:07 +05:30
|
|
|
|
|
|
|
/* Let the login program take care of password validation. */
|
2007-12-04 15:18:40 +05:30
|
|
|
/* We use PATH because we trust that root doesn't set "bad" PATH,
|
|
|
|
* and getty is not suid-root applet. */
|
2008-03-17 14:25:44 +05:30
|
|
|
/* With -n, logname == NULL, and login will ask for username instead */
|
2007-12-04 15:18:40 +05:30
|
|
|
BB_EXECLP(options.login, options.login, "--", logname, NULL);
|
2010-09-01 15:01:43 +05:30
|
|
|
bb_error_msg_and_die("can't execute '%s'", options.login);
|
2002-06-05 02:15:46 +05:30
|
|
|
}
|