]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libopie/opieextra.c
This commit was generated by cvs2svn to compensate for changes in r80650,
[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  * $FreeBSD$
7  */
8
9 #include <stdio.h>
10 #include <opie.h>
11
12 /*
13  * opie_haopie()
14  *
15  * Returns: 1 user doesnt exist, -1 file error, 0 user exists.
16  *
17  */
18 int
19 opie_haskey(username)
20 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(username)
36 char *username;
37 {
38         int i;
39         static char str[OPIE_CHALLENGE_MAX];
40         struct opie opie;
41
42         i = opiechallenge(&opie, username, str);
43         if (i == -1)
44                 return(0);
45
46         return(str);
47 }
48  
49 /*
50  * opie_passverify()
51  *
52  * Check to see if answer is the correct one to the current
53  * challenge.
54  *
55  * Returns: 0 success, -1 failure
56  *
57  */
58 int
59 opie_passverify(username, passwd)
60 char *username;
61 char *passwd;
62 {
63         int i;
64         struct opie opie;
65
66         i = opielookup(&opie, username);
67         if (i == -1 || i == 1)
68                 return(-1);
69
70         if (opieverify(&opie, passwd) == 0)
71                 return(opie.opie_n);
72
73         return(-1);
74 }
75
76 #define OPIE_HASH_DEFAULT       1
77
78 /* Current hash type (index into opie_hash_types array) */
79 static int opie_hash_type = OPIE_HASH_DEFAULT;
80
81 struct opie_algorithm_table {
82         const char *name;
83 };
84
85 static struct opie_algorithm_table opie_algorithm_table[] = {
86         "md4", "md5"
87 };
88
89 /* Get current hash type */
90 const char *
91 opie_get_algorithm()
92 {
93         return(opie_algorithm_table[opie_hash_type].name);
94 }
95
96