2 * Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2002 Networks Associates Technologies, Inc.
7 * Portions of this software were developed for the FreeBSD Project by
8 * ThinkSec AS and NAI Labs, the Security Research Division of Network
9 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
10 * ("CBOSS"), as part of the DARPA CHATS research program.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)login.c 8.4 (Berkeley) 4/2/94
37 * $FreeBSD: src/usr.bin/login/login.c,v 1.106 2007/07/04 00:00:40 scf Exp $
42 * login -h hostname (for telnetd, etc.)
43 * login -f name (for pre-authenticated login: datakit, xterm, etc.)
46 #include <sys/copyright.h>
47 #include <sys/param.h>
51 #include <sys/resource.h>
58 #include <login_cap.h>
69 #include <security/pam_appl.h>
70 #include <security/openpam.h>
73 #include "pathnames.h"
75 static int auth_pam(void);
76 static void bail(int, int);
77 static int export(const char *);
78 static void export_pam_environment(void);
79 static int motd(const char *);
80 static void badlogin(char *);
81 static char *getloginname(void);
82 static void pam_syslog(const char *);
83 static void pam_cleanup(void);
84 static void refused(const char *, const char *, int);
85 static const char *stypeof(char *);
86 static void sigint(int);
87 static void timedout(int);
88 static void usage(void);
90 #define TTYGRPNAME "tty" /* group to own ttys */
91 #define DEFAULT_BACKOFF 3
92 #define DEFAULT_RETRIES 10
93 #define DEFAULT_PROMPT "login: "
94 #define DEFAULT_PASSWD_PROMPT "Password:"
95 #define TERM_UNKNOWN "su"
96 #define DEFAULT_WARN (2L * 7L * 86400L) /* Two weeks */
97 #define NO_SLEEP_EXIT 0
101 * This bounds the time given to login. Not a define so it can
102 * be patched on machines where it's too small.
104 static u_int timeout
= 300;
106 /* Buffer for signal handling of timeout */
107 static jmp_buf timeout_buf
;
112 static char *envinit
[1]; /* empty environment list */
115 * Command line flags and arguments
117 static int fflag
; /* -f: do not perform authentication */
118 static int hflag
; /* -h: login from remote host */
119 static char *hostname
; /* hostname from command line */
120 static int pflag
; /* -p: preserve environment */
125 static char *username
; /* user name */
126 static char *olduser
; /* previous user name */
131 static char default_prompt
[] = DEFAULT_PROMPT
;
132 static const char *prompt
;
133 static char default_passwd_prompt
[] = DEFAULT_PASSWD_PROMPT
;
134 static const char *passwd_prompt
;
141 static pam_handle_t
*pamh
= NULL
;
142 static struct pam_conv pamc
= { openpam_ttyconv
, NULL
};
144 static int pam_silent
= PAM_SILENT
;
145 static int pam_cred_established
;
146 static int pam_session_established
;
149 main(int argc
, char **argv
)
153 int retries
, backoff
;
154 int ask
, ch
, cnt
, quietlog
, rootlogin
, rval
;
159 char tname
[sizeof(_PATH_TTY
) + 10];
162 const char *shell
= NULL
;
163 login_cap_t
*lc
= NULL
;
164 login_cap_t
*lc_user
= NULL
;
167 char auditsuccess
= 1;
170 signal(SIGQUIT
, SIG_IGN
);
171 signal(SIGINT
, SIG_IGN
);
172 signal(SIGHUP
, SIG_IGN
);
173 if (setjmp(timeout_buf
)) {
176 fprintf(stderr
, "Login timed out after %d seconds\n",
178 bail(NO_SLEEP_EXIT
, 0);
180 signal(SIGALRM
, timedout
);
182 setpriority(PRIO_PROCESS
, 0, 0);
184 openlog("login", 0, LOG_AUTH
);
190 while ((ch
= getopt(argc
, argv
, "fh:p")) != -1)
197 errx(1, "-h option: %s", strerror(EPERM
));
198 if (strlen(optarg
) >= MAXHOSTNAMELEN
)
199 errx(1, "-h option: %s: exceeds maximum "
200 "hostname size", optarg
);
210 syslog(LOG_ERR
, "invalid flag %c", ch
);
217 username
= strdup(*argv
);
218 if (username
== NULL
)
225 setproctitle("-%s", getprogname());
227 for (cnt
= getdtablesize(); cnt
> 2; cnt
--)
233 ttyn
= ttyname(STDIN_FILENO
);
234 if (ttyn
== NULL
|| *ttyn
== '\0') {
235 snprintf(tname
, sizeof(tname
), "%s??", _PATH_TTY
);
238 if (strncmp(ttyn
, _PATH_DEV
, sizeof(_PATH_DEV
) -1) == 0)
239 tty
= ttyn
+ sizeof(_PATH_DEV
) -1;
244 * Get "login-retries" & "login-backoff" from default class
246 lc
= login_getclass(NULL
);
247 prompt
= login_getcapstr(lc
, "login_prompt",
248 default_prompt
, default_prompt
);
249 passwd_prompt
= login_getcapstr(lc
, "passwd_prompt",
250 default_passwd_prompt
, default_passwd_prompt
);
251 retries
= login_getcapnum(lc
, "login-retries",
252 DEFAULT_RETRIES
, DEFAULT_RETRIES
);
253 backoff
= login_getcapnum(lc
, "login-backoff",
254 DEFAULT_BACKOFF
, DEFAULT_BACKOFF
);
259 * Try to authenticate the user until we succeed or time out.
261 for (cnt
= 0;; ask
= 1) {
267 username
= getloginname();
272 * Note if trying multiple user names; log failures for
273 * previous user name, but don't bother logging one failure
274 * for nonexistent name (mistyped username).
276 if (failures
&& strcmp(olduser
, username
) != 0) {
277 if (failures
> (pwd
? 0 : 1))
282 * Load the PAM policy and set some variables
284 pam_err
= pam_start("login", username
, &pamc
, &pamh
);
285 if (pam_err
!= PAM_SUCCESS
) {
286 pam_syslog("pam_start()");
288 au_login_fail("PAM Error", 1);
290 bail(NO_SLEEP_EXIT
, 1);
292 pam_err
= pam_set_item(pamh
, PAM_TTY
, tty
);
293 if (pam_err
!= PAM_SUCCESS
) {
294 pam_syslog("pam_set_item(PAM_TTY)");
296 au_login_fail("PAM Error", 1);
298 bail(NO_SLEEP_EXIT
, 1);
300 pam_err
= pam_set_item(pamh
, PAM_RHOST
, hostname
);
301 if (pam_err
!= PAM_SUCCESS
) {
302 pam_syslog("pam_set_item(PAM_RHOST)");
304 au_login_fail("PAM Error", 1);
306 bail(NO_SLEEP_EXIT
, 1);
309 pwd
= getpwnam(username
);
310 if (pwd
!= NULL
&& pwd
->pw_uid
== 0)
314 * If the -f option was specified and the caller is
315 * root or the caller isn't changing their uid, don't
318 if (pwd
!= NULL
&& fflag
&&
319 (uid
== (uid_t
)0 || uid
== (uid_t
)pwd
->pw_uid
)) {
320 /* already authenticated */
323 auditsuccess
= 0; /* opened a terminal window only */
327 setpriority(PRIO_PROCESS
, 0, -4);
329 setpriority(PRIO_PROCESS
, 0, 0);
332 if (pwd
&& rval
== 0)
338 * We are not exiting here, but this corresponds to a failed
339 * login event, so set exitstatus to 1.
342 au_login_fail("Login incorrect", 1);
345 printf("Login incorrect\n");
351 * Allow up to 'retry' (10) attempts, but start
352 * backing off after 'backoff' (3) attempts.
354 if (++cnt
> backoff
) {
355 if (cnt
>= retries
) {
359 sleep((u_int
)((cnt
- backoff
) * 5));
363 /* committed to login -- turn off timeout */
365 signal(SIGHUP
, SIG_DFL
);
370 /* Audit successful login. */
376 * Establish the login class.
378 lc
= login_getpwclass(pwd
);
379 lc_user
= login_getuserclass(pwd
);
381 if (!(quietlog
= login_getcapbool(lc_user
, "hushlogin", 0)))
382 quietlog
= login_getcapbool(lc
, "hushlogin", 0);
385 * Switching needed for NFS with root access disabled.
387 * XXX: This change fails to modify the additional groups for the
388 * process, and as such, may restrict rights normally granted
389 * through those groups.
391 setegid(pwd
->pw_gid
);
392 seteuid(rootlogin
? 0 : pwd
->pw_uid
);
393 if (!*pwd
->pw_dir
|| chdir(pwd
->pw_dir
) < 0) {
394 if (login_getcapbool(lc
, "requirehome", 0))
395 refused("Home directory not available", "HOMEDIR", 1);
397 refused("Cannot find root directory", "ROOTDIR", 1);
398 if (!quietlog
|| *pwd
->pw_dir
)
399 printf("No home directory.\nLogging in with home = \"/\".\n");
400 pwd
->pw_dir
= strdup("/");
401 if (pwd
->pw_dir
== NULL
) {
402 syslog(LOG_NOTICE
, "strdup(): %m");
409 quietlog
= access(_PATH_HUSHLOGIN
, F_OK
) == 0;
414 shell
= login_getcapstr(lc
, "shell", pwd
->pw_shell
, pwd
->pw_shell
);
415 if (*pwd
->pw_shell
== '\0')
416 pwd
->pw_shell
= strdup(_PATH_BSHELL
);
417 if (pwd
->pw_shell
== NULL
) {
418 syslog(LOG_NOTICE
, "strdup(): %m");
421 if (*shell
== '\0') /* Not overridden */
422 shell
= pwd
->pw_shell
;
423 if ((shell
= strdup(shell
)) == NULL
) {
424 syslog(LOG_NOTICE
, "strdup(): %m");
429 * Set device protections, depending on what terminal the
430 * user is logged in. This feature is used on Suns to give
431 * console users better privacy.
433 login_fbtab(tty
, pwd
->pw_uid
, pwd
->pw_gid
);
436 * Clear flags of the tty. None should be set, and when the
437 * user sets them otherwise, this can cause the chown to fail.
438 * Since it isn't clear that flags are useful on character
439 * devices, we just clear them.
441 * We don't log in the case of EOPNOTSUPP because dev might be
442 * on NFS, which doesn't support chflags.
444 * We don't log in the EROFS because that means that /dev is on
445 * a read only file system and we assume that the permissions there
448 if (ttyn
!= tname
&& chflags(ttyn
, 0))
449 if (errno
!= EOPNOTSUPP
&& errno
!= EROFS
)
450 syslog(LOG_ERR
, "chflags(%s): %m", ttyn
);
451 if (ttyn
!= tname
&& chown(ttyn
, pwd
->pw_uid
,
452 (gr
= getgrnam(TTYGRPNAME
)) ? gr
->gr_gid
: pwd
->pw_gid
))
454 syslog(LOG_ERR
, "chown(%s): %m", ttyn
);
457 * Exclude cons/vt/ptys only, assume dialup otherwise
458 * TODO: Make dialup tty determination a library call
459 * for consistency (finger etc.)
461 if (hflag
&& isdialuptty(tty
))
462 syslog(LOG_INFO
, "DIALUP %s, %s", tty
, pwd
->pw_name
);
466 * Syslog each successful login, so we don't have to watch
467 * hundreds of wtmp or lastlogin files.
470 syslog(LOG_INFO
, "login from %s on %s as %s",
471 hostname
, tty
, pwd
->pw_name
);
473 syslog(LOG_INFO
, "login on %s as %s",
478 * If fflag is on, assume caller/authenticator has logged root
481 if (rootlogin
&& fflag
== 0) {
483 syslog(LOG_NOTICE
, "ROOT LOGIN (%s) ON %s FROM %s",
484 username
, tty
, hostname
);
486 syslog(LOG_NOTICE
, "ROOT LOGIN (%s) ON %s",
491 * Destroy environment unless user has requested its
492 * preservation - but preserve TERM in all cases
494 term
= getenv("TERM");
498 if (setenv("TERM", term
, 0) == -1)
499 err(1, "setenv: cannot set TERM=%s", term
);
503 * PAM modules might add supplementary groups during pam_setcred().
505 if (setusercontext(lc
, pwd
, pwd
->pw_uid
, LOGIN_SETGROUP
) != 0) {
506 syslog(LOG_ERR
, "setusercontext() failed - exiting");
507 bail(NO_SLEEP_EXIT
, 1);
510 pam_err
= pam_setcred(pamh
, pam_silent
|PAM_ESTABLISH_CRED
);
511 if (pam_err
!= PAM_SUCCESS
) {
512 pam_syslog("pam_setcred()");
513 bail(NO_SLEEP_EXIT
, 1);
515 pam_cred_established
= 1;
517 pam_err
= pam_open_session(pamh
, pam_silent
);
518 if (pam_err
!= PAM_SUCCESS
) {
519 pam_syslog("pam_open_session()");
520 bail(NO_SLEEP_EXIT
, 1);
522 pam_session_established
= 1;
525 * We must fork() before setuid() because we need to call
526 * pam_close_session() as root.
531 } else if (pid
!= 0) {
533 * Parent: wait for child to finish, then clean up
537 setproctitle("-%s [pam]", getprogname());
538 waitpid(pid
, &status
, 0);
539 bail(NO_SLEEP_EXIT
, 0);
543 * NOTICE: We are now in the child process!
547 * Add any environment variables the PAM modules may have set.
549 export_pam_environment();
552 * We're done with PAM now; our parent will deal with the rest.
558 * We don't need to be root anymore, so set the login name and
561 if (setlogin(username
) != 0) {
562 syslog(LOG_ERR
, "setlogin(%s): %m - exiting", username
);
563 bail(NO_SLEEP_EXIT
, 1);
565 if (setusercontext(lc
, pwd
, pwd
->pw_uid
,
566 LOGIN_SETALL
& ~(LOGIN_SETLOGIN
|LOGIN_SETGROUP
)) != 0) {
567 syslog(LOG_ERR
, "setusercontext() failed - exiting");
571 if (setenv("SHELL", pwd
->pw_shell
, 1) == -1)
572 err(1, "setenv: cannot set SHELL=%s", pwd
->pw_shell
);
573 if (setenv("HOME", pwd
->pw_dir
, 1) == -1)
574 err(1, "setenv: cannot set HOME=%s", pwd
->pw_dir
);
575 /* Overwrite "term" from login.conf(5) for any known TERM */
576 if (term
== NULL
&& (tp
= stypeof(tty
)) != NULL
) {
577 if (setenv("TERM", tp
, 1) == -1)
578 err(1, "setenv: cannot set TERM=%s", tp
);
580 if (setenv("TERM", TERM_UNKNOWN
, 0) == -1)
581 err(1, "setenv: cannot set TERM=%s", TERM_UNKNOWN
);
584 if (setenv("LOGNAME", username
, 1) == -1)
585 err(1, "setenv: cannot set LOGNAME=%s", username
);
586 if (setenv("USER", username
, 1) == -1)
587 err(1, "setenv: cannot set USER=%s", username
);
589 rootlogin
? _PATH_STDPATH
: _PATH_DEFPATH
, 0) == -1) {
590 err(1, "setenv: cannot set PATH=%s",
591 rootlogin
? _PATH_STDPATH
: _PATH_DEFPATH
);
597 cw
= login_getcapstr(lc
, "copyright", NULL
, NULL
);
598 if (cw
== NULL
|| motd(cw
) == -1)
599 printf("%s", copyright
);
603 cw
= login_getcapstr(lc
, "welcome", NULL
, NULL
);
604 if (cw
!= NULL
&& access(cw
, F_OK
) == 0)
607 motd(_PATH_MOTDFILE
);
609 if (login_getcapbool(lc_user
, "nocheckmail", 0) == 0 &&
610 login_getcapbool(lc
, "nocheckmail", 0) == 0) {
613 /* $MAIL may have been set by class. */
616 asprintf(&cx
, "%s/%s",
617 _PATH_MAILDIR
, pwd
->pw_name
);
619 if (cx
&& stat(cx
, &st
) == 0 && st
.st_size
!= 0)
620 printf("You have %smail.\n",
621 (st
.st_mtime
> st
.st_atime
) ? "new " : "");
622 if (getenv("MAIL") == NULL
)
627 login_close(lc_user
);
630 signal(SIGALRM
, SIG_DFL
);
631 signal(SIGQUIT
, SIG_DFL
);
632 signal(SIGINT
, SIG_DFL
);
633 signal(SIGTSTP
, SIG_IGN
);
636 * Login shells have a leading '-' in front of argv[0]
638 p
= strrchr(pwd
->pw_shell
, '/');
639 if (asprintf(&arg0
, "-%s", p
? p
+ 1 : pwd
->pw_shell
) >= MAXPATHLEN
) {
640 syslog(LOG_ERR
, "user: %s: shell exceeds maximum pathname size",
642 errx(1, "shell exceeds maximum pathname size");
643 } else if (arg0
== NULL
) {
644 err(1, "asprintf()");
647 execlp(shell
, arg0
, NULL
);
656 * Attempt to authenticate the user using PAM. Returns 0 if the user is
657 * authenticated, or 1 if not authenticated. If some sort of PAM system
658 * error occurs (e.g., the "/etc/pam.conf" file is missing) then this
659 * function returns -1. This can be used as an indication that we should
660 * fall back to a different authentication mechanism.
665 const char *tmpl_user
;
669 pam_err
= pam_authenticate(pamh
, pam_silent
);
674 * With PAM we support the concept of a "template"
675 * user. The user enters a login name which is
676 * authenticated by PAM, usually via a remote service
677 * such as RADIUS or TACACS+. If authentication
678 * succeeds, a different but related "template" name
679 * is used for setting the credentials, shell, and
680 * home directory. The name the user enters need only
681 * exist on the remote authentication server, but the
682 * template name must be present in the local password
685 * This is supported by two various mechanisms in the
686 * individual modules. However, from the application's
687 * point of view, the template user is always passed
688 * back as a changed value of the PAM_USER item.
690 pam_err
= pam_get_item(pamh
, PAM_USER
, &item
);
691 if (pam_err
== PAM_SUCCESS
) {
692 tmpl_user
= (const char *)item
;
693 if (strcmp(username
, tmpl_user
) != 0)
694 pwd
= getpwnam(tmpl_user
);
696 pam_syslog("pam_get_item(PAM_USER)");
702 case PAM_USER_UNKNOWN
:
708 pam_syslog("pam_authenticate()");
714 pam_err
= pam_acct_mgmt(pamh
, pam_silent
);
718 case PAM_NEW_AUTHTOK_REQD
:
719 pam_err
= pam_chauthtok(pamh
,
720 pam_silent
|PAM_CHANGE_EXPIRED_AUTHTOK
);
721 if (pam_err
!= PAM_SUCCESS
) {
722 pam_syslog("pam_chauthtok()");
727 pam_syslog("pam_acct_mgmt()");
734 pam_end(pamh
, pam_err
);
741 * Export any environment variables PAM modules may have set
744 export_pam_environment(void)
749 pam_env
= pam_getenvlist(pamh
);
750 if (pam_env
!= NULL
) {
751 for (pp
= pam_env
; *pp
!= NULL
; pp
++) {
759 * Perform sanity checks on an environment variable:
760 * - Make sure there is an '=' in the string.
761 * - Make sure the string doesn't run on too long.
762 * - Do not export certain variables. This list was taken from the
763 * Solaris pam_putenv(3) man page.
767 export(const char *s
)
769 static const char *noexport
[] = {
770 "SHELL", "HOME", "LOGNAME", "MAIL", "CDPATH",
777 if (strlen(s
) > 1024 || (p
= strchr(s
, '=')) == NULL
)
779 if (strncmp(s
, "LD_", 3) == 0)
781 for (pp
= noexport
; *pp
!= NULL
; pp
++) {
783 if (s
[n
] == '=' && strncmp(s
, *pp
, n
) == 0)
787 if (setenv(s
, p
+ 1, 1) == -1)
788 err(1, "setenv: cannot set %s=%s", s
, p
+ 1);
797 fprintf(stderr
, "usage: login [-fp] [-h hostname] [username]\n");
802 * Prompt user and read login name from stdin.
810 nbuf
= malloc(MAXLOGNAME
);
814 printf("%s", prompt
);
815 for (p
= nbuf
; (ch
= getchar()) != '\n'; ) {
818 bail(NO_SLEEP_EXIT
, 0);
820 if (p
< nbuf
+ MAXLOGNAME
- 1)
826 if (nbuf
[0] == '-') {
828 memmove(nbuf
, nbuf
+ 1, strlen(nbuf
));
830 pam_silent
= PAM_SILENT
;
836 * SIGINT handler for motd().
838 static volatile int motdinterrupt
;
840 sigint(int signo __unused
)
846 * Display the contents of a file (such as /etc/motd).
849 motd(const char *motdfile
)
855 if ((f
= fopen(motdfile
, "r")) == NULL
)
858 oldint
= signal(SIGINT
, sigint
);
859 while ((ch
= fgetc(f
)) != EOF
&& !motdinterrupt
)
861 signal(SIGINT
, oldint
);
862 if (ch
!= EOF
|| ferror(f
)) {
871 * SIGALRM handler, to enforce login prompt timeout.
873 * XXX This can potentially confuse the hell out of PAM. We should
874 * XXX instead implement a conversation function that returns
875 * XXX PAM_CONV_ERR when interrupted by a signal, and have the signal
876 * XXX handler just set a flag.
879 timedout(int signo __unused
)
882 longjmp(timeout_buf
, signo
);
892 syslog(LOG_NOTICE
, "%d LOGIN FAILURE%s FROM %s",
893 failures
, failures
> 1 ? "S" : "", hostname
);
894 syslog(LOG_AUTHPRIV
|LOG_NOTICE
,
895 "%d LOGIN FAILURE%s FROM %s, %s",
896 failures
, failures
> 1 ? "S" : "", hostname
, name
);
898 syslog(LOG_NOTICE
, "%d LOGIN FAILURE%s ON %s",
899 failures
, failures
> 1 ? "S" : "", tty
);
900 syslog(LOG_AUTHPRIV
|LOG_NOTICE
,
901 "%d LOGIN FAILURE%s ON %s, %s",
902 failures
, failures
> 1 ? "S" : "", tty
, name
);
912 if (ttyid
!= NULL
&& *ttyid
!= '\0') {
913 t
= getttynam(ttyid
);
914 if (t
!= NULL
&& t
->ty_type
!= NULL
)
921 refused(const char *msg
, const char *rtype
, int lout
)
925 printf("%s.\n", msg
);
927 syslog(LOG_NOTICE
, "LOGIN %s REFUSED (%s) FROM %s ON TTY %s",
928 pwd
->pw_name
, rtype
, hostname
, tty
);
930 syslog(LOG_NOTICE
, "LOGIN %s REFUSED (%s) ON TTY %s",
931 pwd
->pw_name
, rtype
, tty
);
940 pam_syslog(const char *msg
)
942 syslog(LOG_ERR
, "%s: %s", msg
, pam_strerror(pamh
, pam_err
));
953 if (pam_session_established
) {
954 pam_err
= pam_close_session(pamh
, 0);
955 if (pam_err
!= PAM_SUCCESS
)
956 pam_syslog("pam_close_session()");
958 pam_session_established
= 0;
959 if (pam_cred_established
) {
960 pam_err
= pam_setcred(pamh
, pam_silent
|PAM_DELETE_CRED
);
961 if (pam_err
!= PAM_SUCCESS
)
962 pam_syslog("pam_setcred()");
964 pam_cred_established
= 0;
965 pam_end(pamh
, pam_err
);
971 * Exit, optionally after sleeping a few seconds
974 bail(int sec
, int eval
)