From 21c13470b533669a5f31c7246a89ff2b06d6b6ed Mon Sep 17 00:00:00 2001 From: tytso Date: Thu, 6 Feb 1997 18:58:30 +0000 Subject: [PATCH] First cut of MIT Warehouse extract program. --- gen/Imakefile | 15 +++--- gen/warehouse.pc | 135 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 gen/warehouse.pc diff --git a/gen/Imakefile b/gen/Imakefile index 8be5aac0..7f3a359c 100644 --- a/gen/Imakefile +++ b/gen/Imakefile @@ -12,26 +12,26 @@ SRCDIR = $(SRCTOP)/gen #ifdef GDSS SRCS = util.c moddiff.c passwd.c hesiod.c \ nfs.c mailhub.c sis.c pobox.c \ - hosts.c network.c + hosts.c network.c warehouse.c OBJS = util.o moddiff.o passwd.o hesiod.o \ nfs.o mailhub.o sis.o pobox.o \ - hosts.o network.o + hosts.o network.o warehouse.o CODE = util.c moddiff.pc passwd.pc hesiod.pc \ nfs.pc mailhub.pc sis.pc pobox.pc \ - hosts.pc network.pc + hosts.pc network.pc warehouse.pc LIBS = -L/usr/athena/lib ../lib/libmoira.a -lcom_err -lzephyr \ ../server/libmrglue.a $(LIBGDSS) -lkrb -ldes -lhesiod ${SQL_LIB} DEFINES = $(GDSSINC) #else /* GDSS */ SRCS = util.c moddiff.c passwd.c hesiod.c \ nfs.c mailhub.c pobox.c \ - hosts.c network.c + hosts.c network.c warehouse.c OBJS = util.o moddiff.o passwd.o hesiod.o \ nfs.o mailhub.o pobox.o \ - hosts.o network.o + hosts.o network.o warehouse.o CODE = util.c moddiff.pc passwd.pc hesiod.pc \ nfs.pc mailhub.pc pobox.pc \ - hosts.pc network.pc + hosts.pc network.pc warehouse.pc LIBS = -L/usr/athena/lib ../lib/libmoira.a -lcom_err -lzephyr \ ../server/libmrglue.a -lkrb -ldes -lhesiod ${SQL_LIB} DEFINES = @@ -57,3 +57,6 @@ program(hosts.gen, hosts.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(hosts) program(network.gen, network.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) sqlfile(network) +program(warehouse.gen, warehouse.o util.o moddiff.o,${MR_LIBDEP},${LIBS},${PROGDIR}) +sqlfile(warehouse) + diff --git a/gen/warehouse.pc b/gen/warehouse.pc new file mode 100644 index 00000000..1ec74544 --- /dev/null +++ b/gen/warehouse.pc @@ -0,0 +1,135 @@ +/* $Header$ + * + * This generates a database extract from the users table for the MIT + * Warehouse. + * + * (c) Copyright 1992 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +EXEC SQL INCLUDE sqlca; + +extern int errno; +char *whoami = "warehouse.gen"; +char *db = "moira/moira"; + +main(argc, argv) +int argc; +char **argv; +{ + int out = 1 /* stdout */; + char *outf = NULL, outft[64]; + struct stat sb; + int flag1; + struct timeval now; + EXEC SQL BEGIN DECLARE SECTION; + char login[9], signature[68], clearid[17], kname[257]; + EXEC SQL VAR signature IS STRING(68); + char last[17], first[17], middle[17], type[9]; + int sigdate, sigwho; + struct { char clearid[17]; + char login[12]; + char last[17]; + char middle[17]; + char first[17]; + char sigdate[12]; + char sigwho[60]; + char signature[69]; + } outrec; + EXEC SQL END DECLARE SECTION; + + initialize_sms_error_table (); + + EXEC SQL CONNECT :db; + + if (argc == 2) { + if (stat(argv[1], &sb) == 0) { + if (ModDiff (&flag1, "users", sb.st_mtime) == 0 && + flag1 < 0) { + fprintf(stderr, "File %s does not need to be rebuilt.\n", + argv[1]); + exit(MR_NO_CHANGE); + } + } + outf = argv[1]; + sprintf(outft, "%s~", outf); + if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) { + fprintf(stderr, "unable to open %s for output\n", outf); + exit(MR_OCONFIG); + } + } else if (argc != 1) { + fprintf(stderr, "usage: %s [outfile]\n", argv[0]); + exit(MR_ARGS); + } else { + outf = NULL; + } + + /* The following is declarative, not executed, + * and so is dependent on where it is in the file, + * not in the order of execution of statements. + */ + EXEC SQL WHENEVER SQLERROR GOTO sqlerr; + + EXEC SQL DECLARE x CURSOR FOR + SELECT u.clearid, u.login, u.last, u.first, u.middle, u.type, + u.sigdate, u.sigwho, u.signature + FROM users u WHERE u.status = 1 or u.status=5 or u.status=6; + EXEC SQL OPEN x; + while (1) { + EXEC SQL FETCH x INTO :clearid, :login, :last, :first, + :middle, :type, :sigdate, :sigwho, :signature; + if (sqlca.sqlcode != 0) break; + if (!isdigit(id[1])) continue; + strtrim(login); + strtrim(clearid); + strtrim(last); + strtrim(first); + strtrim(middle); + strtrim(type); + memset(&outrec, 0, sizeof(outrec)); + strcpy(outrec.login, login); + strcpy(outrec.id, id); + strcpy(outrec.last, last); + strcpy(outrec.first, first); + strcpy(outrec.middle, middle); + strcpy(outrec.type, type); + if (sigwho) { + sprintf(outrec.sigdate, "%d", sigdate); + memcpy(outrec.signature, signature, sizeof(signature)); + EXEC SQL SELECT string from strings + WHERE string_id = :sigwho + INTO :kname; + strcpy(outrec.sigwho, kname); + } + write(out, &outrec, sizeof(outrec)); + } + EXEC SQL CLOSE x; + + EXEC SQL COMMIT; + + if (close(out)) { + perror("close failed"); + exit(MR_CCONFIG); + } + if (outf) + fix_file(outf); + exit(MR_SUCCESS); + + sqlerr: + db_error(sqlca.sqlcode); + exit(MR_DBMS_ERR); +} -- 2.45.2