opieextra.c revision 84216
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: head/lib/libopie/opieextra.c 84216 2001-09-30 22:04:49Z dillon $"); 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 */ 19int 20opie_haskey(username) 21char *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 */ 35char * 36opie_keyinfo(username) 37char *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 */ 59int 60opie_passverify(username, passwd) 61char *username; 62char *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) */ 80static int opie_hash_type = OPIE_HASH_DEFAULT; 81 82struct opie_algorithm_table { 83 const char *name; 84}; 85 86static struct opie_algorithm_table opie_algorithm_table[] = { 87 "md4", "md5" 88}; 89 90/* Get current hash type */ 91const char * 92opie_get_algorithm() 93{ 94 return(opie_algorithm_table[opie_hash_type].name); 95} 96 97 98