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