Initial checkin. These sources match those used to build the version

of the util shipped with GNO v2.0.4.
This commit is contained in:
gdr-ftp 1998-03-09 15:50:56 +00:00
parent 31e9970070
commit 451e159fb7
27 changed files with 3546 additions and 0 deletions

5
usr.sbin/cron/Makefile Normal file
View File

@ -0,0 +1,5 @@
cron.root: cron.c
compile -p cron.c keep=cron
cron: cron.root
link -p cron keep=cron

5
usr.sbin/cron/README Normal file
View File

@ -0,0 +1,5 @@
I converted cron to use syslog(). In my /etc/syslog.conf file, LOG_CRON
messages are configured to go in /var/log/cronlog. I modifed cron as a
demonstration of this.
- Phillip Vandry

48
usr.sbin/cron/cron.8 Normal file
View File

@ -0,0 +1,48 @@
CRON(8) UNIX Programmer's Manual CRON(8)
NAME
cron - clock daemon
SYNOPSIS
/usr/sbin/cron
DESCRIPTION
Cron executes commands at specified dates and times accord-
ing to the instructions in the file /etc/crontab (if it exists).
Since cron never exits, it should only be executed once. This
is best done by running cron from the initialization process
through the file /etc/inittab; see init(8).
The crontab file consists of lines of seven fields each.
The fields are separated by spaces or tabs. The first five
are integer patterns to specify:
o+ minute (0-59)
o+ hour (0-23)
o+ day of the month (1-31)
o+ month of the year (1-12)
o+ day of the week (1-7 with 1 = Monday)
Each of these patterns may contain:
o+ a number in the range above
o+ two numbers separated by a minus meaning a range inclusive
o+ a list of numbers separated by commas meaning any of the
numbers
o+ an asterisk meaning all legal values
The sixth field is a user name: the command will be run with
that user's uid and permissions. The seventh field consists
of all the text on a line following the sixth field, includ-
ing spaces and tabs; this text is treated as a command which
is executed by the Shell at the specified times. A percent
character (``%'') in this field is translated to a new-line
character.
The crontab file is checked by cron every minute, on the
minute.
FILES
/etc/crontab

324
usr.sbin/cron/cron.c Normal file
View File

