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>
20 EXEC SQL INCLUDE sqlca;
24 #define HTYPE "UNSPECA"
29 /* max number of bytes of a data record that can be returned in a hesiod
30 * query. This is 512 - overhead (~66) [derived empirically]
32 #define MAXHESSIZE 446
36 #define min(x,y) ((x) < (y) ? (x) : (y))
37 struct hash *machines = NULL;
38 struct hash *users = NULL;
39 char *whoami = "hesiod.gen";
51 char *malloc(), *strsave();
63 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
67 initialize_sms_error_table ();
68 sprintf(hesiod_dir, "%s/hesiod", DCM_DIR);
71 EXEC SQL CONNECT moira;
72 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
75 EXEC SQL DATABASE moira;
78 changed = do_passwd();
79 changed += do_filsys();
80 changed += do_cluster();
81 changed += do_printcap();
82 changed += do_palladium();
84 changed += do_service();
85 changed += do_groups();
91 EXEC SQL CLOSE DATABASE;
95 fprintf(stderr, "No files updated.\n");
96 if (argc == 2 && stat(argv[1], &sb) == 0)
101 fprintf(stderr, "Building tar file.\n");
102 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
113 EXEC SQL BEGIN DECLARE SECTION;
116 EXEC SQL END DECLARE SECTION;
121 machines = create_hash(1000);
122 EXEC SQL DECLARE m_cursor CURSOR FOR
126 EXEC SQL OPEN m_cursor;
128 EXEC SQL FETCH m_cursor INTO :name, :id;
129 if (sqlca.sqlcode != 0) break;
130 hash_store(machines, id, strsave(strtrim(name)));
132 if (sqlca.sqlcode < 0) {
133 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
134 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
138 EXEC SQL CLOSE m_cursor;
143 EXEC SQL COMMIT WORK;
150 FILE *pout, *uout, *bout;
151 char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
152 struct stat psb, usb, bsb;
156 EXEC SQL BEGIN DECLARE SECTION;
157 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
158 char nn[17], ptype[9];
159 int uid, flag1, flag2, id, pid, status;
160 EXEC SQL END DECLARE SECTION;
162 sprintf(poutf, "%s/passwd.db", hesiod_dir);
163 sprintf(uoutf, "%s/uid.db", hesiod_dir);
164 sprintf(boutf, "%s/pobox.db", hesiod_dir);
166 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
167 stat(boutf, &bsb) == 0) {
168 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
169 if (ModDiff (&flag1, "users", ftime) ||
170 ModDiff (&flag2, "machine", ftime))
172 if (flag1 < 0 && flag2 < 0) {
173 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
178 sprintf(poutft, "%s~", poutf);
179 pout = fopen(poutft, "w");
181 perror("cannot open passwd.db~ for write");
184 sprintf(uoutft, "%s~", uoutf);
185 uout = fopen(uoutft, "w");
187 perror("cannot open uid.db~ for write");
190 sprintf(boutft, "%s~", boutf);
191 bout = fopen(boutft, "w");
193 perror("cannot open pobox.db for write");
197 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
200 users = create_hash(12001);
201 EXEC SQL DECLARE u_cursor CURSOR FOR
202 SELECT login, uid, shell, fullname, nickname, office_addr,
203 office_phone, home_phone, users_id, pop_id, potype, status
205 WHERE status = 1 or status = 5 or status = 6
207 EXEC SQL OPEN u_cursor;
209 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
210 :oa, :op, :hp, :id, :pid, :ptype, :status;
211 if (sqlca.sqlcode != 0) break;
219 u = (struct user *) malloc(sizeof(struct user));
220 strcpy(u->name, login);
222 hash_store(users, id, u);
224 fprintf(pout, "%s.passwd\tHS %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
225 login, HTYPE, login, uid, fullname, nn, oa, op, hp,
227 fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login);
229 if (ptype[0] == 'P' && (mach = hash_lookup(machines, pid))) {
230 fprintf(bout, "%s.pobox\tHS %s \"POP %s %s\"\n",
231 login, HTYPE, mach, login);
234 if (sqlca.sqlcode < 0) {
235 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
236 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
240 EXEC SQL CLOSE u_cursor;
245 EXEC SQL COMMIT WORK;
248 if (fclose(pout) || fclose(uout) || fclose(bout)) {
249 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
261 FILE *iout, *gout, *lout;
262 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
264 register struct bucket *b, **p;
267 struct stat isb, gsb, lsb;
269 EXEC SQL BEGIN DECLARE SECTION;
271 int gid, id, lid, flag1, flag2, flag3, len;
272 EXEC SQL END DECLARE SECTION;
275 sprintf(ioutf, "%s/gid.db", hesiod_dir);
276 sprintf(goutf, "%s/group.db", hesiod_dir);
277 sprintf(loutf, "%s/grplist.db", hesiod_dir);
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 if (ModDiff (&flag1, "users", ftime) ||
282 ModDiff (&flag2, "list", ftime) ||
283 ModDiff (&flag3, "imembers", ftime))
285 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
286 fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
291 sprintf(buf, "%s~", ioutf);
292 iout = fopen(buf, "w");
294 perror("cannot open gid.db for write");
297 sprintf(buf, "%s~", goutf);
298 gout = fopen(buf, "w");
300 perror("cannot open group.db for write");
303 sprintf(buf, "%s~", loutf);
304 lout = fopen(buf, "w");
306 perror("cannot open grplist.db for write");
310 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
312 /* make space for group list */
313 groups = create_hash(15001);
315 /* The following WHENEVER is declarative, not executed,
316 * and applies for the remainder of this file only.
318 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
320 /* get lock records */
321 EXEC SQL SELECT modtime INTO :name FROM list WHERE list_id = 0;
322 EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0;
324 EXEC SQL DECLARE l_cursor CURSOR FOR
325 SELECT name, gid, list_id
327 WHERE grouplist != 0 AND active != 0
329 EXEC SQL OPEN l_cursor;
331 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
332 if (sqlca.sqlcode != 0) break;
334 sprintf(buf, "%s:%d", name, gid);
335 hash_store(groups, lid, strsave(buf));
336 fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
337 fprintf(gout, "%s.group\tHS %s \"%s:*:%d:\"\n",
338 name, HTYPE, name, gid);
340 EXEC SQL CLOSE l_cursor;
345 /* now do grplists */
347 users = create_hash(12001);
348 EXEC SQL DECLARE u_cursor2 CURSOR FOR
349 SELECT users_id, login
353 EXEC SQL OPEN u_cursor2;
355 EXEC SQL FETCH u_cursor2 INTO :id, :name;
356 if (sqlca.sqlcode != 0) break;
357 u = (struct user *) malloc(sizeof(struct user));
358 strcpy(u->name, strtrim(name));
360 hash_store(users, id, u);
362 EXEC SQL CLOSE u_cursor2;
365 EXEC SQL DECLARE i_cursor CURSOR FOR
366 SELECT list_id, member_id
368 WHERE member_type = 'USER'
370 EXEC SQL OPEN i_cursor;
372 EXEC SQL FETCH i_cursor INTO :lid, :id;
373 if (sqlca.sqlcode != 0) break;
374 if (((l = hash_lookup(groups, lid)) != NULL) &&
375 (u = (struct user *) hash_lookup(users, id))) {
376 g = (struct grp *) malloc(sizeof(struct grp));
382 EXEC SQL CLOSE i_cursor;
387 EXEC SQL COMMIT WORK;
390 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
391 for (b = *p; b; b = b->next) {
392 if ((g = ((struct user *)b->data)->lists) == NULL)
394 fprintf(lout, "%s.grplist\tHS %s \"",
395 ((struct user *)b->data)->name, HTYPE);
397 for (; g; g = g->next) {
398 if (len + strlen(g->lid) + 1 < MAXHESSIZE) {
402 len += strlen(g->lid) + 1;
404 com_err(whoami, 0, "truncated grp list for user %s",
405 ((struct user *)b->data)->name);
413 if (fclose(iout) || fclose(gout) || fclose(lout)) {
414 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
422 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
423 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
432 char outf[64], outft[64], *mach, *group;
436 struct save_queue *sq, *sq2, *sq_create();
437 EXEC SQL BEGIN DECLARE SECTION;
438 char name[33], type[9], loc[81], access[2], mount[33], trans[257];
440 int flag1, flag2, flag3, flag4, id, fid;
441 EXEC SQL END DECLARE SECTION;
444 sprintf(outf, "%s/filsys.db", hesiod_dir);
446 if (stat(outf, &sb) == 0) {
449 if (ModDiff(&flag1, "filesys", ftime)) exit (MR_DATE);
450 if (ModDiff(&flag2, "machine", ftime)) exit (MR_DATE);
451 if (ModDiff(&flag3, "alias", ftime)) exit (MR_DATE);
452 if (ModDiff(&flag4, "fsgroup", ftime)) exit (MR_DATE);
454 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
455 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
460 sprintf(outft, "%s~", outf);
461 out = fopen(outft, "w");
463 perror("cannot open filsys.db for write");
467 fprintf(stderr, "Building filsys.db\n");
472 EXEC SQL DECLARE f_cursor CURSOR FOR
473 SELECT label, type, name, mach_id, access, mount, comments, filsys_id
476 EXEC SQL OPEN f_cursor;
478 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
479 :mount, :comments, :fid;
480 if (sqlca.sqlcode != 0) break;
482 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
483 if (mach = hash_lookup(machines, id)) {
484 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
485 strtrim(name), HTYPE, type, strtrim(loc), mach,
486 strtrim(access), strtrim(mount));
488 } else if (!strcmp(type, "AFS")) {
489 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
490 strtrim(name), HTYPE, strtrim(loc), strtrim(access),
492 } else if (!strcmp(type, "ERR")) {
493 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
494 strtrim(name), HTYPE, strtrim(comments));
495 } else if (!strcmp(type, "FSGROUP")) {
496 sprintf(trans, "%s:%d", strtrim(name), fid);
497 sq_save_data(sq, strsave(trans));
498 } else if (!strcmp(type, "MUL")) {
499 sprintf(trans, "%s:%d", strtrim(name), fid);
500 sq_save_data(sq2, strsave(trans));
503 EXEC SQL CLOSE f_cursor;
505 while (sq_get_data(sq, &group)) {
506 fid = atoi(index(group, ':')+1);
507 *index(group, ':') = 0;
509 EXEC SQL DECLARE f_cursor2 CURSOR FOR
510 SELECT DISTINCT f.type, f.name, f.mach_id, f.access, f.mount,
511 f.comments, 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_cursor2;
517 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access,:mount,
518 :comments, :name, :trans;
519 if (sqlca.sqlcode != 0) break;
521 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
522 if (mach = hash_lookup(machines, id)) {
523 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
524 group, HTYPE, type, strtrim(loc), mach,
525 strtrim(access), strtrim(mount));
527 } else if (!strcmp(type, "AFS")) {
528 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
529 group, HTYPE, strtrim(loc), strtrim(access),
531 } else if (!strcmp(type, "ERR")) {
532 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
533 group, HTYPE, strtrim(comments));
536 EXEC SQL CLOSE f_cursor2;
541 while (sq_get_data(sq2, &group)) {
542 fid = atoi(index(group, ':') + 1);
543 *index(group, ':') = 0;
544 fprintf(out, "%s.filsys\tHS %s \"MUL", group, HTYPE);
545 EXEC SQL DECLARE f_cursor3 CURSOR FOR
546 SELECT DISTINCT f.label, g.key
547 FROM filesys f, fsgroup g
548 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
550 EXEC SQL OPEN f_cursor3;
552 EXEC SQL FETCH f_cursor3 INTO :name, :trans;
553 if (sqlca.sqlcode != 0) break;
554 fprintf(out, " %s", strtrim(name));
556 EXEC SQL CLOSE f_cursor3;
557 fprintf(out, "\"\n");
562 EXEC SQL DECLARE a_cursor CURSOR FOR
565 WHERE type = 'FILESYS';
566 EXEC SQL OPEN a_cursor;
568 EXEC SQL FETCH a_cursor INTO :name, :trans;
569 if (sqlca.sqlcode != 0) break;
570 fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n",
571 strtrim(name), strtrim(trans));
573 EXEC SQL CLOSE a_cursor;
578 EXEC SQL COMMIT WORK;
582 fprintf(stderr, "Unsuccessful close of filsys.db\n");
588 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
589 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
596 * Modified from sys/types.h:
598 int setsize; /* = howmany(setbits, NSETBITS) */
600 typedef long set_mask;
601 #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
603 #define howmany(x, y) (((x)+((y)-1))/(y))
606 #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
607 #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
608 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
609 #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
610 #define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask))
611 #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
618 for (i = 0; i < setsize * NSETBITS; i++)
619 if (SET_ISSET(i, set))
628 char outf[64], outft[64], *mach, machbuf[33], *p;
631 EXEC SQL BEGIN DECLARE SECTION;
632 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
633 char name[33], label2[17], data[33];
634 EXEC SQL END DECLARE SECTION;
635 set_mask **machs, *ms, *ps;
638 sprintf(outf, "%s/cluster.db", hesiod_dir);
640 if (stat(outf, &sb) == 0) {
642 if (ModDiff (&flag1, "cluster", ftime)
643 || ModDiff (&flag2, "machine", ftime)
644 || ModDiff (&flag3, "mcmap", ftime)
645 || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE);
646 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
647 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
652 sprintf(outft, "%s~", outf);
653 out = fopen(outft, "w");
655 perror("cannot open cluster.db for write");
659 fprintf(stderr, "Building cluster.db\n");
662 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM cluster;
664 setsize = howmany(maxclu, NSETBITS);
666 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
668 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
669 bzero(machs, (maxmach + 1) * sizeof(int));
671 EXEC SQL DECLARE p_cursor CURSOR FOR
672 SELECT mach_id, clu_id
675 EXEC SQL OPEN p_cursor;
677 EXEC SQL FETCH p_cursor INTO :mid, :cid;
678 if (sqlca.sqlcode != 0) break;
679 if (!(ms = machs[mid])) {
680 ms = machs[mid] = SET_CREATE();
685 EXEC SQL CLOSE p_cursor;
687 for (mid = 1; mid < maxmach; mid++) {
691 if (nbitsset(ms) > 1) {
693 for (cid = 1; cid < maxclu; cid++) {
694 if (SET_ISSET(cid, ms)) {
695 EXEC SQL DECLARE d_cursor CURSOR FOR
696 SELECT serv_label, serv_cluster
699 EXEC SQL OPEN d_cursor;
701 EXEC SQL FETCH d_cursor INTO :label2, :data;
702 if (sqlca.sqlcode != 0) break;
706 "mrinternal-%d.cluster\tHS %s \"%s %s\"\n",
707 mid, HTYPE, label2, data);
709 EXEC SQL CLOSE d_cursor;
714 for (cid = 1; cid < maxclu; cid++)
715 if (SET_ISSET(cid, ms)) break;
717 EXEC SQL SELECT name INTO :name FROM cluster WHERE clu_id = :cid;
721 if (mach = hash_lookup(machines, mid)) {
722 for (p = machbuf; *mach && *mach != '.'; mach++)
726 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
729 fprintf(out, "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
732 for (id = mid + 1; id < maxmach; id++) {
733 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
736 if (mach = hash_lookup(machines, id)) {
737 for (p = machbuf; *mach && *mach != '.'; mach++)
741 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
745 "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
754 EXEC SQL DECLARE d_cursor2 CURSOR FOR
755 SELECT c.name, d.serv_label, d.serv_cluster
756 FROM svc d, cluster c
757 WHERE c.clu_id = d.clu_id;
758 EXEC SQL OPEN d_cursor2;
760 EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
761 if (sqlca.sqlcode != 0) break;
765 fprintf(out, "%s.cluster\tHS %s \"%s %s\"\n",
766 name, HTYPE, label2, data);
773 EXEC SQL COMMIT WORK;
777 fprintf(stderr, "Unsuccessful close of cluster.db\n");
783 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
784 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
793 char outf[64], outft[64];
796 EXEC SQL BEGIN DECLARE SECTION;
797 char name[17], rp[17], sd[33];
798 int flag1, flag2, ka, pc, rm, rq;
799 EXEC SQL END DECLARE SECTION;
801 sprintf(outf, "%s/printcap.db", hesiod_dir);
803 if (stat(outf, &sb) == 0) {
805 if (ModDiff (&flag1, "printcap", ftime)
806 || ModDiff (&flag2, "machine", ftime))
808 if (flag1 < 0 && flag2 < 0) {
809 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
814 sprintf(outft, "%s~", outf);
815 out = fopen(outft, "w");
817 perror("cannot open printcap.db for write");
821 fprintf(stderr, "Building printcap.db\n");
824 EXEC SQL DECLARE p_cursor2 CURSOR FOR
825 SELECT name, rp, dir, mach_id, auth, price, quotaserver
827 EXEC SQL OPEN p_cursor2;
829 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
830 if (sqlca.sqlcode != 0) break;
834 fprintf(out, "%s.pcap\tHS %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
835 name, HTYPE, name, rp, hash_lookup(machines, rm), sd, ka, pc);
837 fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq));
841 EXEC SQL CLOSE p_cursor2;
846 EXEC SQL COMMIT WORK;
850 fprintf(stderr, "Unsuccessful close of pcap.db\n");
856 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
857 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
866 char outf[64], outft[64];
869 EXEC SQL BEGIN DECLARE SECTION;
870 char name[33], trans[129];
871 int flag, flag1, ident, rm;
872 EXEC SQL END DECLARE SECTION;
874 sprintf(outf, "%s/palladium.db", hesiod_dir);
876 if (stat(outf, &sb) == 0) {
878 if ((ModDiff (&flag, "palladium", ftime)) ||
879 (ModDiff (&flag1, "alias", ftime))) exit (MR_DATE);
880 if (flag < 0 && flag1 < 0) {
881 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
886 sprintf(outft, "%s~", outf);
887 out = fopen(outft, "w");
889 perror("cannot open palladium.db for write");
893 fprintf(stderr, "Building palladium.db\n");
896 EXEC SQL DECLARE p_cursor3 CURSOR FOR
897 SELECT name, ident, mach_id
899 EXEC SQL OPEN p_cursor3;
901 EXEC SQL FETCH p_cursor3 INTO :name, :ident, :rm;
902 if (sqlca.sqlcode != 0) break;
905 "%s.palladium\tHS %s \"%s %d %s interface directory\"\n",
906 name, HTYPE, hash_lookup(machines, rm), ident, name);
908 EXEC SQL CLOSE p_cursor3;
910 EXEC SQL DECLARE a_cursor2 CURSOR FOR
913 WHERE type = 'PALLADIUM';
914 EXEC SQL OPEN a_cursor2;
916 EXEC SQL FETCH a_cursor2 INTO :name, :trans;
917 if (sqlca.sqlcode != 0) break;
920 fprintf(out, "%s.palladium\tHS %s \"%s\"\n", name, HTYPE, trans);
922 EXEC SQL CLOSE a_cursor2;
927 EXEC SQL COMMIT WORK;
931 fprintf(stderr, "Unsuccessful close of palladium.db\n");
937 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
938 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
947 char outf[64], outft[64], *mach;
950 EXEC SQL BEGIN DECLARE SECTION;
952 int flag1, flag2, id;
953 EXEC SQL END DECLARE SECTION;
955 sprintf(outf, "%s/sloc.db", hesiod_dir);
957 if (stat(outf, &sb) == 0) {
959 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
960 (ModDiff (&flag2, "machine", ftime))) exit (MR_DATE);
961 if (flag1 < 0 && flag2 < 0) {
962 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
967 sprintf(outft, "%s~", outf);
968 out = fopen(outft, "w");
970 perror("cannot open sloc.db for write");
974 fprintf(stderr, "Building sloc.db\n");
977 EXEC SQL DECLARE s_cursor CURSOR FOR
978 SELECT DISTINCT service, mach_id
981 EXEC SQL OPEN s_cursor;
983 EXEC SQL FETCH s_cursor INTO :service, :id;
984 if (sqlca.sqlcode != 0) break;
986 if (mach = hash_lookup(machines, id))
987 fprintf(out, "%s.sloc\tHS %s %s\n", service, HTYPE, mach);
989 EXEC SQL CLOSE s_cursor;
994 EXEC SQL COMMIT WORK;
998 fprintf(stderr, "Unsuccessful close of sloc.db\n");
1005 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
1006 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
1008 exit(MR_INGRES_ERR);
1014 char outf[64], outft[64];
1017 EXEC SQL BEGIN DECLARE SECTION;
1018 char service[33], protocol[9], altserv[129];
1020 EXEC SQL END DECLARE SECTION;
1022 sprintf(outf, "%s/service.db", hesiod_dir);
1024 if (stat(outf, &sb) == 0) {
1025 ftime = sb.st_mtime;
1026 if (ModDiff (&flag1, "services", ftime)) exit (MR_DATE);
1028 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
1033 sprintf(outft, "%s~", outf);
1034 out = fopen(outft, "w");
1036 perror("cannot open service.db for write");
1040 fprintf(stderr, "Building service.db\n");
1042 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1043 SELECT name, protocol, port
1045 EXEC SQL OPEN s_cursor2;
1047 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1048 if (sqlca.sqlcode != 0) break;
1049 lowercase(protocol); /* Convert protocol to lowercase */
1052 fprintf(out, "%s.service\tHS %s \"%s %s %d\"\n",
1053 service, HTYPE, service, protocol, port);
1055 EXEC SQL CLOSE s_cursor2;
1057 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1060 WHERE type = 'SERVICE';
1061 EXEC SQL OPEN a_cursor3;
1063 EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
1064 if (sqlca.sqlcode != 0) break;
1067 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
1069 EXEC SQL CLOSE a_cursor3;
1074 EXEC SQL COMMIT WORK;
1078 fprintf(stderr, "Unsuccessful close of service.db\n");
1084 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
1085 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
1087 exit(MR_INGRES_ERR);