Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / contrib / opie / libopie / challenge.c
1 /* challenge.c: The opiechallenge() 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.32. Added extended response set
18                 identifier to the challenge.
19         Modified by cmetz for OPIE 2.3. Use opie_ prefix. Send debug info to
20                 syslog. Add sha plumbing.
21         Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
22         Created at NRL for OPIE 2.2 from opiesubr2.c
23
24 $FreeBSD: src/contrib/opie/libopie/challenge.c,v 1.1.1.2.6.2 2002/07/15 14:48:47 des Exp $
25 $DragonFly: src/contrib/opie/libopie/challenge.c,v 1.2 2003/06/17 04:24:05 dillon Exp $
26
27 */
28 #include "opie_cfg.h"
29 #include <stdio.h>
30 #include <string.h>
31 #if DEBUG
32 #include <syslog.h>
33 #endif /* DEBUG */
34 #include "opie.h"
35
36 /* Return an OTP challenge string for user 'name'. 
37
38    The return values are:
39
40    0  = All good
41    -1 = Low-level error (file, memory, I/O, etc.)
42    1  = High-level error (user not found or locked)
43
44    This function MUST eventually be followed by an opieverify() to release
45    the user lock and file handles.
46
47    This function will give you a blanked-out state block if it returns a
48    nonzero status. Even though it returns a non-zero status and a blank
49    state block, you still MUST call opieverify() to clear the lock and
50    any internal state (the latter condition is not actually used yet).
51 */
52
53 static char *algids[] = { NULL, NULL, NULL, "sha1", "md4", "md5" };
54
55 int opiechallenge FUNCTION((mp, name, ss), struct opie *mp AND char *name AND char *ss)
56 {
57   int rval = -1;
58
59   rval = opielookup(mp, name);
60 #if DEBUG
61   if (rval) syslog(LOG_DEBUG, "opiechallenge: opielookup(mp, name=%s) returned %d", name, rval);
62 #endif /* DEBUG */
63
64   if (!rval) {
65     rval = opielock(name);
66 #if DEBUG
67     if (rval) syslog(LOG_DEBUG, "opiechallenge: opielock(name=%s) returned %d", name, rval);
68 #endif /* DEBUG */
69   }
70
71   if (rval ||
72     (snprintf(ss, OPIE_CHALLENGE_MAX, "otp-%s %d %s ext", algids[MDX], mp->opie_n - 1, mp->opie_seed) >= OPIE_CHALLENGE_MAX)) {
73     opierandomchallenge(ss);
74     memset(mp, 0, sizeof(*mp));
75   }
76
77   return rval;
78 }