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);
69 EXEC SQL DATABASE sms;
72 changed = do_passwd();
73 changed += do_filsys();
74 changed += do_cluster();
75 changed += do_printcap();
76 changed += do_palladium();
78 changed += do_service();
79 changed += do_groups();
85 EXEC SQL CLOSE DATABASE;
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 EXEC SQL OPEN m_cursor;
121 EXEC SQL FETCH m_cursor INTO :name, :id;
122 if (sqlca.sqlcode != 0) break;
123 hash_store(machines, id, strsave(strtrim(name)));
125 if (sqlca.sqlcode < 0) {
126 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
127 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
131 EXEC SQL CLOSE m_cursor;
135 EXEC SQL COMMIT WORK;
142 FILE *pout, *uout, *bout;
143 char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
144 struct stat psb, usb, bsb;
148 EXEC SQL BEGIN DECLARE SECTION;
149 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
150 char nn[17], ptype[9];
151 int uid, flag1, flag2, id, pid, status;
152 EXEC SQL END DECLARE SECTION;
154 sprintf(poutf, "%s/passwd.db", hesiod_dir);
155 sprintf(uoutf, "%s/uid.db", hesiod_dir);
156 sprintf(boutf, "%s/pobox.db", hesiod_dir);
158 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
159 stat(boutf, &bsb) == 0) {
160 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
161 if (ModDiff (&flag1, "users", ftime) ||
162 ModDiff (&flag2, "machine", ftime))
164 if (flag1 < 0 && flag2 < 0) {
165 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
170 sprintf(poutft, "%s~", poutf);
171 pout = fopen(poutft, "w");
173 perror("cannot open passwd.db~ for write");
176 sprintf(uoutft, "%s~", uoutf);
177 uout = fopen(uoutft, "w");
179 perror("cannot open uid.db~ for write");
182 sprintf(boutft, "%s~", boutf);
183 bout = fopen(boutft, "w");
185 perror("cannot open pobox.db for write");
189 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
192 users = create_hash(12001);
193 EXEC SQL DECLARE u_cursor CURSOR FOR
194 SELECT login, uid, shell, fullname, nickname, office_addr,
195 office_phone, home_phone, users_id, pop_id, potype, status
197 WHERE status = 1 or status = 6;
198 EXEC SQL OPEN u_cursor;
200 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
201 :oa, :op, :hp, :id, :pid, :ptype, :status;
202 if (sqlca.sqlcode != 0) break;
210 u = (struct user *) malloc(sizeof(struct user));
211 strcpy(u->name, login);
213 hash_store(users, id, u);
215 fprintf(pout, "%s.passwd\tHS %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
216 login, HTYPE, login, uid, fullname, nn, oa, op, hp,
218 fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login);
220 if (ptype[0] == 'P' && (mach = hash_lookup(machines, pid))) {
221 fprintf(bout, "%s.pobox\tHS %s \"POP %s %s\"\n",
222 login, HTYPE, mach, login);
225 if (sqlca.sqlcode < 0) {
226 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
227 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
231 EXEC SQL CLOSE u_cursor;
235 EXEC SQL COMMIT WORK;
238 if (fclose(pout) || fclose(uout) || fclose(bout)) {
239 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
251 FILE *iout, *gout, *lout;
252 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
254 register struct bucket *b, **p;
257 struct stat isb, gsb, lsb;
259 EXEC SQL BEGIN DECLARE SECTION;
261 int gid, id, lid, flag1, flag2, flag3;
262 EXEC SQL END DECLARE SECTION;
265 sprintf(ioutf, "%s/gid.db", hesiod_dir);
266 sprintf(goutf, "%s/group.db", hesiod_dir);
267 sprintf(loutf, "%s/grplist.db", hesiod_dir);
269 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
270 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
271 if (ModDiff (&flag1, "users", ftime) ||
272 ModDiff (&flag2, "list", ftime) ||
273 ModDiff (&flag3, "imembers", ftime))
275 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
276 fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
281 sprintf(buf, "%s~", ioutf);
282 iout = fopen(buf, "w");
284 perror("cannot open gid.db for write");
287 sprintf(buf, "%s~", goutf);
288 gout = fopen(buf, "w");
290 perror("cannot open group.db for write");
293 sprintf(buf, "%s~", loutf);
294 lout = fopen(buf, "w");
296 perror("cannot open grplist.db for write");
300 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
302 /* make space for group list */
303 groups = create_hash(15001);
305 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
307 /* get lock records */
308 EXEC SQL SELECT modtime INTO :name FROM list WHERE list_id = 0;
309 EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0;
311 EXEC SQL DECLARE l_cursor CURSOR FOR
312 SELECT name, gid, list_id
314 WHERE grp != 0 AND active != 0;
315 EXEC SQL OPEN l_cursor;
317 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
318 if (sqlca.sqlcode != 0) break;
320 sprintf(buf, "%s:%d", name, gid);
321 hash_store(groups, lid, strsave(buf));
322 fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
323 fprintf(gout, "%s.group\tHS %s \"%s:*:%d:\"\n",
324 name, HTYPE, name, gid);
326 EXEC SQL CLOSE l_cursor;
331 /* now do grplists */
333 users = create_hash(12001);
334 EXEC SQL DECLARE u_cursor2 CURSOR FOR
335 SELECT users_id, login
338 EXEC SQL OPEN u_cursor2;
340 EXEC SQL FETCH u_cursor2 INTO :id, :name;
341 if (sqlca.sqlcode != 0) break;
342 u = (struct user *) malloc(sizeof(struct user));
343 strcpy(u->name, strtrim(name));
345 hash_store(users, id, u);
347 EXEC SQL CLOSE u_cursor2;
350 EXEC SQL DECLARE i_cursor CURSOR FOR
351 SELECT list_id, member_id
353 WHERE member_type = "USER";
354 EXEC SQL OPEN i_cursor;
356 EXEC SQL FETCH i_cursor INTO :lid, :id;
357 if (sqlca.sqlcode != 0) break;
358 if (((l = hash_lookup(groups, lid)) != NULL) &&
359 (u = (struct user *) hash_lookup(users, id))) {
360 g = (struct grp *) malloc(sizeof(struct grp));
366 EXEC SQL CLOSE i_cursor;
370 EXEC SQL COMMIT WORK;
373 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
374 for (b = *p; b; b = b->next) {
375 if ((g = ((struct user *)b->data)->lists) == NULL)
377 fprintf(lout, "%s.grplist\tHS %s \"",
378 ((struct user *)b->data)->name, HTYPE);
379 for (; g; g = g->next) {
388 if (fclose(iout) || fclose(gout) || fclose(lout)) {
389 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
397 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
398 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
407 char outf[64], outft[64], *mach, *group;
411 struct save_queue *sq, *sq_create();
412 EXEC SQL BEGIN DECLARE SECTION;
413 char name[33], type[9], loc[81], access[2], mount[33], trans[257];
415 int flag1, flag2, flag3, flag4, id, fid;
416 EXEC SQL END DECLARE SECTION;
419 sprintf(outf, "%s/filsys.db", hesiod_dir);
421 if (stat(outf, &sb) == 0) {
424 if (ModDiff(&flag1, "filesys", ftime)) exit (MR_DATE);
425 if (ModDiff(&flag2, "machine", ftime)) exit (MR_DATE);
426 if (ModDiff(&flag3, "alias", ftime)) exit (MR_DATE);
427 if (ModDiff(&flag4, "fsgroup", ftime)) exit (MR_DATE);
429 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
430 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
435 sprintf(outft, "%s~", outf);
436 out = fopen(outft, "w");
438 perror("cannot open filsys.db for write");
442 fprintf(stderr, "Building filsys.db\n");
446 EXEC SQL DECLARE f_cursor CURSOR FOR
447 SELECT label, type, name, mach_id, access, mount, comments, filsys_id
449 EXEC SQL OPEN f_cursor;
451 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
452 :mount, :comments, :fid;
453 if (sqlca.sqlcode != 0) break;
455 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
456 if (mach = hash_lookup(machines, id)) {
457 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
458 strtrim(name), HTYPE, type, strtrim(loc), mach,
459 strtrim(access), strtrim(mount));
461 } else if (!strcmp(type, "AFS")) {
462 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
463 strtrim(name), HTYPE, strtrim(loc), strtrim(access),
465 } else if (!strcmp(type, "ERR")) {
466 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
467 strtrim(name), HTYPE, strtrim(comments));
468 } else if (!strcmp(type, "FSGROUP")) {
469 sprintf(trans, "%s:%d", strtrim(name), fid);
470 sq_save_data(sq, strsave(trans));
473 EXEC SQL CLOSE f_cursor;
475 while (sq_get_data(sq, &group)) {
476 fid = atoi(index(group, ':')+1);
477 *index(group, ':') = 0;
479 EXEC SQL DECLARE f_cursor2 CURSOR FOR
480 SELECT DISTINCT f.type, f.name, f.mach_id, f.access, f.mount,
481 f.comments, f.label, g.key
482 FROM filesys f, fsgroup g
483 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
485 EXEC SQL OPEN f_cursor2;
487 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access,:mount,
488 :comments, :name, :trans;
489 if (sqlca.sqlcode != 0) break;
491 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
492 if (mach = hash_lookup(machines, id)) {
493 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
494 group, HTYPE, type, strtrim(loc), mach,
495 strtrim(access), strtrim(mount));
497 } else if (!strcmp(type, "AFS")) {
498 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
499 group, HTYPE, strtrim(loc), strtrim(access),
501 } else if (!strcmp(type, "ERR")) {
502 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
503 group, HTYPE, strtrim(comments));
506 EXEC SQL CLOSE f_cursor2;
511 EXEC SQL DECLARE a_cursor CURSOR FOR
514 WHERE type = "FILESYS";
515 EXEC SQL OPEN a_cursor;
517 EXEC SQL FETCH a_cursor INTO :name, :trans;
518 if (sqlca.sqlcode != 0) break;
519 fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n",
520 strtrim(name), strtrim(trans));
522 EXEC SQL CLOSE a_cursor;
526 EXEC SQL COMMIT WORK;
530 fprintf(stderr, "Unsuccessful close of filsys.db\n");
536 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
537 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
544 * Modified from sys/types.h:
546 int setsize; /* = howmany(setbits, NSETBITS) */
548 typedef long set_mask;
549 #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
551 #define howmany(x, y) (((x)+((y)-1))/(y))
554 #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
555 #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
556 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
557 #define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
558 #define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask))
559 #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
566 for (i = 0; i < setsize * NSETBITS; i++)
567 if (SET_ISSET(i, set))
576 char outf[64], outft[64], *mach, machbuf[33], *p;
579 EXEC SQL BEGIN DECLARE SECTION;
580 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
581 char name[33], label2[17], data[33];
582 EXEC SQL END DECLARE SECTION;
583 set_mask **machs, *ms, *ps;
586 sprintf(outf, "%s/cluster.db", hesiod_dir);
588 if (stat(outf, &sb) == 0) {
590 if (ModDiff (&flag1, "cluster", ftime)
591 || ModDiff (&flag2, "machine", ftime)
592 || ModDiff (&flag3, "mcmap", ftime)
593 || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE);
594 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
595 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
600 sprintf(outft, "%s~", outf);
601 out = fopen(outft, "w");
603 perror("cannot open cluster.db for write");
607 fprintf(stderr, "Building cluster.db\n");
610 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM cluster;
612 setsize = howmany(maxclu, NSETBITS);
614 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
616 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
617 bzero(machs, (maxmach + 1) * sizeof(int));
619 EXEC SQL DECLARE p_cursor CURSOR FOR
620 SELECT mach_id, clu_id
622 EXEC SQL OPEN p_cursor;
624 EXEC SQL FETCH p_cursor INTO :mid, :cid;
625 if (sqlca.sqlcode != 0) break;
626 if (!(ms = machs[mid])) {
627 ms = machs[mid] = SET_CREATE();
632 EXEC SQL CLOSE p_cursor;
634 for (mid = 1; mid < maxmach; mid++) {
638 if (nbitsset(ms) > 1) {
640 for (cid = 1; cid < maxclu; cid++) {
641 if (SET_ISSET(cid, ms)) {
642 EXEC SQL DECLARE d_cursor CURSOR FOR
643 SELECT serv_label, serv_cluster
646 EXEC SQL OPEN d_cursor;
648 EXEC SQL FETCH d_cursor INTO :label2, :data;
649 if (sqlca.sqlcode != 0) break;
653 "mrinternal-%d.cluster\tHS %s \"%s %s\"\n",
654 mid, HTYPE, label2, data);
656 EXEC SQL CLOSE d_cursor;
661 for (cid = 1; cid < maxclu; cid++)
662 if (SET_ISSET(cid, ms)) break;
664 EXEC SQL SELECT name INTO :name FROM cluster WHERE clu_id = :cid;
668 if (mach = hash_lookup(machines, mid)) {
669 for (p = machbuf; *mach && *mach != '.'; mach++)
673 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
676 fprintf(out, "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
679 for (id = mid + 1; id < maxmach; id++) {
680 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
683 if (mach = hash_lookup(machines, id)) {
684 for (p = machbuf; *mach && *mach != '.'; mach++)
688 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
692 "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
701 EXEC SQL DECLARE d_cursor2 CURSOR FOR
702 SELECT c.name, d.serv_label, d.serv_cluster
703 FROM svc d, cluster c
704 WHERE c.clu_id = d.clu_id;
705 EXEC SQL OPEN d_cursor2;
707 EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
708 if (sqlca.sqlcode != 0) break;
712 fprintf(out, "%s.cluster\tHS %s \"%s %s\"\n",
713 name, HTYPE, label2, data);
719 EXEC SQL COMMIT WORK;
723 fprintf(stderr, "Unsuccessful close of cluster.db\n");
729 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
730 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
739 char outf[64], outft[64];
742 EXEC SQL BEGIN DECLARE SECTION;
743 char name[17], rp[17], sd[33];
744 int flag, ka, pc, rm, rq;
745 EXEC SQL END DECLARE SECTION;
747 sprintf(outf, "%s/printcap.db", hesiod_dir);
749 if (stat(outf, &sb) == 0) {
751 if (ModDiff (&flag, "printcap", ftime)) exit (MR_DATE);
753 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
758 sprintf(outft, "%s~", outf);
759 out = fopen(outft, "w");
761 perror("cannot open printcap.db for write");
765 fprintf(stderr, "Building printcap.db\n");
768 EXEC SQL DECLARE p_cursor2 CURSOR FOR
769 SELECT name, rp, dir, mach_id, auth, price, quotaserver
771 EXEC SQL OPEN p_cursor2;
773 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
774 if (sqlca.sqlcode != 0) break;
778 fprintf(out, "%s.pcap\tHS %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
779 name, HTYPE, name, rp, hash_lookup(machines, rm), sd, ka, pc);
781 fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq));
785 EXEC SQL CLOSE p_cursor2;
789 EXEC SQL COMMIT WORK;
793 fprintf(stderr, "Unsuccessful close of pcap.db\n");
799 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
800 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
809 char outf[64], outft[64];
812 EXEC SQL BEGIN DECLARE SECTION;
813 char name[33], trans[129];
814 int flag, flag1, ident, rm;
815 EXEC SQL END DECLARE SECTION;
817 sprintf(outf, "%s/palladium.db", hesiod_dir);
819 if (stat(outf, &sb) == 0) {
821 if ((ModDiff (&flag, "palladium", ftime)) ||
822 (ModDiff (&flag1, "alias", ftime))) exit (MR_DATE);
823 if (flag < 0 && flag1 < 0) {
824 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
829 sprintf(outft, "%s~", outf);
830 out = fopen(outft, "w");
832 perror("cannot open palladium.db for write");
836 fprintf(stderr, "Building palladium.db\n");
839 EXEC SQL DECLARE p_cursor3 CURSOR FOR
840 SELECT name, ident, mach_id
842 EXEC SQL OPEN p_cursor3;
844 EXEC SQL FETCH p_cursor3 INTO :name, :ident, :rm;
845 if (sqlca.sqlcode != 0) break;
848 "%s.palladium\tHS %s \"%s %d %s interface directory\"\n",
849 name, HTYPE, hash_lookup(machines, rm), ident, name);
851 EXEC SQL CLOSE p_cursor3;
853 EXEC SQL DECLARE a_cursor2 CURSOR FOR
856 WHERE type = "PALLADIUM";
857 EXEC SQL OPEN a_cursor2;
859 EXEC SQL FETCH a_cursor2 INTO :name, :trans;
860 if (sqlca.sqlcode != 0) break;
863 fprintf(out, "%s.palladium\tHS %s \"%s\"\n", name, HTYPE, trans);
865 EXEC SQL CLOSE a_cursor2;
869 EXEC SQL COMMIT WORK;
873 fprintf(stderr, "Unsuccessful close of palladium.db\n");
879 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
880 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
889 char outf[64], outft[64], *mach;
892 EXEC SQL BEGIN DECLARE SECTION;
894 int flag1, flag2, id;
895 EXEC SQL END DECLARE SECTION;
897 sprintf(outf, "%s/sloc.db", hesiod_dir);
899 if (stat(outf, &sb) == 0) {
901 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
902 (ModDiff (&flag2, "machine", ftime))) exit (MR_DATE);
903 if (flag1 < 0 && flag2 < 0) {
904 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
909 sprintf(outft, "%s~", outf);
910 out = fopen(outft, "w");
912 perror("cannot open sloc.db for write");
916 fprintf(stderr, "Building sloc.db\n");
919 EXEC SQL DECLARE s_cursor CURSOR FOR
920 SELECT DISTINCT service, mach_id
923 EXEC SQL OPEN s_cursor;
925 EXEC SQL FETCH s_cursor INTO :service, :id;
926 if (sqlca.sqlcode != 0) break;
928 if (mach = hash_lookup(machines, id))
929 fprintf(out, "%s.sloc\tHS %s %s\n", service, HTYPE, mach);
931 EXEC SQL CLOSE s_cursor;
935 EXEC SQL COMMIT WORK;
939 fprintf(stderr, "Unsuccessful close of sloc.db\n");
946 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
947 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
955 char outf[64], outft[64];
958 EXEC SQL BEGIN DECLARE SECTION;
959 char service[33], protocol[9], altserv[129];
961 EXEC SQL END DECLARE SECTION;
963 sprintf(outf, "%s/service.db", hesiod_dir);
965 if (stat(outf, &sb) == 0) {
967 if (ModDiff (&flag1, "services", ftime)) exit (MR_DATE);
969 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
974 sprintf(outft, "%s~", outf);
975 out = fopen(outft, "w");
977 perror("cannot open service.db for write");
981 fprintf(stderr, "Building service.db\n");
983 EXEC SQL DECLARE s_cursor2 CURSOR FOR
984 SELECT name, protocol, port
986 EXEC SQL OPEN s_cursor2;
988 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
989 if (sqlca.sqlcode != 0) break;
990 lowercase(protocol); /* Convert protocol to lowercase */
993 fprintf(out, "%s.service\tHS %s \"%s %s %d\"\n",
994 service, HTYPE, service, protocol, port);
996 EXEC SQL CLOSE s_cursor2;
998 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1001 WHERE type = "SERVICE";
1002 EXEC SQL OPEN a_cursor3;
1004 EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
1005 if (sqlca.sqlcode != 0) break;
1008 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
1010 EXEC SQL CLOSE a_cursor3;
1014 EXEC SQL COMMIT WORK;
1018 fprintf(stderr, "Unsuccessful close of service.db\n");
1024 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
1025 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
1027 exit(MR_INGRES_ERR);