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.
7 * (c) Copyright 1988, 1990 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
12 #include <mit-copyright.h>
15 #include <moira_site.h>
16 #include <sys/types.h>
21 EXEC SQL INCLUDE sqlca;
25 #define HTYPE "UNSPECA"
32 #define HESIOD_SUBDIR "hesiod"
35 /* max number of bytes of a data record that can be returned in a hesiod
36 * query. This is 512 - overhead (~66) [derived empirically]
38 #define MAXHESSIZE 446
42 #define min(x,y) ((x) < (y) ? (x) : (y))
43 struct hash *machines = NULL;
44 struct hash *users = NULL;
45 char *whoami = "hesiod.gen";
46 char *db = "moira/moira";
58 char *malloc(), *strsave();
70 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
74 initialize_sms_error_table ();
75 sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR);
79 changed = do_passwd();
80 changed += do_filsys();
81 changed += do_cluster();
82 changed += do_printcap();
83 changed += do_palladium();
85 changed += do_service();
86 changed += do_groups();
89 fprintf(stderr, "No files updated.\n");
90 if (argc == 2 && stat(argv[1], &sb) == 0)
95 fprintf(stderr, "Building tar file.\n");
96 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
107 EXEC SQL BEGIN DECLARE SECTION;
110 EXEC SQL END DECLARE SECTION;
115 machines = create_hash(1000);
116 EXEC SQL DECLARE m_cursor CURSOR FOR
119 WHERE status = 1 and mach_id != 0
121 EXEC SQL OPEN m_cursor;
123 EXEC SQL FETCH m_cursor INTO :name, :id;
124 if (sqlca.sqlcode != 0) break;
125 hash_store(machines, id, strsave(strtrim(name)));
127 if (sqlca.sqlcode < 0) db_error(sqlca.sqlcode);
128 EXEC SQL CLOSE m_cursor;
135 FILE *pout, *uout, *bout;
136 char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
137 struct stat psb, usb, bsb;
141 EXEC SQL BEGIN DECLARE SECTION;
142 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
143 char nn[17], ptype[9];
144 int uid, flag1, flag2, id, pid, status;
145 EXEC SQL END DECLARE SECTION;
147 sprintf(poutf, "%s/passwd.db", hesiod_dir);
148 sprintf(uoutf, "%s/uid.db", hesiod_dir);
149 sprintf(boutf, "%s/pobox.db", hesiod_dir);
151 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
152 stat(boutf, &bsb) == 0) {
153 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
154 if (ModDiff (&flag1, "users", ftime) ||
155 ModDiff (&flag2, "machine", ftime))
157 if (flag1 < 0 && flag2 < 0) {
158 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
163 sprintf(poutft, "%s~", poutf);
164 pout = fopen(poutft, "w");
166 perror("cannot open passwd.db~ for write");
169 sprintf(uoutft, "%s~", uoutf);
170 uout = fopen(uoutft, "w");
172 perror("cannot open uid.db~ for write");
175 sprintf(boutft, "%s~", boutf);
176 bout = fopen(boutft, "w");
178 perror("cannot open pobox.db for write");
182 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
185 users = create_hash(12001);
186 EXEC SQL DECLARE u_cursor CURSOR FOR
187 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
188 office_phone, home_phone, users_id, pop_id, potype, status
190 WHERE status = 1 or status = 5 or status = 6
192 EXEC SQL OPEN u_cursor;
194 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
195 :oa, :op, :hp, :id, :pid, :ptype, :status;
196 if (sqlca.sqlcode != 0) break;
204 u = (struct user *) malloc(sizeof(struct user));
205 strcpy(u->name, login);
207 hash_store(users, id, u);
209 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
210 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
211 op, hp, login, shell);
212 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS,
215 if (pid != 0 && (mach = hash_lookup(machines, pid))) {
216 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
217 login, HCLASS, HTYPE, mach, login);
220 if (sqlca.sqlcode < 0) db_error(sqlca.sqlcode);
221 EXEC SQL CLOSE u_cursor;
224 if (fclose(pout) || fclose(uout) || fclose(bout)) {
225 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
237 FILE *iout, *gout, *lout;
238 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
240 register struct bucket *b, **p;
243 struct stat isb, gsb, lsb;
245 EXEC SQL BEGIN DECLARE SECTION;
247 int gid, id, lid, flag1, flag2, flag3, len;
248 EXEC SQL END DECLARE SECTION;
251 sprintf(ioutf, "%s/gid.db", hesiod_dir);
252 sprintf(goutf, "%s/group.db", hesiod_dir);
253 sprintf(loutf, "%s/grplist.db", hesiod_dir);
255 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
256 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
257 if (ModDiff (&flag1, "users", ftime) ||
258 ModDiff (&flag2, "list", ftime) ||
259 ModDiff (&flag3, "imembers", ftime))
261 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
262 fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
267 sprintf(buf, "%s~", ioutf);
268 iout = fopen(buf, "w");
270 perror("cannot open gid.db for write");
273 sprintf(buf, "%s~", goutf);
274 gout = fopen(buf, "w");
276 perror("cannot open group.db for write");
279 sprintf(buf, "%s~", loutf);
280 lout = fopen(buf, "w");
282 perror("cannot open grplist.db for write");
286 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
288 /* make space for group list */
289 groups = create_hash(15001);
291 /* The following WHENEVER is declarative, not executed,
292 * and applies for the remainder of this file only.
294 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
296 EXEC SQL DECLARE l_cursor CURSOR FOR
297 SELECT name, gid, list_id
299 WHERE grouplist != 0 AND active != 0
301 EXEC SQL OPEN l_cursor;
303 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
304 if (sqlca.sqlcode != 0) break;
306 sprintf(buf, "%s:%d", name, gid);
307 hash_store(groups, lid, strsave(buf));
308 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
309 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
310 name, HCLASS, HTYPE, name, gid);
312 EXEC SQL CLOSE l_cursor;
317 /* now do grplists */
319 users = create_hash(12001);
320 EXEC SQL DECLARE u_cursor2 CURSOR FOR
321 SELECT users_id, login
325 EXEC SQL OPEN u_cursor2;
327 EXEC SQL FETCH u_cursor2 INTO :id, :name;
328 if (sqlca.sqlcode != 0) break;
329 u = (struct user *) malloc(sizeof(struct user));
330 strcpy(u->name, strtrim(name));
332 hash_store(users, id, u);
334 EXEC SQL CLOSE u_cursor2;
337 EXEC SQL DECLARE i_cursor CURSOR FOR
338 SELECT list_id, member_id
340 WHERE member_type = 'USER'
342 EXEC SQL OPEN i_cursor;
344 EXEC SQL FETCH i_cursor INTO :lid, :id;
345 if (sqlca.sqlcode != 0) break;
346 if (((l = hash_lookup(groups, lid)) != NULL) &&
347 (u = (struct user *) hash_lookup(users, id))) {
348 g = (struct grp *) malloc(sizeof(struct grp));
354 EXEC SQL CLOSE i_cursor;
358 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
359 for (b = *p; b; b = b->next) {
360 if ((g = ((struct user *)b->data)->lists) == NULL)
362 fprintf(lout, "%s.grplist\t%s %s \"",
363 ((struct user *)b->data)->name, HCLASS, HTYPE);
365 for (; g; g = g->next) {
366 if (len + strlen(g->lid) + 1 < MAXHESSIZE) {
370 len += strlen(g->lid) + 1;
372 com_err(whoami, 0, "truncated grp list for user %s",
373 ((struct user *)b->data)->name);
381 if (fclose(iout) || fclose(gout) || fclose(lout)) {
382 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
390 db_error(sqlca.sqlcode);
398 char outf[64], outft[64], *mach, *group;
402 struct save_queue *sq, *sq2, *sq_create();
403 EXEC SQL BEGIN DECLARE SECTION;
404 char name[33], type[9], loc[81], access[2], mount[33], trans[257];
406 int flag1, flag2, flag3, flag4, id, fid;
407 EXEC SQL END DECLARE SECTION;
409 sprintf(outf, "%s/filsys.db", hesiod_dir);
411 if (stat(outf, &sb) == 0) {
414 if (ModDiff(&flag1, "filesys", ftime)) exit (MR_DATE);
415 if (ModDiff(&flag2, "machine", ftime)) exit (MR_DATE);
416 if (ModDiff(&flag3, "alias", ftime)) exit (MR_DATE);
417 if (ModDiff(&flag4, "fsgroup", ftime)) exit (MR_DATE);
419 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
420 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
425 sprintf(outft, "%s~", outf);
426 out = fopen(outft, "w");
428 perror("cannot open filsys.db for write");
432 fprintf(stderr, "Building filsys.db\n");
437 EXEC SQL DECLARE f_cursor CURSOR FOR
438 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
441 EXEC SQL OPEN f_cursor;
443 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
444 :mount, :comments, :fid;
445 if (sqlca.sqlcode != 0) break;
447 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
448 if (mach = hash_lookup(machines, id)) {
449 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
450 strtrim(name), HCLASS, HTYPE, type, strtrim(loc),
451 mach, strtrim(access), strtrim(mount));
453 } else if (!strcmp(type, "AFS")) {
454 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
455 strtrim(name), HCLASS, HTYPE, strtrim(loc),
456 strtrim(access), strtrim(mount));
457 } else if (!strcmp(type, "ERR")) {
458 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
459 strtrim(name), HCLASS, HTYPE, strtrim(comments));
460 } else if (!strcmp(type, "FSGROUP")) {
461 sprintf(trans, "%s:%d", strtrim(name), fid);
462 sq_save_data(sq, strsave(trans));
463 } else if (!strcmp(type, "MUL")) {
464 sprintf(trans, "%s:%d", strtrim(name), fid);
465 sq_save_data(sq2, strsave(trans));
468 EXEC SQL CLOSE f_cursor;
470 while (sq_get_data(sq, &group)) {
471 fid = atoi(strchr(group, ':')+1);
472 *strchr(group, ':') = 0;
474 EXEC SQL DECLARE f_cursor2 CURSOR FOR
475 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
476 f.comments, f.label, g.key
477 FROM filesys f, fsgroup g
478 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
480 EXEC SQL OPEN f_cursor2;
481 for (flag1=1;;flag1++) {
482 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access,:mount,
483 :comments, :name, :trans;
484 if (sqlca.sqlcode != 0) break;
486 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
487 if (mach = hash_lookup(machines, id)) {
488 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
489 group, HCLASS, HTYPE, type, strtrim(loc), mach,
490 strtrim(access), strtrim(mount), flag1);
492 } else if (!strcmp(type, "AFS")) {
493 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
494 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
495 strtrim(mount), flag1);
496 } else if (!strcmp(type, "ERR")) {
497 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
498 group, HCLASS, HTYPE, strtrim(comments));
501 EXEC SQL CLOSE f_cursor2;
506 while (sq_get_data(sq2, &group)) {
507 fid = atoi(strchr(group, ':') + 1);
508 *strchr(group, ':') = 0;
509 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
510 EXEC SQL DECLARE f_cursor3 CURSOR FOR
511 SELECT DISTINCT f.label, g.key
512 FROM filesys f, fsgroup g
513 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
515 EXEC SQL OPEN f_cursor3;
517 EXEC SQL FETCH f_cursor3 INTO :name, :trans;
518 if (sqlca.sqlcode != 0) break;
519 fprintf(out, " %s", strtrim(name));
521 EXEC SQL CLOSE f_cursor3;
522 fprintf(out, "\"\n");
527 EXEC SQL DECLARE a_cursor CURSOR FOR
530 WHERE type = 'FILESYS';
531 EXEC SQL OPEN a_cursor;
533 EXEC SQL FETCH a_cursor INTO :name, :trans;
534 if (sqlca.sqlcode != 0) break;
535 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
536 strtrim(name), HCLASS, strtrim(trans));
538 EXEC SQL CLOSE a_cursor;
543 fprintf(stderr, "Unsuccessful close of filsys.db\n");
549 db_error(sqlca.sqlcode);
555 * Modified from sys/types.h:
557 int setsize; /* = howmany(setbits, NSETBITS) */
559 typedef long set_mask;
560 #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
562 #define howmany(x, y) (((x)+((y)-1))/(y))
565 #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
566 #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
567 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
568 #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
569 #define SET_ZERO(p) memset((char *)(p), 0, setsize * sizeof(set_mask))
570 #define SET_CMP(p1, p2) (memcmp((p1), (p2), setsize * sizeof(set_mask)))
577 for (i = 0; i < setsize * NSETBITS; i++)
578 if (SET_ISSET(i, set))
587 char outf[64], outft[64], *mach, machbuf[41], *p;
590 EXEC SQL BEGIN DECLARE SECTION;
591 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
592 char name[41], label2[17], data[33];
593 EXEC SQL END DECLARE SECTION;
594 set_mask **machs, *ms, *ps;
597 sprintf(outf, "%s/cluster.db", hesiod_dir);
599 if (stat(outf, &sb) == 0) {
601 if (ModDiff (&flag1, "clusters", ftime)
602 || ModDiff (&flag2, "machine", ftime)
603 || ModDiff (&flag3, "mcmap", ftime)
604 || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE);
605 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
606 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
611 sprintf(outft, "%s~", outf);
612 out = fopen(outft, "w");
614 perror("cannot open cluster.db for write");
618 fprintf(stderr, "Building cluster.db\n");
621 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
623 setsize = howmany(maxclu, NSETBITS);
625 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
627 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
628 memset(machs, 0, (maxmach + 1) * sizeof(int));
630 EXEC SQL DECLARE p_cursor CURSOR FOR
631 SELECT mach_id, clu_id
634 EXEC SQL OPEN p_cursor;
636 EXEC SQL FETCH p_cursor INTO :mid, :cid;
637 if (sqlca.sqlcode != 0) break;
638 if (!(ms = machs[mid])) {
639 ms = machs[mid] = SET_CREATE();
644 EXEC SQL CLOSE p_cursor;
646 for (mid = 1; mid < maxmach; mid++) {
650 if (nbitsset(ms) > 1) {
652 for (cid = 1; cid < maxclu; cid++) {
653 if (SET_ISSET(cid, ms)) {
654 EXEC SQL DECLARE d_cursor CURSOR FOR
655 SELECT serv_label, serv_cluster
658 EXEC SQL OPEN d_cursor;
660 EXEC SQL FETCH d_cursor INTO :label2, :data;
661 if (sqlca.sqlcode != 0) break;
665 "mrinternal-%d.cluster\t%s %s \"%s %s\"\n",
666 mid, HCLASS, HTYPE, label2, data);
668 EXEC SQL CLOSE d_cursor;
673 for (cid = 1; cid < maxclu; cid++)
674 if (SET_ISSET(cid, ms)) break;
676 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
680 if (mach = hash_lookup(machines, mid)) {
681 for (p = machbuf; *mach && *mach != '.'; mach++)
685 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
686 machbuf, HCLASS, name);
688 fprintf(out, "%s.cluster\t%s CNAME mrinternal-%d.cluster\n",
689 machbuf, HCLASS, mid);
691 for (id = mid + 1; id < maxmach; id++) {
692 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
695 if (mach = hash_lookup(machines, id)) {
696 for (p = machbuf; *mach && *mach != '.'; mach++)
700 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
701 machbuf, HCLASS, name);
704 "%s.cluster\t%s CNAME mrinternal-%d.cluster\n",
705 machbuf, HCLASS, mid);
713 EXEC SQL DECLARE d_cursor2 CURSOR FOR
714 SELECT c.name, d.serv_label, d.serv_cluster
715 FROM svc d, clusters c
716 WHERE c.clu_id = d.clu_id;
717 EXEC SQL OPEN d_cursor2;
719 EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
720 if (sqlca.sqlcode != 0) break;
724 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
725 name, HCLASS, HTYPE, label2, data);
731 fprintf(stderr, "Unsuccessful close of cluster.db\n");
737 db_error(sqlca.sqlcode);
745 char outf[64], outft[64];
748 EXEC SQL BEGIN DECLARE SECTION;
749 char name[17], rp[17], sd[33];
750 int flag1, flag2, ka, pc, rm, rq;
751 EXEC SQL END DECLARE SECTION;
753 sprintf(outf, "%s/printcap.db", hesiod_dir);
755 if (stat(outf, &sb) == 0) {
757 if (ModDiff (&flag1, "printcap", ftime)
758 || ModDiff (&flag2, "machine", ftime))
760 if (flag1 < 0 && flag2 < 0) {
761 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
766 sprintf(outft, "%s~", outf);
767 out = fopen(outft, "w");
769 perror("cannot open printcap.db for write");
773 fprintf(stderr, "Building printcap.db\n");
776 EXEC SQL DECLARE p_cursor2 CURSOR FOR
777 SELECT name, rp, dir, mach_id, auth, price, quotaserver
779 EXEC SQL OPEN p_cursor2;
781 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
782 if (sqlca.sqlcode != 0) break;
783 if (!hash_lookup(machines, rm)) continue;
787 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
788 name, HCLASS, HTYPE, name, rp, hash_lookup(machines, rm),
790 if (rq && hash_lookup(machines, rq))
791 fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq));
795 EXEC SQL CLOSE p_cursor2;
800 fprintf(stderr, "Unsuccessful close of pcap.db\n");
806 db_error(sqlca.sqlcode);
814 char outf[64], outft[64];
817 EXEC SQL BEGIN DECLARE SECTION;
818 char name[33], trans[129];
819 int flag, flag1, identifier, rm;
820 EXEC SQL END DECLARE SECTION;
822 sprintf(outf, "%s/palladium.db", hesiod_dir);
824 if (stat(outf, &sb) == 0) {
826 if ((ModDiff (&flag, "palladium", ftime)) ||
827 (ModDiff (&flag1, "alias", ftime))) exit (MR_DATE);
828 if (flag < 0 && flag1 < 0) {
829 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
834 sprintf(outft, "%s~", outf);
835 out = fopen(outft, "w");
837 perror("cannot open palladium.db for write");
841 fprintf(stderr, "Building palladium.db\n");
844 EXEC SQL DECLARE p_cursor3 CURSOR FOR
845 SELECT name, identifier, mach_id
847 EXEC SQL OPEN p_cursor3;
849 EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm;
850 if (sqlca.sqlcode != 0) break;
851 if (!hash_lookup(machines, rm)) break;
854 "%s.palladium\t%s %s \"%s %d %s interface directory\"\n",
855 name, HCLASS, HTYPE, hash_lookup(machines, rm), identifier,
858 EXEC SQL CLOSE p_cursor3;
860 EXEC SQL DECLARE a_cursor2 CURSOR FOR
863 WHERE type = 'PALLADIUM';
864 EXEC SQL OPEN a_cursor2;
866 EXEC SQL FETCH a_cursor2 INTO :name, :trans;
867 if (sqlca.sqlcode != 0) break;
870 fprintf(out, "%s.palladium\t%s %s \"%s\"\n", name, HCLASS, HTYPE,
873 EXEC SQL CLOSE a_cursor2;
878 fprintf(stderr, "Unsuccessful close of palladium.db\n");
884 db_error(sqlca.sqlcode);
892 char outf[64], outft[64], *mach;
895 EXEC SQL BEGIN DECLARE SECTION;
897 int flag1, flag2, id;
898 EXEC SQL END DECLARE SECTION;
900 sprintf(outf, "%s/sloc.db", hesiod_dir);
902 if (stat(outf, &sb) == 0) {
904 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
905 (ModDiff (&flag2, "machine", ftime))) exit (MR_DATE);
906 if (flag1 < 0 && flag2 < 0) {
907 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
912 sprintf(outft, "%s~", outf);
913 out = fopen(outft, "w");
915 perror("cannot open sloc.db for write");
919 fprintf(stderr, "Building sloc.db\n");
922 EXEC SQL DECLARE s_cursor CURSOR FOR
923 SELECT DISTINCT service, mach_id
926 EXEC SQL OPEN s_cursor;
928 EXEC SQL FETCH s_cursor INTO :service, :id;
929 if (sqlca.sqlcode != 0) break;
931 if (mach = hash_lookup(machines, id))
932 fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
934 EXEC SQL CLOSE s_cursor;
939 fprintf(stderr, "Unsuccessful close of sloc.db\n");
946 db_error(sqlca.sqlcode);
953 char outf[64], outft[64];
956 EXEC SQL BEGIN DECLARE SECTION;
957 char service[33], protocol[9], altserv[129];
959 EXEC SQL END DECLARE SECTION;
961 sprintf(outf, "%s/service.db", hesiod_dir);
963 if (stat(outf, &sb) == 0) {
965 if (ModDiff (&flag1, "services", ftime)) exit (MR_DATE);
967 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
972 sprintf(outft, "%s~", outf);
973 out = fopen(outft, "w");
975 perror("cannot open service.db for write");
979 fprintf(stderr, "Building service.db\n");
981 EXEC SQL DECLARE s_cursor2 CURSOR FOR
982 SELECT name, protocol, port
984 EXEC SQL OPEN s_cursor2;
986 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
987 if (sqlca.sqlcode != 0) break;
988 lowercase(protocol); /* Convert protocol to lowercase */
991 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
992 service, HCLASS, HTYPE, service, protocol, port);
994 EXEC SQL CLOSE s_cursor2;
996 EXEC SQL DECLARE a_cursor3 CURSOR FOR
999 WHERE type = 'SERVICE';
1000 EXEC SQL OPEN a_cursor3;
1002 EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
1003 if (sqlca.sqlcode != 0) break;
1006 fprintf(out, "%s.service\t%s CNAME %s.service\n", service, HCLASS,
1009 EXEC SQL CLOSE a_cursor3;
1014 fprintf(stderr, "Unsuccessful close of service.db\n");
1020 db_error(sqlca.sqlcode);