2000-04-10 11:09:42 +00:00
|
|
|
/* parsechallenge.c: The __opieparsechallenge() library function.
|
1997-02-06 17:52:29 +00:00
|
|
|
|
1997-09-29 08:53:38 +00:00
|
|
|
%%% copyright-cmetz-96
|
2002-03-21 22:50:02 +00:00
|
|
|
This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
|
|
|
|
The Inner Net License Version 3 applies to this software.
|
1997-02-06 17:52:29 +00:00
|
|
|
You should have received a copy of the license with this software. If
|
|
|
|
you didn't get a copy, you may request one from <license@inner.net>.
|
|
|
|
|
|
|
|
History:
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
Modified by cmetz for OPIE 2.4. Use OPIE_SEQUENCE_MAX, check for
|
|
|
|
sequence number of zero.
|
2000-04-10 11:09:42 +00:00
|
|
|
Modified by cmetz for OPIE 2.32. Check for extended response sets.
|
|
|
|
Change prefix to double underscore.
|
1997-02-06 17:52:29 +00:00
|
|
|
Created by cmetz for OPIE 2.3 using generator.c as a guide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opie_cfg.h"
|
|
|
|
#if HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif /* HAVE_STRING_H */
|
|
|
|
#include "opie.h"
|
|
|
|
|
|
|
|
struct algorithm {
|
|
|
|
char *name;
|
|
|
|
int num;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct algorithm algorithms[] = {
|
|
|
|
{ "md5", 5 },
|
|
|
|
{ "md4", 4 },
|
|
|
|
{ "sha1", 3 },
|
|
|
|
{ NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2000-04-10 11:09:42 +00:00
|
|
|
int __opieparsechallenge FUNCTION((buffer, algorithm, sequence, seed, exts), char *buffer AND int *algorithm AND int *sequence AND char **seed AND int *exts)
|
1997-02-06 17:52:29 +00:00
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
|
|
|
|
if (!(c = strchr(buffer, ' ')))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
{
|
|
|
|
struct algorithm *a;
|
|
|
|
|
|
|
|
for (a = algorithms; a->name && strncmp(buffer, a->name, (int)(c - buffer)); a++);
|
|
|
|
if (!a->name)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*algorithm = a->num;
|
|
|
|
}
|
|
|
|
|
2002-03-21 22:50:02 +00:00
|
|
|
if (((*sequence = strtoul(++c, &c, 10)) > OPIE_SEQUENCE_MAX) || !*sequence)
|
1997-02-06 17:52:29 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
while(*c && isspace(*c)) c++;
|
|
|
|
if (!*c)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
buffer = c;
|
|
|
|
while(*c && !isspace(*c)) c++;
|
|
|
|
|
|
|
|
{
|
|
|
|
int i = (int)(c - buffer);
|
|
|
|
|
|
|
|
if ((i > OPIE_SEED_MAX) || (i < OPIE_SEED_MIN))
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*seed = buffer;
|
2000-04-10 11:09:42 +00:00
|
|
|
*(c++) = 0;
|
|
|
|
|
|
|
|
while(*c && !isspace(*c)) c++;
|
|
|
|
if (*c && !strncmp(c, "ext", 3))
|
|
|
|
*exts = 1;
|
|
|
|
else
|
|
|
|
*exts = 0;
|
1997-02-06 17:52:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|