]>
Commit | Line | Data |
---|---|---|
dfb56d6b | 1 | /* $Header$ |
2 | * | |
3 | * This generates the zone files necessary to load a hesiod server. | |
4 | * The following zones are generated: | |
5 | */ | |
6 | ||
7 | #include <stdio.h> | |
8 | #include <sms.h> | |
9 | #include <sms_app.h> | |
10 | #include <sys/types.h> | |
11 | #include <sys/stat.h> | |
12 | #include <sys/time.h> | |
13 | ||
14 | #define HESIOD_DIR "/u1/sms/dcm/hesiod" | |
15 | ||
16 | #define min(x,y) ((x) < (y) ? (x) : (y)) | |
17 | ||
18 | char *malloc(), *strsave(); | |
19 | char *ingres_date_and_time(), *ingres_time(), *ingres_date(); | |
20 | ||
21 | main(argc, argv) | |
22 | int argc; | |
23 | char **argv; | |
24 | { | |
25 | char cmd[64]; | |
26 | struct stat sb; | |
27 | int changed = 0; | |
28 | ||
29 | if (argc > 2) { | |
30 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
31 | exit(-1); | |
32 | } | |
33 | ||
34 | ## ingres sms | |
35 | ## set lockmode session where readlock = nolock | |
36 | ||
37 | changed = do_passwd(); | |
38 | changed += do_pobox(); | |
39 | changed += do_groups(); | |
40 | changed += do_filsys(); | |
41 | changed += do_cluster(); | |
42 | changed += do_printers(); | |
43 | changed += do_services(); | |
44 | ||
45 | ## exit | |
46 | ||
47 | if (!changed) { | |
48 | fprintf(stderr, "No files updated.\n"); | |
49 | if (argc == 2 && stat(argv[1], &sb) == 0) | |
50 | exit(0); | |
51 | } | |
52 | ||
53 | if (argc == 2) { | |
54 | sprintf(cmd, "cd %s; tar cf %s .", HESIOD_DIR, argv[1]); | |
55 | exit(system(cmd)); | |
56 | } | |
57 | ||
58 | exit(0); | |
59 | } | |
60 | ||
61 | ||
62 | do_passwd() | |
63 | ##{ | |
64 | FILE *pout, *uout; | |
65 | char poutf[64], uoutf[64]; | |
66 | struct stat psb, usb; | |
67 | time_t ftime; | |
68 | ## char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime; | |
69 | ## int uid, flag; | |
70 | ||
71 | sprintf(poutf, "%s/passwd.db", HESIOD_DIR); | |
72 | sprintf(uoutf, "%s/uid.db", HESIOD_DIR); | |
73 | ||
74 | if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0) { | |
75 | ftime = min(psb.st_mtime, usb.st_mtime); | |
76 | filetime = ingres_date_and_time(ftime); | |
77 | ## retrieve (flag = int4(interval("min", tblstats.modtime - filetime))) | |
78 | ## where tblstats.table = "users" | |
79 | if (flag < 0) { | |
80 | fprintf(stderr, "Files passwd.db and uid.db do not need to be rebuilt.\n"); | |
81 | return(0); | |
82 | } | |
83 | } | |
84 | ||
85 | pout = fopen(poutf, "w"); | |
86 | if (!pout) { | |
87 | perror("cannot open passwd.db for write"); | |
88 | exit(-1); | |
89 | } | |
90 | uout = fopen(uoutf, "w"); | |
91 | if (!uout) { | |
92 | perror("cannot open uid.db for write"); | |
93 | exit(-1); | |
94 | } | |
95 | ||
96 | fprintf(stderr, "Building passwd.db and uid.db\n"); | |
97 | ||
98 | ## range of u is users | |
99 | ## retrieve (login = u.#login, uid = u.#uid, shell = u.#shell, | |
100 | ## fullname = u.#fullname, oa = u.office_addr, | |
101 | ## op = u.office_phone, hp = u.home_phone) | |
102 | ## where u.status != 0 sort by #login { | |
103 | trim(login); | |
104 | trim(fullname); | |
105 | trim(oa); | |
106 | trim(op); | |
107 | trim(hp); | |
108 | trim(shell); | |
109 | fprintf(pout, "%s.passwd\tHS UNSPECA \"%s:*:%d:101:%s,%s,%s,%s:/mit/%s:%s\"\n", | |
110 | login, login, uid, fullname, oa, op, hp, login, shell); | |
111 | fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login); | |
112 | ## } | |
113 | ||
114 | if (fclose(pout) || fclose(uout)) { | |
115 | fprintf(stderr, "Unsuccessful file close of passwd.db or uid.db\n"); | |
116 | exit(-1); | |
117 | } | |
118 | return(1); | |
119 | ##} | |
120 | ||
121 | ||
122 | do_pobox() | |
123 | ##{ | |
124 | FILE *out; | |
125 | char outf[64]; | |
126 | struct stat sb; | |
127 | time_t ftime; | |
128 | ## char login[9], mach[33], *filetime; | |
129 | ## int flag1, flag2; | |
130 | ||
131 | sprintf(outf, "%s/pobox.db", HESIOD_DIR); | |
132 | ||
133 | if (stat(outf, &sb) == 0) { | |
134 | ftime = sb.st_mtime; | |
135 | filetime = ingres_date_and_time(ftime); | |
136 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
137 | ## where tblstats.table = "users" | |
138 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
139 | ## where tblstats.table = "machine" | |
140 | if (flag1 < 0 && flag2 < 0) { | |
141 | fprintf(stderr,"File pobox.db does not need to be rebuilt.\n"); | |
142 | return(0); | |
143 | } | |
144 | } | |
145 | ||
146 | out = fopen(outf, "w"); | |
147 | if (!out) { | |
148 | perror("cannot open pobox.db for write"); | |
149 | exit(-1); | |
150 | } | |
151 | ||
152 | fprintf(stderr, "Building pobox.db\n"); | |
153 | ||
154 | ## range of u is users | |
155 | ## range of m is machine | |
156 | ## retrieve (login = u.#login, mach = m.#name) | |
157 | ## where u.potype = "POP" and m.mach_id = u.pop_id { | |
158 | trim(login); | |
159 | trim(mach); | |
160 | fprintf(out, "%s.pobox\tHS UNSPECA \"POP %s %s\"\n", | |
161 | login, mach, login); | |
162 | ## } | |
163 | ||
164 | if (fclose(out)) { | |
165 | fprintf(stderr, "Unsuccessful close of pobox.db\n"); | |
166 | exit(-1); | |
167 | } | |
168 | return(1); | |
169 | ##} | |
170 | ||
171 | ||
172 | do_groups() | |
173 | ##{ | |
174 | FILE *iout, *gout, *lout; | |
175 | char ioutf[64], goutf[64], loutf[64], buf[256]; | |
176 | char **groups; | |
177 | struct stat isb, gsb, lsb; | |
178 | time_t ftime; | |
179 | struct save_queue *sq, *sq_create(); | |
180 | register int first; | |
181 | ## char name[33], *filetime; | |
182 | ## int gid, id, lid, flag1, flag2, flag3, maxid; | |
183 | ||
184 | /* open files */ | |
185 | sprintf(ioutf, "%s/gid.db", HESIOD_DIR); | |
186 | sprintf(goutf, "%s/group.db", HESIOD_DIR); | |
187 | sprintf(loutf, "%s/grplist.db", HESIOD_DIR); | |
188 | ||
189 | if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) { | |
190 | ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime)); | |
191 | filetime = ingres_date_and_time(ftime); | |
192 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
193 | ## where tblstats.table = "users" | |
194 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
195 | ## where tblstats.table = "list" | |
196 | ## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime))) | |
197 | ## where tblstats.table = "members" | |
198 | if (flag1 < 0 && flag2 < 0 && flag3 < 0) { | |
199 | fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n"); | |
200 | return(0); | |
201 | } | |
202 | } | |
203 | ||
204 | iout = fopen(ioutf, "w"); | |
205 | if (!iout) { | |
206 | perror("cannot open gid.db for write"); | |
207 | exit(-1); | |
208 | } | |
209 | gout = fopen(goutf, "w"); | |
210 | if (!gout) { | |
211 | perror("cannot open group.db for write"); | |
212 | exit(-1); | |
213 | } | |
214 | lout = fopen(loutf, "w"); | |
215 | if (!lout) { | |
216 | perror("cannot open grplist.db for write"); | |
217 | exit(-1); | |
218 | } | |
219 | ||
220 | fprintf(stderr, "Building gid.db, group.db, and grplist.db\n"); | |
221 | ||
222 | /* make space for group list */ | |
223 | ## range of l is list | |
224 | ## retrieve (maxid = max(l.#list_id)) | |
225 | groups = (char **)malloc((maxid + 1) * sizeof(char *)); | |
226 | if (groups == NULL) { | |
227 | fprintf(stderr, "unable to malloc space for groups\n"); | |
228 | exit(1); | |
229 | } | |
230 | bzero(groups, (maxid + 1) * sizeof(char *)); | |
231 | ||
232 | /* retrieve simple groups */ | |
233 | ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) | |
234 | ## where l.group != 0 { | |
235 | trim(name); | |
236 | sprintf(buf, "%s:%d", name, gid); | |
237 | groups[lid] = strsave(buf); | |
238 | fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name); | |
239 | fprintf(gout, "%s.group\tHS UNSPECA \"%s:*:%d:\"\n", | |
240 | name, name, gid); | |
241 | ## } | |
242 | ||
243 | /* get special cases: lists that aren't groups themselves but are | |
244 | * members of groups. */ | |
245 | sq = sq_create(); | |
246 | ## range of m is members | |
247 | ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) | |
248 | ## where l.group = 0 and m.member_type = "LIST" and | |
249 | ## m.member_id = l.list_id and m.list_id = list.list_id and | |
250 | ## list.group != 0 { | |
251 | trim(name); | |
252 | sprintf(buf, "%s:%d", name, gid); | |
253 | groups[lid] = strsave(buf); | |
254 | sq_save_data(sq, lid); | |
255 | ## } | |
256 | while (sq_get_data(sq, &id)) { | |
257 | ## repeat retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) | |
258 | ## where l.group = 0 and m.member_type = "LIST" and | |
259 | ## m.member_id = l.list_id and m.list_id = @id { | |
260 | trim(name); | |
261 | sprintf(buf, "%s:%d", name, gid); | |
262 | groups[lid] = strsave(buf); | |
263 | sq_save_unique_data(sq, lid); | |
264 | ## } | |
265 | } | |
266 | sq_destroy(sq); | |
267 | ||
268 | /* now do grplists */ | |
269 | sq = sq_create(); | |
270 | ## range of u is users | |
271 | ## retrieve (id = u.users_id) where u.status != 0 { | |
272 | sq_save_data(sq, id); | |
273 | ## } | |
274 | while (sq_get_data(sq, &id)) { | |
275 | ## repeat retrieve (name = u.login) where u.users_id = @id | |
276 | trim(name); | |
277 | first = 1; | |
278 | ## repeat retrieve (lid = m.list_id) | |
279 | ## where m.member_type = "USER" and m.member_id = @id { | |
280 | if (groups[lid]) { | |
281 | if (first) | |
282 | fprintf(lout, "%s.grplist\tHS UNSPECA \"%s",name,groups[lid]); | |
283 | else | |
284 | fprintf(lout, ":%s", groups[lid]); | |
285 | first = 0; | |
286 | } | |
287 | ## } | |
288 | if (!first) | |
289 | fprintf(lout, "\"\n"); | |
290 | } | |
291 | sq_destroy(sq); | |
292 | for (id = 0; id < maxid; id++) | |
293 | if (groups[id]) | |
294 | free(groups[id]); | |
295 | free(groups); | |
296 | ||
297 | if (fclose(iout) || fclose(gout) || fclose(lout)) { | |
298 | fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n"); | |
299 | exit(-1); | |
300 | } | |
301 | return(1); | |
302 | ##} | |
303 | ||
304 | ||
305 | do_filsys() | |
306 | ##{ | |
307 | FILE *out; | |
308 | char outf[64]; | |
309 | struct stat sb; | |
310 | time_t ftime; | |
311 | ## char name[33], type[9], loc[33], mach[33], access[2], mount[33], trans[257]; | |
312 | ## char *filetime; | |
313 | ## int flag1, flag2, flag3; | |
314 | ||
315 | sprintf(outf, "%s/filsys.db", HESIOD_DIR); | |
316 | ||
317 | if (stat(outf, &sb) == 0) { | |
318 | ftime = sb.st_mtime; | |
319 | filetime = ingres_date_and_time(ftime); | |
320 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
321 | ## where tblstats.table = "filesys" | |
322 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
323 | ## where tblstats.table = "machine" | |
324 | ## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime))) | |
325 | ## where tblstats.table = "alias" | |
326 | if (flag1 < 0 && flag2 < 0 && flag3 < 0) { | |
327 | fprintf(stderr, "File filsys.db does not need to be rebuilt.\n"); | |
328 | return(0); | |
329 | } | |
330 | } | |
331 | ||
332 | ||
333 | out = fopen(outf, "w"); | |
334 | if (!out) { | |
335 | perror("cannot open filsys.db for write"); | |
336 | exit(-1); | |
337 | } | |
338 | ||
339 | fprintf(stderr, "Building filsys.db\n"); | |
340 | ||
341 | ## range of f is filesys | |
342 | ## range of m is machine | |
343 | ## retrieve (name = f.label, type = f.#type, loc = f.#name, mach = m.#name, | |
344 | ## access = f.#access, mount = f.#mount) | |
345 | ## where m.mach_id = f.mach_id { | |
346 | trim(name); | |
347 | trim(type); | |
348 | trim(loc); | |
349 | trim(mach); | |
350 | trim(access); | |
351 | trim(mount); | |
352 | fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n", | |
353 | name, type, loc, mach, access, mount); | |
354 | ## } | |
355 | ||
356 | ## range of a is alias | |
357 | ## retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" { | |
358 | trim(name); | |
359 | trim(trans); | |
360 | fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n", name, trans); | |
361 | ## } | |
362 | ||
363 | if (fclose(out)) { | |
364 | fprintf(stderr, "Unsuccessful close of filsys.db\n"); | |
365 | exit(-1); | |
366 | } | |
367 | return(1); | |
368 | ##} | |
369 | ||
370 | ||
371 | /* | |
372 | * Modified from sys/types.h: | |
373 | */ | |
374 | int setsize; /* = howmany(setbits, NSETBITS) */ | |
375 | ||
376 | typedef long set_mask; | |
377 | #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */ | |
378 | #ifndef howmany | |
379 | #define howmany(x, y) (((x)+((y)-1))/(y)) | |
380 | #endif | |
381 | ||
382 | #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS))) | |
383 | #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS))) | |
384 | #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS))) | |
385 | #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask))) | |
386 | #define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask)) | |
387 | #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask))) | |
388 | ||
389 | ||
390 | do_cluster() | |
391 | ##{ | |
392 | FILE *out; | |
393 | char outf[64]; | |
394 | struct stat sb; | |
395 | time_t ftime; | |
396 | ## int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id; | |
397 | ## char name[33], label[17], data[33], mach[33], *filetime; | |
398 | set_mask **machs, *ms, *ps; | |
399 | ||
400 | sprintf(outf, "%s/cluster.db", HESIOD_DIR); | |
401 | ||
402 | if (stat(outf, &sb) == 0) { | |
403 | ftime = sb.st_mtime; | |
404 | filetime = ingres_date_and_time(ftime); | |
405 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
406 | ## where tblstats.table = "cluster" | |
407 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
408 | ## where tblstats.table = "machine" | |
409 | ## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime))) | |
410 | ## where tblstats.table = "mcmap" | |
411 | ## retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime))) | |
412 | ## where tblstats.table = "svc" | |
413 | if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) { | |
414 | fprintf(stderr, "File cluster.db does not need to be rebuilt.\n"); | |
415 | return(0); | |
416 | } | |
417 | } | |
418 | ||
419 | out = fopen(outf, "w"); | |
420 | if (!out) { | |
421 | perror("cannot open cluster.db for write"); | |
422 | exit(-1); | |
423 | } | |
424 | ||
425 | fprintf(stderr, "Building cluster.db\n"); | |
426 | ||
427 | ## range of c is cluster | |
428 | ## retrieve (maxclu = max(c.clu_id)) | |
429 | setsize = howmany(maxclu, NSETBITS); | |
430 | ## range of m is machine | |
431 | ## retrieve (maxmach = max(m.mach_id)) | |
432 | machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **)); | |
433 | bzero(machs, (maxmach + 1) * sizeof(int)); | |
434 | ||
435 | ## range of p is mcmap | |
436 | ## retrieve (mid = p.mach_id, cid = p.clu_id) { | |
437 | if (!(ms = machs[mid])) { | |
438 | ms = machs[mid] = SET_CREATE(); | |
439 | SET_ZERO(ms); | |
440 | } | |
441 | SET_SET(cid, ms); | |
442 | ## } | |
443 | ||
444 | ## range of d is svc | |
445 | for (mid = 1; mid < maxmach; mid++) { | |
446 | if (!machs[mid]) | |
447 | continue; | |
448 | ms = machs[mid]; | |
449 | fprintf(out, "smsinternal-%d.cluster", mid); | |
450 | for (cid = 1; cid < maxclu; cid++) { | |
451 | if (SET_ISSET(cid, ms)) { | |
452 | ## repeat retrieve (label = d.serv_label, data = d.serv_cluster) | |
453 | ## where d.clu_id = @cid { | |
454 | trim(label); | |
455 | trim(data); | |
456 | fprintf(out, "\tHS UNSPECA \"%s %s\"\n", label, data); | |
457 | ## } | |
458 | } | |
459 | } | |
460 | ||
461 | ## repeat retrieve (mach = m.#name) where m.mach_id = @mid | |
462 | trim(mach); | |
463 | fprintf(out, "%s.cluster\tHS CNAME smmsinternal-%d.cluster\n", | |
464 | mach, mid); | |
465 | for (id = mid + 1; id < maxmach; id++) { | |
466 | if ((ps = machs[id]) && !SET_CMP(ms, ps)) { | |
467 | free(ps); | |
468 | machs[id] = NULL; | |
469 | ## repeat retrieve (mach = m.#name) where m.mach_id = @id | |
470 | trim(mach); | |
471 | fprintf(out, "%s.cluster\tHS CNAME smmsinternal-%d.cluster\n", | |
472 | mach, mid); | |
473 | } | |
474 | } | |
475 | free(ms); | |
476 | machs[mid] = NULL; | |
477 | } | |
478 | free(machs); | |
479 | ||
480 | ## retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster) | |
481 | ## where c.clu_id = d.clu_id { | |
482 | trim(name); | |
483 | trim(label); | |
484 | trim(data); | |
485 | fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n", | |
486 | name, label, data); | |
487 | ## } | |
488 | ||
489 | if (fclose(out)) { | |
490 | fprintf(stderr, "Unsuccessful close of cluster.db\n"); | |
491 | exit(-1); | |
492 | } | |
493 | return(1); | |
494 | ##} | |
495 | ||
496 | ||
497 | do_printers() | |
498 | ##{ | |
499 | FILE *out; | |
500 | char outf[64]; | |
501 | struct stat sb; | |
502 | time_t ftime; | |
503 | ## char name[33], pcap[513], *filetime; | |
504 | ## int flag; | |
505 | ||
506 | sprintf(outf, "%s/printcap.db", HESIOD_DIR); | |
507 | ||
508 | if (stat(outf, &sb) == 0) { | |
509 | ftime = sb.st_mtime; | |
510 | filetime = ingres_date_and_time(ftime); | |
511 | ## retrieve (flag = int4(interval("min", tblstats.modtime - filetime))) | |
512 | ## where tblstats.table = "printcap" | |
513 | if (flag < 0) { | |
514 | fprintf(stderr, "File printcap.db does not need to be rebuilt.\n"); | |
515 | return(0); | |
516 | } | |
517 | } | |
518 | ||
519 | out = fopen(outf, "w"); | |
520 | if (!out) { | |
521 | perror("cannot open printcap.db for write"); | |
522 | exit(-1); | |
523 | } | |
524 | ||
525 | fprintf(stderr, "Building printcap.db\n"); | |
526 | ||
527 | ## range of p is printcap | |
528 | ## retrieve (name = p.#name, pcap = p.#pcap) { | |
529 | trim(name); | |
530 | trim(pcap); | |
531 | fprintf(out, "%s.pcap\tHS UNSPECA \"%s\"\n", name, pcap); | |
532 | ## } | |
533 | ||
534 | if (fclose(out)) { | |
535 | fprintf(stderr, "Unsuccessful close of pcap.db\n"); | |
536 | exit(-1); | |
537 | } | |
538 | return(1); | |
539 | ##} | |
540 | ||
541 | ||
542 | do_services() | |
543 | ##{ | |
544 | FILE *out; | |
545 | char outf[64]; | |
546 | struct stat sb; | |
547 | time_t ftime; | |
548 | ## char mach[33], service[17], protocol[9], *filetime; | |
549 | ## int port, flag1, flag2; | |
550 | ||
551 | sprintf(outf, "%s/sloc.db", HESIOD_DIR); | |
552 | ||
553 | if (stat(outf, &sb) == 0) { | |
554 | ftime = sb.st_mtime; | |
555 | filetime = ingres_date_and_time(ftime); | |
556 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
557 | ## where tblstats.table = "serverhosts" | |
558 | ## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime))) | |
559 | ## where tblstats.table = "machine" | |
560 | if (flag1 < 0 && flag2 < 0) { | |
561 | fprintf(stderr, "File sloc.db does not need to be rebuilt.\n"); | |
562 | goto next; | |
563 | } | |
564 | } | |
565 | ||
566 | out = fopen(outf, "w"); | |
567 | if (!out) { | |
568 | perror("cannot open sloc.db for write"); | |
569 | exit(-1); | |
570 | } | |
571 | ||
572 | fprintf(stderr, "Building sloc.db\n"); | |
573 | ||
574 | ## range of s is serverhosts | |
575 | ## retrieve (service = s.#service, mach = m.name) | |
576 | ## where m.mach_id = s.mach_id { | |
577 | trim(service); | |
578 | trim(mach); | |
579 | fprintf(out, "%s.sloc\tHS UNSPECA %s\n", service, mach); | |
580 | ## } | |
581 | ||
582 | if (fclose(out)) { | |
583 | fprintf(stderr, "Unsuccessful close of sloc.db\n"); | |
584 | exit(-1); | |
585 | } | |
586 | ||
587 | next: | |
588 | sprintf(outf, "%s/service.db", HESIOD_DIR); | |
589 | ||
590 | if (stat(outf, &sb) == 0) { | |
591 | ftime = sb.st_mtime; | |
592 | filetime = ingres_date_and_time(ftime); | |
593 | ## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime))) | |
594 | ## where tblstats.table = "services" | |
595 | if (flag1 < 0) { | |
596 | fprintf(stderr, "File service.db does not need to be rebuilt.\n"); | |
597 | return(0); | |
598 | } | |
599 | } | |
600 | ||
601 | out = fopen(outf, "w"); | |
602 | if (!out) { | |
603 | perror("cannot open service.db for write"); | |
604 | exit(-1); | |
605 | } | |
606 | ||
607 | fprintf(stderr, "Building service.db\n"); | |
608 | ||
609 | ## range of s is services | |
610 | ## retrieve (service = s.name, protocol = lowercase(s.#protocol), | |
611 | ## port = s.#port) { | |
612 | trim(service); | |
613 | trim(protocol); | |
614 | fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n", | |
615 | service, service, protocol, port); | |
616 | ## } | |
617 | ||
618 | if (fclose(out)) { | |
619 | fprintf(stderr, "Unsuccessful close of service.db\n"); | |
620 | exit(-1); | |
621 | } | |
622 | return(1); | |
623 | ##} |