]>
Commit | Line | Data |
---|---|---|
f852c398 | 1 | /* $Header$ |
2 | * | |
3 | * This generates zephyr acl files | |
4 | * | |
5 | * (c) Copyright 1990 by the Massachusetts Institute of Technology. | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
10 | #include <mit-copyright.h> | |
11 | #include <stdio.h> | |
12 | #include <moira.h> | |
13 | #include <moira_site.h> | |
14 | #include <sys/types.h> | |
15 | #include <sys/stat.h> | |
16 | #include <sys/time.h> | |
17 | EXEC SQL INCLUDE sqlca; | |
18 | ||
19 | extern int errno; | |
20 | char *whoami = "zephyr.gen"; | |
21 | ||
22 | char zephyr_dir[BUFSIZ]; | |
23 | ||
24 | ||
25 | main(argc, argv) | |
26 | int argc; | |
27 | char **argv; | |
28 | { | |
29 | struct stat sb; | |
30 | int changed; | |
31 | char cmd[256]; | |
32 | ||
33 | if (argc > 2) { | |
34 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
35 | exit(MR_ARGS); | |
36 | } | |
37 | ||
38 | sprintf(zephyr_dir, "%s/zephyr", DCM_DIR); | |
39 | ||
40 | #ifsql INGRES | |
9fd1c2b8 | 41 | EXEC SQL CONNECT moira; |
f852c398 | 42 | #endsql |
43 | #ifsql INFORMIX | |
9fd1c2b8 | 44 | EXEC SQL DATABASE moira; |
f852c398 | 45 | #endsql |
46 | ||
47 | changed = do_classes(); | |
48 | ||
49 | #ifsql INGRES | |
50 | EXEC SQL DISCONNECT; | |
51 | #endsql | |
52 | #ifsql INFORMIX | |
53 | EXEC SQL CLOSE DATABASE; | |
54 | #endsql | |
55 | ||
56 | if (!changed) { | |
57 | fprintf(stderr, "No files updated.\n"); | |
58 | if (argc == 2 && stat(argv[1], &sb) == 0) | |
59 | exit(MR_NO_CHANGE); | |
60 | } | |
61 | ||
62 | if (argc == 2) { | |
63 | fprintf(stderr, "Building tar file.\n"); | |
64 | sprintf(cmd, "cd %s; tar cf %s .", zephyr_dir, argv[1]); | |
65 | if (system(cmd)) | |
66 | exit(MR_TAR_FAIL); | |
67 | } | |
68 | ||
69 | exit(MR_SUCCESS); | |
70 | } | |
71 | ||
72 | ||
73 | struct zclass { | |
74 | char class[17]; | |
75 | char xtype[9]; | |
76 | char stype[9]; | |
77 | char wtype[9]; | |
78 | char utype[9]; | |
79 | int xid; | |
80 | int sid; | |
81 | int wid; | |
82 | int uid; | |
83 | struct zclass *next; | |
84 | }; | |
85 | ||
86 | ||
87 | int do_classes() | |
88 | { | |
89 | FILE *out; | |
90 | char outclass[256], buf[256]; | |
91 | struct zclass *top, *next, *zc; | |
92 | struct stat sb; | |
93 | int flag1, flag2; | |
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; | |
98 | ||
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)) | |
103 | exit(MR_DATE); | |
104 | if (flag1 < 0 && flag2 < 0) { | |
105 | fprintf(stderr, "Zephyr files do not need to be rebuilt.\n"); | |
106 | return(0); | |
107 | } | |
108 | } | |
109 | ||
110 | sprintf(buf, "%s~", outclass); | |
111 | out = fopen(buf, "w"); | |
112 | if (out == NULL) { | |
113 | perror("opening class-registry.acl"); | |
114 | exit(MR_OCONFIG); | |
115 | } | |
116 | top = (struct zclass *)malloc(sizeof(struct zclass)); | |
117 | next = top; | |
118 | ||
9fd1c2b8 | 119 | /* The following is declarative, not executed, |
120 | * and so is dependent on where it is in the file, | |
121 | * not in the order of execution of statements. | |
122 | */ | |
f852c398 | 123 | EXEC SQL WHENEVER SQLERROR GOTO sqlerr; |
124 | EXEC SQL DECLARE classes CURSOR FOR SELECT class, xmt_type, xmt_id, | |
125 | sub_type, sub_id, iws_type, iws_id, iui_type, iui_id | |
126 | FROM zephyr; | |
127 | EXEC SQL OPEN classes; | |
128 | while (1) { | |
129 | EXEC SQL FETCH classes INTO | |
130 | :zclass, :zxtype, :zxid, :zstype, :zsid, | |
131 | :zwtype, :zwid, :zutype, :zuid; | |
132 | if (sqlca.sqlcode != 0) break; | |
133 | zc = (struct zclass *)malloc(sizeof(struct zclass)); | |
134 | next->next = zc; | |
135 | next = zc; | |
136 | strcpy(zc->class, zclass); | |
137 | strcpy(zc->xtype, zxtype); | |
138 | strcpy(zc->stype, zstype); | |
139 | strcpy(zc->wtype, zwtype); | |
140 | strcpy(zc->utype, zutype); | |
141 | zc->xid = zxid; | |
142 | zc->sid = zsid; | |
143 | zc->wid = zwid; | |
144 | zc->uid = zuid; | |
145 | } | |
146 | if (sqlca.sqlcode != 100) { | |
147 | fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); | |
148 | exit(MR_INGRES_ERR); | |
149 | } | |
150 | EXEC SQL CLOSE classes; | |
151 | for (zc = top->next; zc; zc = zc->next) { | |
152 | fprintf(out, "%s:\n", strtrim(zc->class)); | |
153 | fprintf(stderr, "Working on %s\n", zc->class); | |
154 | if (!strcasecmp(strtrim(zc->xtype), "LIST")) { | |
155 | getlist(zc->xid, zc->class, "xmt"); | |
156 | } else if (!strcasecmp(zc->xtype, "KERBEROS")) { | |
157 | getstring(zc->xid, zc->class, "xmt"); | |
158 | } else if (!strcasecmp(zc->xtype, "USER")) { | |
159 | getuser(zc->xid, zc->class, "xmt"); | |
160 | } else if (!strcasecmp(zc->xtype, "NONE")) { | |
161 | getnone(zc->class, "xmt"); | |
162 | } | |
163 | if (!strcasecmp(strtrim(zc->stype), "LIST")) { | |
164 | getlist(zc->sid, zc->class, "sub"); | |
165 | } else if (!strcasecmp(zc->stype, "KERBEROS")) { | |
166 | getstring(zc->sid, zc->class, "sub"); | |
167 | } else if (!strcasecmp(zc->stype, "USER")) { | |
168 | getuser(zc->sid, zc->class, "sub"); | |
169 | } else if (!strcasecmp(zc->stype, "NONE")) { | |
170 | getnone(zc->class, "sub"); | |
171 | } | |
172 | if (!strcasecmp(strtrim(zc->wtype), "LIST")) { | |
173 | getlist(zc->wid, zc->class, "iws"); | |
174 | } else if (!strcasecmp(zc->wtype, "KERBEROS")) { | |
175 | getstring(zc->wid, zc->class, "iws"); | |
176 | } else if (!strcasecmp(zc->wtype, "USER")) { | |
177 | getuser(zc->wid, zc->class, "iws"); | |
178 | } else if (!strcasecmp(zc->wtype, "NONE")) { | |
179 | getnone(zc->class, "iws"); | |
180 | } | |
181 | if (!strcasecmp(strtrim(zc->utype), "LIST")) { | |
182 | getlist(zc->uid, zc->class, "iui"); | |
183 | } else if (!strcasecmp(zc->utype, "KERBEROS")) { | |
184 | getstring(zc->uid, zc->class, "iui"); | |
185 | } else if (!strcasecmp(zc->utype, "USER")) { | |
186 | getuser(zc->uid, zc->class, "iui"); | |
187 | } else if (!strcasecmp(zc->utype, "NONE")) { | |
188 | getnone(zc->class, "iui"); | |
189 | } | |
190 | } | |
191 | fclose(out); | |
192 | fix_file(outclass); | |
193 | return(1); | |
194 | sqlerr: | |
195 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
196 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
197 | sqlca.sqlcode); | |
198 | exit(MR_INGRES_ERR); | |
199 | } | |
200 | ||
201 | ||
202 | getlist(list_id, zclass, atype) | |
203 | int list_id; | |
204 | char *zclass; | |
205 | char *atype; | |
206 | { | |
207 | char ofile[256], buf[256]; | |
208 | FILE *out; | |
209 | EXEC SQL BEGIN DECLARE SECTION; | |
210 | char str[257]; | |
211 | int zid; | |
212 | EXEC SQL END DECLARE SECTION; | |
213 | ||
214 | zid = list_id; | |
215 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
216 | fprintf(buf, "%s~", ofile); | |
217 | out = fopen(buf, "w"); | |
218 | if (out == NULL) { | |
219 | perror("opening acl file"); | |
220 | exit(MR_OCONFIG); | |
221 | } | |
222 | ||
223 | EXEC SQL DECLARE umember CURSOR FOR SELECT users.login | |
224 | FROM users, imembers | |
9fd1c2b8 | 225 | WHERE imembers.list_id = :zid and imembers.member_type='USER' and |
f852c398 | 226 | imembers.member_id=users.users_id; |
227 | EXEC SQL OPEN umember; | |
228 | while (1) { | |
229 | EXEC SQL FETCH umember INTO :str; | |
230 | if (sqlca.sqlcode != 0) break; | |
231 | fprintf(out, "%s\n", strtrim(str)); | |
232 | } | |
233 | if (sqlca.sqlcode != 100) { | |
234 | fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); | |
235 | exit(MR_INGRES_ERR); | |
236 | } | |
237 | EXEC SQL CLOSE umember; | |
238 | ||
239 | EXEC SQL DECLARE smember CURSOR FOR SELECT strings.string | |
240 | FROM strings, imembers | |
241 | WHERE imembers.list_id = :zid and imembers.member_id=strings.string_id | |
9fd1c2b8 | 242 | and (imembers.member_type='STRING' or imembers.member_type='KERBEROS'); |
f852c398 | 243 | EXEC SQL OPEN smember; |
244 | while (1) { | |
245 | EXEC SQL FETCH smember INTO :str; | |
246 | if (sqlca.sqlcode != 0) break; | |
247 | fprintf(out, "%s\n", strtrim(str)); | |
248 | } | |
249 | if (sqlca.sqlcode != 100) { | |
250 | fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); | |
251 | exit(MR_INGRES_ERR); | |
252 | } | |
253 | EXEC SQL CLOSE smember; | |
254 | if (fclose(out)) { | |
255 | perror("closing acl file"); | |
256 | exit(MR_CCONFIG); | |
257 | } | |
258 | fix_file(ofile); | |
259 | return; | |
260 | sqlerr: | |
261 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
262 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
263 | sqlca.sqlcode); | |
264 | exit(MR_INGRES_ERR); | |
265 | } | |
266 | ||
267 | getstring(string_id, zclass, atype) | |
268 | int string_id; | |
269 | char *zclass; | |
270 | char *atype; | |
271 | { | |
272 | char ofile[256], buf[256]; | |
273 | FILE *out; | |
274 | EXEC SQL BEGIN DECLARE SECTION; | |
275 | char str[257]; | |
276 | int zid; | |
277 | EXEC SQL END DECLARE SECTION; | |
278 | ||
279 | zid = string_id; | |
280 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
281 | fprintf(buf, "%s~", ofile); | |
282 | out = fopen(buf, "w"); | |
283 | if (out == NULL) { | |
284 | perror("opening acl file"); | |
285 | exit(MR_OCONFIG); | |
286 | } | |
287 | ||
288 | EXEC SQL SELECT string INTO :str FROM strings WHERE string_id = :zid; | |
289 | if (sqlca.sqlcode != 0) { | |
290 | if (sqlca.sqlcode == 100) { | |
291 | fprintf(stderr, "String %d not found for class %s type %s\n", | |
292 | zid, zclass, atype); | |
293 | } else { | |
294 | fprintf(stderr, "SQL error %d\n", sqlca.sqlcode); | |
295 | exit(MR_INGRES_ERR); | |
296 | } | |
297 | } | |
298 | if (!strcmp(strtrim(str), "WILDCARD")) { | |
299 | strcpy(str, "*.*@*"); | |
300 | } | |
301 | fprintf(out, "%s\n", str); | |
302 | if (fclose(out)) { | |
303 | perror("closing acl file"); | |
304 | exit(MR_CCONFIG); | |
305 | } | |
306 | fix_file(ofile); | |
307 | return; | |
308 | sqlerr: | |
309 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
310 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
311 | sqlca.sqlcode); | |
312 | exit(MR_INGRES_ERR); | |
313 | } | |
314 | ||
315 | ||
316 | getuser(user_id, zclass, atype) | |
317 | int user_id; | |
318 | char *zclass; | |
319 | char *atype; | |
320 | { | |
321 | char ofile[256], buf[256]; | |
322 | FILE *out; | |
323 | EXEC SQL BEGIN DECLARE SECTION; | |
324 | char login[9]; | |
325 | int zid; | |
326 | EXEC SQL END DECLARE SECTION; | |
327 | ||
328 | zid = user_id; | |
329 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
330 | fprintf(buf, "%s~", ofile); | |
331 | out = fopen(buf, "w"); | |
332 | if (out == NULL) { | |
333 | perror("opening acl file"); | |
334 | exit(MR_OCONFIG); | |
335 | } | |
336 | ||
337 | EXEC SQL SELECT login INTO :login FROM users WHERE users_id = :zid; | |
338 | if (sqlca.sqlcode != 0) { | |
339 | if (sqlca.sqlcode == 100) { | |
340 | fprintf(stderr, "User %d not found\n", zid); | |
341 | } else { | |
342 | fprintf(stderr, "SQL error %d\n", sqlca.sqlcode); | |
343 | exit(MR_INGRES_ERR); | |
344 | } | |
345 | } | |
346 | fprintf(out, "%s\n", strtrim(login)); | |
347 | if (fclose(out)) { | |
348 | perror("closing acl file"); | |
349 | exit(MR_CCONFIG); | |
350 | } | |
351 | fix_file(ofile); | |
352 | return; | |
353 | sqlerr: | |
354 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
355 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
356 | sqlca.sqlcode); | |
357 | exit(MR_INGRES_ERR); | |
358 | } | |
359 | ||
360 | ||
361 | getnone(zclass, atype) | |
362 | char *zclass; | |
363 | char *atype; | |
364 | { | |
365 | char ofile[256]; | |
366 | ||
367 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
368 | unlink(ofile); | |
369 | } |