getdevpath.3: Fix reference and sort.
[dragonfly.git] / lib / libopie / opieextra.c
blobb6dccda1273a4c9b088fa2fc78830892fc1fa032
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.
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 */
10 #include <sys/types.h>
11 #include <stdio.h>
12 #include <opie.h>
15 * opie_haopie()
17 * Returns: 1 user doesnt exist, -1 file error, 0 user exists.
20 int
21 opie_haskey(char *username)
23 struct opie opie;
25 return opielookup(&opie, username);
29 * opie_keyinfo()
31 * Returns the current sequence number and
32 * seed for the passed user.
35 char *
36 opie_keyinfo(char *username)
38 int i;
39 static char str[OPIE_CHALLENGE_MAX];
40 struct opie opie;
42 i = opiechallenge(&opie, username, str);
43 if (i == -1)
44 return(0);
46 return(str);
50 * opie_passverify()
52 * Check to see if answer is the correct one to the current
53 * challenge.
55 * Returns: 0 success, -1 failure
58 int
59 opie_passverify(char *username, char *passwd)
61 int i;
62 struct opie opie;
64 i = opielookup(&opie, username);
65 if (i == -1 || i == 1)
66 return(-1);
68 if (opieverify(&opie, passwd) == 0)
69 return(opie.opie_n);
71 return(-1);
74 #define OPIE_HASH_DEFAULT 1
76 /* Current hash type (index into opie_hash_types array) */
77 static int opie_hash_type = OPIE_HASH_DEFAULT;
79 struct opie_algorithm_table {
80 const char *name;
83 static struct opie_algorithm_table opie_algorithm_table[] = {
84 "md4", "md5"
87 /* Get current hash type */
88 const char *
89 opie_get_algorithm(void)
91 return(opie_algorithm_table[opie_hash_type].name);