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;
125 EXEC SQL DECLARE classes CURSOR FOR SELECT class, xmt_type, xmt_id,
126 sub_type, sub_id, iws_type, iws_id, iui_type, iui_id
128 EXEC SQL OPEN classes;
130 EXEC SQL FETCH classes INTO
131 :zclass, :zxtype, :zxid, :zstype, :zsid,
132 :zwtype, :zwid, :zutype, :zuid;
133 if (sqlca.sqlcode != 0) break;
134 zc = (struct zclass *)malloc(sizeof(struct zclass));
137 strcpy(zc->class, zclass);
138 strcpy(zc->xtype, zxtype);
139 strcpy(zc->stype, zstype);
140 strcpy(zc->wtype, zwtype);
141 strcpy(zc->utype, zutype);
147 if (sqlca.sqlcode != 100) {
148 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
151 EXEC SQL CLOSE classes;
152 for (zc = top->next; zc; zc = zc->next) {
153 fprintf(out, "%s:\n", strtrim(zc->class));
154 fprintf(stderr, "Working on %s\n", zc->class);
155 if (!strcasecmp(strtrim(zc->xtype), "LIST")) {
156 getlist(zc->xid, zc->class, "xmt");
157 } else if (!strcasecmp(zc->xtype, "KERBEROS")) {
158 getstring(zc->xid, zc->class, "xmt");
159 } else if (!strcasecmp(zc->xtype, "USER")) {
160 getuser(zc->xid, zc->class, "xmt");
161 } else if (!strcasecmp(zc->xtype, "NONE")) {
162 getnone(zc->class, "xmt");
164 if (!strcasecmp(strtrim(zc->stype), "LIST")) {
165 getlist(zc->sid, zc->class, "sub");
166 } else if (!strcasecmp(zc->stype, "KERBEROS")) {
167 getstring(zc->sid, zc->class, "sub");
168 } else if (!strcasecmp(zc->stype, "USER")) {
169 getuser(zc->sid, zc->class, "sub");
170 } else if (!strcasecmp(zc->stype, "NONE")) {
171 getnone(zc->class, "sub");
173 if (!strcasecmp(strtrim(zc->wtype), "LIST")) {
174 getlist(zc->wid, zc->class, "iws");
175 } else if (!strcasecmp(zc->wtype, "KERBEROS")) {
176 getstring(zc->wid, zc->class, "iws");
177 } else if (!strcasecmp(zc->wtype, "USER")) {
178 getuser(zc->wid, zc->class, "iws");
179 } else if (!strcasecmp(zc->wtype, "NONE")) {
180 getnone(zc->class, "iws");
182 if (!strcasecmp(strtrim(zc->utype), "LIST")) {
183 getlist(zc->uid, zc->class, "iui");
184 } else if (!strcasecmp(zc->utype, "KERBEROS")) {
185 getstring(zc->uid, zc->class, "iui");
186 } else if (!strcasecmp(zc->utype, "USER")) {
187 getuser(zc->uid, zc->class, "iui");
188 } else if (!strcasecmp(zc->utype, "NONE")) {
189 getnone(zc->class, "iui");
196 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
197 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
203 getlist(list_id, zclass, atype)
208 char ofile[256], buf[256];
210 EXEC SQL BEGIN DECLARE SECTION;
213 EXEC SQL END DECLARE SECTION;
216 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
217 fprintf(buf, "%s~", ofile);
218 out = fopen(buf, "w");
220 perror("opening acl file");
224 EXEC SQL DECLARE umember CURSOR FOR SELECT users.login
226 WHERE imembers.list_id = :zid and imembers.member_type='USER' and
227 imembers.member_id=users.users_id;
228 EXEC SQL OPEN umember;
230 EXEC SQL FETCH umember INTO :str;
231 if (sqlca.sqlcode != 0) break;
232 fprintf(out, "%s\n", strtrim(str));
234 if (sqlca.sqlcode != 100) {
235 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
238 EXEC SQL CLOSE umember;
240 EXEC SQL DECLARE smember CURSOR FOR SELECT strings.string
241 FROM strings, imembers
242 WHERE imembers.list_id = :zid and imembers.member_id=strings.string_id
243 and (imembers.member_type='STRING' or imembers.member_type='KERBEROS');
244 EXEC SQL OPEN smember;
246 EXEC SQL FETCH smember INTO :str;
247 if (sqlca.sqlcode != 0) break;
248 fprintf(out, "%s\n", strtrim(str));
250 if (sqlca.sqlcode != 100) {
251 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
254 EXEC SQL CLOSE smember;
256 perror("closing acl file");
262 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
263 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
268 getstring(string_id, zclass, atype)
273 char ofile[256], buf[256];
275 EXEC SQL BEGIN DECLARE SECTION;
278 EXEC SQL END DECLARE SECTION;
281 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
282 fprintf(buf, "%s~", ofile);
283 out = fopen(buf, "w");
285 perror("opening acl file");
289 EXEC SQL SELECT string INTO :str FROM strings WHERE string_id = :zid;
290 if (sqlca.sqlcode != 0) {
291 if (sqlca.sqlcode == 100) {
292 fprintf(stderr, "String %d not found for class %s type %s\n",
295 fprintf(stderr, "SQL error %d\n", sqlca.sqlcode);
299 if (!strcmp(strtrim(str), "WILDCARD")) {
300 strcpy(str, "*.*@*");
302 fprintf(out, "%s\n", str);
304 perror("closing acl file");
310 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
311 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
317 getuser(user_id, zclass, atype)
322 char ofile[256], buf[256];
324 EXEC SQL BEGIN DECLARE SECTION;
327 EXEC SQL END DECLARE SECTION;
330 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
331 fprintf(buf, "%s~", ofile);
332 out = fopen(buf, "w");
334 perror("opening acl file");
338 EXEC SQL SELECT login INTO :login FROM users WHERE users_id = :zid;
339 if (sqlca.sqlcode != 0) {
340 if (sqlca.sqlcode == 100) {
341 fprintf(stderr, "User %d not found\n", zid);
343 fprintf(stderr, "SQL error %d\n", sqlca.sqlcode);
347 fprintf(out, "%s\n", strtrim(login));
349 perror("closing acl file");
355 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
356 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
362 getnone(zclass, atype)
368 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);