@ -0,0 +1,324 @@
/* Converted to use syslog() by Phillip Vandry
#define NO_SYSLOG to get the old version */
#pragma stacksize 768
#pragma optimize -1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gno/gno.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <sys/syslog.h>
#include "pathnames.h"
#define DEBUG(x)
/* #define DEBUG(x) x */
#define MAX_INTLIST 10
#define IT_ITEM 0
#define IT_RANGE 1
#define IT_LIST 2
#define IT_ALL 3
#ifdef __ORCAC__
#define NL 13
#else
#define NL 10
#endif
typedef struct intlist {
int itype;
int count;
int intarr[MAX_INTLIST];
} intlist;
typedef struct ctentry {
struct ctentry *next;
intlist minute;
intlist hour;
intlist day;
intlist month;
intlist weekday;
char *user;
char *cmd;
} ctentry;
struct ctentry *crontab = NULL;
#ifdef NO_SYSLOG
FILE *cl;
void cronlog(char *s)
{
time_t t;
char *s1;
time(&t);
s1 = ctime(&t);
s1[strlen(s1)-1] = 0;
fprintf(cl,"%s: %s\n",s1,s);
}
#endif
void disposecrontab(void)
{
struct ctentry *x = crontab,*x2;
while (x) {
free(x->user);
free(x->cmd);
x2 = x->next;
free(x);
x = x2;
}
crontab = NULL;
}
char rcbuf[256];
int scanws(int i)
{
while (!(isspace(rcbuf[i]))) i++;
while (isspace(rcbuf[i])) i++;
return i;
}
int scan2ws(int i)
{
while ( !( isspace(rcbuf[i++]) ) );
return i;
}
int scandig(int i)
{
while ( isdigit(rcbuf[i])) i++;
return i;
}
int parseItem(int ind, struct intlist *i)
{
int nind;
int count;
if (rcbuf[ind] == '*')
i->itype = IT_ALL;
else {
i->itype = IT_ITEM;
sscanf(rcbuf+ind,"%d",&i->intarr[0]);
nind = scandig(ind);
if (rcbuf[nind] == ',') {
ind = nind;
count = 1;
while (rcbuf[ind] == ',') {
sscanf(rcbuf+ind+1,"%d",&i->intarr[count]);
ind = scandig(ind+1);
count++;
}
i->itype = IT_LIST;
i->count = count;
}
else if (rcbuf[nind] == '-') {
sscanf(rcbuf+nind+1,"%d",&i->intarr[1]);
ind = nind;
i->itype = IT_RANGE;
}
}
return scanws(ind);
}
void readcrontab(void)
{
FILE *ct;
ctentry *n;
int ind,nind;
if (crontab) disposecrontab();
retry:
ct = fopen(PATH_crontab,"r");
if (ct == NULL) {
#ifndef NO_SYSLOG
syslog(LOG_ERR, "couldn't open crontab");
#else
perror("couldn't open crontab");
cronlog("couldn't open crontab");
#endif
sleep(30);
goto retry;
}
while (!feof(ct)) {
if (fgets(rcbuf,255,ct) == NULL) break;
DEBUG(fprintf(stderr,"gotline %s",rcbuf));
if (rcbuf[0] == '#') continue;
if (strlen(rcbuf) < 2) continue;
rcbuf[strlen(rcbuf)-1] = 0;
n = malloc(sizeof(ctentry));
if (crontab) n->next = crontab;
else n->next = NULL;
crontab = n;
ind = parseItem(0,&n->minute);
ind = parseItem(ind,&n->hour);
ind = parseItem(ind,&n->day);
ind = parseItem(ind,&n->month);
ind = parseItem(ind,&n->weekday);
nind = scan2ws(ind);
n->user = malloc(nind-ind+1);
memcpy(n->user,rcbuf+ind,nind-ind);
n->user[nind-ind] = 0;
ind = scanws(ind);
n->cmd = malloc(strlen(rcbuf)-ind+1);
strcpy(n->cmd,rcbuf+ind);
for (ind = 0; ind < strlen(n->cmd); ind++)
if (n->cmd[ind] == '%') n->cmd[ind] = NL;
rcbuf[0] = rcbuf[1] = 0;
}
fclose(ct);
}
int matchItem(struct intlist *i,int t)
{
int p;
if (i->itype == IT_ALL) return 1;
else if (i->itype == IT_ITEM) {
if (t == i->intarr[0]) return 1;
else return 0;
}
else if (i->itype == IT_RANGE) {
if ((t >= i->intarr[0]) && (t <= i->intarr[1]))
return 1;
else return 0;
}
else if (i->itype == IT_LIST) {
for (p = 0; p < i->count; p++)
if (i->intarr[p] == t) return 1;
return 0;
}
}
int matchTime(ctentry *x,struct tm *t)
{
if (matchItem(&x->minute,t->tm_min) &&
matchItem(&x->hour,t->tm_hour) &&
matchItem(&x->day,t->tm_mday) &&
matchItem(&x->month,t->tm_mon) /* &&
matchItem(&x->weekday,t->tm_wday) */ )
return 1;
return 0;
}
void printItem(struct intlist *i)
{
int p;
if (i->itype == IT_ALL) fprintf(stderr,"* ");
else if (i->itype == IT_ITEM)
fprintf(stderr,"%d ",i->intarr[0]);
else if (i->itype == IT_RANGE)
fprintf(stderr,"%d-%d",i->intarr[0],i->intarr[1]);
else if (i->itype == IT_LIST) {
fprintf(stderr,"%d",i->intarr[0]);
for (p = 1; p < i->count; p++)
fprintf(stderr,",%d",i->intarr[p]);
}
}
void docrontab(void)
{
struct tm *t;
time_t t1;
ctentry *x = crontab;
char *cmdpath;
word ind = 0;
t1 = time(NULL);
t = localtime(&t1);
if (x == NULL) { /* syslog(LOG_NOTICE, "crontab empty");*/ return; }
while (x) {
DEBUG(printItem(&x->minute));
DEBUG(printItem(&x->hour));
DEBUG(printItem(&x->day));
DEBUG(printItem(&x->month));
DEBUG(printItem(&x->weekday));
DEBUG(fprintf(stderr,":%s \n",x->cmd));
if (matchTime(x,t)) {
DEBUG(fprintf(stderr,"matched!\n"));
ind = strpos(x->cmd,' ');
if (ind == -1) ind = strlen(x->cmd);
cmdpath = malloc(ind+1);
memcpy(cmdpath,x->cmd,ind);
cmdpath[ind] = 0;
exec(cmdpath,x->cmd);
}
x = x->next;
}
}
int main(int argc, char *argv[])
{
time_t ct_mod,start_time;
unsigned int i;
struct tm *exptime;
static struct stat sb;
int sl;
/* Previously this was a for. ORCA/C didn't compile that right, though.
This generates more efficient code anyway */
i = 3;
while (++i < 20) close(i);
#ifndef NO_SYSLOG
openlog(NULL, 0, LOG_CRON);
#else
cl = fopen(PATH_cronlog,"a");
if (!cl) {
perror("cron: couldn't open cronlog file");
exit(1);
}
#endif
/* turn off buffering so cronlog is up-to-date in the event of a
* system crash
*/
#ifdef NO_SYSLOG
setvbuf(cl,NULL,_IONBF,0l);
cronlog("cron started up");
#else
syslog(LOG_INFO, "cron started up");
#endif
/*
* start cron sessions on or near an exact minute
* (giving 2 seconds leeway for 'bounce')
*/
start_time = time(NULL);
exptime = localtime(&start_time);
sleep(62 - exptime->tm_sec);
#pragma optimize 0 /* ORCA/C has problems... */
ct_mod = 0l;
while (1) {
DEBUG(fprintf(stderr,"loop\n"));
stat(PATH_crontab,&sb);
if (sb.st_mtime != ct_mod) {
ct_mod = sb.st_mtime;
readcrontab();
}
#pragma optimize 1
docrontab();
/*
* account for the time we spent loading/parsing/executing
*/
start_time = time(NULL);
exptime = localtime(&start_time);
sl = 61-exptime->tm_sec;
/*while (sl < 0) sl+=60;*/
DEBUG(fprintf(stderr,"sleep: %d\n",sl));
sleep(sl);
}
}

