big <utmp.h>-inspired netbsd switch

import/switch of:
init, getty, reboot, halt, shutdown, wall, last

changes:
	. change reboot() call to netbsd prototype and args
	. allows pristine <utmp.h>
	. use clean <sys/reboot.h> instead of <minix/reboot.h>
	. implement TIOCSCTTY for use by getty so getty can get
	  controlling terminal from init's child(ren)
	. allow NULL envp for exec

Change-Id: I5ca02cb4230857140c08794bbfeba7df982c58a3
This commit is contained in:
Ben Gras
2013-09-09 13:20:18 +00:00
committed by Lionel Sambuc
parent fa06ff0ee3
commit a06e2ab395
93 changed files with 8096 additions and 2465 deletions

View File

@@ -5,7 +5,8 @@
SUBDIR= \
fingerd ftpd \
ld.elf_so
ld.elf_so \
getty
.if defined(__MINIX)
SUBDIR+= makewhatis

12
libexec/getty/Makefile Normal file
View File

@@ -0,0 +1,12 @@
# $NetBSD: Makefile,v 1.19 2010/02/03 15:34:43 roy Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/4/93
WARNS?= 2 # XXX: many const & sign-compare issues
PROG= getty
SRCS= main.c init.c subr.c
DPADD+= ${LIBUTIL} ${LIBTERMINFO}
LDADD+= -lutil -lterminfo
MAN= getty.8 gettytab.5 ttys.5
.include <bsd.prog.mk>

52
libexec/getty/extern.h Normal file
View File

@@ -0,0 +1,52 @@
/* $NetBSD: extern.h,v 1.6 2003/08/07 09:46:41 agc Exp $ */
/*
* Copyright (c) 1993
* 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
* 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. 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.
*
* from: @(#)extern.h 8.1 (Berkeley) 6/4/93
*/
struct delayval;
int adelay(int, struct delayval *);
char *autobaud(void);
int delaybits(void);
void edithost(char *);
void gendefaults(void);
int getent(char *, char *);
int getflag(char *);
long getnum(char *);
char *getstr(char *, char **);
void gettable(char *, char *);
void makeenv(char *[]);
char *portselector(void);
void set_ttydefaults(int);
void setchars(void);
void setdefaults(void);
void setflags(int);
int speed(int);

177
libexec/getty/getty.8 Normal file
View File

@@ -0,0 +1,177 @@
.\" $NetBSD: getty.8,v 1.17 2003/08/07 09:46:42 agc Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" 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
.\" 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. 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.
.\"
.\" from: @(#)getty.8 8.1 (Berkeley) 6/4/93
.\"
.Dd December 12, 1998
.Dt GETTY 8
.Os
.Sh NAME
.Nm getty ,
.Nm uugetty
.Nd set terminal modes for system access
.Sh SYNOPSIS
.Nm
.Oo
.Ar type
.Op Ar tty
.Oc
.Nm uugetty
.Oo
.Ar type
.Op Ar tty
.Oc
.Sh DESCRIPTION
The
.Nm
program
is called by
.Xr init 8
to open and initialize the tty line, read a login name, and invoke
.Xr login 1 .
The devices on which to run
.Nm
are normally determined by
.Xr ttys 5 .
.Pp
The
.Nm
program can also recognize a Point to Point Protocol
.Pq Tn PPP
negotiation, and, if the
.Sy pp
attribute in
.Xr gettytab 5
is set, invoke the program given by that string, e.g.,
.Xr pppd 8 ,
instead of
.Xr login 1 .
This makes it possible to use a single serial port for either a
.Qq shell
account with command line interface, or a
.Tn PPP
network link.
.Pp
The argument
.Ar tty
is the special device file in
.Pa /dev
to open for the terminal
.Po
for example,
.Qq ttyh0
.Pc .
If there is no argument or the argument is
.Ql Fl ,
the tty line is assumed to be open as file descriptor 0.
.Pp
The
.Ar type
argument can be used to make
.Nm
treat the terminal line specially.
This argument is used as an index into the
.Xr gettytab 5
database, to determine the characteristics of the line.
If there is no argument, or there is no such table, the
.Em default
table is used.
If there is no
.Pa /etc/gettytab
a set of system defaults is used.
If indicated by the table located,
.Nm
will clear the terminal screen,
print a banner heading,
and prompt for a login name.
Usually either the banner or the login prompt will include
the system hostname.
.Pp
.Nm
uses the
.Xr ttyaction 3
facility with an action of
.Qq getty
and user
.Qq root
to execute site-specific commands when it starts.
.Pp
Most of the default actions of
.Nm
can be circumvented, or modified, by a suitable
.Xr gettytab 5
table.
.Pp
The
.Nm
program can be set to timeout after some interval,
which will cause dial up lines to hang up
if the login name is not entered reasonably quickly.
.Pp
The
.Nm uugetty
program is the same, except that it uses
.Xr pidlock 3
to respect the locks in
.Pa /var/spool/lock
of processes that dial out on that tty.
.Sh FILES
.Bl -tag -width /var/spool/lock/LCK..ttyXX -compact
.It Pa /etc/gettytab
.It Pa /etc/ttys
.It Pa /var/spool/lock/LCK..ttyXX
.El
.Sh DIAGNOSTICS
.Bl -diag
.It "ttyxx: No such device or address."
.It "ttyxx: No such file or address."
A terminal which is turned on in the
.Xr ttys 5
file cannot be opened, likely because the requisite
lines are either not configured into the system, the associated device
was not attached during boot-time system configuration,
or the special file in
.Pa /dev
does not exist.
.El
.Sh SEE ALSO
.Xr login 1 ,
.Xr ioctl 2 ,
.Xr pidlock 3 ,
.Xr ttyaction 3 ,
.Xr tty 4 ,
.Xr gettytab 5 ,
.Xr ttys 5 ,
.Xr init 8 ,
.Xr pppd 8
.Sh HISTORY
A
.Nm
program appeared in
.At v6 .

423
libexec/getty/gettytab.5 Normal file
View File

