1 /* writerec.c: The __opiewriterec() 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 and sequence number are
13 Modified by cmetz for OPIE 2.31. Removed active attack protection
14 support. Fixed passwd bug.
15 Created by cmetz for OPIE 2.3 from passwd.c.
22 #else /* TM_IN_SYS_TIME */
24 #endif /* TM_IN_SYS_TIME */
25 #include <sys/types.h>
28 #endif /* HAVE_UNISTD_H */
31 #endif /* HAVE_STRING_H */
34 #endif /* HAVE_STDLIB_H */
38 char *__opienone
= "****************";
40 int __opiewriterec
FUNCTION((opie
), struct opie
*opie
)
42 char buf
[17], buf2
[64];
49 if (strftime(buf2
, sizeof(buf2
), " %b %d,%Y %T", localtime(&now
)) < 1)
52 if (!(opie
->opie_flags
& __OPIE_FLAGS_READ
)) {
54 i
= opielookup(&opie2
, opie
->opie_principal
);
55 opie
->opie_flags
= opie2
.opie_flags
;
56 opie
->opie_recstart
= opie2
.opie_recstart
;
59 for (c
= opie
->opie_seed
; *c
; c
++)
63 if ((opie
->opie_n
< 0) || (opie
->opie_n
> 9999))
68 if (!(f
= __opieopen(KEY_FILE
, 1, 0644)))
70 if (fseek(f
, opie
->opie_recstart
, SEEK_SET
))
74 if (!(f
= __opieopen(KEY_FILE
, 2, 0644)))
81 if (fprintf(f
, "%s %04d %-16s %s %-21s\n", opie
->opie_principal
, opie
->opie_n
, opie
->opie_seed
, opie
->opie_val
? opie
->opie_val
: __opienone
, buf2
) < 1)