3
usr.sbin/cron/cronlog Normal file
View File

@ -0,0 +1,3 @@
Sat Jan 30 06:30:26 1993: cron started up
Sat Jan 30 06:30:33 1993: cron started up
Sun Jan 31 07:43:51 1993: cron started up

BIN
usr.sbin/cron/crontab Normal file

Binary file not shown.

View File

@ -0,0 +1,2 @@
#define PATH_crontab "/etc/crontab"
#define PATH_cronlog "/etc/cronlog"

17
usr.sbin/getty/Makefile Normal file
View File

@ -0,0 +1,17 @@
main.a: main.c pathnames.h
compile -i main.c keep=main
init.a: init.c pathnames.h
compile -i init.c keep=init
subr.a: subr.c
compile -i subr.c keep=subr
gettytab.a: gettytab.c pathnames.h
compile -i +w gettytab.c keep=gettytab
ttydflts.a: ttydefaults.c
compile -i ttydefaults.c keep=ttydflts
getty: main.c init.c subr.c gettytab.c ttydefaults.c
compile linkfile

View File

@ -0,0 +1,145 @@
GNO Manual Addendum
-------------------
This file contains information on parts of GNO that changed after
the documentation was printed.
Known Bugs
----------
The default gshrc file created by the installer generates a $HOME
directory that uses colon delimiters (e.g., :hd1:gno:user:root). A bug
in handling the ~ character causes attempts to, for example, "ls ~/foo"
to fail, because that gets interpreted as "ls :hd1:gno:user:root/foo",
where the system interprets "root/foo" as a single filename. You should
either change the gshrc file to use '/' delimiters, or use the ':'
delimiter when also using ~ (i.e., "ls ~:foo")
Getty (2.0.3)
-------------
The 'getty' program provided with GNO 2.0.3 and later has a new feature and
a fixed bug.
o Getty used to overrun its stack space in ways that were hard to
detect; this has been fixed
o There is a new type of entry in the gettytab file:
P|8bit.9600|9600-baud-8bit|8bit:\
:sp#9600:p8:tt=vt100:hu#8:
The 'hu#' entry represents the RS232 signal line that is to be
used as carrier detect, and thus will cause a SIGHUP signal to
be sent to the processes running on that port. In this example,
'8' indicates a '1' in bit 3 of the following byte:
[7] break/abort
[6] tx underrun
* [5] DSR (input handshake line)
[4] reserved
* [3] DCD (general purpose input line)
[2] tx buff empty
[1] reserved
[0] rx char available
The only lines that have any meaning are marked with '*'s. The
default line is #5 (value 32) due to the strange wiring of some
modem cables. Setting this value to zero (0) turns off hangup
checking completely.
How to Control Serial Ports with stty
-------------------------------------
'stty' is short for 'set tty parameters', and can be used to control
various aspects of the serial ports and other terminal devices.
stty modifies the parameters of the terminal that stty's standard input
references; e.g., to modify .ttya parameters, do something like this:
stty ... < .ttya
To set the baud rate, simply enter the baud rate you want on the command line.
e.g., to set the printer port's baud rate to 19200 baud, do
stty 19200 <.ttyb
The various other parameters that stty supports are described in the tty(4)
manual page.
How to use the Multi-User package
---------------------------------
If you choose to install the multi-user package, the nature of the GNO
system changes quite a bit. First off, instead of GNO simply being a shell
on your IIGS's screen, the console becomes a terminal through which you
can log into the system.
When you start GNO after installing the MU package, you'll see some intro
text (terminal name, and name of the computer), and then a 'login' prompt.
At this prompt, users type in their unique user names (and normally a
password) to gain entry to your computer. GNO comes with one user already
configured : 'root'. To get into GNO the first time, type 'root' at the
login prompt. No password is set by default, so you won't be asked for one.
If you want to protect entry to your computer with a password, use the 'passwd'
command to change your password.
% passwd
You'll be prompted for your old password, which is nothing - so hit return.
Then you type in the new password - twice, to make sure you entered it
correctly. This is done because, sensibly, when entering a password the
keys you type are not echoed on the screen.
Don't forget your password! If you do, you'll have to manually edit the
/etc/passwd file, and delete the second field; the one right after the username
and a colon (:), and that looks like gibberish because it's encrypted. Delete
everything between the two colons to remove the password.
There are two ways to exit GNO with the MU package installed; simply typing
'exit' at the shell will only return to the login prompt.
'init 5' at the shell will cause GNO to shut down and return to the program
launcher you used to run GNO (usually the Finder).
'init 0' will shut down GNO and will reboot your computer.
There is a file that contains a log of activity on the system, including
bad attempts to log in. This file is /var/adm/syslog. Typing
'more /var/adm/syslog' from the shell will display the contents of this file.
Other applications may also use the syslog file to record notable events.
How to use the line printer daemon
(or, lpr is your friend)
----------------------------------
The print spooling system included with GNO is very versatile because it
takes advantage of GNO's multitasking capabilities. Anyone can write a program
that communicates with lpd (line printer daemon) to spool a print job. At
this time the communication specification is not yet available; contact Procyon
for more information.
You must start lpd differently depending on whether you're using the MU package
or using GNO in single-user mode. For single-user, simply type
/usr/sbin/lpd &
To start the spooler process.
With MU, simply uncomment (remove the '#') the line in the /etc/inittab file
corresponding to lpd. Then, lpd will be started automatically whenever you
run GNO. Note that either way you start lpd, it is currently limited to
using the printer baud rate specified in the IIGS control panel, and to
using serial printers. lpd does not work with laser printers hooked up via
an AppleTalk network. It also requires you to use the printer port.
There are currently two programs that use lpd; lpr, and FilePort. lpr is
the standard UNIX 'print a text file' program. Typing
lpr file1 file2 ...
will print the text files you list, adding headers and page numbers.
FilePort is a GS/OS printer driver that works with desktop applications.
To turn it on, use the Control Panel NDA, select 'DC Printer', and choose
your printer type and 'FilePort' (for 'Port').
From then on, whenever you print from a desktop program in GNO, the output
will be spooled. If you wish to print from outside GNO, you will have to
choose the regular port driver again in the Control Panel NDA (usually
'Printer').

