summaryrefslogtreecommitdiff
path: root/check/pam.c
blob: 5fbb877967b0aa6b7062c81f25da86464ff18f4c (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
#include <stdio.h>

#include <security/pam_appl.h>
#include <security/pam_misc.h>

#include "check.h"

int authenticate(const char *user)
{
	int ret = 1;
	pam_handle_t *pamh = NULL;
	struct pam_conv conv = {
		.conv = misc_conv,
	};

	if (pam_start(PAM_SERVICE_NAME, user, &conv, &pamh) != PAM_SUCCESS) {
		fatal(0, "PAM error");
		return 1;
	}

	if (pam_authenticate(pamh, 0) == PAM_SUCCESS) {
		ret = 0;
	}

	pam_end(pamh, 0);

	return ret;
}