diff options
author | pst <pst@FreeBSD.org> | 1997-02-06 17:52:29 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1997-02-06 17:52:29 +0000 |
commit | 2dfcbf193123fd16b26454eeffa4bbd014e52c53 (patch) | |
tree | ec9d150c9da4390c2d223a04ac002523cbfd7f36 /contrib/opie/libopie/writerec.c | |
download | FreeBSD-src-2dfcbf193123fd16b26454eeffa4bbd014e52c53.zip FreeBSD-src-2dfcbf193123fd16b26454eeffa4bbd014e52c53.tar.gz |
Initial import of OPIE v2.3 from
ftp://ftp.nrl.navy.mil/pub/security/opie/
Diffstat (limited to 'contrib/opie/libopie/writerec.c')
-rw-r--r-- | contrib/opie/libopie/writerec.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/contrib/opie/libopie/writerec.c b/contrib/opie/libopie/writerec.c new file mode 100644 index 0000000..6978669 --- /dev/null +++ b/contrib/opie/libopie/writerec.c @@ -0,0 +1,85 @@ +/* writerec.c: The __opiewriterec() library function. + +%%% copyright-cmetz +This software is Copyright 1996 by Craig Metz, All Rights Reserved. +The Inner Net License Version 2 applies to this software. +You should have received a copy of the license with this software. If +you didn't get a copy, you may request one from <license@inner.net>. + + History: + + Created by cmetz for OPIE 2.3 from passwd.c. +*/ +#include "opie_cfg.h" + +#include <stdio.h> +#if TM_IN_SYS_TIME +#include <sys/time.h> +#else /* TM_IN_SYS_TIME */ +#include <time.h> +#endif /* TM_IN_SYS_TIME */ +#include <sys/types.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif /* HAVE_UNISTD_H */ +#if HAVE_STRING_H +#include <string.h> +#endif /* HAVE_STRING_H */ +#if HAVE_STDLIB_H +#include <stdlib.h> +#endif /* HAVE_STDLIB_H */ +#include "opie.h" + +char *__opienone = "****************"; + +int __opiewriterec FUNCTION((opie), struct opie *opie) +{ + char buf[17], buf2[64]; + time_t now; + FILE *f, *f2 = NULL; + int i = 0; + + time(&now); + if (strftime(buf2, sizeof(buf2), " %b %d,%Y %T", localtime(&now)) < 1) + return -1; + + if (!(opie->opie_flags & __OPIE_FLAGS_READ)) { + struct opie opie2; + i = opielookup(&opie2, opie->opie_principal); + } + + switch(i) { + case 0: + if (!(f = __opieopen(STD_KEY_FILE, 1, 0644))) + return -1; + if (!(f2 = __opieopen(EXT_KEY_FILE, 1, 0600))) + return -1; + if (fseek(f, opie->opie_recstart, SEEK_SET)) + return -1; + if (fseek(f2, opie->opie_extrecstart, SEEK_SET)) + return -1; + break; + case 1: + if (!(f = __opieopen(STD_KEY_FILE, 2, 0644))) + return -1; + if (!(f2 = __opieopen(EXT_KEY_FILE, 2, 0600))) + return -1; + break; + default: + return -1; + } + + 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) + return -1; + + fclose(f); + + if (f2) { + if (fprintf(f2, "%-32s %-16s %-77s\n", opie->opie_principal, opie->opie_reinitkey ? opie->opie_reinitkey : __opienone, "") < 1) + return -1; + + fclose(f2); + } + + return 0; +} |