summaryrefslogtreecommitdiffstats
path: root/contrib/opie/libopie/parsechallenge.c
blob: 2035c381b356a8dd3fd291ba50cceb3cbb0722b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* parsechallenge.c: The __opieparsechallenge() library function.

%%% copyright-cmetz-96
This software is Copyright 1996-1998 by Craig Metz, All Rights Reserved.
The Inner Net License Version 2 applies to this software.
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:

	Modified by cmetz for OPIE 2.32. Check for extended response sets.
		Change prefix to double underscore.
	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 },
};

int __opieparsechallenge FUNCTION((buffer, algorithm, sequence, seed, exts), char *buffer AND int *algorithm AND int *sequence AND char **seed AND int *exts)
{
  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;
  }

  if ((*sequence = strtoul(++c, &c, 10)) > 9999)
    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;
  *(c++) = 0;

  while(*c && !isspace(*c)) c++;
  if (*c && !strncmp(c, "ext", 3))
    *exts = 1;
  else
    *exts = 0;

  return 0;
}
OpenPOWER on IntegriCloud