@@ -0,0 +1,423 @@
.\" $NetBSD: gettytab.5,v 1.36 2012/04/21 12:27:28 roy Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" 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
.\" 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. 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.
.\"
.\" from: @(#)gettytab.5 8.4 (Berkeley) 4/19/94
.\"
.Dd April 5, 2012
.Dt GETTYTAB 5
.Os
.Sh NAME
.Nm gettytab
.Nd terminal configuration data base
.Sh SYNOPSIS
.Nm
.Sh DESCRIPTION
The
.Nm
file
is a simplified version of the
.Xr capfile 5
data base
used to describe terminal lines.
The initial terminal login process
.Xr getty 8
accesses the
.Nm
file each time it starts, allowing simpler
reconfiguration of terminal characteristics.
Each entry in the data base
is used to describe one class of terminals.
.Pp
Where to run
.Xr getty 8
processes is normally defined by
.Xr ttys 5 .
.Pp
There is a default terminal class,
.Em default ,
that is used to set global defaults for all other classes.
(That is, the
.Em default
entry is read, then the entry for the class required
is used to override particular settings.)
The
.Em default
entry is also normally read by other programs that present login prompts
to the user, such as
.Xr telnetd 8 ,
in order to retrieve the values of the
.Em he ,
.Em hn ,
.Em im ,
and
.Em if
capabilities.
.Sh CAPABILITIES
Refer to
.Xr capfile 5
for a description of the file layout.
The
.Em default
column below lists defaults obtained if there is
no entry in the table obtained, nor one in the special
.Em default
table.
.Bl -column Namexx /usr/bin/login Default
.It Sy Name Type Default Description
.It "ab bool false Auto-baud speed select mechanism for the Micom 600 portselector. Selection is done by looking at how the character `\er' is garbled at 300, 1200, 4800, and 9600 baud."
.It "al str NULL user to auto-login instead of prompting"
.It "ap bool false terminal uses any parity"
.It "bk str 0377 alternative end of line character (input break)"
.It "b2 str 0377 alternative end of line character (input break)"
.It "c0 num unused tty control flags to write messages"
.It "c1 num unused tty control flags to read login name"
.It "c2 num unused tty control flags to leave terminal as"
.It "ce bool false use crt erase algorithm"
.It "ck bool false use crt kill algorithm"
.It "cl str" Ta Dv NULL Ta
.No "screen clear sequence"
.It "co bool false console - add"
.Ql \er\en
after login prompt
.It "cs bool false clear screen based on terminal type in /etc/ttys"
.It "ds str" Ta So Li ^Y Sc Ta
.No "delayed suspend character"
.It "dx bool false set"
.Dv DECCTLQ
.It "ec bool false leave echo"
.Tn OFF
.It "ep bool false terminal uses even parity"
.It "er str" Ta So Li ^? Sc Ta
.No "erase character"
.It "et str" Ta So Li ^D Sc Ta
.No "end of text"
.Pq Dv EOF
character
.It "ev str" Ta Dv NULL Ta
.No "initial environment"
.It "f0 num unused tty mode flags to write messages"
.It "f1 num unused tty mode flags to read login name"
.It "f2 num unused tty mode flags to leave terminal as"
.It "fl str" Ta So Li ^O Sc Ta
.No "output flush character"
.It "hc bool false do"
.Tn NOT
hangup line on last close
.It "he str" Ta Dv NULL Ta
.No "hostname editing string"
.It "hn str hostname hostname"
.It "ht bool false terminal has real tabs"
.It "i0 num unused tty input flags to write messages"
.It "i1 num unused tty input flags to read login name"
.It "i2 num unused tty input flags to leave terminal as"
.It "if str NULL display named file before prompt, like /etc/issue"
.It "ig bool false ignore garbage characters in login name"
.It "im str" Ta Dv NULL Ta
.No "initial (banner) message"
.It "in str" Ta So Li ^C Sc Ta
.No "interrupt character"
.It "is num unused input speed"
.It "kl str" Ta So Li ^U Sc Ta
.No "kill character"
.It "l0 num unused tty local flags to write messages"
.It "l1 num unused tty local flags to read login name"
.It "l2 num unused tty local flags to leave terminal as"
.It "lc bool false terminal has lower case"
.It "lm str login: login prompt"
.It "ln str" Ta So Li ^V Sc Ta
.No "``literal next'' character"
.It "lo str" Ta Pa /usr/bin/login Ta
.No "program to exec when name obtained"
.It "mb bool false do flow control based on carrier"
.It "nl bool false terminal has (or might have) a newline character"
.It "nn bool false do not prompt for a login name"
.It "np bool false terminal uses no parity (i.e. 8-bit characters)"
.It "nx str default next table (for auto speed selection)"
.It "o0 num unused tty output flags to write messages"
.It "o1 num unused tty output flags to read login name"
.It "o2 num unused tty output flags to leave terminal as"
.It "op bool false terminal uses odd parity"
.It "os num unused output speed"
.It "pc str" Ta So Li \e0 Sc Ta
.No "pad character"
.It "pe bool false use printer (hard copy) erase algorithm"
.It "pf num 0 delay"
between first prompt and following flush (seconds)
.It "pp str unused PPP authentication program"
.It "ps bool false line connected to a"
.Tn MICOM
port selector
.It "qu str" Ta So Li \&^\e Sc Ta
.No "quit character"
.It "rp str" Ta So Li ^R Sc Ta
.No "line retype character"
.It "rw bool false do"
.Tn NOT
use raw for input, use cbreak
.It "sp num unused line speed (input and output)"
.It "st str" Ta So Li ^T Sc Ta
.No "status character"
.It "su str" Ta So Li ^Z Sc Ta
.No "suspend character"
.It "tc str none table continuation"
.It "to num 0 timeout (seconds)"
.It "tt str" Ta Dv NULL Ta
.No "terminal type (for environment)"
.It "ub bool false do unbuffered output (of prompts etc)"
.It "we str" Ta So Li ^W Sc Ta
.No "word erase character"
.It "xc bool false do"
.Tn NOT
echo control chars as
.Ql ^X
.It "xf str" Ta So Li ^S Sc Ta Dv XOFF
(stop output) character
.It "xn str" Ta So Li ^Q Sc Ta Dv XON
(start output) character
.El
.Pp
The following capabilities are no longer supported by
.Xr getty 8 :
.Bl -column Namexx /usr/bin/login Default
.It "bd num 0 backspace delay"
.It "cb bool false use crt backspace mode"
.It "cd num 0 carriage-return delay"
.It "fd num 0 form-feed (vertical motion) delay"
.It "nd num 0 newline (line-feed) delay"
.It "uc bool false terminal is known upper case only"
.El
.Pp
If no line speed is specified, speed will not be altered
from that which prevails when getty is entered.
Specifying an input or output speed will override
line speed for stated direction only.
.Pp
Terminal modes to be used for the output of the message,
for input of the login name,
and to leave the terminal set as upon completion,
are derived from the boolean flags specified.
If the derivation should prove inadequate,
any (or all) of these three may be overridden
with one of the
.Em \&c0 ,
.Em \&c1 ,
.Em \&c2 ,
.Em \&i0 ,
.Em \&i1 ,
.Em \&i2 ,
.Em \&l0 ,
.Em \&l1 ,
.Em \&l2 ,
.Em \&o0 ,
.Em \&o1 ,
or
.Em \&o2
numeric specifications, which can be used to specify
(usually in octal, with a leading '0')
the exact values of the flags.
These flags correspond to the termios
.Em c_cflag ,
.Em c_iflag ,
.Em c_lflag ,
and
.Em c_oflag
fields, respectively.
Each these sets must be completely specified to be effective.
The
.Em \&f0 ,
.Em \&f1 ,
and
.Em \&f2
are excepted for backwards compatibility with a previous incarnation of
the TTY sub-system.
In these flags the bottom 16 bits of the (32 bits) value contain the sgttyb
.Em sg_flags
field, while the top 16 bits represent the local mode word.
.Pp
Should
.Xr getty 8
receive a null character
(presumed to indicate a line break)
it will restart using the table indicated by the
.Em nx
entry.
If there is none, it will re-use its original table.
.Pp
Delays are specified in milliseconds, the nearest possible
delay available in the tty driver will be used.
Should greater certainty be desired, delays
with values 0, 1, 2, and 3 are interpreted as
choosing that particular delay algorithm from the driver.
.Pp
The
.Em \&cl
screen clear string may be preceded by a (decimal) number
of milliseconds of delay required (a la termcap).
This delay is simulated by repeated use of the pad character
.Em \&pc .
.Pp
The initial message, and login message,
.Em \&im
and
.Em \&lm
may include any of the following character sequences, which expand to
information about the environment in which
.Xr getty 8
is running.
.Pp
.Bl -tag -width \&%xxx -compact
.It \&%d
The current date.
.It \&%h
The hostname of the machine, which is normally obtained from the
system using
.Xr gethostname 3 ,
but may also be overridden by the
.Em \&hn
table entry.
In either case it may be edited with the
.Em \&he
string.
A '@' in the
.Em \&he
string causes one character from the real hostname to
be copied to the final hostname.
A '#' in the
.Em \&he
string causes the next character of the real hostname
to be skipped.
Each character that
is neither '@' nor '#' is copied into the final hostname.
Surplus '@' and '#' characters are ignored.
.It \&%t
The tty name.
.It "\&%m, \&%r, \&%s, \&%v"
The type of machine, release of the operating system, name of the
operating system, and version of the kernel, respectively, as
returned by
.Xr uname 3 .
.It \&%%
A
.Dq %
character.
.El
.Pp
When getty execs the login process, given
in the
.Em \&lo
string (usually
.Dq Pa /usr/bin/login ) ,
it will have set
the environment to include the terminal type, as indicated
by the
.Em \&tt
string (if it exists).
The
.Em \&ev
string, can be used to enter additional data into
the environment.
It is a list of comma separated strings, each of which
will presumably be of the form
.Em name=value .
.Pp
If a non-zero timeout is specified, with
.Em \&to ,
then getty will exit within the indicated
number of seconds, either having
received a login name and passed control
to
.Xr login 1 ,
or having received an alarm signal, and exited.
This may be useful to hangup dial in lines.
.Pp
Output from
.Xr getty 8
is even parity unless
.Em \&op
or
.Em \&np
is specified.
The
.Em \&op
string
may be specified with
.Em \&ap
to allow any parity on input, but generate odd parity output.
Note: this only applies while getty is being run,
terminal driver limitations prevent a more complete
implementation.
.Xr getty 8
does not check parity of input characters in
.Dv RAW
mode.
.Pp
If
.Em \&pp
string is specified and a Point to Point Protocol
.Pq Tn PPP
link bringup sequence is recognized,
.Xr getty 8
will invoke the program referenced by the
.Em \&pp
string, e.g.
.Xr pppd 8 .
This can be used to handle incoming
.Tn PPP
calls.
.Sh SEE ALSO
.Xr login 1 ,
.Xr gethostname 3 ,
.Xr uname 3 ,
.Xr capfile 5 ,
.Xr ttys 5 ,
.Xr getty 8 ,
.Xr pppd 8 ,
.Xr telnetd 8
.Sh HISTORY
The
.Nm
file format appeared in
.Bx 4.2 .
.Sh BUGS
The special characters (erase, kill, etc.) are reset to system defaults
by
.Xr login 1 .
In
.Em all
cases, '#' or '^H' typed in a login name will be treated as
an erase character, and '@' will be treated as a kill character.
.Pp
The delay stuff is a real crock.
Apart from its general lack of flexibility, some
of the delay algorithms are not implemented.
The terminal driver should support sane delay settings.
.Pp
The
.Em \&he
capability is stupid.

