1 /* readrec.c: The __opiereadrec() library function.
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
11 Modified by cmetz for OPIE 2.4. Check that seed, sequence number, and
12 response values are valid.
13 Modified by cmetz for OPIE 2.31. Removed active attack protection
14 support. Fixed a debug message typo. Keep going after bogus
15 records. Set read flag.
16 Created by cmetz for OPIE 2.3.
21 #include <sys/types.h>
25 #endif /* HAVE_UNISTD_H */
28 #endif /* HAVE_STRING_H */
31 #endif /* HAVE_STDLIB_H */
34 #endif /* HAVE_FCNTL_H */
42 static int parserec FUNCTION((opie), struct opie *opie)
46 if (!(c2 = strchr(opie->opie_principal = opie->opie_buf, ' ')))
49 while(*c2 == ' ') c2++;
52 if (!(c2 = strchr(c = c2, ' ')))
60 opie->opie_n = strtoul(c, &c3, 10);
62 if (*c3 || (opie->opie_n <= 0) || (opie->opie_n > 9999))
66 if (!(c2 = strchr(opie->opie_seed = c2, ' ')))
71 for (c = opie->opie_seed; *c; c++)
75 while(*c2 == ' ') c2++;
77 if (!(c2 = strchr(opie->opie_val = c2, ' ')))
83 struct opie_otpkey otpkey;
85 if (!opieatob8(&otpkey, opie->opie_val))
92 int __opiereadrec FUNCTION((opie), struct opie *opie)
97 if (!(f = __opieopen(KEY_FILE, 0, 0644))) {
99 syslog(LOG_DEBUG, "__opiereadrec: __opieopen(KEY_FILE..) failed!");
107 if ((i = open(KEY_FILE, O_RDWR)) < 0) {
108 opie->opie_flags &= ~__OPIE_FLAGS_RW;
110 syslog(LOG_DEBUG, "__opiereadrec: open(KEY_FILE, O_RDWR) failed: %s", strerror(errno));
114 opie->opie_flags |= __OPIE_FLAGS_RW;
118 if (opie->opie_buf[0]) {
119 if (fseek(f, opie->opie_recstart, SEEK_SET))
122 if (fgets(opie->opie_buf, sizeof(opie->opie_buf), f))
128 opie->opie_flags |= __OPIE_FLAGS_READ;
133 if (!opie->opie_principal)
137 char *c, principal[OPIE_PRINCIPAL_MAX];
140 if (c = strchr(opie->opie_principal, ':'))
142 if (strlen(opie->opie_principal) > OPIE_PRINCIPAL_MAX)
143 (opie->opie_principal)[OPIE_PRINCIPAL_MAX] = 0;
145 strcpy(principal, opie->opie_principal);
148 if ((opie->opie_recstart = ftell(f)) < 0)
151 if (!fgets(opie->opie_buf, sizeof(opie->opie_buf), f)) {
158 } while (strcmp(principal, opie->opie_principal));