159118Skris/* parsechallenge.c: The __opieparsechallenge() library function. 222347Spst 329964Sache%%% copyright-cmetz-96 492906SmarkmThis software is Copyright 1996-2001 by Craig Metz, All Rights Reserved. 592906SmarkmThe Inner Net License Version 3 applies to this software. 622347SpstYou should have received a copy of the license with this software. If 722347Spstyou didn't get a copy, you may request one from <license@inner.net>. 822347Spst 922347Spst History: 1022347Spst 1192906Smarkm Modified by cmetz for OPIE 2.4. Use OPIE_SEQUENCE_MAX, check for 1292906Smarkm sequence number of zero. 1359118Skris Modified by cmetz for OPIE 2.32. Check for extended response sets. 1459118Skris Change prefix to double underscore. 1522347Spst Created by cmetz for OPIE 2.3 using generator.c as a guide. 1622347Spst*/ 1722347Spst 1822347Spst#include "opie_cfg.h" 1922347Spst#if HAVE_STRING_H 2022347Spst#include <string.h> 2122347Spst#endif /* HAVE_STRING_H */ 2222347Spst#include "opie.h" 2322347Spst 2422347Spststruct algorithm { 2522347Spst char *name; 2622347Spst int num; 2722347Spst}; 2822347Spst 2922347Spststatic struct algorithm algorithms[] = { 3022347Spst { "md5", 5 }, 3122347Spst { "md4", 4 }, 3222347Spst { "sha1", 3 }, 3322347Spst { NULL, 0 }, 3422347Spst}; 3522347Spst 3659118Skrisint __opieparsechallenge FUNCTION((buffer, algorithm, sequence, seed, exts), char *buffer AND int *algorithm AND int *sequence AND char **seed AND int *exts) 3722347Spst{ 3822347Spst char *c; 3922347Spst 4022347Spst if (!(c = strchr(buffer, ' '))) 4122347Spst return 1; 4222347Spst 4322347Spst { 4422347Spst struct algorithm *a; 4522347Spst 4622347Spst for (a = algorithms; a->name && strncmp(buffer, a->name, (int)(c - buffer)); a++); 4722347Spst if (!a->name) 4822347Spst return -1; 4922347Spst 5022347Spst *algorithm = a->num; 5122347Spst } 5222347Spst 5392906Smarkm if (((*sequence = strtoul(++c, &c, 10)) > OPIE_SEQUENCE_MAX) || !*sequence) 5422347Spst return -1; 5522347Spst 5622347Spst while(*c && isspace(*c)) c++; 5722347Spst if (!*c) 5822347Spst return -1; 5922347Spst 6022347Spst buffer = c; 6122347Spst while(*c && !isspace(*c)) c++; 6222347Spst 6322347Spst { 6422347Spst int i = (int)(c - buffer); 6522347Spst 6622347Spst if ((i > OPIE_SEED_MAX) || (i < OPIE_SEED_MIN)) 6722347Spst return -1; 6822347Spst } 6922347Spst 7022347Spst *seed = buffer; 7159118Skris *(c++) = 0; 7222347Spst 7359118Skris while(*c && !isspace(*c)) c++; 7459118Skris if (*c && !strncmp(c, "ext", 3)) 7559118Skris *exts = 1; 7659118Skris else 7759118Skris *exts = 0; 7859118Skris 7922347Spst return 0; 8022347Spst} 81