173
libexec/getty/gettytab.h Normal file
View File

@@ -0,0 +1,173 @@
/* $NetBSD: gettytab.h,v 1.16 2006/11/16 04:31:24 christos Exp $ */
/*
* Copyright (c) 1983, 1993, 1994
* 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
* 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. 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.
*
* from: @(#)gettytab.h 8.2 (Berkeley) 3/30/94
*/
/*
* Getty description definitions.
*/
struct gettystrs {
char *field; /* name to lookup in gettytab */
char *defalt; /* value we find by looking in defaults */
char *value; /* value that we find there */
};
struct gettynums {
char *field; /* name to lookup */
long defalt; /* number we find in defaults */
long value; /* number we find there */
int set; /* we actually got this one */
};
struct gettyflags {
char *field; /* name to lookup */
char invrt; /* name existing in gettytab --> false */
char defalt; /* true/false in defaults */
char value; /* true/false flag */
char set; /* we found it */
};
/*
* See init.c for the arrays indexed by these values.
*/
/*
* String values.
*/
#define NX gettystrs[0].value
#define CL gettystrs[1].value
#define IM gettystrs[2].value
#define LM gettystrs[3].value
#define ER gettystrs[4].value
#define KL gettystrs[5].value
#define ET gettystrs[6].value
#define PC gettystrs[7].value
#define TT gettystrs[8].value
#define EV gettystrs[9].value
#define LO gettystrs[10].value
#define HN gettystrs[11].value
#define HE gettystrs[12].value
#define IN gettystrs[13].value
#define QU gettystrs[14].value
#define XN gettystrs[15].value
#define XF gettystrs[16].value
#define BK gettystrs[17].value
#define SU gettystrs[18].value
#define DS gettystrs[19].value
#define RP gettystrs[20].value
#define FL gettystrs[21].value
#define WE gettystrs[22].value
#define LN gettystrs[23].value
#define ST gettystrs[24].value
#define B2 gettystrs[25].value
#define PP gettystrs[26].value
#define IF gettystrs[27].value
#define AL gettystrs[28].value
/*
* Numeric definitions.
*/
#define IS gettynums[0].value
#define OS gettynums[1].value
#define SP gettynums[2].value
#define ND gettynums[3].value
#define CD gettynums[4].value
#define TD gettynums[5].value
#define FD gettynums[6].value
#define BD gettynums[7].value
#define TO gettynums[8].value
#define F0 gettynums[9].value
#define F0set gettynums[9].set
#define F1 gettynums[10].value
#define F1set gettynums[10].set
#define F2 gettynums[11].value
#define F2set gettynums[11].set
#define PF gettynums[12].value
#define C0 gettynums[13].value
#define C0set gettynums[13].set
#define C1 gettynums[14].value
#define C1set gettynums[14].set
#define C2 gettynums[15].value
#define C2set gettynums[15].set
#define I0 gettynums[16].value
#define I0set gettynums[16].set
#define I1 gettynums[17].value
#define I1set gettynums[17].set
#define I2 gettynums[18].value
#define I2set gettynums[18].set
#define L0 gettynums[19].value
#define L0set gettynums[19].set
#define L1 gettynums[20].value
#define L1set gettynums[20].set
#define L2 gettynums[21].value
#define L2set gettynums[21].set
#define O0 gettynums[22].value
#define O0set gettynums[22].set
#define O1 gettynums[23].value
#define O1set gettynums[23].set
#define O2 gettynums[24].value
#define O2set gettynums[24].set
/*
* Boolean values.
*/
#define HT gettyflags[0].value
#define NL gettyflags[1].value
#define EP gettyflags[2].value
#define EPset gettyflags[2].set
#define OP gettyflags[3].value
#define OPset gettyflags[3].set
#define AP gettyflags[4].value
#define APset gettyflags[4].set
#define EC gettyflags[5].value
#define CO gettyflags[6].value
#define CB gettyflags[7].value
#define CK gettyflags[8].value
#define CE gettyflags[9].value
#define PE gettyflags[10].value
#define RW gettyflags[11].value
#define XC gettyflags[12].value
#define LC gettyflags[13].value
#define UC gettyflags[14].value
#define IG gettyflags[15].value
#define PS gettyflags[16].value
#define HC gettyflags[17].value
#define UB gettyflags[18].value
#define AB gettyflags[19].value
#define DX gettyflags[20].value
#define NP gettyflags[21].value
#define MB gettyflags[22].value
#define CS gettyflags[23].value
#define NN gettyflags[24].value
extern struct gettyflags gettyflags[];
extern struct gettynums gettynums[];
extern struct gettystrs gettystrs[];

146
libexec/getty/init.c Normal file
View File

