AMD64 - AUDIT RUN - Fix format strings, size_t, and other issues
[dragonfly.git] / contrib / opie / libopie / randomchallenge.c
1 /* randomchallenge.c: The opierandomchallenge() library function.
2
3 %%% portions-copyright-cmetz-96
4 Portions of this software are Copyright 1996-1999 by Craig Metz, All Rights
5 Reserved. The Inner Net License Version 2 applies to these portions of
6 the software.
7 You should have received a copy of the license with this software. If
8 you didn't get a copy, you may request one from <license@inner.net>.
9
10 Portions of this software are Copyright 1995 by Randall Atkinson and Dan
11 McDonald, All Rights Reserved. All Rights under this copyright are assigned
12 to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
13 License 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 "opie_cfg.h"
32 #include "opie.h"
33
34 static char *algids[] = { 0, 0, 0, "sha1", "md4", "md5" };
35
36 /* Generate a random challenge */
37 /* This could grow into quite a monster, really. Random is good enough for
38    most situations; it is certainly better than a fixed string */
39 VOIDRET opierandomchallenge FUNCTION((prompt), char *prompt)
40 {
41   char buf[OPIE_SEED_MAX+1];
42
43   buf[0] = 0;
44   if (opienewseed(buf))
45     strcpy(buf, "ke4452");
46
47   snprintf(prompt, OPIE_CHALLENGE_MAX+1, "otp-%s %d %s ext", algids[MDX],
48         (rand() % 499) + 1, buf);
49 }