1/*
2 * This file contains routines modified from OpenBSD. Parts are contributed
3 * by Todd Miller <millert@openbsd.org>, Theo De Raadt <deraadt@openbsd.org>
4 * and possibly others.
5 */
6
7#include <sys/cdefs.h>
8__FBSDID("$FreeBSD$");
9
10#include <sys/types.h>
11#include <stdio.h>
12#include <opie.h>
13
14/*
15 * opie_haopie()
16 *
17 * Returns: 1 user doesnt exist, -1 file error, 0 user exists.
18 *
19 */
20int
21opie_haskey(username)
22char *username;
23{
24	struct opie opie;
25
26	return opielookup(&opie, username);
27}
28
29/*
30 * opie_keyinfo()
31 *
32 * Returns the current sequence number and
33 * seed for the passed user.
34 *
35 */
36char *
37opie_keyinfo(username)
38char *username;
39{
40	int i;
41	static char str[OPIE_CHALLENGE_MAX];
42	struct opie opie;
43
44	i = opiechallenge(&opie, username, str);
45	if (i == -1)
46		return(0);
47
48	return(str);
49}
50
51/*
52 * opie_passverify()
53 *
54 * Check to see if answer is the correct one to the current
55 * challenge.
56 *
57 * Returns: 0 success, -1 failure
58 *
59 */
60int
61opie_passverify(username, passwd)
62char *username;
63char *passwd;
64{
65	int i;
66	struct opie opie;
67
68	i = opielookup(&opie, username);
69	if (i == -1 || i == 1)
70		return(-1);
71
72	if (opieverify(&opie, passwd) == 0)
73		return(opie.opie_n);
74
75	return(-1);
76}
77
78#define OPIE_HASH_DEFAULT	1
79
80/* Current hash type (index into opie_hash_types array) */
81static int opie_hash_type = OPIE_HASH_DEFAULT;
82
83struct opie_algorithm_table {
84	const char *name;
85};
86
87static struct opie_algorithm_table opie_algorithm_table[] = {
88	"md4", "md5"
89};
90
91/* Get current hash type */
92const char *
93opie_get_algorithm()
94{
95	return(opie_algorithm_table[opie_hash_type].name);
96}
97
98
99