@@ -0,0 +1,146 @@
/* $NetBSD: init.c,v 1.17 2007/12/03 09:54:24 isaki Exp $ */
/*
* Copyright (c) 1983, 1993
* 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
* 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. 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)init.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: init.c,v 1.17 2007/12/03 09:54:24 isaki Exp $");
#endif
#endif /* not lint */
/*
* Getty table initializations.
*
* Melbourne getty.
*/
#include <termios.h>
#include "gettytab.h"
#include "pathnames.h"
extern struct termios tmode;
extern char hostname[];
#define M(a) ((char *)&tmode.c_cc[a])
struct gettystrs gettystrs[] = {
{ "nx" }, /* next table */
{ "cl" }, /* screen clear characters */
{ "im" }, /* initial message */
{ "lm", "login: " }, /* login message */
{ "er", M(VERASE) }, /* erase character */
{ "kl", M(VKILL) }, /* kill character */
{ "et", M(VEOF) }, /* eof chatacter (eot) */
{ "pc", "" }, /* pad character */
{ "tt" }, /* terminal type */
{ "ev" }, /* environment */
{ "lo", _PATH_LOGIN }, /* login program */
{ "hn", hostname }, /* host name */
{ "he" }, /* host name edit */
{ "in", M(VINTR) }, /* interrupt char */
{ "qu", M(VQUIT) }, /* quit char */
{ "xn", M(VSTART) }, /* XON (start) char */
{ "xf", M(VSTOP) }, /* XOFF (stop) char */
{ "bk", M(VEOL) }, /* brk char (alt \n) */
{ "su", M(VSUSP) }, /* suspend char */
{ "ds", M(VDSUSP) }, /* delayed suspend */
{ "rp", M(VREPRINT) }, /* reprint char */
{ "fl", M(VDISCARD) }, /* flush output */
{ "we", M(VWERASE) }, /* word erase */
{ "ln", M(VLNEXT) }, /* literal next */
{ "st", M(VSTATUS) }, /* status */
{ "b2", M(VEOL2) }, /* alt brk char */
{ "pp" }, /* ppp login program */
{ "if" }, /* sysv-like 'issue' filename */
{ "al" }, /* user to auto-login */
{ 0 }
};
struct gettynums gettynums[] = {
{ "is" }, /* input speed */
{ "os" }, /* output speed */
{ "sp" }, /* both speeds */
{ "nd" }, /* newline delay */
{ "cd" }, /* carriage-return delay */
{ "td" }, /* tab delay */
{ "fd" }, /* form-feed delay */
{ "bd" }, /* backspace delay */
{ "to" }, /* timeout */
{ "f0" }, /* output flags */
{ "f1" }, /* input flags */
{ "f2" }, /* user mode flags */
{ "pf" }, /* delay before flush at 1st prompt */
{ "c0" }, /* output c_flags */
{ "c1" }, /* input c_flags */
{ "c2" }, /* user mode c_flags */
{ "i0" }, /* output i_flags */
{ "i1" }, /* input i_flags */
{ "i2" }, /* user mode i_flags */
{ "l0" }, /* output l_flags */
{ "l1" }, /* input l_flags */
{ "l2" }, /* user mode l_flags */
{ "o0" }, /* output o_flags */
{ "o1" }, /* input o_flags */
{ "o2" }, /* user mode o_flags */
{ 0 }
};
struct gettyflags gettyflags[] = {
{ "ht", 0 }, /* has tabs */
{ "nl", 1 }, /* has newline char */
{ "ep", 0 }, /* even parity */
{ "op", 0 }, /* odd parity */
{ "ap", 0 }, /* any parity */
{ "ec", 1 }, /* no echo */
{ "co", 0 }, /* console special */
{ "cb", 0 }, /* crt backspace */
{ "ck", 0 }, /* crt kill */
{ "ce", 0 }, /* crt erase */
{ "pe", 0 }, /* printer erase */
{ "rw", 1 }, /* don't use raw */
{ "xc", 1 }, /* don't ^X ctl chars */
{ "lc", 0 }, /* terminal las lower case */
{ "uc", 0 }, /* terminal has no lower case */
{ "ig", 0 }, /* ignore garbage */
{ "ps", 0 }, /* do port selector speed select */
{ "hc", 1 }, /* don't set hangup on close */
{ "ub", 0 }, /* unbuffered output */
{ "ab", 0 }, /* auto-baud detect with '\r' */
{ "dx", 0 }, /* set decctlq */
{ "np", 0 }, /* no parity at all (8bit chars) */
{ "mb", 0 }, /* do MDMBUF flow control */
{ "cs", 0 }, /* clear screen based on term type */
{ "nn", 0 }, /* don't prompt for login name */
{ 0 }
};

707
libexec/getty/main.c Normal file
View File

