summaryrefslogtreecommitdiff
path: root/accel-pppd/pwdb.c
blob: f4440b8f567ff8ec53fa26b157383138ddefc8b2 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdlib.h>

#include "triton.h"

#include "pwdb.h"

#include "memdebug.h"

static LIST_HEAD(pwdb_handlers);

int __export pwdb_check(struct ap_session *ses, const char *username, int type, ...)
{
	struct pwdb_t *pwdb;
	int r, res = PWDB_NO_IMPL;
	va_list args;

	va_start(args, type);

	list_for_each_entry(pwdb, &pwdb_handlers, entry) {
		if (!pwdb->check)
			continue;
		r = pwdb->check(pwdb, ses, username, type, args);
		if (r == PWDB_NO_IMPL)
			continue;
		if (r == PWDB_SUCCESS)
			return PWDB_SUCCESS;
		res = r;
	}

	return res;
}
__export char *pwdb_get_passwd(struct ap_session *ses, const char *username)
{
	struct pwdb_t *pwdb;
	char *r = NULL;

	list_for_each_entry(pwdb, &pwdb_handlers, entry) {
		if (!pwdb->get_passwd)
			continue;
		r = pwdb->get_passwd(pwdb, ses, username);
		if (r)
			break;
	}

	return r;
}

void __export pwdb_register(struct pwdb_t *pwdb)
{
	list_add_tail(&pwdb->entry, &pwdb_handlers);
}
void __export pwdb_unregister(struct pwdb_t *pwdb)
{
	list_del(&pwdb->entry);
}