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);
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_sloc();
114 changed += do_service();
115 changed += do_groups();
119 fprintf(stderr, "No files updated.\n");
120 if (argc == 2 && stat(argv[1], &sb) == 0)
126 fprintf(stderr, "Building tar file.\n");
127 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
138 EXEC SQL BEGIN DECLARE SECTION;
140 char name[MACHINE_NAME_SIZE];
141 EXEC SQL END DECLARE SECTION;
146 machines = create_hash(1000);
147 EXEC SQL DECLARE m_cursor CURSOR FOR
150 WHERE status = 1 and mach_id != 0
152 EXEC SQL OPEN m_cursor;
155 EXEC SQL FETCH m_cursor INTO :name, :id;
161 hash_store(machines, id, strdup(name));
163 if (sqlca.sqlcode < 0)
164 db_error(sqlca.sqlcode);
165 EXEC SQL CLOSE m_cursor;
170 /* Determine whether or not a name is a valid DNS label.
171 (Can't start or end with . or have two .s in a row) */
172 int valid(char *name)
176 for (sawdot = 1; *name; name++)
194 FILE *pout, *uout, *bout;
195 char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
196 char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
197 struct stat psb, usb, bsb;
201 EXEC SQL BEGIN DECLARE SECTION;
202 char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE];
203 char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE];
204 char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE];
205 char nn[USERS_NICKNAME_SIZE], ptype[USERS_POTYPE_SIZE];
206 int uid, flag1, flag2, id, pid, status;
207 EXEC SQL END DECLARE SECTION;
209 sprintf(poutf, "%s/passwd.db", hesiod_dir);
210 sprintf(uoutf, "%s/uid.db", hesiod_dir);
211 sprintf(boutf, "%s/pobox.db", hesiod_dir);
213 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
214 stat(boutf, &bsb) == 0)
216 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
217 if (ModDiff (&flag1, "users", ftime) ||
218 ModDiff (&flag2, "machine", ftime))
220 if (flag1 < 0 && flag2 < 0)
222 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db "
223 "do not need to be rebuilt.\n");
228 sprintf(poutft, "%s~", poutf);
229 pout = fopen(poutft, "w");
232 perror("cannot open passwd.db~ for write");
235 sprintf(uoutft, "%s~", uoutf);
236 uout = fopen(uoutft, "w");
239 perror("cannot open uid.db~ for write");
242 sprintf(boutft, "%s~", boutf);
243 bout = fopen(boutft, "w");
246 perror("cannot open pobox.db for write");
250 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
253 users = create_hash(12001);
254 EXEC SQL DECLARE u_cursor CURSOR FOR
255 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
256 office_phone, home_phone, users_id, pop_id, potype, status
258 WHERE status = 1 OR status = 2 OR status = 5 OR status = 6
260 EXEC SQL OPEN u_cursor;
263 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
264 :oa, :op, :hp, :id, :pid, :ptype, :status;
274 u = malloc(sizeof(struct user));
275 strcpy(u->name, login);
277 hash_store(users, id, u);
278 if (status == 1 || status == 2)
280 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
281 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
282 op, hp, login, shell);
283 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
285 if (pid != 0 && (mach = hash_lookup(machines, pid)))
287 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
288 login, HCLASS, HTYPE, mach, login);
291 if (sqlca.sqlcode < 0)
292 db_error(sqlca.sqlcode);
293 EXEC SQL CLOSE u_cursor;
296 if (fclose(pout) || fclose(uout) || fclose(bout))
298 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
310 FILE *iout, *gout, *lout;
311 char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
312 char buf[MAXPATHLEN], *l;
314 struct bucket *b, **p;
317 struct stat isb, gsb, lsb;
319 EXEC SQL BEGIN DECLARE SECTION;
320 char name[LIST_NAME_SIZE];
321 int gid, id, lid, flag1, flag2, flag3, len;
322 EXEC SQL END DECLARE SECTION;
325 sprintf(ioutf, "%s/gid.db", hesiod_dir);
326 sprintf(goutf, "%s/group.db", hesiod_dir);
327 sprintf(loutf, "%s/grplist.db", hesiod_dir);
329 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 &&
330 stat(loutf, &lsb) == 0)
332 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
333 if (ModDiff (&flag1, "users", ftime) ||
334 ModDiff (&flag2, "list", ftime) ||
335 ModDiff (&flag3, "imembers", ftime))
337 if (flag1 < 0 && flag2 < 0 && flag3 < 0)
339 fprintf(stderr, "Files gid.db, group.db and grplist.db "
340 "do not need to be rebuilt.\n");
345 sprintf(buf, "%s~", ioutf);
346 iout = fopen(buf, "w");
349 perror("cannot open gid.db for write");
352 sprintf(buf, "%s~", goutf);
353 gout = fopen(buf, "w");
356 perror("cannot open group.db for write");
359 sprintf(buf, "%s~", loutf);
360 lout = fopen(buf, "w");
363 perror("cannot open grplist.db for write");
367 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
369 /* make space for group list */
370 groups = create_hash(15001);
372 /* The following WHENEVER is declarative, not executed,
373 * and applies for the remainder of this file only.
375 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
377 EXEC SQL DECLARE l_cursor CURSOR FOR
378 SELECT name, gid, list_id
380 WHERE grouplist != 0 AND active != 0
382 EXEC SQL OPEN l_cursor;
385 char buf[LIST_NAME_SIZE + 10];
387 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
393 sprintf(buf, "%s:%d", name, gid);
394 hash_store(groups, lid, strdup(buf));
395 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
396 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
397 name, HCLASS, HTYPE, name, gid);
399 EXEC SQL CLOSE l_cursor;
404 /* now do grplists */
407 users = create_hash(12001);
408 EXEC SQL DECLARE u_cursor2 CURSOR FOR
409 SELECT users_id, login
411 WHERE status = 1 OR status = 2
413 EXEC SQL OPEN u_cursor2;
416 EXEC SQL FETCH u_cursor2 INTO :id, :name;
419 u = malloc(sizeof(struct user));
420 strcpy(u->name, strtrim(name));
422 hash_store(users, id, u);
424 EXEC SQL CLOSE u_cursor2;
427 EXEC SQL DECLARE i_cursor CURSOR FOR
428 SELECT list_id, member_id
430 WHERE member_type = 'USER'
432 EXEC SQL OPEN i_cursor;
435 EXEC SQL FETCH i_cursor INTO :lid, :id;
438 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
440 g = malloc(sizeof(struct grp));
446 EXEC SQL CLOSE i_cursor;
450 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
452 for (b = *p; b; b = b->next)
454 if (!(g = ((struct user *)b->data)->lists))
456 fprintf(lout, "%s.grplist\t%s %s \"",
457 ((struct user *)b->data)->name, HCLASS, HTYPE);
459 for (; g; g = g->next)
461 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
466 len += strlen(g->lid) + 1;
470 com_err(whoami, 0, "truncated grp list for user %s",
471 ((struct user *)b->data)->name);
479 if (fclose(iout) || fclose(gout) || fclose(lout))
481 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
489 db_error(sqlca.sqlcode);
497 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
500 struct save_queue *sq, *sq2;
501 EXEC SQL BEGIN DECLARE SECTION;
502 char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
503 char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
504 char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
505 char key[FSGROUP_KEY_SIZE];
506 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
507 int flag1, flag2, flag3, flag4, id, fid;
508 EXEC SQL END DECLARE SECTION;
510 sprintf(outf, "%s/filsys.db", hesiod_dir);
512 if (stat(outf, &sb) == 0)
516 if (ModDiff(&flag1, "filesys", ftime))
518 if (ModDiff(&flag2, "machine", ftime))
520 if (ModDiff(&flag3, "alias", ftime))
522 if (ModDiff(&flag4, "fsgroup", ftime))
525 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
527 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
532 sprintf(outft, "%s~", outf);
533 out = fopen(outft, "w");
536 perror("cannot open filsys.db for write");
540 fprintf(stderr, "Building filsys.db\n");
545 EXEC SQL DECLARE f_cursor CURSOR FOR
546 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
549 EXEC SQL OPEN f_cursor;
552 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
553 :mount, :comments, :fid;
560 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
562 if ((mach = hash_lookup(machines, id)))
564 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
565 name, HCLASS, HTYPE, type, strtrim(loc),
566 mach, strtrim(access), strtrim(mount));
569 else if (!strcmp(type, "AFS"))
571 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
572 name, HCLASS, HTYPE, strtrim(loc),
573 strtrim(access), strtrim(mount));
575 else if (!strcmp(type, "ERR"))
577 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
578 name, HCLASS, HTYPE, strtrim(comments));
580 else if (!strcmp(type, "FSGROUP"))
582 char buf[FILESYS_NAME_SIZE + 10];
583 sprintf(buf, "%s:%d", name, fid);
584 sq_save_data(sq, strdup(buf));
586 else if (!strcmp(type, "MUL"))
588 char buf[FILESYS_NAME_SIZE + 10];
589 sprintf(buf, "%s:%d", name, fid);
590 sq_save_data(sq2, strdup(buf));
593 EXEC SQL CLOSE f_cursor;
595 while (sq_get_data(sq, &group))
597 fid = atoi(strchr(group, ':') + 1);
598 *strchr(group, ':') = 0;
600 EXEC SQL DECLARE f_cursor2 CURSOR FOR
601 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
602 f.comments, f.label, g.key
603 FROM filesys f, fsgroup g
604 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
606 EXEC SQL OPEN f_cursor2;
607 for (flag1 = 1; ; flag1++)
609 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
610 :comments, :name, :key;
614 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
616 if ((mach = hash_lookup(machines, id)))
618 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
619 group, HCLASS, HTYPE, type, strtrim(loc), mach,
620 strtrim(access), strtrim(mount), flag1);
623 else if (!strcmp(type, "AFS"))
625 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
626 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
627 strtrim(mount), flag1);
629 else if (!strcmp(type, "ERR"))
631 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
632 group, HCLASS, HTYPE, strtrim(comments));
635 EXEC SQL CLOSE f_cursor2;
640 while (sq_get_data(sq2, &group))
642 fid = atoi(strchr(group, ':') + 1);
643 *strchr(group, ':') = 0;
644 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
645 EXEC SQL DECLARE f_cursor3 CURSOR FOR
646 SELECT DISTINCT f.label, g.key
647 FROM filesys f, fsgroup g
648 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
650 EXEC SQL OPEN f_cursor3;
653 EXEC SQL FETCH f_cursor3 INTO :name, :key;
656 fprintf(out, " %s", strtrim(name));
658 EXEC SQL CLOSE f_cursor3;
659 fprintf(out, "\"\n");
664 EXEC SQL DECLARE a_cursor CURSOR FOR
667 WHERE type = 'FILESYS';
668 EXEC SQL OPEN a_cursor;
671 EXEC SQL FETCH a_cursor INTO :aname, :trans;
676 if (!valid(aname) || !valid(trans))
678 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
679 aname, HCLASS, trans);
681 EXEC SQL CLOSE a_cursor;
687 fprintf(stderr, "Unsuccessful close of filsys.db\n");
693 db_error(sqlca.sqlcode);
697 int nbitsset(set_mask *set)
701 for (i = 0; i < setsize * NSETBITS; i++)
703 if (SET_ISSET(i, set))
713 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
714 char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
717 EXEC SQL BEGIN DECLARE SECTION;
718 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
719 char name[CLUSTERS_NAME_SIZE];
720 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
721 EXEC SQL END DECLARE SECTION;
722 set_mask **machs, *ms, *ps;
724 sprintf(outf, "%s/cluster.db", hesiod_dir);
726 if (stat(outf, &sb) == 0)
729 if (ModDiff (&flag1, "clusters", ftime)
730 || ModDiff (&flag2, "machine", ftime)
731 || ModDiff (&flag3, "mcmap", ftime)
732 || ModDiff (&flag4, "svc", ftime))
734 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0)
736 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
741 sprintf(outft, "%s~", outf);
742 out = fopen(outft, "w");
745 perror("cannot open cluster.db for write");
749 fprintf(stderr, "Building cluster.db\n");
752 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
754 setsize = howmany(maxclu, NSETBITS);
756 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
758 machs = malloc((maxmach + 1) * sizeof(set_mask **));
759 memset(machs, 0, (maxmach + 1) * sizeof(int));
761 EXEC SQL DECLARE p_cursor CURSOR FOR
762 SELECT mach_id, clu_id
765 EXEC SQL OPEN p_cursor;
768 EXEC SQL FETCH p_cursor INTO :mid, :cid;
771 if (!(ms = machs[mid]))
773 ms = machs[mid] = SET_CREATE();
778 EXEC SQL CLOSE p_cursor;
780 for (mid = 1; mid < maxmach; mid++)
785 if (nbitsset(ms) > 1)
787 sprintf(clubuf, "mrinternal-%d", mid);
788 for (cid = 1; cid < maxclu; cid++)
790 if (SET_ISSET(cid, ms))
792 EXEC SQL DECLARE d_cursor CURSOR FOR
793 SELECT serv_label, serv_cluster
796 EXEC SQL OPEN d_cursor;
799 EXEC SQL FETCH d_cursor INTO :label, :data;
804 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
805 clubuf, HCLASS, HTYPE, label, data);
807 EXEC SQL CLOSE d_cursor;
813 for (cid = 1; cid < maxclu; cid++)
814 if (SET_ISSET(cid, ms))
817 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
821 strcpy(clubuf, name);
824 if ((mach = hash_lookup(machines, mid)))
826 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
827 mach, HCLASS, clubuf);
828 for (p = machbuf; *mach && *mach != '.'; mach++)
830 if (!strcasecmp(mach, ".mit.edu"))
833 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
834 machbuf, HCLASS, clubuf);
837 for (id = mid + 1; id < maxmach; id++)
839 if ((ps = machs[id]) && !SET_CMP(ms, ps))
843 if ((mach = hash_lookup(machines, id)))
845 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
846 mach, HCLASS, clubuf);
847 for (p = machbuf; *mach && *mach != '.'; mach++)
849 if (!strcasecmp(mach, ".mit.edu"))
852 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
853 machbuf, HCLASS, clubuf);
862 EXEC SQL DECLARE d_cursor2 CURSOR FOR
863 SELECT c.name, d.serv_label, d.serv_cluster
864 FROM svc d, clusters c
865 WHERE c.clu_id = d.clu_id;
866 EXEC SQL OPEN d_cursor2;
869 EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
877 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
878 name, HCLASS, HTYPE, label, data);
885 fprintf(stderr, "Unsuccessful close of cluster.db\n");
891 db_error(sqlca.sqlcode);
896 int do_printcap(void)
899 char outf[MAXPATHLEN], outft[MAXPATHLEN];
902 EXEC SQL BEGIN DECLARE SECTION;
903 char name[PRINTERS_NAME_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE];
904 char rp[PRINTERS_RP_SIZE], type[PRINTERS_TYPE_SIZE];
905 char duplexrp[PRINTERS_RP_SIZE], pskind[PRINTSERVERS_KIND_SIZE];
906 int flag1, flag2, ka, rm;
907 EXEC SQL END DECLARE SECTION;
910 sprintf(outf, "%s/printcap.db", hesiod_dir);
912 if (stat(outf, &sb) == 0)
915 if (ModDiff (&flag1, "printers", ftime)
916 || ModDiff (&flag2, "printservers", ftime)
917 || ModDiff (&flag2, "machine", ftime))
919 if (flag1 < 0 && flag2 < 0)
921 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
926 sprintf(outft, "%s~", outf);
927 out = fopen(outft, "w");
930 perror("cannot open printcap.db for write");
934 fprintf(stderr, "Building printcap.db\n");
937 EXEC SQL DECLARE p_cursor2 CURSOR FOR
938 SELECT p.name, p.duplexname, p.type, p.rp, p.rm, p.ka, ps.kind
939 FROM printers p, printservers ps
940 WHERE p.rm = ps.mach_id;
941 EXEC SQL OPEN p_cursor2;
944 EXEC SQL FETCH p_cursor2 INTO :name, :duplexname, :type,
945 :rp, :rm, :ka, :pskind;
948 if (!(rmname = hash_lookup(machines, rm)))
954 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:",
955 name, HCLASS, HTYPE, name, rp, rmname, ka);
958 if (!strcmp(pskind, "BSD"))
959 fprintf(out, "auth=none:remote_support=RQM:");
960 else if (!strcmp(pskind, "ATHENA"))
961 fprintf(out, "auth=kerberos4:az:remote_support=RQM:");
962 else if (!strcmp(pskind, "LPRNG"))
963 fprintf(out, "auth=kerberos5:xn:");
968 if (!valid(duplexname))
970 if (!strcmp(strtrim(type), "ALIAS"))
972 EXEC SQL SELECT duplexname INTO :duplexrp
973 FROM printers WHERE name = :rp;
977 strcpy(duplexrp, duplexname);
978 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:",
979 duplexname, HCLASS, HTYPE, duplexname, duplexrp,
982 if (!strcmp(pskind, "BSD"))
983 fprintf(out, "auth=none:remote_support=RQM:");
984 else if (!strcmp(pskind, "ATHENA"))
985 fprintf(out, "auth=kerberos4:az:remote_support=RQM:");
986 else if (!strcmp(pskind, "LPRNG"))
987 fprintf(out, "auth=kerberos5:xn:");
991 EXEC SQL CLOSE p_cursor2;
997 fprintf(stderr, "Unsuccessful close of pcap.db\n");
1003 db_error(sqlca.sqlcode);
1011 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
1014 EXEC SQL BEGIN DECLARE SECTION;
1015 char service[SERVERHOSTS_SERVICE_SIZE];
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 (valid(service) && (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[MAXPATHLEN], outft[MAXPATHLEN];
1082 EXEC SQL BEGIN DECLARE SECTION;
1083 char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE];
1084 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
1086 EXEC SQL END DECLARE SECTION;
1088 sprintf(outf, "%s/service.db", hesiod_dir);
1090 if (stat(outf, &sb) == 0)
1092 ftime = sb.st_mtime;
1093 if (ModDiff (&flag1, "services", ftime))
1097 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
1102 sprintf(outft, "%s~", outf);
1103 out = fopen(outft, "w");
1106 perror("cannot open service.db for write");
1110 fprintf(stderr, "Building service.db\n");
1112 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1113 SELECT name, protocol, port
1115 EXEC SQL OPEN s_cursor2;
1118 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1121 lowercase(protocol); /* Convert protocol to lowercase */
1123 if (!valid(service))
1126 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1127 service, HCLASS, HTYPE, service, protocol, port);
1129 EXEC SQL CLOSE s_cursor2;
1131 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1134 WHERE type = 'SERVICE';
1135 EXEC SQL OPEN a_cursor3;
1138 EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
1143 if (!valid(aname) || !valid(trans))
1145 fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
1148 EXEC SQL CLOSE a_cursor3;
1154 fprintf(stderr, "Unsuccessful close of service.db\n");
1160 db_error(sqlca.sqlcode);