@@ -0,0 +1,707 @@
/* $NetBSD: main.c,v 1.59 2012/06/28 08:55:10 roy Exp $ */
/*-
* Copyright (c) 1980, 1993
* 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
* 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. 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)main.c 8.1 (Berkeley) 6/20/93";
#else
__RCSID("$NetBSD: main.c,v 1.59 2012/06/28 08:55:10 roy Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/utsname.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <pwd.h>
#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <term.h>
#include <time.h>
#include <ttyent.h>
#include <unistd.h>
#include <util.h>
#include "gettytab.h"
#include "pathnames.h"
#include "extern.h"
extern char editedhost[];
/*
* Set the amount of running time that getty should accumulate
* before deciding that something is wrong and exit.
*/
#define GETTY_TIMEOUT 60 /* seconds */
/* 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 */
struct termios tmode, omode;
int crmod, digit_or_punc, lower, upper;
char hostname[MAXHOSTNAMELEN + 1];
struct utsname kerninfo;
char name[LOGIN_NAME_MAX];
char dev[] = _PATH_DEV;
char ttyn[32];
char lockfile[512];
uid_t ttyowner;
char *rawttyn;
#define OBUFSIZ 128
#define TABBUFSIZ 512
char defent[TABBUFSIZ];
char tabent[TABBUFSIZ];
char *env[128];
const unsigned 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
};
#define ERASE tmode.c_cc[VERASE]
#define KILL tmode.c_cc[VKILL]
#define EOT tmode.c_cc[VEOF]
static void clearscreen(void);
jmp_buf timeout;
static void
/*ARGSUSED*/
dingdong(int signo)
{
(void)alarm(0);
(void)signal(SIGALRM, SIG_DFL);
longjmp(timeout, 1);
}
jmp_buf intrupt;
static void
/*ARGSUSED*/
interrupt(int signo)
{
(void)signal(SIGINT, interrupt);
longjmp(intrupt, 1);
}
#ifndef __minix
/*
* Action to take when getty is running too long.
*/
static void
/*ARGSUSED*/
timeoverrun(int signo)
{
syslog(LOG_ERR, "getty exiting due to excessive running time");
exit(1);
}
#endif
static int getname(void);
static void oflush(void);
static void prompt(void);
static int putchr(int);
static void putf(const char *);
static void xputs(const char *);
#define putpad(s) tputs(s, 1, putchr)
int
main(int argc, char *argv[], char *envp[])
{
const char *progname;
char *tname;
int repcnt = 0, failopenlogged = 0, uugetty = 0, first_time = 1;
struct rlimit limit;
struct passwd *pw;
int rval;
(void)signal(SIGINT, SIG_IGN);
openlog("getty", LOG_PID, LOG_AUTH);
(void)gethostname(hostname, sizeof(hostname));
hostname[sizeof(hostname) - 1] = '\0';
if (hostname[0] == '\0')
(void)strlcpy(hostname, "Amnesiac", sizeof(hostname));
(void)uname(&kerninfo);
progname = getprogname();
if (progname[0] == 'u' && progname[1] == 'u')
uugetty = 1;
/*
* Find id of uucp login (if present) so we can chown tty properly.
*/
if (uugetty && (pw = getpwnam("uucp")))
ttyowner = pw->pw_uid;
else
ttyowner = 0;
/*
* Limit running time to deal with broken or dead lines.
*/
#ifndef __minix
(void)signal(SIGXCPU, timeoverrun);
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = GETTY_TIMEOUT;
(void)setrlimit(RLIMIT_CPU, &limit);
#endif
/*
* 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
* that the file descriptors are already set up for us.
* J. Gettys - MIT Project Athena.
*/
if (argc <= 2 || strcmp(argv[2], "-") == 0) {
(void)strlcpy(ttyn, ttyname(0), sizeof(ttyn));
}
else {
int i;
rawttyn = argv[2];
(void)strlcpy(ttyn, dev, sizeof(ttyn));
(void)strlcat(ttyn, argv[2], sizeof(ttyn));
if (uugetty) {
(void)chown(ttyn, ttyowner, 0);
(void)strlcpy(lockfile, _PATH_LOCK,
sizeof(lockfile));
(void)strlcat(lockfile, argv[2],
sizeof(lockfile));
/*
* wait for lockfiles to go away before we try
* to open
*/
if (pidlock(lockfile, 0, 0, 0) != 0) {
syslog(LOG_ERR,
"%s: can't create lockfile", ttyn);
exit(1);
}
(void)unlink(lockfile);
}
if (strcmp(argv[0], "+") != 0) {
(void)chown(ttyn, ttyowner, 0);
(void)chmod(ttyn, 0600);
#ifndef __minix
(void)revoke(ttyn);
#endif
if (ttyaction(ttyn, "getty", "root"))
syslog(LOG_WARNING, "%s: ttyaction failed",
ttyn);
/*
* Delay the open so DTR stays down long enough
* to be detected.
*/
(void)sleep(2);
while ((i = open(ttyn, O_RDWR)) == -1) {
if ((repcnt % 10 == 0) &&
(errno != ENXIO || !failopenlogged)) {
syslog(LOG_WARNING, "%s: %m", ttyn);
closelog();
failopenlogged = 1;
}
repcnt++;
(void)sleep(60);
}
if (uugetty && pidlock(lockfile, 0, 0, 0) != 0) {
syslog(LOG_ERR, "%s: can't create lockfile",
ttyn);
exit(1);
}
if (uugetty)
(void)chown(lockfile, ttyowner, 0);
(void)login_tty(i);
}
}
/* Start with default tty settings */
if (tcgetattr(0, &tmode) < 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
exit(1);
}
omode = tmode;
gettable("default", defent);
gendefaults();
tname = "default";
if (argc > 1)
tname = argv[1];
for (;;) {
int off;
rval = 0;
gettable(tname, tabent);
if (OPset || EPset || APset)
APset++, OPset++, EPset++;
setdefaults();
off = 0;
(void)tcflush(0, TCIOFLUSH); /* clear out the crap */
#ifndef __minix
(void)ioctl(0, FIONBIO, &off); /* turn off non-blocking mode */
(void)ioctl(0, FIOASYNC, &off); /* ditto for async mode */
#endif
if (IS)
(void)cfsetispeed(&tmode, (speed_t)IS);
else if (SP)
(void)cfsetispeed(&tmode, (speed_t)SP);
if (OS)
(void)cfsetospeed(&tmode, (speed_t)OS);
else if (SP)
(void)cfsetospeed(&tmode, (speed_t)SP);
setflags(0);
setchars();
if (tcsetattr(0, TCSANOW, &tmode) < 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
exit(1);
}
if (AB) {
tname = autobaud();
continue;
}
if (PS) {
tname = portselector();
continue;
}
if (CS)
clearscreen();
if (CL && *CL)
putpad(CL);
edithost(HE);
/*
* If this is the first time through this, and an
* issue file has been given, then send it.
*/
if (first_time != 0 && IF != NULL) {
char buf[_POSIX2_LINE_MAX];
FILE *fp;
if ((fp = fopen(IF, "r")) != NULL) {
while (fgets(buf, sizeof(buf) - 1, fp) != NULL)
putf(buf);
(void)fclose(fp);
}
}
first_time = 0;
if (IM && *IM)
putf(IM);
oflush();
if (setjmp(timeout)) {
tmode.c_ispeed = tmode.c_ospeed = 0;
(void)tcsetattr(0, TCSANOW, &tmode);
exit(1);
}
if (TO) {
(void)signal(SIGALRM, dingdong);
(void)alarm((unsigned int)TO);
}
if (NN) {
name[0] = '\0';
lower = 1;
upper = digit_or_punc = 0;
} else if (AL) {
const char *p = AL;
char *q = name;
while (*p && q < &name[sizeof name - 1]) {
if (isupper((unsigned char)*p))
upper = 1;
else if (islower((unsigned char)*p))
lower = 1;
else if (isdigit((unsigned char)*p))
digit_or_punc = 1;
*q++ = *p++;
}
} else if ((rval = getname()) == 2) {
setflags(2);
(void)execle(PP, "ppplogin", ttyn, (char *) 0, env);
syslog(LOG_ERR, "%s: %m", PP);
exit(1);
}
if (rval || AL || NN) {
int i;
oflush();
(void)alarm(0);
(void)signal(SIGALRM, SIG_DFL);
if (name[0] == '-') {
xputs("user names may not start with '-'.");
continue;
}
if (!(upper || lower || digit_or_punc))
continue;
setflags(2);
if (crmod) {
tmode.c_iflag |= ICRNL;
tmode.c_oflag |= ONLCR;
}
#if XXX
if (upper || UC)
tmode.sg_flags |= LCASE;
if (lower || LC)
tmode.sg_flags &= ~LCASE;
#endif
if (tcsetattr(0, TCSANOW, &tmode) < 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
exit(1);
}
(void)signal(SIGINT, SIG_DFL);
for (i = 0; envp[i] != NULL; i++)
env[i] = envp[i];
makeenv(&env[i]);
limit.rlim_max = RLIM_INFINITY;
limit.rlim_cur = RLIM_INFINITY;
#ifndef __minix
(void)setrlimit(RLIMIT_CPU, &limit);
#endif
if (NN)
(void)execle(LO, "login", AL ? "-fp" : "-p",
NULL, env);
else
(void)execle(LO, "login", AL ? "-fp" : "-p",
"--", name, NULL, env);
syslog(LOG_ERR, "%s: %m", LO);
exit(1);
}
(void)alarm(0);
(void)signal(SIGALRM, SIG_DFL);
(void)signal(SIGINT, SIG_IGN);
if (NX && *NX)
tname = NX;
if (uugetty)
(void)unlink(lockfile);
}
}
static int
getname(void)
{
int c;
char *np;
unsigned char cs;
int ppp_state, ppp_connection;
/*
* Interrupt may happen if we use CBREAK mode
*/
if (setjmp(intrupt)) {
(void)signal(SIGINT, SIG_IGN);
return (0);
}
(void)signal(SIGINT, interrupt);
setflags(1);
prompt();
if (PF > 0) {
oflush();
(void)sleep((unsigned int)PF);
PF = 0;
}
if (tcsetattr(0, TCSANOW, &tmode) < 0) {
syslog(LOG_ERR, "%s: %m", ttyn);
exit(1);
}
crmod = digit_or_punc = lower = upper = 0;
ppp_state = ppp_connection = 0;
np = name;
for (;;) {
oflush();
if (read(STDIN_FILENO, &cs, 1) <= 0)
exit(0);
if ((c = cs&0177) == 0)
return (0);
/*
* 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;
}
if (c == EOT)
exit(1);
if (c == '\r' || c == '\n' ||
np >= &name[LOGIN_NAME_MAX - 1]) {
*np = '\0';
putf("\r\n");
break;
}
if (islower(c))
lower = 1;
else if (isupper(c))
upper = 1;
else if (c == ERASE || c == '#' || c == '\b') {
if (np > name) {
np--;
if (cfgetospeed(&tmode) >= 1200)
xputs("\b \b");
else
putchr(cs);
}
continue;
} else if (c == KILL || c == '@') {
putchr(cs);
putchr('\r');
if (cfgetospeed(&tmode) < 1200)
putchr('\n');
/* this is the way they do it down under ... */
else if (np > name)
xputs(
" \r");
prompt();
np = name;
continue;
} else if (isdigit(c) || c == '_')
digit_or_punc = 1;
if (IG && (c <= ' ' || c > 0176))
continue;
*np++ = c;
putchr(cs);
/*
* An MS-Windows direct connect PPP "client" won't send its
* first PPP packet until we respond to its "CLIENT" poll
* with a CRLF sequence. We cater to yet another broken
* implementation of a previously-standard protocol...
*/
*np = '\0';
if (strstr(name, "CLIENT"))
putf("\r\n");
}
(void)signal(SIGINT, SIG_IGN);
*np = 0;
if (c == '\r')
crmod = 1;
if ((upper && !lower && !LC) || UC)
for (np = name; *np; np++)
*np = tolower((unsigned char)*np);
return (1 + ppp_connection);
}
static void
xputs(const char *s)
{
while (*s)
putchr(*s++);
}
char outbuf[OBUFSIZ];
size_t obufcnt = 0;
static int
putchr(int cc)
{
unsigned char c;
c = cc;
if (!NP) {
c |= partab[c&0177] & 0200;
if (OP)
c ^= 0200;
}
if (!UB) {
outbuf[obufcnt++] = c;
if (obufcnt >= OBUFSIZ)
oflush();
return 1;
}
return write(STDOUT_FILENO, &c, 1);
}
static void
oflush(void)
{
if (obufcnt)
(void)write(STDOUT_FILENO, outbuf, obufcnt);
obufcnt = 0;
}
static void
prompt(void)
{
putf(LM);
if (CO)
putchr('\n');
}
static void
putf(const char *cp)
{
time_t t;
char *slash, db[100];
while (*cp) {
if (*cp != '%') {
putchr(*cp++);
continue;
}
switch (*++cp) {
case 't':
if ((slash = strstr(ttyn, "/pts/")) == NULL)
slash = strrchr(ttyn, '/');
if (slash == NULL)
xputs(ttyn);
else
xputs(&slash[1]);
break;
case 'h':
xputs(editedhost);
break;
case 'd':
(void)time(&t);
(void)strftime(db, sizeof(db),
"%l:%M%p on %A, %d %B %Y", localtime(&t));
xputs(db);
break;
case 's':
xputs(kerninfo.sysname);
break;
case 'm':
xputs(kerninfo.machine);
break;
case 'r':
xputs(kerninfo.release);
break;
case 'v':
xputs(kerninfo.version);
break;
case '%':
putchr('%');
break;
}
if (*cp)
cp++;
}
}
static void
clearscreen(void)
{
struct ttyent *typ;
int err;
if (rawttyn == NULL)
return;
typ = getttynam(rawttyn);
if ((typ == NULL) || (typ->ty_type == NULL) ||
(typ->ty_type[0] == 0))
return;
if (setupterm(typ->ty_type, 0, &err) == ERR)
return;
if (clear_screen)
putpad(clear_screen);
del_curterm(cur_term);
cur_term = NULL;
}

