]>
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 | |
41 | EXEC SQL CONNECT sms; | |
42 | #endsql | |
43 | #ifsql INFORMIX | |
44 | EXEC SQL DATABASE sms; | |
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 | ||
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 | |
122 | FROM zephyr; | |
123 | EXEC SQL OPEN classes; | |
124 | while (1) { | |
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)); | |
130 | next->next = zc; | |
131 | next = zc; | |
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); | |
137 | zc->xid = zxid; | |
138 | zc->sid = zsid; | |
139 | zc->wid = zwid; | |
140 | zc->uid = zuid; | |
141 | } | |
142 | if (sqlca.sqlcode != 100) { | |
143 | fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); | |
144 | exit(MR_INGRES_ERR); | |
145 | } | |
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"); | |
158 | } | |
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"); | |
167 | } | |
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"); | |
176 | } | |
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"); | |
185 | } | |
186 | } | |
187 | fclose(out); | |
188 | fix_file(outclass); | |
189 | return(1); | |
190 | sqlerr: | |
191 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
192 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
193 | sqlca.sqlcode); | |
194 | exit(MR_INGRES_ERR); | |
195 | } | |
196 | ||
197 | ||
198 | getlist(list_id, zclass, atype) | |
199 | int list_id; | |
200 | char *zclass; | |
201 | char *atype; | |
202 | { | |
203 | char ofile[256], buf[256]; | |
204 | FILE *out; | |
205 | EXEC SQL BEGIN DECLARE SECTION; | |
206 | char str[257]; | |
207 | int zid; | |
208 | EXEC SQL END DECLARE SECTION; | |
209 | ||
210 | zid = list_id; | |
211 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
212 | fprintf(buf, "%s~", ofile); | |
213 | out = fopen(buf, "w"); | |
214 | if (out == NULL) { | |
215 | perror("opening acl file"); | |
216 | exit(MR_OCONFIG); | |
217 | } | |
218 | ||
219 | EXEC SQL DECLARE umember CURSOR FOR SELECT users.login | |
220 | FROM users, imembers | |
221 | WHERE imembers.list_id = :zid and imembers.member_type="USER" and | |
222 | imembers.member_id=users.users_id; | |
223 | EXEC SQL OPEN umember; | |
224 | while (1) { | |
225 | EXEC SQL FETCH umember INTO :str; | |
226 | if (sqlca.sqlcode != 0) break; | |
227 | fprintf(out, "%s\n", strtrim(str)); | |
228 | } | |
229 | if (sqlca.sqlcode != 100) { | |
230 | fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); | |
231 | exit(MR_INGRES_ERR); | |
232 | } | |
233 | EXEC SQL CLOSE umember; | |
234 | ||
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; | |
240 | while (1) { | |
241 | EXEC SQL FETCH smember INTO :str; | |
242 | if (sqlca.sqlcode != 0) break; | |
243 | fprintf(out, "%s\n", strtrim(str)); | |
244 | } | |
245 | if (sqlca.sqlcode != 100) { | |
246 | fprintf(stderr, "DBMS error %d\n", sqlca.sqlcode); | |
247 | exit(MR_INGRES_ERR); | |
248 | } | |
249 | EXEC SQL CLOSE smember; | |
250 | if (fclose(out)) { | |
251 | perror("closing acl file"); | |
252 | exit(MR_CCONFIG); | |
253 | } | |
254 | fix_file(ofile); | |
255 | return; | |
256 | sqlerr: | |
257 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
258 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
259 | sqlca.sqlcode); | |
260 | exit(MR_INGRES_ERR); | |
261 | } | |
262 | ||
263 | getstring(string_id, zclass, atype) | |
264 | int string_id; | |
265 | char *zclass; | |
266 | char *atype; | |
267 | { | |
268 | char ofile[256], buf[256]; | |
269 | FILE *out; | |
270 | EXEC SQL BEGIN DECLARE SECTION; | |
271 | char str[257]; | |
272 | int zid; | |
273 | EXEC SQL END DECLARE SECTION; | |
274 | ||
275 | zid = string_id; | |
276 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
277 | fprintf(buf, "%s~", ofile); | |
278 | out = fopen(buf, "w"); | |
279 | if (out == NULL) { | |
280 | perror("opening acl file"); | |
281 | exit(MR_OCONFIG); | |
282 | } | |
283 | ||
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", | |
288 | zid, zclass, atype); | |
289 | } else { | |
290 | fprintf(stderr, "SQL error %d\n", sqlca.sqlcode); | |
291 | exit(MR_INGRES_ERR); | |
292 | } | |
293 | } | |
294 | if (!strcmp(strtrim(str), "WILDCARD")) { | |
295 | strcpy(str, "*.*@*"); | |
296 | } | |
297 | fprintf(out, "%s\n", str); | |
298 | if (fclose(out)) { | |
299 | perror("closing acl file"); | |
300 | exit(MR_CCONFIG); | |
301 | } | |
302 | fix_file(ofile); | |
303 | return; | |
304 | sqlerr: | |
305 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
306 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
307 | sqlca.sqlcode); | |
308 | exit(MR_INGRES_ERR); | |
309 | } | |
310 | ||
311 | ||
312 | getuser(user_id, zclass, atype) | |
313 | int user_id; | |
314 | char *zclass; | |
315 | char *atype; | |
316 | { | |
317 | char ofile[256], buf[256]; | |
318 | FILE *out; | |
319 | EXEC SQL BEGIN DECLARE SECTION; | |
320 | char login[9]; | |
321 | int zid; | |
322 | EXEC SQL END DECLARE SECTION; | |
323 | ||
324 | zid = user_id; | |
325 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
326 | fprintf(buf, "%s~", ofile); | |
327 | out = fopen(buf, "w"); | |
328 | if (out == NULL) { | |
329 | perror("opening acl file"); | |
330 | exit(MR_OCONFIG); | |
331 | } | |
332 | ||
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); | |
337 | } else { | |
338 | fprintf(stderr, "SQL error %d\n", sqlca.sqlcode); | |
339 | exit(MR_INGRES_ERR); | |
340 | } | |
341 | } | |
342 | fprintf(out, "%s\n", strtrim(login)); | |
343 | if (fclose(out)) { | |
344 | perror("closing acl file"); | |
345 | exit(MR_CCONFIG); | |
346 | } | |
347 | fix_file(ofile); | |
348 | return; | |
349 | sqlerr: | |
350 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
351 | critical_alert("DCM", "Zephyr build encountered DATABASE ERROR %d", | |
352 | sqlca.sqlcode); | |
353 | exit(MR_INGRES_ERR); | |
354 | } | |
355 | ||
356 | ||
357 | getnone(zclass, atype) | |
358 | char *zclass; | |
359 | char *atype; | |
360 | { | |
361 | char ofile[256]; | |
362 | ||
363 | sprintf(ofile, "%s/%s-%s.acl", zephyr_dir, atype, zclass); | |
364 | unlink(ofile); | |
365 | } |