]> andersk Git - moira.git/commitdiff
First cut of MIT Warehouse extract program.
authortytso <tytso>
Thu, 6 Feb 1997 18:58:30 +0000 (18:58 +0000)
committertytso <tytso>
Thu, 6 Feb 1997 18:58:30 +0000 (18:58 +0000)
gen/Imakefile
gen/warehouse.pc [new file with mode: 0644]

index 8be5aac06e7d5a4b75b8a8ed76e3dbdc3f198612..7f3a359ca4659333fd8fa6910ba9a3b1ff535889 100644 (file)
@@ -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 (file)
index 0000000..1ec7454
--- /dev/null
@@ -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
+ *  <mit-copyright.h>.
+ */
+
+#include <mit-copyright.h>
+#include <stdio.h>
+#include <moira.h>
+#include <moira_site.h>
+#include <des.h>
+#include <krb.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/file.h>
+#include <string.h>
+#include <ctype.h>
+#include <fcntl.h>
+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);
+}
This page took 0.067046 seconds and 5 git commands to generate.