Home | History | Annotate | Line # | Download | only in getty
main.c revision 1.26
      1  1.26      mrg /*	$NetBSD: main.c,v 1.26 1998/07/06 06:48:19 mrg Exp $	*/
      2  1.18  thorpej 
      3   1.1      cgd /*-
      4   1.8       pk  * Copyright (c) 1980, 1993
      5   1.8       pk  *	The Regents of the University of California.  All rights reserved.
      6   1.1      cgd  *
      7   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1      cgd  * modification, are permitted provided that the following conditions
      9   1.1      cgd  * are met:
     10   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1      cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1      cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1      cgd  *    must display the following acknowledgement:
     17   1.1      cgd  *	This product includes software developed by the University of
     18   1.1      cgd  *	California, Berkeley and its contributors.
     19   1.1      cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1      cgd  *    may be used to endorse or promote products derived from this software
     21   1.1      cgd  *    without specific prior written permission.
     22   1.1      cgd  *
     23   1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1      cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1      cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1      cgd  * SUCH DAMAGE.
     34   1.1      cgd  */
     35   1.1      cgd 
     36  1.22    mikel #include <sys/cdefs.h>
     37  1.22    mikel 
     38   1.1      cgd #ifndef lint
     39  1.22    mikel __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
     40  1.22    mikel 	The Regents of the University of California.  All rights reserved.\n");
     41   1.1      cgd #endif /* not lint */
     42   1.1      cgd 
     43   1.1      cgd #ifndef lint
     44  1.18  thorpej #if 0
     45  1.18  thorpej static char sccsid[] = "from: @(#)main.c	8.1 (Berkeley) 6/20/93";
     46  1.18  thorpej #else
     47  1.26      mrg __RCSID("$NetBSD: main.c,v 1.26 1998/07/06 06:48:19 mrg Exp $");
     48  1.18  thorpej #endif
     49   1.1      cgd #endif /* not lint */
     50   1.1      cgd 
     51   1.1      cgd #include <sys/param.h>
     52   1.1      cgd #include <sys/stat.h>
     53  1.14      jtc #include <termios.h>
     54   1.7       pk #include <sys/ioctl.h>
     55   1.8       pk #include <sys/resource.h>
     56   1.3  mycroft #include <sys/utsname.h>
     57  1.21    mikel 
     58  1.15      cgd #include <errno.h>
     59   1.1      cgd #include <fcntl.h>
     60   1.1      cgd #include <time.h>
     61   1.1      cgd #include <ctype.h>
     62   1.8       pk #include <fcntl.h>
     63  1.23      cjs #include <pwd.h>
     64   1.1      cgd #include <setjmp.h>
     65   1.8       pk #include <signal.h>
     66   1.8       pk #include <stdlib.h>
     67   1.8       pk #include <string.h>
     68   1.1      cgd #include <syslog.h>
     69   1.8       pk #include <time.h>
     70   1.1      cgd #include <unistd.h>
     71  1.17      jtc #include <util.h>
     72   1.8       pk 
     73   1.1      cgd #include "gettytab.h"
     74   1.1      cgd #include "pathnames.h"
     75   1.8       pk #include "extern.h"
     76   1.8       pk 
     77  1.23      cjs extern char *__progname;
     78  1.23      cjs 
     79   1.8       pk /*
     80   1.8       pk  * Set the amount of running time that getty should accumulate
     81   1.8       pk  * before deciding that something is wrong and exit.
     82   1.8       pk  */
     83   1.8       pk #define GETTY_TIMEOUT	60 /* seconds */
     84   1.1      cgd 
     85   1.8       pk struct termios tmode, omode;
     86   1.1      cgd 
     87   1.1      cgd int crmod, digit, lower, upper;
     88   1.1      cgd 
     89  1.26      mrg char	hostname[MAXHOSTNAMELEN + 1];
     90   1.3  mycroft struct	utsname kerninfo;
     91   1.1      cgd char	name[16];
     92   1.1      cgd char	dev[] = _PATH_DEV;
     93   1.1      cgd char	ttyn[32];
     94  1.23      cjs char	lockfile[512];
     95  1.23      cjs uid_t	ttyowner;
     96   1.1      cgd 
     97   1.1      cgd #define	OBUFSIZ		128
     98   1.1      cgd #define	TABBUFSIZ	512
     99   1.1      cgd 
    100   1.1      cgd char	defent[TABBUFSIZ];
    101   1.1      cgd char	tabent[TABBUFSIZ];
    102   1.1      cgd 
    103   1.1      cgd char	*env[128];
    104   1.1      cgd 
    105   1.1      cgd char partab[] = {
    106   1.1      cgd 	0001,0201,0201,0001,0201,0001,0001,0201,
    107   1.1      cgd 	0202,0004,0003,0205,0005,0206,0201,0001,
    108   1.1      cgd 	0201,0001,0001,0201,0001,0201,0201,0001,
    109   1.1      cgd 	0001,0201,0201,0001,0201,0001,0001,0201,
    110   1.1      cgd 	0200,0000,0000,0200,0000,0200,0200,0000,
    111   1.1      cgd 	0000,0200,0200,0000,0200,0000,0000,0200,
    112   1.1      cgd 	0000,0200,0200,0000,0200,0000,0000,0200,
    113   1.1      cgd 	0200,0000,0000,0200,0000,0200,0200,0000,
    114   1.1      cgd 	0200,0000,0000,0200,0000,0200,0200,0000,
    115   1.1      cgd 	0000,0200,0200,0000,0200,0000,0000,0200,
    116   1.1      cgd 	0000,0200,0200,0000,0200,0000,0000,0200,
    117   1.1      cgd 	0200,0000,0000,0200,0000,0200,0200,0000,
    118   1.1      cgd 	0000,0200,0200,0000,0200,0000,0000,0200,
    119   1.1      cgd 	0200,0000,0000,0200,0000,0200,0200,0000,
    120   1.1      cgd 	0200,0000,0000,0200,0000,0200,0200,0000,
    121   1.1      cgd 	0000,0200,0200,0000,0200,0000,0000,0201
    122   1.1      cgd };
    123   1.1      cgd 
    124   1.7       pk #define	ERASE	tmode.c_cc[VERASE]
    125   1.7       pk #define	KILL	tmode.c_cc[VKILL]
    126   1.7       pk #define	EOT	tmode.c_cc[VEOF]
    127   1.1      cgd 
    128  1.22    mikel static void	dingdong __P((int));
    129  1.22    mikel static void	interrupt __P((int));
    130  1.22    mikel void		timeoverrun __P((int));
    131  1.22    mikel 
    132   1.1      cgd jmp_buf timeout;
    133   1.1      cgd 
    134   1.1      cgd static void
    135  1.22    mikel dingdong(signo)
    136  1.22    mikel 	int signo;
    137   1.1      cgd {
    138   1.1      cgd 
    139   1.1      cgd 	alarm(0);
    140   1.1      cgd 	signal(SIGALRM, SIG_DFL);
    141   1.1      cgd 	longjmp(timeout, 1);
    142   1.1      cgd }
    143   1.1      cgd 
    144   1.1      cgd jmp_buf	intrupt;
    145   1.1      cgd 
    146   1.1      cgd static void
    147  1.22    mikel interrupt(signo)
    148  1.22    mikel 	int signo;
    149   1.1      cgd {
    150   1.1      cgd 
    151   1.1      cgd 	signal(SIGINT, interrupt);
    152   1.1      cgd 	longjmp(intrupt, 1);
    153   1.1      cgd }
    154   1.1      cgd 
    155   1.8       pk /*
    156   1.8       pk  * Action to take when getty is running too long.
    157   1.8       pk  */
    158   1.8       pk void
    159   1.8       pk timeoverrun(signo)
    160   1.8       pk 	int signo;
    161   1.8       pk {
    162   1.8       pk 
    163   1.8       pk 	syslog(LOG_ERR, "getty exiting due to excessive running time\n");
    164   1.8       pk 	exit(1);
    165   1.8       pk }
    166   1.8       pk 
    167  1.22    mikel int		main __P((int, char **));
    168   1.8       pk static int	getname __P((void));
    169   1.8       pk static void	oflush __P((void));
    170   1.8       pk static void	prompt __P((void));
    171   1.8       pk static void	putchr __P((int));
    172  1.24  thorpej static void	putf __P((const char *));
    173  1.24  thorpej static void	putpad __P((const char *));
    174  1.24  thorpej static void	xputs __P((const char *));
    175   1.8       pk 
    176   1.8       pk int
    177   1.1      cgd main(argc, argv)
    178   1.1      cgd 	int argc;
    179   1.8       pk 	char *argv[];
    180   1.1      cgd {
    181   1.8       pk 	extern char **environ;
    182   1.1      cgd 	char *tname;
    183  1.23      cjs 	int repcnt = 0, failopenlogged = 0, uugetty = 0;
    184   1.8       pk 	struct rlimit limit;
    185  1.23      cjs 	struct passwd *pw;
    186   1.1      cgd 
    187  1.22    mikel #ifdef __GNUC__
    188  1.22    mikel 	(void)&tname;		/* XXX gcc -Wall */
    189  1.22    mikel #endif
    190  1.22    mikel 
    191   1.1      cgd 	signal(SIGINT, SIG_IGN);
    192   1.1      cgd /*
    193   1.1      cgd 	signal(SIGQUIT, SIG_DFL);
    194   1.1      cgd */
    195  1.26      mrg 	openlog("getty", LOG_ODELAY|LOG_PID, LOG_AUTH);
    196   1.1      cgd 	gethostname(hostname, sizeof(hostname));
    197  1.26      mrg 	hostname[sizeof(hostname) - 1] = '\0';
    198   1.1      cgd 	if (hostname[0] == '\0')
    199   1.1      cgd 		strcpy(hostname, "Amnesiac");
    200   1.3  mycroft 	uname(&kerninfo);
    201   1.8       pk 
    202  1.23      cjs 	if (__progname[0] == 'u' && __progname[1] == 'u')
    203  1.23      cjs 		uugetty = 1;
    204  1.23      cjs 
    205  1.23      cjs 	/*
    206  1.23      cjs 	 * Find id of uucp login (if present) so we can chown tty properly.
    207  1.23      cjs 	 */
    208  1.23      cjs 	if (uugetty && (pw = getpwnam("uucp")))
    209  1.23      cjs 		ttyowner = pw->pw_uid;
    210  1.23      cjs 	else
    211  1.23      cjs 		ttyowner = 0;
    212  1.23      cjs 
    213   1.8       pk 	/*
    214   1.8       pk 	 * Limit running time to deal with broken or dead lines.
    215   1.8       pk 	 */
    216   1.8       pk 	(void)signal(SIGXCPU, timeoverrun);
    217   1.8       pk 	limit.rlim_max = RLIM_INFINITY;
    218   1.8       pk 	limit.rlim_cur = GETTY_TIMEOUT;
    219   1.8       pk 	(void)setrlimit(RLIMIT_CPU, &limit);
    220   1.8       pk 
    221   1.1      cgd 	/*
    222   1.1      cgd 	 * The following is a work around for vhangup interactions
    223   1.1      cgd 	 * which cause great problems getting window systems started.
    224   1.1      cgd 	 * If the tty line is "-", we do the old style getty presuming
    225   1.1      cgd 	 * that the file descriptors are already set up for us.
    226   1.1      cgd 	 * J. Gettys - MIT Project Athena.
    227   1.1      cgd 	 */
    228  1.20      tls 	if (argc <= 2 || strcmp(argv[2], "-") == 0) {
    229  1.20      tls 	    strncpy(ttyn, ttyname(0), 32);
    230  1.20      tls 	    ttyn[31] = (char)NULL;
    231  1.20      tls 	}
    232   1.1      cgd 	else {
    233   1.1      cgd 	    int i;
    234   1.1      cgd 
    235   1.1      cgd 	    strcpy(ttyn, dev);
    236   1.1      cgd 	    strncat(ttyn, argv[2], sizeof(ttyn)-sizeof(dev));
    237  1.23      cjs 
    238  1.23      cjs 	    if (uugetty)  {
    239  1.23      cjs 		chown(ttyn, ttyowner, 0);
    240  1.23      cjs 		strcpy(lockfile, _PATH_LOCK);
    241  1.23      cjs 		strncat(lockfile, argv[2], sizeof(lockfile)-sizeof(_PATH_LOCK));
    242  1.23      cjs 		/* wait for lockfiles to go away before we try to open */
    243  1.23      cjs 		if ( pidlock(lockfile, 0, 0, 0) != 0 )  {
    244  1.23      cjs 		    syslog(LOG_ERR, "%s: can't create lockfile", ttyn);
    245  1.23      cjs 		    exit(1);
    246  1.23      cjs 		}
    247  1.23      cjs 		unlink(lockfile);
    248  1.23      cjs 	    }
    249   1.1      cgd 	    if (strcmp(argv[0], "+") != 0) {
    250  1.23      cjs 		chown(ttyn, ttyowner, 0);
    251   1.1      cgd 		chmod(ttyn, 0600);
    252   1.1      cgd 		revoke(ttyn);
    253  1.19      gwr 		if (ttyaction(ttyn, "getty", "root"))
    254  1.19      gwr 			syslog(LOG_ERR,"%s: ttyaction failed", ttyn);
    255   1.1      cgd 		/*
    256   1.1      cgd 		 * Delay the open so DTR stays down long enough to be detected.
    257   1.1      cgd 		 */
    258   1.1      cgd 		sleep(2);
    259   1.1      cgd 		while ((i = open(ttyn, O_RDWR)) == -1) {
    260  1.15      cgd 			if ((repcnt % 10 == 0) &&
    261  1.15      cgd 			    (errno != ENXIO || !failopenlogged)) {
    262   1.1      cgd 				syslog(LOG_ERR, "%s: %m", ttyn);
    263   1.1      cgd 				closelog();
    264  1.15      cgd 				failopenlogged = 1;
    265   1.1      cgd 			}
    266   1.1      cgd 			repcnt++;
    267   1.1      cgd 			sleep(60);
    268   1.1      cgd 		}
    269  1.23      cjs 		if (uugetty && pidlock(lockfile, 0, 0, 0) != 0)  {
    270  1.23      cjs 			syslog(LOG_ERR, "%s: can't create lockfile", ttyn);
    271  1.23      cjs 			exit(1);
    272  1.23      cjs 		}
    273  1.23      cjs 		(void) chown(lockfile, ttyowner, 0);
    274   1.1      cgd 		login_tty(i);
    275   1.1      cgd 	    }
    276   1.1      cgd 	}
    277   1.1      cgd 
    278   1.7       pk 	/* Start with default tty settings */
    279   1.7       pk 	if (tcgetattr(0, &tmode) < 0) {
    280   1.7       pk 		syslog(LOG_ERR, "%s: %m", ttyn);
    281   1.7       pk 		exit(1);
    282   1.7       pk 	}
    283   1.8       pk 	omode = tmode;
    284   1.7       pk 
    285   1.5      cgd 	gettable("default", defent);
    286   1.1      cgd 	gendefaults();
    287   1.1      cgd 	tname = "default";
    288   1.1      cgd 	if (argc > 1)
    289   1.1      cgd 		tname = argv[1];
    290   1.1      cgd 	for (;;) {
    291   1.8       pk 		int off;
    292   1.1      cgd 
    293   1.5      cgd 		gettable(tname, tabent);
    294   1.1      cgd 		if (OPset || EPset || APset)
    295   1.1      cgd 			APset++, OPset++, EPset++;
    296   1.1      cgd 		setdefaults();
    297   1.8       pk 		off = 0;
    298  1.12       pk 		(void)tcflush(0, TCIOFLUSH);	/* clear out the crap */
    299   1.1      cgd 		ioctl(0, FIONBIO, &off);	/* turn off non-blocking mode */
    300   1.1      cgd 		ioctl(0, FIOASYNC, &off);	/* ditto for async mode */
    301   1.7       pk 
    302   1.1      cgd 		if (IS)
    303   1.9  mycroft 			cfsetispeed(&tmode, IS);
    304   1.1      cgd 		else if (SP)
    305   1.9  mycroft 			cfsetispeed(&tmode, SP);
    306   1.1      cgd 		if (OS)
    307   1.9  mycroft 			cfsetospeed(&tmode, OS);
    308   1.1      cgd 		else if (SP)
    309   1.9  mycroft 			cfsetospeed(&tmode, SP);
    310   1.7       pk 		setflags(0);
    311   1.1      cgd 		setchars();
    312   1.7       pk 		if (tcsetattr(0, TCSANOW, &tmode) < 0) {
    313   1.7       pk 			syslog(LOG_ERR, "%s: %m", ttyn);
    314   1.7       pk 			exit(1);
    315   1.7       pk 		}
    316   1.1      cgd 		if (AB) {
    317   1.1      cgd 			tname = autobaud();
    318   1.1      cgd 			continue;
    319   1.1      cgd 		}
    320   1.1      cgd 		if (PS) {
    321   1.1      cgd 			tname = portselector();
    322   1.1      cgd 			continue;
    323   1.1      cgd 		}
    324   1.1      cgd 		if (CL && *CL)
    325   1.1      cgd 			putpad(CL);
    326   1.1      cgd 		edithost(HE);
    327   1.1      cgd 		if (IM && *IM)
    328   1.1      cgd 			putf(IM);
    329   1.1      cgd 		if (setjmp(timeout)) {
    330   1.7       pk 			tmode.c_ispeed = tmode.c_ospeed = 0;
    331   1.7       pk 			(void)tcsetattr(0, TCSANOW, &tmode);
    332   1.1      cgd 			exit(1);
    333   1.1      cgd 		}
    334   1.1      cgd 		if (TO) {
    335   1.1      cgd 			signal(SIGALRM, dingdong);
    336   1.1      cgd 			alarm(TO);
    337   1.1      cgd 		}
    338   1.1      cgd 		if (getname()) {
    339  1.25      mrg 			int i;
    340   1.1      cgd 
    341   1.1      cgd 			oflush();
    342   1.1      cgd 			alarm(0);
    343   1.1      cgd 			signal(SIGALRM, SIG_DFL);
    344   1.1      cgd 			if (name[0] == '-') {
    345  1.24  thorpej 				xputs("user names may not start with '-'.");
    346   1.1      cgd 				continue;
    347   1.1      cgd 			}
    348   1.1      cgd 			if (!(upper || lower || digit))
    349   1.1      cgd 				continue;
    350   1.7       pk 			setflags(2);
    351   1.7       pk 			if (crmod) {
    352   1.7       pk 				tmode.c_iflag |= ICRNL;
    353   1.7       pk 				tmode.c_oflag |= ONLCR;
    354   1.7       pk 			}
    355   1.7       pk #if XXX
    356   1.1      cgd 			if (upper || UC)
    357   1.1      cgd 				tmode.sg_flags |= LCASE;
    358   1.1      cgd 			if (lower || LC)
    359   1.1      cgd 				tmode.sg_flags &= ~LCASE;
    360   1.7       pk #endif
    361   1.7       pk 			if (tcsetattr(0, TCSANOW, &tmode) < 0) {
    362   1.7       pk 				syslog(LOG_ERR, "%s: %m", ttyn);
    363   1.7       pk 				exit(1);
    364   1.7       pk 			}
    365   1.1      cgd 			signal(SIGINT, SIG_DFL);
    366   1.1      cgd 			for (i = 0; environ[i] != (char *)0; i++)
    367   1.1      cgd 				env[i] = environ[i];
    368   1.1      cgd 			makeenv(&env[i]);
    369   1.8       pk 
    370   1.8       pk 			limit.rlim_max = RLIM_INFINITY;
    371   1.8       pk 			limit.rlim_cur = RLIM_INFINITY;
    372   1.8       pk 			(void)setrlimit(RLIMIT_CPU, &limit);
    373  1.16  mycroft 			execle(LO, "login", "-p", "--", name, (char *)0, env);
    374   1.1      cgd 			syslog(LOG_ERR, "%s: %m", LO);
    375   1.1      cgd 			exit(1);
    376   1.1      cgd 		}
    377   1.1      cgd 		alarm(0);
    378   1.1      cgd 		signal(SIGALRM, SIG_DFL);
    379   1.1      cgd 		signal(SIGINT, SIG_IGN);
    380   1.1      cgd 		if (NX && *NX)
    381   1.1      cgd 			tname = NX;
    382  1.23      cjs 		unlink(lockfile);
    383   1.1      cgd 	}
    384   1.1      cgd }
    385   1.1      cgd 
    386   1.8       pk static int
    387   1.1      cgd getname()
    388   1.1      cgd {
    389  1.25      mrg 	int c;
    390  1.25      mrg 	char *np;
    391   1.1      cgd 	char cs;
    392   1.1      cgd 
    393   1.1      cgd 	/*
    394   1.1      cgd 	 * Interrupt may happen if we use CBREAK mode
    395   1.1      cgd 	 */
    396   1.1      cgd 	if (setjmp(intrupt)) {
    397   1.1      cgd 		signal(SIGINT, SIG_IGN);
    398   1.1      cgd 		return (0);
    399   1.1      cgd 	}
    400   1.1      cgd 	signal(SIGINT, interrupt);
    401   1.7       pk 	setflags(1);
    402   1.1      cgd 	prompt();
    403   1.1      cgd 	if (PF > 0) {
    404   1.1      cgd 		oflush();
    405   1.1      cgd 		sleep(PF);
    406   1.1      cgd 		PF = 0;
    407   1.1      cgd 	}
    408   1.7       pk 	if (tcsetattr(0, TCSANOW, &tmode) < 0) {
    409   1.7       pk 		syslog(LOG_ERR, "%s: %m", ttyn);
    410   1.7       pk 		exit(1);
    411   1.7       pk 	}
    412   1.1      cgd 	crmod = digit = lower = upper = 0;
    413   1.1      cgd 	np = name;
    414   1.1      cgd 	for (;;) {
    415   1.1      cgd 		oflush();
    416   1.1      cgd 		if (read(STDIN_FILENO, &cs, 1) <= 0)
    417   1.1      cgd 			exit(0);
    418   1.1      cgd 		if ((c = cs&0177) == 0)
    419   1.1      cgd 			return (0);
    420   1.1      cgd 		if (c == EOT)
    421   1.1      cgd 			exit(1);
    422   1.1      cgd 		if (c == '\r' || c == '\n' || np >= &name[sizeof name]) {
    423   1.1      cgd 			putf("\r\n");
    424   1.1      cgd 			break;
    425   1.1      cgd 		}
    426   1.1      cgd 		if (islower(c))
    427   1.1      cgd 			lower = 1;
    428   1.1      cgd 		else if (isupper(c))
    429   1.1      cgd 			upper = 1;
    430   1.1      cgd 		else if (c == ERASE || c == '#' || c == '\b') {
    431   1.1      cgd 			if (np > name) {
    432   1.1      cgd 				np--;
    433  1.10  mycroft 				if (cfgetospeed(&tmode) >= 1200)
    434  1.24  thorpej 					xputs("\b \b");
    435   1.1      cgd 				else
    436   1.1      cgd 					putchr(cs);
    437   1.1      cgd 			}
    438   1.1      cgd 			continue;
    439   1.1      cgd 		} else if (c == KILL || c == '@') {
    440   1.1      cgd 			putchr(cs);
    441   1.1      cgd 			putchr('\r');
    442  1.10  mycroft 			if (cfgetospeed(&tmode) < 1200)
    443   1.1      cgd 				putchr('\n');
    444   1.1      cgd 			/* this is the way they do it down under ... */
    445   1.1      cgd 			else if (np > name)
    446  1.24  thorpej 				xputs(
    447  1.24  thorpej 				    "                                     \r");
    448   1.1      cgd 			prompt();
    449   1.1      cgd 			np = name;
    450   1.1      cgd 			continue;
    451   1.1      cgd 		} else if (isdigit(c))
    452   1.1      cgd 			digit++;
    453   1.1      cgd 		if (IG && (c <= ' ' || c > 0176))
    454   1.1      cgd 			continue;
    455   1.1      cgd 		*np++ = c;
    456   1.1      cgd 		putchr(cs);
    457   1.1      cgd 	}
    458   1.1      cgd 	signal(SIGINT, SIG_IGN);
    459   1.1      cgd 	*np = 0;
    460   1.1      cgd 	if (c == '\r')
    461   1.1      cgd 		crmod = 1;
    462  1.22    mikel 	if ((upper && !lower && !LC) || UC)
    463   1.1      cgd 		for (np = name; *np; np++)
    464   1.1      cgd 			if (isupper(*np))
    465   1.1      cgd 				*np = tolower(*np);
    466   1.1      cgd 	return (1);
    467   1.1      cgd }
    468   1.1      cgd 
    469   1.8       pk static void
    470   1.1      cgd putpad(s)
    471  1.25      mrg 	const char *s;
    472   1.1      cgd {
    473  1.25      mrg 	int pad = 0;
    474  1.10  mycroft 	speed_t ospeed = cfgetospeed(&tmode);
    475   1.1      cgd 
    476   1.1      cgd 	if (isdigit(*s)) {
    477   1.1      cgd 		while (isdigit(*s)) {
    478   1.1      cgd 			pad *= 10;
    479   1.1      cgd 			pad += *s++ - '0';
    480   1.1      cgd 		}
    481   1.1      cgd 		pad *= 10;
    482   1.1      cgd 		if (*s == '.' && isdigit(s[1])) {
    483   1.1      cgd 			pad += s[1] - '0';
    484   1.1      cgd 			s += 2;
    485   1.1      cgd 		}
    486   1.1      cgd 	}
    487   1.1      cgd 
    488  1.24  thorpej 	xputs(s);
    489   1.1      cgd 	/*
    490   1.1      cgd 	 * If no delay needed, or output speed is
    491   1.1      cgd 	 * not comprehensible, then don't try to delay.
    492   1.1      cgd 	 */
    493  1.10  mycroft 	if (pad == 0 || ospeed <= 0)
    494   1.1      cgd 		return;
    495   1.1      cgd 
    496   1.1      cgd 	/*
    497   1.1      cgd 	 * Round up by a half a character frame, and then do the delay.
    498   1.1      cgd 	 * Too bad there are no user program accessible programmed delays.
    499   1.1      cgd 	 * Transmitting pad characters slows many terminals down and also
    500   1.1      cgd 	 * loads the system.
    501   1.1      cgd 	 */
    502  1.10  mycroft 	pad = (pad * ospeed + 50000) / 100000;
    503  1.10  mycroft 	while (pad--)
    504   1.1      cgd 		putchr(*PC);
    505   1.1      cgd }
    506   1.1      cgd 
    507   1.8       pk static void
    508  1.24  thorpej xputs(s)
    509  1.25      mrg 	const char *s;
    510   1.1      cgd {
    511   1.1      cgd 	while (*s)
    512   1.1      cgd 		putchr(*s++);
    513   1.1      cgd }
    514   1.1      cgd 
    515   1.1      cgd char	outbuf[OBUFSIZ];
    516   1.1      cgd int	obufcnt = 0;
    517   1.1      cgd 
    518   1.8       pk static void
    519   1.1      cgd putchr(cc)
    520   1.8       pk 	int cc;
    521   1.1      cgd {
    522   1.1      cgd 	char c;
    523   1.1      cgd 
    524   1.1      cgd 	c = cc;
    525   1.1      cgd 	if (!NP) {
    526   1.1      cgd 		c |= partab[c&0177] & 0200;
    527   1.1      cgd 		if (OP)
    528   1.1      cgd 			c ^= 0200;
    529   1.1      cgd 	}
    530   1.1      cgd 	if (!UB) {
    531   1.1      cgd 		outbuf[obufcnt++] = c;
    532   1.1      cgd 		if (obufcnt >= OBUFSIZ)
    533   1.1      cgd 			oflush();
    534   1.1      cgd 	} else
    535   1.1      cgd 		write(STDOUT_FILENO, &c, 1);
    536   1.1      cgd }
    537   1.1      cgd 
    538   1.8       pk static void
    539   1.1      cgd oflush()
    540   1.1      cgd {
    541   1.1      cgd 	if (obufcnt)
    542   1.1      cgd 		write(STDOUT_FILENO, outbuf, obufcnt);
    543   1.1      cgd 	obufcnt = 0;
    544   1.1      cgd }
    545   1.1      cgd 
    546   1.8       pk static void
    547   1.1      cgd prompt()
    548   1.1      cgd {
    549   1.1      cgd 
    550   1.1      cgd 	putf(LM);
    551   1.1      cgd 	if (CO)
    552   1.1      cgd 		putchr('\n');
    553   1.1      cgd }
    554   1.1      cgd 
    555   1.8       pk static void
    556   1.1      cgd putf(cp)
    557  1.25      mrg 	const char *cp;
    558   1.1      cgd {
    559   1.1      cgd 	extern char editedhost[];
    560   1.1      cgd 	time_t t;
    561   1.1      cgd 	char *slash, db[100];
    562   1.1      cgd 
    563   1.1      cgd 	while (*cp) {
    564   1.1      cgd 		if (*cp != '%') {
    565   1.1      cgd 			putchr(*cp++);
    566   1.1      cgd 			continue;
    567   1.1      cgd 		}
    568   1.1      cgd 		switch (*++cp) {
    569   1.1      cgd 
    570   1.1      cgd 		case 't':
    571   1.8       pk 			slash = strrchr(ttyn, '/');
    572   1.1      cgd 			if (slash == (char *) 0)
    573  1.24  thorpej 				xputs(ttyn);
    574   1.1      cgd 			else
    575  1.24  thorpej 				xputs(&slash[1]);
    576   1.1      cgd 			break;
    577   1.1      cgd 
    578   1.1      cgd 		case 'h':
    579  1.24  thorpej 			xputs(editedhost);
    580   1.1      cgd 			break;
    581   1.1      cgd 
    582   1.1      cgd 		case 'd': {
    583  1.13  mycroft 			static char fmt[] = "%l:% %p on %A, %d %B %Y";
    584   1.1      cgd 
    585   1.1      cgd 			fmt[4] = 'M';		/* I *hate* SCCS... */
    586   1.1      cgd 			(void)time(&t);
    587   1.1      cgd 			(void)strftime(db, sizeof(db), fmt, localtime(&t));
    588  1.24  thorpej 			xputs(db);
    589   1.3  mycroft 			break;
    590   1.3  mycroft 
    591   1.3  mycroft 		case 's':
    592  1.24  thorpej 			xputs(kerninfo.sysname);
    593   1.3  mycroft 			break;
    594   1.3  mycroft 
    595   1.3  mycroft 		case 'm':
    596  1.24  thorpej 			xputs(kerninfo.machine);
    597   1.3  mycroft 			break;
    598   1.3  mycroft 
    599   1.3  mycroft 		case 'r':
    600  1.24  thorpej 			xputs(kerninfo.release);
    601   1.3  mycroft 			break;
    602   1.3  mycroft 
    603   1.3  mycroft 		case 'v':
    604  1.24  thorpej 			xputs(kerninfo.version);
    605   1.1      cgd 			break;
    606   1.1      cgd 		}
    607   1.1      cgd 
    608   1.1      cgd 		case '%':
    609   1.1      cgd 			putchr('%');
    610   1.1      cgd 			break;
    611   1.1      cgd 		}
    612   1.1      cgd 		cp++;
    613   1.1      cgd 	}
    614   1.1      cgd }
    615