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-1998 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
12 #include <mit-copyright.h>
14 #include <moira_site.h>
24 EXEC SQL INCLUDE sqlca;
36 #define HESIOD_SUBDIR "hesiod"
39 /* max number of bytes of a data record that can be returned in a hesiod
40 * query. This is 512 - overhead (~66) [derived empirically]
42 #define MAXHESSIZE 446
44 char hesiod_dir[MAXPATHLEN];
46 #define min(x, y) ((x) < (y) ? (x) : (y))
47 struct hash *machines = NULL;
48 struct hash *users = NULL;
49 char *whoami = "hesiod.gen";
50 char *db = "moira/moira";
57 char name[USERS_LOGIN_SIZE];
62 * Modified from sys/types.h:
64 int setsize; /* = howmany(setbits, NSETBITS) */
66 typedef long set_mask;
67 #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
69 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
72 #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
73 #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
74 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
75 #define SET_CREATE() (malloc(setsize * sizeof(set_mask)))
76 #define SET_ZERO(p) memset(p, 0, setsize * sizeof(set_mask))
77 #define SET_CMP(p1, p2) (memcmp(p1, p2, setsize * sizeof(set_mask)))
81 int nbitsset(set_mask *set);
82 int valid(char *name);
88 int do_printcap(void);
89 int do_palladium(void);
93 int main(int argc, char **argv)
101 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
105 initialize_sms_error_table();
106 sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR);
108 EXEC SQL CONNECT :db;
110 changed = do_passwd();
111 changed += do_filsys();
112 changed += do_cluster();
113 changed += do_printcap();
114 changed += do_palladium();
115 changed += do_sloc();
116 changed += do_service();
117 changed += do_groups();
121 fprintf(stderr, "No files updated.\n");
122 if (argc == 2 && stat(argv[1], &sb) == 0)
128 fprintf(stderr, "Building tar file.\n");
129 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
140 EXEC SQL BEGIN DECLARE SECTION;
142 char name[MACHINE_NAME_SIZE];
143 EXEC SQL END DECLARE SECTION;
148 machines = create_hash(1000);
149 EXEC SQL DECLARE m_cursor CURSOR FOR
152 WHERE status = 1 and mach_id != 0
154 EXEC SQL OPEN m_cursor;
157 EXEC SQL FETCH m_cursor INTO :name, :id;
163 hash_store(machines, id, strdup(name));
165 if (sqlca.sqlcode < 0)
166 db_error(sqlca.sqlcode);
167 EXEC SQL CLOSE m_cursor;
172 /* Determine whether or not a name is a valid DNS label.
173 (Can't start or end with . or have two .s in a row) */
174 int valid(char *name)
178 for (sawdot = 1; *name; name++)
196 FILE *pout, *uout, *bout;
197 char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
198 char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
199 struct stat psb, usb, bsb;
203 EXEC SQL BEGIN DECLARE SECTION;
204 char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE];
205 char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE];
206 char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE];
207 char nn[USERS_NICKNAME_SIZE], ptype[USERS_POTYPE_SIZE];
208 int uid, flag1, flag2, id, pid, status;
209 EXEC SQL END DECLARE SECTION;
211 sprintf(poutf, "%s/passwd.db", hesiod_dir);
212 sprintf(uoutf, "%s/uid.db", hesiod_dir);
213 sprintf(boutf, "%s/pobox.db", hesiod_dir);
215 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
216 stat(boutf, &bsb) == 0)
218 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
219 if (ModDiff (&flag1, "users", ftime) ||
220 ModDiff (&flag2, "machine", ftime))
222 if (flag1 < 0 && flag2 < 0)
224 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db "
225 "do not need to be rebuilt.\n");
230 sprintf(poutft, "%s~", poutf);
231 pout = fopen(poutft, "w");
234 perror("cannot open passwd.db~ for write");
237 sprintf(uoutft, "%s~", uoutf);
238 uout = fopen(uoutft, "w");
241 perror("cannot open uid.db~ for write");
244 sprintf(boutft, "%s~", boutf);
245 bout = fopen(boutft, "w");
248 perror("cannot open pobox.db for write");
252 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
255 users = create_hash(12001);
256 EXEC SQL DECLARE u_cursor CURSOR FOR
257 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
258 office_phone, home_phone, users_id, pop_id, potype, status
260 WHERE status = 1 OR status = 2 OR status = 5 OR status = 6
262 EXEC SQL OPEN u_cursor;
265 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
266 :oa, :op, :hp, :id, :pid, :ptype, :status;
276 u = malloc(sizeof(struct user));
277 strcpy(u->name, login);
279 hash_store(users, id, u);
282 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
283 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
284 op, hp, login, shell);
285 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
287 if (pid != 0 && (mach = hash_lookup(machines, pid)))
289 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
290 login, HCLASS, HTYPE, mach, login);
293 if (sqlca.sqlcode < 0)
294 db_error(sqlca.sqlcode);
295 EXEC SQL CLOSE u_cursor;
298 if (fclose(pout) || fclose(uout) || fclose(bout))
300 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
312 FILE *iout, *gout, *lout;
313 char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
314 char buf[MAXPATHLEN], *l;
316 struct bucket *b, **p;
319 struct stat isb, gsb, lsb;
321 EXEC SQL BEGIN DECLARE SECTION;
322 char name[LIST_NAME_SIZE];
323 int gid, id, lid, flag1, flag2, flag3, len;
324 EXEC SQL END DECLARE SECTION;
327 sprintf(ioutf, "%s/gid.db", hesiod_dir);
328 sprintf(goutf, "%s/group.db", hesiod_dir);
329 sprintf(loutf, "%s/grplist.db", hesiod_dir);
331 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 &&
332 stat(loutf, &lsb) == 0)
334 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
335 if (ModDiff (&flag1, "users", ftime) ||
336 ModDiff (&flag2, "list", ftime) ||
337 ModDiff (&flag3, "imembers", ftime))
339 if (flag1 < 0 && flag2 < 0 && flag3 < 0)
341 fprintf(stderr, "Files gid.db, group.db and grplist.db "
342 "do not need to be rebuilt.\n");
347 sprintf(buf, "%s~", ioutf);
348 iout = fopen(buf, "w");
351 perror("cannot open gid.db for write");
354 sprintf(buf, "%s~", goutf);
355 gout = fopen(buf, "w");
358 perror("cannot open group.db for write");
361 sprintf(buf, "%s~", loutf);
362 lout = fopen(buf, "w");
365 perror("cannot open grplist.db for write");
369 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
371 /* make space for group list */
372 groups = create_hash(15001);
374 /* The following WHENEVER is declarative, not executed,
375 * and applies for the remainder of this file only.
377 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
379 EXEC SQL DECLARE l_cursor CURSOR FOR
380 SELECT name, gid, list_id
382 WHERE grouplist != 0 AND active != 0
384 EXEC SQL OPEN l_cursor;
387 char buf[LIST_NAME_SIZE + 10];
389 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
395 sprintf(buf, "%s:%d", name, gid);
396 hash_store(groups, lid, strdup(buf));
397 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
398 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
399 name, HCLASS, HTYPE, name, gid);
401 EXEC SQL CLOSE l_cursor;
406 /* now do grplists */
409 users = create_hash(12001);
410 EXEC SQL DECLARE u_cursor2 CURSOR FOR
411 SELECT users_id, login
413 WHERE status = 1 OR status = 2
415 EXEC SQL OPEN u_cursor2;
418 EXEC SQL FETCH u_cursor2 INTO :id, :name;
421 u = malloc(sizeof(struct user));
422 strcpy(u->name, strtrim(name));
424 hash_store(users, id, u);
426 EXEC SQL CLOSE u_cursor2;
429 EXEC SQL DECLARE i_cursor CURSOR FOR
430 SELECT list_id, member_id
432 WHERE member_type = 'USER'
434 EXEC SQL OPEN i_cursor;
437 EXEC SQL FETCH i_cursor INTO :lid, :id;
440 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
442 g = malloc(sizeof(struct grp));
448 EXEC SQL CLOSE i_cursor;
452 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
454 for (b = *p; b; b = b->next)
456 if (!(g = ((struct user *)b->data)->lists))
458 fprintf(lout, "%s.grplist\t%s %s \"",
459 ((struct user *)b->data)->name, HCLASS, HTYPE);
461 for (; g; g = g->next)
463 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
468 len += strlen(g->lid) + 1;
472 com_err(whoami, 0, "truncated grp list for user %s",
473 ((struct user *)b->data)->name);
481 if (fclose(iout) || fclose(gout) || fclose(lout))
483 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
491 db_error(sqlca.sqlcode);
499 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
502 struct save_queue *sq, *sq2;
503 EXEC SQL BEGIN DECLARE SECTION;
504 char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
505 char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
506 char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
507 char key[FSGROUP_KEY_SIZE];
508 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
509 int flag1, flag2, flag3, flag4, id, fid;
510 EXEC SQL END DECLARE SECTION;
512 sprintf(outf, "%s/filsys.db", hesiod_dir);
514 if (stat(outf, &sb) == 0)
518 if (ModDiff(&flag1, "filesys", ftime))
520 if (ModDiff(&flag2, "machine", ftime))
522 if (ModDiff(&flag3, "alias", ftime))
524 if (ModDiff(&flag4, "fsgroup", ftime))
527 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
529 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
534 sprintf(outft, "%s~", outf);
535 out = fopen(outft, "w");
538 perror("cannot open filsys.db for write");
542 fprintf(stderr, "Building filsys.db\n");
547 EXEC SQL DECLARE f_cursor CURSOR FOR
548 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
551 EXEC SQL OPEN f_cursor;
554 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
555 :mount, :comments, :fid;
562 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
564 if ((mach = hash_lookup(machines, id)))
566 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
567 name, HCLASS, HTYPE, type, strtrim(loc),
568 mach, strtrim(access), strtrim(mount));
571 else if (!strcmp(type, "AFS"))
573 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
574 name, HCLASS, HTYPE, strtrim(loc),
575 strtrim(access), strtrim(mount));
577 else if (!strcmp(type, "ERR"))
579 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
580 name, HCLASS, HTYPE, strtrim(comments));
582 else if (!strcmp(type, "FSGROUP"))
584 char buf[FILESYS_NAME_SIZE + 10];
585 sprintf(buf, "%s:%d", name, fid);
586 sq_save_data(sq, strdup(buf));
588 else if (!strcmp(type, "MUL"))
590 char buf[FILESYS_NAME_SIZE + 10];
591 sprintf(buf, "%s:%d", name, fid);
592 sq_save_data(sq2, strdup(buf));
595 EXEC SQL CLOSE f_cursor;
597 while (sq_get_data(sq, &group))
599 fid = atoi(strchr(group, ':') + 1);
600 *strchr(group, ':') = 0;
602 EXEC SQL DECLARE f_cursor2 CURSOR FOR
603 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
604 f.comments, f.label, g.key
605 FROM filesys f, fsgroup g
606 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
608 EXEC SQL OPEN f_cursor2;
609 for (flag1 = 1; ; flag1++)
611 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
612 :comments, :name, :key;
616 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
618 if ((mach = hash_lookup(machines, id)))
620 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
621 group, HCLASS, HTYPE, type, strtrim(loc), mach,
622 strtrim(access), strtrim(mount), flag1);
625 else if (!strcmp(type, "AFS"))
627 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
628 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
629 strtrim(mount), flag1);
631 else if (!strcmp(type, "ERR"))
633 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
634 group, HCLASS, HTYPE, strtrim(comments));
637 EXEC SQL CLOSE f_cursor2;
642 while (sq_get_data(sq2, &group))
644 fid = atoi(strchr(group, ':') + 1);
645 *strchr(group, ':') = 0;
646 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
647 EXEC SQL DECLARE f_cursor3 CURSOR FOR
648 SELECT DISTINCT f.label, g.key
649 FROM filesys f, fsgroup g
650 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
652 EXEC SQL OPEN f_cursor3;
655 EXEC SQL FETCH f_cursor3 INTO :name, :key;
658 fprintf(out, " %s", strtrim(name));
660 EXEC SQL CLOSE f_cursor3;
661 fprintf(out, "\"\n");
666 EXEC SQL DECLARE a_cursor CURSOR FOR
669 WHERE type = 'FILESYS';
670 EXEC SQL OPEN a_cursor;
673 EXEC SQL FETCH a_cursor INTO :aname, :trans;
678 if (!valid(aname) || !valid(trans))
680 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
681 aname, HCLASS, trans);
683 EXEC SQL CLOSE a_cursor;
689 fprintf(stderr, "Unsuccessful close of filsys.db\n");
695 db_error(sqlca.sqlcode);
699 int nbitsset(set_mask *set)
703 for (i = 0; i < setsize * NSETBITS; i++)
705 if (SET_ISSET(i, set))
715 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
716 char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
719 EXEC SQL BEGIN DECLARE SECTION;
720 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
721 char name[CLUSTERS_NAME_SIZE];
722 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
723 EXEC SQL END DECLARE SECTION;
724 set_mask **machs, *ms, *ps;
726 sprintf(outf, "%s/cluster.db", hesiod_dir);
728 if (stat(outf, &sb) == 0)
731 if (ModDiff (&flag1, "clusters", ftime)
732 || ModDiff (&flag2, "machine", ftime)
733 || ModDiff (&flag3, "mcmap", ftime)
734 || ModDiff (&flag4, "svc", ftime))
736 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
738 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
743 sprintf(outft, "%s~", outf);
744 out = fopen(outft, "w");
747 perror("cannot open cluster.db for write");
751 fprintf(stderr, "Building cluster.db\n");
754 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
756 setsize = howmany(maxclu, NSETBITS);
758 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
760 machs = malloc((maxmach + 1) * sizeof(set_mask **));
761 memset(machs, 0, (maxmach + 1) * sizeof(int));
763 EXEC SQL DECLARE p_cursor CURSOR FOR
764 SELECT mach_id, clu_id
767 EXEC SQL OPEN p_cursor;
770 EXEC SQL FETCH p_cursor INTO :mid, :cid;
773 if (!(ms = machs[mid]))
775 ms = machs[mid] = SET_CREATE();
780 EXEC SQL CLOSE p_cursor;
782 for (mid = 1; mid < maxmach; mid++)
787 if (nbitsset(ms) > 1)
789 sprintf(clubuf, "mrinternal-%d", mid);
790 for (cid = 1; cid < maxclu; cid++)
792 if (SET_ISSET(cid, ms))
794 EXEC SQL DECLARE d_cursor CURSOR FOR
795 SELECT serv_label, serv_cluster
798 EXEC SQL OPEN d_cursor;
801 EXEC SQL FETCH d_cursor INTO :label, :data;
806 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
807 clubuf, HCLASS, HTYPE, label, data);
809 EXEC SQL CLOSE d_cursor;
815 for (cid = 1; cid < maxclu; cid++)
816 if (SET_ISSET(cid, ms))
819 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
823 strcpy(clubuf, name);
826 if ((mach = hash_lookup(machines, mid)))
828 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
829 mach, HCLASS, clubuf);
830 for (p = machbuf; *mach && *mach != '.'; mach++)
832 if (!strcasecmp(mach, ".mit.edu"))
835 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
836 machbuf, HCLASS, clubuf);
839 for (id = mid + 1; id < maxmach; id++)
841 if ((ps = machs[id]) && !SET_CMP(ms, ps))
845 if ((mach = hash_lookup(machines, id)))
847 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
848 mach, HCLASS, clubuf);
849 for (p = machbuf; *mach && *mach != '.'; mach++)
851 if (!strcasecmp(mach, ".mit.edu"))
854 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
855 machbuf, HCLASS, clubuf);
864 EXEC SQL DECLARE d_cursor2 CURSOR FOR
865 SELECT c.name, d.serv_label, d.serv_cluster
866 FROM svc d, clusters c
867 WHERE c.clu_id = d.clu_id;
868 EXEC SQL OPEN d_cursor2;
871 EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
879 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
880 name, HCLASS, HTYPE, label, data);
887 fprintf(stderr, "Unsuccessful close of cluster.db\n");
893 db_error(sqlca.sqlcode);
898 int do_printcap(void)
901 char outf[MAXPATHLEN], outft[MAXPATHLEN];
904 EXEC SQL BEGIN DECLARE SECTION;
905 char name[PRINTCAP_NAME_SIZE], rp[PRINTCAP_RP_SIZE], sd[PRINTCAP_DIR_SIZE];
906 int flag1, flag2, ka, pc, rm, rq;
907 EXEC SQL END DECLARE SECTION;
909 sprintf(outf, "%s/printcap.db", hesiod_dir);
911 if (stat(outf, &sb) == 0)
914 if (ModDiff (&flag1, "printcap", ftime)
915 || ModDiff (&flag2, "machine", ftime))
917 if (flag1 < 0 && flag2 < 0)
919 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
924 sprintf(outft, "%s~", outf);
925 out = fopen(outft, "w");
928 perror("cannot open printcap.db for write");
932 fprintf(stderr, "Building printcap.db\n");
935 EXEC SQL DECLARE p_cursor2 CURSOR FOR
936 SELECT name, rp, dir, mach_id, auth, price, quotaserver
938 EXEC SQL OPEN p_cursor2;
941 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
944 if (!hash_lookup(machines, rm))
951 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
952 name, HCLASS, HTYPE, name, rp, (char *)hash_lookup(machines, rm),
954 if (rq && hash_lookup(machines, rq))
955 fprintf(out, ":rq=%s\"\n", (char *)hash_lookup(machines, rq));
959 EXEC SQL CLOSE p_cursor2;
965 fprintf(stderr, "Unsuccessful close of pcap.db\n");
971 db_error(sqlca.sqlcode);
976 int do_palladium(void)
979 char outf[MAXPATHLEN], outft[MAXPATHLEN];
982 EXEC SQL BEGIN DECLARE SECTION;
983 char name[PALLADIUM_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
984 char aname[ALIAS_NAME_SIZE];
985 int flag, flag1, identifier, rm;
986 EXEC SQL END DECLARE SECTION;
988 sprintf(outf, "%s/palladium.db", hesiod_dir);
990 if (stat(outf, &sb) == 0)
993 if ((ModDiff (&flag, "palladium", ftime)) ||
994 (ModDiff (&flag1, "alias", ftime)))
996 if (flag < 0 && flag1 < 0)
998 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
1003 sprintf(outft, "%s~", outf);
1004 out = fopen(outft, "w");
1007 perror("cannot open palladium.db for write");
1011 fprintf(stderr, "Building palladium.db\n");
1014 EXEC SQL DECLARE p_cursor3 CURSOR FOR
1015 SELECT name, identifier, mach_id
1017 EXEC SQL OPEN p_cursor3;
1020 EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm;
1023 if (!hash_lookup(machines, rm))
1028 fprintf(out, "%s.palladium\t%s %s \"%s %d %s interface directory\"\n",
1029 name, HCLASS, HTYPE, (char *)hash_lookup(machines, rm),
1032 EXEC SQL CLOSE p_cursor3;
1034 EXEC SQL DECLARE a_cursor2 CURSOR FOR
1037 WHERE type = 'PALLADIUM';
1038 EXEC SQL OPEN a_cursor2;
1041 EXEC SQL FETCH a_cursor2 INTO :aname, :trans;
1048 fprintf(out, "%s.palladium\t%s %s \"%s\"\n",
1049 aname, HCLASS, HTYPE, trans);
1051 EXEC SQL CLOSE a_cursor2;
1057 fprintf(stderr, "Unsuccessful close of palladium.db\n");
1063 db_error(sqlca.sqlcode);
1071 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
1074 EXEC SQL BEGIN DECLARE SECTION;
1075 char service[SERVERHOSTS_SERVICE_SIZE];
1076 int flag1, flag2, id;
1077 EXEC SQL END DECLARE SECTION;
1079 sprintf(outf, "%s/sloc.db", hesiod_dir);
1081 if (stat(outf, &sb) == 0)
1083 ftime = sb.st_mtime;
1084 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
1085 (ModDiff (&flag2, "machine", ftime)))
1087 if (flag1 < 0 && flag2 < 0)
1089 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
1094 sprintf(outft, "%s~", outf);
1095 out = fopen(outft, "w");
1098 perror("cannot open sloc.db for write");
1102 fprintf(stderr, "Building sloc.db\n");
1105 EXEC SQL DECLARE s_cursor CURSOR FOR
1106 SELECT DISTINCT service, mach_id
1109 EXEC SQL OPEN s_cursor;
1112 EXEC SQL FETCH s_cursor INTO :service, :id;
1116 if (valid(service) && (mach = hash_lookup(machines, id)))
1117 fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
1119 EXEC SQL CLOSE s_cursor;
1125 fprintf(stderr, "Unsuccessful close of sloc.db\n");
1132 db_error(sqlca.sqlcode);
1136 int do_service(void)
1139 char outf[MAXPATHLEN], outft[MAXPATHLEN];
1142 EXEC SQL BEGIN DECLARE SECTION;
1143 char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE];
1144 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
1146 EXEC SQL END DECLARE SECTION;
1148 sprintf(outf, "%s/service.db", hesiod_dir);
1150 if (stat(outf, &sb) == 0)
1152 ftime = sb.st_mtime;
1153 if (ModDiff (&flag1, "services", ftime))
1157 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
1162 sprintf(outft, "%s~", outf);
1163 out = fopen(outft, "w");
1166 perror("cannot open service.db for write");
1170 fprintf(stderr, "Building service.db\n");
1172 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1173 SELECT name, protocol, port
1175 EXEC SQL OPEN s_cursor2;
1178 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1181 lowercase(protocol); /* Convert protocol to lowercase */
1183 if (!valid(service))
1186 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1187 service, HCLASS, HTYPE, service, protocol, port);
1189 EXEC SQL CLOSE s_cursor2;
1191 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1194 WHERE type = 'SERVICE';
1195 EXEC SQL OPEN a_cursor3;
1198 EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
1203 if (!valid(aname) || !valid(trans))
1205 fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
1208 EXEC SQL CLOSE a_cursor3;
1214 fprintf(stderr, "Unsuccessful close of service.db\n");
1220 db_error(sqlca.sqlcode);