How buggy this little piece of code could be? Repair strnvis() buffersize
[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.4 2008/09/30 16:57:05 swildner 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(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(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(char *username, char *passwd)
60 {
61         int i;
62         struct opie opie;
63
64         i = opielookup(&opie, username);
65         if (i == -1 || i == 1)
66                 return(-1);
67
68         if (opieverify(&opie, passwd) == 0)
69                 return(opie.opie_n);
70
71         return(-1);
72 }
73
74 #define OPIE_HASH_DEFAULT       1
75
76 /* Current hash type (index into opie_hash_types array) */
77 static int opie_hash_type = OPIE_HASH_DEFAULT;
78
79 struct opie_algorithm_table {
80         const char *name;
81 };
82
83 static struct opie_algorithm_table opie_algorithm_table[] = {
84         "md4", "md5"
85 };
86
87 /* Get current hash type */
88 const char *
89 opie_get_algorithm(void)
90 {
91         return(opie_algorithm_table[opie_hash_type].name);
92 }
93
94