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 (~78) [derived empirically]
41 * (it used to be 446 with older versions of bind)
43 #define MAXHESSIZE 434
45 char hesiod_dir[MAXPATHLEN];
47 #define min(x, y) ((x) < (y) ? (x) : (y))
48 struct hash *machines = NULL;
49 struct hash *users = NULL;
50 char *whoami = "hesiod.gen";
51 char *db = "moira/moira";
58 char name[USERS_LOGIN_SIZE];
63 * Modified from sys/types.h:
65 int setsize; /* = howmany(setbits, NSETBITS) */
67 typedef long set_mask;
68 #define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
70 #define howmany(x, y) (((x) + ((y) - 1)) / (y))
73 #define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
74 #define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
75 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
76 #define SET_CREATE() (malloc(setsize * sizeof(set_mask)))
77 #define SET_ZERO(p) memset(p, 0, setsize * sizeof(set_mask))
78 #define SET_CMP(p1, p2) (memcmp(p1, p2, setsize * sizeof(set_mask)))
82 int nbitsset(set_mask *set);
83 int valid(char *name);
89 int do_printcap(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_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;
162 hash_store(machines, id, strdup(name));
164 if (sqlca.sqlcode < 0)
165 db_error(sqlca.sqlcode);
166 EXEC SQL CLOSE m_cursor;
171 /* Determine whether or not a name is a valid DNS label.
172 (Can't start or end with . or have two .s in a row) */
173 int valid(char *name)
177 for (sawdot = 1; *name; name++)
195 FILE *pout, *uout, *bout;
196 char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
197 char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
198 struct stat psb, usb, bsb;
202 EXEC SQL BEGIN DECLARE SECTION;
203 char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE];
204 char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE];
205 char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE];
206 char nn[USERS_NICKNAME_SIZE];
207 int uid, flag1, flag2, id, pid, iid, mid, status;
208 EXEC SQL END DECLARE SECTION;
210 sprintf(poutf, "%s/passwd.db", hesiod_dir);
211 sprintf(uoutf, "%s/uid.db", hesiod_dir);
212 sprintf(boutf, "%s/pobox.db", hesiod_dir);
214 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
215 stat(boutf, &bsb) == 0)
217 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
218 if (ModDiff (&flag1, "users", ftime) ||
219 ModDiff (&flag2, "machine", ftime))
221 if (flag1 < 0 && flag2 < 0)
223 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db "
224 "do not need to be rebuilt.\n");
229 sprintf(poutft, "%s~", poutf);
230 pout = fopen(poutft, "w");
233 perror("cannot open passwd.db~ for write");
236 sprintf(uoutft, "%s~", uoutf);
237 uout = fopen(uoutft, "w");
240 perror("cannot open uid.db~ for write");
243 sprintf(boutft, "%s~", boutf);
244 bout = fopen(boutft, "w");
247 perror("cannot open pobox.db for write");
251 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
254 users = create_hash(12001);
255 EXEC SQL DECLARE u_cursor CURSOR FOR
256 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
257 office_phone, home_phone, users_id, pop_id, imap_id, status
259 WHERE status = 1 OR status = 2 OR status = 5 OR status = 6
261 EXEC SQL OPEN u_cursor;
264 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
265 :oa, :op, :hp, :id, :pid, :iid, :status;
275 u = malloc(sizeof(struct user));
276 strcpy(u->name, login);
278 hash_store(users, id, u);
279 if (status == 1 || status == 2)
281 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
282 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
283 op, hp, login, shell);
284 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
289 EXEC SQL SELECT mach_id INTO :mid FROM filesys
290 WHERE filsys_id = :iid AND type = 'IMAP';
291 if (sqlca.sqlcode == 0)
295 if (pid != 0 && (mach = hash_lookup(machines, pid)))
297 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
298 login, HCLASS, HTYPE, mach, login);
301 if (sqlca.sqlcode < 0)
302 db_error(sqlca.sqlcode);
303 EXEC SQL CLOSE u_cursor;
306 if (fclose(pout) || fclose(uout) || fclose(bout))
308 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
320 FILE *iout, *gout, *lout;
321 char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
322 char buf[MAXPATHLEN], *l;
324 struct bucket *b, **p;
327 struct stat isb, gsb, lsb;
329 EXEC SQL BEGIN DECLARE SECTION;
330 char name[LIST_NAME_SIZE];
331 int gid, id, lid, flag1, flag2, flag3, len;
332 EXEC SQL END DECLARE SECTION;
335 sprintf(ioutf, "%s/gid.db", hesiod_dir);
336 sprintf(goutf, "%s/group.db", hesiod_dir);
337 sprintf(loutf, "%s/grplist.db", hesiod_dir);
339 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 &&
340 stat(loutf, &lsb) == 0)
342 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
343 if (ModDiff (&flag1, "users", ftime) ||
344 ModDiff (&flag2, "list", ftime) ||
345 ModDiff (&flag3, "imembers", ftime))
347 if (flag1 < 0 && flag2 < 0 && flag3 < 0)
349 fprintf(stderr, "Files gid.db, group.db and grplist.db "
350 "do not need to be rebuilt.\n");
355 sprintf(buf, "%s~", ioutf);
356 iout = fopen(buf, "w");
359 perror("cannot open gid.db for write");
362 sprintf(buf, "%s~", goutf);
363 gout = fopen(buf, "w");
366 perror("cannot open group.db for write");
369 sprintf(buf, "%s~", loutf);
370 lout = fopen(buf, "w");
373 perror("cannot open grplist.db for write");
377 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
379 /* make space for group list */
380 groups = create_hash(15001);
382 /* The following WHENEVER is declarative, not executed,
383 * and applies for the remainder of this file only.
385 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
387 EXEC SQL DECLARE l_cursor CURSOR FOR
388 SELECT name, gid, list_id
390 WHERE grouplist != 0 AND active != 0
392 EXEC SQL OPEN l_cursor;
395 char buf[LIST_NAME_SIZE + 10];
397 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
403 sprintf(buf, "%s:%d", name, gid);
404 hash_store(groups, lid, strdup(buf));
405 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
406 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
407 name, HCLASS, HTYPE, name, gid);
409 EXEC SQL CLOSE l_cursor;
414 /* now do grplists */
417 users = create_hash(12001);
418 EXEC SQL DECLARE u_cursor2 CURSOR FOR
419 SELECT users_id, login
421 WHERE status = 1 OR status = 2;
422 EXEC SQL OPEN u_cursor2;
425 EXEC SQL FETCH u_cursor2 INTO :id, :name;
428 u = malloc(sizeof(struct user));
429 strcpy(u->name, strtrim(name));
431 hash_store(users, id, u);
433 EXEC SQL CLOSE u_cursor2;
436 EXEC SQL DECLARE i_cursor CURSOR FOR
437 SELECT m.list_id, m.member_id
438 FROM imembers m, list l
439 WHERE m.member_type = 'USER'
440 AND m.list_id = l.list_id AND l.grouplist = 1 AND l.nfsgroup = 1;
441 EXEC SQL OPEN i_cursor;
444 EXEC SQL FETCH i_cursor INTO :lid, :id;
447 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
449 g = malloc(sizeof(struct grp));
455 EXEC SQL CLOSE i_cursor;
459 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
461 for (b = *p; b; b = b->next)
463 if (!(g = ((struct user *)b->data)->lists))
465 fprintf(lout, "%s.grplist\t%s %s \"",
466 ((struct user *)b->data)->name, HCLASS, HTYPE);
468 for (; g; g = g->next)
470 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
475 len += strlen(g->lid) + 1;
479 com_err(whoami, 0, "truncated grp list for user %s",
480 ((struct user *)b->data)->name);
488 if (fclose(iout) || fclose(gout) || fclose(lout))
490 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
498 db_error(sqlca.sqlcode);
506 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
509 struct save_queue *sq, *sq2;
510 EXEC SQL BEGIN DECLARE SECTION;
511 char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
512 char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
513 char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
514 char key[FSGROUP_KEY_SIZE];
515 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
516 int flag1, flag2, flag3, flag4, id, fid;
517 EXEC SQL END DECLARE SECTION;
519 sprintf(outf, "%s/filsys.db", hesiod_dir);
521 if (stat(outf, &sb) == 0)
525 if (ModDiff(&flag1, "filesys", ftime))
527 if (ModDiff(&flag2, "machine", ftime))
529 if (ModDiff(&flag3, "alias", ftime))
531 if (ModDiff(&flag4, "fsgroup", ftime))
534 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
536 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
541 sprintf(outft, "%s~", outf);
542 out = fopen(outft, "w");
545 perror("cannot open filsys.db for write");
549 fprintf(stderr, "Building filsys.db\n");
554 EXEC SQL DECLARE f_cursor CURSOR FOR
555 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
558 EXEC SQL OPEN f_cursor;
561 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
562 :mount, :comments, :fid;
569 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
571 if ((mach = hash_lookup(machines, id)))
573 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
574 name, HCLASS, HTYPE, type, strtrim(loc),
575 mach, strtrim(access), strtrim(mount));
578 else if (!strcmp(type, "AFS"))
580 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
581 name, HCLASS, HTYPE, strtrim(loc),
582 strtrim(access), strtrim(mount));
584 else if (!strcmp(type, "ERR"))
586 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
587 name, HCLASS, HTYPE, strtrim(comments));
589 else if (!strcmp(type, "FSGROUP"))
591 char buf[FILESYS_NAME_SIZE + 10];
592 sprintf(buf, "%s:%d", name, fid);
593 sq_save_data(sq, strdup(buf));
595 else if (!strcmp(type, "MUL"))
597 char buf[FILESYS_NAME_SIZE + 10];
598 sprintf(buf, "%s:%d", name, fid);
599 sq_save_data(sq2, strdup(buf));
602 EXEC SQL CLOSE f_cursor;
604 while (sq_get_data(sq, &group))
606 fid = atoi(strchr(group, ':') + 1);
607 *strchr(group, ':') = 0;
609 EXEC SQL DECLARE f_cursor2 CURSOR FOR
610 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
611 f.comments, f.label, g.key
612 FROM filesys f, fsgroup g
613 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
615 EXEC SQL OPEN f_cursor2;
616 for (flag1 = 1; ; flag1++)
618 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
619 :comments, :name, :key;
623 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
625 if ((mach = hash_lookup(machines, id)))
627 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
628 group, HCLASS, HTYPE, type, strtrim(loc), mach,
629 strtrim(access), strtrim(mount), flag1);
632 else if (!strcmp(type, "AFS"))
634 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
635 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
636 strtrim(mount), flag1);
638 else if (!strcmp(type, "ERR"))
640 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
641 group, HCLASS, HTYPE, strtrim(comments));
644 EXEC SQL CLOSE f_cursor2;
649 while (sq_get_data(sq2, &group))
651 fid = atoi(strchr(group, ':') + 1);
652 *strchr(group, ':') = 0;
653 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
654 EXEC SQL DECLARE f_cursor3 CURSOR FOR
655 SELECT DISTINCT f.label, g.key
656 FROM filesys f, fsgroup g
657 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
659 EXEC SQL OPEN f_cursor3;
662 EXEC SQL FETCH f_cursor3 INTO :name, :key;
665 fprintf(out, " %s", strtrim(name));
667 EXEC SQL CLOSE f_cursor3;
668 fprintf(out, "\"\n");
673 EXEC SQL DECLARE a_cursor CURSOR FOR
676 WHERE type = 'FILESYS';
677 EXEC SQL OPEN a_cursor;
680 EXEC SQL FETCH a_cursor INTO :aname, :trans;
685 if (!valid(aname) || !valid(trans))
687 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
688 aname, HCLASS, trans);
690 EXEC SQL CLOSE a_cursor;
696 fprintf(stderr, "Unsuccessful close of filsys.db\n");
702 db_error(sqlca.sqlcode);
706 int nbitsset(set_mask *set)
710 for (i = 0; i < setsize * NSETBITS; i++)
712 if (SET_ISSET(i, set))
722 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
723 char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
726 EXEC SQL BEGIN DECLARE SECTION;
727 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
728 char name[CLUSTERS_NAME_SIZE];
729 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
730 EXEC SQL END DECLARE SECTION;
731 set_mask **machs, *ms, *ps;
733 sprintf(outf, "%s/cluster.db", hesiod_dir);
735 if (stat(outf, &sb) == 0)
738 if (ModDiff (&flag1, "clusters", ftime)
739 || ModDiff (&flag2, "machine", ftime)
740 || ModDiff (&flag3, "mcmap", ftime)
741 || ModDiff (&flag4, "svc", ftime))
743 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
745 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
750 sprintf(outft, "%s~", outf);
751 out = fopen(outft, "w");
754 perror("cannot open cluster.db for write");
758 fprintf(stderr, "Building cluster.db\n");
761 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
763 setsize = howmany(maxclu, NSETBITS);
765 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
767 machs = malloc((maxmach + 1) * sizeof(set_mask **));
768 memset(machs, 0, (maxmach + 1) * sizeof(int));
770 EXEC SQL DECLARE p_cursor CURSOR FOR
771 SELECT mach_id, clu_id
774 EXEC SQL OPEN p_cursor;
777 EXEC SQL FETCH p_cursor INTO :mid, :cid;
780 if (!(ms = machs[mid]))
782 ms = machs[mid] = SET_CREATE();
787 EXEC SQL CLOSE p_cursor;
789 for (mid = 1; mid < maxmach; mid++)
794 if (nbitsset(ms) > 1)
796 sprintf(clubuf, "mrinternal-%d", mid);
797 for (cid = 1; cid < maxclu; cid++)
799 if (SET_ISSET(cid, ms))
801 EXEC SQL DECLARE d_cursor CURSOR FOR
802 SELECT serv_label, serv_cluster
805 EXEC SQL OPEN d_cursor;
808 EXEC SQL FETCH d_cursor INTO :label, :data;
813 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
814 clubuf, HCLASS, HTYPE, label, data);
816 EXEC SQL CLOSE d_cursor;
822 for (cid = 1; cid < maxclu; cid++)
823 if (SET_ISSET(cid, ms))
826 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
830 strcpy(clubuf, name);
833 if ((mach = hash_lookup(machines, mid)))
835 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
836 mach, HCLASS, clubuf);
837 for (p = machbuf; *mach && *mach != '.'; mach++)
839 if (!strcasecmp(mach, ".mit.edu"))
842 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
843 machbuf, HCLASS, clubuf);
846 for (id = mid + 1; id < maxmach; id++)
848 if ((ps = machs[id]) && !SET_CMP(ms, ps))
852 if ((mach = hash_lookup(machines, id)))
854 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
855 mach, HCLASS, clubuf);
856 for (p = machbuf; *mach && *mach != '.'; mach++)
858 if (!strcasecmp(mach, ".mit.edu"))
861 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
862 machbuf, HCLASS, clubuf);
871 EXEC SQL DECLARE d_cursor2 CURSOR FOR
872 SELECT c.name, d.serv_label, d.serv_cluster
873 FROM svc d, clusters c
874 WHERE c.clu_id = d.clu_id;
875 EXEC SQL OPEN d_cursor2;
878 EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
886 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
887 name, HCLASS, HTYPE, label, data);
894 fprintf(stderr, "Unsuccessful close of cluster.db\n");
900 db_error(sqlca.sqlcode);
905 int do_printcap(void)
908 char outf[MAXPATHLEN], outft[MAXPATHLEN];
911 EXEC SQL BEGIN DECLARE SECTION;
912 char name[PRINTERS_NAME_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE];
913 char rp[PRINTERS_RP_SIZE], type[PRINTERS_TYPE_SIZE];
914 char duplexrp[PRINTERS_RP_SIZE], pskind[PRINTSERVERS_KIND_SIZE];
915 int flag1, flag2, ka, rm, mc;
916 EXEC SQL END DECLARE SECTION;
919 sprintf(outf, "%s/printcap.db", hesiod_dir);
921 if (stat(outf, &sb) == 0)
924 if (ModDiff (&flag1, "printers", ftime)
925 || ModDiff (&flag2, "printservers", ftime)
926 || ModDiff (&flag2, "machine", ftime))
928 if (flag1 < 0 && flag2 < 0)
930 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
935 sprintf(outft, "%s~", outf);
936 out = fopen(outft, "w");
939 perror("cannot open printcap.db for write");
943 fprintf(stderr, "Building printcap.db\n");
946 EXEC SQL DECLARE p_cursor2 CURSOR FOR
947 SELECT p.name, p.duplexname, p.type, p.rp, p.rm, p.ka, p.mc, ps.kind
948 FROM printers p, printservers ps
949 WHERE p.rm = ps.mach_id;
950 EXEC SQL OPEN p_cursor2;
953 EXEC SQL FETCH p_cursor2 INTO :name, :duplexname, :type,
954 :rp, :rm, :ka, :mc, :pskind;
957 if (!(rmname = hash_lookup(machines, rm)))
963 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
964 name, HCLASS, HTYPE, name, rp, rmname, ka, mc);
967 if (!strcmp(pskind, "BSD"))
968 fprintf(out, "auth=none:remote_support=RQM:");
969 else if (!strcmp(pskind, "ATHENA"))
971 fprintf(out, "auth=%s:az:remote_support=RQM:",
972 ka ? "kerberos4" : "none");
974 else if (!strcmp(pskind, "LPRNG"))
975 fprintf(out, "auth=kerberos5:xn:");
980 if (!valid(duplexname))
982 if (!strcmp(strtrim(type), "ALIAS"))
984 EXEC SQL SELECT duplexname INTO :duplexrp
985 FROM printers WHERE name = :rp;
989 strcpy(duplexrp, duplexname);
990 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
991 duplexname, HCLASS, HTYPE, duplexname, duplexrp,
994 if (!strcmp(pskind, "BSD"))
995 fprintf(out, "auth=none:remote_support=RQM:");
996 else if (!strcmp(pskind, "ATHENA"))
998 fprintf(out, "auth=%s:az:remote_support=RQM:",
999 ka ? "kerberos4" : "none");
1001 else if (!strcmp(pskind, "LPRNG"))
1002 fprintf(out, "auth=kerberos5:xn:");
1006 EXEC SQL CLOSE p_cursor2;
1012 fprintf(stderr, "Unsuccessful close of pcap.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 (valid(service) && (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 */
1138 if (!valid(service))
1141 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1142 service, HCLASS, HTYPE, service, protocol, port);
1144 EXEC SQL CLOSE s_cursor2;
1146 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1149 WHERE type = 'SERVICE';
1150 EXEC SQL OPEN a_cursor3;
1153 EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
1158 if (!valid(aname) || !valid(trans))
1160 fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
1163 EXEC SQL CLOSE a_cursor3;
1169 fprintf(stderr, "Unsuccessful close of service.db\n");
1175 db_error(sqlca.sqlcode);