--- chfn.c 2008-05-29 23:23:58.000000000 +0200 +++ chfn-new.c 2008-05-29 23:36:06.000000000 +0200 @@ -69,9 +69,6 @@ static int wflg = 0; /* -w - set work phone number */ static int hflg = 0; /* -h - set home phone number */ static int oflg = 0; /* -o - set other information */ -#ifdef USE_PAM -static pam_handle_t *pamh = NULL; -#endif /* * External identifiers @@ -318,6 +315,7 @@ { #ifdef USE_PAM int retval; + pam_handle_t *pamh = NULL; struct passwd *pampw; #endif @@ -356,31 +354,21 @@ } #else /* !USE_PAM */ - retval = PAM_SUCCESS; - pampw = getpwuid (getuid ()); /* local, no need for xgetpwuid */ if (pampw == NULL) { - retval = PAM_USER_UNKNOWN; + fprintf (stderr, _("%s: user unknown.\n"), Prog); + exit (E_NOPERM); } - if (retval == PAM_SUCCESS) { - retval = pam_start ("chfn", pampw->pw_name, &conv, &pamh); - } + retval = pam_start ("chfn", pampw->pw_name, &conv, &pamh); - if (retval == PAM_SUCCESS) { + if (retval == PAM_SUCCESS) retval = pam_authenticate (pamh, 0); - if (retval != PAM_SUCCESS) { - pam_end (pamh, retval); - } - } - if (retval == PAM_SUCCESS) { + if (retval == PAM_SUCCESS) retval = pam_acct_mgmt (pamh, 0); - if (retval != PAM_SUCCESS) { - pam_end (pamh, retval); - } - } + pam_end (pamh, retval); if (retval != PAM_SUCCESS) { fprintf (stderr, _("%s: PAM authentication failed\n"), Prog); exit (E_NOPERM); @@ -714,10 +702,6 @@ nscd_flush_cache ("passwd"); -#ifdef USE_PAM - pam_end (pamh, PAM_SUCCESS); -#endif /* USE_PAM */ - closelog (); exit (E_SUCCESS); }