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 256
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++)
197 FILE *pout, *uout, *bout;
198 char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
199 char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
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], potype[USERS_POTYPE_SIZE];
207 int uid, id, pid, iid, eid, 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 sprintf(poutft, "%s~", poutf);
215 pout = fopen(poutft, "w");
218 perror("cannot open passwd.db~ for write");
221 sprintf(uoutft, "%s~", uoutf);
222 uout = fopen(uoutft, "w");
225 perror("cannot open uid.db~ for write");
228 sprintf(boutft, "%s~", boutf);
229 bout = fopen(boutft, "w");
232 perror("cannot open pobox.db for write");
236 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
239 users = create_hash(12001);
240 EXEC SQL DECLARE u_cursor CURSOR FOR
241 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
242 office_phone, home_phone, users_id, potype, pop_id, imap_id, exchange_id,
245 WHERE status = 1 OR status = 2 OR status = 5 OR status = 6
247 EXEC SQL OPEN u_cursor;
250 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
251 :oa, :op, :hp, :id, :potype, :pid, :iid, :eid, :status;
262 u = malloc(sizeof(struct user));
263 strcpy(u->name, login);
265 hash_store(users, id, u);
266 if (status == 1 || status == 2)
268 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
269 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
270 op, hp, login, shell);
271 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
276 /* Check for IMAP. Can't use iid because it should be zero. */
277 EXEC SQL SELECT mach_id INTO :mid FROM filesys
278 WHERE label = :login || '.po' AND type = 'IMAP';
279 if (sqlca.sqlcode == 0)
283 /* EXCHANGE user with no IMAP filesystem. Give them
284 * IMAP.EXCHANGE.MIT.EDU instead of EXCHANGE.MIT.EDU.
286 EXEC SQL SELECT mach_id INTO :eid FROM machine
287 WHERE name = 'IMAP.EXCHANGE.MIT.EDU';
288 if (sqlca.sqlcode == 0)
295 EXEC SQL SELECT mach_id INTO :mid FROM filesys
296 WHERE filsys_id = :iid AND type = 'IMAP';
297 if (sqlca.sqlcode == 0)
301 if ((strcmp(potype, "NONE") != 0) && pid != 0 &&
302 (mach = hash_lookup(machines, pid)))
304 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
305 login, HCLASS, HTYPE, mach, login);
308 if (sqlca.sqlcode < 0)
309 db_error(sqlca.sqlcode);
310 EXEC SQL CLOSE u_cursor;
313 if (fclose(pout) || fclose(uout) || fclose(bout))
315 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
327 FILE *iout, *gout, *lout;
328 char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
329 char buf[MAXPATHLEN], *l;
331 struct bucket *b, **p;
334 EXEC SQL BEGIN DECLARE SECTION;
335 char name[LIST_NAME_SIZE];
336 int gid, id, lid, len;
337 EXEC SQL END DECLARE SECTION;
340 sprintf(ioutf, "%s/gid.db", hesiod_dir);
341 sprintf(goutf, "%s/group.db", hesiod_dir);
342 sprintf(loutf, "%s/grplist.db", hesiod_dir);
344 sprintf(buf, "%s~", ioutf);
345 iout = fopen(buf, "w");
348 perror("cannot open gid.db for write");
351 sprintf(buf, "%s~", goutf);
352 gout = fopen(buf, "w");
355 perror("cannot open group.db for write");
358 sprintf(buf, "%s~", loutf);
359 lout = fopen(buf, "w");
362 perror("cannot open grplist.db for write");
366 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
368 /* make space for group list */
369 groups = create_hash(15001);
371 /* The following WHENEVER is declarative, not executed,
372 * and applies for the remainder of this file only.
374 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
376 EXEC SQL DECLARE l_cursor CURSOR FOR
377 SELECT name, gid, list_id
379 WHERE grouplist != 0 AND active != 0
381 EXEC SQL OPEN l_cursor;
384 char buf[LIST_NAME_SIZE + 10];
386 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
392 sprintf(buf, "%s:%d", name, gid);
393 hash_store(groups, lid, strdup(buf));
394 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
395 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
396 name, HCLASS, HTYPE, name, gid);
398 EXEC SQL CLOSE l_cursor;
403 /* now do grplists */
406 users = create_hash(12001);
407 EXEC SQL DECLARE u_cursor2 CURSOR FOR
408 SELECT users_id, login
410 WHERE status = 1 OR status = 2;
411 EXEC SQL OPEN u_cursor2;
414 EXEC SQL FETCH u_cursor2 INTO :id, :name;
417 u = malloc(sizeof(struct user));
418 strcpy(u->name, strtrim(name));
420 hash_store(users, id, u);
422 EXEC SQL CLOSE u_cursor2;
425 EXEC SQL DECLARE i_cursor CURSOR FOR
426 SELECT m.list_id, m.member_id
427 FROM imembers m, list l
428 WHERE m.member_type = 'USER'
429 AND m.list_id = l.list_id AND l.grouplist = 1 AND l.nfsgroup = 1;
430 EXEC SQL OPEN i_cursor;
433 EXEC SQL FETCH i_cursor INTO :lid, :id;
436 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
438 g = malloc(sizeof(struct grp));
444 EXEC SQL CLOSE i_cursor;
448 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
450 for (b = *p; b; b = b->next)
452 if (!(g = ((struct user *)b->data)->lists))
454 fprintf(lout, "%s.grplist\t%s %s \"",
455 ((struct user *)b->data)->name, HCLASS, HTYPE);
457 for (; g; g = g->next)
459 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
464 len += strlen(g->lid) + 1;
468 com_err(whoami, 0, "truncated grp list for user %s",
469 ((struct user *)b->data)->name);
477 if (fclose(iout) || fclose(gout) || fclose(lout))
479 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
487 db_error(sqlca.sqlcode);
495 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
496 struct save_queue *sq, *sq2;
497 EXEC SQL BEGIN DECLARE SECTION;
498 char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
499 char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
500 char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
501 char key[FSGROUP_KEY_SIZE];
502 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
504 EXEC SQL END DECLARE SECTION;
506 sprintf(outf, "%s/filsys.db", hesiod_dir);
508 sprintf(outft, "%s~", outf);
509 out = fopen(outft, "w");
512 perror("cannot open filsys.db for write");
516 fprintf(stderr, "Building filsys.db\n");
521 EXEC SQL DECLARE f_cursor CURSOR FOR
522 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
525 EXEC SQL OPEN f_cursor;
528 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
529 :mount, :comments, :fid;
536 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
538 if ((mach = hash_lookup(machines, id)))
540 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
541 name, HCLASS, HTYPE, type, strtrim(loc),
542 mach, strtrim(access), strtrim(mount));
545 else if (!strcmp(type, "AFS"))
547 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
548 name, HCLASS, HTYPE, strtrim(loc),
549 strtrim(access), strtrim(mount));
551 else if (!strcmp(type, "ERR"))
553 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
554 name, HCLASS, HTYPE, strtrim(comments));
556 else if (!strcmp(type, "FSGROUP"))
558 char buf[FILESYS_NAME_SIZE + 10];
559 sprintf(buf, "%s:%d", name, fid);
560 sq_save_data(sq, strdup(buf));
562 else if (!strcmp(type, "MUL"))
564 char buf[FILESYS_NAME_SIZE + 10];
565 sprintf(buf, "%s:%d", name, fid);
566 sq_save_data(sq2, strdup(buf));
569 EXEC SQL CLOSE f_cursor;
571 while (sq_get_data(sq, &group))
573 fid = atoi(strchr(group, ':') + 1);
574 *strchr(group, ':') = 0;
576 EXEC SQL DECLARE f_cursor2 CURSOR FOR
577 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
578 f.comments, f.label, g.key
579 FROM filesys f, fsgroup g
580 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
582 EXEC SQL OPEN f_cursor2;
583 for (flag = 1; ; flag++)
585 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
586 :comments, :name, :key;
590 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
592 if ((mach = hash_lookup(machines, id)))
594 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
595 group, HCLASS, HTYPE, type, strtrim(loc), mach,
596 strtrim(access), strtrim(mount), flag);
599 else if (!strcmp(type, "AFS"))
601 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
602 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
603 strtrim(mount), flag);
605 else if (!strcmp(type, "ERR"))
607 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
608 group, HCLASS, HTYPE, strtrim(comments));
611 EXEC SQL CLOSE f_cursor2;
616 while (sq_get_data(sq2, &group))
618 fid = atoi(strchr(group, ':') + 1);
619 *strchr(group, ':') = 0;
620 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
621 EXEC SQL DECLARE f_cursor3 CURSOR FOR
622 SELECT DISTINCT f.label, g.key
623 FROM filesys f, fsgroup g
624 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
626 EXEC SQL OPEN f_cursor3;
629 EXEC SQL FETCH f_cursor3 INTO :name, :key;
632 fprintf(out, " %s", strtrim(name));
634 EXEC SQL CLOSE f_cursor3;
635 fprintf(out, "\"\n");
640 EXEC SQL DECLARE a_cursor CURSOR FOR
643 WHERE type = 'FILESYS';
644 EXEC SQL OPEN a_cursor;
647 EXEC SQL FETCH a_cursor INTO :aname, :trans;
652 if (!valid(aname) || !valid(trans))
654 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
655 aname, HCLASS, trans);
657 EXEC SQL CLOSE a_cursor;
663 fprintf(stderr, "Unsuccessful close of filsys.db\n");
669 db_error(sqlca.sqlcode);
673 int nbitsset(set_mask *set)
677 for (i = 0; i < setsize * NSETBITS; i++)
679 if (SET_ISSET(i, set))
689 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
690 char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
691 EXEC SQL BEGIN DECLARE SECTION;
692 int maxmach, maxclu, mid, cid, id;
693 char name[CLUSTERS_NAME_SIZE];
694 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
695 EXEC SQL END DECLARE SECTION;
696 set_mask **machs, *ms, *ps;
698 sprintf(outf, "%s/cluster.db", hesiod_dir);
700 sprintf(outft, "%s~", outf);
701 out = fopen(outft, "w");
704 perror("cannot open cluster.db for write");
708 fprintf(stderr, "Building cluster.db\n");
711 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
713 setsize = howmany(maxclu, NSETBITS);
715 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
717 machs = malloc((maxmach + 1) * sizeof(set_mask **));
718 memset(machs, 0, (maxmach + 1) * sizeof(int));
720 EXEC SQL DECLARE p_cursor CURSOR FOR
721 SELECT mach_id, clu_id
724 EXEC SQL OPEN p_cursor;
727 EXEC SQL FETCH p_cursor INTO :mid, :cid;
730 if (!(ms = machs[mid]))
732 ms = machs[mid] = SET_CREATE();
737 EXEC SQL CLOSE p_cursor;
739 for (mid = 1; mid < maxmach; mid++)
744 if (nbitsset(ms) > 1)
746 sprintf(clubuf, "mrinternal-%d", mid);
747 for (cid = 1; cid < maxclu; cid++)
749 if (SET_ISSET(cid, ms))
751 EXEC SQL DECLARE d_cursor CURSOR FOR
752 SELECT serv_label, serv_cluster
755 EXEC SQL OPEN d_cursor;
758 EXEC SQL FETCH d_cursor INTO :label, :data;
763 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
764 clubuf, HCLASS, HTYPE, label, data);
766 EXEC SQL CLOSE d_cursor;
772 for (cid = 1; cid < maxclu; cid++)
773 if (SET_ISSET(cid, ms))
776 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
780 strcpy(clubuf, name);
783 if ((mach = hash_lookup(machines, mid)))
785 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
786 mach, HCLASS, clubuf);
787 for (p = machbuf; *mach && *mach != '.'; mach++)
789 if (!strcasecmp(mach, ".mit.edu"))
792 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
793 machbuf, HCLASS, clubuf);
796 for (id = mid + 1; id < maxmach; id++)
798 if ((ps = machs[id]) && !SET_CMP(ms, ps))
802 if ((mach = hash_lookup(machines, id)))
804 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
805 mach, HCLASS, clubuf);
806 for (p = machbuf; *mach && *mach != '.'; mach++)
808 if (!strcasecmp(mach, ".mit.edu"))
811 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
812 machbuf, HCLASS, clubuf);
821 EXEC SQL DECLARE d_cursor2 CURSOR FOR
822 SELECT c.name, d.serv_label, d.serv_cluster
823 FROM svc d, clusters c
824 WHERE c.clu_id = d.clu_id;
825 EXEC SQL OPEN d_cursor2;
828 EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
836 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
837 name, HCLASS, HTYPE, label, data);
844 fprintf(stderr, "Unsuccessful close of cluster.db\n");
850 db_error(sqlca.sqlcode);
855 int do_printcap(void)
858 char outf[MAXPATHLEN], outft[MAXPATHLEN];
859 EXEC SQL BEGIN DECLARE SECTION;
860 char name[PRINTERS_NAME_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE];
861 char rp[PRINTERS_RP_SIZE], type[PRINTERS_TYPE_SIZE];
862 char duplexrp[PRINTERS_RP_SIZE], pskind[PRINTSERVERS_KIND_SIZE];
864 EXEC SQL END DECLARE SECTION;
867 sprintf(outf, "%s/printcap.db", hesiod_dir);
869 sprintf(outft, "%s~", outf);
870 out = fopen(outft, "w");
873 perror("cannot open printcap.db for write");
877 fprintf(stderr, "Building printcap.db\n");
880 EXEC SQL DECLARE p_cursor2 CURSOR FOR
881 SELECT p.name, p.duplexname, p.type, p.rp, p.rm, p.ka, p.mc, ps.kind
882 FROM printers p, printservers ps
883 WHERE p.rm = ps.mach_id;
884 EXEC SQL OPEN p_cursor2;
887 EXEC SQL FETCH p_cursor2 INTO :name, :duplexname, :type,
888 :rp, :rm, :ka, :mc, :pskind;
891 if (!(rmname = hash_lookup(machines, rm)))
897 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
898 name, HCLASS, HTYPE, name, rp, rmname, ka, mc);
901 if (!strcmp(pskind, "BSD"))
902 fprintf(out, "auth=none:remote_support=RQM:");
903 else if (!strcmp(pskind, "ATHENA"))
905 fprintf(out, "auth=%s:az:remote_support=RQM:",
906 ka ? "kerberos4" : "none");
908 else if (!strcmp(pskind, "LPRNG"))
909 fprintf(out, "auth=kerberos5:xn:");
914 if (!valid(duplexname))
916 if (!strcmp(strtrim(type), "ALIAS"))
918 EXEC SQL SELECT duplexname INTO :duplexrp
919 FROM printers WHERE name = :rp;
923 strcpy(duplexrp, duplexname);
924 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
925 duplexname, HCLASS, HTYPE, duplexname, duplexrp,
928 if (!strcmp(pskind, "BSD"))
929 fprintf(out, "auth=none:remote_support=RQM:");
930 else if (!strcmp(pskind, "ATHENA"))
932 fprintf(out, "auth=%s:az:remote_support=RQM:",
933 ka ? "kerberos4" : "none");
935 else if (!strcmp(pskind, "LPRNG"))
936 fprintf(out, "auth=kerberos5:xn:");
940 EXEC SQL CLOSE p_cursor2;
946 fprintf(stderr, "Unsuccessful close of pcap.db\n");
952 db_error(sqlca.sqlcode);
960 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
961 EXEC SQL BEGIN DECLARE SECTION;
962 char service[SERVERHOSTS_SERVICE_SIZE];
964 EXEC SQL END DECLARE SECTION;
966 sprintf(outf, "%s/sloc.db", hesiod_dir);
968 sprintf(outft, "%s~", outf);
969 out = fopen(outft, "w");
972 perror("cannot open sloc.db for write");
976 fprintf(stderr, "Building sloc.db\n");
979 EXEC SQL DECLARE s_cursor CURSOR FOR
980 SELECT DISTINCT service, mach_id
983 EXEC SQL OPEN s_cursor;
986 EXEC SQL FETCH s_cursor INTO :service, :id;
990 if (valid(service) && (mach = hash_lookup(machines, id)))
991 fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
993 EXEC SQL CLOSE s_cursor;
999 fprintf(stderr, "Unsuccessful close of sloc.db\n");
1006 db_error(sqlca.sqlcode);
1010 int do_service(void)
1013 char outf[MAXPATHLEN], outft[MAXPATHLEN];
1014 EXEC SQL BEGIN DECLARE SECTION;
1015 char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE];
1016 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
1018 EXEC SQL END DECLARE SECTION;
1020 sprintf(outf, "%s/service.db", hesiod_dir);
1022 sprintf(outft, "%s~", outf);
1023 out = fopen(outft, "w");
1026 perror("cannot open service.db for write");
1030 fprintf(stderr, "Building service.db\n");
1032 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1033 SELECT name, protocol, port
1035 EXEC SQL OPEN s_cursor2;
1038 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1041 lowercase(protocol); /* Convert protocol to lowercase */
1043 if (!valid(service))
1046 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1047 service, HCLASS, HTYPE, service, protocol, port);
1049 EXEC SQL CLOSE s_cursor2;
1051 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1054 WHERE type = 'SERVICE';
1055 EXEC SQL OPEN a_cursor3;
1058 EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
1063 if (!valid(aname) || !valid(trans))
1065 fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
1068 EXEC SQL CLOSE a_cursor3;
1074 fprintf(stderr, "Unsuccessful close of service.db\n");
1080 db_error(sqlca.sqlcode);