127
usr.sbin/getty/getty.8 Normal file
View File

@ -0,0 +1,127 @@
.\" 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
.\" 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.
.\"
.\" @(#)getty.8 6.6 (Berkeley) 4/25/91
.\"
.Dd April 25, 1991
.Dt GETTY 8
.Os BSD 4
.Sh NAME
.Nm getty
.Nd set terminal mode
.Sh SYNOPSIS
.Nm getty
.Oo
.Ar type
.Op Ar tty
.Oc
.Sh DESCRIPTION
The
.Nm getty
program
is called by
.Xr init 8
to open and initialize the tty line, read a login name, and invoke
.Xr login 1 .
.Pp
The argument
.Ar tty
is the special device file in
.Pa /dev
to open for the terminal (for example, ``ttyh0'').
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 getty
treat the terminal line specially.
This argument is used as an index into the
.Nm 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 getty
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
Most of the default actions of
.Nm getty
can be circumvented, or modified, by a suitable
.Nm gettytab
table.
.Pp
The
.Nm getty
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.
.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
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 FILES
.Bl -tag -width /etc/gettytab -compact
.It Pa /etc/gettytab
.El
.Sh SEE ALSO
.Xr gettytab 5 ,
.Xr init 8 ,
.Xr login 1 ,
.Xr ioctl 2 ,
.Xr tty 4 ,
.Xr ttys 5
.Sh HISTORY
A
.Nm getty
program appeared in
.At v6 .

