]> andersk Git - moira.git/blame - gen/hesiod.dc
Initial revision
[moira.git] / gen / hesiod.dc
CommitLineData
bac4ceaa 1/* $Header$
2 *
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.
6 *
7 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
9 * <mit-copyright.h>.
10 */
11
12#include <mit-copyright.h>
13#include <stdio.h>
14#include <moira.h>
15#include <moira_site.h>
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <sys/time.h>
19#include <ctype.h>
20EXEC SQL INCLUDE sqlca;
21
22
23#ifdef ATHENA
24#define HTYPE "UNSPECA"
25#else
26#define HTYPE "TXT"
27#endif
28
29char hesiod_dir[64];
30
31#define min(x,y) ((x) < (y) ? (x) : (y))
32struct hash *machines = NULL;
33struct hash *users = NULL;
34char *whoami = "hesiod.gen";
35
36struct grp {
37 struct grp *next;
38 char *lid;
39};
40struct user {
41 char name[9];
42 struct grp *lists;
43};
44
45void lowercase();
46char *malloc(), *strsave();
47
48
49main(argc, argv)
50int argc;
51char **argv;
52{
53 char cmd[64];
54 struct stat sb;
55 int changed = 0;
56
57 if (argc > 2) {
58 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
59 exit(MR_ARGS);
60 }
61
62 initialize_sms_error_table ();
63 sprintf(hesiod_dir, "%s/hesiod", DCM_DIR);
64
65#ifsql INGRES
66 EXEC SQL CONNECT sms;
67#endsql
68#ifsql INFORMIX
69 EXEC SQL DATABASE sms;
70#endsql
71
72 changed = do_passwd();
73 changed += do_filsys();
74 changed += do_cluster();
75 changed += do_printcap();
76 changed += do_palladium();
77 changed += do_sloc();
78 changed += do_service();
79 changed += do_groups();
80
81#ifsql INGRES
82 EXEC SQL DISCONNECT;
83#endsql
84#ifsql INFORMIX
85 EXEC SQL CLOSE DATABASE;
86#endsql
87
88 if (!changed) {
89 fprintf(stderr, "No files updated.\n");
90 if (argc == 2 && stat(argv[1], &sb) == 0)
91 exit(MR_NO_CHANGE);
92 }
93
94 if (argc == 2) {
95 fprintf(stderr, "Building tar file.\n");
96 sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
97 if (system(cmd))
98 exit(MR_TAR_FAIL);
99 }
100
101 exit(MR_SUCCESS);
102}
103
104
105get_mach()
106{
107 EXEC SQL BEGIN DECLARE SECTION;
108 int id;
109 char name[33];
110 EXEC SQL END DECLARE SECTION;
111
112 if (machines)
113 return;
114
115 machines = create_hash(1000);
116 EXEC SQL DECLARE m_cursor CURSOR FOR
117 SELECT NAME, MACH_ID
118 FROM MACHINE;
119 EXEC SQL OPEN m_cursor;
120 while (1) {
121 EXEC SQL FETCH m_cursor INTO :name, :id;
122 if (sqlca.sqlcode != 0) break;
123 hash_store(machines, id, strsave(strtrim(name)));
124 }
125 if (sqlca.sqlcode < 0) {
126 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
127 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
128 sqlca.sqlcode);
129 exit(MR_INGRES_ERR);
130 }
131 EXEC SQL CLOSE m_cursor;
132#ifsql INGRES
133#endsql
134#ifsql INFORMIX
135 EXEC SQL COMMIT WORK;
136#endsql
137}
138
139
140do_passwd()
141{
142 FILE *pout, *uout, *bout;
143 char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
144 struct stat psb, usb, bsb;
145 time_t ftime;
146 struct user *u;
147 char *mach;
148 EXEC SQL BEGIN DECLARE SECTION;
149 char login[9], shell[33], fullname[33], oa[17], op[13], hp[17];
150 char nn[17], ptype[9];
151 int uid, flag1, flag2, id, pid;
152 EXEC SQL END DECLARE SECTION;
153
154 sprintf(poutf, "%s/passwd.db", hesiod_dir);
155 sprintf(uoutf, "%s/uid.db", hesiod_dir);
156 sprintf(boutf, "%s/pobox.db", hesiod_dir);
157
158 if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
159 stat(boutf, &bsb) == 0) {
160 ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
161 if (ModDiff (&flag1, "users", ftime) ||
162 ModDiff (&flag2, "machine", ftime))
163 exit (MR_DATE);
164 if (flag1 < 0 && flag2 < 0) {
165 fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
166 return(0);
167 }
168 }
169
170 sprintf(poutft, "%s~", poutf);
171 pout = fopen(poutft, "w");
172 if (!pout) {
173 perror("cannot open passwd.db~ for write");
174 exit(MR_OCONFIG);
175 }
176 sprintf(uoutft, "%s~", uoutf);
177 uout = fopen(uoutft, "w");
178 if (!uout) {
179 perror("cannot open uid.db~ for write");
180 exit(MR_OCONFIG);
181 }
182 sprintf(boutft, "%s~", boutf);
183 bout = fopen(boutft, "w");
184 if (!bout) {
185 perror("cannot open pobox.db for write");
186 exit(MR_OCONFIG);
187 }
188
189 fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
190 get_mach();
191
192 users = create_hash(12001);
193 EXEC SQL DECLARE u_cursor CURSOR FOR
194 SELECT login, uid, shell, fullname, nickname, office_addr,
195 office_phone, home_phone, users_id, pop_id, potype
196 FROM users
197 WHERE status = 1;
198 EXEC SQL OPEN u_cursor;
199 while (1) {
200 EXEC SQL FETCH u_cursor INTO :login, :uid, :shell, :fullname, :nn,
201 :oa, :op, :hp, :id, :pid, :ptype;
202 if (sqlca.sqlcode != 0) break;
203 strtrim(login);
204 dequote(fullname);
205 dequote(nn);
206 dequote(oa);
207 dequote(op);
208 dequote(hp);
209 dequote(shell);
210 u = (struct user *) malloc(sizeof(struct user));
211 strcpy(u->name, login);
212 u->lists = NULL;
213 hash_store(users, id, u);
214 fprintf(pout, "%s.passwd\tHS %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
215 login, HTYPE, login, uid, fullname, nn, oa, op, hp, login, shell);
216 fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login);
217 if (ptype[0] == 'P' && (mach = hash_lookup(machines, pid))) {
218 fprintf(bout, "%s.pobox\tHS %s \"POP %s %s\"\n",
219 login, HTYPE, mach, login);
220 }
221 }
222 if (sqlca.sqlcode < 0) {
223 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
224 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
225 sqlca.sqlcode);
226 exit(MR_INGRES_ERR);
227 }
228 EXEC SQL CLOSE u_cursor;
229#ifsql INGRES
230#endsql
231#ifsql INFORMIX
232 EXEC SQL COMMIT WORK;
233#endsql
234
235 if (fclose(pout) || fclose(uout) || fclose(bout)) {
236 fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
237 exit(MR_CCONFIG);
238 }
239 fix_file(poutf);
240 fix_file(uoutf);
241 fix_file(boutf);
242 return(1);
243}
244
245
246do_groups()
247{
248 FILE *iout, *gout, *lout;
249 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
250 struct hash *groups;
251 register struct bucket *b, **p;
252 struct grp *g;
253 struct user *u;
254 struct stat isb, gsb, lsb;
255 time_t ftime;
256 EXEC SQL BEGIN DECLARE SECTION;
257 char name[33];
258 int gid, id, lid, flag1, flag2, flag3;
259 EXEC SQL END DECLARE SECTION;
260
261 /* open files */
262 sprintf(ioutf, "%s/gid.db", hesiod_dir);
263 sprintf(goutf, "%s/group.db", hesiod_dir);
264 sprintf(loutf, "%s/grplist.db", hesiod_dir);
265
266 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
267 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
268 if (ModDiff (&flag1, "users", ftime) ||
269 ModDiff (&flag2, "list", ftime) ||
270 ModDiff (&flag3, "imembers", ftime))
271 exit (MR_DATE);
272 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
273 fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
274 return(0);
275 }
276 }
277
278 sprintf(buf, "%s~", ioutf);
279 iout = fopen(buf, "w");
280 if (!iout) {
281 perror("cannot open gid.db for write");
282 exit(MR_OCONFIG);
283 }
284 sprintf(buf, "%s~", goutf);
285 gout = fopen(buf, "w");
286 if (!gout) {
287 perror("cannot open group.db for write");
288 exit(MR_OCONFIG);
289 }
290 sprintf(buf, "%s~", loutf);
291 lout = fopen(buf, "w");
292 if (!lout) {
293 perror("cannot open grplist.db for write");
294 exit(MR_OCONFIG);
295 }
296
297 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
298
299 /* make space for group list */
300 groups = create_hash(15001);
301
302 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
303
304 /* get lock records */
305 EXEC SQL SELECT modtime INTO :name FROM list WHERE list_id = 0;
306 EXEC SQL SELECT modtime INTO :name FROM users WHERE users_id = 0;
307
308 EXEC SQL DECLARE l_cursor CURSOR FOR
309 SELECT name, gid, list_id
310 FROM list
311 WHERE grp != 0 AND active != 0;
312 EXEC SQL OPEN l_cursor;
313 while (1) {
314 EXEC SQL FETCH l_cursor INTO :name, :gid, :lid;
315 if (sqlca.sqlcode != 0) break;
316 strtrim(name);
317 sprintf(buf, "%s:%d", name, gid);
318 hash_store(groups, lid, strsave(buf));
319 fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
320 fprintf(gout, "%s.group\tHS %s \"%s:*:%d:\"\n",
321 name, HTYPE, name, gid);
322 }
323 EXEC SQL CLOSE l_cursor;
324
325 fflush(iout);
326 fflush(gout);
327
328 /* now do grplists */
329 if (users == NULL) {
330 users = create_hash(12001);
331 EXEC SQL DECLARE u_cursor2 CURSOR FOR
332 SELECT users_id, login
333 FROM users
334 WHERE status = 1;
335 EXEC SQL OPEN u_cursor2;
336 while (1) {
337 EXEC SQL FETCH u_cursor2 INTO :id, :name;
338 if (sqlca.sqlcode != 0) break;
339 u = (struct user *) malloc(sizeof(struct user));
340 strcpy(u->name, strtrim(name));
341 u->lists = NULL;
342 hash_store(users, id, u);
343 }
344 EXEC SQL CLOSE u_cursor2;
345 }
346
347 EXEC SQL DECLARE i_cursor CURSOR FOR
348 SELECT list_id, member_id
349 FROM imembers
350 WHERE member_type = "USER";
351 EXEC SQL OPEN i_cursor;
352 while (1) {
353 EXEC SQL FETCH i_cursor INTO :lid, :id;
354 if (sqlca.sqlcode != 0) break;
355 if (((l = hash_lookup(groups, lid)) != NULL) &&
356 (u = (struct user *) hash_lookup(users, id))) {
357 g = (struct grp *) malloc(sizeof(struct grp));
358 g->next = u->lists;
359 u->lists = g;
360 g->lid = l;
361 }
362 }
363 EXEC SQL CLOSE i_cursor;
364#ifsql INGRES
365#endsql
366#ifsql INFORMIX
367 EXEC SQL COMMIT WORK;
368#endsql
369
370 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
371 for (b = *p; b; b = b->next) {
372 if ((g = ((struct user *)b->data)->lists) == NULL)
373 continue;
374 fprintf(lout, "%s.grplist\tHS %s \"",
375 ((struct user *)b->data)->name, HTYPE);
376 for (; g; g = g->next) {
377 fputs(g->lid, lout);
378 if (g->next)
379 putc(':', lout);
380 }
381 fputs("\"\n", lout);
382 }
383 }
384
385 if (fclose(iout) || fclose(gout) || fclose(lout)) {
386 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
387 exit(MR_CCONFIG);
388 }
389 fix_file(ioutf);
390 fix_file(goutf);
391 fix_file(loutf);
392 return(1);
393 sqlerr:
394 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
395 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
396 sqlca.sqlcode);
397 exit(MR_INGRES_ERR);
398}
399
400
401do_filsys()
402{
403 FILE *out;
404 char outf[64], outft[64], *mach, machbuf[128], *group;
405 register char *p;
406 struct stat sb;
407 time_t ftime;
408 struct save_queue *sq, *sq_create();
409 EXEC SQL BEGIN DECLARE SECTION;
410 char name[33], type[9], loc[81], access[2], mount[33], trans[257];
411 char comments[65];
412 int flag1, flag2, flag3, flag4, id, fid;
413 EXEC SQL END DECLARE SECTION;
414 char *index();
415
416 sprintf(outf, "%s/filsys.db", hesiod_dir);
417
418 if (stat(outf, &sb) == 0) {
419 ftime = sb.st_mtime;
420
421 if (ModDiff(&flag1, "filesys", ftime)) exit (MR_DATE);
422 if (ModDiff(&flag2, "machine", ftime)) exit (MR_DATE);
423 if (ModDiff(&flag3, "alias", ftime)) exit (MR_DATE);
424 if (ModDiff(&flag4, "fsgroup", ftime)) exit (MR_DATE);
425
426 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
427 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
428 return(0);
429 }
430 }
431
432 sprintf(outft, "%s~", outf);
433 out = fopen(outft, "w");
434 if (!out) {
435 perror("cannot open filsys.db for write");
436 exit(MR_OCONFIG);
437 }
438
439 fprintf(stderr, "Building filsys.db\n");
440 get_mach();
441 sq = sq_create();
442
443 EXEC SQL DECLARE f_cursor CURSOR FOR
444 SELECT label, type, name, mach_id, access, mount, comments, filsys_id
445 FROM filesys;
446 EXEC SQL OPEN f_cursor;
447 while (1) {
448 EXEC SQL FETCH f_cursor INTO :name, :type, :loc, :id, :access,
449 :mount, :comments, :fid;
450 if (sqlca.sqlcode != 0) break;
451 strtrim(type);
452 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
453 if (mach = hash_lookup(machines, id)) {
454 for (p = machbuf; *mach && *mach != '.'; mach++) {
455 if (isupper(*mach))
456 *p++ = tolower(*mach);
457 else
458 *p++ = *mach;
459 }
460 *p = 0;
461 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
462 strtrim(name), HTYPE, type, strtrim(loc), machbuf,
463 strtrim(access), strtrim(mount));
464 }
465 } else if (!strcmp(type, "AFS")) {
466 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
467 strtrim(name), HTYPE, strtrim(loc), strtrim(access),
468 strtrim(mount));
469 } else if (!strcmp(type, "ERR")) {
470 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
471 strtrim(name), HTYPE, strtrim(comments));
472 } else if (!strcmp(type, "FSGROUP")) {
473 sprintf(trans, "%s:%d", strtrim(name), fid);
474 sq_save_data(sq, strsave(trans));
475 }
476 }
477 EXEC SQL CLOSE f_cursor;
478
479 while (sq_get_data(sq, &group)) {
480 fid = atoi(index(group, ':')+1);
481 *index(group, ':') = 0;
482
483 EXEC SQL DECLARE f_cursor2 CURSOR FOR
484 SELECT DISTINCT f.type, f.name, f.mach_id, f.access, f.mount,
485 f.comments, f.label, g.key
486 FROM filesys f, fsgroup g
487 WHERE f.filsys_id = g.filsys_id AND g.group_id = :fid
488 ORDER BY key, label;
489 EXEC SQL OPEN f_cursor2;
490 while (1) {
491 EXEC SQL FETCH f_cursor2 INTO :type, :loc, :id, :access,:mount,
492 :comments, :name, :trans;
493 if (sqlca.sqlcode != 0) break;
494 strtrim(type);
495 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
496 if (mach = hash_lookup(machines, id)) {
497 for (p = machbuf; *mach && *mach != '.'; mach++) {
498 if (isupper(*mach))
499 *p++ = tolower(*mach);
500 else
501 *p++ = *mach;
502 }
503 *p = 0;
504 fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
505 group, HTYPE, type, strtrim(loc), machbuf,
506 strtrim(access), strtrim(mount));
507 }
508 } else if (!strcmp(type, "AFS")) {
509 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
510 group, HTYPE, strtrim(loc), strtrim(access),
511 strtrim(mount));
512 } else if (!strcmp(type, "ERR")) {
513 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
514 group, HTYPE, strtrim(comments));
515 }
516 }
517 EXEC SQL CLOSE f_cursor2;
518 free(group);
519 }
520 sq_destroy(sq);
521
522 EXEC SQL DECLARE a_cursor CURSOR FOR
523 SELECT name, trans
524 FROM alias
525 WHERE type = "FILESYS";
526 EXEC SQL OPEN a_cursor;
527 while (1) {
528 EXEC SQL FETCH a_cursor INTO :name, :trans;
529 if (sqlca.sqlcode != 0) break;
530 fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n",
531 strtrim(name), strtrim(trans));
532 }
533 EXEC SQL CLOSE a_cursor;
534#ifsql INGRES
535#endsql
536#ifsql INFORMIX
537 EXEC SQL COMMIT WORK;
538#endsql
539
540 if (fclose(out)) {
541 fprintf(stderr, "Unsuccessful close of filsys.db\n");
542 exit(MR_CCONFIG);
543 }
544 fix_file(outf);
545 return(1);
546 sqlerr:
547 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
548 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
549 sqlca.sqlcode);
550 exit(MR_INGRES_ERR);
551}
552
553
554/*
555 * Modified from sys/types.h:
556 */
557int setsize; /* = howmany(setbits, NSETBITS) */
558
559typedef long set_mask;
560#define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
561#ifndef howmany
562#define howmany(x, y) (((x)+((y)-1))/(y))
563#endif
564
565#define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
566#define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
567#define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
568#define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
569#define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask))
570#define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
571
572int nbitsset(set)
573set_mask *set;
574{
575 int i, ret;
576 ret = 0;
577 for (i = 0; i < setsize * NSETBITS; i++)
578 if (SET_ISSET(i, set))
579 ret++;
580 return(ret);
581}
582
583
584do_cluster()
585{
586 FILE *out;
587 char outf[64], outft[64], *mach, machbuf[33], *p;
588 struct stat sb;
589 time_t ftime;
590 EXEC SQL BEGIN DECLARE SECTION;
591 int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
592 char name[33], label2[17], data[33];
593 EXEC SQL END DECLARE SECTION;
594 set_mask **machs, *ms, *ps;
595 int oneclu;
596
597 sprintf(outf, "%s/cluster.db", hesiod_dir);
598
599 if (stat(outf, &sb) == 0) {
600 ftime = sb.st_mtime;
601 if (ModDiff (&flag1, "cluster", ftime)
602 || ModDiff (&flag2, "machine", ftime)
603 || ModDiff (&flag3, "mcmap", ftime)
604 || ModDiff (&flag4, "svc", ftime)) exit (MR_DATE);
605 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
606 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
607 return(0);
608 }
609 }
610
611 sprintf(outft, "%s~", outf);
612 out = fopen(outft, "w");
613 if (!out) {
614 perror("cannot open cluster.db for write");
615 exit(MR_OCONFIG);
616 }
617
618 fprintf(stderr, "Building cluster.db\n");
619 get_mach();
620
621 EXEC SQL SELECT MAX(clu_id) INTO :maxclu FROM cluster;
622 maxclu++;
623 setsize = howmany(maxclu, NSETBITS);
624
625 EXEC SQL SELECT MAX(mach_id) INTO :maxmach FROM machine;
626 maxmach++;
627 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
628 bzero(machs, (maxmach + 1) * sizeof(int));
629
630 EXEC SQL DECLARE p_cursor CURSOR FOR
631 SELECT mach_id, clu_id
632 FROM mcmap;
633 EXEC SQL OPEN p_cursor;
634 while (1) {
635 EXEC SQL FETCH p_cursor INTO :mid, :cid;
636 if (sqlca.sqlcode != 0) break;
637 if (!(ms = machs[mid])) {
638 ms = machs[mid] = SET_CREATE();
639 SET_ZERO(ms);
640 }
641 SET_SET(cid, ms);
642 }
643 EXEC SQL CLOSE p_cursor;
644
645 for (mid = 1; mid < maxmach; mid++) {
646 if (!machs[mid])
647 continue;
648 ms = machs[mid];
649 if (nbitsset(ms) > 1) {
650 oneclu = 0;
651 for (cid = 1; cid < maxclu; cid++) {
652 if (SET_ISSET(cid, ms)) {
653 EXEC SQL DECLARE d_cursor CURSOR FOR
654 SELECT serv_label, serv_cluster
655 FROM svc
656 WHERE clu_id = :cid;
657 EXEC SQL OPEN d_cursor;
658 while (1) {
659 EXEC SQL FETCH d_cursor INTO :label2, :data;
660 if (sqlca.sqlcode != 0) break;
661 strtrim(label2);
662 strtrim(data);
663 fprintf(out,
664 "mrinternal-%d.cluster\tHS %s \"%s %s\"\n",
665 mid, HTYPE, label2, data);
666 }
667 EXEC SQL CLOSE d_cursor;
668 }
669 }
670 } else {
671 oneclu = 1;
672 for (cid = 1; cid < maxclu; cid++)
673 if (SET_ISSET(cid, ms)) break;
674
675 EXEC SQL SELECT name INTO :name FROM cluster WHERE clu_id = :cid;
676 strtrim(name);
677 }
678
679 if (mach = hash_lookup(machines, mid)) {
680 for (p = machbuf; *mach && *mach != '.'; mach++)
681 *p++ = *mach;
682 *p = 0;
683 if (oneclu)
684 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
685 machbuf, name);
686 else
687 fprintf(out, "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
688 machbuf, mid);
689 }
690 for (id = mid + 1; id < maxmach; id++) {
691 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
692 free(ps);
693 machs[id] = NULL;
694 if (mach = hash_lookup(machines, id)) {
695 for (p = machbuf; *mach && *mach != '.'; mach++)
696 *p++ = *mach;
697 *p = 0;
698 if (oneclu)
699 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
700 machbuf, name);
701 else
702 fprintf(out,
703 "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
704 machbuf, mid);
705 }
706 }
707 }
708 free(ms);
709 machs[mid] = NULL;
710 }
711
712 EXEC SQL DECLARE d_cursor2 CURSOR FOR
713 SELECT c.name, d.serv_label, d.serv_cluster
714 FROM svc d, cluster c
715 WHERE c.clu_id = d.clu_id;
716 EXEC SQL OPEN d_cursor2;
717 while (1) {
718 EXEC SQL FETCH d_cursor2 INTO :name, :label2, :data;
719 if (sqlca.sqlcode != 0) break;
720 strtrim(name);
721 strtrim(label2);
722 strtrim(data);
723 fprintf(out, "%s.cluster\tHS %s \"%s %s\"\n",
724 name, HTYPE, label2, data);
725 }
726 free(machs);
727#ifsql INGRES
728#endsql
729#ifsql INFORMIX
730 EXEC SQL COMMIT WORK;
731#endsql
732
733 if (fclose(out)) {
734 fprintf(stderr, "Unsuccessful close of cluster.db\n");
735 exit(MR_CCONFIG);
736 }
737 fix_file(outf);
738 return(1);
739 sqlerr:
740 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
741 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
742 sqlca.sqlcode);
743 exit(MR_INGRES_ERR);
744}
745
746
747do_printcap()
748{
749 FILE *out;
750 char outf[64], outft[64];
751 struct stat sb;
752 time_t ftime;
753 EXEC SQL BEGIN DECLARE SECTION;
754 char name[17], rp[17], sd[33];
755 int flag, ka, pc, rm, rq;
756 EXEC SQL END DECLARE SECTION;
757
758 sprintf(outf, "%s/printcap.db", hesiod_dir);
759
760 if (stat(outf, &sb) == 0) {
761 ftime = sb.st_mtime;
762 if (ModDiff (&flag, "printcap", ftime)) exit (MR_DATE);
763 if (flag < 0) {
764 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
765 return(0);
766 }
767 }
768
769 sprintf(outft, "%s~", outf);
770 out = fopen(outft, "w");
771 if (!out) {
772 perror("cannot open printcap.db for write");
773 exit(MR_OCONFIG);
774 }
775
776 fprintf(stderr, "Building printcap.db\n");
777 get_mach();
778
779 EXEC SQL DECLARE p_cursor2 CURSOR FOR
780 SELECT name, rp, dir, mach_id, auth, price, quotaserver
781 FROM printcap;
782 EXEC SQL OPEN p_cursor2;
783 while (1) {
784 EXEC SQL FETCH p_cursor2 INTO :name, :rp, :sd, :rm, :ka, :pc, :rq;
785 if (sqlca.sqlcode != 0) break;
786 strtrim(name);
787 strtrim(rp);
788 strtrim(sd);
789 fprintf(out, "%s.pcap\tHS %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
790 name, HTYPE, name, rp, hash_lookup(machines, rm), sd, ka, pc);
791 if (rq)
792 fprintf(out, ":rq=%s\"\n", hash_lookup(machines, rq));
793 else
794 fputs("\"\n", out);
795 }
796 EXEC SQL CLOSE p_cursor2;
797#ifsql INGRES
798#endsql
799#ifsql INFORMIX
800 EXEC SQL COMMIT WORK;
801#endsql
802
803 if (fclose(out)) {
804 fprintf(stderr, "Unsuccessful close of pcap.db\n");
805 exit(MR_CCONFIG);
806 }
807 fix_file(outf);
808 return(1);
809 sqlerr:
810 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
811 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
812 sqlca.sqlcode);
813 exit(MR_INGRES_ERR);
814 }
815
816
817do_palladium()
818{
819 FILE *out;
820 char outf[64], outft[64];
821 struct stat sb;
822 time_t ftime;
823 EXEC SQL BEGIN DECLARE SECTION;
824 char name[33], trans[129];
825 int flag, flag1, ident, rm;
826 EXEC SQL END DECLARE SECTION;
827
828 sprintf(outf, "%s/palladium.db", hesiod_dir);
829
830 if (stat(outf, &sb) == 0) {
831 ftime = sb.st_mtime;
832 if ((ModDiff (&flag, "palladium", ftime)) ||
833 (ModDiff (&flag1, "alias", ftime))) exit (MR_DATE);
834 if (flag < 0 && flag1 < 0) {
835 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
836 return(0);
837 }
838 }
839
840 sprintf(outft, "%s~", outf);
841 out = fopen(outft, "w");
842 if (!out) {
843 perror("cannot open palladium.db for write");
844 exit(MR_OCONFIG);
845 }
846
847 fprintf(stderr, "Building palladium.db\n");
848 get_mach();
849
850 EXEC SQL DECLARE p_cursor3 CURSOR FOR
851 SELECT name, ident, mach_id
852 FROM palladium;
853 EXEC SQL OPEN p_cursor3;
854 while (1) {
855 EXEC SQL FETCH p_cursor3 INTO :name, :ident, :rm;
856 if (sqlca.sqlcode != 0) break;
857 strtrim(name);
858 fprintf(out,
859 "%s.palladium\tHS %s \"%s %d %s interface directory\"\n",
860 name, HTYPE, hash_lookup(machines, rm), ident, name);
861 }
862 EXEC SQL CLOSE p_cursor3;
863
864 EXEC SQL DECLARE a_cursor2 CURSOR FOR
865 SELECT name, trans
866 FROM alias
867 WHERE type = "PALLADIUM";
868 EXEC SQL OPEN a_cursor2;
869 while (1) {
870 EXEC SQL FETCH a_cursor2 INTO :name, :trans;
871 if (sqlca.sqlcode != 0) break;
872 strtrim(name);
873 strtrim(trans);
874 fprintf(out, "%s.palladium\tHS %s \"%s\"\n", name, HTYPE, trans);
875 }
876 EXEC SQL CLOSE a_cursor2;
877#ifsql INGRES
878#endsql
879#ifsql INFORMIX
880 EXEC SQL COMMIT WORK;
881#endsql
882
883 if (fclose(out)) {
884 fprintf(stderr, "Unsuccessful close of palladium.db\n");
885 exit(MR_CCONFIG);
886 }
887 fix_file(outf);
888 return(1);
889 sqlerr:
890 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
891 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
892 sqlca.sqlcode);
893 exit(MR_INGRES_ERR);
894}
895
896
897do_sloc()
898{
899 FILE *out;
900 char outf[64], outft[64], *mach;
901 struct stat sb;
902 time_t ftime;
903 EXEC SQL BEGIN DECLARE SECTION;
904 char service[17];
905 int flag1, flag2, id;
906 EXEC SQL END DECLARE SECTION;
907
908 sprintf(outf, "%s/sloc.db", hesiod_dir);
909
910 if (stat(outf, &sb) == 0) {
911 ftime = sb.st_mtime;
912 if ((ModDiff (&flag1, "serverhosts", ftime)) ||
913 (ModDiff (&flag2, "machine", ftime))) exit (MR_DATE);
914 if (flag1 < 0 && flag2 < 0) {
915 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
916 return(0);
917 }
918 }
919
920 sprintf(outft, "%s~", outf);
921 out = fopen(outft, "w");
922 if (!out) {
923 perror("cannot open sloc.db for write");
924 exit(MR_OCONFIG);
925 }
926
927 fprintf(stderr, "Building sloc.db\n");
928 get_mach();
929
930 EXEC SQL DECLARE s_cursor CURSOR FOR
931 SELECT DISTINCT service, mach_id
932 FROM serverhosts
933 ORDER BY service;
934 EXEC SQL OPEN s_cursor;
935 while (1) {
936 EXEC SQL FETCH s_cursor INTO :service, :id;
937 if (sqlca.sqlcode != 0) break;
938 strtrim(service);
939 if (mach = hash_lookup(machines, id))
940 fprintf(out, "%s.sloc\tHS %s %s\n", service, HTYPE, mach);
941 }
942 EXEC SQL CLOSE s_cursor;
943#ifsql INGRES
944#endsql
945#ifsql INFORMIX
946 EXEC SQL COMMIT WORK;
947#endsql
948
949 if (fclose(out)) {
950 fprintf(stderr, "Unsuccessful close of sloc.db\n");
951 exit(MR_CCONFIG);
952 }
953
954 fix_file(outf);
955 return(1);
956 sqlerr:
957 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
958 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
959 sqlca.sqlcode);
960 exit(MR_INGRES_ERR);
961}
962
963do_service()
964{
965 FILE *out;
966 char outf[64], outft[64];
967 struct stat sb;
968 time_t ftime;
969 EXEC SQL BEGIN DECLARE SECTION;
970 char service[33], protocol[9], altserv[129];
971 int port, flag1;
972 EXEC SQL END DECLARE SECTION;
973
974 sprintf(outf, "%s/service.db", hesiod_dir);
975
976 if (stat(outf, &sb) == 0) {
977 ftime = sb.st_mtime;
978 if (ModDiff (&flag1, "services", ftime)) exit (MR_DATE);
979 if (flag1 < 0) {
980 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
981 return(0);
982 }
983 }
984
985 sprintf(outft, "%s~", outf);
986 out = fopen(outft, "w");
987 if (!out) {
988 perror("cannot open service.db for write");
989 exit(MR_OCONFIG);
990 }
991
992 fprintf(stderr, "Building service.db\n");
993
994 EXEC SQL DECLARE s_cursor2 CURSOR FOR
995 SELECT name, protocol, port
996 FROM services;
997 EXEC SQL OPEN s_cursor2;
998 while (1) {
999 EXEC SQL FETCH s_cursor2 INTO :service, :protocol, :port;
1000 if (sqlca.sqlcode != 0) break;
1001 lowercase(protocol); /* Convert protocol to lowercase */
1002 strtrim(service);
1003 strtrim(protocol);
1004 fprintf(out, "%s.service\tHS %s \"%s %s %d\"\n",
1005 service, HTYPE, service, protocol, port);
1006 }
1007 EXEC SQL CLOSE s_cursor2;
1008
1009 EXEC SQL DECLARE a_cursor3 CURSOR FOR
1010 SELECT name, trans
1011 FROM alias
1012 WHERE type = "SERVICE";
1013 EXEC SQL OPEN a_cursor3;
1014 while (1) {
1015 EXEC SQL FETCH a_cursor3 INTO :service, :altserv;
1016 if (sqlca.sqlcode != 0) break;
1017 strtrim(service);
1018 strtrim(altserv);
1019 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
1020 }
1021 EXEC SQL CLOSE a_cursor3;
1022#ifsql INGRES
1023#endsql
1024#ifsql INFORMIX
1025 EXEC SQL COMMIT WORK;
1026#endsql
1027
1028 if (fclose(out)) {
1029 fprintf(stderr, "Unsuccessful close of service.db\n");
1030 exit(MR_CCONFIG);
1031 }
1032 fix_file(outf);
1033 return(1);
1034 sqlerr:
1035 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
1036 critical_alert("DCM", "Hesiod build encountered DATABASE ERROR %d",
1037 sqlca.sqlcode);
1038 exit(MR_INGRES_ERR);
1039}
This page took 0.173221 seconds and 5 git commands to generate.