3 * This generates zephyr acl files
5 * (c) Copyright 1990 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include <moira_site.h>
14 #include <sys/types.h>
17 EXEC SQL INCLUDE sqlca;
20 char *whoami = "zephyr.gen";
22 char zephyr_dir[BUFSIZ];
34 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
38 sprintf(zephyr_dir, "%s/zephyr", DCM_DIR);
41 EXEC SQL CONNECT moira;
42 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
45 EXEC SQL DATABASE moira;
48 changed = do_classes();
54 EXEC SQL CLOSE DATABASE;
58 fprintf(stderr, "No files updated.\n");
59 if (argc == 2 && stat(argv[1], &sb) == 0)
64 fprintf(stderr, "Building tar file.\n");
65 sprintf(cmd, "cd %s; tar cf %s .", zephyr_dir, argv[1]);
91 char outclass[256], buf[256];
92 struct zclass *top, *next, *zc;
95 EXEC SQL BEGIN DECLARE SECTION;
96 char zclass[17], zxtype[9], zstype[9], zwtype[9], zutype[9];
97 int zxid, zsid, zwid, zuid;
98 EXEC SQL END DECLARE SECTION;
100 sprintf(outclass, "%s/class-registry.acl", zephyr_dir);
101 if (stat(outclass, &sb) == 0) {
102 if (ModDiff(&flag1, "zephyr", sb.st_mtime) ||
103 ModDiff(&flag2, "imembers", sb.st_mtime))
105 if (flag1 < 0 && flag2 < 0) {
106 fprintf(stderr, "Zephyr files do not need to be rebuilt.\n");
111 sprintf(buf, "%s~", outclass);
112 out = fopen(buf, "w");
114 perror("opening class-registry.acl");
117 top = (struct zclass *)malloc(sizeof(struct zclass));
120 /* The following is declarative, not executed,
121 * and so is dependent on where it is in the file,
122 * not in the order of execution of statements.
124 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
126 /* Acquire locks for tables */
127 EXEC SQL SELECT modtime INTO :zclass FROM imembers WHERE list_id=0;
128 EXEC SQL SELECT modtime INTO :zclass FROM users WHERE list_id = 0;
129 EXEC SQL SELECT modtime INTO :zclass FROM zephyr WHERE xmt_id = 0;
131 EXEC SQL DECLARE classes CURSOR FOR SELECT class, xmt_type, xmt_id,
132 sub_type, sub_id, iws_type, iws_id, iui_type, iui_id
133 FROM zephyr WHERE xmt_id != 0;
134 EXEC SQL OPEN classes;
136 EXEC SQL FETCH classes INTO
137 :zclass, :zxtype, :zxid, :zstype, :zsid,
138 :zwtype, :zwid, :zutype, :zuid;
139 if (sqlca.sqlcode != 0) break;
140 zc = (struct zclass *)malloc(sizeof(struct zclass));
143 strcpy(zc->class, zclass);
144 strcpy(zc->xtype, zxtype);
145 strcpy(zc->stype, zstype);
146 strcpy(zc->wtype, zwtype);
147 strcpy(zc->utype, zutype);
153 if (sqlca.sqlcode != 100) {
154 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
157 EXEC SQL CLOSE classes;
158 for (zc = top->next; zc; zc = zc->next) {
159 fprintf(out, "%s:\n", strtrim(zc->class));
160 fprintf(stderr, "Working on %s\n", zc->class);
161 if (!strcasecmp(strtrim(zc->xtype), "LIST")) {
162 getlist(zc->xid, zc->class, "xmt");
163 } else if (!strcasecmp(zc->xtype, "KERBEROS")) {
164 getstring(zc->xid, zc->class, "xmt");
165 } else if (!strcasecmp(zc->xtype, "USER")) {
166 getuser(zc->xid, zc->class, "xmt");
167 } else if (!strcasecmp(zc->xtype, "NONE")) {
168 getnone(zc->class, "xmt");
170 if (!strcasecmp(strtrim(zc->stype), "LIST")) {
171 getlist(zc->sid, zc->class, "sub");
172 } else if (!strcasecmp(zc->stype, "KERBEROS")) {
173 getstring(zc->sid, zc->class, "sub");
174 } else if (!strcasecmp(zc->stype, "USER")) {
175 getuser(zc->sid, zc->class, "sub");
176 } else if (!strcasecmp(zc->stype, "NONE")) {
177 getnone(zc->class, "sub");
179 if (!strcasecmp(strtrim(zc->wtype), "LIST")) {
180 getlist(zc->wid, zc->class, "iws");
181 } else if (!strcasecmp(zc->wtype, "KERBEROS")) {
182 getstring(zc->wid, zc->class, "iws");
183 } else if (!strcasecmp(zc->wtype, "USER")) {
184 getuser(zc->wid, zc->class, "iws");
185 } else if (!strcasecmp(zc->wtype, "NONE")) {
186 getnone(zc->class, "iws");
188 if (!strcasecmp(strtrim(zc->utype), "LIST")) {
189 getlist(zc->uid, zc->class, "iui");
190 } else if (!strcasecmp(zc->utype, "KERBEROS")) {
191 getstring(zc->uid, zc->class, "iui");
192 } else if (!strcasecmp(zc->utype, "USER")) {
193 getuser(zc->uid, zc->class, "iui");
194 } else if (!strcasecmp(zc->utype, "NONE")) {
195 getnone(zc->class, "iui");
202 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
203 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
209 getlist(list_id, zclass, atype)
214 char ofile[256], buf[256];
216 EXEC SQL BEGIN DECLARE SECTION;
219 EXEC SQL END DECLARE SECTION;
222 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
223 fprintf(buf, "%s~", ofile);
224 out = fopen(buf, "w");
226 perror("opening acl file");
230 EXEC SQL DECLARE umember CURSOR FOR SELECT users.login
232 WHERE imembers.list_id = :zid and imembers.member_type='USER' and
233 imembers.member_id=users.users_id;
234 EXEC SQL OPEN umember;
236 EXEC SQL FETCH umember INTO :str;
237 if (sqlca.sqlcode != 0) break;
238 fprintf(out, "%s\n", strtrim(str));
240 if (sqlca.sqlcode != 100) {
241 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
244 EXEC SQL CLOSE umember;
246 EXEC SQL DECLARE smember CURSOR FOR SELECT strings.string
247 FROM strings, imembers
248 WHERE imembers.list_id = :zid and imembers.member_id=strings.string_id
249 and (imembers.member_type='STRING' or imembers.member_type='KERBEROS');
250 EXEC SQL OPEN smember;
252 EXEC SQL FETCH smember INTO :str;
253 if (sqlca.sqlcode != 0) break;
254 fprintf(out, "%s\n", strtrim(str));
256 if (sqlca.sqlcode != 100) {
257 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
260 EXEC SQL CLOSE smember;
262 perror("closing acl file");
268 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
269 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
274 getstring(string_id, zclass, atype)
279 char ofile[256], buf[256];
281 EXEC SQL BEGIN DECLARE SECTION;
284 EXEC SQL END DECLARE SECTION;
287 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
288 fprintf(buf, "%s~", ofile);
289 out = fopen(buf, "w");
291 perror("opening acl file");
295 EXEC SQL SELECT string INTO :str FROM strings WHERE string_id = :zid;
296 if (sqlca.sqlcode != 0) {
297 if (sqlca.sqlcode == 100) {
298 fprintf(stderr, "String %d not found for class %s type %s\n",
301 fprintf(stderr, "SQL error %d\n", sqlca.sqlcode);
305 if (!strcmp(strtrim(str), "WILDCARD")) {
306 strcpy(str, "*.*@*");
308 fprintf(out, "%s\n", str);
310 perror("closing acl file");
316 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
317 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
323 getuser(user_id, zclass, atype)
328 char ofile[256], buf[256];
330 EXEC SQL BEGIN DECLARE SECTION;
333 EXEC SQL END DECLARE SECTION;
336 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
337 fprintf(buf, "%s~", ofile);
338 out = fopen(buf, "w");
340 perror("opening acl file");
344 EXEC SQL SELECT login INTO :login FROM users WHERE users_id = :zid;
345 if (sqlca.sqlcode != 0) {
346 if (sqlca.sqlcode == 100) {
347 fprintf(stderr, "User %d not found\n", zid);
349 fprintf(stderr, "SQL error %d\n", sqlca.sqlcode);
353 fprintf(out, "%s\n", strtrim(login));
355 perror("closing acl file");
361 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
362 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
368 getnone(zclass, atype)
374 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);