160572Skris/* 260572Skris * This file contains routines modified from OpenBSD. Parts are contributed 360572Skris * by Todd Miller <millert@openbsd.org>, Theo De Raadt <deraadt@openbsd.org> 460572Skris * and possibly others. 560572Skris */ 660572Skris 784216Sdillon#include <sys/cdefs.h> 884216Sdillon__FBSDID("$FreeBSD: releng/10.2/lib/libopie/opieextra.c 92918 2002-03-22 00:12:20Z markm $"); 984216Sdillon 1092918Smarkm#include <sys/types.h> 1160572Skris#include <stdio.h> 1260572Skris#include <opie.h> 1360572Skris 1460572Skris/* 1560572Skris * opie_haopie() 1660572Skris * 1760572Skris * Returns: 1 user doesnt exist, -1 file error, 0 user exists. 1860572Skris * 1960572Skris */ 2060572Skrisint 2160572Skrisopie_haskey(username) 2260572Skrischar *username; 2360572Skris{ 2460572Skris struct opie opie; 2560572Skris 2660572Skris return opielookup(&opie, username); 2760572Skris} 2860572Skris 2960572Skris/* 3060572Skris * opie_keyinfo() 3160572Skris * 3260572Skris * Returns the current sequence number and 3360572Skris * seed for the passed user. 3460572Skris * 3560572Skris */ 3660572Skrischar * 3760572Skrisopie_keyinfo(username) 3860572Skrischar *username; 3960572Skris{ 4060572Skris int i; 4160572Skris static char str[OPIE_CHALLENGE_MAX]; 4260572Skris struct opie opie; 4360572Skris 4460572Skris i = opiechallenge(&opie, username, str); 4560572Skris if (i == -1) 4660572Skris return(0); 4760572Skris 4860572Skris return(str); 4960572Skris} 5060572Skris 5160572Skris/* 5260572Skris * opie_passverify() 5360572Skris * 5460572Skris * Check to see if answer is the correct one to the current 5560572Skris * challenge. 5660572Skris * 5760572Skris * Returns: 0 success, -1 failure 5860572Skris * 5960572Skris */ 6060572Skrisint 6160572Skrisopie_passverify(username, passwd) 6260572Skrischar *username; 6360572Skrischar *passwd; 6460572Skris{ 6560572Skris int i; 6660572Skris struct opie opie; 6760572Skris 6860572Skris i = opielookup(&opie, username); 6960572Skris if (i == -1 || i == 1) 7060572Skris return(-1); 7160572Skris 7260572Skris if (opieverify(&opie, passwd) == 0) 7360572Skris return(opie.opie_n); 7460572Skris 7560572Skris return(-1); 7660572Skris} 7760572Skris 7860572Skris#define OPIE_HASH_DEFAULT 1 7960572Skris 8060572Skris/* Current hash type (index into opie_hash_types array) */ 8160572Skrisstatic int opie_hash_type = OPIE_HASH_DEFAULT; 8260572Skris 8360572Skrisstruct opie_algorithm_table { 8460572Skris const char *name; 8560572Skris}; 8660572Skris 8760572Skrisstatic struct opie_algorithm_table opie_algorithm_table[] = { 8860572Skris "md4", "md5" 8960572Skris}; 9060572Skris 9160572Skris/* Get current hash type */ 9260572Skrisconst char * 9360572Skrisopie_get_algorithm() 9460572Skris{ 9560572Skris return(opie_algorithm_table[opie_hash_type].name); 9660572Skris} 9760572Skris 9860572Skris 99