1 /* challenge.c: The opiechallenge() library function.
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
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>.
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.
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
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 $
36 /* Return an OTP challenge string for user 'name'.
38 The return values are:
41 -1 = Low-level error (file, memory, I/O, etc.)
42 1 = High-level error (user not found or locked)
44 This function MUST eventually be followed by an opieverify() to release
45 the user lock and file handles.
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).
53 static char *algids[] = { NULL, NULL, NULL, "sha1", "md4", "md5" };
55 int opiechallenge FUNCTION((mp, name, ss), struct opie *mp AND char *name AND char *ss)
59 rval = opielookup(mp, name);
61 if (rval) syslog(LOG_DEBUG, "opiechallenge: opielookup(mp, name=%s) returned %d", name, rval);
65 rval = opielock(name);
67 if (rval) syslog(LOG_DEBUG, "opiechallenge: opielock(name=%s) returned %d", name, 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));