From 4ab0df0ae2c64fe9e6e00c6417d80ce31bc14167 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 13 Sep 2011 12:51:55 +0200 Subject: login: remove pam_handle_t from main() Signed-off-by: Karel Zak --- login-utils/login.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'login-utils/login.c') diff --git a/login-utils/login.c b/login-utils/login.c index d318e120c..5ad5444f0 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -840,7 +840,6 @@ int main(int argc, char **argv) char *pwdbuf = NULL; struct passwd *pwd = NULL, _pwd; - pam_handle_t *pamh; struct login_context cxt = { .pid = getpid(), /* PID */ @@ -949,8 +948,7 @@ int main(int argc, char **argv) openlog("login", LOG_ODELAY, LOG_AUTHPRIV); init_tty(&cxt); - - pamh = init_loginpam(&cxt); + init_loginpam(&cxt); /* login -f, then the user has already been authenticated */ cxt.noauth = cxt.noauth && getuid() == 0 ? 1 : 0; @@ -970,7 +968,7 @@ int main(int argc, char **argv) warnx(_("\nSession setup problem, abort.")); syslog(LOG_ERR, _("Invalid user name \"%s\" in %s:%d. Abort."), cxt.username, __FUNCTION__, __LINE__); - pam_end(pamh, PAM_SYSTEM_ERR); + pam_end(cxt.pamh, PAM_SYSTEM_ERR); exit(EXIT_FAILURE); } @@ -992,7 +990,7 @@ int main(int argc, char **argv) if (retcode < 0) { syslog(LOG_ERR, _("groups initialization failed: %m")); warnx(_("\nSession setup problem, abort.")); - pam_end(pamh, PAM_SYSTEM_ERR); + pam_end(cxt.pamh, PAM_SYSTEM_ERR); exit(EXIT_FAILURE); } @@ -1063,7 +1061,7 @@ int main(int argc, char **argv) { int i; - char **env = pam_getenvlist(pamh); + char **env = pam_getenvlist(cxt.pamh); if (env != NULL) { for (i = 0; env[i]; i++) { @@ -1156,15 +1154,20 @@ int main(int argc, char **argv) child_pid = fork(); if (child_pid < 0) { - /* error in fork() */ - warn(_("failure forking")); - pam_setcred(pamh, PAM_DELETE_CRED); - pam_end(pamh, pam_close_session(pamh, 0)); + /* + * fork() error + */ + warn(_("fork failed")); + + pam_setcred(cxt.pamh, PAM_DELETE_CRED); + pam_end(cxt.pamh, pam_close_session(cxt.pamh, 0)); exit(EXIT_FAILURE); } if (child_pid) { - /* parent - wait for child to finish, then cleanup session */ + /* + * parent - wait for child to finish, then cleanup session + */ close(0); close(1); close(2); @@ -1175,8 +1178,9 @@ int main(int argc, char **argv) /* wait as long as any child is there */ while (wait(NULL) == -1 && errno == EINTR) ; openlog("login", LOG_ODELAY, LOG_AUTHPRIV); - pam_setcred(pamh, PAM_DELETE_CRED); - pam_end(pamh, pam_close_session(pamh, 0)); + + pam_setcred(cxt.pamh, PAM_DELETE_CRED); + pam_end(cxt.pamh, pam_close_session(cxt.pamh, 0)); exit(EXIT_SUCCESS); } -- cgit v1.2.3-55-g7522