2007-10-07 17:14:44 +05:30
|
|
|
#include <config.h>
|
|
|
|
|
2007-10-07 17:17:11 +05:30
|
|
|
#ident "$Id: pwdcheck.c,v 1.9 2005/10/19 15:21:07 kloczek Exp $"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
2007-10-07 17:14:44 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "pwauth.h"
|
|
|
|
#ifdef HAVE_SHADOW_H
|
|
|
|
#include <shadow.h>
|
|
|
|
#endif
|
|
|
|
#ifdef USE_PAM
|
|
|
|
#include "pam_defs.h"
|
|
|
|
#endif
|
|
|
|
#define WRONGPWD2 "incorrect password for `%s'"
|
2007-10-07 17:16:07 +05:30
|
|
|
void passwd_check (const char *user, const char *passwd, const char *progname)
|
2007-10-07 17:14:44 +05:30
|
|
|
{
|
|
|
|
#ifdef USE_PAM
|
|
|
|
pam_handle_t *pamh = NULL;
|
|
|
|
int retcode;
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
if (pam_start (progname, user, &conv, &pamh)) {
|
|
|
|
bailout:
|
|
|
|
SYSLOG ((LOG_WARN, WRONGPWD2, user));
|
|
|
|
sleep (1);
|
|
|
|
fprintf (stderr, _("Incorrect password for %s.\n"), user);
|
|
|
|
exit (1);
|
2007-10-07 17:14:44 +05:30
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
if (pam_authenticate (pamh, 0))
|
2007-10-07 17:14:44 +05:30
|
|
|
goto bailout;
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
retcode = pam_acct_mgmt (pamh, 0);
|
2007-10-07 17:15:40 +05:30
|
|
|
if (retcode == PAM_NEW_AUTHTOK_REQD)
|
2007-10-07 17:15:23 +05:30
|
|
|
retcode = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
|
2007-10-07 17:15:49 +05:30
|
|
|
if (retcode)
|
2007-10-07 17:14:44 +05:30
|
|
|
goto bailout;
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
if (pam_setcred (pamh, 0))
|
2007-10-07 17:14:44 +05:30
|
|
|
goto bailout;
|
|
|
|
|
|
|
|
/* no need to establish a session; this isn't a session-oriented
|
|
|
|
* activity... */
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
#else /* !USE_PAM */
|
2007-10-07 17:14:44 +05:30
|
|
|
|
|
|
|
struct spwd *sp;
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
if ((sp = getspnam (user)))
|
2007-10-07 17:14:44 +05:30
|
|
|
passwd = sp->sp_pwdp;
|
2007-10-07 17:15:23 +05:30
|
|
|
endspent ();
|
|
|
|
if (pw_auth (passwd, user, PW_LOGIN, (char *) 0) != 0) {
|
|
|
|
SYSLOG ((LOG_WARN, WRONGPWD2, user));
|
|
|
|
sleep (1);
|
|
|
|
fprintf (stderr, _("Incorrect password for %s.\n"), user);
|
|
|
|
exit (1);
|
2007-10-07 17:14:44 +05:30
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:44 +05:30
|
|
|
}
|