37
libexec/getty/pathnames.h Normal file
View File

@@ -0,0 +1,37 @@
/* $NetBSD: pathnames.h,v 1.9 2008/02/04 15:27:20 christos Exp $ */
/*
* Copyright (c) 1989, 1993
* 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
* 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. 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.
*
* from: @(#)pathnames.h 8.1 (Berkeley) 6/4/93
*/
#include <paths.h>
#define _PATH_LOGIN "/usr/bin/login"
#define _PATH_LOCK "/var/spool/lock/LCK.."

743
libexec/getty/subr.c Normal file
View File

@@ -0,0 +1,743 @@
/* $NetBSD: subr.c,v 1.33 2006/11/16 04:31:24 christos Exp $ */
/*
* Copyright (c) 1983, 1993
* 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
* 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. 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "from: @(#)subr.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: subr.c,v 1.33 2006/11/16 04:31:24 christos Exp $");
#endif
#endif /* not lint */
/*
* Melbourne getty.
*/
#ifndef __minix
#define COMPAT_43
#endif
#include <sys/param.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <poll.h>
#include "extern.h"
#include "gettytab.h"
#include "pathnames.h"
extern struct termios tmode, omode;
#ifndef __minix
static void compatflags(long);
#endif
/*
* Get a table entry.
*/
void
gettable(char *name, char *buf)
{
struct gettystrs *sp;
struct gettynums *np;
struct gettyflags *fp;
long n;
const char *dba[2];
dba[0] = _PATH_GETTYTAB;
dba[1] = 0;
if (cgetent(&buf, dba, name) != 0)
return;
for (sp = gettystrs; sp->field; sp++)
(void)cgetstr(buf, sp->field, &sp->value);
for (np = gettynums; np->field; np++) {
if (cgetnum(buf, np->field, &n) == -1)
np->set = 0;
else {
np->set = 1;
np->value = n;
}
}
for (fp = gettyflags; fp->field; fp++) {
if (cgetcap(buf, fp->field, ':') == NULL)
fp->set = 0;
else {
fp->set = 1;
fp->value = 1 ^ 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(void)
{
struct gettystrs *sp;
struct gettynums *np;
struct gettyflags *fp;
for (sp = gettystrs; sp->field; sp++)
if (sp->value)
sp->defalt = sp->value;
for (np = gettynums; np->field; np++)
if (np->set)
np->defalt = np->value;
for (fp = gettyflags; fp->field; fp++)
if (fp->set)
fp->defalt = fp->value;
else
fp->defalt = fp->invrt;
}
void
setdefaults(void)
{
struct gettystrs *sp;
struct gettynums *np;
struct gettyflags *fp;
for (sp = gettystrs; sp->field; sp++)
if (!sp->value)
sp->value = sp->defalt;
for (np = gettynums; np->field; np++)
if (!np->set)
np->value = np->defalt;
for (fp = gettyflags; fp->field; fp++)
if (!fp->set)
fp->value = fp->defalt;
}
static char **
charnames[] = {
&ER, &KL, &IN, &QU, &XN, &XF, &ET, &BK,
&SU, &DS, &RP, &FL, &WE, &LN, &ST, &B2, 0
};
static cc_t *
charvars[] = {
&tmode.c_cc[VERASE], &tmode.c_cc[VKILL], &tmode.c_cc[VINTR],
&tmode.c_cc[VQUIT], &tmode.c_cc[VSTART], &tmode.c_cc[VSTOP],
&tmode.c_cc[VEOF], &tmode.c_cc[VEOL], &tmode.c_cc[VSUSP],
&tmode.c_cc[VDSUSP], &tmode.c_cc[VREPRINT], &tmode.c_cc[VDISCARD],
&tmode.c_cc[VWERASE], &tmode.c_cc[VLNEXT], &tmode.c_cc[VSTATUS],
&tmode.c_cc[VEOL2], 0
};
void
setchars(void)
{
int i;
char *p;
for (i = 0; charnames[i]; i++) {
p = *charnames[i];
if (p && *p)
*charvars[i] = *p;
else
*charvars[i] = _POSIX_VDISABLE;
}
}
/* Macros to clear/set/test flags. */
#define SET(t, f) (t) |= (f)
#define CLR(t, f) (t) &= ~(f)
#define ISSET(t, f) ((t) & (f))
void
setflags(int n)
{
tcflag_t iflag, oflag, cflag, lflag;
#ifdef COMPAT_43
switch (n) {
case 0:
if (F0set) {
compatflags(F0);
return;
}
break;
case 1:
if (F1set) {
compatflags(F1);
return;
}
break;
default:
if (F2set) {
compatflags(F2);
return;
}
break;
}
#endif
switch (n) {
case 0:
if (C0set && I0set && L0set && O0set) {
tmode.c_cflag = C0;
tmode.c_iflag = I0;
tmode.c_lflag = L0;
tmode.c_oflag = O0;
return;
}
break;
case 1:
if (C1set && I1set && L1set && O1set) {
tmode.c_cflag = C1;
tmode.c_iflag = I1;
tmode.c_lflag = L1;
tmode.c_oflag = O1;
return;
}
break;
default:
if (C2set && I2set && L2set && O2set) {
tmode.c_cflag = C2;
tmode.c_iflag = I2;
tmode.c_lflag = L2;
tmode.c_oflag = O2;
return;
}
break;
}
iflag = omode.c_iflag;
oflag = omode.c_oflag;
cflag = omode.c_cflag;
lflag = omode.c_lflag;
if (NP) {
CLR(cflag, CSIZE|PARENB);
SET(cflag, CS8);
CLR(iflag, ISTRIP|INPCK|IGNPAR);
} else if (AP || EP || OP) {
CLR(cflag, CSIZE);
SET(cflag, CS7|PARENB);
SET(iflag, ISTRIP);
if (OP && !EP) {
SET(iflag, INPCK|IGNPAR);
SET(cflag, PARODD);
if (AP)
CLR(iflag, INPCK);
} else if (EP && !OP) {
SET(iflag, INPCK|IGNPAR);
CLR(cflag, PARODD);
if (AP)
CLR(iflag, INPCK);
} else if (AP || (EP && OP)) {
CLR(iflag, INPCK|IGNPAR);
CLR(cflag, PARODD);
}
} /* else, leave as is */
#if 0
if (UC)
f |= LCASE;
#endif
if (HC)
SET(cflag, HUPCL);
else
CLR(cflag, HUPCL);
#ifndef __minix
if (MB)
SET(cflag, MDMBUF);
else
CLR(cflag, MDMBUF);
#endif
if (NL) {
SET(iflag, ICRNL);
SET(oflag, ONLCR|OPOST);
} else {
CLR(iflag, ICRNL);
CLR(oflag, ONLCR);
}
#ifndef __minix
if (!HT)
SET(oflag, OXTABS|OPOST);
else
CLR(oflag, OXTABS);
#endif
#ifdef XXX_DELAY
SET(f, delaybits());
#endif
if (n == 1) { /* read mode flags */
if (RW) {
iflag = 0;
CLR(oflag, OPOST);
CLR(cflag, CSIZE|PARENB);
SET(cflag, CS8);
lflag = 0;
} else {
CLR(lflag, ICANON);
}
goto out;
}
if (n == 0)
goto out;
#if 0
if (CB)
SET(f, CRTBS);
#endif
if (CE)
SET(lflag, ECHOE);
else
CLR(lflag, ECHOE);
#ifndef __minix
if (CK)
SET(lflag, ECHOKE);
else
CLR(lflag, ECHOKE);
if (PE)
SET(lflag, ECHOPRT);
else
CLR(lflag, ECHOPRT);
#endif
if (EC)
SET(lflag, ECHO);
else
CLR(lflag, ECHO);
#ifndef __minix
if (XC)
SET(lflag, ECHOCTL);
else
CLR(lflag, ECHOCTL);
#endif
if (DX)
SET(lflag, IXANY);
else
CLR(lflag, IXANY);
out:
tmode.c_iflag = iflag;
tmode.c_oflag = oflag;
tmode.c_cflag = cflag;
tmode.c_lflag = lflag;
}
#ifdef COMPAT_43
/*
* Old TTY => termios, snatched from <sys/kern/tty_compat.c>
*/
void
compatflags(long flags)
{
tcflag_t iflag, oflag, cflag, lflag;
iflag = BRKINT|ICRNL|IMAXBEL|IXON|IXANY;
oflag = OPOST|ONLCR|OXTABS;
cflag = CREAD;
lflag = ICANON|ISIG|IEXTEN;
if (ISSET(flags, TANDEM))
SET(iflag, IXOFF);
else
CLR(iflag, IXOFF);
if (ISSET(flags, ECHO))
SET(lflag, ECHO);
else
CLR(lflag, ECHO);
if (ISSET(flags, CRMOD)) {
SET(iflag, ICRNL);
SET(oflag, ONLCR);
} else {
CLR(iflag, ICRNL);
CLR(oflag, ONLCR);
}
if (ISSET(flags, XTABS))
SET(oflag, OXTABS);
else
CLR(oflag, OXTABS);
if (ISSET(flags, RAW)) {
iflag &= IXOFF;
CLR(lflag, ISIG|ICANON|IEXTEN);
CLR(cflag, PARENB);
} else {
SET(iflag, BRKINT|IXON|IMAXBEL);
SET(lflag, ISIG|IEXTEN);
if (ISSET(flags, CBREAK))
CLR(lflag, ICANON);
else
SET(lflag, ICANON);
switch (ISSET(flags, ANYP)) {
case 0:
CLR(cflag, PARENB);
break;
case ANYP:
SET(cflag, PARENB);
CLR(iflag, INPCK);
break;
case EVENP:
SET(cflag, PARENB);
SET(iflag, INPCK);
CLR(cflag, PARODD);
break;
case ODDP:
SET(cflag, PARENB);
SET(iflag, INPCK);
SET(cflag, PARODD);
break;
}
}
/* Nothing we can do with CRTBS. */
if (ISSET(flags, PRTERA))
SET(lflag, ECHOPRT);
else
CLR(lflag, ECHOPRT);
if (ISSET(flags, CRTERA))
SET(lflag, ECHOE);
else
CLR(lflag, ECHOE);
#ifndef __minix
/* Nothing we can do with TILDE. */
if (ISSET(flags, MDMBUF))
SET(cflag, MDMBUF);
else
CLR(cflag, MDMBUF);
#endif
if (ISSET(flags, NOHANG))
CLR(cflag, HUPCL);
else
SET(cflag, HUPCL);
#ifndef __minix
if (ISSET(flags, CRTKIL))
SET(lflag, ECHOKE);
else
CLR(lflag, ECHOKE);
#endif
if (ISSET(flags, CTLECH))
SET(lflag, ECHOCTL);
else
CLR(lflag, ECHOCTL);
if (!ISSET(flags, DECCTQ))
SET(iflag, IXANY);
else
CLR(iflag, IXANY);
CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH);
SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
if (ISSET(flags, RAW|LITOUT|PASS8)) {
CLR(cflag, CSIZE);
SET(cflag, CS8);
if (!ISSET(flags, RAW|PASS8))
SET(iflag, ISTRIP);
else
CLR(iflag, ISTRIP);
if (!ISSET(flags, RAW|LITOUT))
SET(oflag, OPOST);
else
CLR(oflag, OPOST);
} else {
CLR(cflag, CSIZE);
SET(cflag, CS7);
SET(iflag, ISTRIP);
SET(oflag, OPOST);
}
tmode.c_iflag = iflag;
tmode.c_oflag = oflag;
tmode.c_cflag = cflag;
tmode.c_lflag = lflag;
}
#endif
#ifdef XXX_DELAY
struct delayval {
unsigned delay; /* delay in ms */
int bits;
};
/*
* below are random guesses, I can't be bothered checking
*/
struct delayval crdelay[] = {
{ 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 },
};
struct delayval bsdelay[] = {
{ 1, BS1 },
{ 0, 0 },
};
struct delayval ffdelay[] = {
{ 1, FF1 },
{ 1750, FF1 },
{ 0, FF1 },
};
struct delayval tbdelay[] = {
{ 1, TAB1 },
{ 2, TAB2 },
{ 3, XTABS }, /* this is expand tabs */
{ 100, TAB1 },
{ 0, TAB2 },
};
int
delaybits(void)
{
int f;
f = adelay(CD, crdelay);
f |= adelay(ND, nldelay);
f |= adelay(FD, ffdelay);
f |= adelay(TD, tbdelay);
f |= adelay(BD, bsdelay);
return (f);
}
int
adelay(int ms, struct delayval *dp)
{
if (ms == 0)
return (0);
while (dp->delay && ms > dp->delay)
dp++;
return (dp->bits);
}
#endif
char editedhost[MAXHOSTNAMELEN];
void
edithost(char *pat)
{
char *host = HN;
char *res = editedhost;
if (!pat)
pat = "";
while (*pat) {
switch (*pat) {
case '#':
if (*host)
host++;
break;
case '@':
if (*host)
*res++ = *host++;
break;
default:
*res++ = *pat;
break;
}
if (res == &editedhost[sizeof editedhost - 1]) {
*res = '\0';
return;
}
pat++;
}
if (*host)
(void)strncpy(res, host,
sizeof editedhost - (res - editedhost) - 1);
else
*res = '\0';
editedhost[sizeof editedhost - 1] = '\0';
}
void
makeenv(char *env[])
{
static char termbuf[128] = "TERM=";
char *p, *q;
char **ep;
ep = env;
if (TT && *TT) {
(void)strlcat(termbuf, TT, sizeof(termbuf));
*ep++ = termbuf;
}
if ((p = EV) != NULL) {
q = p;
while ((q = strchr(q, ',')) != NULL) {
*q++ = '\0';
*ep++ = p;
p = q;
}
if (*p)
*ep++ = p;
}
*ep = (char *)0;
}
/*
* This speed select mechanism is written for the Develcon DATASWITCH.
* The Develcon sends a string of the form "B{speed}\n" at a predefined
* baud rate. This string indicates the user's actual speed.
* The routine below returns the terminal type mapped from derived speed.
*/
struct portselect {
char *ps_baud;
char *ps_type;
} portspeeds[] = {
{ "B110", "std.110" },
{ "B134", "std.134" },
{ "B150", "std.150" },
{ "B300", "std.300" },
{ "B600", "std.600" },
{ "B1200", "std.1200" },
{ "B2400", "std.2400" },
{ "B4800", "std.4800" },
{ "B9600", "std.9600" },
{ "B19200", "std.19200" },
{ 0 }
};
char *
portselector(void)
{
char c, baud[20], *type = "default";
struct portselect *ps;
int len;
(void)alarm(5*60);
for (len = 0; len < sizeof (baud) - 1; len++) {
if (read(STDIN_FILENO, &c, 1) <= 0)
break;
c &= 0177;
if (c == '\n' || c == '\r')
break;
if (c == 'B')
len = 0; /* in case of leading garbage */
baud[len] = c;
}
baud[len] = '\0';
for (ps = portspeeds; ps->ps_baud; ps++)
if (strcmp(ps->ps_baud, baud) == 0) {
type = ps->ps_type;
break;
}
(void)sleep(2); /* wait for connection to complete */
return (type);
}
/*
* This auto-baud speed select mechanism is written for the Micom 600
* portselector. Selection is done by looking at how the character '\r'
* is garbled at the different speeds.
*/
#include <sys/time.h>
char *
autobaud(void)
{
struct pollfd set[1];
struct timespec timeout;
char c, *type = "9600-baud";
(void)tcflush(0, TCIOFLUSH);
set[0].fd = STDIN_FILENO;
set[0].events = POLLIN;
if (poll(set, 1, 5000) <= 0)
return (type);
if (read(STDIN_FILENO, &c, 1) != 1)
return (type);
timeout.tv_sec = 0;
timeout.tv_nsec = 20000;
(void)nanosleep(&timeout, NULL);
(void)tcflush(0, TCIOFLUSH);
switch (c & 0377) {
case 0200: /* 300-baud */
type = "300-baud";
break;
case 0346: /* 1200-baud */
type = "1200-baud";
break;
case 015: /* 2400-baud */
case 0215:
type = "2400-baud";
break;
default: /* 4800-baud */
type = "4800-baud";
break;
case 0377: /* 9600-baud */
type = "9600-baud";
break;
}
return (type);
}

227
libexec/getty/ttys.5 Normal file
View File

@@ -0,0 +1,227 @@
.\" $NetBSD: ttys.5,v 1.18 2012/04/21 12:27:28 roy Exp $
.\"
.\" Copyright (c) 1985, 1991, 1993
.\" 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
.\" 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. 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.
.\"
.\" from: @(#)ttys.5 8.1 (Berkeley) 6/4/93
.\"
.Dd April 5, 2012
.Dt TTYS 5
.Os
.Sh NAME
.Nm ttys
.Nd terminal initialization information
.Sh DESCRIPTION
The file
.Nm
contains information that is used by various routines to initialize
and control the use of terminal special files.
This information is read with the
.Xr getttyent 3
library routines.
.Pp
There is one line in the
.Nm
file per special device file.
Fields are separated by tabs and/or spaces.
Fields comprising more than one word should be enclosed in double
quotes (``"'').
Blank lines and comments may appear anywhere in the file; comments
are delimited by hash marks (``#'') and new lines.
Any unspecified fields will default to null.
.Pp
Each line in
.Nm
has the format:
.Dl tty command type flags
.Pp
The first field is the
name of the terminal special file as it is found in
.Pa /dev .
.Pp
The second field of the file is the command to execute for the line,
usually
.Xr getty 8 ,
which initializes and opens the line, setting the speed, waiting for
a user name and executing the
.Xr login 1
program.
However, it can be any desired command, for example the start up
for a window system terminal emulator or some other daemon process,
and can contain multiple words if quoted.
.Pp
The third field is the type of terminal usually connected to that
tty line, normally the one found in the
.Xr terminfo 5
data base file.
The environment variable
.Dv TERM
is initialized with the value by either
.Xr getty 8
or
.Xr login 1 .
.Pp
The remaining fields set flags in the
.Fa ty_status
entry (see
.Xr getttyent 3 )
or specify a window system process that
.Xr init 8
will maintain for the terminal line
or a key into a database of tty attributes (currently unused).
.Pp
.Bl -tag -width softcar
.It Sy on No or Sy off
.Xr init 8
should (or should not) execute the command given in the second field.
.It Sy secure
If
.Sy on
is specified, allows users with a uid of 0
.Pq e.g. Qq root
to login on this line.
.It Sy local
Sets the
.Dv TIOCFLAG_CLOCAL
.Xr tty 4
flag for the device.
This will cause the
.Xr termios 4
.Dv CLOCAL
flag to be set on every open and thus modem control signal lines will be
ignored by default.
.It Sy softcar
Causes the driver to ignore hardware carrier on the line (by setting the
.Dv TIOCFLAG_SOFTCAR
.Xr tty 4
flag).
.It Sy rtscts
Sets the
.Dv TIOCFLAG_CRTSCTS
.Xr tty 4
flag for the device to enable
.Tn RTS /
.Tn CTS
.Qq hardware
flow control by default.
.It Sy mdmbuf
Sets the
.Dv TIOCFLAG_MDMBUF
.Xr tty 4
flag for the device to enable
.Tn DTR /
.Tn DCD
.Qq hardware
flow control by default.
.El
.Pp
The flags
.Qq local ,
.Qq rtscts ,
.Qq mdmbuf ,
and
.Qq softcar
modify the default behaviour of the terminal line, and their actions
are device driver dependent.
These flag fields should not be quoted.
.Pp
The string ``window='' may be followed by a quoted command
string which
.Xr init 8
will execute
.Em before
starting the command specified by the second field.
.Pp
The string ``class='' may be followed by a quoted string used
as a key into a database of attributes for that category of tty.
See
.Xr getttynam 3
for more information on this feature.
.Pp
After changing the
.Nm
file a
.Dv SIGHUP
signal can be sent to
.Xr init 8
with the command
.Dq Li "kill \-s HUP 1" .
On receipt of this signal,
.Xr init 8
will re-read the
.Nm
file and spawn any necessary
.Xr getty 8
processes.
.Pp
.Sy Nota Bene :
Sending
.Dv SIGHUP
to
.Xr init 8
does
.Em not
change the state of the various
.Xr tty 4
device flags listed above; the
.Xr ttyflags 8
program must be run for changes in those flags to take effect on the devices.
.Sh FILES
.Bl -tag -width /etc/ttys -compact
.It Pa /etc/ttys
.El
.Sh EXAMPLES
.Bd -literal
# root login on console at 1200 baud
console "/usr/libexec/getty std.1200" vt100 on secure
# dialup at 1200 baud, no root logins
ttyd0 "/usr/libexec/getty d1200" dialup on # 555-1234
# Mike's terminal: hp2621
ttyh0 "/usr/libexec/getty std.9600" hp2621-nl on # 457 Evans
# John's terminal: vt100
ttyh1 "/usr/libexec/getty std.9600" vt100 on # 459 Evans
# terminal emulate/window system
ttyv0 "/usr/new/xterm -L :0" vs100 on window="/usr/new/Xvs100 0"
# Network pseudo ttys -- don't enable getty
ttyp0 none network
ttyp1 none network off
.Ed
.Sh SEE ALSO
.Xr login 1 ,
.Xr getttyent 3 ,
.Xr ttyslot 3 ,
.Xr tty 4 ,
.Xr gettytab 5 ,
.Xr terminfo 5 ,
.Xr getty 8 ,
.Xr init 8 ,
.Xr ttyflags 8
.Sh HISTORY
A
.Nm
file appeared in
.At v6 .