323
usr.sbin/getty/gettytab.5 Normal file
View File

@ -0,0 +1,323 @@
.\" 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
.\" 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.
.\"
.\" @(#)gettytab.5 6.7 (Berkeley) 5/10/91
.\"
.Dd May 10, 1991
.Dt GETTYTAB 5
.Os BSD 4.2
.Sh NAME
.Nm gettytab
.Nd terminal configuration data base
.Sh SYNOPSIS
.Nm gettytab
.Sh DESCRIPTION
The
.Nm gettytab
file
is a simplified version of the
.Xr termcap 5
data base
used to describe terminal lines.
The initial terminal login process
.Xr getty 8
accesses the
.Nm gettytab
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
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.)
.Sh CAPABILITIES
Refer to
.Xr termcap 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 "ap bool false terminal uses any parity"
.It "bd num 0 backspace delay"
.It "bk str 0377 alternate end of line character (input break)"
.It "cb bool false use crt backspace mode"
.It "cd num 0 carriage-return delay"
.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 \en
after login prompt
.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 enviroment"
.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 "fd num 0 form-feed (vertical motion) delay"
.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 "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 "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 "nd num 0 newline (line-feed) delay"
.It "nl bool false terminal has (or might have) a newline character"
.It "nx str default next table (for auto speed selection)"
.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 "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 "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 "uc bool false terminal is known upper case only"
.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
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 overriden
with one of the
.Em \&f0 ,
.Em \&f1 ,
or
.Em \&f2
numeric specifications, which can be used to specify
(usually in octal, with a leading '0')
the exact values of the flags.
Local (new tty) flags are set in the top 16 bits
of this (32 bit) value.
.Pp
Should
.Xr getty
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 the character sequence
.Em \&%h
or
.Em \&%t
to obtain
the hostname or tty name respectively.
.Pf ( Em %%
obtains a single '%' character.)
The hostname is normally obtained from the system,
but may be set by the
.Em \&hn
table entry.
In either case it may be edited with
.Em \&he .
The
.Em \&he
string is a sequence of characters, each character that
is neither '@' nor '#' is copied into the final hostname.
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.
Surplus '@' and '#' characters are ignored.
.Pp
When getty execs the login process, given
in the
.Em \&lo
string (usually
.Dq Pa /usr/bin/login ) ,
it will have set
the enviroment 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 ,
or having received an alarm signal, and exited.
This may be useful to hangup dial in lines.
.Pp
Output from
.Xr getty
is even parity unless
.Em \&op
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
does not check parity of input characters in
.Dv RAW
mode.
.Sh SEE ALSO
.Xr login 1 ,
.Xr termcap 5 ,
.Xr getty 8 .
.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 form 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.
.Pp
The
.Xr termcap
format is horrid, something more rational should
have been chosen.
.Sh HISTORY
The
.Nm gettytab
file format appeared in 4.2BSD.

