]> andersk Git - moira.git/blame - gen/warehouse.pc
remove a redundant comparison
[moira.git] / gen / warehouse.pc
CommitLineData
21c13470 1/* $Header$
2 *
3 * This generates a database extract from the users table for the MIT
4 * Warehouse.
5 *
6 * (c) Copyright 1992 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 */
10
11#include <mit-copyright.h>
12#include <stdio.h>
13#include <moira.h>
14#include <moira_site.h>
15#include <des.h>
16#include <krb.h>
7ce1db33 17#include <gdss.h>
21c13470 18#include <sys/types.h>
19#include <sys/stat.h>
20#include <sys/time.h>
21#include <sys/file.h>
22#include <string.h>
23#include <ctype.h>
24#include <fcntl.h>
25EXEC SQL INCLUDE sqlca;
26
27extern int errno;
7ce1db33 28char *whoami = "sis.gen";
21c13470 29char *db = "moira/moira";
30
97cd0053 31#ifndef WAREHOUSE_SUBDIR
32#define WAREHOUSE_SUBDIR "warehouse"
33#endif
34
35char warehouse_dir[128];
36
21c13470 37main(argc, argv)
38int argc;
39char **argv;
40{
41 int out = 1 /* stdout */;
42 char *outf = NULL, outft[64];
98a7b0ee 43 char control_fn[80], cmd[256];
97cd0053 44 FILE *f;
21c13470 45 struct stat sb;
46 int flag1;
7ce1db33 47 SigInfo si;
21c13470 48 struct timeval now;
97cd0053 49 int records = 0;
21c13470 50 EXEC SQL BEGIN DECLARE SECTION;
7ce1db33 51 char login[9], sig[257], id[17], kname[257];
8852b73e 52 char fname[17], lname[17], middle[17];
7ce1db33 53 EXEC SQL VAR sig IS STRING(257);
54 int timestamp, sigwho;
55 struct { char login[12];
56 char id[12];
8852b73e 57 char fname[20];
58 char lname[20];
59 char middle[20];
7ce1db33 60 char sig[256];
21c13470 61 } outrec;
62 EXEC SQL END DECLARE SECTION;
63
64 initialize_sms_error_table ();
65
97cd0053 66 sprintf(warehouse_dir, "%s/%s", DCM_DIR, WAREHOUSE_SUBDIR);
67
21c13470 68 EXEC SQL CONNECT :db;
69
70 if (argc == 2) {
71 if (stat(argv[1], &sb) == 0) {
72 if (ModDiff (&flag1, "users", sb.st_mtime) == 0 &&
73 flag1 < 0) {
74 fprintf(stderr, "File %s does not need to be rebuilt.\n",
75 argv[1]);
76 exit(MR_NO_CHANGE);
77 }
78 }
79 outf = argv[1];
97cd0053 80 sprintf(outft, "%s/username_id.map", warehouse_dir);
21c13470 81 if ((out = open(outft, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, 0666)) < 0) {
82 fprintf(stderr, "unable to open %s for output\n", outf);
83 exit(MR_OCONFIG);
84 }
85 } else if (argc != 1) {
86 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
87 exit(MR_ARGS);
88 } else {
89 outf = NULL;
90 }
91
92 /* The following is declarative, not executed,
93 * and so is dependent on where it is in the file,
94 * not in the order of execution of statements.
95 */
96 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
97
98 EXEC SQL DECLARE x CURSOR FOR
8852b73e 99 SELECT u.login, u.clearid, u.signature, u.sigdate, s.string, u.sigwho,
100 u.first, u.last, u.middle
7ce1db33 101 FROM users u, strings s
97cd0053 102 WHERE (u.status = 1 or u.status=2 or u.status=5 or
103 u.status=6 or u.status=7)
104 and u.sigwho = s.string_id;
21c13470 105 EXEC SQL OPEN x;
106 while (1) {
8852b73e 107 EXEC SQL FETCH x INTO :login, :id, :sig, :timestamp, :kname, :sigwho,
108 :fname, :lname, :middle;
21c13470 109 if (sqlca.sqlcode != 0) break;
7ce1db33 110 if (id == 0) continue;
21c13470 111 if (!isdigit(id[1])) continue;
112 strtrim(login);
7ce1db33 113 strtrim(id);
114 strtrim(kname);
8852b73e 115 strtrim(fname);
116 strtrim(lname);
117 strtrim(middle);
21c13470 118 memset(&outrec, 0, sizeof(outrec));
119 strcpy(outrec.login, login);
120 strcpy(outrec.id, id);
8852b73e 121 strcpy(outrec.fname, fname);
122 strcpy(outrec.lname, lname);
123 strcpy(outrec.middle, middle);
21c13470 124 if (sigwho) {
7ce1db33 125 si.timestamp = timestamp;
126 si.SigInfoVersion = 0; /* XXXXXX this isn't used */
127 kname_parse(si.pname, si.pinst, si.prealm, kname);
128 si.rawsig = (unsigned char *)sig;
129 GDSS_Recompose(&si, outrec.sig);
21c13470 130 }
131 write(out, &outrec, sizeof(outrec));
97cd0053 132 records++;
21c13470 133 }
134 EXEC SQL CLOSE x;
135
136 EXEC SQL COMMIT;
137
138 if (close(out)) {
139 perror("close failed");
140 exit(MR_CCONFIG);
141 }
97cd0053 142 sprintf(control_fn, "%s/username_id.ctl", warehouse_dir);
143
144 f = fopen(control_fn, "w");
145 if (!f) {
146 perror("creating username_id control file");
147 exit(MR_OCONFIG);
148 }
149 fprintf(f, "username_id.map --- Moira feed for MIT Data Warehouse\n");
150 fprintf(f, "%d records\n", records);
8852b73e 151 fprintf(f, "%d bytes\n", records * (12+12+20+20+20+256));
97cd0053 152 fprintf(f, "Full feed\n");
153 fprintf(f, "Fixed format -- binary\n");
154 fclose(f);
155 if (outf) {
156 fprintf(stderr, "Building tar file.\n");
157 sprintf(cmd, "(cd %s; tar cf - . ) | compress > %s",
158 warehouse_dir, outf);
159 if (system(cmd))
160 exit(MR_TAR_FAIL);
161 }
162
21c13470 163 exit(MR_SUCCESS);
164
165 sqlerr:
166 db_error(sqlca.sqlcode);
167 exit(MR_DBMS_ERR);
168}
This page took 0.12421 seconds and 5 git commands to generate.