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"
31 #define min(x,y) ((x) < (y) ? (x) : (y))
32 struct hash *machines = NULL;
33 struct hash *users = NULL;
34 char *whoami = "hesiod.gen";
46 char *malloc(), *strsave();
58 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
62 initialize_sms_error_table ();
63 sprintf(hesiod_dir, "%s/hesiod", DCM_DIR);
66 EXEC SQL CONNECT moira;
67 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
70 EXEC SQL DATABASE moira;
73 changed = do_passwd();
74 changed += do_filsys();
75 changed += do_cluster();
76 changed += do_printcap();
77 changed += do_palladium();
79 changed += do_service();
80 changed += do_groups();
86 EXEC SQL CLOSE DATABASE;
90 fprintf(stderr, "No files updated.\n");
91 if (argc == 2 && stat(argv[1], &sb) == 0)
96 fprintf(stderr, "Building tar file.\n");
97 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
108 EXEC SQL BEGIN DECLARE SECTION;
111 EXEC SQL END DECLARE SECTION;
116 machines = create_hash(1000);
117 EXEC SQL DECLARE m_cursor CURSOR FOR
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) {
128 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
129 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
133 EXEC SQL CLOSE m_cursor;
138 EXEC SQL COMMIT WORK;
145 FILE *pout, *uout, *bout;
146 char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
147 struct stat psb, usb, bsb;
151 EXEC SQL BEGIN DECLARE SECTION;
152 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
153 char nn[17], ptype[9];
154 int uid, flag1, flag2, id, pid, status;
155 EXEC SQL END DECLARE SECTION;
157 sprintf(poutf, "%s/passwd.db", hesiod_dir);
158 sprintf(uoutf, "%s/uid.db", hesiod_dir);
159 sprintf(boutf, "%s/pobox.db", hesiod_dir);
161 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
162 stat(boutf, &bsb) == 0) {
163 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
164 if (ModDiff (&flag1, "users", ftime) ||
165 ModDiff (&flag2, "machine", ftime))
167 if (flag1 < 0 && flag2 < 0) {
168 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
173 sprintf(poutft, "%s~", poutf);
174 pout = fopen(poutft, "w");
176 perror("cannot open passwd.db~ for write");
179 sprintf(uoutft, "%s~", uoutf);
180 uout = fopen(uoutft, "w");
182 perror("cannot open uid.db~ for write");
185 sprintf(boutft, "%s~", boutf);
186 bout = fopen(boutft, "w");
188 perror("cannot open pobox.db for write");
192 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
195 users = create_hash(12001);
196 EXEC SQL DECLARE u_cursor CURSOR FOR
197 SELECT login, uid, shell, fullname, nickname, office_addr,
198 office_phone, home_phone, users_id, pop_id, potype, status
200 WHERE status = 1 or status = 5 or status = 6
202 EXEC SQL OPEN u_cursor;
204 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
205 :oa, :op, :hp, :id, :pid, :ptype, :status;
206 if (sqlca.sqlcode != 0) break;
214 u = (struct user *) malloc(sizeof(struct user));
215 strcpy(u->name, login);
217 hash_store(users, id, u);
219 fprintf(pout, "%s.passwd\tHS %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
220 login, HTYPE, login, uid, fullname, nn, oa, op, hp,
222 fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login);
224 if (ptype[0] == 'P' && (mach = hash_lookup(machines, pid))) {
225 fprintf(bout, "%s.pobox\tHS %s \"POP %s %s\"\n",
226 login, HTYPE, mach, login);
229 if (sqlca.sqlcode < 0) {
230 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
231 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
235 EXEC SQL CLOSE u_cursor;
240 EXEC SQL COMMIT WORK;
243 if (fclose(pout) || fclose(uout) || fclose(bout)) {
244 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
256 FILE *iout, *gout, *lout;
257 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
259 register struct bucket *b, **p;
262 struct stat isb, gsb, lsb;
264 EXEC SQL BEGIN DECLARE SECTION;
266 int gid, id, lid, flag1, flag2, flag3;
267 EXEC SQL END DECLARE SECTION;
270 sprintf(ioutf, "%s/gid.db", hesiod_dir);
271 sprintf(goutf, "%s/group.db", hesiod_dir);
272 sprintf(loutf, "%s/grplist.db", hesiod_dir);
274 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
275 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
276 if (ModDiff (&flag1, "users", ftime) ||
277 ModDiff (&flag2, "list", ftime) ||
278 ModDiff (&flag3, "imembers", ftime))
280 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
281 fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
286 sprintf(buf, "%s~", ioutf);
287 iout = fopen(buf, "w");
289 perror("cannot open gid.db for write");
292 sprintf(buf, "%s~", goutf);
293 gout = fopen(buf, "w");
295 perror("cannot open group.db for write");
298 sprintf(buf, "%s~", loutf);
299 lout = fopen(buf, "w");
301 perror("cannot open grplist.db for write");
305 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
307 /* make space for group list */
308 groups = create_hash(15001);
310 /* The following WHENEVER is declarative, not executed,
311 * and applies for the remainder of this file only.
313 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
315 /* get lock records */
316 EXEC SQL SELECT modtime INTO :name FROM list WHERE list_id = 0;
317 EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0;
319 EXEC SQL DECLARE l_cursor CURSOR FOR
320 SELECT name, gid, list_id
322 WHERE grouplist != 0 AND active != 0
324 EXEC SQL OPEN l_cursor;
326 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
327 if (sqlca.sqlcode != 0) break;
329 sprintf(buf, "%s:%d", name, gid);
330 hash_store(groups, lid, strsave(buf));
331 fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
332 fprintf(gout, "%s.group\tHS %s \"%s:*:%d:\"\n",
333 name, HTYPE, name, gid);
335 EXEC SQL CLOSE l_cursor;
340 /* now do grplists */
342 users = create_hash(12001);
343 EXEC SQL DECLARE u_cursor2 CURSOR FOR
344 SELECT users_id, login
348 EXEC SQL OPEN u_cursor2;
350 EXEC SQL FETCH u_cursor2 INTO :id, :name;
351 if (sqlca.sqlcode != 0) break;
352 u = (struct user *) malloc(sizeof(struct user));
353 strcpy(u->name, strtrim(name));
355 hash_store(users, id, u);
357 EXEC SQL CLOSE u_cursor2;
360 EXEC SQL DECLARE i_cursor CURSOR FOR
361 SELECT list_id, member_id
363 WHERE member_type = 'USER'
365 EXEC SQL OPEN i_cursor;
367 EXEC SQL FETCH i_cursor INTO :lid, :id;
368 if (sqlca.sqlcode != 0) break;
369 if (((l = hash_lookup(groups, lid)) != NULL) &&
370 (u = (struct user *) hash_lookup(users, id))) {
371 g = (struct grp *) malloc(sizeof(struct grp));
377 EXEC SQL CLOSE i_cursor;
382 EXEC SQL COMMIT WORK;
385 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
386 for (b = *p; b; b = b->next) {
387 if ((g = ((struct user *)b->data)->lists) == NULL)
389 fprintf(lout, "%s.grplist\tHS %s \"",
390 ((struct user *)b->data)->name, HTYPE);
391 for (; g; g = g->next) {
400 if (fclose(iout) || fclose(gout) || fclose(lout)) {
401 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
409 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
410 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
419 char outf[64], outft[64], *mach, *group;
423 struct save_queue *sq, *sq2, *sq_create();
424 EXEC SQL BEGIN DECLARE SECTION;
425 char name[33], type[9], loc[81], access[2], mount[33], trans[257];
427 int flag1, flag2, flag3, flag4, id, fid;
428 EXEC SQL END DECLARE SECTION;
431 sprintf(outf, "%s/filsys.db", hesiod_dir);
433 if (stat(outf, &sb) == 0) {
436 if (ModDiff(&flag1, "filesys", ftime)) exit (MR_DATE);
437 if (ModDiff(&flag2, "machine", ftime)) exit (MR_DATE);
438 if (ModDiff(&flag3, "alias", ftime)) exit (MR_DATE);
439 if (ModDiff(&flag4, "fsgroup", ftime)) exit (MR_DATE);
441 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
442 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
447 sprintf(outft, "%s~", outf);
448 out = fopen(outft, "w");
450 perror("cannot open filsys.db for write");
454 fprintf(stderr, "Building filsys.db\n");
459 EXEC SQL DECLARE f_cursor CURSOR FOR
460 SELECT label, type, name, mach_id, access, mount, comments, filsys_id
463 EXEC SQL OPEN f_cursor;
465 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
466 :mount, :comments, :fid;
467 if (sqlca.sqlcode != 0) break;
469 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
470 if (mach = hash_lookup(machines, id)) {
471 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
472 strtrim(name), HTYPE, type, strtrim(loc), mach,
473 strtrim(access), strtrim(mount));
475 } else if (!strcmp(type, "AFS")) {
476 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
477 strtrim(name), HTYPE, strtrim(loc), strtrim(access),
479 } else if (!strcmp(type, "ERR")) {
480 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
481 strtrim(name), HTYPE, strtrim(comments));
482 } else if (!strcmp(type, "FSGROUP")) {
483 sprintf(trans, "%s:%d", strtrim(name), fid);
484 sq_save_data(sq, strsave(trans));
485 } else if (!strcmp(type, "MUL")) {
486 sprintf(trans, "%s:%d", strtrim(name), fid);
487 sq_save_data(sq2, strsave(trans));
490 EXEC SQL CLOSE f_cursor;
492 while (sq_get_data(sq, &group)) {
493 fid = atoi(index(group, ':')+1);
494 *index(group, ':') = 0;
496 EXEC SQL DECLARE f_cursor2 CURSOR FOR
497 SELECT DISTINCT f.type, f.name, f.mach_id, f.access, f.mount,
498 f.comments, f.label, g.key
499 FROM filesys f, fsgroup g
500 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
502 EXEC SQL OPEN f_cursor2;
504 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access,:mount,
505 :comments, :name, :trans;
506 if (sqlca.sqlcode != 0) break;
508 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
509 if (mach = hash_lookup(machines, id)) {
510 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
511 group, HTYPE, type, strtrim(loc), mach,
512 strtrim(access), strtrim(mount));
514 } else if (!strcmp(type, "AFS")) {
515 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
516 group, HTYPE, strtrim(loc), strtrim(access),
518 } else if (!strcmp(type, "ERR")) {
519 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
520 group, HTYPE, strtrim(comments));
523 EXEC SQL CLOSE f_cursor2;
528 while (sq_get_data(sq2, &group)) {
529 fid = atoi(index(group, ':') + 1);
530 *index(group, ':') = 0;
531 fprintf(out, "%s.filsys\tHS %s \"MUL", group, HTYPE);
532 EXEC SQL DECLARE f_cursor3 CURSOR FOR
533 SELECT DISTINCT f.label, g.key
534 FROM filesys f, fsgroup g
535 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
537 EXEC SQL OPEN f_cursor3;
539 EXEC SQL FETCH f_cursor3 INTO :name, :trans;
540 if (sqlca.sqlcode != 0) break;
541 fprintf(out, " %s", strtrim(name));
543 EXEC SQL CLOSE f_cursor3;
544 fprintf(out, "\"\n");
549 EXEC SQL DECLARE a_cursor CURSOR FOR
552 WHERE type = 'FILESYS';
553 EXEC SQL OPEN a_cursor;
555 EXEC SQL FETCH a_cursor INTO :name, :trans;
556 if (sqlca.sqlcode != 0) break;
557 fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n",
558 strtrim(name), strtrim(trans));
560 EXEC SQL CLOSE a_cursor;
565 EXEC SQL COMMIT WORK;
569 fprintf(stderr, "Unsuccessful close of filsys.db\n");
575 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
576 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
583 * Modified from sys/types.h:
585 int setsize; /* = howmany(setbits, NSETBITS) */
587 typedef long set_mask;
588 #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
590 #define howmany(x, y) (((x)+((y)-1))/(y))
593 #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
594 #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
595 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
596 #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
597 #define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask))
598 #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
605 for (i = 0; i < setsize * NSETBITS; i++)
606 if (SET_ISSET(i, set))
615 char outf[64], outft[64], *mach, machbuf[33], *p;
618 EXEC SQL BEGIN DECLARE SECTION;
619 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
620 char name[33], label2[17], data[33];
621 EXEC SQL END DECLARE SECTION;
622 set_mask **machs, *ms, *ps;
625 sprintf(outf, "%s/cluster.db", hesiod_dir);
627 if (stat(outf, &sb) == 0) {
629 if (ModDiff (&flag1, "cluster", ftime)
630 || ModDiff (&flag2, "machine", ftime)
631 || ModDiff (&flag3, "mcmap", ftime)
632 || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE);
633 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
634 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
639 sprintf(outft, "%s~", outf);
640 out = fopen(outft, "w");
642 perror("cannot open cluster.db for write");
646 fprintf(stderr, "Building cluster.db\n");
649 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM cluster;
651 setsize = howmany(maxclu, NSETBITS);
653 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
655 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
656 bzero(machs, (maxmach + 1) * sizeof(int));
658 EXEC SQL DECLARE p_cursor CURSOR FOR
659 SELECT mach_id, clu_id
662 EXEC SQL OPEN p_cursor;
664 EXEC SQL FETCH p_cursor INTO :mid, :cid;
665 if (sqlca.sqlcode != 0) break;
666 if (!(ms = machs[mid])) {
667 ms = machs[mid] = SET_CREATE();
672 EXEC SQL CLOSE p_cursor;
674 for (mid = 1; mid < maxmach; mid++) {
678 if (nbitsset(ms) > 1) {
680 for (cid = 1; cid < maxclu; cid++) {
681 if (SET_ISSET(cid, ms)) {
682 EXEC SQL DECLARE d_cursor CURSOR FOR
683 SELECT serv_label, serv_cluster
686 EXEC SQL OPEN d_cursor;
688 EXEC SQL FETCH d_cursor INTO :label2, :data;
689 if (sqlca.sqlcode != 0) break;
693 "mrinternal-%d.cluster\tHS %s \"%s %s\"\n",
694 mid, HTYPE, label2, data);
696 EXEC SQL CLOSE d_cursor;
701 for (cid = 1; cid < maxclu; cid++)
702 if (SET_ISSET(cid, ms)) break;
704 EXEC SQL SELECT name INTO :name FROM cluster WHERE clu_id = :cid;
708 if (mach = hash_lookup(machines, mid)) {
709 for (p = machbuf; *mach && *mach != '.'; mach++)
713 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
716 fprintf(out, "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
719 for (id = mid + 1; id < maxmach; id++) {
720 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
723 if (mach = hash_lookup(machines, id)) {
724 for (p = machbuf; *mach && *mach != '.'; mach++)
728 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
732 "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
741 EXEC SQL DECLARE d_cursor2 CURSOR FOR
742 SELECT c.name, d.serv_label, d.serv_cluster
743 FROM svc d, cluster c
744 WHERE c.clu_id = d.clu_id;
745 EXEC SQL OPEN d_cursor2;
747 EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
748 if (sqlca.sqlcode != 0) break;
752 fprintf(out, "%s.cluster\tHS %s \"%s %s\"\n",
753 name, HTYPE, label2, data);
760 EXEC SQL COMMIT WORK;
764 fprintf(stderr, "Unsuccessful close of cluster.db\n");
770 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
771 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
780 char outf[64], outft[64];
783 EXEC SQL BEGIN DECLARE SECTION;
784 char name[17], rp[17], sd[33];
785 int flag, ka, pc, rm, rq;
786 EXEC SQL END DECLARE SECTION;
788 sprintf(outf, "%s/printcap.db", hesiod_dir);
790 if (stat(outf, &sb) == 0) {
792 if (ModDiff (&flag, "printcap", ftime)) exit (MR_DATE);
794 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
799 sprintf(outft, "%s~", outf);
800 out = fopen(outft, "w");
802 perror("cannot open printcap.db for write");
806 fprintf(stderr, "Building printcap.db\n");
809 EXEC SQL DECLARE p_cursor2 CURSOR FOR
810 SELECT name, rp, dir, mach_id, auth, price, quotaserver
812 EXEC SQL OPEN p_cursor2;
814 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
815 if (sqlca.sqlcode != 0) break;
819 fprintf(out, "%s.pcap\tHS %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
820 name, HTYPE, name, rp, hash_lookup(machines, rm), sd, ka, pc);
822 fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq));
826 EXEC SQL CLOSE p_cursor2;
831 EXEC SQL COMMIT WORK;
835 fprintf(stderr, "Unsuccessful close of pcap.db\n");
841 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
842 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
851 char outf[64], outft[64];
854 EXEC SQL BEGIN DECLARE SECTION;
855 char name[33], trans[129];
856 int flag, flag1, ident, rm;
857 EXEC SQL END DECLARE SECTION;
859 sprintf(outf, "%s/palladium.db", hesiod_dir);
861 if (stat(outf, &sb) == 0) {
863 if ((ModDiff (&flag, "palladium", ftime)) ||
864 (ModDiff (&flag1, "alias", ftime))) exit (MR_DATE);
865 if (flag < 0 && flag1 < 0) {
866 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
871 sprintf(outft, "%s~", outf);
872 out = fopen(outft, "w");
874 perror("cannot open palladium.db for write");
878 fprintf(stderr, "Building palladium.db\n");
881 EXEC SQL DECLARE p_cursor3 CURSOR FOR
882 SELECT name, ident, mach_id
884 EXEC SQL OPEN p_cursor3;
886 EXEC SQL FETCH p_cursor3 INTO :name, :ident, :rm;
887 if (sqlca.sqlcode != 0) break;
890 "%s.palladium\tHS %s \"%s %d %s interface directory\"\n",
891 name, HTYPE, hash_lookup(machines, rm), ident, name);
893 EXEC SQL CLOSE p_cursor3;
895 EXEC SQL DECLARE a_cursor2 CURSOR FOR
898 WHERE type = 'PALLADIUM';
899 EXEC SQL OPEN a_cursor2;
901 EXEC SQL FETCH a_cursor2 INTO :name, :trans;
902 if (sqlca.sqlcode != 0) break;
905 fprintf(out, "%s.palladium\tHS %s \"%s\"\n", name, HTYPE, trans);
907 EXEC SQL CLOSE a_cursor2;
912 EXEC SQL COMMIT WORK;
916 fprintf(stderr, "Unsuccessful close of palladium.db\n");
922 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
923 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
932 char outf[64], outft[64], *mach;
935 EXEC SQL BEGIN DECLARE SECTION;
937 int flag1, flag2, id;
938 EXEC SQL END DECLARE SECTION;
940 sprintf(outf, "%s/sloc.db", hesiod_dir);
942 if (stat(outf, &sb) == 0) {
944 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
945 (ModDiff (&flag2, "machine", ftime))) exit (MR_DATE);
946 if (flag1 < 0 && flag2 < 0) {
947 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
952 sprintf(outft, "%s~", outf);
953 out = fopen(outft, "w");
955 perror("cannot open sloc.db for write");
959 fprintf(stderr, "Building sloc.db\n");
962 EXEC SQL DECLARE s_cursor CURSOR FOR
963 SELECT DISTINCT service, mach_id
966 EXEC SQL OPEN s_cursor;
968 EXEC SQL FETCH s_cursor INTO :service, :id;
969 if (sqlca.sqlcode != 0) break;
971 if (mach = hash_lookup(machines, id))
972 fprintf(out, "%s.sloc\tHS %s %s\n", service, HTYPE, mach);
974 EXEC SQL CLOSE s_cursor;
979 EXEC SQL COMMIT WORK;
983 fprintf(stderr, "Unsuccessful close of sloc.db\n");
990 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
991 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
999 char outf[64], outft[64];
1002 EXEC SQL BEGIN DECLARE SECTION;
1003 char service[33], protocol[9], altserv[129];
1005 EXEC SQL END DECLARE SECTION;
1007 sprintf(outf, "%s/service.db", hesiod_dir);
1009 if (stat(outf, &sb) == 0) {
1010 ftime = sb.st_mtime;
1011 if (ModDiff (&flag1, "services", ftime)) exit (MR_DATE);
1013 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
1018 sprintf(outft, "%s~", outf);
1019 out = fopen(outft, "w");
1021 perror("cannot open service.db for write");
1025 fprintf(stderr, "Building service.db\n");
1027 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1028 SELECT name, protocol, port
1030 EXEC SQL OPEN s_cursor2;
1032 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1033 if (sqlca.sqlcode != 0) break;
1034 lowercase(protocol); /* Convert protocol to lowercase */
1037 fprintf(out, "%s.service\tHS %s \"%s %s %d\"\n",
1038 service, HTYPE, service, protocol, port);
1040 EXEC SQL CLOSE s_cursor2;
1042 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1045 WHERE type = 'SERVICE';
1046 EXEC SQL OPEN a_cursor3;
1048 EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
1049 if (sqlca.sqlcode != 0) break;
1052 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
1054 EXEC SQL CLOSE a_cursor3;
1059 EXEC SQL COMMIT WORK;
1063 fprintf(stderr, "Unsuccessful close of service.db\n");
1069 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
1070 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
1072 exit(MR_INGRES_ERR);