opieextra.c revision 60572
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: head/lib/libopie/opieextra.c 60572 2000-05-15 04:20:54Z kris $ 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 */ 18int 19opie_haskey(username) 20char *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 */ 34char * 35opie_keyinfo(username) 36char *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 */ 58int 59opie_passverify(username, passwd) 60char *username; 61char *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) */ 79static int opie_hash_type = OPIE_HASH_DEFAULT; 80 81struct opie_algorithm_table { 82 const char *name; 83}; 84 85static struct opie_algorithm_table opie_algorithm_table[] = { 86 "md4", "md5" 87}; 88 89/* Get current hash type */ 90const char * 91opie_get_algorithm() 92{ 93 return(opie_algorithm_table[opie_hash_type].name); 94} 95 96 97