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);
44 EXEC SQL DATABASE sms;
47 changed = do_classes();
53 EXEC SQL CLOSE DATABASE;
57 fprintf(stderr, "No files updated.\n");
58 if (argc == 2 && stat(argv[1], &sb) == 0)
63 fprintf(stderr, "Building tar file.\n");
64 sprintf(cmd, "cd %s; tar cf %s .", zephyr_dir, argv[1]);
90 char outclass[256], buf[256];
91 struct zclass *top, *next, *zc;
94 EXEC SQL BEGIN DECLARE SECTION;
95 char zclass[17], zxtype[9], zstype[9], zwtype[9], zutype[9];
96 int zxid, zsid, zwid, zuid;
97 EXEC SQL END DECLARE SECTION;
99 sprintf(outclass, "%s/class-registry.acl", zephyr_dir);
100 if (stat(outclass, &sb) == 0) {
101 if (ModDiff(&flag1, "zephyr", sb.st_mtime) ||
102 ModDiff(&flag2, "imembers", sb.st_mtime))
104 if (flag1 < 0 && flag2 < 0) {
105 fprintf(stderr, "Zephyr files do not need to be rebuilt.\n");
110 sprintf(buf, "%s~", outclass);
111 out = fopen(buf, "w");
113 perror("opening class-registry.acl");
116 top = (struct zclass *)malloc(sizeof(struct zclass));
119 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
120 EXEC SQL DECLARE classes CURSOR FOR SELECT class, xmt_type, xmt_id,
121 sub_type, sub_id, iws_type, iws_id, iui_type, iui_id
123 EXEC SQL OPEN classes;
125 EXEC SQL FETCH classes INTO
126 :zclass, :zxtype, :zxid, :zstype, :zsid,
127 :zwtype, :zwid, :zutype, :zuid;
128 if (sqlca.sqlcode != 0) break;
129 zc = (struct zclass *)malloc(sizeof(struct zclass));
132 strcpy(zc->class, zclass);
133 strcpy(zc->xtype, zxtype);
134 strcpy(zc->stype, zstype);
135 strcpy(zc->wtype, zwtype);
136 strcpy(zc->utype, zutype);
142 if (sqlca.sqlcode != 100) {
143 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
146 EXEC SQL CLOSE classes;
147 for (zc = top->next; zc; zc = zc->next) {
148 fprintf(out, "%s:\n", strtrim(zc->class));
149 fprintf(stderr, "Working on %s\n", zc->class);
150 if (!strcasecmp(strtrim(zc->xtype), "LIST")) {
151 getlist(zc->xid, zc->class, "xmt");
152 } else if (!strcasecmp(zc->xtype, "KERBEROS")) {
153 getstring(zc->xid, zc->class, "xmt");
154 } else if (!strcasecmp(zc->xtype, "USER")) {
155 getuser(zc->xid, zc->class, "xmt");
156 } else if (!strcasecmp(zc->xtype, "NONE")) {
157 getnone(zc->class, "xmt");
159 if (!strcasecmp(strtrim(zc->stype), "LIST")) {
160 getlist(zc->sid, zc->class, "sub");
161 } else if (!strcasecmp(zc->stype, "KERBEROS")) {
162 getstring(zc->sid, zc->class, "sub");
163 } else if (!strcasecmp(zc->stype, "USER")) {
164 getuser(zc->sid, zc->class, "sub");
165 } else if (!strcasecmp(zc->stype, "NONE")) {
166 getnone(zc->class, "sub");
168 if (!strcasecmp(strtrim(zc->wtype), "LIST")) {
169 getlist(zc->wid, zc->class, "iws");
170 } else if (!strcasecmp(zc->wtype, "KERBEROS")) {
171 getstring(zc->wid, zc->class, "iws");
172 } else if (!strcasecmp(zc->wtype, "USER")) {
173 getuser(zc->wid, zc->class, "iws");
174 } else if (!strcasecmp(zc->wtype, "NONE")) {
175 getnone(zc->class, "iws");
177 if (!strcasecmp(strtrim(zc->utype), "LIST")) {
178 getlist(zc->uid, zc->class, "iui");
179 } else if (!strcasecmp(zc->utype, "KERBEROS")) {
180 getstring(zc->uid, zc->class, "iui");
181 } else if (!strcasecmp(zc->utype, "USER")) {
182 getuser(zc->uid, zc->class, "iui");
183 } else if (!strcasecmp(zc->utype, "NONE")) {
184 getnone(zc->class, "iui");
191 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
192 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
198 getlist(list_id, zclass, atype)
203 char ofile[256], buf[256];
205 EXEC SQL BEGIN DECLARE SECTION;
208 EXEC SQL END DECLARE SECTION;
211 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
212 fprintf(buf, "%s~", ofile);
213 out = fopen(buf, "w");
215 perror("opening acl file");
219 EXEC SQL DECLARE umember CURSOR FOR SELECT users.login
221 WHERE imembers.list_id = :zid and imembers.member_type="USER" and
222 imembers.member_id=users.users_id;
223 EXEC SQL OPEN umember;
225 EXEC SQL FETCH umember INTO :str;
226 if (sqlca.sqlcode != 0) break;
227 fprintf(out, "%s\n", strtrim(str));
229 if (sqlca.sqlcode != 100) {
230 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
233 EXEC SQL CLOSE umember;
235 EXEC SQL DECLARE smember CURSOR FOR SELECT strings.string
236 FROM strings, imembers
237 WHERE imembers.list_id = :zid and imembers.member_id=strings.string_id
238 and (imembers.member_type="STRING" or imembers.member_type="KERBEROS");
239 EXEC SQL OPEN smember;
241 EXEC SQL FETCH smember INTO :str;
242 if (sqlca.sqlcode != 0) break;
243 fprintf(out, "%s\n", strtrim(str));
245 if (sqlca.sqlcode != 100) {
246 fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode);
249 EXEC SQL CLOSE smember;
251 perror("closing acl file");
257 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
258 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
263 getstring(string_id, zclass, atype)
268 char ofile[256], buf[256];
270 EXEC SQL BEGIN DECLARE SECTION;
273 EXEC SQL END DECLARE SECTION;
276 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
277 fprintf(buf, "%s~", ofile);
278 out = fopen(buf, "w");
280 perror("opening acl file");
284 EXEC SQL SELECT string INTO :str FROM strings WHERE string_id = :zid;
285 if (sqlca.sqlcode != 0) {
286 if (sqlca.sqlcode == 100) {
287 fprintf(stderr, "String %d not found for class %s type %s\n",
290 fprintf(stderr, "SQL error %d\n", sqlca.sqlcode);
294 if (!strcmp(strtrim(str), "WILDCARD")) {
295 strcpy(str, "*.*@*");
297 fprintf(out, "%s\n", str);
299 perror("closing acl file");
305 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
306 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
312 getuser(user_id, zclass, atype)
317 char ofile[256], buf[256];
319 EXEC SQL BEGIN DECLARE SECTION;
322 EXEC SQL END DECLARE SECTION;
325 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);
326 fprintf(buf, "%s~", ofile);
327 out = fopen(buf, "w");
329 perror("opening acl file");
333 EXEC SQL SELECT login INTO :login FROM users WHERE users_id = :zid;
334 if (sqlca.sqlcode != 0) {
335 if (sqlca.sqlcode == 100) {
336 fprintf(stderr, "User %d not found\n", zid);
338 fprintf(stderr, "SQL error %d\n", sqlca.sqlcode);
342 fprintf(out, "%s\n", strtrim(login));
344 perror("closing acl file");
350 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
351 critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d",
357 getnone(zclass, atype)
363 sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass);