1994-05-27 12:39:25 +00:00
|
|
|
/*-
|
1996-05-05 19:01:13 +00:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-05-27 12:39:25 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-11-21 07:43:53 +00:00
|
|
|
static const char copyright[] =
|
1996-05-05 19:01:13 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
1994-05-27 12:39:25 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-11-21 07:43:53 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)from: main.c 8.1 (Berkeley) 6/20/93";
|
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1998-10-08 23:14:02 +00:00
|
|
|
"$Id: main.c,v 1.22 1997/11/21 07:43:50 charnier Exp $";
|
1994-05-27 12:39:25 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
1996-05-05 19:01:13 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/ttydefaults.h>
|
|
|
|
#include <sys/utsname.h>
|
1994-08-26 05:19:17 +00:00
|
|
|
#include <ctype.h>
|
1997-11-21 07:43:53 +00:00
|
|
|
#include <errno.h>
|
1996-05-05 19:01:13 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <locale.h>
|
1997-11-21 07:43:53 +00:00
|
|
|
#include <libutil.h>
|
|
|
|
#include <signal.h>
|
1994-08-26 05:19:17 +00:00
|
|
|
#include <setjmp.h>
|
1996-05-05 19:01:13 +00:00
|
|
|
#include <signal.h>
|
1994-08-26 05:19:17 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1996-05-05 19:01:13 +00:00
|
|
|
#include <syslog.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
#include "gettytab.h"
|
|
|
|
#include "pathnames.h"
|
1996-05-05 19:01:13 +00:00
|
|
|
#include "extern.h"
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
/*
|
|
|
|
* Set the amount of running time that getty should accumulate
|
|
|
|
* before deciding that something is wrong and exit.
|
|
|
|
*/
|
|
|
|
#define GETTY_TIMEOUT 60 /* seconds */
|
|
|
|
|
|
|
|
#undef CTRL
|
|
|
|
#define CTRL(x) (x&037)
|
|
|
|
|
1996-11-13 01:06:40 +00:00
|
|
|
/* defines for auto detection of incoming PPP calls (->PAP/CHAP) */
|
|
|
|
|
|
|
|
#define PPP_FRAME 0x7e /* PPP Framing character */
|
|
|
|
#define PPP_STATION 0xff /* "All Station" character */
|
|
|
|
#define PPP_ESCAPE 0x7d /* Escape Character */
|
|
|
|
#define PPP_CONTROL 0x03 /* PPP Control Field */
|
|
|
|
#define PPP_CONTROL_ESCAPED 0x23 /* PPP Control Field, escaped */
|
|
|
|
#define PPP_LCP_HI 0xc0 /* LCP protocol - high byte */
|
|
|
|
#define PPP_LCP_LOW 0x21 /* LCP protocol - low byte */
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
struct termios tmode, omode;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
int crmod, digit, lower, upper;
|
|
|
|
|
|
|
|
char hostname[MAXHOSTNAMELEN];
|
1997-02-07 11:45:10 +00:00
|
|
|
char name[MAXLOGNAME*3];
|
1994-05-27 12:39:25 +00:00
|
|
|
char dev[] = _PATH_DEV;
|
|
|
|
char ttyn[32];
|
|
|
|
|
|
|
|
#define OBUFSIZ 128
|
|
|
|
#define TABBUFSIZ 512
|
|
|
|
|
|
|
|
char defent[TABBUFSIZ];
|
|
|
|
char tabent[TABBUFSIZ];
|
|
|
|
|
|
|
|
char *env[128];
|
|
|
|
|
|
|
|
char partab[] = {
|
|
|
|
0001,0201,0201,0001,0201,0001,0001,0201,
|
|
|
|
0202,0004,0003,0205,0005,0206,0201,0001,
|
|
|
|
0201,0001,0001,0201,0001,0201,0201,0001,
|
|
|
|
0001,0201,0201,0001,0201,0001,0001,0201,
|
|
|
|
0200,0000,0000,0200,0000,0200,0200,0000,
|
|
|
|
0000,0200,0200,0000,0200,0000,0000,0200,
|
|
|
|
0000,0200,0200,0000,0200,0000,0000,0200,
|
|
|
|
0200,0000,0000,0200,0000,0200,0200,0000,
|
|
|
|
0200,0000,0000,0200,0000,0200,0200,0000,
|
|
|
|
0000,0200,0200,0000,0200,0000,0000,0200,
|
|
|
|
0000,0200,0200,0000,0200,0000,0000,0200,
|
|
|
|
0200,0000,0000,0200,0000,0200,0200,0000,
|
|
|
|
0000,0200,0200,0000,0200,0000,0000,0200,
|
|
|
|
0200,0000,0000,0200,0000,0200,0200,0000,
|
|
|
|
0200,0000,0000,0200,0000,0200,0200,0000,
|
|
|
|
0000,0200,0200,0000,0200,0000,0000,0201
|
|
|
|
};
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
#define ERASE tmode.c_cc[VERASE]
|
|
|
|
#define KILL tmode.c_cc[VKILL]
|
|
|
|
#define EOT tmode.c_cc[VEOF]
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1998-10-08 23:14:02 +00:00
|
|
|
#define puts Gputs
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void dingdong __P((int));
|
|
|
|
static int getname __P((void));
|
|
|
|
static void interrupt __P((int));
|
|
|
|
static void oflush __P((void));
|
|
|
|
static void prompt __P((void));
|
|
|
|
static void putchr __P((int));
|
|
|
|
static void putf __P((const char *));
|
|
|
|
static void putpad __P((const char *));
|
|
|
|
static void puts __P((const char *));
|
|
|
|
static void timeoverrun __P((int));
|
1997-02-02 14:24:57 +00:00
|
|
|
static char *getline __P((int));
|
|
|
|
static void setttymode __P((const char *, int));
|
|
|
|
static void setdefttymode __P((const char *));
|
|
|
|
static int opentty __P((const char *, int));
|
1996-05-05 19:01:13 +00:00
|
|
|
|
|
|
|
int main __P((int, char **));
|
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
jmp_buf timeout;
|
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
static void
|
1996-05-05 19:01:13 +00:00
|
|
|
dingdong(signo)
|
|
|
|
int signo;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
alarm(0);
|
|
|
|
longjmp(timeout, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
jmp_buf intrupt;
|
|
|
|
|
|
|
|
static void
|
1996-05-05 19:01:13 +00:00
|
|
|
interrupt(signo)
|
|
|
|
int signo;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
longjmp(intrupt, 1);
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
/*
|
|
|
|
* Action to take when getty is running too long.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
timeoverrun(signo)
|
|
|
|
int signo;
|
|
|
|
{
|
|
|
|
|
1997-11-21 07:43:53 +00:00
|
|
|
syslog(LOG_ERR, "getty exiting due to excessive running time");
|
1996-05-05 19:01:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1994-05-27 12:39:25 +00:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
1994-08-26 05:19:17 +00:00
|
|
|
char **argv;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
1994-08-26 05:19:17 +00:00
|
|
|
extern char **environ;
|
1996-05-05 19:01:13 +00:00
|
|
|
const char *tname;
|
1997-02-09 16:12:08 +00:00
|
|
|
int first_sleep = 1, first_time = 1;
|
1996-05-05 19:01:13 +00:00
|
|
|
struct rlimit limit;
|
1996-11-13 01:06:40 +00:00
|
|
|
int rval;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
signal(SIGINT, SIG_IGN);
|
1994-08-29 17:28:58 +00:00
|
|
|
signal(SIGQUIT, SIG_IGN);
|
1994-08-26 05:19:17 +00:00
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
openlog("getty", LOG_ODELAY|LOG_CONS|LOG_PID, LOG_AUTH);
|
1994-05-27 12:39:25 +00:00
|
|
|
gethostname(hostname, sizeof(hostname));
|
|
|
|
if (hostname[0] == '\0')
|
|
|
|
strcpy(hostname, "Amnesiac");
|
1996-05-05 19:01:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Limit running time to deal with broken or dead lines.
|
|
|
|
*/
|
|
|
|
(void)signal(SIGXCPU, timeoverrun);
|
|
|
|
limit.rlim_max = RLIM_INFINITY;
|
|
|
|
limit.rlim_cur = GETTY_TIMEOUT;
|
|
|
|
(void)setrlimit(RLIMIT_CPU, &limit);
|
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
gettable("default", defent);
|
|
|
|
gendefaults();
|
|
|
|
tname = "default";
|
|
|
|
if (argc > 1)
|
|
|
|
tname = argv[1];
|
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
/*
|
|
|
|
* The following is a work around for vhangup interactions
|
|
|
|
* which cause great problems getting window systems started.
|
|
|
|
* If the tty line is "-", we do the old style getty presuming
|
1995-05-30 05:51:47 +00:00
|
|
|
* that the file descriptors are already set up for us.
|
1994-05-27 12:39:25 +00:00
|
|
|
* J. Gettys - MIT Project Athena.
|
|
|
|
*/
|
|
|
|
if (argc <= 2 || strcmp(argv[2], "-") == 0)
|
1997-02-02 14:24:57 +00:00
|
|
|
strcpy(ttyn, ttyname(STDIN_FILENO));
|
1994-05-27 12:39:25 +00:00
|
|
|
else {
|
|
|
|
strcpy(ttyn, dev);
|
|
|
|
strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
|
|
|
|
if (strcmp(argv[0], "+") != 0) {
|
|
|
|
chown(ttyn, 0, 0);
|
|
|
|
chmod(ttyn, 0600);
|
|
|
|
revoke(ttyn);
|
1997-02-02 14:24:57 +00:00
|
|
|
|
|
|
|
gettable(tname, tabent);
|
|
|
|
|
|
|
|
/* Init modem sequence has been specified
|
|
|
|
*/
|
|
|
|
if (IC) {
|
|
|
|
if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
|
|
|
|
exit(1);
|
|
|
|
setdefttymode(tname);
|
|
|
|
if (getty_chat(IC, CT, DC) > 0) {
|
|
|
|
syslog(LOG_ERR, "modem init problem on %s", ttyn);
|
1997-02-09 16:12:08 +00:00
|
|
|
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
|
1997-02-02 14:24:57 +00:00
|
|
|
exit(1);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
1997-02-02 14:24:57 +00:00
|
|
|
|
|
|
|
if (AC) {
|
|
|
|
int i, rfds;
|
|
|
|
struct timeval timeout;
|
|
|
|
|
|
|
|
if (!opentty(ttyn, O_RDWR|O_NONBLOCK))
|
|
|
|
exit(1);
|
|
|
|
setdefttymode(tname);
|
|
|
|
rfds = 1 << 0; /* FD_SET */
|
|
|
|
timeout.tv_sec = RT;
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
i = select(32, (fd_set*)&rfds, (fd_set*)NULL,
|
|
|
|
(fd_set*)NULL, RT ? &timeout : NULL);
|
|
|
|
if (i < 0) {
|
|
|
|
syslog(LOG_ERR, "select %s: %m", ttyn);
|
|
|
|
} else if (i == 0) {
|
|
|
|
syslog(LOG_NOTICE, "recycle tty %s", ttyn);
|
1997-02-09 16:12:08 +00:00
|
|
|
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
|
1997-02-02 14:24:57 +00:00
|
|
|
exit(0); /* recycle for init */
|
|
|
|
}
|
|
|
|
i = getty_chat(AC, CT, DC);
|
|
|
|
if (i > 0) {
|
|
|
|
syslog(LOG_ERR, "modem answer problem on %s", ttyn);
|
1997-02-09 16:12:08 +00:00
|
|
|
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
|
1997-02-02 14:24:57 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else { /* blocking open */
|
|
|
|
if (!opentty(ttyn, O_RDWR))
|
|
|
|
exit(1);
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
/* Start with default tty settings */
|
1997-02-02 14:24:57 +00:00
|
|
|
if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
|
|
|
|
syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
|
1996-05-05 19:01:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Don't rely on the driver too much, and initialize crucial
|
|
|
|
* things according to <sys/ttydefaults.h>. Avoid clobbering
|
|
|
|
* the c_cc[] settings however, the console drivers might wish
|
|
|
|
* to leave their idea of the preferred VERASE key value
|
|
|
|
* there.
|
|
|
|
*/
|
|
|
|
tmode.c_iflag = TTYDEF_IFLAG;
|
|
|
|
tmode.c_oflag = TTYDEF_OFLAG;
|
|
|
|
tmode.c_lflag = TTYDEF_LFLAG;
|
|
|
|
tmode.c_cflag = TTYDEF_CFLAG;
|
|
|
|
omode = tmode;
|
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
for (;;) {
|
|
|
|
|
1997-02-09 16:12:08 +00:00
|
|
|
/*
|
|
|
|
* if a delay was specified then sleep for that
|
|
|
|
* number of seconds before writing the initial prompt
|
|
|
|
*/
|
|
|
|
if (first_sleep && DE) {
|
|
|
|
sleep(DE);
|
|
|
|
/* remove any noise */
|
|
|
|
(void)tcflush(STDIN_FILENO, TCIOFLUSH);
|
|
|
|
}
|
|
|
|
first_sleep = 0;
|
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
setttymode(tname, 0);
|
1994-05-27 12:39:25 +00:00
|
|
|
if (AB) {
|
|
|
|
tname = autobaud();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (PS) {
|
|
|
|
tname = portselector();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (CL && *CL)
|
|
|
|
putpad(CL);
|
|
|
|
edithost(HE);
|
1996-12-31 01:30:38 +00:00
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
/* if this is the first time through this, and an
|
|
|
|
issue file has been given, then send it */
|
|
|
|
if (first_time && IF) {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if ((fd = open(IF, O_RDONLY)) != -1) {
|
|
|
|
char * cp;
|
|
|
|
|
|
|
|
while ((cp = getline(fd)) != NULL) {
|
|
|
|
putf(cp);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
1997-02-09 16:12:08 +00:00
|
|
|
first_time = 0;
|
1996-12-31 01:30:38 +00:00
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
if (IM && *IM)
|
|
|
|
putf(IM);
|
|
|
|
if (setjmp(timeout)) {
|
1996-05-07 16:42:26 +00:00
|
|
|
cfsetispeed(&tmode, B0);
|
|
|
|
cfsetospeed(&tmode, B0);
|
1997-02-02 14:24:57 +00:00
|
|
|
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tmode);
|
1994-05-27 12:39:25 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (TO) {
|
|
|
|
signal(SIGALRM, dingdong);
|
|
|
|
alarm(TO);
|
|
|
|
}
|
1996-11-13 01:06:40 +00:00
|
|
|
if ((rval = getname()) == 2) {
|
1997-06-03 12:56:47 +00:00
|
|
|
oflush();
|
|
|
|
alarm(0);
|
1996-11-13 01:06:40 +00:00
|
|
|
execle(PP, "ppplogin", ttyn, (char *) 0, env);
|
|
|
|
syslog(LOG_ERR, "%s: %m", PP);
|
|
|
|
exit(1);
|
|
|
|
} else if (rval) {
|
1994-05-27 12:39:25 +00:00
|
|
|
register int i;
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
oflush();
|
1994-05-27 12:39:25 +00:00
|
|
|
alarm(0);
|
|
|
|
signal(SIGALRM, SIG_DFL);
|
|
|
|
if (name[0] == '-') {
|
|
|
|
puts("user names may not start with '-'.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!(upper || lower || digit))
|
|
|
|
continue;
|
1996-05-05 19:01:13 +00:00
|
|
|
setflags(2);
|
|
|
|
if (crmod) {
|
|
|
|
tmode.c_iflag |= ICRNL;
|
|
|
|
tmode.c_oflag |= ONLCR;
|
|
|
|
}
|
|
|
|
#if REALLY_OLD_TTYS
|
|
|
|
if (upper || UC)
|
|
|
|
tmode.sg_flags |= LCASE;
|
|
|
|
if (lower || LC)
|
|
|
|
tmode.sg_flags &= ~LCASE;
|
|
|
|
#endif
|
1997-02-02 14:24:57 +00:00
|
|
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) {
|
|
|
|
syslog(LOG_ERR, "tcsetattr %s: %m", ttyn);
|
1996-05-05 19:01:13 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
signal(SIGINT, SIG_DFL);
|
1994-05-27 12:39:25 +00:00
|
|
|
for (i = 0; environ[i] != (char *)0; i++)
|
|
|
|
env[i] = environ[i];
|
|
|
|
makeenv(&env[i]);
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
limit.rlim_max = RLIM_INFINITY;
|
|
|
|
limit.rlim_cur = RLIM_INFINITY;
|
|
|
|
(void)setrlimit(RLIMIT_CPU, &limit);
|
1994-05-27 12:39:25 +00:00
|
|
|
execle(LO, "login", "-p", name, (char *) 0, env);
|
|
|
|
syslog(LOG_ERR, "%s: %m", LO);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
alarm(0);
|
|
|
|
signal(SIGALRM, SIG_DFL);
|
1996-05-05 19:01:13 +00:00
|
|
|
signal(SIGINT, SIG_IGN);
|
1994-05-27 12:39:25 +00:00
|
|
|
if (NX && *NX)
|
|
|
|
tname = NX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
static int
|
|
|
|
opentty(const char *ttyn, int flags)
|
|
|
|
{
|
|
|
|
int i, j = 0;
|
|
|
|
int failopenlogged = 0;
|
|
|
|
|
|
|
|
while (j < 10 && (i = open(ttyn, flags)) == -1)
|
|
|
|
{
|
|
|
|
if (((j % 10) == 0) && (errno != ENXIO || !failopenlogged)) {
|
|
|
|
syslog(LOG_ERR, "open %s: %m", ttyn);
|
|
|
|
failopenlogged = 1;
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
sleep(60);
|
|
|
|
}
|
|
|
|
if (i == -1) {
|
|
|
|
syslog(LOG_ERR, "open %s: %m", ttyn);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
login_tty(i);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setdefttymode(tname)
|
|
|
|
const char * tname;
|
|
|
|
{
|
|
|
|
if (tcgetattr(STDIN_FILENO, &tmode) < 0) {
|
|
|
|
syslog(LOG_ERR, "tcgetattr %s: %m", ttyn);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
tmode.c_iflag = TTYDEF_IFLAG;
|
|
|
|
tmode.c_oflag = TTYDEF_OFLAG;
|
|
|
|
tmode.c_lflag = TTYDEF_LFLAG;
|
|
|
|
tmode.c_cflag = TTYDEF_CFLAG;
|
|
|
|
omode = tmode;
|
|
|
|
setttymode(tname, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setttymode(tname, raw)
|
|
|
|
const char * tname;
|
|
|
|
int raw;
|
|
|
|
{
|
|
|
|
int off = 0;
|
|
|
|
|
|
|
|
gettable(tname, tabent);
|
|
|
|
if (OPset || EPset || APset)
|
|
|
|
APset++, OPset++, EPset++;
|
|
|
|
setdefaults();
|
|
|
|
(void)tcflush(STDIN_FILENO, TCIOFLUSH); /* clear out the crap */
|
|
|
|
ioctl(STDIN_FILENO, FIONBIO, &off); /* turn off non-blocking mode */
|
|
|
|
ioctl(STDIN_FILENO, FIOASYNC, &off); /* ditto for async mode */
|
|
|
|
|
|
|
|
if (IS)
|
|
|
|
cfsetispeed(&tmode, speed(IS));
|
|
|
|
else if (SP)
|
|
|
|
cfsetispeed(&tmode, speed(SP));
|
|
|
|
if (OS)
|
|
|
|
cfsetospeed(&tmode, speed(OS));
|
|
|
|
else if (SP)
|
|
|
|
cfsetospeed(&tmode, speed(SP));
|
|
|
|
setflags(0);
|
|
|
|
setchars();
|
|
|
|
if (raw)
|
|
|
|
cfmakeraw(&tmode);
|
|
|
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) {
|
|
|
|
syslog(LOG_ERR, "tcsetattr %s: %m", ttyn);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static int
|
1994-05-27 12:39:25 +00:00
|
|
|
getname()
|
|
|
|
{
|
|
|
|
register int c;
|
|
|
|
register char *np;
|
1996-11-13 01:06:40 +00:00
|
|
|
unsigned char cs;
|
1997-02-02 14:24:57 +00:00
|
|
|
int ppp_state = 0;
|
1996-11-13 01:06:40 +00:00
|
|
|
int ppp_connection = 0;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt may happen if we use CBREAK mode
|
|
|
|
*/
|
|
|
|
if (setjmp(intrupt)) {
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
signal(SIGINT, interrupt);
|
1996-05-05 19:01:13 +00:00
|
|
|
setflags(1);
|
1994-05-27 12:39:25 +00:00
|
|
|
prompt();
|
1994-08-26 05:19:17 +00:00
|
|
|
oflush();
|
1994-05-27 12:39:25 +00:00
|
|
|
if (PF > 0) {
|
|
|
|
sleep(PF);
|
|
|
|
PF = 0;
|
|
|
|
}
|
1997-02-02 14:24:57 +00:00
|
|
|
if (tcsetattr(STDIN_FILENO, TCSANOW, &tmode) < 0) {
|
1996-05-05 19:01:13 +00:00
|
|
|
syslog(LOG_ERR, "%s: %m", ttyn);
|
|
|
|
exit(1);
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
crmod = digit = lower = upper = 0;
|
|
|
|
np = name;
|
|
|
|
for (;;) {
|
|
|
|
oflush();
|
|
|
|
if (read(STDIN_FILENO, &cs, 1) <= 0)
|
|
|
|
exit(0);
|
|
|
|
if ((c = cs&0177) == 0)
|
|
|
|
return (0);
|
1996-11-13 01:06:40 +00:00
|
|
|
|
|
|
|
/* PPP detection state machine..
|
|
|
|
Look for sequences:
|
|
|
|
PPP_FRAME, PPP_STATION, PPP_ESCAPE, PPP_CONTROL_ESCAPED or
|
|
|
|
PPP_FRAME, PPP_STATION, PPP_CONTROL (deviant from RFC)
|
|
|
|
See RFC1662.
|
|
|
|
Derived from code from Michael Hancock, <michaelh@cet.co.jp>
|
|
|
|
and Erik 'PPP' Olson, <eriko@wrq.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (PP && (cs == PPP_FRAME)) {
|
|
|
|
ppp_state = 1;
|
|
|
|
} else if (ppp_state == 1 && cs == PPP_STATION) {
|
|
|
|
ppp_state = 2;
|
|
|
|
} else if (ppp_state == 2 && cs == PPP_ESCAPE) {
|
|
|
|
ppp_state = 3;
|
|
|
|
} else if ((ppp_state == 2 && cs == PPP_CONTROL)
|
|
|
|
|| (ppp_state == 3 && cs == PPP_CONTROL_ESCAPED)) {
|
|
|
|
ppp_state = 4;
|
|
|
|
} else if (ppp_state == 4 && cs == PPP_LCP_HI) {
|
|
|
|
ppp_state = 5;
|
|
|
|
} else if (ppp_state == 5 && cs == PPP_LCP_LOW) {
|
|
|
|
ppp_connection = 1;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
ppp_state = 0;
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
if (c == EOT || c == CTRL('d'))
|
1994-05-27 12:39:25 +00:00
|
|
|
exit(1);
|
1997-02-02 14:43:32 +00:00
|
|
|
if (c == '\r' || c == '\n' || np >= &name[sizeof name-1]) {
|
1994-05-27 12:39:25 +00:00
|
|
|
putf("\r\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (islower(c))
|
|
|
|
lower = 1;
|
|
|
|
else if (isupper(c))
|
|
|
|
upper = 1;
|
1994-08-26 05:19:17 +00:00
|
|
|
else if (c == ERASE || c == '\b' || c == 0177) {
|
1994-05-27 12:39:25 +00:00
|
|
|
if (np > name) {
|
|
|
|
np--;
|
1996-05-05 19:01:13 +00:00
|
|
|
if (cfgetospeed(&tmode) >= 1200)
|
1994-05-27 12:39:25 +00:00
|
|
|
puts("\b \b");
|
|
|
|
else
|
|
|
|
putchr(cs);
|
|
|
|
}
|
|
|
|
continue;
|
1996-05-05 19:01:13 +00:00
|
|
|
} else if (c == KILL || c == CTRL('u')) {
|
1994-05-27 12:39:25 +00:00
|
|
|
putchr('\r');
|
1996-05-05 19:01:13 +00:00
|
|
|
if (cfgetospeed(&tmode) < 1200)
|
1994-05-27 12:39:25 +00:00
|
|
|
putchr('\n');
|
|
|
|
/* this is the way they do it down under ... */
|
|
|
|
else if (np > name)
|
|
|
|
puts(" \r");
|
|
|
|
prompt();
|
|
|
|
np = name;
|
|
|
|
continue;
|
|
|
|
} else if (isdigit(c))
|
|
|
|
digit++;
|
|
|
|
if (IG && (c <= ' ' || c > 0176))
|
|
|
|
continue;
|
|
|
|
*np++ = c;
|
|
|
|
putchr(cs);
|
|
|
|
}
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
*np = 0;
|
|
|
|
if (c == '\r')
|
|
|
|
crmod = 1;
|
1996-05-05 19:01:13 +00:00
|
|
|
if ((upper && !lower && !LC) || UC)
|
1994-05-27 12:39:25 +00:00
|
|
|
for (np = name; *np; np++)
|
|
|
|
if (isupper(*np))
|
|
|
|
*np = tolower(*np);
|
1996-11-13 01:06:40 +00:00
|
|
|
return (1 + ppp_connection);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void
|
1994-05-27 12:39:25 +00:00
|
|
|
putpad(s)
|
1996-05-05 19:01:13 +00:00
|
|
|
register const char *s;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
register pad = 0;
|
1996-05-05 19:01:13 +00:00
|
|
|
speed_t ospeed = cfgetospeed(&tmode);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
if (isdigit(*s)) {
|
|
|
|
while (isdigit(*s)) {
|
|
|
|
pad *= 10;
|
|
|
|
pad += *s++ - '0';
|
|
|
|
}
|
|
|
|
pad *= 10;
|
|
|
|
if (*s == '.' && isdigit(s[1])) {
|
|
|
|
pad += s[1] - '0';
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
puts(s);
|
|
|
|
/*
|
|
|
|
* If no delay needed, or output speed is
|
|
|
|
* not comprehensible, then don't try to delay.
|
|
|
|
*/
|
1996-05-05 19:01:13 +00:00
|
|
|
if (pad == 0 || ospeed <= 0)
|
1994-05-27 12:39:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Round up by a half a character frame, and then do the delay.
|
|
|
|
* Too bad there are no user program accessible programmed delays.
|
|
|
|
* Transmitting pad characters slows many terminals down and also
|
|
|
|
* loads the system.
|
|
|
|
*/
|
1996-05-05 19:01:13 +00:00
|
|
|
pad = (pad * ospeed + 50000) / 100000;
|
|
|
|
while (pad--)
|
1994-05-27 12:39:25 +00:00
|
|
|
putchr(*PC);
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void
|
1994-05-27 12:39:25 +00:00
|
|
|
puts(s)
|
1996-05-05 19:01:13 +00:00
|
|
|
register const char *s;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
while (*s)
|
|
|
|
putchr(*s++);
|
|
|
|
}
|
|
|
|
|
|
|
|
char outbuf[OBUFSIZ];
|
|
|
|
int obufcnt = 0;
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void
|
1994-05-27 12:39:25 +00:00
|
|
|
putchr(cc)
|
1996-05-05 19:01:13 +00:00
|
|
|
int cc;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
c = cc;
|
|
|
|
if (!NP) {
|
|
|
|
c |= partab[c&0177] & 0200;
|
|
|
|
if (OP)
|
|
|
|
c ^= 0200;
|
|
|
|
}
|
|
|
|
if (!UB) {
|
|
|
|
outbuf[obufcnt++] = c;
|
|
|
|
if (obufcnt >= OBUFSIZ)
|
|
|
|
oflush();
|
|
|
|
} else
|
|
|
|
write(STDOUT_FILENO, &c, 1);
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void
|
1994-05-27 12:39:25 +00:00
|
|
|
oflush()
|
|
|
|
{
|
|
|
|
if (obufcnt)
|
|
|
|
write(STDOUT_FILENO, outbuf, obufcnt);
|
|
|
|
obufcnt = 0;
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void
|
1994-05-27 12:39:25 +00:00
|
|
|
prompt()
|
|
|
|
{
|
|
|
|
|
|
|
|
putf(LM);
|
|
|
|
if (CO)
|
|
|
|
putchr('\n');
|
|
|
|
}
|
|
|
|
|
1997-02-02 14:24:57 +00:00
|
|
|
|
|
|
|
static char *
|
|
|
|
getline(fd)
|
|
|
|
int fd;
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
static char linebuf[512];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is certainly slow, but it avoids having to include
|
|
|
|
* stdio.h unnecessarily. Issue files should be small anyway.
|
|
|
|
*/
|
|
|
|
while (i < (sizeof linebuf - 3) && read(fd, linebuf+i, 1)==1) {
|
|
|
|
if (linebuf[i] == '\n') {
|
|
|
|
/* Don't rely on newline mode, assume raw */
|
|
|
|
linebuf[i++] = '\r';
|
|
|
|
linebuf[i++] = '\n';
|
|
|
|
linebuf[i] = '\0';
|
|
|
|
return linebuf;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
linebuf[i] = '\0';
|
|
|
|
return i ? linebuf : 0;
|
|
|
|
}
|
|
|
|
|
1996-05-05 19:01:13 +00:00
|
|
|
static void
|
1994-05-27 12:39:25 +00:00
|
|
|
putf(cp)
|
1996-05-05 19:01:13 +00:00
|
|
|
register const char *cp;
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
extern char editedhost[];
|
|
|
|
time_t t;
|
|
|
|
char *slash, db[100];
|
|
|
|
|
1997-02-02 07:38:26 +00:00
|
|
|
static struct utsname kerninfo;
|
|
|
|
|
|
|
|
if (!*kerninfo.sysname)
|
|
|
|
uname(&kerninfo);
|
|
|
|
|
1994-05-27 12:39:25 +00:00
|
|
|
while (*cp) {
|
|
|
|
if (*cp != '%') {
|
|
|
|
putchr(*cp++);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (*++cp) {
|
|
|
|
|
|
|
|
case 't':
|
1996-05-05 19:01:13 +00:00
|
|
|
slash = strrchr(ttyn, '/');
|
1994-05-27 12:39:25 +00:00
|
|
|
if (slash == (char *) 0)
|
|
|
|
puts(ttyn);
|
|
|
|
else
|
|
|
|
puts(&slash[1]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
puts(editedhost);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': {
|
1996-05-05 19:01:13 +00:00
|
|
|
t = (time_t)0;
|
1994-05-27 12:39:25 +00:00
|
|
|
(void)time(&t);
|
1996-05-05 19:01:13 +00:00
|
|
|
if (Lo)
|
|
|
|
(void)setlocale(LC_TIME, Lo);
|
|
|
|
(void)strftime(db, sizeof(db), "%+", localtime(&t));
|
1994-05-27 12:39:25 +00:00
|
|
|
puts(db);
|
1995-08-03 05:44:46 +00:00
|
|
|
break;
|
1996-05-05 19:01:13 +00:00
|
|
|
|
|
|
|
case 's':
|
|
|
|
puts(kerninfo.sysname);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
puts(kerninfo.machine);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
puts(kerninfo.release);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
puts(kerninfo.version);
|
|
|
|
break;
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
putchr('%');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
}
|