2 * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char copyright[] =
36 "@(#) Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994\n\
37 The Regents of the University of California. All rights reserved.\n";
42 static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94";
44 static const char rcsid[] =
50 * login -h hostname (for telnetd, etc.)
51 * login -f name (for pre-authenticated login: datakit, xterm, etc.)
54 #include <sys/copyright.h>
55 #include <sys/param.h>
57 #include <sys/socket.h>
59 #include <sys/resource.h>
61 #include <netinet/in.h>
62 #include <arpa/inet.h>
68 #include <login_cap.h>
82 #include <security/pam_appl.h>
83 #include <security/openpam.h>
87 #include "pathnames.h"
89 /* wrapper for KAME-special getnameinfo() */
90 #ifndef NI_WITHSCOPEID
91 #define NI_WITHSCOPEID 0
94 void badlogin(char *);
95 void checknologin(void);
97 void getloginname(void);
98 void motd(const char *);
102 void refused(char *,char *,int);
103 char *stypeof(char *);
105 int login_access(char *, char *);
106 void login_fbtab(char *, uid_t, gid_t);
109 static int auth_pam(void);
110 static int export_pam_environment(void);
111 static int ok_to_export(const char *);
113 static pam_handle_t *pamh = NULL;
114 static char **environ_pam;
117 if ((e = pam_setcred(pamh, PAM_DELETE_CRED)) != PAM_SUCCESS) \
118 syslog(LOG_ERR, "pam_setcred: %s", pam_strerror(pamh, e)); \
119 if ((e = pam_close_session(pamh,0)) != PAM_SUCCESS) \
120 syslog(LOG_ERR, "pam_close_session: %s", pam_strerror(pamh, e)); \
121 if ((e = pam_end(pamh, e)) != PAM_SUCCESS) \
122 syslog(LOG_ERR, "pam_end: %s", pam_strerror(pamh, e)); \
126 static int auth_traditional(void);
127 extern void login(struct utmp *);
128 static void usage(void);
130 #define TTYGRPNAME "tty" /* name of group to own ttys */
131 #define DEFAULT_BACKOFF 3
132 #define DEFAULT_RETRIES 10
133 #define DEFAULT_PROMPT "login: "
134 #define DEFAULT_PASSWD_PROMPT "Password:"
137 * This bounds the time given to login. Not a define so it can
138 * be patched on machines where it's too small.
142 /* Buffer for signal handling of timeout */
147 char *term, *envinit[1], *hostname, *tty, *username;
148 const char *passwd_prompt, *prompt;
149 char full_hostname[MAXHOSTNAMELEN];
156 extern char **environ;
161 int rootok, retries, backoff;
162 int ask, ch, cnt, fflag, hflag, pflag, quietlog, rootlogin, rval;
168 char tbuf[MAXPATHLEN + 2];
169 char tname[sizeof(_PATH_TTY) + 10];
170 const char *shell = NULL;
171 login_cap_t *lc = NULL;
177 (void)signal(SIGQUIT, SIG_IGN);
178 (void)signal(SIGINT, SIG_IGN);
179 (void)signal(SIGHUP, SIG_IGN);
180 if (setjmp(timeout_buf)) {
183 (void)fprintf(stderr, "Login timed out after %d seconds\n",
187 (void)signal(SIGALRM, timedout);
188 (void)alarm(timeout);
189 (void)setpriority(PRIO_PROCESS, 0, 0);
191 openlog("login", LOG_ODELAY, LOG_AUTH);
194 * -p is used by getty to tell login not to destroy the environment
195 * -f is used to skip a second login authentication
196 * -h is used by other servers to pass the name of the remote
197 * host to login so that it may be placed in utmp and wtmp
199 *full_hostname = '\0';
202 fflag = hflag = pflag = 0;
206 while ((ch = getopt(argc, argv, "fh:p")) != -1)
213 errx(1, "-h option: %s", strerror(EPERM));
215 if (strlcpy(full_hostname, optarg,
216 sizeof(full_hostname)) >= sizeof(full_hostname))
217 errx(1, "-h option: %s: exceeds maximum "
218 "hostname size", optarg);
220 trimdomain(optarg, UT_HOSTSIZE);
222 if (strlen(optarg) > UT_HOSTSIZE) {
223 struct addrinfo hints, *res;
226 memset(&hints, 0, sizeof(hints));
227 hints.ai_family = AF_UNSPEC;
228 ga_err = getaddrinfo(optarg, NULL, &hints,
231 char hostbuf[MAXHOSTNAMELEN];
233 getnameinfo(res->ai_addr,
236 sizeof(hostbuf), NULL, 0,
239 optarg = strdup(hostbuf);
240 if (optarg == NULL) {
246 optarg = "invalid hostname";
258 syslog(LOG_ERR, "invalid flag %c", ch);
270 for (cnt = getdtablesize(); cnt > 2; cnt--)
273 ttyn = ttyname(STDIN_FILENO);
274 if (ttyn == NULL || *ttyn == '\0') {
275 (void)snprintf(tname, sizeof(tname), "%s??", _PATH_TTY);
278 if ((tty = strrchr(ttyn, '/')) != NULL)
284 * Get "login-retries" & "login-backoff" from default class
286 lc = login_getclass(NULL);
287 prompt = login_getcapstr(lc, "prompt", DEFAULT_PROMPT, DEFAULT_PROMPT);
288 passwd_prompt = login_getcapstr(lc, "passwd_prompt",
289 DEFAULT_PASSWD_PROMPT, DEFAULT_PASSWD_PROMPT);
290 retries = login_getcapnum(lc, "login-retries", DEFAULT_RETRIES,
292 backoff = login_getcapnum(lc, "login-backoff", DEFAULT_BACKOFF,
297 for (cnt = 0;; ask = 1) {
303 rootok = rootterm(tty); /* Default (auth may change) */
305 if (strlen(username) > UT_NAMESIZE)
306 username[UT_NAMESIZE] = '\0';
309 * Note if trying multiple user names; log failures for
310 * previous user name, but don't bother logging one failure
311 * for nonexistent name (mistyped username).
313 if (failures && strcmp(tbuf, username)) {
314 if (failures > (pwd ? 0 : 1))
317 (void)strlcpy(tbuf, username, sizeof(tbuf));
319 pwd = getpwnam(username);
322 * if we have a valid account name, and it doesn't have a
323 * password, or the -f option was specified and the caller
324 * is root or the caller isn't changing their uid, don't
328 if (pwd->pw_uid == 0)
331 if (fflag && (uid == (uid_t)0 ||
332 uid == (uid_t)pwd->pw_uid)) {
333 /* already authenticated */
335 } else if (pwd->pw_passwd[0] == '\0') {
336 if (!rootlogin || rootok) {
337 /* pretend password okay */
346 (void)setpriority(PRIO_PROCESS, 0, -4);
350 * Try to authenticate using PAM. If a PAM system error
351 * occurs, perhaps because of a botched configuration,
352 * then fall back to using traditional Unix authentication.
354 if ((rval = auth_pam()) == -1)
356 rval = auth_traditional();
358 (void)setpriority(PRIO_PROCESS, 0, 0);
362 * PAM authentication may have changed "pwd" to the
363 * entry for the template user. Check again to see if
364 * this is a root login after all.
366 if (pwd != NULL && pwd->pw_uid == 0)
372 * If trying to log in as root without Kerberos,
373 * but with insecure terminal, refuse the login attempt.
376 if (rootlogin && !rootok)
377 refused(NULL, "NOROOT", 0);
378 else /* valid password & authenticated */
382 (void)printf("Login incorrect\n");
386 * we allow up to 'retry' (10) tries,
387 * but after 'backoff' (3) we start backing off
389 if (++cnt > backoff) {
390 if (cnt >= retries) {
394 sleep((u_int)((cnt - backoff) * 5));
398 /* committed to login -- turn off timeout */
399 (void)alarm((u_int)0);
400 (void)signal(SIGHUP, SIG_DFL);
405 * Establish the login class.
407 lc = login_getpwclass(pwd);
409 /* if user not super-user, check for disabled logins */
411 auth_checknologin(lc);
413 quietlog = login_getcapbool(lc, "hushlogin", 0);
415 * Switching needed for NFS with root access disabled.
417 * XXX: This change fails to modify the additional groups for the
418 * process, and as such, may restrict rights normally granted
419 * through those groups.
421 (void)setegid(pwd->pw_gid);
422 (void)seteuid(rootlogin ? 0 : pwd->pw_uid);
423 if (!*pwd->pw_dir || chdir(pwd->pw_dir) < 0) {
424 if (login_getcapbool(lc, "requirehome", 0))
425 refused("Home directory not available", "HOMEDIR", 1);
427 refused("Cannot find root directory", "ROOTDIR", 1);
428 if (!quietlog || *pwd->pw_dir)
429 printf("No home directory.\nLogging in with home = \"/\".\n");
435 quietlog = access(_PATH_HUSHLOGIN, F_OK) == 0;
437 if (pwd->pw_change || pwd->pw_expire)
438 (void)gettimeofday(&tp, (struct timezone *)NULL);
440 #define DEFAULT_WARN (2L * 7L * 86400L) /* Two weeks */
442 warntime = login_getcaptime(lc, "warnexpire", DEFAULT_WARN,
445 if (pwd->pw_expire) {
446 if (tp.tv_sec >= pwd->pw_expire) {
447 refused("Sorry -- your account has expired", "EXPIRED",
449 } else if (pwd->pw_expire - tp.tv_sec < warntime && !quietlog)
450 (void)printf("Warning: your account expires on %s",
451 ctime(&pwd->pw_expire));
454 warntime = login_getcaptime(lc, "warnpassword", DEFAULT_WARN,
458 if (pwd->pw_change) {
459 if (tp.tv_sec >= pwd->pw_change) {
460 (void)printf("Sorry -- your password has expired.\n");
462 syslog(LOG_INFO, "%s Password expired - forcing change",
464 } else if (pwd->pw_change - tp.tv_sec < warntime && !quietlog)
465 (void)printf("Warning: your password expires on %s",
466 ctime(&pwd->pw_change));
471 struct addrinfo hints, *res;
474 memset(&hints, 0, sizeof(hints));
475 hints.ai_family = AF_UNSPEC;
476 ga_err = getaddrinfo(full_hostname, NULL, &hints,
479 char hostbuf[MAXHOSTNAMELEN];
481 getnameinfo(res->ai_addr, res->ai_addrlen,
482 hostbuf, sizeof(hostbuf), NULL, 0,
483 NI_NUMERICHOST|NI_WITHSCOPEID);
484 if ((optarg = strdup(hostbuf)) == NULL) {
485 syslog(LOG_NOTICE, "strdup(): %m");
492 if (!auth_hostok(lc, full_hostname, optarg))
493 refused("Permission denied", "HOST", 1);
496 if (!auth_ttyok(lc, tty))
497 refused("Permission denied", "TTY", 1);
499 if (!auth_timeok(lc, time(NULL)))
500 refused("Logins not available right now", "TIME", 1);
502 shell = login_getcapstr(lc, "shell", pwd->pw_shell, pwd->pw_shell);
503 if (*pwd->pw_shell == '\0')
504 pwd->pw_shell = _PATH_BSHELL;
505 if (*shell == '\0') /* Not overridden */
506 shell = pwd->pw_shell;
507 if ((shell = strdup(shell)) == NULL) {
508 syslog(LOG_NOTICE, "strdup(): %m");
513 if (login_access(pwd->pw_name, hostname ? full_hostname : tty) == 0)
514 refused("Permission denied", "ACCESS", 1);
515 #endif /* LOGIN_ACCESS */
517 /* Nothing else left to fail -- really log in. */
518 memset((void *)&utmp, 0, sizeof(utmp));
519 (void)time(&utmp.ut_time);
520 (void)strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
522 (void)strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
523 (void)strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
529 * Set device protections, depending on what terminal the
530 * user is logged in. This feature is used on Suns to give
531 * console users better privacy.
533 login_fbtab(tty, pwd->pw_uid, pwd->pw_gid);
536 * Clear flags of the tty. None should be set, and when the
537 * user sets them otherwise, this can cause the chown to fail.
538 * Since it isn't clear that flags are useful on character
539 * devices, we just clear them.
541 if (chflags(ttyn, 0) && errno != EOPNOTSUPP)
542 syslog(LOG_ERR, "chmod(%s): %m", ttyn);
543 if (chown(ttyn, pwd->pw_uid,
544 (gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid))
545 syslog(LOG_ERR, "chmod(%s): %m", ttyn);
549 * Preserve TERM if it happens to be already set.
551 if ((term = getenv("TERM")) != NULL) {
552 if ((term = strdup(term)) == NULL) {
560 * Exclude cons/vt/ptys only, assume dialup otherwise
561 * TODO: Make dialup tty determination a library call
562 * for consistency (finger etc.)
564 if (hostname==NULL && isdialuptty(tty))
565 syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name);
569 * Syslog each successful login, so we don't have to watch hundreds
570 * of wtmp or lastlogin files.
573 syslog(LOG_INFO, "login from %s on %s as %s",
574 full_hostname, tty, pwd->pw_name);
576 syslog(LOG_INFO, "login on %s as %s",
581 * If fflag is on, assume caller/authenticator has logged root login.
583 if (rootlogin && fflag == 0)
586 syslog(LOG_NOTICE, "ROOT LOGIN (%s) ON %s FROM %s",
587 username, tty, full_hostname);
589 syslog(LOG_NOTICE, "ROOT LOGIN (%s) ON %s",
594 * Destroy environment unless user has requested its preservation.
595 * We need to do this before setusercontext() because that may
596 * set or reset some environment variables.
602 * PAM modules might add supplementary groups during pam_setcred().
604 if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETGROUP) != 0) {
605 syslog(LOG_ERR, "setusercontext() failed - exiting");
611 if ((e = pam_open_session(pamh, 0)) != PAM_SUCCESS) {
612 syslog(LOG_ERR, "pam_open_session: %s",
613 pam_strerror(pamh, e));
614 } else if ((e = pam_setcred(pamh, PAM_ESTABLISH_CRED))
616 syslog(LOG_ERR, "pam_setcred: %s",
617 pam_strerror(pamh, e));
621 * Add any environmental variables that the
622 * PAM modules may have set.
623 * Call *after* opening session!
626 environ_pam = pam_getenvlist(pamh);
628 export_pam_environment();
632 * We must fork() before setuid() because we need to call
633 * pam_close_session() as root.
641 /* parent - wait for child to finish, then cleanup
647 if ((e = pam_end(pamh, 0)) != PAM_SUCCESS)
648 syslog(LOG_ERR, "pam_end: %s",
649 pam_strerror(pamh, e));
655 * We don't need to be root anymore, so
656 * set the user and session context
658 if (setlogin(username) != 0) {
659 syslog(LOG_ERR, "setlogin(%s): %m - exiting", username);
662 if (setusercontext(lc, pwd, pwd->pw_uid,
663 LOGIN_SETALL & ~(LOGIN_SETLOGIN|LOGIN_SETGROUP)) != 0) {
664 syslog(LOG_ERR, "setusercontext() failed - exiting");
668 (void)setenv("SHELL", pwd->pw_shell, 1);
669 (void)setenv("HOME", pwd->pw_dir, 1);
670 if (term != NULL && *term != '\0')
671 (void)setenv("TERM", term, 1); /* Preset overrides */
673 (void)setenv("TERM", stypeof(tty), 0); /* Fallback doesn't */
675 (void)setenv("LOGNAME", username, 1);
676 (void)setenv("USER", username, 1);
677 (void)setenv("PATH", rootlogin ? _PATH_STDPATH : _PATH_DEFPATH, 0);
682 cw = login_getcapstr(lc, "copyright", NULL, NULL);
683 if (cw != NULL && access(cw, F_OK) == 0)
686 (void)printf("%s\n\t%s %s\n",
687 "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994",
688 "The Regents of the University of California. ",
689 "All rights reserved.");
693 cw = login_getcapstr(lc, "welcome", NULL, NULL);
694 if (cw == NULL || access(cw, F_OK) != 0)
698 cw = getenv("MAIL"); /* $MAIL may have been set by class */
700 strlcpy(tbuf, cw, sizeof(tbuf));
702 snprintf(tbuf, sizeof(tbuf), "%s/%s", _PATH_MAILDIR,
704 if (stat(tbuf, &st) == 0 && st.st_size != 0)
705 (void)printf("You have %smail.\n",
706 (st.st_mtime > st.st_atime) ? "new " : "");
711 (void)signal(SIGALRM, SIG_DFL);
712 (void)signal(SIGQUIT, SIG_DFL);
713 (void)signal(SIGINT, SIG_DFL);
714 (void)signal(SIGTSTP, SIG_IGN);
717 * Login shells have a leading '-' in front of argv[0]
719 if (snprintf(tbuf, sizeof(tbuf), "-%s",
720 (p = strrchr(pwd->pw_shell, '/')) ? p + 1 : pwd->pw_shell) >=
722 syslog(LOG_ERR, "user: %s: shell exceeds maximum pathname size",
724 errx(1, "shell exceeds maximum pathname size");
727 execlp(shell, tbuf, (char *)0);
740 salt = pwd != NULL ? pwd->pw_passwd : "xx";
742 p = getpass(passwd_prompt);
746 if (!p[0] && pwd->pw_passwd[0])
748 if (strcmp(ep, pwd->pw_passwd) == 0)
752 /* clear entered password */
753 memset(p, 0, strlen(p));
759 * Attempt to authenticate the user using PAM. Returns 0 if the user is
760 * authenticated, or 1 if not authenticated. If some sort of PAM system
761 * error occurs (e.g., the "/etc/pam.conf" file is missing) then this
762 * function returns -1. This can be used as an indication that we should
763 * fall back to a different authentication mechanism.
768 const char *tmpl_user;
772 static struct pam_conv conv = { openpam_ttyconv, NULL };
774 if ((e = pam_start("login", username, &conv, &pamh)) != PAM_SUCCESS) {
775 syslog(LOG_ERR, "pam_start: %s", pam_strerror(pamh, e));
778 if ((e = pam_set_item(pamh, PAM_TTY, tty)) != PAM_SUCCESS) {
779 syslog(LOG_ERR, "pam_set_item(PAM_TTY): %s",
780 pam_strerror(pamh, e));
783 if (hostname != NULL &&
784 (e = pam_set_item(pamh, PAM_RHOST, full_hostname)) != PAM_SUCCESS) {
785 syslog(LOG_ERR, "pam_set_item(PAM_RHOST): %s",
786 pam_strerror(pamh, e));
789 e = pam_authenticate(pamh, 0);
794 * With PAM we support the concept of a "template"
795 * user. The user enters a login name which is
796 * authenticated by PAM, usually via a remote service
797 * such as RADIUS or TACACS+. If authentication
798 * succeeds, a different but related "template" name
799 * is used for setting the credentials, shell, and
800 * home directory. The name the user enters need only
801 * exist on the remote authentication server, but the
802 * template name must be present in the local password
805 * This is supported by two various mechanisms in the
806 * individual modules. However, from the application's
807 * point of view, the template user is always passed
808 * back as a changed value of the PAM_USER item.
810 if ((e = pam_get_item(pamh, PAM_USER, &item)) ==
812 tmpl_user = (const char *) item;
813 if (strcmp(username, tmpl_user) != 0)
814 pwd = getpwnam(tmpl_user);
816 syslog(LOG_ERR, "Couldn't get PAM_USER: %s",
817 pam_strerror(pamh, e));
822 case PAM_USER_UNKNOWN:
828 syslog(LOG_ERR, "pam_authenticate: %s", pam_strerror(pamh, e));
834 e = pam_acct_mgmt(pamh, 0);
835 if (e == PAM_NEW_AUTHTOK_REQD) {
836 e = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
837 if (e != PAM_SUCCESS) {
838 syslog(LOG_ERR, "pam_chauthtok: %s",
839 pam_strerror(pamh, e));
842 } else if (e != PAM_SUCCESS) {
848 if ((e = pam_end(pamh, e)) != PAM_SUCCESS) {
849 syslog(LOG_ERR, "pam_end: %s", pam_strerror(pamh, e));
857 export_pam_environment()
861 for (pp = environ_pam; *pp != NULL; pp++) {
862 if (ok_to_export(*pp))
870 * Sanity checks on PAM environmental variables:
871 * - Make sure there is an '=' in the string.
872 * - Make sure the string doesn't run on too long.
873 * - Do not export certain variables. This list was taken from the
874 * Solaris pam_putenv(3) man page.
880 static const char *noexport[] = {
881 "SHELL", "HOME", "LOGNAME", "MAIL", "CDPATH",
887 if (strlen(s) > 1024 || strchr(s, '=') == NULL)
889 if (strncmp(s, "LD_", 3) == 0)
891 for (pp = noexport; *pp != NULL; pp++) {
893 if (s[n] == '=' && strncmp(s, *pp, n) == 0)
904 (void)fprintf(stderr, "usage: login [-fp] [-h hostname] [username]\n");
909 * Allow for authentication style and/or kerberos instance
912 #define NBUFSIZ UT_NAMESIZE + 64
919 static char nbuf[NBUFSIZ];
922 (void)printf("%s", prompt);
923 for (p = nbuf; (ch = getchar()) != '\n'; ) {
928 if (p < nbuf + (NBUFSIZ - 1))
933 (void)fprintf(stderr,
934 "login names may not start with '-'.\n");
950 return ((t = getttynam(ttyn)) && t->ty_status & TTY_SECURE);
953 volatile int motdinterrupt;
964 const char *motdfile;
970 if ((fd = open(motdfile, O_RDONLY, 0)) < 0)
973 oldint = signal(SIGINT, sigint);
974 while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0 && !motdinterrupt)
975 (void)write(fileno(stdout), tbuf, nchars);
976 (void)signal(SIGINT, oldint);
986 longjmp(timeout_buf, signo);
997 if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) {
998 (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
1000 if (read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll) &&
1002 (void)printf("Last login: %.*s ",
1003 24-5, (char *)ctime(&ll.ll_time));
1004 if (*ll.ll_host != '\0')
1005 (void)printf("from %.*s\n",
1006 (int)sizeof(ll.ll_host),
1009 (void)printf("on %.*s\n",
1010 (int)sizeof(ll.ll_line),
1013 (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET);
1015 memset((void *)&ll, 0, sizeof(ll));
1016 (void)time(&ll.ll_time);
1017 (void)strncpy(ll.ll_line, tty, sizeof(ll.ll_line));
1019 (void)strncpy(ll.ll_host, hostname, sizeof(ll.ll_host));
1020 (void)write(fd, (char *)&ll, sizeof(ll));
1023 syslog(LOG_ERR, "cannot open %s: %m", _PATH_LASTLOG);
1035 syslog(LOG_NOTICE, "%d LOGIN FAILURE%s FROM %s",
1036 failures, failures > 1 ? "S" : "", full_hostname);
1037 syslog(LOG_AUTHPRIV|LOG_NOTICE,
1038 "%d LOGIN FAILURE%s FROM %s, %s",
1039 failures, failures > 1 ? "S" : "", full_hostname, name);
1041 syslog(LOG_NOTICE, "%d LOGIN FAILURE%s ON %s",
1042 failures, failures > 1 ? "S" : "", tty);
1043 syslog(LOG_AUTHPRIV|LOG_NOTICE,
1044 "%d LOGIN FAILURE%s ON %s, %s",
1045 failures, failures > 1 ? "S" : "", tty, name);
1051 #define UNKNOWN "su"
1059 if (ttyid != NULL && *ttyid != '\0') {
1060 t = getttynam(ttyid);
1061 if (t != NULL && t->ty_type != NULL)
1062 return (t->ty_type);
1068 refused(msg, rtype, lout)
1075 printf("%s.\n", msg);
1077 syslog(LOG_NOTICE, "LOGIN %s REFUSED (%s) FROM %s ON TTY %s",
1078 pwd->pw_name, rtype, full_hostname, tty);
1080 syslog(LOG_NOTICE, "LOGIN %s REFUSED (%s) ON TTY %s",
1081 pwd->pw_name, rtype, tty);