Home | History | Annotate | Line # | Download | only in login
login.c revision 1.17
      1 /*	$NetBSD: login.c,v 1.17 1997/02/11 08:15:10 mrg Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef lint
     37 static char copyright[] =
     38 "@(#) Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994\n\
     39 	The Regents of the University of California.  All rights reserved.\n";
     40 #endif /* not lint */
     41 
     42 #ifndef lint
     43 #if 0
     44 static char sccsid[] = "@(#)login.c	8.4 (Berkeley) 4/2/94";
     45 #endif
     46 static char rcsid[] = "$NetBSD: login.c,v 1.17 1997/02/11 08:15:10 mrg Exp $";
     47 #endif /* not lint */
     48 
     49 /*
     50  * login [ name ]
     51  * login -h hostname	(for telnetd, etc.)
     52  * login -f name	(for pre-authenticated login: datakit, xterm, etc.)
     53  */
     54 
     55 #include <sys/param.h>
     56 #include <sys/stat.h>
     57 #include <sys/time.h>
     58 #include <sys/resource.h>
     59 #include <sys/file.h>
     60 
     61 #include <err.h>
     62 #include <errno.h>
     63 #include <grp.h>
     64 #include <pwd.h>
     65 #include <setjmp.h>
     66 #include <signal.h>
     67 #include <stdio.h>
     68 #include <stdlib.h>
     69 #include <string.h>
     70 #include <syslog.h>
     71 #include <ttyent.h>
     72 #include <tzfile.h>
     73 #include <unistd.h>
     74 #include <utmp.h>
     75 #include <util.h>
     76 
     77 #include "pathnames.h"
     78 
     79 void	 badlogin __P((char *));
     80 void	 checknologin __P((void));
     81 void	 dolastlog __P((int));
     82 void	 getloginname __P((void));
     83 void	 motd __P((void));
     84 int	 rootterm __P((char *));
     85 void	 sigint __P((int));
     86 void	 sleepexit __P((int));
     87 char	*stypeof __P((char *));
     88 void	 timedout __P((int));
     89 int	 pwcheck __P((char *, char *, char *, char *));
     90 #if defined(KERBEROS) || defined(KERBEROS5)
     91 int	 klogin __P((struct passwd *, char *, char *, char *));
     92 void	 kdestroy __P((void));
     93 void	 dofork __P((void));
     94 #endif
     95 
     96 extern void login __P((struct utmp *));
     97 
     98 #define	TTYGRPNAME	"tty"		/* name of group to own ttys */
     99 
    100 /*
    101  * This bounds the time given to login.  Not a define so it can
    102  * be patched on machines where it's too small.
    103  */
    104 u_int	timeout = 300;
    105 
    106 #if defined(KERBEROS) || defined(KERBEROS5)
    107 int	notickets = 1;
    108 char	*instance;
    109 char	*krbtkfile_env;
    110 int	authok;
    111 #endif
    112 
    113 struct	passwd *pwd;
    114 int	failures;
    115 char	term[64], *envinit[1], *hostname, *username, *tty;
    116 
    117 int
    118 main(argc, argv)
    119 	int argc;
    120 	char *argv[];
    121 {
    122 	extern char **environ;
    123 	struct group *gr;
    124 	struct stat st;
    125 	struct timeval tp;
    126 	struct utmp utmp;
    127 	int ask, ch, cnt, fflag, hflag, pflag, quietlog, rootlogin, rval;
    128 	uid_t uid;
    129 	char *domain, *p, *salt, *ttyn;
    130 	char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10];
    131 	char localhost[MAXHOSTNAMELEN];
    132 
    133 	(void)signal(SIGALRM, timedout);
    134 	(void)alarm(timeout);
    135 	(void)signal(SIGQUIT, SIG_IGN);
    136 	(void)signal(SIGINT, SIG_IGN);
    137 	(void)setpriority(PRIO_PROCESS, 0, 0);
    138 
    139 	openlog("login", LOG_ODELAY, LOG_AUTH);
    140 
    141 	/*
    142 	 * -p is used by getty to tell login not to destroy the environment
    143 	 * -f is used to skip a second login authentication
    144 	 * -h is used by other servers to pass the name of the remote
    145 	 *    host to login so that it may be placed in utmp and wtmp
    146 	 */
    147 	domain = NULL;
    148 	if (gethostname(localhost, sizeof(localhost)) < 0)
    149 		syslog(LOG_ERR, "couldn't get local hostname: %m");
    150 	else
    151 		domain = strchr(localhost, '.');
    152 
    153 	fflag = hflag = pflag = 0;
    154 	uid = getuid();
    155 	while ((ch = getopt(argc, argv, "fh:p")) != EOF)
    156 		switch (ch) {
    157 		case 'f':
    158 			fflag = 1;
    159 			break;
    160 		case 'h':
    161 			if (uid)
    162 				errx(1, "-h option: %s", strerror(EPERM));
    163 			hflag = 1;
    164 			if (domain && (p = strchr(optarg, '.')) &&
    165 			    strcasecmp(p, domain) == 0)
    166 				*p = 0;
    167 			hostname = optarg;
    168 			break;
    169 		case 'p':
    170 			pflag = 1;
    171 			break;
    172 		case '?':
    173 		default:
    174 			if (!uid)
    175 				syslog(LOG_ERR, "invalid flag %c", ch);
    176 			(void)fprintf(stderr,
    177 			    "usage: login [-fp] [-h hostname] [username]\n");
    178 			exit(1);
    179 		}
    180 	argc -= optind;
    181 	argv += optind;
    182 
    183 	if (*argv) {
    184 		username = *argv;
    185 		ask = 0;
    186 	} else
    187 		ask = 1;
    188 
    189 	for (cnt = getdtablesize(); cnt > 2; cnt--)
    190 		(void)close(cnt);
    191 
    192 	ttyn = ttyname(STDIN_FILENO);
    193 	if (ttyn == NULL || *ttyn == '\0') {
    194 		(void)snprintf(tname, sizeof(tname), "%s??", _PATH_TTY);
    195 		ttyn = tname;
    196 	}
    197 	if (tty = strrchr(ttyn, '/'))
    198 		++tty;
    199 	else
    200 		tty = ttyn;
    201 
    202 	for (cnt = 0;; ask = 1) {
    203 #if defined(KERBEROS) || defined(KERBEROS5)
    204 	        kdestroy();
    205 #endif
    206 		if (ask) {
    207 			fflag = 0;
    208 			getloginname();
    209 		}
    210 		rootlogin = 0;
    211 #ifdef	KERBEROS
    212 		if ((instance = strchr(username, '.')) != NULL) {
    213 			if (strncmp(instance, ".root", 5) == 0)
    214 				rootlogin = 1;
    215 			*instance++ = '\0';
    216 		} else
    217 			instance = "";
    218 #endif
    219 #ifdef KERBEROS5
    220 		if ((instance = strchr(username, '/')) != NULL) {
    221 			if (strncmp(instance, "/root", 5) == 0)
    222 				rootlogin = 1;
    223 			*instance++ = '\0';
    224 		} else
    225 			instance = "";
    226 #endif
    227 		if (strlen(username) > MAXLOGNAME)
    228 			username[MAXLOGNAME] = '\0';
    229 
    230 		/*
    231 		 * Note if trying multiple user names; log failures for
    232 		 * previous user name, but don't bother logging one failure
    233 		 * for nonexistent name (mistyped username).
    234 		 */
    235 		if (failures && strcmp(tbuf, username)) {
    236 			if (failures > (pwd ? 0 : 1))
    237 				badlogin(tbuf);
    238 			failures = 0;
    239 		}
    240 		(void)strncpy(tbuf, username, sizeof(tbuf) - 1);
    241 
    242 		if (pwd = getpwnam(username))
    243 			salt = pwd->pw_passwd;
    244 		else
    245 			salt = "xx";
    246 
    247 		/*
    248 		 * if we have a valid account name, and it doesn't have a
    249 		 * password, or the -f option was specified and the caller
    250 		 * is root or the caller isn't changing their uid, don't
    251 		 * authenticate.
    252 		 */
    253 		if (pwd) {
    254 			if (pwd->pw_uid == 0)
    255 				rootlogin = 1;
    256 
    257 			if (fflag && (uid == 0 || uid == pwd->pw_uid)) {
    258 				/* already authenticated */
    259 				break;
    260 			} else if (pwd->pw_passwd[0] == '\0') {
    261 				/* pretend password okay */
    262 				rval = 0;
    263 				goto ttycheck;
    264 			}
    265 		}
    266 
    267 		fflag = 0;
    268 
    269 		(void)setpriority(PRIO_PROCESS, 0, -4);
    270 
    271 		p = getpass("Password:");
    272 
    273 		if (pwd) {
    274 #if defined(KERBEROS) || defined(KERBEROS5)
    275 			rval = klogin(pwd, instance, localhost, p);
    276 			if (rval != 0 && rootlogin && pwd->pw_uid != 0)
    277 				rootlogin = 0;
    278 			if (rval == 0)
    279 				authok = 1;
    280 			else if (rval == 1) {
    281 				if (pwd->pw_uid != 0)
    282 					rootlogin = 0;
    283 				rval = pwcheck(username, p, salt, pwd->pw_passwd);
    284 			}
    285 #else
    286 			rval = pwcheck(username, p, salt, pwd->pw_passwd);
    287 #endif
    288 		}
    289 		memset(p, 0, strlen(p));
    290 
    291 		(void)setpriority(PRIO_PROCESS, 0, 0);
    292 
    293 	ttycheck:
    294 		/*
    295 		 * If trying to log in as root without Kerberos,
    296 		 * but with insecure terminal, refuse the login attempt.
    297 		 */
    298 #if defined(KERBEROS) || defined(KERBEROS5)
    299 		if (authok == 0)
    300 #endif
    301 		if (pwd && !rval && rootlogin && !rootterm(tty)) {
    302 			(void)fprintf(stderr,
    303 			    "%s login refused on this terminal.\n",
    304 			    pwd->pw_name);
    305 			if (hostname)
    306 				syslog(LOG_NOTICE,
    307 				    "LOGIN %s REFUSED FROM %s ON TTY %s",
    308 				    pwd->pw_name, hostname, tty);
    309 			else
    310 				syslog(LOG_NOTICE,
    311 				    "LOGIN %s REFUSED ON TTY %s",
    312 				     pwd->pw_name, tty);
    313 			continue;
    314 		}
    315 
    316 		if (pwd && !rval)
    317 			break;
    318 
    319 		(void)printf("Login incorrect\n");
    320 		failures++;
    321 		/* we allow 10 tries, but after 3 we start backing off */
    322 		if (++cnt > 3) {
    323 			if (cnt >= 10) {
    324 				badlogin(username);
    325 				sleepexit(1);
    326 			}
    327 			sleep((u_int)((cnt - 3) * 5));
    328 		}
    329 	}
    330 
    331 	/* committed to login -- turn off timeout */
    332 	(void)alarm((u_int)0);
    333 
    334 	endpwent();
    335 
    336 	/* if user not super-user, check for disabled logins */
    337 	if (!rootlogin)
    338 		checknologin();
    339 
    340 	if (chdir(pwd->pw_dir) < 0) {
    341 		(void)printf("No home directory %s!\n", pwd->pw_dir);
    342 		if (chdir("/"))
    343 			exit(0);
    344 		pwd->pw_dir = "/";
    345 		(void)printf("Logging in with home = \"/\".\n");
    346 	}
    347 
    348 	quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0;
    349 
    350 	if (pwd->pw_change || pwd->pw_expire)
    351 		(void)gettimeofday(&tp, (struct timezone *)NULL);
    352 	if (pwd->pw_change)
    353 		if (tp.tv_sec >= pwd->pw_change) {
    354 			(void)printf("Sorry -- your password has expired.\n");
    355 			sleepexit(1);
    356 		} else if (pwd->pw_change - tp.tv_sec <
    357 		    2 * DAYSPERWEEK * SECSPERDAY && !quietlog)
    358 			(void)printf("Warning: your password expires on %s",
    359 			    ctime(&pwd->pw_change));
    360 	if (pwd->pw_expire)
    361 		if (tp.tv_sec >= pwd->pw_expire) {
    362 			(void)printf("Sorry -- your account has expired.\n");
    363 			sleepexit(1);
    364 		} else if (pwd->pw_expire - tp.tv_sec <
    365 		    2 * DAYSPERWEEK * SECSPERDAY && !quietlog)
    366 			(void)printf("Warning: your account expires on %s",
    367 			    ctime(&pwd->pw_expire));
    368 
    369 	/* Nothing else left to fail -- really log in. */
    370 	memset((void *)&utmp, 0, sizeof(utmp));
    371 	(void)time(&utmp.ut_time);
    372 	(void)strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
    373 	if (hostname)
    374 		(void)strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
    375 	(void)strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
    376 	login(&utmp);
    377 
    378 	dolastlog(quietlog);
    379 
    380 	(void)chown(ttyn, pwd->pw_uid,
    381 	    (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
    382 
    383 	if (ttyaction(ttyn, "login", pwd->pw_name))
    384 		(void)printf("Warning: ttyaction failed.\n");
    385 
    386 #if defined(KERBEROS) || defined(KERBEROS5)
    387 	/* Fork so that we can call kdestroy */
    388 	if (krbtkfile_env)
    389 	    dofork();
    390 #endif
    391 	(void)setgid(pwd->pw_gid);
    392 
    393 	initgroups(username, pwd->pw_gid);
    394 
    395 	if (*pwd->pw_shell == '\0')
    396 		pwd->pw_shell = _PATH_BSHELL;
    397 
    398 	/* Destroy environment unless user has requested its preservation. */
    399 	if (!pflag)
    400 		environ = envinit;
    401 	(void)setenv("HOME", pwd->pw_dir, 1);
    402 	(void)setenv("SHELL", pwd->pw_shell, 1);
    403 	if (term[0] == '\0')
    404 		(void)strncpy(term, stypeof(tty), sizeof(term));
    405 	(void)setenv("TERM", term, 0);
    406 	(void)setenv("LOGNAME", pwd->pw_name, 1);
    407 	(void)setenv("USER", pwd->pw_name, 1);
    408 	(void)setenv("PATH", _PATH_DEFPATH, 0);
    409 #ifdef KERBEROS
    410 	if (krbtkfile_env)
    411 		(void)setenv("KRBTKFILE", krbtkfile_env, 1);
    412 #endif
    413 #ifdef KERBEROS5
    414 	if (krbtkfile_env)
    415 		(void)setenv("KRB5CCNAME", krbtkfile_env, 1);
    416 #endif
    417 
    418 	if (tty[sizeof("tty")-1] == 'd')
    419 		syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
    420 
    421 	/* If fflag is on, assume caller/authenticator has logged root login. */
    422 	if (rootlogin && fflag == 0)
    423 		if (hostname)
    424 			syslog(LOG_NOTICE, "ROOT LOGIN (%s) ON %s FROM %s",
    425 			    username, tty, hostname);
    426 		else
    427 			syslog(LOG_NOTICE, "ROOT LOGIN (%s) ON %s", username, tty);
    428 
    429 #if defined(KERBEROS) || defined(KERBEROS5)
    430 	if (!quietlog && notickets == 1)
    431 		(void)printf("Warning: no Kerberos tickets issued.\n");
    432 #endif
    433 
    434 	if (!quietlog) {
    435 		(void)printf("%s\n\t%s  %s\n\n",
    436 	    "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994",
    437 		    "The Regents of the University of California. ",
    438 		    "All rights reserved.");
    439 		motd();
    440 		(void)snprintf(tbuf,
    441 		    sizeof(tbuf), "%s/%s", _PATH_MAILDIR, pwd->pw_name);
    442 		if (stat(tbuf, &st) == 0 && st.st_size != 0)
    443 			(void)printf("You have %smail.\n",
    444 			    (st.st_mtime > st.st_atime) ? "new " : "");
    445 	}
    446 
    447 	(void)signal(SIGALRM, SIG_DFL);
    448 	(void)signal(SIGQUIT, SIG_DFL);
    449 	(void)signal(SIGINT, SIG_DFL);
    450 	(void)signal(SIGTSTP, SIG_IGN);
    451 
    452 	tbuf[0] = '-';
    453 	(void)strncpy(tbuf + 1, (p = strrchr(pwd->pw_shell, '/')) ?
    454 	    p + 1 : pwd->pw_shell, sizeof(tbuf) - 2);
    455 
    456 	if (setlogin(pwd->pw_name) < 0)
    457 		syslog(LOG_ERR, "setlogin() failure: %m");
    458 
    459 	/* Discard permissions last so can't get killed and drop core. */
    460 	if (rootlogin)
    461 		(void) setuid(0);
    462 	else
    463 		(void) setuid(pwd->pw_uid);
    464 
    465 	execlp(pwd->pw_shell, tbuf, 0);
    466 	err(1, "%s", pwd->pw_shell);
    467 }
    468 
    469 int
    470 pwcheck(user, p, salt, passwd)
    471 	char *user, *p, *salt, *passwd;
    472 {
    473 #ifdef SKEY
    474 	if (strcasecmp(p, "s/key") == 0)
    475 		if (skey_haskey(user))
    476 			return 1;
    477 		else
    478 			return skey_authenticate(user);
    479 #endif
    480 	return strcmp(crypt(p, salt), passwd);
    481 }
    482 
    483 #if defined(KERBEROS) || defined(KERBEROS5)
    484 #define	NBUFSIZ		(MAXLOGNAME + 1 + 5)	/* .root suffix */
    485 #else
    486 #define	NBUFSIZ		(MAXLOGNAME + 1)
    487 #endif
    488 
    489 #if defined(KERBEROS) || defined(KERBEROS5)
    490 /*
    491  * This routine handles cleanup stuff, and the like.
    492  * It exists only in the child process.
    493  */
    494 #include <sys/wait.h>
    495 void
    496 dofork()
    497 {
    498     int child;
    499 
    500     if (!(child = fork()))
    501 	    return; /* Child process */
    502 
    503     /* Setup stuff?  This would be things we could do in parallel with login */
    504     (void) chdir("/");	/* Let's not keep the fs busy... */
    505 
    506     /* If we're the parent, watch the child until it dies */
    507     while (wait(0) != child)
    508 	    ;
    509 
    510     /* Cleanup stuff */
    511     /* Run kdestroy to destroy tickets */
    512     kdestroy();
    513 
    514     /* Leave */
    515     exit(0);
    516 }
    517 #endif
    518 
    519 void
    520 getloginname()
    521 {
    522 	int ch;
    523 	char *p;
    524 	static char nbuf[NBUFSIZ];
    525 
    526 	for (;;) {
    527 		(void)printf("login: ");
    528 		for (p = nbuf; (ch = getchar()) != '\n'; ) {
    529 			if (ch == EOF) {
    530 				badlogin(username);
    531 				exit(0);
    532 			}
    533 			if (p < nbuf + (NBUFSIZ - 1))
    534 				*p++ = ch;
    535 		}
    536 		if (p > nbuf)
    537 			if (nbuf[0] == '-')
    538 				(void)fprintf(stderr,
    539 				    "login names may not start with '-'.\n");
    540 			else {
    541 				*p = '\0';
    542 				username = nbuf;
    543 				break;
    544 			}
    545 	}
    546 }
    547 
    548 int
    549 rootterm(ttyn)
    550 	char *ttyn;
    551 {
    552 	struct ttyent *t;
    553 
    554 	return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE);
    555 }
    556 
    557 jmp_buf motdinterrupt;
    558 
    559 void
    560 motd()
    561 {
    562 	int fd, nchars;
    563 	sig_t oldint;
    564 	char tbuf[8192];
    565 
    566 	if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0)
    567 		return;
    568 	oldint = signal(SIGINT, sigint);
    569 	if (setjmp(motdinterrupt) == 0)
    570 		while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
    571 			(void)write(fileno(stdout), tbuf, nchars);
    572 	(void)signal(SIGINT, oldint);
    573 	(void)close(fd);
    574 }
    575 
    576 /* ARGSUSED */
    577 void
    578 sigint(signo)
    579 	int signo;
    580 {
    581 	longjmp(motdinterrupt, 1);
    582 }
    583 
    584 /* ARGSUSED */
    585 void
    586 timedout(signo)
    587 	int signo;
    588 {
    589 	(void)fprintf(stderr, "Login timed out after %d seconds\n", timeout);
    590 	exit(0);
    591 }
    592 
    593 void
    594 checknologin()
    595 {
    596 	int fd, nchars;
    597 	char tbuf[8192];
    598 
    599 	if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) {
    600 		while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
    601 			(void)write(fileno(stdout), tbuf, nchars);
    602 		sleepexit(0);
    603 	}
    604 }
    605 
    606 void
    607 dolastlog(quiet)
    608 	int quiet;
    609 {
    610 	struct lastlog ll;
    611 	int fd;
    612 
    613 	if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) {
    614 		(void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
    615 		if (!quiet) {
    616 			if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) &&
    617 			    ll.ll_time != 0) {
    618 				(void)printf("Last login: %.*s ",
    619 				    24-5, (char *)ctime(&ll.ll_time));
    620 				if (*ll.ll_host != '\0')
    621 					(void)printf("from %.*s\n",
    622 					    (int)sizeof(ll.ll_host),
    623 					    ll.ll_host);
    624 				else
    625 					(void)printf("on %.*s\n",
    626 					    (int)sizeof(ll.ll_line),
    627 					    ll.ll_line);
    628 			}
    629 			(void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
    630 		}
    631 		memset((void *)&ll, 0, sizeof(ll));
    632 		(void)time(&ll.ll_time);
    633 		(void)strncpy(ll.ll_line, tty, sizeof(ll.ll_line));
    634 		if (hostname)
    635 			(void)strncpy(ll.ll_host, hostname, sizeof(ll.ll_host));
    636 		(void)write(fd, (char *)&ll, sizeof(ll));
    637 		(void)close(fd);
    638 	}
    639 }
    640 
    641 void
    642 badlogin(name)
    643 	char *name;
    644 {
    645 	if (failures == 0)
    646 		return;
    647 	if (hostname) {
    648 		syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s",
    649 		    failures, failures > 1 ? "S" : "", hostname);
    650 		syslog(LOG_AUTHPRIV|LOG_NOTICE,
    651 		    "%d LOGIN FAILURE%s FROM %s, %s",
    652 		    failures, failures > 1 ? "S" : "", hostname, name);
    653 	} else {
    654 		syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s",
    655 		    failures, failures > 1 ? "S" : "", tty);
    656 		syslog(LOG_AUTHPRIV|LOG_NOTICE,
    657 		    "%d LOGIN FAILURE%s ON %s, %s",
    658 		    failures, failures > 1 ? "S" : "", tty, name);
    659 	}
    660 }
    661 
    662 #undef	UNKNOWN
    663 #define	UNKNOWN	"su"
    664 
    665 char *
    666 stypeof(ttyid)
    667 	char *ttyid;
    668 {
    669 	struct ttyent *t;
    670 
    671 	return (ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN);
    672 }
    673 
    674 void
    675 sleepexit(eval)
    676 	int eval;
    677 {
    678 	(void)sleep(5);
    679 	exit(eval);
    680 }
    681