Merge from vendor branch LIBSTDC++:
[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  * $DragonFly: src/lib/libopie/opieextra.c,v 1.2 2003/06/17 04:26:50 dillon Exp $
8  */
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  */
20 int
21 opie_haskey(username)
22 char *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  */
36 char *
37 opie_keyinfo(username)
38 char *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  */
60 int
61 opie_passverify(username, passwd)
62 char *username;
63 char *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) */
81 static int opie_hash_type = OPIE_HASH_DEFAULT;
82
83 struct opie_algorithm_table {
84         const char *name;
85 };
86
87 static struct opie_algorithm_table opie_algorithm_table[] = {
88         "md4", "md5"
89 };
90
91 /* Get current hash type */
92 const char *
93 opie_get_algorithm()
94 {
95         return(opie_algorithm_table[opie_hash_type].name);
96 }
97
98