Merge branch 'vendor/TNFTP'
[dragonfly.git] / lib / libopie / opieextra.c
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  * $FreeBSD: src/lib/libopie/opieextra.c,v 1.1.2.2 2002/07/15 14:17:08 des Exp $
7  */
8
9 #include <sys/types.h>
10 #include <stdio.h>
11 #include <opie.h>
12
13 /*
14  * opie_haopie()
15  *
16  * Returns: 1 user doesnt exist, -1 file error, 0 user exists.
17  *
18  */
19 int
20 opie_haskey(char *username)
21 {
22         struct opie opie;
23  
24         return opielookup(&opie, username);
25 }
26  
27 /*
28  * opie_keyinfo()
29  *
30  * Returns the current sequence number and
31  * seed for the passed user.
32  *
33  */
34 char *
35 opie_keyinfo(char *username)
36 {
37         int i;
38         static char str[OPIE_CHALLENGE_MAX];
39         struct opie opie;
40
41         i = opiechallenge(&opie, username, str);
42         if (i == -1)
43                 return(0);
44
45         return(str);
46 }
47  
48 /*
49  * opie_passverify()
50  *
51  * Check to see if answer is the correct one to the current
52  * challenge.
53  *
54  * Returns: 0 success, -1 failure
55  *
56  */
57 int
58 opie_passverify(char *username, char *passwd)
59 {
60         int i;
61         struct opie opie;
62
63         i = opielookup(&opie, username);
64         if (i == -1 || i == 1)
65                 return(-1);
66
67         if (opieverify(&opie, passwd) == 0)
68                 return(opie.opie_n);
69
70         return(-1);
71 }
72
73 #define OPIE_HASH_DEFAULT       1
74
75 /* Current hash type (index into opie_hash_types array) */
76 static int opie_hash_type = OPIE_HASH_DEFAULT;
77
78 struct opie_algorithm_table {
79         const char *name;
80 };
81
82 static struct opie_algorithm_table opie_algorithm_table[] = {
83         { "md4" }, { "md5" }
84 };
85
86 /* Get current hash type */
87 const char *
88 opie_get_algorithm(void)
89 {
90         return(opie_algorithm_table[opie_hash_type].name);
91 }
92
93