summaryrefslogtreecommitdiffstats
path: root/libmisc/pwdcheck.c
blob: 15fc3a33221b487d3439a73d18f59112f418f16c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * SPDX-FileCopyrightText: 2000 - 2005, Tomasz Kłoczko
 * SPDX-FileCopyrightText: 2007 - 2008, Nicolas François
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <config.h>

#ident "$Id$"

#ifndef USE_PAM

#include <stdio.h>
#include <shadow.h>
#include "prototypes.h"
#include "defines.h"
#include "pwauth.h"
#include "shadowlog.h"

void passwd_check (const char *user, const char *passwd, unused const char *progname)
{
	struct spwd *sp;

	sp = getspnam (user); /* !USE_PAM, no need for xgetspnam */
	if (NULL != sp) {
		passwd = sp->sp_pwdp;
	}
	if (pw_auth (passwd, user, PW_LOGIN, (char *) 0) != 0) {
		SYSLOG ((LOG_WARN, "incorrect password for `%s'", user));
		(void) sleep (1);
		fprintf (log_get_logfd(), _("Incorrect password for %s.\n"), user);
		exit (EXIT_FAILURE);
	}
}
#else			/* USE_PAM */
extern int errno;	/* warning: ANSI C forbids an empty source file */
#endif			/* USE_PAM */