]>
Commit | Line | Data |
---|---|---|
1 | /* $Header$ | |
2 | * | |
3 | * This generates the zone files necessary to load a hesiod server. | |
4 | * The following zones are generated: passwd, uid, pobox, group, | |
5 | * grplist, gid, filsys, cluster, pcap, sloc, service. | |
6 | * | |
7 | * (c) Copyright 1988 by the Massachusetts Institute of Technology. | |
8 | * For copying and distribution information, please see the file | |
9 | * <mit-copyright.h>. | |
10 | */ | |
11 | ||
12 | #include <mit-copyright.h> | |
13 | #include <stdio.h> | |
14 | #include <sms.h> | |
15 | #include <sms_app.h> | |
16 | #include <sys/types.h> | |
17 | #include <sys/stat.h> | |
18 | #include <sys/time.h> | |
19 | #include <ctype.h> | |
20 | ||
21 | ||
22 | #define HESIOD_DIR "/u1/sms/dcm/hesiod" | |
23 | ||
24 | #define min(x,y) ((x) < (y) ? (x) : (y)) | |
25 | struct hash *machines = NULL; | |
26 | struct hash *users = NULL; | |
27 | char *whoami = "hesiod.gen"; | |
28 | ||
29 | struct grp { | |
30 | struct grp *next; | |
31 | int id; | |
32 | }; | |
33 | struct user { | |
34 | char name[9]; | |
35 | struct grp *lists; | |
36 | }; | |
37 | ||
38 | char *malloc(), *strsave(); | |
39 | char *ingres_date_and_time(), *ingres_time(), *ingres_date(); | |
40 | ||
41 | main(argc, argv) | |
42 | int argc; | |
43 | char **argv; | |
44 | { | |
45 | char cmd[64]; | |
46 | struct stat sb; | |
47 | int changed = 0; | |
48 | int ingerr(); | |
49 | ||
50 | if (argc > 2) { | |
51 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
52 | exit(SMS_ARGS); | |
53 | } | |
54 | ||
55 | IIseterr(ingerr); | |
56 | ||
57 | ## ingres sms | |
58 | ||
59 | changed = do_passwd(); | |
60 | changed += do_pobox(); | |
61 | changed += do_filsys(); | |
62 | changed += do_cluster(); | |
63 | changed += do_printers(); | |
64 | changed += do_sloc(); | |
65 | changed += do_service(); | |
66 | changed += do_groups(); | |
67 | ||
68 | ## exit | |
69 | ||
70 | if (!changed) { | |
71 | fprintf(stderr, "No files updated.\n"); | |
72 | if (argc == 2 && stat(argv[1], &sb) == 0) | |
73 | exit(SMS_NO_CHANGE); | |
74 | } | |
75 | ||
76 | if (argc == 2) { | |
77 | fprintf(stderr, "Building tar file.\n"); | |
78 | sprintf(cmd, "cd %s; tar cf %s .", HESIOD_DIR, argv[1]); | |
79 | if (system(cmd)) | |
80 | exit(SMS_TAR_FAIL); | |
81 | } | |
82 | ||
83 | exit(SMS_SUCCESS); | |
84 | } | |
85 | ||
86 | ||
87 | /* | |
88 | * ingerr: (supposedly) called when Ingres indicates an error. | |
89 | * I have not yet been able to get this to work to intercept a | |
90 | * database open error. | |
91 | */ | |
92 | #define INGRES_DEADLOCK 4700 | |
93 | ||
94 | static int ingerr(num) | |
95 | int *num; | |
96 | { | |
97 | char buf[256]; | |
98 | int ingres_errno; | |
99 | ||
100 | switch (*num) { | |
101 | case INGRES_DEADLOCK: | |
102 | ingres_errno = SMS_DEADLOCK; | |
103 | break; | |
104 | default: | |
105 | ingres_errno = SMS_INGRES_ERR; | |
106 | } | |
107 | com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num); | |
108 | critical_alert("DCM", "Hesiod build encountered INGRES ERROR %d", *num); | |
109 | exit(ingres_errno); | |
110 | } | |
111 | ||
112 | ||
113 | get_mach() | |
114 | ##{ | |
115 | ## int id; | |
116 | ## char name[33]; | |
117 | ||
118 | if (machines) | |
119 | return; | |
120 | ||
121 | machines = create_hash(1000); | |
122 | ## retrieve (name = machine.#name, id = machine.mach_id) { | |
123 | hash_store(machines, id, strsave(strtrim(name))); | |
124 | ## } | |
125 | ##} | |
126 | ||
127 | ||
128 | do_passwd() | |
129 | ##{ | |
130 | FILE *pout, *uout; | |
131 | char poutf[64], uoutf[64], poutft[64], uoutft[64]; | |
132 | struct stat psb, usb; | |
133 | time_t ftime; | |
134 | struct user *u; | |
135 | ## char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime; | |
136 | ## char nn[17]; | |
137 | ## int uid, flag, id; | |
138 | ||
139 | sprintf(poutf, "%s/passwd.db", HESIOD_DIR); | |
140 | sprintf(uoutf, "%s/uid.db", HESIOD_DIR); | |
141 | ||
142 | if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0) { | |
143 | ftime = min(psb.st_mtime, usb.st_mtime); | |
144 | filetime = ingres_date_and_time(ftime); | |
145 | ## retrieve (flag = int4(interval("min", tblstats.modtime - filetime))) | |
146 | ## where tblstats.table = "users" | |
147 | if (flag < 0) { | |
148 | fprintf(stderr, "Files passwd.db and uid.db do not need to be rebuilt.\n"); | |
149 | return(0); | |
150 | } | |
151 | } | |
152 | ||
153 | sprintf(poutft, "%s~", poutf); | |
154 | pout = fopen(poutft, "w"); | |
155 | if (!pout) { | |
156 | perror("cannot open passwd.db~ for write"); | |
157 | exit(SMS_OCONFIG); | |
158 | } | |
159 | sprintf(uoutft, "%s~", uoutf); | |
160 | uout = fopen(uoutft, "w"); | |
161 | if (!uout) { | |
162 | perror("cannot open uid.db~ for write"); | |
163 | exit(SMS_OCONFIG); | |
164 | } | |
165 | ||
166 | fprintf(stderr, "Building passwd.db and uid.db\n"); | |
167 | ||
168 | users = create_hash(10000); | |
169 | ## range of u is users | |
170 | ## retrieve (login = u.#login, uid = u.#uid, shell = u.#shell, | |
171 | ## fullname = u.#fullname, nn = u.nickname, oa = u.office_addr, | |
172 | ## op = u.office_phone, hp = u.home_phone, id = u.users_id) | |
173 | ## where u.status = 1 { | |
174 | strtrim(login); | |
175 | dequote(fullname); | |
176 | dequote(nn); | |
177 | dequote(oa); | |
178 | dequote(op); | |
179 | dequote(hp); | |
180 | dequote(shell); | |
181 | u = (struct user *) malloc(sizeof(struct user)); | |
182 | strcpy(u->name, login); | |
183 | u->lists = NULL; | |
184 | hash_store(users, id, u); | |
185 | fprintf(pout, "%s.passwd\tHS UNSPECA \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n", | |
186 | login, login, uid, fullname, nn, oa, op, hp, login, shell); | |
187 | fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login); | |
188 | ## } | |
189 | ||
190 | if (fclose(pout) || fclose(uout)) { | |
191 | fprintf(stderr, "Unsuccessful file close of passwd.db or uid.db\n"); | |
192 | exit(SMS_CCONFIG); | |
193 | } | |
194 | fix_file(poutf); | |
195 | fix_file(uoutf); | |
196 | return(1); | |
197 | ##} | |
198 | ||
199 | ||
200 | do_pobox() | |
201 | ##{ | |
202 | FILE *out; | |
203 | char outf[64], outft[64], *mach; | |
204 | struct stat sb; | |
205 | time_t ftime; | |
206 | ## char login[9], *filetime; | |
207 | ## int flag1, flag2, id; | |
208 | ||
209 | sprintf(outf, "%s/pobox.db", HESIOD_DIR); | |
210 | ||
211 | if (stat(outf, &sb) == 0) { | |
212 | ftime = sb.st_mtime; | |
213 | filetime = ingres_date_and_time(ftime); | |
214 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
215 | ## where tblstats.table = "users" | |
216 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
217 | ## where tblstats.table = "machine" | |
218 | if (flag1 < 0 && flag2 < 0) { | |
219 | fprintf(stderr,"File pobox.db does not need to be rebuilt.\n"); | |
220 | return(0); | |
221 | } | |
222 | } | |
223 | ||
224 | sprintf(outft, "%s~", outf); | |
225 | out = fopen(outft, "w"); | |
226 | if (!out) { | |
227 | perror("cannot open pobox.db for write"); | |
228 | exit(SMS_OCONFIG); | |
229 | } | |
230 | ||
231 | fprintf(stderr, "Building pobox.db\n"); | |
232 | get_mach(); | |
233 | ||
234 | ## range of u is users | |
235 | ## retrieve (login = u.#login, id = u.pop_id) | |
236 | ## where u.status = 1 and u.potype = "POP" { | |
237 | strtrim(login); | |
238 | if (mach = hash_lookup(machines, id)) | |
239 | fprintf(out, "%s.pobox\tHS UNSPECA \"POP %s %s\"\n", | |
240 | login, mach, login); | |
241 | ## } | |
242 | ||
243 | if (fclose(out)) { | |
244 | fprintf(stderr, "Unsuccessful close of pobox.db\n"); | |
245 | exit(SMS_CCONFIG); | |
246 | } | |
247 | fix_file(outf); | |
248 | return(1); | |
249 | ##} | |
250 | ||
251 | ||
252 | /************************************************************************ | |
253 | * WARNING: this routine mallocs a large amount of memory which it never frees. | |
254 | * This is considered OK only because main has been arranged to call this | |
255 | * last, so the process will exit shortly after we return. | |
256 | */ | |
257 | ||
258 | do_groups() | |
259 | ##{ | |
260 | FILE *iout, *gout, *lout; | |
261 | char ioutf[64], goutf[64], loutf[64], buf[512], *l; | |
262 | struct hash *groups; | |
263 | register struct bucket *b, **p; | |
264 | struct grp *g; | |
265 | struct user *u; | |
266 | struct stat isb, gsb, lsb; | |
267 | time_t ftime; | |
268 | register struct save_queue *sq; | |
269 | struct save_queue *sq_create(); | |
270 | register int i; | |
271 | ## char name[33], *filetime; | |
272 | ## int gid, id, lid, flag1, flag2, flag3, maxid; | |
273 | ||
274 | /* open files */ | |
275 | sprintf(ioutf, "%s/gid.db", HESIOD_DIR); | |
276 | sprintf(goutf, "%s/group.db", HESIOD_DIR); | |
277 | sprintf(loutf, "%s/grplist.db", HESIOD_DIR); | |
278 | ||
279 | if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) { | |
280 | ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime)); | |
281 | filetime = ingres_date_and_time(ftime); | |
282 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
283 | ## where tblstats.table = "users" | |
284 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
285 | ## where tblstats.table = "list" | |
286 | ## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime))) | |
287 | ## where tblstats.table = "members" | |
288 | if (flag1 < 0 && flag2 < 0 && flag3 < 0) { | |
289 | fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n"); | |
290 | return(0); | |
291 | } | |
292 | } | |
293 | ||
294 | sprintf(buf, "%s~", ioutf); | |
295 | iout = fopen(buf, "w"); | |
296 | if (!iout) { | |
297 | perror("cannot open gid.db for write"); | |
298 | exit(SMS_OCONFIG); | |
299 | } | |
300 | sprintf(buf, "%s~", goutf); | |
301 | gout = fopen(buf, "w"); | |
302 | if (!gout) { | |
303 | perror("cannot open group.db for write"); | |
304 | exit(SMS_OCONFIG); | |
305 | } | |
306 | sprintf(buf, "%s~", loutf); | |
307 | lout = fopen(buf, "w"); | |
308 | if (!lout) { | |
309 | perror("cannot open grplist.db for write"); | |
310 | exit(SMS_OCONFIG); | |
311 | } | |
312 | ||
313 | fprintf(stderr, "Building gid.db, group.db, and grplist.db\n"); | |
314 | ||
315 | /* make space for group list */ | |
316 | groups = create_hash(15000); | |
317 | ||
318 | /* retrieve simple groups */ | |
319 | ## range of l is list | |
320 | ## begin transaction | |
321 | ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) | |
322 | ## where l.group != 0 and l.active != 0 { | |
323 | strtrim(name); | |
324 | sprintf(buf, "%s:%d", name, gid); | |
325 | hash_store(groups, lid, strsave(buf)); | |
326 | fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name); | |
327 | fprintf(gout, "%s.group\tHS UNSPECA \"%s:*:%d:\"\n", | |
328 | name, name, gid); | |
329 | ## } | |
330 | ||
331 | fflush(iout); | |
332 | fflush(gout); | |
333 | ||
334 | /* get special cases: lists that aren't groups themselves but are | |
335 | * members of groups. */ | |
336 | sq = sq_create(); | |
337 | ## range of m is members | |
338 | ## retrieve (name = list.#name, gid = list.#gid, lid = l.list_id) | |
339 | ## where l.active != 0 and list.active != 0 and m.member_type = "LIST" and | |
340 | ## m.member_id = l.list_id and m.list_id = list.list_id and | |
341 | ## list.group != 0 { | |
342 | strtrim(name); | |
343 | if (l = hash_lookup(groups, lid)) { | |
344 | sprintf(buf, "%s:%s:%d", l, name, gid); | |
345 | free(l); | |
346 | } else { | |
347 | sprintf(buf, "%s:%d", name, gid); | |
348 | } | |
349 | hash_store(groups, lid, strsave(buf)); | |
350 | sq_save_unique_data(sq, lid); | |
351 | ## } | |
352 | ||
353 | while (sq_get_data(sq, &id)) { | |
354 | ## repeat retrieve (lid = l.list_id) where m.member_type = "LIST" and | |
355 | ## m.list_id = @id and m.member_id = l.list_id and l.active != 0 { | |
356 | if (l = hash_lookup(groups, lid)) { | |
357 | sprintf(buf, "%s:%s", l, hash_lookup(groups, id)); | |
358 | free(l); | |
359 | l = strsave(buf); | |
360 | } else { | |
361 | l = hash_lookup(groups, id); | |
362 | } | |
363 | hash_store(groups, lid, l); | |
364 | sq_save_unique_data(sq, lid); | |
365 | ## } | |
366 | } | |
367 | sq_destroy(sq); | |
368 | ||
369 | /* now do grplists */ | |
370 | if (users == NULL) { | |
371 | users = create_hash(10000); | |
372 | ## range of u is users | |
373 | ## retrieve (id = u.users_id, name = u.login) where u.status = 1 { | |
374 | u = (struct user *) malloc(sizeof(struct user)); | |
375 | strcpy(u->name, strtrim(name)); | |
376 | u->lists = NULL; | |
377 | hash_store(users, id, u); | |
378 | ## } | |
379 | } | |
380 | ||
381 | ## repeat retrieve (lid = m.list_id, id = m.member_id) | |
382 | ## where m.member_type = "USER" { | |
383 | if ((u = (struct user *) hash_lookup(users, id)) && | |
384 | (hash_lookup(groups, lid) != NULL)) { | |
385 | g = (struct grp *) malloc(sizeof(struct grp)); | |
386 | g->next = u->lists; | |
387 | u->lists = g; | |
388 | g->id = lid; | |
389 | } | |
390 | ## } | |
391 | ## end transaction | |
392 | ||
393 | for (p = &(users->data[users->size - 1]); p >= users->data; p--) { | |
394 | for (b = *p; b; b = b->next) { | |
395 | i = 0; | |
396 | sprintf(buf, "%s.grplist\tHS UNSPECA \"", | |
397 | ((struct user *)b->data)->name); | |
398 | for (g = ((struct user *)b->data)->lists; g; g = g->next) | |
399 | if (l = hash_lookup(groups, g->id)) { | |
400 | i++; | |
401 | strcat(buf, l); | |
402 | if (g->next) | |
403 | strcat(buf, ":"); | |
404 | } | |
405 | strcat(buf, "\"\n"); | |
406 | /* Do duplicate detection here */ | |
407 | if (i > 1) { | |
408 | remove_duplicate_groups(buf); | |
409 | } | |
410 | fputs(buf, lout); | |
411 | } | |
412 | } | |
413 | ||
414 | #ifdef notdef | |
415 | /* This is commented out because it takes on the order of 30 minutes to | |
416 | * run. Instead, we never free the memory, but the program will exit | |
417 | * shortly anyway. | |
418 | */ | |
419 | sq_destroy(sq); | |
420 | { | |
421 | register char **p; | |
422 | for (p = &groups[maxid-1]; p >= groups; p--) | |
423 | if (*p) | |
424 | free(*p); | |
425 | } | |
426 | free(groups); | |
427 | #endif | |
428 | ||
429 | if (fclose(iout) || fclose(gout) || fclose(lout)) { | |
430 | fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n"); | |
431 | exit(SMS_CCONFIG); | |
432 | } | |
433 | fix_file(ioutf); | |
434 | fix_file(goutf); | |
435 | fix_file(loutf); | |
436 | return(1); | |
437 | ##} | |
438 | ||
439 | ||
440 | #define MAXGROUPS 256 | |
441 | ||
442 | remove_duplicate_groups(p) | |
443 | register char *p; | |
444 | { | |
445 | register char *pp; | |
446 | char *index(); | |
447 | register int *mp; | |
448 | int memory[MAXGROUPS], i, *mg = &memory[MAXGROUPS-1]; | |
449 | ||
450 | bzero(memory, MAXGROUPS * sizeof(int)); | |
451 | while (p = index(p, ':')) { | |
452 | i = atoi(++p); | |
453 | for (mp = memory; *mp && mp < mg; mp++) | |
454 | if (*mp == i) { | |
455 | if (p = index(p, ':')) | |
456 | strcpy(pp, ++p); | |
457 | else { | |
458 | strcpy(--pp, "\"\n"); | |
459 | } | |
460 | p = pp; | |
461 | break; | |
462 | } | |
463 | if (*mp == i) | |
464 | continue; | |
465 | *mp = i; | |
466 | if (!(p = index(p, ':'))) | |
467 | return; | |
468 | pp = ++p; | |
469 | } | |
470 | } | |
471 | ||
472 | ||
473 | do_filsys() | |
474 | ##{ | |
475 | FILE *out; | |
476 | char outf[64], outft[64], *mach, machbuf[128]; | |
477 | register char *p; | |
478 | struct stat sb; | |
479 | time_t ftime; | |
480 | ## char name[33], type[9], loc[33], access[2], mount[33], trans[257]; | |
481 | ## char *filetime, comments[65]; | |
482 | ## int flag1, flag2, flag3, id; | |
483 | ||
484 | sprintf(outf, "%s/filsys.db", HESIOD_DIR); | |
485 | ||
486 | if (stat(outf, &sb) == 0) { | |
487 | ftime = sb.st_mtime; | |
488 | filetime = ingres_date_and_time(ftime); | |
489 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
490 | ## where tblstats.table = "filesys" | |
491 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
492 | ## where tblstats.table = "machine" | |
493 | ## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime))) | |
494 | ## where tblstats.table = "alias" | |
495 | if (flag1 < 0 && flag2 < 0 && flag3 < 0) { | |
496 | fprintf(stderr, "File filsys.db does not need to be rebuilt.\n"); | |
497 | return(0); | |
498 | } | |
499 | } | |
500 | ||
501 | sprintf(outft, "%s~", outf); | |
502 | out = fopen(outft, "w"); | |
503 | if (!out) { | |
504 | perror("cannot open filsys.db for write"); | |
505 | exit(SMS_OCONFIG); | |
506 | } | |
507 | ||
508 | fprintf(stderr, "Building filsys.db\n"); | |
509 | get_mach(); | |
510 | ||
511 | ## range of f is filesys | |
512 | ## retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id, | |
513 | ## access = f.#access, mount = f.#mount, comments = f.#comments) { | |
514 | strtrim(name); | |
515 | strtrim(type); | |
516 | if (strcmp(type, "ERR")) { | |
517 | strtrim(loc); | |
518 | strtrim(access); | |
519 | strtrim(mount); | |
520 | if (mach = hash_lookup(machines, id)) { | |
521 | for (p = machbuf; *mach && *mach != '.'; mach++) { | |
522 | if (isupper(*mach)) | |
523 | *p++ = tolower(*mach); | |
524 | else | |
525 | *p++ = *mach; | |
526 | *p = 0; | |
527 | } | |
528 | fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n", | |
529 | name, type, loc, machbuf, access, mount); | |
530 | } | |
531 | } else { | |
532 | strtrim(comments); | |
533 | fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n", | |
534 | name, comments); | |
535 | } | |
536 | ## } | |
537 | ||
538 | ||
539 | ||
540 | ## range of a is alias | |
541 | ## retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" { | |
542 | strtrim(name); | |
543 | strtrim(trans); | |
544 | fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n", name, trans); | |
545 | ## } | |
546 | ||
547 | if (fclose(out)) { | |
548 | fprintf(stderr, "Unsuccessful close of filsys.db\n"); | |
549 | exit(SMS_CCONFIG); | |
550 | } | |
551 | fix_file(outf); | |
552 | return(1); | |
553 | ##} | |
554 | ||
555 | ||
556 | /* | |
557 | * Modified from sys/types.h: | |
558 | */ | |
559 | int setsize; /* = howmany(setbits, NSETBITS) */ | |
560 | ||
561 | typedef long set_mask; | |
562 | #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */ | |
563 | #ifndef howmany | |
564 | #define howmany(x, y) (((x)+((y)-1))/(y)) | |
565 | #endif | |
566 | ||
567 | #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS))) | |
568 | #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS))) | |
569 | #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS))) | |
570 | #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask))) | |
571 | #define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask)) | |
572 | #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask))) | |
573 | ||
574 | ||
575 | do_cluster() | |
576 | ##{ | |
577 | FILE *out; | |
578 | char outf[64], outft[64], *mach, machbuf[33], *p; | |
579 | struct stat sb; | |
580 | time_t ftime; | |
581 | ## int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id; | |
582 | ## char name[33], label[17], data[33], *filetime; | |
583 | set_mask **machs, *ms, *ps; | |
584 | ||
585 | sprintf(outf, "%s/cluster.db", HESIOD_DIR); | |
586 | ||
587 | if (stat(outf, &sb) == 0) { | |
588 | ftime = sb.st_mtime; | |
589 | filetime = ingres_date_and_time(ftime); | |
590 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
591 | ## where tblstats.table = "cluster" | |
592 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
593 | ## where tblstats.table = "machine" | |
594 | ## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime))) | |
595 | ## where tblstats.table = "mcmap" | |
596 | ## retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime))) | |
597 | ## where tblstats.table = "svc" | |
598 | if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) { | |
599 | fprintf(stderr, "File cluster.db does not need to be rebuilt.\n"); | |
600 | return(0); | |
601 | } | |
602 | } | |
603 | ||
604 | sprintf(outft, "%s~", outf); | |
605 | out = fopen(outft, "w"); | |
606 | if (!out) { | |
607 | perror("cannot open cluster.db for write"); | |
608 | exit(SMS_OCONFIG); | |
609 | } | |
610 | ||
611 | fprintf(stderr, "Building cluster.db\n"); | |
612 | get_mach(); | |
613 | ||
614 | ## range of c is cluster | |
615 | ## begin transaction | |
616 | ## retrieve (maxclu = max(c.clu_id)) | |
617 | maxclu++; | |
618 | setsize = howmany(maxclu, NSETBITS); | |
619 | ## range of m is machine | |
620 | ## retrieve (maxmach = max(m.mach_id)) | |
621 | maxmach++; | |
622 | machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **)); | |
623 | bzero(machs, (maxmach + 1) * sizeof(int)); | |
624 | ||
625 | ## range of p is mcmap | |
626 | ## retrieve (mid = p.mach_id, cid = p.clu_id) { | |
627 | if (!(ms = machs[mid])) { | |
628 | ms = machs[mid] = SET_CREATE(); | |
629 | SET_ZERO(ms); | |
630 | } | |
631 | SET_SET(cid, ms); | |
632 | ## } | |
633 | ||
634 | ## range of d is svc | |
635 | for (mid = 1; mid < maxmach; mid++) { | |
636 | if (!machs[mid]) | |
637 | continue; | |
638 | ms = machs[mid]; | |
639 | for (cid = 1; cid < maxclu; cid++) { | |
640 | if (SET_ISSET(cid, ms)) { | |
641 | ## repeat retrieve (label = d.serv_label, data = d.serv_cluster) | |
642 | ## where d.clu_id = @cid { | |
643 | strtrim(label); | |
644 | strtrim(data); | |
645 | fprintf(out, | |
646 | "smsinternal-%d.cluster\tHS UNSPECA \"%s %s\"\n", | |
647 | mid, label, data); | |
648 | ## } | |
649 | } | |
650 | } | |
651 | ||
652 | if (mach = hash_lookup(machines, mid)) { | |
653 | for (p = machbuf; *mach && *mach != '.'; mach++) | |
654 | *p++ = *mach; | |
655 | *p = 0; | |
656 | fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n", | |
657 | machbuf, mid); | |
658 | } | |
659 | for (id = mid + 1; id < maxmach; id++) { | |
660 | if ((ps = machs[id]) && !SET_CMP(ms, ps)) { | |
661 | free(ps); | |
662 | machs[id] = NULL; | |
663 | if (mach = hash_lookup(machines, id)) { | |
664 | for (p = machbuf; *mach && *mach != '.'; mach++) | |
665 | *p++ = *mach; | |
666 | *p = 0; | |
667 | fprintf(out,"%s.cluster\tHS CNAME smsinternal-%d.cluster\n", | |
668 | machbuf, mid); | |
669 | } | |
670 | } | |
671 | } | |
672 | free(ms); | |
673 | machs[mid] = NULL; | |
674 | } | |
675 | ||
676 | ## retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster) | |
677 | ## where c.clu_id = d.clu_id { | |
678 | strtrim(name); | |
679 | strtrim(label); | |
680 | strtrim(data); | |
681 | fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n", | |
682 | name, label, data); | |
683 | ## } | |
684 | ## end transaction | |
685 | free(machs); | |
686 | ||
687 | if (fclose(out)) { | |
688 | fprintf(stderr, "Unsuccessful close of cluster.db\n"); | |
689 | exit(SMS_CCONFIG); | |
690 | } | |
691 | fix_file(outf); | |
692 | return(1); | |
693 | ##} | |
694 | ||
695 | ||
696 | do_printers() | |
697 | ##{ | |
698 | FILE *out; | |
699 | char outf[64], outft[64]; | |
700 | struct stat sb; | |
701 | time_t ftime; | |
702 | ## char name[17], rp[17], sd[33], rm[33], *filetime; | |
703 | ## int flag; | |
704 | ||
705 | sprintf(outf, "%s/printcap.db", HESIOD_DIR); | |
706 | ||
707 | if (stat(outf, &sb) == 0) { | |
708 | ftime = sb.st_mtime; | |
709 | filetime = ingres_date_and_time(ftime); | |
710 | ## retrieve (flag = int4(interval("min", tblstats.modtime - filetime))) | |
711 | ## where tblstats.table = "printcap" | |
712 | if (flag < 0) { | |
713 | fprintf(stderr, "File printcap.db does not need to be rebuilt.\n"); | |
714 | return(0); | |
715 | } | |
716 | } | |
717 | ||
718 | sprintf(outft, "%s~", outf); | |
719 | out = fopen(outft, "w"); | |
720 | if (!out) { | |
721 | perror("cannot open printcap.db for write"); | |
722 | exit(SMS_OCONFIG); | |
723 | } | |
724 | ||
725 | fprintf(stderr, "Building printcap.db\n"); | |
726 | ||
727 | ## range of p is printcap | |
728 | ## retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name) | |
729 | ## where machine.mach_id = p.mach_id { | |
730 | strtrim(name); | |
731 | strtrim(rp); | |
732 | strtrim(sd); | |
733 | strtrim(rm); | |
734 | fprintf(out, "%s.pcap\tHS UNSPECA \"%s:rp=%s:rm=%s:sd=%s\"\n", | |
735 | name, name, rp, rm, sd); | |
736 | ## } | |
737 | ||
738 | if (fclose(out)) { | |
739 | fprintf(stderr, "Unsuccessful close of pcap.db\n"); | |
740 | exit(SMS_CCONFIG); | |
741 | } | |
742 | fix_file(outf); | |
743 | return(1); | |
744 | ##} | |
745 | ||
746 | ||
747 | do_sloc() | |
748 | ##{ | |
749 | FILE *out, *old, *new; | |
750 | char outf[64], outft[64], *mach; | |
751 | struct stat sb; | |
752 | time_t ftime; | |
753 | register int c; | |
754 | ## char service[17], *filetime; | |
755 | ## int port, flag1, flag2, id; | |
756 | ||
757 | sprintf(outf, "%s/sloc.db", HESIOD_DIR); | |
758 | ||
759 | if (stat(outf, &sb) == 0) { | |
760 | ftime = sb.st_mtime; | |
761 | filetime = ingres_date_and_time(ftime); | |
762 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
763 | ## where tblstats.table = "serverhosts" | |
764 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
765 | ## where tblstats.table = "machine" | |
766 | if (flag1 < 0 && flag2 < 0) { | |
767 | fprintf(stderr, "File sloc.db does not need to be rebuilt.\n"); | |
768 | return(0); | |
769 | } | |
770 | } | |
771 | ||
772 | sprintf(outft, "%s~", outf); | |
773 | out = fopen(outft, "w"); | |
774 | if (!out) { | |
775 | perror("cannot open sloc.db for write"); | |
776 | exit(SMS_OCONFIG); | |
777 | } | |
778 | ||
779 | fprintf(stderr, "Building sloc.db\n"); | |
780 | get_mach(); | |
781 | ||
782 | ## range of s is serverhosts | |
783 | ## retrieve (service = s.#service, id = s.mach_id) | |
784 | ## sort by #service { | |
785 | strtrim(service); | |
786 | if (mach = hash_lookup(machines, id)) | |
787 | fprintf(out, "%s.sloc\tHS UNSPECA %s\n", service, mach); | |
788 | ## } | |
789 | ||
790 | if (fclose(out)) { | |
791 | fprintf(stderr, "Unsuccessful close of sloc.db\n"); | |
792 | exit(SMS_CCONFIG); | |
793 | } | |
794 | ||
795 | fix_file(outf); | |
796 | return(1); | |
797 | ##} | |
798 | ||
799 | do_service() | |
800 | ##{ | |
801 | FILE *out; | |
802 | char outf[64], outft[64]; | |
803 | struct stat sb; | |
804 | time_t ftime; | |
805 | ## char mach[33], service[33], protocol[9], altserv[129], *filetime; | |
806 | ## int port, flag1, flag2; | |
807 | ||
808 | sprintf(outf, "%s/service.db", HESIOD_DIR); | |
809 | ||
810 | if (stat(outf, &sb) == 0) { | |
811 | ftime = sb.st_mtime; | |
812 | filetime = ingres_date_and_time(ftime); | |
813 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
814 | ## where tblstats.table = "services" | |
815 | if (flag1 < 0) { | |
816 | fprintf(stderr, "File service.db does not need to be rebuilt.\n"); | |
817 | return(0); | |
818 | } | |
819 | } | |
820 | ||
821 | sprintf(outft, "%s~", outf); | |
822 | out = fopen(outft, "w"); | |
823 | if (!out) { | |
824 | perror("cannot open service.db for write"); | |
825 | exit(SMS_OCONFIG); | |
826 | } | |
827 | ||
828 | fprintf(stderr, "Building service.db\n"); | |
829 | ||
830 | ## range of s is services | |
831 | ## retrieve (service = s.name, protocol = lowercase(s.#protocol), | |
832 | ## port = s.#port) { | |
833 | strtrim(service); | |
834 | strtrim(protocol); | |
835 | fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n", | |
836 | service, service, protocol, port); | |
837 | ## } | |
838 | ||
839 | ## range of a is alias | |
840 | ## retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" { | |
841 | strtrim(service); | |
842 | strtrim(altserv); | |
843 | fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv); | |
844 | ## } | |
845 | ||
846 | if (fclose(out)) { | |
847 | fprintf(stderr, "Unsuccessful close of service.db\n"); | |
848 | exit(SMS_CCONFIG); | |
849 | } | |
850 | fix_file(outf); | |
851 | return(1); | |
852 | ##} |