Replace this with the 1.1.5.1 getty. David says that the 4.4 version is too

broken to live.
Submitted by:	jkh
This commit is contained in:
Jordan K. Hubbard 1994-08-26 05:19:17 +00:00
parent ee307ac8ce
commit fef0aded64
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=2286
9 changed files with 164 additions and 239 deletions

View File

@ -1,7 +1,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# @(#)Makefile 5.12 (Berkeley) 1/21/91
PROG= getty
SRCS= main.c init.c subr.c ttydefaults.c fbtab_stuff.c
SRCS= main.c init.c subr.c gettytab.c
DPADD= ${LIBUTIL}
LDADD= -lutil
MAN5= gettytab.5 ttys.5

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\" Copyright (c) 1980, 1991 Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)getty.8 8.1 (Berkeley) 6/4/93
.\" @(#)getty.8 6.6 (Berkeley) 4/25/91
.\"
.Dd June 4, 1993
.Dd April 25, 1991
.Dt GETTY 8
.Os BSD 4
.Sh NAME
@ -61,13 +61,6 @@ If there is no argument or the argument is
.Ql Fl ,
the tty line is assumed to be open as file descriptor 0.
.Pp
If the argument
.Ar tty
matches the first entry in one of the lines in
.Pa /etc/fbtab
the userid and groupid of the device list on that line is reset to root and
wheel respectively.
.Pp
The
.Ar type
argument can be used to make
@ -118,11 +111,9 @@ does not exist.
.El
.Sh FILES
.Bl -tag -width /etc/gettytab -compact
.It Pa /etc/fbtab
.It Pa /etc/gettytab
.El
.Sh SEE ALSO
.Xr fbtab 5 ,
.Xr gettytab 5 ,
.Xr init 8 ,
.Xr login 1 ,

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)gettytab.5 8.4 (Berkeley) 4/19/94
.\" @(#)gettytab.5 6.7 (Berkeley) 5/10/91
.\"
.Dd April 19, 1994
.Dd May 10, 1991
.Dt GETTYTAB 5
.Os BSD 4.2
.Sh NAME
@ -131,7 +131,6 @@ hangup line on last close
.No "program to exec when name obtained"
.It "nd num 0 newline (line-feed) delay"
.It "nl bool false terminal has (or might have) a newline character"
.It "np bool false terminal uses no parity (i.e. 8-bit characters)"
.It "nx str default next table (for auto speed selection)"
.It "op bool false terminal uses odd parity"
.It "os num unused output speed"

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1993, 1994
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1983 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)gettytab.h 8.2 (Berkeley) 3/30/94
* @(#)gettytab.h 5.5 (Berkeley) 3/27/91
*/
/*
@ -134,10 +134,10 @@ struct gettyflags {
#define DX gettyflags[20].value
#define NP gettyflags[21].value
int getent __P((char *, char *));
long getnum __P((char *));
int getflag __P((char *));
char *getstr __P((char *, char **));
int getent();
long getnum();
int getflag();
char *getstr();
extern struct gettyflags gettyflags[];
extern struct gettynums gettynums[];

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1983 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,7 +32,7 @@
*/
#ifndef lint
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 6/4/93";
static char sccsid[] = "@(#)init.c 5.6 (Berkeley) 3/27/91";
#endif /* not lint */
/*

View File

@ -1,6 +1,6 @@
/*-
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1980 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -32,42 +32,32 @@
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
char copyright[] =
"@(#) Copyright (c) 1980 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/20/93";
static char sccsid[] = "@(#)main.c 5.16 (Berkeley) 3/27/91";
#endif /* not lint */
#define USE_OLD_TTY
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/resource.h>
#include <ctype.h>
#include <ctype.h>
#include <fcntl.h>
#include <setjmp.h>
#include <sgtty.h>
#include <signal.h>
#include <fcntl.h>
#include <sgtty.h>
#include <time.h>
#include <ctype.h>
#include <setjmp.h>
#include <syslog.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "gettytab.h"
#include "pathnames.h"
#include "extern.h"
/*
* Set the amount of running time that getty should accumulate
* before deciding that something is wrong and exit.
*/
#define GETTY_TIMEOUT 60 /* seconds */
struct sgttyb tmode = {
0, 0, CERASE, CKILL, 0
@ -94,7 +84,9 @@ char *ttyname();
#define TABBUFSIZ 512
char defent[TABBUFSIZ];
char defstrs[TABBUFSIZ];
char tabent[TABBUFSIZ];
char tabstrs[TABBUFSIZ];
char *env[128];
@ -142,54 +134,21 @@ interrupt()
longjmp(intrupt, 1);
}
/*
* Action to take when getty is running too long.
*/
void
timeoverrun(signo)
int signo;
{
syslog(LOG_ERR, "getty exiting due to excessive running time\n");
exit(1);
}
static int getname __P((void));
static void oflush __P((void));
static void prompt __P((void));
static void putchr __P((int));
static void putf __P((char *));
static void putpad __P((char *));
static void puts __P((char *));
extern void reset_fbtab __P((char *));
int
main(argc, argv)
int argc;
char *argv[];
char **argv;
{
extern char **environ;
extern char **environ;
char *tname;
long allflags;
int repcnt = 0;
struct rlimit limit;
signal(SIGINT, SIG_IGN);
/*
signal(SIGQUIT, SIG_DFL);
*/
openlog("getty", LOG_ODELAY|LOG_CONS, LOG_AUTH);
gethostname(hostname, sizeof(hostname));
if (hostname[0] == '\0')
strcpy(hostname, "Amnesiac");
/*
* 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);
/*
* The following is a work around for vhangup interactions
* which cause great problems getting window systems started.
@ -208,10 +167,6 @@ main(argc, argv)
chown(ttyn, 0, 0);
chmod(ttyn, 0600);
revoke(ttyn);
/*
* Delay the open so DTR stays down long enough to be detected.
*/
sleep(2);
while ((i = open(ttyn, O_RDWR)) == -1) {
if (repcnt % 10 == 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
@ -224,25 +179,24 @@ main(argc, argv)
}
}
/* Read the FBTAB file and check if we have to reset perms/ownership */
reset_fbtab(ttyn);
gettable("default", defent);
gettable("default", defent, defstrs);
gendefaults();
tname = "default";
if (argc > 1)
tname = argv[1];
for (;;) {
int off;
int off = 0;
int flushboth = 0;
struct sgttyb fake;
gettable(tname, tabent);
gettable(tname, tabent, tabstrs);
if (OPset || EPset || APset)
APset++, OPset++, EPset++;
setdefaults();
off = 0;
ioctl(0, TIOCFLUSH, &off); /* clear out the crap */
ioctl(0, TIOCFLUSH, &flushboth); /* clear out the crap */
ioctl(0, FIONBIO, &off); /* turn off non-blocking mode */
ioctl(0, FIOASYNC, &off); /* ditto for async mode */
ioctl(0, TIOCGETP, &fake); /* initialize kernel termios */
if (IS)
tmode.sg_ispeed = speed(IS);
else if (SP)
@ -251,8 +205,7 @@ main(argc, argv)
tmode.sg_ospeed = speed(OS);
else if (SP)
tmode.sg_ospeed = speed(SP);
tmode.sg_flags = setflags(0);
ioctl(0, TIOCSETP, &tmode);
set_tmode(0);
setchars();
ioctl(0, TIOCSETC, &tc);
if (HC)
@ -284,58 +237,39 @@ main(argc, argv)
if (getname()) {
register int i;
oflush();
alarm(0);
signal(SIGALRM, SIG_DFL);
oflush();
if (name[0] == '-') {
puts("user names may not start with '-'.");
continue;
}
if (!(upper || lower || digit))
continue;
allflags = setflags(2);
tmode.sg_flags = allflags & 0xffff;
allflags >>= 16;
if (crmod || NL)
tmode.sg_flags |= CRMOD;
if (upper || UC)
tmode.sg_flags |= LCASE;
if (lower || LC)
tmode.sg_flags &= ~LCASE;
ioctl(0, TIOCSETP, &tmode);
set_tmode(2);
ioctl(0, TIOCSLTC, &ltc);
ioctl(0, TIOCLSET, &allflags);
signal(SIGINT, SIG_DFL);
for (i = 0; environ[i] != (char *)0; i++)
env[i] = environ[i];
makeenv(&env[i]);
/*
* this is what login was doing anyway.
* soon we rewrite getty completely.
*/
set_ttydefaults(0);
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = RLIM_INFINITY;
(void)setrlimit(RLIMIT_CPU, &limit);
execle(LO, "login", "-p", name, (char *) 0, env);
syslog(LOG_ERR, "%s: %m", LO);
exit(1);
}
signal(SIGINT, SIG_IGN);
alarm(0);
signal(SIGALRM, SIG_DFL);
signal(SIGINT, SIG_IGN);
if (NX && *NX)
tname = NX;
}
}
static int
getname()
{
register int c;
register char *np;
char cs;
int flushin = 1 /*FREAD*/;
/*
* Interrupt may happen if we use CBREAK mode
@ -345,16 +279,14 @@ getname()
return (0);
}
signal(SIGINT, interrupt);
tmode.sg_flags = setflags(0);
ioctl(0, TIOCSETP, &tmode);
tmode.sg_flags = setflags(1);
ioctl(0, TIOCFLUSH, &flushin); /* purge any input */
prompt();
oflush();
if (PF > 0) {
oflush();
sleep(PF);
PF = 0;
}
ioctl(0, TIOCSETP, &tmode);
set_tmode(1);
crmod = digit = lower = upper = 0;
np = name;
for (;;) {
@ -363,7 +295,7 @@ getname()
exit(0);
if ((c = cs&0177) == 0)
return (0);
if (c == EOT)
if (c == EOT || c == 4 /*^D*/)
exit(1);
if (c == '\r' || c == '\n' || np >= &name[sizeof name]) {
putf("\r\n");
@ -373,7 +305,7 @@ getname()
lower = 1;
else if (isupper(c))
upper = 1;
else if (c == ERASE || c == '#' || c == '\b') {
else if (c == ERASE || c == '\b' || c == 0177) {
if (np > name) {
np--;
if (tmode.sg_ospeed >= B1200)
@ -382,8 +314,7 @@ getname()
putchr(cs);
}
continue;
} else if (c == KILL || c == '@') {
putchr(cs);
} else if (c == KILL || c == 025 /*^U*/) {
putchr('\r');
if (tmode.sg_ospeed < B1200)
putchr('\n');
@ -416,7 +347,6 @@ short tmspc10[] = {
0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 15
};
static void
putpad(s)
register char *s;
{
@ -458,7 +388,6 @@ putpad(s)
putchr(*PC);
}
static void
puts(s)
register char *s;
{
@ -469,9 +398,7 @@ puts(s)
char outbuf[OBUFSIZ];
int obufcnt = 0;
static void
putchr(cc)
int cc;
{
char c;
@ -489,7 +416,6 @@ putchr(cc)
write(STDOUT_FILENO, &c, 1);
}
static void
oflush()
{
if (obufcnt)
@ -497,7 +423,6 @@ oflush()
obufcnt = 0;
}
static void
prompt()
{
@ -506,7 +431,6 @@ prompt()
putchr('\n');
}
static void
putf(cp)
register char *cp;
{
@ -522,7 +446,7 @@ putf(cp)
switch (*++cp) {
case 't':
slash = strrchr(ttyn, '/');
slash = rindex(ttyn, '/');
if (slash == (char *) 0)
puts(ttyn);
else
@ -550,3 +474,29 @@ putf(cp)
cp++;
}
}
/*
* The conversions from sgttyb to termios make LITOUT and PASS8 affect
* the parity. So every TIOCSETP ioctl has to be paired with a TIOCLSET
* ioctl (at least if LITOUT or PASS8 has changed, and PASS8 may vary
* with 'n').
*/
set_tmode(n)
int n;
{
long allflags;
allflags = setflags(n);
tmode.sg_flags = allflags & 0xffff;
allflags >>= 16;
if (n == 2) {
if (crmod || NL)
tmode.sg_flags |= CRMOD;
if (upper || UC)
tmode.sg_flags |= LCASE;
if (lower || LC)
tmode.sg_flags &= ~LCASE;
}
ioctl(0, TIOCSETP, &tmode);
ioctl(0, TIOCLSET, &allflags);
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,12 +30,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)pathnames.h 8.1 (Berkeley) 6/4/93
* @(#)pathnames.h 5.3 (Berkeley) 6/1/90
*/
#include <paths.h>
#define _PATH_GETTYTAB "/etc/gettytab"
#define _PATH_LOGIN "/usr/bin/login"
#define _PATH_FBTAB "/etc/fbtab"
#define _PATH_LOGINDEVPERM "/etc/logindevperm"
#define _PATH_GETTYTAB "/etc/gettytab"
#define _PATH_LOGIN "/usr/bin/login"

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
* Copyright (c) 1983 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -29,24 +29,28 @@
* 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.
*
* PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
* -------------------- ----- ----------------------
* CURRENT PATCH LEVEL: 1 00150
* -------------------- ----- ----------------------
*
* 22 Apr 93 Rodney W. Grimes support for 57600 and 115200 baud
*
*/
#ifndef lint
static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/4/93";
static char sccsid[] = "@(#)subr.c 5.10 (Berkeley) 2/26/91";
#endif /* not lint */
/*
* Melbourne getty.
*/
#define USE_OLD_TTY
#include <stdlib.h>
#include <sgtty.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include "gettytab.h"
#include "extern.h"
#include "pathnames.h"
extern struct sgttyb tmode;
extern struct tchars tc;
@ -55,25 +59,23 @@ extern struct ltchars ltc;
/*
* Get a table entry.
*/
void
gettable(name, buf)
char *name, *buf;
gettable(name, buf, area)
char *name, *buf, *area;
{
register struct gettystrs *sp;
register struct gettynums *np;
register struct gettyflags *fp;
long n;
char *dba[2];
dba[0] = _PATH_GETTYTAB;
dba[1] = 0;
register n;
if (cgetent(&buf, dba, name) != 0)
hopcount = 0; /* new lookup, start fresh */
if (getent(buf, name) != 1)
return;
for (sp = gettystrs; sp->field; sp++)
cgetstr(buf, sp->field, &sp->value);
for (sp = gettystrs; sp->field; sp++)
sp->value = getstr(sp->field, &area);
for (np = gettynums; np->field; np++) {
if (cgetnum(buf, np->field, &n) == -1)
n = getnum(np->field);
if (n == -1)
np->set = 0;
else {
np->set = 1;
@ -81,27 +83,16 @@ gettable(name, buf)
}
}
for (fp = gettyflags; fp->field; fp++) {
if (cgetcap(buf, fp->field, ':') == NULL)
n = getflag(fp->field);
if (n == -1)
fp->set = 0;
else {
fp->set = 1;
fp->value = 1 ^ fp->invrt;
fp->value = n ^ fp->invrt;
}
}
#ifdef DEBUG
printf("name=\"%s\", buf=\"%s\"\n", name, buf);
for (sp = gettystrs; sp->field; sp++)
printf("cgetstr: %s=%s\n", sp->field, sp->value);
for (np = gettynums; np->field; np++)
printf("cgetnum: %s=%d\n", np->field, np->value);
for (fp = gettyflags; fp->field; fp++)
printf("cgetflags: %s='%c' set='%c'\n", fp->field,
fp->value + '0', fp->set + '0');
exit(1);
#endif /* DEBUG */
}
void
gendefaults()
{
register struct gettystrs *sp;
@ -121,7 +112,6 @@ gendefaults()
fp->defalt = fp->invrt;
}
void
setdefaults()
{
register struct gettystrs *sp;
@ -154,7 +144,6 @@ charvars[] = {
&ltc.t_werasc, &ltc.t_lnextc, 0
};
void
setchars()
{
register int i;
@ -171,7 +160,6 @@ setchars()
long
setflags(n)
int n;
{
register long f;
@ -198,6 +186,8 @@ setflags(n)
f |= ODDP;
else if (EP)
f |= EVENP;
if (NP)
f |= PASS8;
if (UC)
f |= LCASE;
@ -255,45 +245,44 @@ struct delayval {
*/
struct delayval crdelay[] = {
{ 1, CR1 },
{ 2, CR2 },
{ 3, CR3 },
{ 83, CR1 },
{ 166, CR2 },
{ 0, CR3 },
1, CR1,
2, CR2,
3, CR3,
83, CR1,
166, CR2,
0, CR3,
};
struct delayval nldelay[] = {
{ 1, NL1 }, /* special, calculated */
{ 2, NL2 },
{ 3, NL3 },
{ 100, NL2 },
{ 0, NL3 },
1, NL1, /* special, calculated */
2, NL2,
3, NL3,
100, NL2,
0, NL3,
};
struct delayval bsdelay[] = {
{ 1, BS1 },
{ 0, 0 },
1, BS1,
0, 0,
};
struct delayval ffdelay[] = {
{ 1, FF1 },
{ 1750, FF1 },
{ 0, FF1 },
1, FF1,
1750, FF1,
0, FF1,
};
struct delayval tbdelay[] = {
{ 1, TAB1 },
{ 2, TAB2 },
{ 3, XTABS }, /* this is expand tabs */
{ 100, TAB1 },
{ 0, TAB2 },
1, TAB1,
2, TAB2,
3, XTABS, /* this is expand tabs */
100, TAB1,
0, TAB2,
};
int
delaybits()
{
register int f;
register f;
f = adelay(CD, crdelay);
f |= adelay(ND, nldelay);
@ -303,7 +292,6 @@ delaybits()
return (f);
}
int
adelay(ms, dp)
register ms;
register struct delayval *dp;
@ -317,7 +305,6 @@ adelay(ms, dp)
char editedhost[32];
void
edithost(pat)
register char *pat;
{
@ -361,30 +348,30 @@ struct speedtab {
int speed;
int uxname;
} speedtab[] = {
{ 50, B50 },
{ 75, B75 },
{ 110, B110 },
{ 134, B134 },
{ 150, B150 },
{ 200, B200 },
{ 300, B300 },
{ 600, B600 },
{ 1200, B1200 },
{ 1800, B1800 },
{ 2400, B2400 },
{ 4800, B4800 },
{ 9600, B9600 },
{ 19200, EXTA },
{ 19, EXTA }, /* for people who say 19.2K */
{ 38400, EXTB },
{ 38, EXTB },
{ 7200, EXTB }, /* alternative */
{ 0 }
50, B50,
75, B75,
110, B110,
134, B134,
150, B150,
200, B200,
300, B300,
600, B600,
1200, B1200,
1800, B1800,
2400, B2400,
4800, B4800,
9600, B9600,
19200, EXTA,
19, EXTA, /* for people who say 19.2K */
38400, EXTB,
38, EXTB,
7200, EXTB, /* alternative */
57600, B57600,
115200, B115200,
0
};
int
speed(val)
int val;
{
register struct speedtab *sp;
@ -398,13 +385,13 @@ speed(val)
return (B300); /* default in impossible cases */
}
void
makeenv(env)
char *env[];
{
static char termbuf[128] = "TERM=";
register char *p, *q;
register char **ep;
char *index();
ep = env;
if (TT && *TT) {
@ -413,7 +400,7 @@ makeenv(env)
}
if (p = EV) {
q = p;
while (q = strchr(q, ',')) {
while (q = index(q, ',')) {
*q++ = '\0';
*ep++ = p;
p = q;

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1985, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\" Copyright (c) 1985, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)ttys.5 8.1 (Berkeley) 6/4/93
.\" @(#)ttys.5 6.8 (Berkeley) 5/4/91
.\"
.Dd June 4, 1993
.Dd May 4, 1991
.Dt TTYS 5
.Os
.Sh NAME