summaryrefslogtreecommitdiffstats
path: root/lib/libopie/opieextra.c
blob: 6e2b6b88328c8eeeff5e3c20d509459327d2977f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * This file contains routines modified from OpenBSD. Parts are contributed
 * by Todd Miller <millert@openbsd.org>, Theo De Raadt <deraadt@openbsd.org>
 * and possibly others.
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/types.h>
#include <stdio.h>
#include <opie.h>

/*
 * opie_haopie()
 *
 * Returns: 1 user doesnt exist, -1 file error, 0 user exists.
 *
 */
int
opie_haskey(username)
char *username;
{
	struct opie opie;
 
	return opielookup(&opie, username);
}
 
/*
 * opie_keyinfo()
 *
 * Returns the current sequence number and
 * seed for the passed user.
 *
 */
char *
opie_keyinfo(username)
char *username;
{
	int i;
	static char str[OPIE_CHALLENGE_MAX];
	struct opie opie;

	i = opiechallenge(&opie, username, str);
	if (i == -1)
		return(0);

	return(str);
}
 
/*
 * opie_passverify()
 *
 * Check to see if answer is the correct one to the current
 * challenge.
 *
 * Returns: 0 success, -1 failure
 *
 */
int
opie_passverify(username, passwd)
char *username;
char *passwd;
{
	int i;
	struct opie opie;

	i = opielookup(&opie, username);
	if (i == -1 || i == 1)
		return(-1);

	if (opieverify(&opie, passwd) == 0)
		return(opie.opie_n);

	return(-1);
}

#define OPIE_HASH_DEFAULT	1

/* Current hash type (index into opie_hash_types array) */
static int opie_hash_type = OPIE_HASH_DEFAULT;

struct opie_algorithm_table {
	const char *name;
};

static struct opie_algorithm_table opie_algorithm_table[] = {
	"md4", "md5"
};

/* Get current hash type */
const char *
opie_get_algorithm()
{
	return(opie_algorithm_table[opie_hash_type].name);
}


OpenPOWER on IntegriCloud