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++)
195 FILE *pout, *uout, *bout;
196 char poutf[MAXPATHLEN], uoutf[MAXPATHLEN], poutft[MAXPATHLEN];
197 char uoutft[MAXPATHLEN], boutf[MAXPATHLEN], boutft[MAXPATHLEN];
200 EXEC SQL BEGIN DECLARE SECTION;
201 char login[USERS_LOGIN_SIZE], shell[USERS_SHELL_SIZE];
202 char fullname[USERS_FULLNAME_SIZE], oa[USERS_OFFICE_ADDR_SIZE];
203 char op[USERS_OFFICE_PHONE_SIZE], hp[USERS_HOME_PHONE_SIZE];
204 char nn[USERS_NICKNAME_SIZE], potype[USERS_POTYPE_SIZE];
205 int uid, id, pid, iid, eid, mid, status;
206 EXEC SQL END DECLARE SECTION;
208 sprintf(poutf, "%s/passwd.db", hesiod_dir);
209 sprintf(uoutf, "%s/uid.db", hesiod_dir);
210 sprintf(boutf, "%s/pobox.db", hesiod_dir);
212 sprintf(poutft, "%s~", poutf);
213 pout = fopen(poutft, "w");
216 perror("cannot open passwd.db~ for write");
219 sprintf(uoutft, "%s~", uoutf);
220 uout = fopen(uoutft, "w");
223 perror("cannot open uid.db~ for write");
226 sprintf(boutft, "%s~", boutf);
227 bout = fopen(boutft, "w");
230 perror("cannot open pobox.db for write");
234 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
237 users = create_hash(12001);
238 EXEC SQL DECLARE u_cursor CURSOR FOR
239 SELECT login, unix_uid, shell, fullname, nickname, office_addr,
240 office_phone, home_phone, users_id, potype, pop_id, imap_id, exchange_id,
243 WHERE status = 1 OR status = 2 OR status = 5 OR status = 6
245 EXEC SQL OPEN u_cursor;
248 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
249 :oa, :op, :hp, :id, :potype, :pid, :iid, :eid, :status;
260 u = malloc(sizeof(struct user));
261 strcpy(u->name, login);
263 hash_store(users, id, u);
264 if (status == 1 || status == 2)
266 fprintf(pout, "%s.passwd\t%s %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
267 login, HCLASS, HTYPE, login, uid, fullname, nn, oa,
268 op, hp, login, shell);
269 fprintf(uout, "%d.uid\t%s CNAME %s.passwd\n", uid, HCLASS, login);
274 /* Check for IMAP. Can't use iid because it should be zero. */
275 EXEC SQL SELECT mach_id INTO :mid FROM filesys
276 WHERE label = :login || '.po' AND type = 'IMAP';
277 if (sqlca.sqlcode == 0)
285 EXEC SQL SELECT mach_id INTO :mid FROM filesys
286 WHERE filsys_id = :iid AND type = 'IMAP';
287 if (sqlca.sqlcode == 0)
291 if ((strcmp(potype, "NONE") != 0) && pid != 0 &&
292 (mach = hash_lookup(machines, pid)))
294 fprintf(bout, "%s.pobox\t%s %s \"POP %s %s\"\n",
295 login, HCLASS, HTYPE, mach, login);
298 if (sqlca.sqlcode < 0)
299 db_error(sqlca.sqlcode);
300 EXEC SQL CLOSE u_cursor;
303 if (fclose(pout) || fclose(uout) || fclose(bout))
305 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
317 FILE *iout, *gout, *lout;
318 char ioutf[MAXPATHLEN], goutf[MAXPATHLEN], loutf[MAXPATHLEN];
319 char buf[MAXPATHLEN], *l;
321 struct bucket *b, **p;
324 EXEC SQL BEGIN DECLARE SECTION;
325 char name[LIST_NAME_SIZE];
326 int gid, id, lid, len;
327 EXEC SQL END DECLARE SECTION;
330 sprintf(ioutf, "%s/gid.db", hesiod_dir);
331 sprintf(goutf, "%s/group.db", hesiod_dir);
332 sprintf(loutf, "%s/grplist.db", hesiod_dir);
334 sprintf(buf, "%s~", ioutf);
335 iout = fopen(buf, "w");
338 perror("cannot open gid.db for write");
341 sprintf(buf, "%s~", goutf);
342 gout = fopen(buf, "w");
345 perror("cannot open group.db for write");
348 sprintf(buf, "%s~", loutf);
349 lout = fopen(buf, "w");
352 perror("cannot open grplist.db for write");
356 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
358 /* make space for group list */
359 groups = create_hash(15001);
361 /* The following WHENEVER is declarative, not executed,
362 * and applies for the remainder of this file only.
364 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
366 EXEC SQL DECLARE l_cursor CURSOR FOR
367 SELECT name, gid, list_id
369 WHERE grouplist != 0 AND active != 0
371 EXEC SQL OPEN l_cursor;
374 char buf[LIST_NAME_SIZE + 10];
376 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
382 sprintf(buf, "%s:%d", name, gid);
383 hash_store(groups, lid, strdup(buf));
384 fprintf(iout, "%d.gid\t%s CNAME %s.group\n", gid, HCLASS, name);
385 fprintf(gout, "%s.group\t%s %s \"%s:*:%d:\"\n",
386 name, HCLASS, HTYPE, name, gid);
388 EXEC SQL CLOSE l_cursor;
393 /* now do grplists */
396 users = create_hash(12001);
397 EXEC SQL DECLARE u_cursor2 CURSOR FOR
398 SELECT users_id, login
400 WHERE status = 1 OR status = 2;
401 EXEC SQL OPEN u_cursor2;
404 EXEC SQL FETCH u_cursor2 INTO :id, :name;
407 u = malloc(sizeof(struct user));
408 strcpy(u->name, strtrim(name));
410 hash_store(users, id, u);
412 EXEC SQL CLOSE u_cursor2;
415 EXEC SQL DECLARE i_cursor CURSOR FOR
416 SELECT m.list_id, m.member_id
417 FROM imembers m, list l
418 WHERE m.member_type = 'USER'
419 AND m.list_id = l.list_id AND l.grouplist = 1 AND l.nfsgroup = 1;
420 EXEC SQL OPEN i_cursor;
423 EXEC SQL FETCH i_cursor INTO :lid, :id;
426 if ((l = hash_lookup(groups, lid)) && (u = hash_lookup(users, id)))
428 g = malloc(sizeof(struct grp));
434 EXEC SQL CLOSE i_cursor;
438 for (p = &(users->data[users->size - 1]); p >= users->data; p--)
440 for (b = *p; b; b = b->next)
442 if (!(g = ((struct user *)b->data)->lists))
444 fprintf(lout, "%s.grplist\t%s %s \"",
445 ((struct user *)b->data)->name, HCLASS, HTYPE);
447 for (; g; g = g->next)
449 if (len + strlen(g->lid) + 1 < MAXHESSIZE)
454 len += strlen(g->lid) + 1;
458 com_err(whoami, 0, "truncated grp list for user %s",
459 ((struct user *)b->data)->name);
467 if (fclose(iout) || fclose(gout) || fclose(lout))
469 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
477 db_error(sqlca.sqlcode);
485 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach, *group;
486 struct save_queue *sq, *sq2;
487 EXEC SQL BEGIN DECLARE SECTION;
488 char name[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
489 char loc[FILESYS_NAME_SIZE], access[FILESYS_RWACCESS_SIZE];
490 char mount[FILESYS_MOUNT_SIZE], comments[FILESYS_COMMENTS_SIZE];
491 char key[FSGROUP_KEY_SIZE];
492 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
494 EXEC SQL END DECLARE SECTION;
496 sprintf(outf, "%s/filsys.db", hesiod_dir);
498 sprintf(outft, "%s~", outf);
499 out = fopen(outft, "w");
502 perror("cannot open filsys.db for write");
506 fprintf(stderr, "Building filsys.db\n");
511 EXEC SQL DECLARE f_cursor CURSOR FOR
512 SELECT label, type, name, mach_id, rwaccess, mount, comments, filsys_id
515 EXEC SQL OPEN f_cursor;
518 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
519 :mount, :comments, :fid;
526 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
528 if ((mach = hash_lookup(machines, id)))
530 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s\"\n",
531 name, HCLASS, HTYPE, type, strtrim(loc),
532 mach, strtrim(access), strtrim(mount));
535 else if (!strcmp(type, "AFS"))
537 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s\"\n",
538 name, HCLASS, HTYPE, strtrim(loc),
539 strtrim(access), strtrim(mount));
541 else if (!strcmp(type, "ERR"))
543 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
544 name, HCLASS, HTYPE, strtrim(comments));
546 else if (!strcmp(type, "FSGROUP"))
548 char buf[FILESYS_NAME_SIZE + 10];
549 sprintf(buf, "%s:%d", name, fid);
550 sq_save_data(sq, strdup(buf));
552 else if (!strcmp(type, "MUL"))
554 char buf[FILESYS_NAME_SIZE + 10];
555 sprintf(buf, "%s:%d", name, fid);
556 sq_save_data(sq2, strdup(buf));
559 EXEC SQL CLOSE f_cursor;
561 while (sq_get_data(sq, &group))
563 fid = atoi(strchr(group, ':') + 1);
564 *strchr(group, ':') = 0;
566 EXEC SQL DECLARE f_cursor2 CURSOR FOR
567 SELECT DISTINCT f.type, f.name, f.mach_id, f.rwaccess, f.mount,
568 f.comments, f.label, g.key
569 FROM filesys f, fsgroup g
570 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
572 EXEC SQL OPEN f_cursor2;
573 for (flag = 1; ; flag++)
575 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access, :mount,
576 :comments, :name, :key;
580 if (!strcmp(type, "NFS") || !strcmp(type, "RVD"))
582 if ((mach = hash_lookup(machines, id)))
584 fprintf(out, "%s.filsys\t%s %s \"%s %s %s %s %s %d\"\n",
585 group, HCLASS, HTYPE, type, strtrim(loc), mach,
586 strtrim(access), strtrim(mount), flag);
589 else if (!strcmp(type, "AFS"))
591 fprintf(out, "%s.filsys\t%s %s \"AFS %s %s %s %d\"\n",
592 group, HCLASS, HTYPE, strtrim(loc), strtrim(access),
593 strtrim(mount), flag);
595 else if (!strcmp(type, "ERR"))
597 fprintf(out, "%s.filsys\t%s %s \"ERR %s\"\n",
598 group, HCLASS, HTYPE, strtrim(comments));
601 EXEC SQL CLOSE f_cursor2;
606 while (sq_get_data(sq2, &group))
608 fid = atoi(strchr(group, ':') + 1);
609 *strchr(group, ':') = 0;
610 fprintf(out, "%s.filsys\t%s %s \"MUL", group, HCLASS, HTYPE);
611 EXEC SQL DECLARE f_cursor3 CURSOR FOR
612 SELECT DISTINCT f.label, g.key
613 FROM filesys f, fsgroup g
614 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
616 EXEC SQL OPEN f_cursor3;
619 EXEC SQL FETCH f_cursor3 INTO :name, :key;
622 fprintf(out, " %s", strtrim(name));
624 EXEC SQL CLOSE f_cursor3;
625 fprintf(out, "\"\n");
630 EXEC SQL DECLARE a_cursor CURSOR FOR
633 WHERE type = 'FILESYS';
634 EXEC SQL OPEN a_cursor;
637 EXEC SQL FETCH a_cursor INTO :aname, :trans;
642 if (!valid(aname) || !valid(trans))
644 fprintf(out, "%s.filsys\t%s CNAME %s.filsys\n",
645 aname, HCLASS, trans);
647 EXEC SQL CLOSE a_cursor;
653 fprintf(stderr, "Unsuccessful close of filsys.db\n");
659 db_error(sqlca.sqlcode);
663 int nbitsset(set_mask *set)
667 for (i = 0; i < setsize * NSETBITS; i++)
669 if (SET_ISSET(i, set))
679 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
680 char machbuf[MACHINE_NAME_SIZE], clubuf[CLUSTERS_NAME_SIZE], *p;
681 EXEC SQL BEGIN DECLARE SECTION;
682 int maxmach, maxclu, mid, cid, id;
683 char name[CLUSTERS_NAME_SIZE];
684 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
685 EXEC SQL END DECLARE SECTION;
686 set_mask **machs, *ms, *ps;
688 sprintf(outf, "%s/cluster.db", hesiod_dir);
690 sprintf(outft, "%s~", outf);
691 out = fopen(outft, "w");
694 perror("cannot open cluster.db for write");
698 fprintf(stderr, "Building cluster.db\n");
701 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM clusters;
703 setsize = howmany(maxclu, NSETBITS);
705 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
707 machs = malloc((maxmach + 1) * sizeof(set_mask **));
708 memset(machs, 0, (maxmach + 1) * sizeof(int));
710 EXEC SQL DECLARE p_cursor CURSOR FOR
711 SELECT mach_id, clu_id
714 EXEC SQL OPEN p_cursor;
717 EXEC SQL FETCH p_cursor INTO :mid, :cid;
720 if (!(ms = machs[mid]))
722 ms = machs[mid] = SET_CREATE();
727 EXEC SQL CLOSE p_cursor;
729 for (mid = 1; mid < maxmach; mid++)
734 if (nbitsset(ms) > 1)
736 sprintf(clubuf, "mrinternal-%d", mid);
737 for (cid = 1; cid < maxclu; cid++)
739 if (SET_ISSET(cid, ms))
741 EXEC SQL DECLARE d_cursor CURSOR FOR
742 SELECT serv_label, serv_cluster
745 EXEC SQL OPEN d_cursor;
748 EXEC SQL FETCH d_cursor INTO :label, :data;
753 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
754 clubuf, HCLASS, HTYPE, label, data);
756 EXEC SQL CLOSE d_cursor;
762 for (cid = 1; cid < maxclu; cid++)
763 if (SET_ISSET(cid, ms))
766 EXEC SQL SELECT name INTO :name FROM clusters WHERE clu_id = :cid;
770 strcpy(clubuf, name);
773 if ((mach = hash_lookup(machines, mid)))
775 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
776 mach, HCLASS, clubuf);
777 for (p = machbuf; *mach && *mach != '.'; mach++)
779 if (!strcasecmp(mach, ".mit.edu"))
782 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
783 machbuf, HCLASS, clubuf);
786 for (id = mid + 1; id < maxmach; id++)
788 if ((ps = machs[id]) && !SET_CMP(ms, ps))
792 if ((mach = hash_lookup(machines, id)))
794 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
795 mach, HCLASS, clubuf);
796 for (p = machbuf; *mach && *mach != '.'; mach++)
798 if (!strcasecmp(mach, ".mit.edu"))
801 fprintf(out, "%s.cluster\t%s CNAME %s.cluster\n",
802 machbuf, HCLASS, clubuf);
811 EXEC SQL DECLARE d_cursor2 CURSOR FOR
812 SELECT c.name, d.serv_label, d.serv_cluster
813 FROM svc d, clusters c
814 WHERE c.clu_id = d.clu_id;
815 EXEC SQL OPEN d_cursor2;
818 EXEC SQL FETCH d_cursor2 INTO :name, :label, :data;
826 fprintf(out, "%s.cluster\t%s %s \"%s %s\"\n",
827 name, HCLASS, HTYPE, label, data);
834 fprintf(stderr, "Unsuccessful close of cluster.db\n");
840 db_error(sqlca.sqlcode);
845 int do_printcap(void)
848 char outf[MAXPATHLEN], outft[MAXPATHLEN];
849 EXEC SQL BEGIN DECLARE SECTION;
850 char name[PRINTERS_NAME_SIZE], duplexname[PRINTERS_DUPLEXNAME_SIZE];
851 char rp[PRINTERS_RP_SIZE], type[PRINTERS_TYPE_SIZE];
852 char duplexrp[PRINTERS_RP_SIZE], pskind[PRINTSERVERS_KIND_SIZE];
854 EXEC SQL END DECLARE SECTION;
857 sprintf(outf, "%s/printcap.db", hesiod_dir);
859 sprintf(outft, "%s~", outf);
860 out = fopen(outft, "w");
863 perror("cannot open printcap.db for write");
867 fprintf(stderr, "Building printcap.db\n");
870 EXEC SQL DECLARE p_cursor2 CURSOR FOR
871 SELECT p.name, p.duplexname, p.type, p.rp, p.rm, p.ka, p.mc, ps.kind
872 FROM printers p, printservers ps
873 WHERE p.rm = ps.mach_id;
874 EXEC SQL OPEN p_cursor2;
877 EXEC SQL FETCH p_cursor2 INTO :name, :duplexname, :type,
878 :rp, :rm, :ka, :mc, :pskind;
881 if (!(rmname = hash_lookup(machines, rm)))
887 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
888 name, HCLASS, HTYPE, name, rp, rmname, ka, mc);
891 if (!strcmp(pskind, "BSD"))
892 fprintf(out, "auth=none:remote_support=RQM:");
893 else if (!strcmp(pskind, "ATHENA"))
895 fprintf(out, "auth=%s:az:remote_support=RQM:",
896 ka ? "kerberos4" : "none");
898 else if (!strcmp(pskind, "LPRNG"))
899 fprintf(out, "auth=kerberos5:xn:");
904 if (!valid(duplexname))
906 if (!strcmp(strtrim(type), "ALIAS"))
908 EXEC SQL SELECT duplexname INTO :duplexrp
909 FROM printers WHERE name = :rp;
913 strcpy(duplexrp, duplexname);
914 fprintf(out, "%s.pcap\t%s %s \"%s:rp=%s:rm=%s:ka#%d:mc#%d:",
915 duplexname, HCLASS, HTYPE, duplexname, duplexrp,
918 if (!strcmp(pskind, "BSD"))
919 fprintf(out, "auth=none:remote_support=RQM:");
920 else if (!strcmp(pskind, "ATHENA"))
922 fprintf(out, "auth=%s:az:remote_support=RQM:",
923 ka ? "kerberos4" : "none");
925 else if (!strcmp(pskind, "LPRNG"))
926 fprintf(out, "auth=kerberos5:xn:");
930 EXEC SQL CLOSE p_cursor2;
936 fprintf(stderr, "Unsuccessful close of pcap.db\n");
942 db_error(sqlca.sqlcode);
950 char outf[MAXPATHLEN], outft[MAXPATHLEN], *mach;
951 EXEC SQL BEGIN DECLARE SECTION;
952 char service[SERVERHOSTS_SERVICE_SIZE];
954 EXEC SQL END DECLARE SECTION;
956 sprintf(outf, "%s/sloc.db", hesiod_dir);
958 sprintf(outft, "%s~", outf);
959 out = fopen(outft, "w");
962 perror("cannot open sloc.db for write");
966 fprintf(stderr, "Building sloc.db\n");
969 EXEC SQL DECLARE s_cursor CURSOR FOR
970 SELECT DISTINCT service, mach_id
973 EXEC SQL OPEN s_cursor;
976 EXEC SQL FETCH s_cursor INTO :service, :id;
980 if (valid(service) && (mach = hash_lookup(machines, id)))
981 fprintf(out, "%s.sloc\t%s %s %s\n", service, HCLASS, HTYPE, mach);
983 EXEC SQL CLOSE s_cursor;
989 fprintf(stderr, "Unsuccessful close of sloc.db\n");
996 db_error(sqlca.sqlcode);
1000 int do_service(void)
1003 char outf[MAXPATHLEN], outft[MAXPATHLEN];
1004 EXEC SQL BEGIN DECLARE SECTION;
1005 char service[SERVICES_NAME_SIZE], protocol[SERVICES_PROTOCOL_SIZE];
1006 char aname[ALIAS_NAME_SIZE], trans[ALIAS_TRANS_SIZE];
1008 EXEC SQL END DECLARE SECTION;
1010 sprintf(outf, "%s/service.db", hesiod_dir);
1012 sprintf(outft, "%s~", outf);
1013 out = fopen(outft, "w");
1016 perror("cannot open service.db for write");
1020 fprintf(stderr, "Building service.db\n");
1022 EXEC SQL DECLARE s_cursor2 CURSOR FOR
1023 SELECT name, protocol, port
1025 EXEC SQL OPEN s_cursor2;
1028 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1031 lowercase(protocol); /* Convert protocol to lowercase */
1033 if (!valid(service))
1036 fprintf(out, "%s.service\t%s %s \"%s %s %d\"\n",
1037 service, HCLASS, HTYPE, service, protocol, port);
1039 EXEC SQL CLOSE s_cursor2;
1041 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1044 WHERE type = 'SERVICE';
1045 EXEC SQL OPEN a_cursor3;
1048 EXEC SQL FETCH a_cursor3 INTO :aname, :trans;
1053 if (!valid(aname) || !valid(trans))
1055 fprintf(out, "%s.service\t%s CNAME %s.service\n", aname, HCLASS,
1058 EXEC SQL CLOSE a_cursor3;
1064 fprintf(stderr, "Unsuccessful close of service.db\n");
1070 db_error(sqlca.sqlcode);