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);
87 int do_printcap(void);
88 int do_palladium(void);
92 int main(int argc, char **argv)
100 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
104 initialize_sms_error_table();
105 sprintf(hesiod_dir, "%s/%s", DCM_DIR, HESIOD_SUBDIR);
107 EXEC SQL CONNECT :db;
109 changed = do_passwd();
110 changed += do_filsys();
111 changed += do_cluster();
112 changed += do_printcap();
113 changed += do_palladium();
114 changed += do_sloc();
115 changed += do_service();
116 changed += do_groups();
120 fprintf(stderr, "No files updated.\n");
121 if (argc == 2 && stat(argv[1], &sb) == 0)
127 fprintf(stderr, "Building tar file.\n");
128 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
139 EXEC SQL BEGIN DECLARE SECTION;
141 char name[MACHINE_NAME_SIZE];
142 EXEC SQL END DECLARE SECTION;
147 machines = create_hash(1000);
148 EXEC SQL DECLARE m_cursor CURSOR FOR
151 WHERE status = 1 and mach_id != 0
153 EXEC SQL OPEN m_cursor;
156 EXEC SQL FETCH m_cursor INTO :name, :id;
159 hash_store(machines, id, strdup(strtrim(name)));
161 if (sqlca.sqlcode < 0)
162 db_error(sqlca.sqlcode);
163 EXEC SQL CLOSE m_cursor;
170 FILE *pout, *uout, *bout;
171 char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
172 char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
173 struct stat psb, usb, bsb;
177 EXEC SQL BEGIN DECLARE SECTION;
178 char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE];
179 char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE];
180 char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE];
181 char nn[USERS_NICKNAME_SIZE], ptype[USERS_POTYPE_SIZE];
182 int uid, flag1, flag2, id, pid, status;
183 EXEC SQL END DECLARE SECTION;
185 sprintf(poutf, "%s/passwd.db", hesiod_dir);
186 sprintf(uoutf, "%s/uid.db", hesiod_dir);
187 sprintf(boutf, "%s/pobox.db", hesiod_dir);
189 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
190 stat(boutf, &bsb) == 0)
192 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
193 if (ModDiff (&flag1, "users", ftime) ||
194 ModDiff (&flag2, "machine", ftime))
196 if (flag1 < 0 && flag2 < 0)
198 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db "
199 "do not need to be rebuilt.\n");
204 sprintf(poutft, "%s~", poutf);
205 pout = fopen(poutft, "w");
208 perror("cannot open passwd.db~ for write");
211 sprintf(uoutft, "%s~", uoutf);
212 uout = fopen(uoutft, "w");
215 perror("cannot open uid.db~ for write");
218 sprintf(boutft, "%s~", boutf);
219 bout = fopen(boutft, "w");
222 perror("cannot open pobox.db for write");
226 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
229 users = create_hash(12001);
230 EXEC SQL DECLARE u_cursor CURSOR FOR
231 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
232 office_phone, home_phone, users_id, pop_id, potype, status
234 WHERE status = 1 or status = 5 or status = 6
236 EXEC SQL OPEN u_cursor;
239 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
240 :oa, :op, :hp, :id, :pid, :ptype, :status;
250 u = malloc(sizeof(struct user));
251 strcpy(u->name, login);
253 hash_store(users, id, u);
256 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
257 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
258 op, hp, login, shell);
259 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
261 if (pid != 0 && (mach = hash_lookup(machines, pid)))
263 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
264 login, HCLASS, HTYPE, mach, login);
267 if (sqlca.sqlcode < 0)
268 db_error(sqlca.sqlcode);
269 EXEC SQL CLOSE u_cursor;
272 if (fclose(pout) || fclose(uout) || fclose(bout))
274 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
286 FILE *iout, *gout, *lout;
287 char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
288 char buf[MAXPATHLEN], *l;
290 struct bucket *b, **p;
293 struct stat isb, gsb, lsb;
295 EXEC SQL BEGIN DECLARE SECTION;
296 char name[LIST_NAME_SIZE];
297 int gid, id, lid, flag1, flag2, flag3, len;
298 EXEC SQL END DECLARE SECTION;
301 sprintf(ioutf, "%s/gid.db", hesiod_dir);
302 sprintf(goutf, "%s/group.db", hesiod_dir);
303 sprintf(loutf, "%s/grplist.db", hesiod_dir);
305 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 &&
306 stat(loutf, &lsb) == 0)
308 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
309 if (ModDiff (&flag1, "users", ftime) ||
310 ModDiff (&flag2, "list", ftime) ||
311 ModDiff (&flag3, "imembers", ftime))
313 if (flag1 < 0 && flag2 < 0 && flag3 < 0)
315 fprintf(stderr, "Files gid.db, group.db and grplist.db "
316 "do not need to be rebuilt.\n");
321 sprintf(buf, "%s~", ioutf);
322 iout = fopen(buf, "w");
325 perror("cannot open gid.db for write");
328 sprintf(buf, "%s~", goutf);
329 gout = fopen(buf, "w");
332 perror("cannot open group.db for write");
335 sprintf(buf, "%s~", loutf);
336 lout = fopen(buf, "w");
339 perror("cannot open grplist.db for write");
343 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
345 /* make space for group list */
346 groups = create_hash(15001);
348 /* The following WHENEVER is declarative, not executed,
349 * and applies for the remainder of this file only.
351 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
353 EXEC SQL DECLARE l_cursor CURSOR FOR
354 SELECT name, gid, list_id
356 WHERE grouplist != 0 AND active != 0
358 EXEC SQL OPEN l_cursor;
361 char buf[LIST_NAME_SIZE + 10];
363 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
367 sprintf(buf, "%s:%d", name, gid);
368 hash_store(groups, lid, strdup(buf));
369 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
370 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
371 name, HCLASS, HTYPE, name, gid);
373 EXEC SQL CLOSE l_cursor;
378 /* now do grplists */
381 users = create_hash(12001);
382 EXEC SQL DECLARE u_cursor2 CURSOR FOR
383 SELECT users_id, login
387 EXEC SQL OPEN u_cursor2;
390 EXEC SQL FETCH u_cursor2 INTO :id, :name;
393 u = malloc(sizeof(struct user));
394 strcpy(u->name, strtrim(name));
396 hash_store(users, id, u);
398 EXEC SQL CLOSE u_cursor2;
401 EXEC SQL DECLARE i_cursor CURSOR FOR
402 SELECT list_id, member_id
404 WHERE member_type = 'USER'
406 EXEC SQL OPEN i_cursor;
409 EXEC SQL FETCH i_cursor INTO :lid, :id;
412 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
414 g = malloc(sizeof(struct grp));
420 EXEC SQL CLOSE i_cursor;
424 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
426 for (b = *p; b; b = b->next)
428 if (!(g = ((struct user *)b->data)->lists))
430 fprintf(lout, "%s.grplist\t%s %s \"",
431 ((struct user *)b->data)->name, HCLASS, HTYPE);
433 for (; g; g = g->next)
435 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
440 len += strlen(g->lid) + 1;
444 com_err(whoami, 0, "truncated grp list for user %s",
445 ((struct user *)b->data)->name);
453 if (fclose(iout) || fclose(gout) || fclose(lout))
455 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
463 db_error(sqlca.sqlcode);
471 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
474 struct save_queue *sq, *sq2;
475 EXEC SQL BEGIN DECLARE SECTION;
476 char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
477 char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
478 char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
479 char key[FSGROUP_KEY_SIZE];
480 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
481 int flag1, flag2, flag3, flag4, id, fid;
482 EXEC SQL END DECLARE SECTION;
484 sprintf(outf, "%s/filsys.db", hesiod_dir);
486 if (stat(outf, &sb) == 0)
490 if (ModDiff(&flag1, "filesys", ftime))
492 if (ModDiff(&flag2, "machine", ftime))
494 if (ModDiff(&flag3, "alias", ftime))
496 if (ModDiff(&flag4, "fsgroup", ftime))
499 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
501 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
506 sprintf(outft, "%s~", outf);
507 out = fopen(outft, "w");
510 perror("cannot open filsys.db for write");
514 fprintf(stderr, "Building filsys.db\n");
519 EXEC SQL DECLARE f_cursor CURSOR FOR
520 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
523 EXEC SQL OPEN f_cursor;
526 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
527 :mount, :comments, :fid;
531 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
533 if ((mach = hash_lookup(machines, id)))
535 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
536 strtrim(name), HCLASS, HTYPE, type, strtrim(loc),
537 mach, strtrim(access), strtrim(mount));
540 else if (!strcmp(type, "AFS"))
542 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
543 strtrim(name), HCLASS, HTYPE, strtrim(loc),
544 strtrim(access), strtrim(mount));
546 else if (!strcmp(type, "ERR"))
548 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
549 strtrim(name), HCLASS, HTYPE, strtrim(comments));
551 else if (!strcmp(type, "FSGROUP"))
553 char buf[FILESYS_NAME_SIZE + 10];
554 sprintf(buf, "%s:%d", strtrim(name), fid);
555 sq_save_data(sq, strdup(buf));
557 else if (!strcmp(type, "MUL"))
559 char buf[FILESYS_NAME_SIZE + 10];
560 sprintf(buf, "%s:%d", strtrim(name), fid);
561 sq_save_data(sq2, strdup(buf));
564 EXEC SQL CLOSE f_cursor;
566 while (sq_get_data(sq, &group))
568 fid = atoi(strchr(group, ':') + 1);
569 *strchr(group, ':') = 0;
571 EXEC SQL DECLARE f_cursor2 CURSOR FOR
572 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
573 f.comments, f.label, g.key
574 FROM filesys f, fsgroup g
575 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
577 EXEC SQL OPEN f_cursor2;
578 for (flag1 = 1; ; flag1++)
580 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
581 :comments, :name, :key;
585 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
587 if ((mach = hash_lookup(machines, id)))
589 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
590 group, HCLASS, HTYPE, type, strtrim(loc), mach,
591 strtrim(access), strtrim(mount), flag1);
594 else if (!strcmp(type, "AFS"))
596 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
597 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
598 strtrim(mount), flag1);
600 else if (!strcmp(type, "ERR"))
602 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
603 group, HCLASS, HTYPE, strtrim(comments));
606 EXEC SQL CLOSE f_cursor2;
611 while (sq_get_data(sq2, &group))
613 fid = atoi(strchr(group, ':') + 1);
614 *strchr(group, ':') = 0;
615 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
616 EXEC SQL DECLARE f_cursor3 CURSOR FOR
617 SELECT DISTINCT f.label, g.key
618 FROM filesys f, fsgroup g
619 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
621 EXEC SQL OPEN f_cursor3;
624 EXEC SQL FETCH f_cursor3 INTO :name, :key;
627 fprintf(out, " %s", strtrim(name));
629 EXEC SQL CLOSE f_cursor3;
630 fprintf(out, "\"\n");
635 EXEC SQL DECLARE a_cursor CURSOR FOR
638 WHERE type = 'FILESYS';
639 EXEC SQL OPEN a_cursor;
642 EXEC SQL FETCH a_cursor INTO :aname, :trans;
645 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
646 strtrim(aname), HCLASS, strtrim(trans));
648 EXEC SQL CLOSE a_cursor;
654 fprintf(stderr, "Unsuccessful close of filsys.db\n");
660 db_error(sqlca.sqlcode);
664 int nbitsset(set_mask *set)
668 for (i = 0; i < setsize * NSETBITS; i++)
670 if (SET_ISSET(i, set))
680 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
681 char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
684 EXEC SQL BEGIN DECLARE SECTION;
685 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
686 char name[CLUSTERS_NAME_SIZE];
687 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
688 EXEC SQL END DECLARE SECTION;
689 set_mask **machs, *ms, *ps;
691 sprintf(outf, "%s/cluster.db", hesiod_dir);
693 if (stat(outf, &sb) == 0)
696 if (ModDiff (&flag1, "clusters", ftime)
697 || ModDiff (&flag2, "machine", ftime)
698 || ModDiff (&flag3, "mcmap", ftime)
699 || ModDiff (&flag4, "svc", ftime))
701 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
703 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
708 sprintf(outft, "%s~", outf);
709 out = fopen(outft, "w");
712 perror("cannot open cluster.db for write");
716 fprintf(stderr, "Building cluster.db\n");
719 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
721 setsize = howmany(maxclu, NSETBITS);
723 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
725 machs = malloc((maxmach + 1) * sizeof(set_mask **));
726 memset(machs, 0, (maxmach + 1) * sizeof(int));
728 EXEC SQL DECLARE p_cursor CURSOR FOR
729 SELECT mach_id, clu_id
732 EXEC SQL OPEN p_cursor;
735 EXEC SQL FETCH p_cursor INTO :mid, :cid;
738 if (!(ms = machs[mid]))
740 ms = machs[mid] = SET_CREATE();
745 EXEC SQL CLOSE p_cursor;
747 for (mid = 1; mid < maxmach; mid++)
752 if (nbitsset(ms) > 1)
754 sprintf(clubuf, "mrinternal-%d", mid);
755 for (cid = 1; cid < maxclu; cid++)
757 if (SET_ISSET(cid, ms))
759 EXEC SQL DECLARE d_cursor CURSOR FOR
760 SELECT serv_label, serv_cluster
763 EXEC SQL OPEN d_cursor;
766 EXEC SQL FETCH d_cursor INTO :label, :data;
771 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
772 clubuf, HCLASS, HTYPE, label, data);
774 EXEC SQL CLOSE d_cursor;
780 for (cid = 1; cid < maxclu; cid++)
781 if (SET_ISSET(cid, ms))
784 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
786 strcpy(clubuf, name);
789 if ((mach = hash_lookup(machines, mid)))
791 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
792 mach, HCLASS, clubuf);
793 for (p = machbuf; *mach && *mach != '.'; mach++)
795 if (!strcasecmp(mach, ".mit.edu"))
798 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
799 machbuf, HCLASS, clubuf);
802 for (id = mid + 1; id < maxmach; id++)
804 if ((ps = machs[id]) && !SET_CMP(ms, ps))
808 if ((mach = hash_lookup(machines, id)))
810 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
811 mach, HCLASS, clubuf);
812 for (p = machbuf; *mach && *mach != '.'; mach++)
814 if (!strcasecmp(mach, ".mit.edu"))
817 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
818 machbuf, HCLASS, clubuf);
827 EXEC SQL DECLARE d_cursor2 CURSOR FOR
828 SELECT c.name, d.serv_label, d.serv_cluster
829 FROM svc d, clusters c
830 WHERE c.clu_id = d.clu_id;
831 EXEC SQL OPEN d_cursor2;
834 EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
840 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
841 name, HCLASS, HTYPE, label, data);
848 fprintf(stderr, "Unsuccessful close of cluster.db\n");
854 db_error(sqlca.sqlcode);
859 int do_printcap(void)
862 char outf[MAXPATHLEN], outft[MAXPATHLEN];
865 EXEC SQL BEGIN DECLARE SECTION;
866 char name[PRINTCAP_NAME_SIZE], rp[PRINTCAP_RP_SIZE], sd[PRINTCAP_DIR_SIZE];
867 int flag1, flag2, ka, pc, rm, rq;
868 EXEC SQL END DECLARE SECTION;
870 sprintf(outf, "%s/printcap.db", hesiod_dir);
872 if (stat(outf, &sb) == 0)
875 if (ModDiff (&flag1, "printcap", ftime)
876 || ModDiff (&flag2, "machine", ftime))
878 if (flag1 < 0 && flag2 < 0)
880 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
885 sprintf(outft, "%s~", outf);
886 out = fopen(outft, "w");
889 perror("cannot open printcap.db for write");
893 fprintf(stderr, "Building printcap.db\n");
896 EXEC SQL DECLARE p_cursor2 CURSOR FOR
897 SELECT name, rp, dir, mach_id, auth, price, quotaserver
899 EXEC SQL OPEN p_cursor2;
902 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
905 if (!hash_lookup(machines, rm))
910 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
911 name, HCLASS, HTYPE, name, rp, (char *)hash_lookup(machines, rm),
913 if (rq && hash_lookup(machines, rq))
914 fprintf(out, ":rq=%s\"\n", (char *)hash_lookup(machines, rq));
918 EXEC SQL CLOSE p_cursor2;
924 fprintf(stderr, "Unsuccessful close of pcap.db\n");
930 db_error(sqlca.sqlcode);
935 int do_palladium(void)
938 char outf[MAXPATHLEN], outft[MAXPATHLEN];
941 EXEC SQL BEGIN DECLARE SECTION;
942 char name[PALLADIUM_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
943 char aname[ALIAS_NAME_SIZE];
944 int flag, flag1, identifier, rm;
945 EXEC SQL END DECLARE SECTION;
947 sprintf(outf, "%s/palladium.db", hesiod_dir);
949 if (stat(outf, &sb) == 0)
952 if ((ModDiff (&flag, "palladium", ftime)) ||
953 (ModDiff (&flag1, "alias", ftime)))
955 if (flag < 0 && flag1 < 0)
957 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
962 sprintf(outft, "%s~", outf);
963 out = fopen(outft, "w");
966 perror("cannot open palladium.db for write");
970 fprintf(stderr, "Building palladium.db\n");
973 EXEC SQL DECLARE p_cursor3 CURSOR FOR
974 SELECT name, identifier, mach_id
976 EXEC SQL OPEN p_cursor3;
979 EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm;
982 if (!hash_lookup(machines, rm))
985 fprintf(out, "%s.palladium\t%s %s \"%s %d %s interface directory\"\n",
986 name, HCLASS, HTYPE, (char *)hash_lookup(machines, rm),
989 EXEC SQL CLOSE p_cursor3;
991 EXEC SQL DECLARE a_cursor2 CURSOR FOR
994 WHERE type = 'PALLADIUM';
995 EXEC SQL OPEN a_cursor2;
998 EXEC SQL FETCH a_cursor2 INTO :aname, :trans;
1003 fprintf(out, "%s.palladium\t%s %s \"%s\"\n",
1004 aname, HCLASS, HTYPE, trans);
1006 EXEC SQL CLOSE a_cursor2;
1012 fprintf(stderr, "Unsuccessful close of palladium.db\n");
1018 db_error(sqlca.sqlcode);
1026 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
1029 EXEC SQL BEGIN DECLARE SECTION;
1030 char service[SERVERHOSTS_SERVICE_SIZE];
1031 int flag1, flag2, id;
1032 EXEC SQL END DECLARE SECTION;
1034 sprintf(outf, "%s/sloc.db", hesiod_dir);
1036 if (stat(outf, &sb) == 0)
1038 ftime = sb.st_mtime;
1039 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
1040 (ModDiff (&flag2, "machine", ftime)))
1042 if (flag1 < 0 && flag2 < 0)
1044 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
1049 sprintf(outft, "%s~", outf);
1050 out = fopen(outft, "w");
1053 perror("cannot open sloc.db for write");
1057 fprintf(stderr, "Building sloc.db\n");
1060 EXEC SQL DECLARE s_cursor CURSOR FOR
1061 SELECT DISTINCT service, mach_id
1064 EXEC SQL OPEN s_cursor;
1067 EXEC SQL FETCH s_cursor INTO :service, :id;
1071 if ((mach = hash_lookup(machines, id)))
1072 fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
1074 EXEC SQL CLOSE s_cursor;
1080 fprintf(stderr, "Unsuccessful close of sloc.db\n");
1087 db_error(sqlca.sqlcode);
1091 int do_service(void)
1094 char outf[MAXPATHLEN], outft[MAXPATHLEN];
1097 EXEC SQL BEGIN DECLARE SECTION;
1098 char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE];
1099 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
1101 EXEC SQL END DECLARE SECTION;
1103 sprintf(outf, "%s/service.db", hesiod_dir);
1105 if (stat(outf, &sb) == 0)
1107 ftime = sb.st_mtime;
1108 if (ModDiff (&flag1, "services", ftime))
1112 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
1117 sprintf(outft, "%s~", outf);
1118 out = fopen(outft, "w");
1121 perror("cannot open service.db for write");
1125 fprintf(stderr, "Building service.db\n");
1127 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1128 SELECT name, protocol, port
1130 EXEC SQL OPEN s_cursor2;
1133 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1136 lowercase(protocol); /* Convert protocol to lowercase */
1139 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1140 service, HCLASS, HTYPE, service, protocol, port);
1142 EXEC SQL CLOSE s_cursor2;
1144 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1147 WHERE type = 'SERVICE';
1148 EXEC SQL OPEN a_cursor3;
1151 EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
1156 fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
1159 EXEC SQL CLOSE a_cursor3;
1165 fprintf(stderr, "Unsuccessful close of service.db\n");
1171 db_error(sqlca.sqlcode);