]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libopie/opieextra.c
This commit was generated by cvs2svn to compensate for changes in r89397,
[FreeBSD/FreeBSD.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
7 #include <sys/cdefs.h>
8 __FBSDID("$FreeBSD$");
9
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(username)
21 char *username;
22 {
23         struct opie opie;
24  
25         return opielookup(&opie, username);
26 }
27  
28 /*
29  * opie_keyinfo()
30  *
31  * Returns the current sequence number and
32  * seed for the passed user.
33  *
34  */
35 char *
36 opie_keyinfo(username)
37 char *username;
38 {
39         int i;
40         static char str[OPIE_CHALLENGE_MAX];
41         struct opie opie;
42
43         i = opiechallenge(&opie, username, str);
44         if (i == -1)
45                 return(0);
46
47         return(str);
48 }
49  
50 /*
51  * opie_passverify()
52  *
53  * Check to see if answer is the correct one to the current
54  * challenge.
55  *
56  * Returns: 0 success, -1 failure
57  *
58  */
59 int
60 opie_passverify(username, passwd)
61 char *username;
62 char *passwd;
63 {
64         int i;
65         struct opie opie;
66
67         i = opielookup(&opie, username);
68         if (i == -1 || i == 1)
69                 return(-1);
70
71         if (opieverify(&opie, passwd) == 0)
72                 return(opie.opie_n);
73
74         return(-1);
75 }
76
77 #define OPIE_HASH_DEFAULT       1
78
79 /* Current hash type (index into opie_hash_types array) */
80 static int opie_hash_type = OPIE_HASH_DEFAULT;
81
82 struct opie_algorithm_table {
83         const char *name;
84 };
85
86 static struct opie_algorithm_table opie_algorithm_table[] = {
87         "md4", "md5"
88 };
89
90 /* Get current hash type */
91 const char *
92 opie_get_algorithm()
93 {
94         return(opie_algorithm_table[opie_hash_type].name);
95 }
96
97