1*43653Sbostic /*- 236515Sbostic * Copyright (c) 1980, 1987, 1988 The Regents of the University of California. 336515Sbostic * All rights reserved. 436515Sbostic * 5*43653Sbostic * %sccs.include.redist.c% 619843Sdist */ 719843Sdist 812678Ssam #ifndef lint 919843Sdist char copyright[] = 1036515Sbostic "@(#) Copyright (c) 1980, 1987, 1988 The Regents of the University of California.\n\ 1119843Sdist All rights reserved.\n"; 1236515Sbostic #endif /* not lint */ 1312678Ssam 1419843Sdist #ifndef lint 15*43653Sbostic static char sccsid[] = "@(#)login.c 5.56 (Berkeley) 06/24/90"; 1636515Sbostic #endif /* not lint */ 1719843Sdist 181043Sbill /* 191043Sbill * login [ name ] 2031695Skarels * login -h hostname (for telnetd, etc.) 2131695Skarels * login -f name (for pre-authenticated login: datakit, xterm, etc.) 221043Sbill */ 231043Sbill 2412984Ssam #include <sys/param.h> 2512687Ssam #include <sys/stat.h> 2612687Ssam #include <sys/time.h> 2712687Ssam #include <sys/resource.h> 2816453Sroot #include <sys/file.h> 2939271Skfall #include <sgtty.h> 3012687Ssam 311043Sbill #include <utmp.h> 321043Sbill #include <signal.h> 3312678Ssam #include <errno.h> 3416453Sroot #include <ttyent.h> 3516453Sroot #include <syslog.h> 3626862Smckusick #include <grp.h> 3736460Sbostic #include <pwd.h> 3836515Sbostic #include <setjmp.h> 3936460Sbostic #include <stdio.h> 4042063Sbostic #include <string.h> 4137203Sbostic #include <tzfile.h> 4237203Sbostic #include "pathnames.h" 431043Sbill 4436460Sbostic #define TTYGRPNAME "tty" /* name of group to own ttys */ 4526862Smckusick 4612687Ssam /* 4736460Sbostic * This bounds the time given to login. Not a define so it can 4836460Sbostic * be patched on machines where it's too small. 4912687Ssam */ 5031509Sbostic int timeout = 300; 51*43653Sbostic #ifdef KERBEROS 52*43653Sbostic int notickets = 1; 53*43653Sbostic #endif 546005Swnj 5536647Skarels struct passwd *pwd; 5636647Skarels int failures; 5740490Sbostic char term[64], *envinit[1], *hostname, *username, *tty; 586005Swnj 5936647Skarels struct sgttyb sgttyb; 6036647Skarels struct tchars tc = { 6113074Ssam CINTR, CQUIT, CSTART, CSTOP, CEOT, CBRK 621365Sbill }; 6336647Skarels struct ltchars ltc = { 64*43653Sbostic CSUSP, CDSUSP, CRPRNT, CDISCARD, CWERASE, CLNEXT 6513074Ssam }; 661365Sbill 6736880Sbostic char *months[] = 6836880Sbostic { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", 6936880Sbostic "Sep", "Oct", "Nov", "Dec" }; 7036880Sbostic 711043Sbill main(argc, argv) 7236460Sbostic int argc; 7336460Sbostic char **argv; 741043Sbill { 75*43653Sbostic extern int optind; 7636460Sbostic extern char *optarg, **environ; 7736880Sbostic struct timeval tp; 7836880Sbostic struct tm *ttp; 7936460Sbostic struct group *gr; 8036460Sbostic register int ch; 8136647Skarels register char *p; 8239271Skfall int ask, fflag, hflag, pflag, cnt, uid; 83*43653Sbostic int quietlog, passwd_req, ioctlval, rval; 84*43653Sbostic char *domain, *salt, *ttyn; 8537692Sbostic char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; 8638034Skfall char localhost[MAXHOSTNAMELEN]; 8736880Sbostic char *ctime(), *ttyname(), *stypeof(), *crypt(), *getpass(); 8836460Sbostic time_t time(); 8936460Sbostic off_t lseek(); 90*43653Sbostic void timedout(); 911043Sbill 9236460Sbostic (void)signal(SIGALRM, timedout); 9336460Sbostic (void)alarm((u_int)timeout); 9436460Sbostic (void)signal(SIGQUIT, SIG_IGN); 9536460Sbostic (void)signal(SIGINT, SIG_IGN); 9636460Sbostic (void)setpriority(PRIO_PROCESS, 0, 0); 9736460Sbostic 9842502Sbostic openlog("login", LOG_ODELAY, LOG_AUTH); 9942502Sbostic 10012687Ssam /* 10118549Ssam * -p is used by getty to tell login not to destroy the environment 10231695Skarels * -f is used to skip a second login authentication 10336523Skarels * -h is used by other servers to pass the name of the remote 10436523Skarels * host to login so that it may be placed in utmp and wtmp 10512687Ssam */ 10638034Skfall domain = NULL; 10738034Skfall if (gethostname(localhost, sizeof(localhost)) < 0) 10838034Skfall syslog(LOG_ERR, "couldn't get local hostname: %m"); 10938034Skfall else 11038034Skfall domain = index(localhost, '.'); 11136460Sbostic 11237203Sbostic fflag = hflag = pflag = 0; 11336460Sbostic passwd_req = 1; 11439271Skfall uid = getuid(); 11537203Sbostic while ((ch = getopt(argc, argv, "fh:p")) != EOF) 11636515Sbostic switch (ch) { 11736460Sbostic case 'f': 11836460Sbostic fflag = 1; 11936460Sbostic break; 12036460Sbostic case 'h': 12139271Skfall if (uid) { 12237203Sbostic (void)fprintf(stderr, 12336460Sbostic "login: -h for super-user only.\n"); 12432313Sbostic exit(1); 12531695Skarels } 12636460Sbostic hflag = 1; 12736460Sbostic if (domain && (p = index(optarg, '.')) && 12836553Sbostic strcasecmp(p, domain) == 0) 12936460Sbostic *p = 0; 13036460Sbostic hostname = optarg; 13136460Sbostic break; 13236460Sbostic case 'p': 13318549Ssam pflag = 1; 13436460Sbostic break; 13536460Sbostic case '?': 13636460Sbostic default: 13739271Skfall if (!uid) 13839271Skfall syslog(LOG_ERR, "invalid flag %c", ch); 13937203Sbostic (void)fprintf(stderr, 14037203Sbostic "usage: login [-fp] [username]\n"); 14136460Sbostic exit(1); 14218549Ssam } 14336460Sbostic argc -= optind; 14436460Sbostic argv += optind; 14536549Sbostic if (*argv) { 14636647Skarels username = *argv; 147*43653Sbostic if (strlen(username) > UT_NAMESIZE) 148*43653Sbostic username[UT_NAMESIZE] = '\0'; 14936549Sbostic ask = 0; 15036647Skarels } else 15136549Sbostic ask = 1; 15236460Sbostic 15336460Sbostic ioctlval = 0; 15436460Sbostic (void)ioctl(0, TIOCLSET, &ioctlval); 15536460Sbostic (void)ioctl(0, TIOCNXCL, 0); 15636515Sbostic (void)fcntl(0, F_SETFL, ioctlval); 15736515Sbostic (void)ioctl(0, TIOCGETP, &sgttyb); 15836515Sbostic sgttyb.sg_erase = CERASE; 15936515Sbostic sgttyb.sg_kill = CKILL; 16036460Sbostic (void)ioctl(0, TIOCSLTC, <c); 16136460Sbostic (void)ioctl(0, TIOCSETC, &tc); 16236515Sbostic (void)ioctl(0, TIOCSETP, &sgttyb); 16336460Sbostic 16436460Sbostic for (cnt = getdtablesize(); cnt > 2; cnt--) 16536460Sbostic close(cnt); 16636460Sbostic 1671043Sbill ttyn = ttyname(0); 16837692Sbostic if (ttyn == NULL || *ttyn == '\0') { 16937692Sbostic (void)sprintf(tname, "%s??", _PATH_TTY); 17037692Sbostic ttyn = tname; 17137692Sbostic } 17236460Sbostic if (tty = rindex(ttyn, '/')) 17336460Sbostic ++tty; 17436460Sbostic else 17516453Sroot tty = ttyn; 17636460Sbostic 17736549Sbostic for (cnt = 0;; ask = 1) { 17838602Sbostic ioctlval = TTYDISC; 17936460Sbostic (void)ioctl(0, TIOCSETD, &ioctlval); 18036460Sbostic 18136549Sbostic if (ask) { 18236515Sbostic fflag = 0; 18336460Sbostic getloginname(); 18436515Sbostic } 18536647Skarels /* 18639271Skfall * Note if trying multiple user names; log failures for 18739271Skfall * previous user name, but don't bother logging one failure 18836647Skarels * for nonexistent name (mistyped username). 18936647Skarels */ 19036647Skarels if (failures && strcmp(tbuf, username)) { 19136647Skarels if (failures > (pwd ? 0 : 1)) 19236549Sbostic badlogin(tbuf); 19336647Skarels failures = 0; 19436549Sbostic } 19536647Skarels (void)strcpy(tbuf, username); 19636515Sbostic if (pwd = getpwnam(username)) 19736515Sbostic salt = pwd->pw_passwd; 198*43653Sbostic else { 199*43653Sbostic /* take up the right amount of time */ 200*43653Sbostic (void)crypt(getpass("Password:"), "xx"); 201*43653Sbostic goto faked; 202*43653Sbostic } 20336460Sbostic 20436460Sbostic /* if user not super-user, check for disabled logins */ 205*43653Sbostic if (pwd->pw_uid) 20636460Sbostic checknologin(); 20736460Sbostic 20812687Ssam /* 20936515Sbostic * Disallow automatic login to root; if not invoked by 21036515Sbostic * root, disallow if the uid's differ. 21112687Ssam */ 212*43653Sbostic if (fflag) { 21338726Skfall passwd_req = 21438726Skfall #ifndef KERBEROS 21538726Skfall pwd->pw_uid == 0 || 21638726Skfall #endif 21736515Sbostic (uid && uid != pwd->pw_uid); 21831695Skarels } 21936460Sbostic 22012687Ssam /* 22136523Skarels * If no pre-authentication and a password exists 22236460Sbostic * for this user, prompt for one and verify it. 22312687Ssam */ 224*43653Sbostic if (!passwd_req || !*pwd->pw_passwd) 22536460Sbostic break; 22612687Ssam 22739271Skfall /* 22839271Skfall * If trying to log in as root, but with insecure terminal, 22939271Skfall * refuse the login attempt. 23039271Skfall */ 23139271Skfall if (pwd->pw_uid == 0 && !rootterm(tty)) { 23239271Skfall (void)fprintf(stderr, 23339271Skfall "%s login refused on this terminal.\n", 23439271Skfall pwd->pw_name); 23539271Skfall if (hostname) 23639271Skfall syslog(LOG_NOTICE, 23739271Skfall "LOGIN %s REFUSED FROM %s ON TTY %s", 23839271Skfall pwd->pw_name, hostname, tty); 23939271Skfall else 24039271Skfall syslog(LOG_NOTICE, 24139271Skfall "LOGIN %s REFUSED ON TTY %s", 24239271Skfall pwd->pw_name, tty); 24339271Skfall continue; 24439271Skfall } 24539271Skfall 246*43653Sbostic (void)setpriority(PRIO_PROCESS, 0, -4); 247*43653Sbostic p = getpass("Password:"); 24836608Skfall 249*43653Sbostic #ifdef KERBEROS 250*43653Sbostic rval = klogin(pwd, localhost, p); 251*43653Sbostic if (rval == 1) 252*43653Sbostic rval = strcmp(crypt(p, salt), pwd->pw_passwd); 253*43653Sbostic #else 254*43653Sbostic rval = strcmp(crypt(p, salt), pwd->pw_passwd); 25537203Sbostic #endif 256*43653Sbostic bzero(p, strlen(p)); 257*43653Sbostic if (!rval) 25836460Sbostic break; 25936460Sbostic 260*43653Sbostic faked: (void)printf("Login incorrect\n"); 26136647Skarels failures++; 26236549Sbostic /* we allow 10 tries, but after 3 we start backing off */ 26336549Sbostic if (++cnt > 3) { 26436549Sbostic if (cnt >= 10) { 26536549Sbostic badlogin(username); 26636549Sbostic (void)ioctl(0, TIOCHPCL, (struct sgttyb *)NULL); 26736549Sbostic sleepexit(1); 26836549Sbostic } 26936549Sbostic sleep((u_int)((cnt - 3) * 5)); 2702822Swnj } 27136460Sbostic } 2721043Sbill 27336460Sbostic /* committed to login -- turn off timeout */ 27436460Sbostic (void)alarm((u_int)0); 27536460Sbostic 276*43653Sbostic /* reset priority */ 277*43653Sbostic (void)setpriority(PRIO_PROCESS, 0, 0); 278*43653Sbostic 27937692Sbostic /* paranoia... */ 28037692Sbostic endpwent(); 28137692Sbostic 28236515Sbostic if (chdir(pwd->pw_dir) < 0) { 28337203Sbostic (void)printf("No directory %s!\n", pwd->pw_dir); 28436515Sbostic if (chdir("/")) 28536515Sbostic exit(0); 28636515Sbostic pwd->pw_dir = "/"; 28737203Sbostic (void)printf("Logging in with home = \"/\".\n"); 28836515Sbostic } 28936515Sbostic 29037203Sbostic quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0; 29137203Sbostic 29236880Sbostic if (pwd->pw_change || pwd->pw_expire) 29336880Sbostic (void)gettimeofday(&tp, (struct timezone *)NULL); 29436880Sbostic if (pwd->pw_change) 29536880Sbostic if (tp.tv_sec >= pwd->pw_change) { 29637203Sbostic (void)printf("Sorry -- your password has expired.\n"); 29736880Sbostic sleepexit(1); 29836880Sbostic } 29938216Sbostic else if (pwd->pw_change - tp.tv_sec < 30038216Sbostic 2 * DAYSPERWEEK * SECSPERDAY && !quietlog) { 30136880Sbostic ttp = localtime(&pwd->pw_change); 30237203Sbostic (void)printf("Warning: your password expires on %s %d, %d\n", 30338216Sbostic months[ttp->tm_mon], ttp->tm_mday, 30438216Sbostic TM_YEAR_BASE + ttp->tm_year); 30536880Sbostic } 30636880Sbostic if (pwd->pw_expire) 30736880Sbostic if (tp.tv_sec >= pwd->pw_expire) { 30837203Sbostic (void)printf("Sorry -- your account has expired.\n"); 30936880Sbostic sleepexit(1); 31036880Sbostic } 31138216Sbostic else if (pwd->pw_expire - tp.tv_sec < 31238216Sbostic 2 * DAYSPERWEEK * SECSPERDAY && !quietlog) { 31336880Sbostic ttp = localtime(&pwd->pw_expire); 31437203Sbostic (void)printf("Warning: your account expires on %s %d, %d\n", 31538216Sbostic months[ttp->tm_mon], ttp->tm_mday, 31638216Sbostic TM_YEAR_BASE + ttp->tm_year); 31736880Sbostic } 31836880Sbostic 31936515Sbostic /* nothing else left to fail -- really log in */ 32036460Sbostic { 32136460Sbostic struct utmp utmp; 32236460Sbostic 323*43653Sbostic bzero((void *)&utmp, sizeof(utmp)); 32436460Sbostic (void)time(&utmp.ut_time); 32536460Sbostic strncpy(utmp.ut_name, username, sizeof(utmp.ut_name)); 32636591Sbostic if (hostname) 32736591Sbostic strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); 32836460Sbostic strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line)); 32936460Sbostic login(&utmp); 33036460Sbostic } 33136460Sbostic 33236549Sbostic dolastlog(quietlog); 33336460Sbostic 33437203Sbostic if (!hflag) { /* XXX */ 33536460Sbostic static struct winsize win = { 0, 0, 0, 0 }; 33636460Sbostic 33736460Sbostic (void)ioctl(0, TIOCSWINSZ, &win); 33836460Sbostic } 33936460Sbostic 34036460Sbostic (void)chown(ttyn, pwd->pw_uid, 34136460Sbostic (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid); 34236460Sbostic (void)chmod(ttyn, 0620); 34336460Sbostic (void)setgid(pwd->pw_gid); 34436460Sbostic 34536460Sbostic initgroups(username, pwd->pw_gid); 34636460Sbostic 34736515Sbostic if (*pwd->pw_shell == '\0') 34837203Sbostic pwd->pw_shell = _PATH_BSHELL; 34936515Sbostic 35036460Sbostic /* destroy environment unless user has requested preservation */ 35118549Ssam if (!pflag) 35218549Ssam environ = envinit; 35336515Sbostic (void)setenv("HOME", pwd->pw_dir, 1); 35436515Sbostic (void)setenv("SHELL", pwd->pw_shell, 1); 35518549Ssam if (term[0] == '\0') 35636647Skarels strncpy(term, stypeof(tty), sizeof(term)); 35736515Sbostic (void)setenv("TERM", term, 0); 35836515Sbostic (void)setenv("USER", pwd->pw_name, 1); 35937252Sbostic (void)setenv("PATH", _PATH_DEFPATH, 0); 36018549Ssam 36116453Sroot if (tty[sizeof("tty")-1] == 'd') 36218549Ssam syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name); 36318549Ssam if (pwd->pw_uid == 0) 36436460Sbostic if (hostname) 36536647Skarels syslog(LOG_NOTICE, "ROOT LOGIN ON %s FROM %s", 36636549Sbostic tty, hostname); 36725230Smckusick else 36836647Skarels syslog(LOG_NOTICE, "ROOT LOGIN ON %s", tty); 36936460Sbostic 370*43653Sbostic #ifdef KERBEROS 371*43653Sbostic if (!quietlog && notickets == 1) 372*43653Sbostic (void)printf("Warning: no Kerberos tickets issued.\n"); 373*43653Sbostic #endif 374*43653Sbostic 3756329Swnj if (!quietlog) { 37617664Sserge struct stat st; 37718549Ssam 37836460Sbostic motd(); 37937203Sbostic (void)sprintf(tbuf, "%s/%s", _PATH_MAILDIR, pwd->pw_name); 38036460Sbostic if (stat(tbuf, &st) == 0 && st.st_size != 0) 38137203Sbostic (void)printf("You have %smail.\n", 38236460Sbostic (st.st_mtime > st.st_atime) ? "new " : ""); 3832822Swnj } 38436460Sbostic 38536460Sbostic (void)signal(SIGALRM, SIG_DFL); 38636460Sbostic (void)signal(SIGQUIT, SIG_DFL); 38736460Sbostic (void)signal(SIGINT, SIG_DFL); 38836460Sbostic (void)signal(SIGTSTP, SIG_IGN); 38936460Sbostic 39036460Sbostic tbuf[0] = '-'; 39136460Sbostic strcpy(tbuf + 1, (p = rindex(pwd->pw_shell, '/')) ? 39236460Sbostic p + 1 : pwd->pw_shell); 39337203Sbostic 39440009Ssklower if (setlogin(pwd->pw_name) < 0) 39540009Ssklower syslog(LOG_ERR, "setlogin() failure: %m"); 39637692Sbostic 39737203Sbostic /* discard permissions last so can't get killed and drop core */ 39837203Sbostic (void)setuid(pwd->pw_uid); 39937203Sbostic 40036460Sbostic execlp(pwd->pw_shell, tbuf, 0); 40137203Sbostic (void)fprintf(stderr, "login: no shell: %s.\n", strerror(errno)); 4021043Sbill exit(0); 4031043Sbill } 4041043Sbill 40536460Sbostic getloginname() 40612687Ssam { 40736460Sbostic register int ch; 40836460Sbostic register char *p; 40936460Sbostic static char nbuf[UT_NAMESIZE + 1]; 41012687Ssam 41136460Sbostic for (;;) { 41237203Sbostic (void)printf("login: "); 41336515Sbostic for (p = nbuf; (ch = getchar()) != '\n'; ) { 41436549Sbostic if (ch == EOF) { 41536549Sbostic badlogin(username); 41612687Ssam exit(0); 41736549Sbostic } 41836515Sbostic if (p < nbuf + UT_NAMESIZE) 41936460Sbostic *p++ = ch; 42012687Ssam } 42136460Sbostic if (p > nbuf) 42236460Sbostic if (nbuf[0] == '-') 42337203Sbostic (void)fprintf(stderr, 42436460Sbostic "login names may not start with '-'.\n"); 42536460Sbostic else { 42636460Sbostic *p = '\0'; 42736460Sbostic username = nbuf; 42836515Sbostic break; 42936460Sbostic } 43012687Ssam } 43112687Ssam } 43212687Ssam 433*43653Sbostic void 43412687Ssam timedout() 43512687Ssam { 43637203Sbostic (void)fprintf(stderr, "Login timed out after %d seconds\n", timeout); 43712687Ssam exit(0); 43812687Ssam } 43912687Ssam 44036647Skarels rootterm(ttyn) 44136647Skarels char *ttyn; 4421043Sbill { 44336460Sbostic struct ttyent *t; 4446466Swnj 44536647Skarels return((t = getttynam(ttyn)) && t->ty_status&TTY_SECURE); 4461043Sbill } 4471043Sbill 44836515Sbostic jmp_buf motdinterrupt; 44936515Sbostic 45036460Sbostic motd() 4512822Swnj { 45236515Sbostic register int fd, nchars; 45338726Skfall sig_t oldint; 45438726Skfall int sigint(); 45536515Sbostic char tbuf[8192]; 4562822Swnj 45737203Sbostic if ((fd = open(_PATH_MOTDFILE, O_RDONLY, 0)) < 0) 45836460Sbostic return; 45936460Sbostic oldint = signal(SIGINT, sigint); 46036515Sbostic if (setjmp(motdinterrupt) == 0) 46136515Sbostic while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) 46236515Sbostic (void)write(fileno(stdout), tbuf, nchars); 46336460Sbostic (void)signal(SIGINT, oldint); 46436515Sbostic (void)close(fd); 46536460Sbostic } 46636460Sbostic 46736460Sbostic sigint() 46836460Sbostic { 46936515Sbostic longjmp(motdinterrupt, 1); 47036460Sbostic } 47136460Sbostic 47236460Sbostic checknologin() 47336460Sbostic { 47436460Sbostic register int fd, nchars; 47536515Sbostic char tbuf[8192]; 47636460Sbostic 47737203Sbostic if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) { 47836460Sbostic while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) 47936460Sbostic (void)write(fileno(stdout), tbuf, nchars); 48036460Sbostic sleepexit(0); 4812822Swnj } 4822822Swnj } 4832822Swnj 48436549Sbostic dolastlog(quiet) 48536460Sbostic int quiet; 4861043Sbill { 48736460Sbostic struct lastlog ll; 48836460Sbostic int fd; 48936880Sbostic char *ctime(); 4901043Sbill 49137203Sbostic if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { 49236515Sbostic (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); 49336460Sbostic if (!quiet) { 49436460Sbostic if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && 49536460Sbostic ll.ll_time != 0) { 49637203Sbostic (void)printf("Last login: %.*s ", 49736460Sbostic 24-5, (char *)ctime(&ll.ll_time)); 49836460Sbostic if (*ll.ll_host != '\0') 49937203Sbostic (void)printf("from %.*s\n", 50036460Sbostic sizeof(ll.ll_host), ll.ll_host); 50136460Sbostic else 50237203Sbostic (void)printf("on %.*s\n", 50336460Sbostic sizeof(ll.ll_line), ll.ll_line); 50436460Sbostic } 50536515Sbostic (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); 50636460Sbostic } 507*43653Sbostic bzero((void *)&ll, sizeof(ll)); 50836460Sbostic (void)time(&ll.ll_time); 50936460Sbostic strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); 51036591Sbostic if (hostname) 51136591Sbostic strncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); 51236460Sbostic (void)write(fd, (char *)&ll, sizeof(ll)); 51336460Sbostic (void)close(fd); 5141043Sbill } 5151043Sbill } 5161043Sbill 51736549Sbostic badlogin(name) 51836549Sbostic char *name; 51936549Sbostic { 52036647Skarels if (failures == 0) 52136549Sbostic return; 52236549Sbostic if (hostname) 52336647Skarels syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s, %s", 52436647Skarels failures, failures > 1 ? "S" : "", hostname, name); 52536549Sbostic else 52636647Skarels syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s, %s", 52736647Skarels failures, failures > 1 ? "S" : "", tty, name); 52836549Sbostic } 52936549Sbostic 5302822Swnj #undef UNKNOWN 53136460Sbostic #define UNKNOWN "su" 5321043Sbill 5331043Sbill char * 53436647Skarels stypeof(ttyid) 53536647Skarels char *ttyid; 5361043Sbill { 53736460Sbostic struct ttyent *t; 5381043Sbill 53936647Skarels return(ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN); 5401043Sbill } 5416005Swnj 54236460Sbostic sleepexit(eval) 54336460Sbostic int eval; 54426862Smckusick { 54536460Sbostic sleep((u_int)5); 54636460Sbostic exit(eval); 54726862Smckusick } 548