3 * This generates a database extract from the users table for the MIT
6 * (c) Copyright 1992 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
15 #include <moira_site.h>
19 #include <sys/types.h>
27 EXEC SQL INCLUDE sqlca;
29 char *whoami = "warehouse.gen";
30 char *db = "moira/moira";
32 #ifndef WAREHOUSE_SUBDIR
33 #define WAREHOUSE_SUBDIR "warehouse"
36 char warehouse_dir[128];
38 int main(int argc, char **argv)
40 int out = STDOUT_FILENO;
41 char *outf = NULL, outft[64];
42 char control_fn[80], cmd[256];
49 EXEC SQL BEGIN DECLARE SECTION;
50 char login[9], sig[257], id[17], kname[257];
51 char fname[17], lname[17], middle[17];
52 EXEC SQL VAR sig IS STRING(257);
53 int timestamp, sigwho;
62 EXEC SQL END DECLARE SECTION;
64 initialize_sms_error_table();
66 sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR);
72 if (stat(argv[1], &sb) == 0)
74 if (ModDiff(&flag1, "users", sb.st_mtime) == 0 && flag1 < 0)
76 fprintf(stderr, "File %s does not need to be rebuilt.\n",
82 sprintf(outft, "%s/username_id.map", warehouse_dir);
83 if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0)
85 fprintf(stderr, "unable to open %s for output\n", outf);
91 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
97 /* The following is declarative, not executed,
98 * and so is dependent on where it is in the file,
99 * not in the order of execution of statements.
101 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
103 EXEC SQL DECLARE x CURSOR FOR
104 SELECT u.login, u.clearid, u.signature, u.sigdate, s.string, u.sigwho,
105 u.first, u.last, u.middle
106 FROM users u, strings s
107 WHERE (u.status = 1 or u.status = 2 or u.status = 5 OR
108 u.status = 6 or u.status = 7)
109 AND u.sigwho = s.string_id;
113 EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname, :sigwho,
114 :fname, :lname, :middle;
127 memset(&outrec, 0, sizeof(outrec));
128 strcpy(outrec.login, login);
129 strcpy(outrec.id, id);
130 strcpy(outrec.fname, fname);
131 strcpy(outrec.lname, lname);
132 strcpy(outrec.middle, middle);
135 si.timestamp = timestamp;
136 si.SigInfoVersion = 0; /* XXXXXX this isn't used */
137 kname_parse(si.pname, si.pinst, si.prealm, kname);
138 si.rawsig = (unsigned char *)sig;
139 GDSS_Recompose(&si, outrec.sig);
141 write(out, &outrec, sizeof(outrec));
150 perror("close failed");
153 sprintf(control_fn, "%s/username_id.ctl", warehouse_dir);
155 f = fopen(control_fn, "w");
158 perror("creating username_id control file");
161 fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n");
162 fprintf(f, "%d records\n", records);
163 fprintf(f, "%d bytes\n", records * (12 + 12 + 20 + 20 + 20 + 256));
164 fprintf(f, "Full feed\n");
165 fprintf(f, "Fixed format -- binary\n");
169 fprintf(stderr, "Building tar file.\n");
170 sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s",
171 warehouse_dir, outf);
179 db_error(sqlca.sqlcode);