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
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";
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;
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[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
172 struct stat psb, usb, bsb;
176 EXEC SQL BEGIN DECLARE SECTION;
177 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
178 char nn[17], ptype[9];
179 int uid, flag1, flag2, id, pid, status;
180 EXEC SQL END DECLARE SECTION;
182 sprintf(poutf, "%s/passwd.db", hesiod_dir);
183 sprintf(uoutf, "%s/uid.db", hesiod_dir);
184 sprintf(boutf, "%s/pobox.db", hesiod_dir);
186 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
187 stat(boutf, &bsb) == 0)
189 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
190 if (ModDiff (&flag1, "users", ftime) ||
191 ModDiff (&flag2, "machine", ftime))
193 if (flag1 < 0 && flag2 < 0)
195 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db "
196 "do not need to be rebuilt.\n");
201 sprintf(poutft, "%s~", poutf);
202 pout = fopen(poutft, "w");
205 perror("cannot open passwd.db~ for write");
208 sprintf(uoutft, "%s~", uoutf);
209 uout = fopen(uoutft, "w");
212 perror("cannot open uid.db~ for write");
215 sprintf(boutft, "%s~", boutf);
216 bout = fopen(boutft, "w");
219 perror("cannot open pobox.db for write");
223 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
226 users = create_hash(12001);
227 EXEC SQL DECLARE u_cursor CURSOR FOR
228 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
229 office_phone, home_phone, users_id, pop_id, potype, status
231 WHERE status = 1 or status = 5 or status = 6
233 EXEC SQL OPEN u_cursor;
236 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
237 :oa, :op, :hp, :id, :pid, :ptype, :status;
247 u = malloc(sizeof(struct user));
248 strcpy(u->name, login);
250 hash_store(users, id, u);
253 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
254 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
255 op, hp, login, shell);
256 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
258 if (pid != 0 && (mach = hash_lookup(machines, pid)))
260 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
261 login, HCLASS, HTYPE, mach, login);
264 if (sqlca.sqlcode < 0)
265 db_error(sqlca.sqlcode);
266 EXEC SQL CLOSE u_cursor;
269 if (fclose(pout) || fclose(uout) || fclose(bout))
271 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
283 FILE *iout, *gout, *lout;
284 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
286 struct bucket *b, **p;
289 struct stat isb, gsb, lsb;
291 EXEC SQL BEGIN DECLARE SECTION;
293 int gid, id, lid, flag1, flag2, flag3, len;
294 EXEC SQL END DECLARE SECTION;
297 sprintf(ioutf, "%s/gid.db", hesiod_dir);
298 sprintf(goutf, "%s/group.db", hesiod_dir);
299 sprintf(loutf, "%s/grplist.db", hesiod_dir);
301 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 &&
302 stat(loutf, &lsb) == 0)
304 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
305 if (ModDiff (&flag1, "users", ftime) ||
306 ModDiff (&flag2, "list", ftime) ||
307 ModDiff (&flag3, "imembers", ftime))
309 if (flag1 < 0 && flag2 < 0 && flag3 < 0)
311 fprintf(stderr, "Files gid.db, group.db and grplist.db "
312 "do not need to be rebuilt.\n");
317 sprintf(buf, "%s~", ioutf);
318 iout = fopen(buf, "w");
321 perror("cannot open gid.db for write");
324 sprintf(buf, "%s~", goutf);
325 gout = fopen(buf, "w");
328 perror("cannot open group.db for write");
331 sprintf(buf, "%s~", loutf);
332 lout = fopen(buf, "w");
335 perror("cannot open grplist.db for write");
339 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
341 /* make space for group list */
342 groups = create_hash(15001);
344 /* The following WHENEVER is declarative, not executed,
345 * and applies for the remainder of this file only.
347 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
349 EXEC SQL DECLARE l_cursor CURSOR FOR
350 SELECT name, gid, list_id
352 WHERE grouplist != 0 AND active != 0
354 EXEC SQL OPEN l_cursor;
357 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
361 sprintf(buf, "%s:%d", name, gid);
362 hash_store(groups, lid, strdup(buf));
363 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
364 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
365 name, HCLASS, HTYPE, name, gid);
367 EXEC SQL CLOSE l_cursor;
372 /* now do grplists */
375 users = create_hash(12001);
376 EXEC SQL DECLARE u_cursor2 CURSOR FOR
377 SELECT users_id, login
381 EXEC SQL OPEN u_cursor2;
384 EXEC SQL FETCH u_cursor2 INTO :id, :name;
387 u = malloc(sizeof(struct user));
388 strcpy(u->name, strtrim(name));
390 hash_store(users, id, u);
392 EXEC SQL CLOSE u_cursor2;
395 EXEC SQL DECLARE i_cursor CURSOR FOR
396 SELECT list_id, member_id
398 WHERE member_type = 'USER'
400 EXEC SQL OPEN i_cursor;
403 EXEC SQL FETCH i_cursor INTO :lid, :id;
406 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
408 g = malloc(sizeof(struct grp));
414 EXEC SQL CLOSE i_cursor;
418 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
420 for (b = *p; b; b = b->next)
422 if (!(g = ((struct user *)b->data)->lists))
424 fprintf(lout, "%s.grplist\t%s %s \"",
425 ((struct user *)b->data)->name, HCLASS, HTYPE);
427 for (; g; g = g->next)
429 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
434 len += strlen(g->lid) + 1;
438 com_err(whoami, 0, "truncated grp list for user %s",
439 ((struct user *)b->data)->name);
447 if (fclose(iout) || fclose(gout) || fclose(lout))
449 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
457 db_error(sqlca.sqlcode);
465 char outf[64], outft[64], *mach, *group;
468 struct save_queue *sq, *sq2;
469 EXEC SQL BEGIN DECLARE SECTION;
470 char name[33], type[9], loc[81], access[2], mount[33], trans[257];
472 int flag1, flag2, flag3, flag4, id, fid;
473 EXEC SQL END DECLARE SECTION;
475 sprintf(outf, "%s/filsys.db", hesiod_dir);
477 if (stat(outf, &sb) == 0)
481 if (ModDiff(&flag1, "filesys", ftime))
483 if (ModDiff(&flag2, "machine", ftime))
485 if (ModDiff(&flag3, "alias", ftime))
487 if (ModDiff(&flag4, "fsgroup", ftime))
490 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
492 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
497 sprintf(outft, "%s~", outf);
498 out = fopen(outft, "w");
501 perror("cannot open filsys.db for write");
505 fprintf(stderr, "Building filsys.db\n");
510 EXEC SQL DECLARE f_cursor CURSOR FOR
511 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
514 EXEC SQL OPEN f_cursor;
517 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
518 :mount, :comments, :fid;
522 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
524 if ((mach = hash_lookup(machines, id)))
526 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
527 strtrim(name), HCLASS, HTYPE, type, strtrim(loc),
528 mach, strtrim(access), strtrim(mount));
531 else if (!strcmp(type, "AFS"))
533 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
534 strtrim(name), HCLASS, HTYPE, strtrim(loc),
535 strtrim(access), strtrim(mount));
537 else if (!strcmp(type, "ERR"))
539 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
540 strtrim(name), HCLASS, HTYPE, strtrim(comments));
542 else if (!strcmp(type, "FSGROUP"))
544 sprintf(trans, "%s:%d", strtrim(name), fid);
545 sq_save_data(sq, strdup(trans));
547 else if (!strcmp(type, "MUL"))
549 sprintf(trans, "%s:%d", strtrim(name), fid);
550 sq_save_data(sq2, strdup(trans));
553 EXEC SQL CLOSE f_cursor;
555 while (sq_get_data(sq, &group))
557 fid = atoi(strchr(group, ':') + 1);
558 *strchr(group, ':') = 0;
560 EXEC SQL DECLARE f_cursor2 CURSOR FOR
561 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
562 f.comments, f.label, g.key
563 FROM filesys f, fsgroup g
564 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
566 EXEC SQL OPEN f_cursor2;
567 for (flag1 = 1; ; flag1++)
569 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
570 :comments, :name, :trans;
574 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
576 if ((mach = hash_lookup(machines, id)))
578 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
579 group, HCLASS, HTYPE, type, strtrim(loc), mach,
580 strtrim(access), strtrim(mount), flag1);
583 else if (!strcmp(type, "AFS"))
585 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
586 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
587 strtrim(mount), flag1);
589 else if (!strcmp(type, "ERR"))
591 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
592 group, HCLASS, HTYPE, strtrim(comments));
595 EXEC SQL CLOSE f_cursor2;
600 while (sq_get_data(sq2, &group))
602 fid = atoi(strchr(group, ':') + 1);
603 *strchr(group, ':') = 0;
604 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
605 EXEC SQL DECLARE f_cursor3 CURSOR FOR
606 SELECT DISTINCT f.label, g.key
607 FROM filesys f, fsgroup g
608 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
610 EXEC SQL OPEN f_cursor3;
613 EXEC SQL FETCH f_cursor3 INTO :name, :trans;
616 fprintf(out, " %s", strtrim(name));
618 EXEC SQL CLOSE f_cursor3;
619 fprintf(out, "\"\n");
624 EXEC SQL DECLARE a_cursor CURSOR FOR
627 WHERE type = 'FILESYS';
628 EXEC SQL OPEN a_cursor;
631 EXEC SQL FETCH a_cursor INTO :name, :trans;
634 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
635 strtrim(name), HCLASS, strtrim(trans));
637 EXEC SQL CLOSE a_cursor;
643 fprintf(stderr, "Unsuccessful close of filsys.db\n");
649 db_error(sqlca.sqlcode);
653 int nbitsset(set_mask *set)
657 for (i = 0; i < setsize * NSETBITS; i++)
659 if (SET_ISSET(i, set))
669 char outf[64], outft[64], *mach, machbuf[64], clubuf[64], *p;
672 EXEC SQL BEGIN DECLARE SECTION;
673 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
674 char name[41], label2[17], data[33];
675 EXEC SQL END DECLARE SECTION;
676 set_mask **machs, *ms, *ps;
678 sprintf(outf, "%s/cluster.db", hesiod_dir);
680 if (stat(outf, &sb) == 0)
683 if (ModDiff (&flag1, "clusters", ftime)
684 || ModDiff (&flag2, "machine", ftime)
685 || ModDiff (&flag3, "mcmap", ftime)
686 || ModDiff (&flag4, "svc", ftime))
688 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
690 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
695 sprintf(outft, "%s~", outf);
696 out = fopen(outft, "w");
699 perror("cannot open cluster.db for write");
703 fprintf(stderr, "Building cluster.db\n");
706 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
708 setsize = howmany(maxclu, NSETBITS);
710 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
712 machs = malloc((maxmach + 1) * sizeof(set_mask **));
713 memset(machs, 0, (maxmach + 1) * sizeof(int));
715 EXEC SQL DECLARE p_cursor CURSOR FOR
716 SELECT mach_id, clu_id
719 EXEC SQL OPEN p_cursor;
722 EXEC SQL FETCH p_cursor INTO :mid, :cid;
725 if (!(ms = machs[mid]))
727 ms = machs[mid] = SET_CREATE();
732 EXEC SQL CLOSE p_cursor;
734 for (mid = 1; mid < maxmach; mid++)
739 if (nbitsset(ms) > 1)
741 sprintf(clubuf, "mrinternal-%d", mid);
742 for (cid = 1; cid < maxclu; cid++)
744 if (SET_ISSET(cid, ms))
746 EXEC SQL DECLARE d_cursor CURSOR FOR
747 SELECT serv_label, serv_cluster
750 EXEC SQL OPEN d_cursor;
753 EXEC SQL FETCH d_cursor INTO :label2, :data;
758 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
759 clubuf, HCLASS, HTYPE, label2, data);
761 EXEC SQL CLOSE d_cursor;
767 for (cid = 1; cid < maxclu; cid++)
768 if (SET_ISSET(cid, ms))
771 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
773 strcpy(clubuf, name);
776 if ((mach = hash_lookup(machines, mid)))
778 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
779 mach, HCLASS, clubuf);
780 for (p = machbuf; *mach && *mach != '.'; mach++)
782 if (!strcasecmp(mach, ".mit.edu"))
785 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
786 machbuf, HCLASS, clubuf);
789 for (id = mid + 1; id < maxmach; id++)
791 if ((ps = machs[id]) && !SET_CMP(ms, ps))
795 if ((mach = hash_lookup(machines, id)))
797 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
798 mach, HCLASS, clubuf);
799 for (p = machbuf; *mach && *mach != '.'; mach++)
801 if (!strcasecmp(mach, ".mit.edu"))
804 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
805 machbuf, HCLASS, clubuf);
814 EXEC SQL DECLARE d_cursor2 CURSOR FOR
815 SELECT c.name, d.serv_label, d.serv_cluster
816 FROM svc d, clusters c
817 WHERE c.clu_id = d.clu_id;
818 EXEC SQL OPEN d_cursor2;
821 EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
827 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
828 name, HCLASS, HTYPE, label2, data);
835 fprintf(stderr, "Unsuccessful close of cluster.db\n");
841 db_error(sqlca.sqlcode);
846 int do_printcap(void)
849 char outf[64], outft[64];
852 EXEC SQL BEGIN DECLARE SECTION;
853 char name[17], rp[17], sd[33];
854 int flag1, flag2, ka, pc, rm, rq;
855 EXEC SQL END DECLARE SECTION;
857 sprintf(outf, "%s/printcap.db", hesiod_dir);
859 if (stat(outf, &sb) == 0)
862 if (ModDiff (&flag1, "printcap", ftime)
863 || ModDiff (&flag2, "machine", ftime))
865 if (flag1 < 0 && flag2 < 0)
867 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
872 sprintf(outft, "%s~", outf);
873 out = fopen(outft, "w");
876 perror("cannot open printcap.db for write");
880 fprintf(stderr, "Building printcap.db\n");
883 EXEC SQL DECLARE p_cursor2 CURSOR FOR
884 SELECT name, rp, dir, mach_id, auth, price, quotaserver
886 EXEC SQL OPEN p_cursor2;
889 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
892 if (!hash_lookup(machines, rm))
897 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
898 name, HCLASS, HTYPE, name, rp, (char *)hash_lookup(machines, rm),
900 if (rq && hash_lookup(machines, rq))
901 fprintf(out, ":rq=%s\"\n", (char *)hash_lookup(machines, rq));
905 EXEC SQL CLOSE p_cursor2;
911 fprintf(stderr, "Unsuccessful close of pcap.db\n");
917 db_error(sqlca.sqlcode);
922 int do_palladium(void)
925 char outf[64], outft[64];
928 EXEC SQL BEGIN DECLARE SECTION;
929 char name[33], trans[129];
930 int flag, flag1, identifier, rm;
931 EXEC SQL END DECLARE SECTION;
933 sprintf(outf, "%s/palladium.db", hesiod_dir);
935 if (stat(outf, &sb) == 0)
938 if ((ModDiff (&flag, "palladium", ftime)) ||
939 (ModDiff (&flag1, "alias", ftime)))
941 if (flag < 0 && flag1 < 0)
943 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
948 sprintf(outft, "%s~", outf);
949 out = fopen(outft, "w");
952 perror("cannot open palladium.db for write");
956 fprintf(stderr, "Building palladium.db\n");
959 EXEC SQL DECLARE p_cursor3 CURSOR FOR
960 SELECT name, identifier, mach_id
962 EXEC SQL OPEN p_cursor3;
965 EXEC SQL FETCH p_cursor3 INTO :name, :identifier, :rm;
968 if (!hash_lookup(machines, rm))
971 fprintf(out, "%s.palladium\t%s %s \"%s %d %s interface directory\"\n",
972 name, HCLASS, HTYPE, (char *)hash_lookup(machines, rm),
975 EXEC SQL CLOSE p_cursor3;
977 EXEC SQL DECLARE a_cursor2 CURSOR FOR
980 WHERE type = 'PALLADIUM';
981 EXEC SQL OPEN a_cursor2;
984 EXEC SQL FETCH a_cursor2 INTO :name, :trans;
989 fprintf(out, "%s.palladium\t%s %s \"%s\"\n", name, HCLASS, HTYPE, trans);
991 EXEC SQL CLOSE a_cursor2;
997 fprintf(stderr, "Unsuccessful close of palladium.db\n");
1003 db_error(sqlca.sqlcode);
1011 char outf[64], outft[64], *mach;
1014 EXEC SQL BEGIN DECLARE SECTION;
1016 int flag1, flag2, id;
1017 EXEC SQL END DECLARE SECTION;
1019 sprintf(outf, "%s/sloc.db", hesiod_dir);
1021 if (stat(outf, &sb) == 0)
1023 ftime = sb.st_mtime;
1024 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
1025 (ModDiff (&flag2, "machine", ftime)))
1027 if (flag1 < 0 && flag2 < 0)
1029 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
1034 sprintf(outft, "%s~", outf);
1035 out = fopen(outft, "w");
1038 perror("cannot open sloc.db for write");
1042 fprintf(stderr, "Building sloc.db\n");
1045 EXEC SQL DECLARE s_cursor CURSOR FOR
1046 SELECT DISTINCT service, mach_id
1049 EXEC SQL OPEN s_cursor;
1052 EXEC SQL FETCH s_cursor INTO :service, :id;
1056 if ((mach = hash_lookup(machines, id)))
1057 fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
1059 EXEC SQL CLOSE s_cursor;
1065 fprintf(stderr, "Unsuccessful close of sloc.db\n");
1072 db_error(sqlca.sqlcode);
1076 int do_service(void)
1079 char outf[64], outft[64];
1082 EXEC SQL BEGIN DECLARE SECTION;
1083 char service[33], protocol[9], altserv[129];
1085 EXEC SQL END DECLARE SECTION;
1087 sprintf(outf, "%s/service.db", hesiod_dir);
1089 if (stat(outf, &sb) == 0)
1091 ftime = sb.st_mtime;
1092 if (ModDiff (&flag1, "services", ftime))
1096 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
1101 sprintf(outft, "%s~", outf);
1102 out = fopen(outft, "w");
1105 perror("cannot open service.db for write");
1109 fprintf(stderr, "Building service.db\n");
1111 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1112 SELECT name, protocol, port
1114 EXEC SQL OPEN s_cursor2;
1117 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1120 lowercase(protocol); /* Convert protocol to lowercase */
1123 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1124 service, HCLASS, HTYPE, service, protocol, port);
1126 EXEC SQL CLOSE s_cursor2;
1128 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1131 WHERE type = 'SERVICE';
1132 EXEC SQL OPEN a_cursor3;
1135 EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
1140 fprintf(out, "%s.service\t%s CNAME %s.service\n", service, HCLASS,
1143 EXEC SQL CLOSE a_cursor3;
1149 fprintf(stderr, "Unsuccessful close of service.db\n");
1155 db_error(sqlca.sqlcode);