login.c revision 25671
11590Srgrimes/*- 21590Srgrimes * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994 31590Srgrimes * The Regents of the University of California. All rights reserved. 41590Srgrimes * 51590Srgrimes * Redistribution and use in source and binary forms, with or without 61590Srgrimes * modification, are permitted provided that the following conditions 71590Srgrimes * are met: 81590Srgrimes * 1. Redistributions of source code must retain the above copyright 91590Srgrimes * notice, this list of conditions and the following disclaimer. 101590Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111590Srgrimes * notice, this list of conditions and the following disclaimer in the 121590Srgrimes * documentation and/or other materials provided with the distribution. 131590Srgrimes * 3. All advertising materials mentioning features or use of this software 141590Srgrimes * must display the following acknowledgement: 151590Srgrimes * This product includes software developed by the University of 161590Srgrimes * California, Berkeley and its contributors. 171590Srgrimes * 4. Neither the name of the University nor the names of its contributors 181590Srgrimes * may be used to endorse or promote products derived from this software 191590Srgrimes * without specific prior written permission. 201590Srgrimes * 211590Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221590Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231590Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241590Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251590Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261590Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271590Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281590Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291590Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301590Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311590Srgrimes * SUCH DAMAGE. 321590Srgrimes */ 331590Srgrimes 3423246Swosch#if 0 351590Srgrimesstatic char copyright[] = 361590Srgrimes"@(#) Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994\n\ 371590Srgrimes The Regents of the University of California. All rights reserved.\n"; 3823246Swosch#endif 391590Srgrimes 401590Srgrimes#ifndef lint 411590Srgrimesstatic char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94"; 421590Srgrimes#endif /* not lint */ 431590Srgrimes 441590Srgrimes/* 451590Srgrimes * login [ name ] 461590Srgrimes * login -h hostname (for telnetd, etc.) 471590Srgrimes * login -f name (for pre-authenticated login: datakit, xterm, etc.) 481590Srgrimes */ 491590Srgrimes 5023246Swosch#include <sys/copyright.h> 511590Srgrimes#include <sys/param.h> 521590Srgrimes#include <sys/stat.h> 531590Srgrimes#include <sys/time.h> 541590Srgrimes#include <sys/resource.h> 551590Srgrimes#include <sys/file.h> 5616423Sache#include <netinet/in.h> 5716423Sache#include <arpa/inet.h> 581590Srgrimes 591590Srgrimes#include <err.h> 601590Srgrimes#include <errno.h> 611590Srgrimes#include <grp.h> 6216423Sache#include <netdb.h> 631590Srgrimes#include <pwd.h> 641590Srgrimes#include <setjmp.h> 651590Srgrimes#include <signal.h> 661590Srgrimes#include <stdio.h> 671590Srgrimes#include <stdlib.h> 681590Srgrimes#include <string.h> 691590Srgrimes#include <syslog.h> 701590Srgrimes#include <ttyent.h> 711590Srgrimes#include <unistd.h> 721590Srgrimes#include <utmp.h> 731590Srgrimes 7421528Sdavidn#ifdef LOGIN_CAP 7521528Sdavidn#include <login_cap.h> 7621528Sdavidn#else /* Undef AUTH as well */ 7721528Sdavidn#undef LOGIN_CAP_AUTH 7821528Sdavidn#endif 7921528Sdavidn 8023985Sdavidn/* 8123985Sdavidn * If LOGIN_CAP_AUTH is activated: 8221528Sdavidn * kerberose & skey logins are runtime selected via login 8321528Sdavidn * login_getstyle() and authentication types for login classes 8421528Sdavidn * The actual login itself is handled via /usr/libexec/login_<style> 8521528Sdavidn * Valid styles are determined by the auth-type=style,style entries 8621528Sdavidn * in the login class. 8721528Sdavidn */ 8821528Sdavidn#ifdef LOGIN_CAP_AUTH 8921528Sdavidn#undef KERBEROS 9021528Sdavidn#undef SKEY 9123985Sdavidn#endif /* LOGIN_CAP_AUTH */ 9223985Sdavidn 933702Spst#ifdef SKEY 943702Spst#include <skey.h> 9521528Sdavidn#endif /* SKEY */ 963702Spst 971590Srgrimes#include "pathnames.h" 981590Srgrimes 991590Srgrimesvoid badlogin __P((char *)); 1001590Srgrimesvoid checknologin __P((void)); 1011590Srgrimesvoid dolastlog __P((int)); 1021590Srgrimesvoid getloginname __P((void)); 10321528Sdavidnvoid motd __P((char *)); 1041590Srgrimesint rootterm __P((char *)); 1051590Srgrimesvoid sigint __P((int)); 1061590Srgrimesvoid sleepexit __P((int)); 10723985Sdavidnvoid refused __P((char *,char *,int)); 1081590Srgrimeschar *stypeof __P((char *)); 1091590Srgrimesvoid timedout __P((int)); 1102224Sguidovoid login_fbtab __P((char *, uid_t, gid_t)); 1111590Srgrimes#ifdef KERBEROS 1121590Srgrimesint klogin __P((struct passwd *, char *, char *, char *)); 1131590Srgrimes#endif 1141590Srgrimes 1151590Srgrimesextern void login __P((struct utmp *)); 1161590Srgrimes 1171590Srgrimes#define TTYGRPNAME "tty" /* name of group to own ttys */ 11823985Sdavidn#define DEFAULT_BACKOFF 3 11923985Sdavidn#define DEFAULT_RETRIES 10 1201590Srgrimes 1211590Srgrimes/* 1221590Srgrimes * This bounds the time given to login. Not a define so it can 1231590Srgrimes * be patched on machines where it's too small. 1241590Srgrimes */ 1251590Srgrimesu_int timeout = 300; 1261590Srgrimes 1271590Srgrimes#ifdef KERBEROS 1281590Srgrimesint notickets = 1; 1295627Swollmanint noticketsdontcomplain = 1; 1301590Srgrimeschar *instance; 1311590Srgrimeschar *krbtkfile_env; 1321590Srgrimesint authok; 1331590Srgrimes#endif 1341590Srgrimes 1351590Srgrimesstruct passwd *pwd; 1361590Srgrimesint failures; 13723985Sdavidnchar *term, *envinit[1], *hostname, *username, *tty; 13816423Sachechar full_hostname[MAXHOSTNAMELEN]; 1391590Srgrimes 1401590Srgrimesint 1411590Srgrimesmain(argc, argv) 1421590Srgrimes int argc; 1431590Srgrimes char *argv[]; 1441590Srgrimes{ 1451590Srgrimes extern char **environ; 1461590Srgrimes struct group *gr; 1471590Srgrimes struct stat st; 1481590Srgrimes struct timeval tp; 1491590Srgrimes struct utmp utmp; 15023985Sdavidn int rootok, retries, backoff; 1511590Srgrimes int ask, ch, cnt, fflag, hflag, pflag, quietlog, rootlogin, rval; 1524878Sugen int changepass; 15323985Sdavidn time_t warntime; 1541590Srgrimes uid_t uid; 1553205Spst char *domain, *p, *ep, *salt, *ttyn; 1561590Srgrimes char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; 1571590Srgrimes char localhost[MAXHOSTNAMELEN]; 15823985Sdavidn char *shell = NULL; 15921528Sdavidn#ifdef LOGIN_CAP 16021528Sdavidn login_cap_t *lc = NULL; 16121528Sdavidn#ifdef LOGIN_CAP_AUTH 16221528Sdavidn char *style, *authtype; 16321528Sdavidn char *auth_method = NULL; 16421528Sdavidn char *instance = NULL; 16521528Sdavidn int authok; 16623985Sdavidn#endif /* LOGIN_CAP_AUTH */ 16723985Sdavidn#endif /* LOGIN_CAP */ 16821528Sdavidn#ifdef SKEY 1693205Spst int permit_passwd = 0; 17021528Sdavidn#endif /* SKEY */ 1711590Srgrimes 1721590Srgrimes (void)signal(SIGALRM, timedout); 1731590Srgrimes (void)alarm(timeout); 1741590Srgrimes (void)signal(SIGQUIT, SIG_IGN); 1751590Srgrimes (void)signal(SIGINT, SIG_IGN); 1761590Srgrimes (void)setpriority(PRIO_PROCESS, 0, 0); 1771590Srgrimes 1781590Srgrimes openlog("login", LOG_ODELAY, LOG_AUTH); 1791590Srgrimes 1801590Srgrimes /* 1811590Srgrimes * -p is used by getty to tell login not to destroy the environment 1821590Srgrimes * -f is used to skip a second login authentication 1831590Srgrimes * -h is used by other servers to pass the name of the remote 1841590Srgrimes * host to login so that it may be placed in utmp and wtmp 1851590Srgrimes */ 1863205Spst *full_hostname = '\0'; 1871590Srgrimes domain = NULL; 18823985Sdavidn term = NULL; 1891590Srgrimes if (gethostname(localhost, sizeof(localhost)) < 0) 1901590Srgrimes syslog(LOG_ERR, "couldn't get local hostname: %m"); 1911590Srgrimes else 1921590Srgrimes domain = strchr(localhost, '.'); 1931590Srgrimes 1941590Srgrimes fflag = hflag = pflag = 0; 1951590Srgrimes uid = getuid(); 19624360Simp while ((ch = getopt(argc, argv, "fh:p")) != -1) 1971590Srgrimes switch (ch) { 1981590Srgrimes case 'f': 1991590Srgrimes fflag = 1; 2001590Srgrimes break; 2011590Srgrimes case 'h': 2021590Srgrimes if (uid) 2031590Srgrimes errx(1, "-h option: %s", strerror(EPERM)); 2041590Srgrimes hflag = 1; 2053205Spst strncpy(full_hostname, optarg, sizeof(full_hostname)-1); 2061590Srgrimes if (domain && (p = strchr(optarg, '.')) && 2071590Srgrimes strcasecmp(p, domain) == 0) 2081590Srgrimes *p = 0; 20916423Sache if (strlen(optarg) > UT_HOSTSIZE) { 21016423Sache struct hostent *hp = gethostbyname(optarg); 21116423Sache 21216423Sache if (hp != NULL) { 21316423Sache struct in_addr in; 21416423Sache 21516423Sache memmove(&in, hp->h_addr, sizeof(in)); 21616423Sache optarg = strdup(inet_ntoa(in)); 21716423Sache } else 21816423Sache optarg = "invalid hostname"; 21916423Sache } 2201590Srgrimes hostname = optarg; 2211590Srgrimes break; 2221590Srgrimes case 'p': 2231590Srgrimes pflag = 1; 2241590Srgrimes break; 2251590Srgrimes case '?': 2261590Srgrimes default: 2271590Srgrimes if (!uid) 2281590Srgrimes syslog(LOG_ERR, "invalid flag %c", ch); 2291590Srgrimes (void)fprintf(stderr, 2301590Srgrimes "usage: login [-fp] [-h hostname] [username]\n"); 2311590Srgrimes exit(1); 2321590Srgrimes } 2331590Srgrimes argc -= optind; 2341590Srgrimes argv += optind; 2351590Srgrimes 2361590Srgrimes if (*argv) { 2371590Srgrimes username = *argv; 2381590Srgrimes ask = 0; 2391590Srgrimes } else 2401590Srgrimes ask = 1; 2411590Srgrimes 2421590Srgrimes for (cnt = getdtablesize(); cnt > 2; cnt--) 2431590Srgrimes (void)close(cnt); 2441590Srgrimes 2451590Srgrimes ttyn = ttyname(STDIN_FILENO); 2461590Srgrimes if (ttyn == NULL || *ttyn == '\0') { 2471590Srgrimes (void)snprintf(tname, sizeof(tname), "%s??", _PATH_TTY); 2481590Srgrimes ttyn = tname; 2491590Srgrimes } 25023985Sdavidn if ((tty = strrchr(ttyn, '/')) != NULL) 2511590Srgrimes ++tty; 2521590Srgrimes else 2531590Srgrimes tty = ttyn; 2541590Srgrimes 25521528Sdavidn#ifdef LOGIN_CAP_AUTH 25621528Sdavidn authtype = hostname ? "rlogin" : "login"; 25721528Sdavidn#endif 25823985Sdavidn#ifdef LOGIN_CAP 25923985Sdavidn /* 26023985Sdavidn * Get "login-retries" & "login-backoff" from default class 26123985Sdavidn */ 26223985Sdavidn lc = login_getclass(NULL); 26323985Sdavidn retries = login_getcapnum(lc, "login-retries", DEFAULT_RETRIES, DEFAULT_RETRIES); 26423985Sdavidn backoff = login_getcapnum(lc, "login-backoff", DEFAULT_BACKOFF, DEFAULT_BACKOFF); 26523985Sdavidn login_close(lc); 26623985Sdavidn lc = NULL; 26723985Sdavidn#else 26823985Sdavidn retries = DEFAULT_RETRIES; 26923985Sdavidn backoff = DEFAULT_BACKOFF; 27023985Sdavidn#endif 27121528Sdavidn 2721590Srgrimes for (cnt = 0;; ask = 1) { 2731590Srgrimes if (ask) { 2741590Srgrimes fflag = 0; 2751590Srgrimes getloginname(); 2761590Srgrimes } 2771590Srgrimes rootlogin = 0; 27821528Sdavidn rootok = rootterm(tty); /* Default (auth may change) */ 27921528Sdavidn#ifdef LOGIN_CAP_AUTH 28021528Sdavidn authok = 0; 28121528Sdavidn if (auth_method = strchr(username, ':')) { 28221528Sdavidn *auth_method = '\0'; 28321528Sdavidn auth_method++; 28421528Sdavidn if (*auth_method == '\0') 28521528Sdavidn auth_method = NULL; 28621528Sdavidn } 28721528Sdavidn /* 28821528Sdavidn * We need to do this regardless of whether 28921528Sdavidn * kerberos is available. 29021528Sdavidn */ 2911590Srgrimes if ((instance = strchr(username, '.')) != NULL) { 2921590Srgrimes if (strncmp(instance, ".root", 5) == 0) 2931590Srgrimes rootlogin = 1; 2941590Srgrimes *instance++ = '\0'; 2951590Srgrimes } else 2961590Srgrimes instance = ""; 29721528Sdavidn#else /* !LOGIN_CAP_AUTH */ 29821528Sdavidn#ifdef KERBEROS 29921528Sdavidn if ((instance = strchr(username, '.')) != NULL) { 30021528Sdavidn if (strncmp(instance, ".root", 5) == 0) 30121528Sdavidn rootlogin = 1; 30221528Sdavidn *instance++ = '\0'; 30321528Sdavidn } else 30421528Sdavidn instance = ""; 30521528Sdavidn#endif /* KERBEROS */ 30621528Sdavidn#endif /* LOGIN_CAP_AUTH */ 30721528Sdavidn 3081590Srgrimes if (strlen(username) > UT_NAMESIZE) 3091590Srgrimes username[UT_NAMESIZE] = '\0'; 3101590Srgrimes 3111590Srgrimes /* 3121590Srgrimes * Note if trying multiple user names; log failures for 3131590Srgrimes * previous user name, but don't bother logging one failure 3141590Srgrimes * for nonexistent name (mistyped username). 3151590Srgrimes */ 3161590Srgrimes if (failures && strcmp(tbuf, username)) { 3171590Srgrimes if (failures > (pwd ? 0 : 1)) 3181590Srgrimes badlogin(tbuf); 3191590Srgrimes failures = 0; 3201590Srgrimes } 3211590Srgrimes (void)strcpy(tbuf, username); 3221590Srgrimes 32323985Sdavidn if ((pwd = getpwnam(username)) != NULL) 32423985Sdavidn salt = pwd->pw_passwd; 32523985Sdavidn else 32623985Sdavidn salt = "xx"; 32723985Sdavidn 32821528Sdavidn#ifdef LOGIN_CAP 32923985Sdavidn /* 33023985Sdavidn * Establish the class now, before we might goto 33121528Sdavidn * within the next block. pwd can be NULL since it 33221528Sdavidn * falls back to the "default" class if it is. 33321528Sdavidn */ 33425671Sdavidn lc = login_getpwclass(pwd); 33521528Sdavidn#endif /* LOGIN_CAP */ 3361590Srgrimes 3371590Srgrimes /* 3381590Srgrimes * if we have a valid account name, and it doesn't have a 3391590Srgrimes * password, or the -f option was specified and the caller 3401590Srgrimes * is root or the caller isn't changing their uid, don't 3411590Srgrimes * authenticate. 3421590Srgrimes */ 34323985Sdavidn rval = 1; 34421528Sdavidn if (pwd != NULL) { 3453205Spst if (pwd->pw_uid == 0) 3463205Spst rootlogin = 1; 3473205Spst 34823985Sdavidn if (fflag && (uid == (uid_t)0 || 34923985Sdavidn uid == (uid_t)pwd->pw_uid)) { 3503205Spst /* already authenticated */ 3513205Spst break; 3523205Spst } else if (pwd->pw_passwd[0] == '\0') { 35324321Sdavidn if (!rootlogin || rootok) { 35424251Sdavidn /* pretend password okay */ 35524251Sdavidn rval = 0; 35624251Sdavidn goto ttycheck; 35724251Sdavidn } 3583205Spst } 3593205Spst } 3603205Spst 3611590Srgrimes fflag = 0; 3621590Srgrimes 3631590Srgrimes (void)setpriority(PRIO_PROCESS, 0, -4); 3641590Srgrimes 36521528Sdavidn#ifdef LOGIN_CAP_AUTH 36621528Sdavidn /* 36723985Sdavidn * This hands off authorization to an authorization program, 36821528Sdavidn * depending on the styles available for the "auth-login", 36923985Sdavidn * auth-rlogin (or default) authorization styles. 37021528Sdavidn * We do this regardless of whether an account exists so that 37121528Sdavidn * the remote user cannot tell a "real" from an invented 37221528Sdavidn * account name. If we don't have an account we just fall 37321528Sdavidn * back to the first method for the "default" class. 37421528Sdavidn */ 37523985Sdavidn if (!(style = login_getstyle(lc, auth_method, authtype))) { 37623985Sdavidn 37723985Sdavidn /* 37823985Sdavidn * No available authorization method 37923985Sdavidn */ 38023985Sdavidn rval = 1; 38123985Sdavidn (void)printf("No auth method available for %s.\n", 38223985Sdavidn authtype); 38321528Sdavidn } else { 38423985Sdavidn 38523985Sdavidn /* 38623985Sdavidn * Put back the kerberos instance, if any was given. 38721528Sdavidn * Don't worry about the non-kerberos case here, since 38821528Sdavidn * if kerberos is not available or not selected and an 38921528Sdavidn * instance is given at the login prompt, su or rlogin -l, 39021528Sdavidn * then anything else should fail as well. 39121528Sdavidn */ 39221528Sdavidn if (*instance) 39321528Sdavidn *(instance - 1) = '.'; 39423985Sdavidn 39523985Sdavidn rval = authenticate(username, 39623985Sdavidn lc ? lc->lc_class : "default", 39723985Sdavidn style, authtype); 39821528Sdavidn /* Junk it again */ 39921528Sdavidn if (*instance) 40021528Sdavidn *(instance - 1) = '\0'; 40121528Sdavidn } 40221528Sdavidn 40321528Sdavidn if (!rval) { 40423985Sdavidn char * approvp; 40523985Sdavidn 40621528Sdavidn /* 40721528Sdavidn * If authentication succeeds, run any approval 40821528Sdavidn * program, if applicable for this class. 40921528Sdavidn */ 41023985Sdavidn approvep = login_getcapstr(lc, "approve", NULL, NULL); 41121528Sdavidn rval = 1; /* Assume bad login again */ 41223985Sdavidn 41323985Sdavidn if (approvep==NULL || 41423985Sdavidn auth_script(approvep, approvep, username, 41523985Sdavidn lc->lc_class, 0) == 0) { 41623985Sdavidn int r; 41723985Sdavidn 41823985Sdavidn r = auth_scan(AUTH_OKAY); 41923985Sdavidn /* 42023985Sdavidn * See what the authorize program says 42123985Sdavidn */ 42221528Sdavidn if (r != AUTH_NONE) { 42321528Sdavidn rval = 0; 42423985Sdavidn 42521528Sdavidn if (!rootok && (r & AUTH_ROOTOKAY)) 42621528Sdavidn rootok = 1; /* root approved */ 42723985Sdavidn else 42823985Sdavidn rootlogin = 0; 42923985Sdavidn 43021528Sdavidn if (!authok && (r & AUTH_SECURE)) 43121528Sdavidn authok = 1; /* secure */ 43221528Sdavidn } 43321528Sdavidn } 43421528Sdavidn } 43521528Sdavidn#else /* !LOGIN_CAP_AUTH */ 43621528Sdavidn#ifdef SKEY 43723985Sdavidn permit_passwd = skeyaccess(username, tty, 43823985Sdavidn hostname ? full_hostname : NULL, 43923985Sdavidn NULL); 4403205Spst p = skey_getpass("Password:", pwd, permit_passwd); 4413205Spst ep = skey_crypt(p, salt, pwd, permit_passwd); 44221528Sdavidn#else /* !SKEY */ 4431590Srgrimes p = getpass("Password:"); 4443205Spst ep = crypt(p, salt); 44521528Sdavidn#endif/* SKEY */ 44623985Sdavidn 44723985Sdavidn if (pwd) { 4481590Srgrimes#ifdef KERBEROS 4497800Swollman#ifdef SKEY 45023985Sdavidn /* 45123985Sdavidn * Do not allow user to type in kerberos password 4527800Swollman * over the net (actually, this is ok for encrypted 4537800Swollman * links, but we have no way of determining if the 4547800Swollman * link is encrypted. 4557800Swollman */ 4567893Srgrimes if (!permit_passwd) { 45723985Sdavidn rval = 1; /* failed */ 4587800Swollman } else 45921528Sdavidn#endif /* SKEY */ 4601590Srgrimes rval = klogin(pwd, instance, localhost, p); 4611590Srgrimes if (rval != 0 && rootlogin && pwd->pw_uid != 0) 4621590Srgrimes rootlogin = 0; 4631590Srgrimes if (rval == 0) 46421528Sdavidn authok = 1; /* kerberos authenticated ok */ 46521528Sdavidn else if (rval == 1) /* fallback to unix passwd */ 4663205Spst rval = strcmp(ep, pwd->pw_passwd); 46721528Sdavidn#else /* !KERBEROS */ 46823985Sdavidn rval = strcmp(ep, pwd->pw_passwd); 46921528Sdavidn#endif /* KERBEROS */ 47023985Sdavidn } 47123985Sdavidn 47221528Sdavidn /* clear entered password */ 4731590Srgrimes memset(p, 0, strlen(p)); 47421528Sdavidn#endif /* LOGIN_CAP_AUTH */ 4751590Srgrimes 4761590Srgrimes (void)setpriority(PRIO_PROCESS, 0, 0); 47723985Sdavidn 47825671Sdavidn#ifdef LOGIN_CAP_AUTH 47921528Sdavidn if (rval) 48021528Sdavidn auth_rmfiles(); 48121528Sdavidn#endif 4823205Spst ttycheck: 4831590Srgrimes /* 4841590Srgrimes * If trying to log in as root without Kerberos, 4851590Srgrimes * but with insecure terminal, refuse the login attempt. 4861590Srgrimes */ 48724222Sdavidn if (pwd && !rval) { 48821528Sdavidn#if defined(KERBEROS) || defined(LOGIN_CAP_AUTH) 48924222Sdavidn if (authok == 0 && rootlogin && !rootok) 49024222Sdavidn#else 49124222Sdavidn if (rootlogin && !rootok) 4921590Srgrimes#endif 49324222Sdavidn refused(NULL, "NOROOT", 0); 49424222Sdavidn else /* valid password & authenticated */ 49524222Sdavidn break; 4961590Srgrimes } 4971590Srgrimes 4981590Srgrimes (void)printf("Login incorrect\n"); 4991590Srgrimes failures++; 50023985Sdavidn 50123985Sdavidn /* 50223985Sdavidn * we allow up to 'retry' (10) tries, 50323985Sdavidn * but after 'backoff' (3) we start backing off 50423985Sdavidn */ 50523985Sdavidn if (++cnt > backoff) { 50623985Sdavidn if (cnt >= retries) { 5071590Srgrimes badlogin(username); 5081590Srgrimes sleepexit(1); 5091590Srgrimes } 5101590Srgrimes sleep((u_int)((cnt - 3) * 5)); 5111590Srgrimes } 5121590Srgrimes } 5131590Srgrimes 5141590Srgrimes /* committed to login -- turn off timeout */ 5151590Srgrimes (void)alarm((u_int)0); 5161590Srgrimes 5171590Srgrimes endpwent(); 5181590Srgrimes 5191590Srgrimes /* if user not super-user, check for disabled logins */ 52021528Sdavidn#ifdef LOGIN_CAP 5211590Srgrimes if (!rootlogin) 52221528Sdavidn auth_checknologin(lc); 52321528Sdavidn#else 52421528Sdavidn if (!rootlogin) 5251590Srgrimes checknologin(); 52621528Sdavidn#endif 5271590Srgrimes 52821528Sdavidn#ifdef LOGIN_CAP 52921528Sdavidn quietlog = login_getcapbool(lc, "hushlogin", 0); 53021528Sdavidn#else 53121528Sdavidn quietlog = 0; 53221528Sdavidn#endif 53321528Sdavidn if (!*pwd->pw_dir || chdir(pwd->pw_dir) < 0) { 53421528Sdavidn#ifdef LOGIN_CAP 53523985Sdavidn if (login_getcapbool(lc, "requirehome", !rootlogin)) 53623985Sdavidn refused("Home directory not available", "HOMEDIR", 1); 53723985Sdavidn#endif 53824485Sdavidn if (chdir("/") < 0) 53923985Sdavidn refused("Cannot find root directory", "ROOTDIR", 1); 5401590Srgrimes pwd->pw_dir = "/"; 54123985Sdavidn if (!quietlog || *pwd->pw_dir) 54223985Sdavidn printf("No home directory.\nLogging in with home = \"/\".\n"); 5431590Srgrimes } 54421528Sdavidn if (!quietlog) 54521528Sdavidn quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0; 5461590Srgrimes 5471590Srgrimes if (pwd->pw_change || pwd->pw_expire) 5481590Srgrimes (void)gettimeofday(&tp, (struct timezone *)NULL); 5492532Sjkh 55021528Sdavidn#define DEFAULT_WARN (2L * 7L & 86400L) /* Two weeks */ 55121528Sdavidn 55223985Sdavidn#ifdef LOGIN_CAP 55323985Sdavidn warntime = login_getcaptime(lc, "warnpassword", 55423985Sdavidn DEFAULT_WARN, DEFAULT_WARN); 55523985Sdavidn#else 55623985Sdavidn warntime = DEFAULT_WARN; 55723985Sdavidn#endif 55823985Sdavidn 5594878Sugen changepass=0; 56021528Sdavidn if (pwd->pw_change) { 5611590Srgrimes if (tp.tv_sec >= pwd->pw_change) { 5621590Srgrimes (void)printf("Sorry -- your password has expired.\n"); 5634878Sugen changepass=1; 56423985Sdavidn syslog(LOG_INFO, 56523985Sdavidn "%s Password expired - forcing change", 56623985Sdavidn pwd->pw_name); 56723985Sdavidn } else if (pwd->pw_change - tp.tv_sec < warntime && !quietlog) 56823985Sdavidn (void)printf("Warning: your password expires on %s", 56923985Sdavidn ctime(&pwd->pw_change)); 57023985Sdavidn } 57123985Sdavidn 57221528Sdavidn#ifdef LOGIN_CAP 57323985Sdavidn warntime = login_getcaptime(lc, "warnexpire", 57423985Sdavidn DEFAULT_WARN, DEFAULT_WARN); 57521528Sdavidn#else 57623985Sdavidn warntime = DEFAULT_WARN; 57721528Sdavidn#endif 57823985Sdavidn 57921528Sdavidn if (pwd->pw_expire) { 5801590Srgrimes if (tp.tv_sec >= pwd->pw_expire) { 58123985Sdavidn refused("Sorry -- your account has expired", 58223985Sdavidn "EXPIRED", 1); 58323985Sdavidn } else if (pwd->pw_expire - tp.tv_sec < warntime && !quietlog) 58423985Sdavidn (void)printf("Warning: your account expires on %s", 58523985Sdavidn ctime(&pwd->pw_expire)); 58621528Sdavidn } 5871590Srgrimes 58821528Sdavidn#ifdef LOGIN_CAP 58921528Sdavidn if (lc != NULL) { 59021528Sdavidn if (hostname) { 59121528Sdavidn struct hostent *hp = gethostbyname(full_hostname); 59221528Sdavidn 59321528Sdavidn if (hp == NULL) 59421528Sdavidn optarg = NULL; 59521528Sdavidn else { 59621528Sdavidn struct in_addr in; 59721528Sdavidn memmove(&in, hp->h_addr, sizeof(in)); 59821528Sdavidn optarg = strdup(inet_ntoa(in)); 59921528Sdavidn } 60023985Sdavidn if (!auth_hostok(lc, full_hostname, optarg)) 60123985Sdavidn refused("Permission denied", "HOST", 1); 60221528Sdavidn } 60321528Sdavidn 60423985Sdavidn if (!auth_ttyok(lc, tty)) 60523985Sdavidn refused("Permission denied", "TTY", 1); 60621528Sdavidn 60723985Sdavidn if (!auth_timeok(lc, time(NULL))) 60823985Sdavidn refused("Logins not available right now", "TIME", 1); 60921528Sdavidn } 61023985Sdavidn shell=login_getcapstr(lc, "shell", pwd->pw_shell, pwd->pw_shell); 61121528Sdavidn#else /* !LOGIN_CAP */ 61223985Sdavidn shell=pwd->pw_shell; 61321528Sdavidn#endif /* LOGIN_CAP */ 61423985Sdavidn if (*pwd->pw_shell == '\0') 61523985Sdavidn pwd->pw_shell = _PATH_BSHELL; 61623985Sdavidn if (*shell == '\0') /* Not overridden */ 61723985Sdavidn shell = pwd->pw_shell; 61823985Sdavidn if ((shell = strdup(shell)) == NULL) { 61923985Sdavidn syslog(LOG_NOTICE, "memory allocation error"); 62023985Sdavidn sleepexit(1); 62123985Sdavidn } 62221528Sdavidn 62321528Sdavidn#ifdef LOGIN_ACCESS 62423985Sdavidn if (login_access(pwd->pw_name, hostname ? full_hostname : tty) == 0) 62523985Sdavidn refused("Permission denied", "ACCESS", 1); 62621528Sdavidn#endif /* LOGIN_ACCESS */ 62721528Sdavidn 6281590Srgrimes /* Nothing else left to fail -- really log in. */ 6291590Srgrimes memset((void *)&utmp, 0, sizeof(utmp)); 6301590Srgrimes (void)time(&utmp.ut_time); 6311590Srgrimes (void)strncpy(utmp.ut_name, username, sizeof(utmp.ut_name)); 6321590Srgrimes if (hostname) 6331590Srgrimes (void)strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host)); 6341590Srgrimes (void)strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line)); 6351590Srgrimes login(&utmp); 6361590Srgrimes 6371590Srgrimes dolastlog(quietlog); 6381590Srgrimes 6392224Sguido /* 6402224Sguido * Set device protections, depending on what terminal the 6412224Sguido * user is logged in. This feature is used on Suns to give 6422224Sguido * console users better privacy. 6432224Sguido */ 6442224Sguido login_fbtab(tty, pwd->pw_uid, pwd->pw_gid); 6452224Sguido 64623985Sdavidn (void)chown(ttyn, pwd->pw_uid, 64723985Sdavidn (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid); 6481590Srgrimes 64923985Sdavidn /* 65023985Sdavidn * Preserve TERM if it happens to be already set. 65123985Sdavidn */ 65224222Sdavidn if ((term = getenv("TERM")) != NULL) 65324222Sdavidn term = strdup(term); 6541590Srgrimes 65523985Sdavidn /* 65623985Sdavidn * Exclude cons/vt/ptys only, assume dialup otherwise 65723985Sdavidn * TODO: Make dialup tty determination a library call 65823985Sdavidn * for consistency (finger etc.) 65923985Sdavidn */ 66024894Sdavidn if (hostname==NULL && isdialuptty(tty)) 6611590Srgrimes syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name); 6621590Srgrimes 6631590Srgrimes#ifdef KERBEROS 6645627Swollman if (!quietlog && notickets == 1 && !noticketsdontcomplain) 6651590Srgrimes (void)printf("Warning: no Kerberos tickets issued.\n"); 6661590Srgrimes#endif 6671590Srgrimes 6683205Spst#ifdef LOGALL 6693205Spst /* 6703205Spst * Syslog each successful login, so we don't have to watch hundreds 6713205Spst * of wtmp or lastlogin files. 6723205Spst */ 67323985Sdavidn if (hostname) 67423985Sdavidn syslog(LOG_INFO, "login from %s on %s as %s", 67523985Sdavidn full_hostname, tty, pwd->pw_name); 67623985Sdavidn else 67723985Sdavidn syslog(LOG_INFO, "login on %s as %s", 67823985Sdavidn tty, pwd->pw_name); 67921528Sdavidn#endif 68021528Sdavidn 68123985Sdavidn /* 68223985Sdavidn * If fflag is on, assume caller/authenticator has logged root login. 68323985Sdavidn */ 68423985Sdavidn if (rootlogin && fflag == 0) 68523985Sdavidn { 68623985Sdavidn if (hostname) 68723985Sdavidn syslog(LOG_NOTICE, "ROOT LOGIN (%s) ON %s FROM %s", 68823985Sdavidn username, tty, full_hostname); 68923985Sdavidn else 69023985Sdavidn syslog(LOG_NOTICE, "ROOT LOGIN (%s) ON %s", 69123985Sdavidn username, tty); 69223985Sdavidn } 69323985Sdavidn 69423985Sdavidn /* 69523985Sdavidn * Destroy environment unless user has requested its preservation. 69623985Sdavidn * We need to do this before setusercontext() because that may 69723985Sdavidn * set or reset some environment variables. 69823985Sdavidn */ 69921528Sdavidn if (!pflag) 70021528Sdavidn environ = envinit; 70121528Sdavidn 70223985Sdavidn /* 70323985Sdavidn * We don't need to be root anymore, so 70421528Sdavidn * set the user and session context 70521528Sdavidn */ 70621528Sdavidn#ifdef LOGIN_CAP 70721528Sdavidn if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL) != 0) { 70821528Sdavidn syslog(LOG_ERR, "setusercontext() failed - exiting"); 70921528Sdavidn exit(1); 7103205Spst } 71121528Sdavidn#else 71221528Sdavidn if (setlogin(pwd->pw_name) < 0) 71321528Sdavidn syslog(LOG_ERR, "setlogin() failure: %m"); 71421528Sdavidn 71521528Sdavidn (void)setgid(pwd->pw_gid); 71621528Sdavidn initgroups(username, pwd->pw_gid); 71721528Sdavidn (void)setuid(rootlogin ? 0 : pwd->pw_uid); 7183205Spst#endif 7193205Spst 72023148Sache (void)setenv("SHELL", pwd->pw_shell, 1); 72121528Sdavidn (void)setenv("HOME", pwd->pw_dir, 1); 72223985Sdavidn if (term != NULL && *term != '\0') 72321528Sdavidn (void)setenv("TERM", term, 1); /* Preset overrides */ 72421528Sdavidn else { 72523985Sdavidn (void)setenv("TERM", stypeof(tty), 0); /* Fallback doesn't */ 72621528Sdavidn } 72721528Sdavidn (void)setenv("LOGNAME", pwd->pw_name, 1); 72821528Sdavidn (void)setenv("USER", pwd->pw_name, 1); 72921528Sdavidn (void)setenv("PATH", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH, 0); 73021528Sdavidn#ifdef KERBEROS 73121528Sdavidn if (krbtkfile_env) 73221528Sdavidn (void)setenv("KRBTKFILE", krbtkfile_env, 1); 73321528Sdavidn#endif 73423985Sdavidn#if LOGIN_CAP_AUTH 73523985Sdavidn auth_env(); 73621528Sdavidn#endif 73721528Sdavidn 73823985Sdavidn#ifdef LOGIN_CAP 7391590Srgrimes if (!quietlog) { 74023985Sdavidn char *cw; 74123985Sdavidn 74223985Sdavidn cw = login_getcapstr(lc, "copyright", NULL, NULL); 74321528Sdavidn if (cw != NULL && access(cw, F_OK) == 0) 74421528Sdavidn motd(cw); 74521528Sdavidn else 74623985Sdavidn (void)printf("%s\n\t%s %s\n", 74723985Sdavidn "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994", 74823985Sdavidn "The Regents of the University of California. ", 74923985Sdavidn "All rights reserved."); 75023985Sdavidn 75123985Sdavidn (void)printf("\n"); 75223985Sdavidn 75321528Sdavidn cw = login_getcapstr(lc, "welcome", NULL, NULL); 75421528Sdavidn if (cw == NULL || access(cw, F_OK) != 0) 75521528Sdavidn cw = _PATH_MOTDFILE; 75621528Sdavidn motd(cw); 75723985Sdavidn 75821528Sdavidn cw = getenv("MAIL"); /* $MAIL may have been set by class */ 75921528Sdavidn if (cw != NULL) { 76021528Sdavidn strncpy(tbuf, cw, sizeof(tbuf)); 76121528Sdavidn tbuf[sizeof(tbuf)-1] = '\0'; 76221528Sdavidn } else 76323985Sdavidn snprintf(tbuf, sizeof(tbuf), "%s/%s", 76423985Sdavidn _PATH_MAILDIR, pwd->pw_name); 76521528Sdavidn#else 76623985Sdavidn if (!quietlog) { 76723985Sdavidn (void)printf("%s\n\t%s %s\n", 76823985Sdavidn "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994", 76923985Sdavidn "The Regents of the University of California. ", 77023985Sdavidn "All rights reserved."); 77121528Sdavidn motd(_PATH_MOTDFILE); 77223985Sdavidn snprintf(tbuf, sizeof(tbuf), "%s/%s", 77323985Sdavidn _PATH_MAILDIR, pwd->pw_name); 77421528Sdavidn#endif 7751590Srgrimes if (stat(tbuf, &st) == 0 && st.st_size != 0) 77623985Sdavidn (void)printf("You have %smail.\n", 77723985Sdavidn (st.st_mtime > st.st_atime) ? "new " : ""); 7781590Srgrimes } 7791590Srgrimes 78021528Sdavidn#ifdef LOGIN_CAP 78121528Sdavidn login_close(lc); 7823205Spst#endif 7833205Spst 7841590Srgrimes (void)signal(SIGALRM, SIG_DFL); 7851590Srgrimes (void)signal(SIGQUIT, SIG_DFL); 7861590Srgrimes (void)signal(SIGINT, SIG_DFL); 7871590Srgrimes (void)signal(SIGTSTP, SIG_IGN); 7881590Srgrimes 7894878Sugen if (changepass) { 79021528Sdavidn if (system(_PATH_CHPASS) != 0) 7914878Sugen sleepexit(1); 7924878Sugen } 7934878Sugen 79423985Sdavidn /* 79523985Sdavidn * Login shells have a leading '-' in front of argv[0] 79623985Sdavidn */ 79723985Sdavidn tbuf[0] = '-'; 79823985Sdavidn (void)strcpy(tbuf + 1, (p = strrchr(pwd->pw_shell, '/')) ? p + 1 : pwd->pw_shell); 79923985Sdavidn 80021528Sdavidn execlp(shell, tbuf, 0); 80121528Sdavidn err(1, "%s", shell); 8021590Srgrimes} 8031590Srgrimes 8041590Srgrimes 80523985Sdavidn/* 80623985Sdavidn * Allow for authentication style and/or kerberos instance 80723985Sdavidn * */ 80821528Sdavidn 80921528Sdavidn#define NBUFSIZ UT_NAMESIZE + 64 81021528Sdavidn 8111590Srgrimesvoid 8121590Srgrimesgetloginname() 8131590Srgrimes{ 8141590Srgrimes int ch; 8151590Srgrimes char *p; 8161590Srgrimes static char nbuf[NBUFSIZ]; 8171590Srgrimes 8181590Srgrimes for (;;) { 8191590Srgrimes (void)printf("login: "); 8201590Srgrimes for (p = nbuf; (ch = getchar()) != '\n'; ) { 8211590Srgrimes if (ch == EOF) { 8221590Srgrimes badlogin(username); 8231590Srgrimes exit(0); 8241590Srgrimes } 8251590Srgrimes if (p < nbuf + (NBUFSIZ - 1)) 8261590Srgrimes *p++ = ch; 8271590Srgrimes } 8281590Srgrimes if (p > nbuf) 8291590Srgrimes if (nbuf[0] == '-') 8301590Srgrimes (void)fprintf(stderr, 8311590Srgrimes "login names may not start with '-'.\n"); 8321590Srgrimes else { 8331590Srgrimes *p = '\0'; 8341590Srgrimes username = nbuf; 8351590Srgrimes break; 8361590Srgrimes } 8371590Srgrimes } 8381590Srgrimes} 8391590Srgrimes 8401590Srgrimesint 8411590Srgrimesrootterm(ttyn) 8421590Srgrimes char *ttyn; 8431590Srgrimes{ 8441590Srgrimes struct ttyent *t; 84523985Sdavidn 8461590Srgrimes return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE); 8471590Srgrimes} 8481590Srgrimes 84921528Sdavidnvolatile int motdinterrupt; 8501590Srgrimes 85121528Sdavidn/* ARGSUSED */ 8521590Srgrimesvoid 85321528Sdavidnsigint(signo) 85421528Sdavidn int signo; 8551590Srgrimes{ 85621528Sdavidn motdinterrupt = 1; 85721528Sdavidn} 85821528Sdavidn 85921528Sdavidnvoid 86021528Sdavidnmotd(motdfile) 86121528Sdavidn char *motdfile; 86221528Sdavidn{ 8631590Srgrimes int fd, nchars; 8641590Srgrimes sig_t oldint; 86521528Sdavidn char tbuf[256]; 8661590Srgrimes 86721528Sdavidn if ((fd = open(motdfile, O_RDONLY, 0)) < 0) 8681590Srgrimes return; 86921528Sdavidn motdinterrupt = 0; 8701590Srgrimes oldint = signal(SIGINT, sigint); 87121528Sdavidn while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0 && !motdinterrupt) 87221528Sdavidn (void)write(fileno(stdout), tbuf, nchars); 8731590Srgrimes (void)signal(SIGINT, oldint); 8741590Srgrimes (void)close(fd); 8751590Srgrimes} 8761590Srgrimes 8771590Srgrimes/* ARGSUSED */ 8781590Srgrimesvoid 8791590Srgrimestimedout(signo) 8801590Srgrimes int signo; 8811590Srgrimes{ 8821590Srgrimes (void)fprintf(stderr, "Login timed out after %d seconds\n", timeout); 8831590Srgrimes exit(0); 8841590Srgrimes} 8851590Srgrimes 88621528Sdavidn#ifndef LOGIN_CAP 8871590Srgrimesvoid 8881590Srgrimeschecknologin() 8891590Srgrimes{ 8901590Srgrimes int fd, nchars; 8911590Srgrimes char tbuf[8192]; 8921590Srgrimes 8931590Srgrimes if ((fd = open(_PATH_NOLOGIN, O_RDONLY, 0)) >= 0) { 8941590Srgrimes while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0) 8951590Srgrimes (void)write(fileno(stdout), tbuf, nchars); 8961590Srgrimes sleepexit(0); 8971590Srgrimes } 8981590Srgrimes} 89921528Sdavidn#endif 9001590Srgrimes 9011590Srgrimesvoid 9021590Srgrimesdolastlog(quiet) 9031590Srgrimes int quiet; 9041590Srgrimes{ 9051590Srgrimes struct lastlog ll; 9061590Srgrimes int fd; 9071590Srgrimes 9081590Srgrimes if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { 9091590Srgrimes (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); 9101590Srgrimes if (!quiet) { 9111590Srgrimes if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) && 9121590Srgrimes ll.ll_time != 0) { 9131590Srgrimes (void)printf("Last login: %.*s ", 9141590Srgrimes 24-5, (char *)ctime(&ll.ll_time)); 9151590Srgrimes if (*ll.ll_host != '\0') 9161590Srgrimes (void)printf("from %.*s\n", 9171590Srgrimes (int)sizeof(ll.ll_host), 9181590Srgrimes ll.ll_host); 9191590Srgrimes else 9201590Srgrimes (void)printf("on %.*s\n", 9211590Srgrimes (int)sizeof(ll.ll_line), 9221590Srgrimes ll.ll_line); 9231590Srgrimes } 9241590Srgrimes (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); 9251590Srgrimes } 9261590Srgrimes memset((void *)&ll, 0, sizeof(ll)); 9271590Srgrimes (void)time(&ll.ll_time); 9281590Srgrimes (void)strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); 9291590Srgrimes if (hostname) 9301590Srgrimes (void)strncpy(ll.ll_host, hostname, sizeof(ll.ll_host)); 9311590Srgrimes (void)write(fd, (char *)&ll, sizeof(ll)); 9321590Srgrimes (void)close(fd); 9331590Srgrimes } 9341590Srgrimes} 9351590Srgrimes 9361590Srgrimesvoid 9371590Srgrimesbadlogin(name) 9381590Srgrimes char *name; 9391590Srgrimes{ 9401590Srgrimes 9411590Srgrimes if (failures == 0) 9421590Srgrimes return; 9431590Srgrimes if (hostname) { 9441590Srgrimes syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s", 94516423Sache failures, failures > 1 ? "S" : "", full_hostname); 9461590Srgrimes syslog(LOG_AUTHPRIV|LOG_NOTICE, 9471590Srgrimes "%d LOGIN FAILURE%s FROM %s, %s", 94816423Sache failures, failures > 1 ? "S" : "", full_hostname, name); 9491590Srgrimes } else { 9501590Srgrimes syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s", 9511590Srgrimes failures, failures > 1 ? "S" : "", tty); 9521590Srgrimes syslog(LOG_AUTHPRIV|LOG_NOTICE, 9531590Srgrimes "%d LOGIN FAILURE%s ON %s, %s", 9541590Srgrimes failures, failures > 1 ? "S" : "", tty, name); 9551590Srgrimes } 9561590Srgrimes} 9571590Srgrimes 9581590Srgrimes#undef UNKNOWN 9591590Srgrimes#define UNKNOWN "su" 9601590Srgrimes 9611590Srgrimeschar * 9621590Srgrimesstypeof(ttyid) 9631590Srgrimes char *ttyid; 9641590Srgrimes{ 96523985Sdavidn 9661590Srgrimes struct ttyent *t; 96723985Sdavidn 9681590Srgrimes return (ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN); 9691590Srgrimes} 9701590Srgrimes 9711590Srgrimesvoid 97223985Sdavidnrefused(msg, rtype, lout) 97323985Sdavidn char *msg; 97423985Sdavidn char *rtype; 97523985Sdavidn int lout; 97623985Sdavidn{ 97723985Sdavidn 97823985Sdavidn if (msg != NULL) 97923985Sdavidn printf("%s.\n", msg); 98023985Sdavidn if (hostname) 98123985Sdavidn syslog(LOG_NOTICE, "LOGIN %s REFUSED (%s) FROM %s ON TTY %s", 98223985Sdavidn pwd->pw_name, rtype, full_hostname, tty); 98323985Sdavidn else 98423985Sdavidn syslog(LOG_NOTICE, "LOGIN %s REFUSED (%s) ON TTY %s", 98523985Sdavidn pwd->pw_name, rtype, tty); 98623985Sdavidn if (lout) 98723985Sdavidn sleepexit(1); 98823985Sdavidn} 98923985Sdavidn 99023985Sdavidnvoid 9911590Srgrimessleepexit(eval) 9921590Srgrimes int eval; 9931590Srgrimes{ 99423985Sdavidn 9951590Srgrimes (void)sleep(5); 9961590Srgrimes exit(eval); 9971590Srgrimes} 998