randomchallenge.c revision 257264
1/* randomchallenge.c: The opierandomchallenge() library function.
2
3%%% portions-copyright-cmetz-96
4Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
5Reserved. The Inner Net License Version 2 applies to these portions of
6the software.
7You should have received a copy of the license with this software. If
8you didn't get a copy, you may request one from <license@inner.net>.
9
10Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11McDonald, All Rights Reserved. All Rights under this copyright are assigned
12to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13License Agreement applies to this software.
14
15        History:
16
17	Modified by cmetz for OPIE 2.4. Use snprintf().
18	Modified by cmetz for OPIE 2.32. Initialize algids[] with 0s
19	     instead of NULL.
20        Modified by cmetz for OPIE 2.3. Add sha support.
21	Modified by cmetz for OPIE 2.22. Don't include stdio.h.
22	     Use opienewseed(). Don't include unneeded headers.
23	Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
24             Changed use of gethostname() to uname(). Ifdefed around some
25             headers.
26        Created at NRL for OPIE 2.2 from opiesubr2.c
27*/
28
29#include <stdio.h>
30#include <string.h>
31#include <stdlib.h>
32#include "opie_cfg.h"
33#include "opie.h"
34
35static char *algids[] = { 0, 0, 0, "sha1", "md4", "md5" };
36
37/* Generate a random challenge */
38/* This could grow into quite a monster, really. Random is good enough for
39   most situations; it is certainly better than a fixed string */
40VOIDRET opierandomchallenge FUNCTION((prompt), char *prompt)
41{
42  char buf[OPIE_SEED_MAX+1];
43
44  buf[0] = 0;
45  if (opienewseed(buf))
46    strcpy(buf, "ke4452");
47
48  snprintf(prompt, OPIE_CHALLENGE_MAX+1, "otp-%s %d %s ext", algids[MDX],
49  	(rand() % 499) + 1, buf);
50}
51