354
usr.sbin/getty/gettytab.c Normal file
View File

@ -0,0 +1,354 @@
/*#pragma debug 25*/
/*#define BUG(__s) {fprintf(stderr,"%s\n",__s);}*/
#define BUG(__s)
#pragma optimize 31
/*
* 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
* 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
static char sccsid[] = "@(#)gettytab.c 5.5 (Berkeley) 2/25/91";
#endif /* not lint */
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "pathnames.h"
#define TABBUFSIZ 512
static char *tbuf;
int hopcount; /* detect infinite loops in termcap, init 0 */
char *skip();
char *getstr();
char *decode();
/*
* Get an entry for terminal name in buffer bp,
* from the termcap file. Parse is very rudimentary;
* we just notice escaped newlines.
*/
getent(bp, name)
char *bp, *name;
{
register char *cp;
register int c;
register int i = 0, cnt = 0;
static char ibuf[TABBUFSIZ];
char *cp2;
int tf;
tbuf = bp;
tf = open(_PATH_GETTYTAB, O_RDONLY);
if (tf < 0)
return (-1);
for (;;) {
cp = bp;
for (;;) {
if (i == cnt) {
cnt = read(tf, ibuf, TABBUFSIZ);
if (cnt <= 0) {
close(tf);
return (0);
}
i = 0;
}
c = ibuf[i++];
if (c == '\n' || c == '\r') {
if (cp > bp && cp[-1] == '\\'){
cp--;
continue;
}
break;
}
if (cp >= bp+TABBUFSIZ) {
write(STDERR_FILENO,"Gettytab entry too long\n", 24);
break;
} else
*cp++ = c;
}
*cp = 0;
/*
* The real work for the match.
*/
if (namatch(name)) {
close(tf);
return(nchktc());
}
}
}
/*
* tnchktc: check the last entry, see if it's tc=xxx. If so,
* recursively find xxx and append that entry (minus the names)
* to take the place of the tc=xxx entry. This allows termcap
* entries to say "like an HP2621 but doesn't turn on the labels".
* Note that this works because of the left to right scan.
*/
#define MAXHOP 32
nchktc()
{
register char *p, *q;
char tcname[16]; /* name of similar terminal */
char *tcbuf;
/*char tcbuf[TABBUFSIZ];*/
char *holdtbuf = tbuf;
int l;
tcbuf = malloc(TABBUFSIZ);
p = tbuf + strlen(tbuf) - 2; /* before the last colon */
while (*--p != ':')
if (p<tbuf) {
write(STDERR_FILENO, "Bad gettytab entry\n", 19);
free(tcbuf);
return (0);
}
p++;
/* p now points to beginning of last field */
if (p[0] != 't' || p[1] != 'c') {
free(tcbuf);
return(1);
}
strcpy(tcname,p+3);
q = tcname;
while (q && *q != ':')
q++;
*q = 0;
if (++hopcount > MAXHOP) {
write(STDERR_FILENO, "Getty: infinite tc= loop\n", 25);
free(tcbuf);
return (0);
}
if (getent(tcbuf, tcname) != 1) {
free(tcbuf);
return(0);
}
for (q=tcbuf; *q != ':'; q++)
;
l = p - holdtbuf + strlen(q);
if (l > TABBUFSIZ) {
write(STDERR_FILENO, "Gettytab entry too long\n", 24);
q[TABBUFSIZ - (p-tbuf)] = 0;
}
strcpy(p, q+1);
tbuf = holdtbuf;
free(tcbuf);
return(1);
}
/*
* Tnamatch deals with name matching. The first field of the termcap
* entry is a sequence of names separated by |'s, so we compare
* against each such name. The normal : terminator after the last
* name (before the first field) stops us.
*/
namatch(char *np)
{
register char *Np, *Bp;
Bp = tbuf;
if (*Bp == '#')
return(0);
for (;;) {
for (Np = np; *Np && *Bp == *Np; Bp++, Np++)
continue;
if (*Np == 0 && (*Bp == '|' || *Bp == ':' || *Bp == 0))
return (1);
while (*Bp && *Bp != ':' && *Bp != '|')
Bp++;
if (*Bp == 0 || *Bp == ':')
return (0);
Bp++;
}
}
/*
* Skip to the next field. Notice that this is very dumb, not
* knowing about \: escapes or any such. If necessary, :'s can be put
* into the termcap file in octal.
*/
static char *
skip(bp)
register char *bp;
{
while (*bp && *bp != ':')
bp++;
if (*bp == ':')
bp++;
return (bp);
}
/*
* Return the (numeric) option id.
* Numeric options look like
* li#80
* i.e. the option string is separated from the numeric value by
* a # character. If the option is not found we return -1.
* Note that we handle octal numbers beginning with 0.
*/
long
getnum(id)
char *id;
{
register long i, base;
register char *bp = tbuf;
for (;;) {
bp = skip(bp);
if (*bp == 0)
return (-1);
if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
continue;
if (*bp == '@')
return(-1);
if (*bp != '#')
continue;
bp++;
base = 10;
if (*bp == '0')
base = 8;
i = 0;
while (isdigit(*bp))
i *= base, i += *bp++ - '0';
return (i);
}
}
/*
* Handle a flag option.
* Flag options are given "naked", i.e. followed by a : or the end
* of the buffer. Return 1 if we find the option, or 0 if it is
* not given.
*/
getflag(id)
char *id;
{
register char *bp = tbuf;
for (;;) {
bp = skip(bp);
if (!*bp)
return (-1);
if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) {
if (!*bp || *bp == ':')
return (1);
else if (*bp == '!')
return (0);
else if (*bp == '@')
return(-1);
}
}
}
/*
* Get a string valued option.
* These are given as
* cl=^Z
* Much decoding is done on the strings, and the strings are
* placed in area, which is a ref parameter which is updated.
* No checking on area overflow.
*/
char *
getstr(id, area)
char *id, **area;
{
register char *bp = tbuf;
for (;;) {
bp = skip(bp);
if (!*bp)
return (0);
if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
continue;
if (*bp == '@')
return(0);
if (*bp != '=')
continue;
bp++;
return (decode(bp, area));
}
}
/*
* Tdecode does the grung work to decode the
* string capability escapes.
*/
static char *
decode(str, area)
register char *str;
char **area;
{
register char *cp;
register int c;
register char *dp;
int i;
cp = *area;
while ((c = *str++) && c != ':') {
switch (c) {
case '^':
c = *str++ & 037;
break;
case '\\':
dp = "E\033^^\\\\::n\nr\rt\tb\bf\f";
c = *str++;
nextc:
if (*dp++ == c) {
c = *dp++;
break;
}
dp++;
if (*dp)
goto nextc;
if (isdigit(c)) {
c -= '0', i = 2;
do
c <<= 3, c |= *str++ - '0';
while (--i && isdigit(*str));
}
break;
}
*cp++ = c;
}
*cp++ = 0;
str = *area;
*area = cp;
return (str);
}

147
usr.sbin/getty/gettytab.h Normal file
View File

@ -0,0 +1,147 @@
/*
* 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
* 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.
*
* @(#)gettytab.h 5.5 (Berkeley) 3/27/91
*/
/*
* 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 */
};
/*
* 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
/*
* 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 HU gettynums[13].value
#define HUset gettynums[13].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[2].set
#define AP gettyflags[4].value
#define APset gettyflags[2].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
int getent();
long getnum();
int getflag();
char *getstr();
extern struct gettyflags gettyflags[];
extern struct gettynums gettynums[];
extern struct gettystrs gettystrs[];
extern int hopcount;

122
usr.sbin/getty/init.c Normal file
View File

@ -0,0 +1,122 @@
/*
* 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
* 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
static char sccsid[] = "@(#)init.c 5.6 (Berkeley) 3/27/91";
#endif /* not lint */
<