]> andersk Git - moira.git/blob - gen/hesiod.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / gen / hesiod.qc
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>
20
21
22 #ifdef ATHENA
23 #define HTYPE "UNSPECA"
24 #else
25 #define HTYPE "TXT"
26 #endif
27
28 char hesiod_dir[64];
29
30 #define min(x,y)        ((x) < (y) ? (x) : (y))
31 struct hash *machines = NULL;
32 struct hash *users = NULL;
33 char *whoami = "hesiod.gen";
34
35 struct grp {
36     struct grp *next;
37     char *lid;
38 };
39 struct user {
40     char name[9];
41     struct grp *lists;
42 };
43
44 char *malloc(), *strsave();
45 char *ingres_date_and_time(), *ingres_time(), *ingres_date();
46
47 main(argc, argv)
48 int argc;
49 char **argv;
50 {
51     char cmd[64];
52     struct stat sb;
53     int changed = 0;
54     int ingerr();
55
56     if (argc > 2) {
57         fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
58         exit(MR_ARGS);
59     }
60
61     IIseterr(ingerr);
62     initialize_sms_error_table ();
63     sprintf(hesiod_dir, "%s/hesiod", DCM_DIR);
64
65 ##  ingres sms
66 ##  set lockmode session where level = table
67
68     changed = do_passwd();
69     changed += do_filsys();
70     changed += do_cluster();
71     changed += do_printcap();
72     changed += do_palladium();
73     changed += do_sloc();
74     changed += do_service();
75     changed += do_groups();
76
77 ##  exit
78
79     if (!changed) {
80         fprintf(stderr, "No files updated.\n");
81         if (argc == 2 && stat(argv[1], &sb) == 0)
82           exit(MR_NO_CHANGE);
83     }
84
85     if (argc == 2) {
86         fprintf(stderr, "Building tar file.\n");
87         sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
88         if (system(cmd))
89           exit(MR_TAR_FAIL);
90     }
91
92     exit(MR_SUCCESS);
93 }
94
95
96 /*
97  * ingerr: (supposedly) called when Ingres indicates an error.
98  * I have not yet been able to get this to work to intercept a
99  * database open error.
100  */
101 #define INGRES_DEADLOCK 4700
102
103 static int ingerr(num)
104     int *num;
105 {
106     int ingres_errno;
107
108     switch (*num) {
109     case INGRES_DEADLOCK:
110         ingres_errno = MR_DEADLOCK;
111         break;
112     default:
113         ingres_errno = MR_INGRES_ERR;
114     }
115     com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
116     critical_alert("DCM", "Hesiod build encountered INGRES ERROR %d", *num);
117     exit(ingres_errno);
118 }
119
120
121 get_mach()
122 ##{
123 ##  int id;
124 ##  char name[33];
125
126     if (machines)
127       return;
128
129     machines = create_hash(1000);
130 ##  retrieve (name = machine.#name, id = machine.mach_id) {
131         hash_store(machines, id, strsave(strtrim(name)));
132 ##  }
133 ##}
134
135
136 do_passwd()
137 ##{
138     FILE *pout, *uout, *bout;
139     char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
140     struct stat psb, usb, bsb;
141     time_t ftime;
142     struct user *u;
143     char *mach;
144 ##  char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime;
145 ##  char nn[17], ptype[9];
146 ##  int uid, flag1, flag2, id, pid;
147
148     sprintf(poutf, "%s/passwd.db", hesiod_dir);
149     sprintf(uoutf, "%s/uid.db", hesiod_dir);
150     sprintf(boutf, "%s/pobox.db", hesiod_dir);
151
152     if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
153         stat(boutf, &bsb) == 0) {
154         ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
155         filetime = ingres_date_and_time(ftime);
156 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
157 ##          where tblstats.table = "users"
158 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
159 ##          where tblstats.table = "machine"
160         if (flag1 < 0 && flag2 < 0) {
161             fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
162             return(0);
163       }
164     }
165
166     sprintf(poutft, "%s~", poutf);
167     pout = fopen(poutft, "w");
168     if (!pout) {
169         perror("cannot open passwd.db~ for write");
170         exit(MR_OCONFIG);
171     }
172     sprintf(uoutft, "%s~", uoutf);
173     uout = fopen(uoutft, "w");
174     if (!uout) {
175         perror("cannot open uid.db~ for write");
176         exit(MR_OCONFIG);
177     }
178     sprintf(boutft, "%s~", boutf);
179     bout = fopen(boutft, "w");
180     if (!bout) {
181         perror("cannot open pobox.db for write");
182         exit(MR_OCONFIG);
183     }
184
185     fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
186     get_mach();
187
188     users = create_hash(12001);
189 ##  range of u is users
190 ##  retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
191 ##            fullname = u.#fullname, nn = u.nickname, oa = u.office_addr,
192 ##            op = u.office_phone, hp = u.home_phone, id = u.users_id,
193 ##            pid = u.pop_id, ptype = u.potype)
194 ##      where u.status = 1 {
195             strtrim(login);
196             dequote(fullname);
197             dequote(nn);
198             dequote(oa);
199             dequote(op);
200             dequote(hp);
201             dequote(shell);
202             u = (struct user *) malloc(sizeof(struct user));
203             strcpy(u->name, login);
204             u->lists = NULL;
205             hash_store(users, id, u);
206             fprintf(pout, "%s.passwd\tHS %s \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n",
207                     login, HTYPE, login, uid, fullname, nn, oa, op, hp, login, shell);
208             fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login);
209             if (ptype[0] == 'P' && (mach = hash_lookup(machines, pid))) {
210                 fprintf(bout, "%s.pobox\tHS %s \"POP %s %s\"\n",
211                         login, HTYPE, mach, login);
212             }
213 ##  }
214
215     if (fclose(pout) || fclose(uout) || fclose(bout)) {
216         fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
217         exit(MR_CCONFIG);
218     }
219     fix_file(poutf);
220     fix_file(uoutf);
221     fix_file(boutf);
222     return(1);
223 ##}
224
225
226 do_groups()
227 ##{
228     FILE *iout, *gout, *lout;
229     char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
230     struct hash *groups;
231     register struct bucket *b, **p;
232     struct grp *g;
233     struct user *u;
234     struct stat isb, gsb, lsb;
235     time_t ftime;
236 ##  char name[33], *filetime;
237 ##  int gid, id, lid, flag1, flag2, flag3;
238
239     /* open files */
240     sprintf(ioutf, "%s/gid.db", hesiod_dir);
241     sprintf(goutf, "%s/group.db", hesiod_dir);
242     sprintf(loutf, "%s/grplist.db", hesiod_dir);
243
244     if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
245         ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
246         filetime = ingres_date_and_time(ftime);
247 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
248 ##          where tblstats.table = "users"
249 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
250 ##          where tblstats.table = "list"
251 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
252 ##          where tblstats.table = "imembers"
253         if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
254             fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
255             return(0);
256       }
257     }
258
259     sprintf(buf, "%s~", ioutf);
260     iout = fopen(buf, "w");
261     if (!iout) {
262         perror("cannot open gid.db for write");
263         exit(MR_OCONFIG);
264     }
265     sprintf(buf, "%s~", goutf);
266     gout = fopen(buf, "w");
267     if (!gout) {
268         perror("cannot open group.db for write");
269         exit(MR_OCONFIG);
270     }
271     sprintf(buf, "%s~", loutf);
272     lout = fopen(buf, "w");
273     if (!lout) {
274         perror("cannot open grplist.db for write");
275         exit(MR_OCONFIG);
276     }
277
278     fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
279
280     /* make space for group list */
281     groups = create_hash(15001);
282
283     /* retrieve simple groups */
284 ##  range of l is list
285 ##  range of m is imembers
286 ##  begin transaction
287     /* get lock records */
288 ##  retrieve (name = l.modtime) where l.list_id = 0
289 ##  retrieve (name = users.modtime) where users.users_id = 0
290
291 ##  retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
292 ##      where l.group != 0 and l.active != 0 {
293             strtrim(name);
294             sprintf(buf, "%s:%d", name, gid);
295             hash_store(groups, lid, strsave(buf));
296             fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
297             fprintf(gout, "%s.group\tHS %s \"%s:*:%d:\"\n",
298                     name, HTYPE, name, gid);
299 ##  }
300
301     fflush(iout);
302     fflush(gout);
303
304     /* now do grplists */
305     if (users == NULL) {
306         users = create_hash(12001);
307 ##      range of u is users
308 ##      retrieve (id = u.users_id, name = u.login) where u.status = 1 {
309           u = (struct user *) malloc(sizeof(struct user));
310           strcpy(u->name, strtrim(name));
311           u->lists = NULL;
312           hash_store(users, id, u);
313 ##      }
314     }
315
316 ##  repeat retrieve (lid = m.list_id, id = m.member_id)
317 ##      where m.member_type = "USER" {
318       if (((l = hash_lookup(groups, lid)) != NULL) &&
319           (u = (struct user *) hash_lookup(users, id))) {
320           g = (struct grp *) malloc(sizeof(struct grp));
321           g->next = u->lists;
322           u->lists = g;
323           g->lid = l;
324       }
325 ##  }
326 ##  end transaction
327
328     for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
329         for (b = *p; b; b = b->next) {
330             if ((g = ((struct user *)b->data)->lists) == NULL)
331               continue;
332             fprintf(lout, "%s.grplist\tHS %s \"",
333                     ((struct user *)b->data)->name, HTYPE);
334             for (; g; g = g->next) {
335                 fputs(g->lid, lout);
336                 if (g->next)
337                   putc(':', lout);
338             }
339             fputs("\"\n", lout);
340         }
341     }
342
343     if (fclose(iout) || fclose(gout) || fclose(lout)) {
344         fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
345         exit(MR_CCONFIG);
346     }
347     fix_file(ioutf);
348     fix_file(goutf);
349     fix_file(loutf);
350     return(1);
351 ##}
352
353
354 do_filsys()
355 ##{
356     FILE *out;
357     char outf[64], outft[64], *mach, machbuf[128], *group;
358     register char *p;
359     struct stat sb;
360     time_t ftime;
361     struct save_queue *sq, *sq_create();
362 ##  char name[33], type[9], loc[81], access[2], mount[33], trans[257];
363 ##  char *filetime, comments[65];
364 ##  int flag1, flag2, flag3, flag4, id, fid;
365     char *index();
366
367     sprintf(outf, "%s/filsys.db", hesiod_dir);
368
369     if (stat(outf, &sb) == 0) {
370         ftime = sb.st_mtime;
371         filetime = ingres_date_and_time(ftime);
372 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
373 ##          where tblstats.table = "filesys"
374 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
375 ##          where tblstats.table = "machine"
376 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
377 ##          where tblstats.table = "alias"
378 ##      retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
379 ##          where tblstats.table = "fsgroup"
380         if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
381             fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
382             return(0);
383       }
384     }
385
386     sprintf(outft, "%s~", outf);
387     out = fopen(outft, "w");
388     if (!out) {
389         perror("cannot open filsys.db for write");
390         exit(MR_OCONFIG);
391     }
392
393     fprintf(stderr, "Building filsys.db\n");
394     get_mach();
395     sq = sq_create();
396
397 ##  range of f is filesys
398 ##  retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id,
399 ##            access = f.#access, mount = f.#mount, comments = f.#comments,
400 ##            fid = f.filsys_id) {
401             strtrim(type);
402             if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
403                 if (mach = hash_lookup(machines, id)) {
404                     for (p = machbuf; *mach && *mach != '.'; mach++) {
405                         if (isupper(*mach))
406                           *p++ = tolower(*mach);
407                         else
408                           *p++ = *mach;
409                     }
410                     *p = 0;
411                     fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
412                             strtrim(name), HTYPE, type, strtrim(loc), machbuf,
413                             strtrim(access), strtrim(mount));
414                 }
415             } else if (!strcmp(type, "AFS")) {
416                 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
417                         strtrim(name), HTYPE, strtrim(loc), strtrim(access),
418                         strtrim(mount));
419             } else if (!strcmp(type, "ERR")) {
420                 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
421                         name, HTYPE, strtrim(comments));
422             } else if (!strcmp(type, "FSGROUP")) {
423                 sprintf(trans, "%s:%d", strtrim(name), fid);
424                 sq_save_data(sq, strsave(trans));
425             }
426 ##  }
427
428 ##  range of g is fsgroup
429     while (sq_get_data(sq, &group)) {
430         fid = atoi(index(group, ':')+1);
431         *index(group, ':') = 0;
432 ##      retrieve (type = f.#type, loc = f.#name, id = f.mach_id,
433 ##                access = f.#access, mount = f.#mount, comments = f.#comments,
434 ##                name = f.#label, trans = g.#key)
435 ##            where f.filsys_id = g.filsys_id and g.group_id = fid
436 ##            sort by #trans, #name {
437             strtrim(type);
438             if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
439                 if (mach = hash_lookup(machines, id)) {
440                     for (p = machbuf; *mach && *mach != '.'; mach++) {
441                         if (isupper(*mach))
442                           *p++ = tolower(*mach);
443                         else
444                           *p++ = *mach;
445                     }
446                     *p = 0;
447                     fprintf(out, "%s.filsys\tHS %s \"%s %s %s %s %s\"\n",
448                             group, HTYPE, type, strtrim(loc), machbuf,
449                             strtrim(access), strtrim(mount));
450                 }
451             } else if (!strcmp(type, "AFS")) {
452                 fprintf(out, "%s.filsys\tHS %s \"AFS %s %s %s\"\n",
453                         group, HTYPE, strtrim(loc), strtrim(access),
454                         strtrim(mount));
455             } else if (!strcmp(type, "ERR")) {
456                 fprintf(out, "%s.filsys\tHS %s \"ERR %s\"\n",
457                         group, HTYPE, strtrim(comments));
458             }
459 ##      }
460         free(group);
461     }
462     sq_destroy(sq);
463
464 ##  range of a is alias
465 ##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
466         fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n",
467                 strtrim(name), strtrim(trans));
468 ##  }
469
470     if (fclose(out)) {
471         fprintf(stderr, "Unsuccessful close of filsys.db\n");
472         exit(MR_CCONFIG);
473     }
474     fix_file(outf);
475     return(1);
476 ##}
477
478
479 /*
480  * Modified from sys/types.h:
481  */
482 int setsize;    /* = howmany(setbits, NSETBITS) */
483
484 typedef long    set_mask;
485 #define NSETBITS        (sizeof(set_mask) * NBBY)       /* bits per mask */
486 #ifndef howmany
487 #define howmany(x, y)   (((x)+((y)-1))/(y))
488 #endif
489
490 #define SET_SET(n, p)   ((p)[(n)/NSETBITS] |=  (1 << ((n) % NSETBITS)))
491 #define SET_CLR(n, p)   ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
492 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] &   (1 << ((n) % NSETBITS)))
493 #define SET_CREATE()    ((set_mask *)malloc(setsize * sizeof(set_mask)))
494 #define SET_ZERO(p)     bzero((char *)(p), setsize * sizeof(set_mask))
495 #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
496
497 int nbitsset(set)
498 set_mask *set;
499 {
500     int i, ret;
501
502     ret = 0;
503     for (i = 0; i < setsize * NSETBITS; i++)
504       if (SET_ISSET(i, set))
505         ret++;
506     return(ret);
507 }
508
509
510 do_cluster()
511 ##{
512     FILE *out;
513     char outf[64], outft[64], *mach, machbuf[33], *p;
514     struct stat sb;
515     time_t ftime;
516 ##  int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
517 ##  char name[33], label[17], data[33], *filetime;
518     set_mask **machs, *ms, *ps;
519     int oneclu;
520
521     sprintf(outf, "%s/cluster.db", hesiod_dir);
522
523     if (stat(outf, &sb) == 0) {
524         ftime = sb.st_mtime;
525         filetime = ingres_date_and_time(ftime);
526 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
527 ##          where tblstats.table = "cluster"
528 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
529 ##          where tblstats.table = "machine"
530 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
531 ##          where tblstats.table = "mcmap"
532 ##      retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
533 ##          where tblstats.table = "svc"
534         if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
535             fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
536             return(0);
537       }
538     }
539
540     sprintf(outft, "%s~", outf);
541     out = fopen(outft, "w");
542     if (!out) {
543         perror("cannot open cluster.db for write");
544         exit(MR_OCONFIG);
545     }
546
547     fprintf(stderr, "Building cluster.db\n");
548     get_mach();
549
550 ##  range of c is cluster
551 ##  begin transaction
552 ##  retrieve (maxclu = max(c.clu_id))
553     maxclu++;
554     setsize = howmany(maxclu, NSETBITS);
555 ##  range of m is machine
556 ##  retrieve (maxmach = max(m.mach_id))
557     maxmach++;
558     machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
559     bzero(machs, (maxmach + 1) * sizeof(int));
560
561 ##  range of p is mcmap
562 ##  retrieve (mid = p.mach_id, cid = p.clu_id) {
563         if (!(ms = machs[mid])) {
564             ms = machs[mid] = SET_CREATE();
565             SET_ZERO(ms);
566         }
567         SET_SET(cid, ms);
568 ##  }
569
570 ##  range of d is svc
571     for (mid = 1; mid < maxmach; mid++) {
572         if (!machs[mid])
573           continue;
574         ms = machs[mid];
575         if (nbitsset(ms) > 1) {
576             oneclu = 0;
577             for (cid = 1; cid < maxclu; cid++) {
578                 if (SET_ISSET(cid, ms)) {
579 ##                repeat retrieve (label = d.serv_label, data = d.serv_cluster)
580 ##                  where d.clu_id = @cid {
581                       strtrim(label);
582                       strtrim(data);
583                       fprintf(out,
584                               "mrinternal-%d.cluster\tHS %s \"%s %s\"\n",
585                               mid, HTYPE, label, data);
586 ##                }
587                 }
588             }
589         } else {
590             oneclu = 1;
591             for (cid = 1; cid < maxclu; cid++)
592               if (SET_ISSET(cid, ms)) break;
593 ##          repeat retrieve (name = c.#name) where c.clu_id = @cid
594             strtrim(name);
595         }
596
597         if (mach = hash_lookup(machines, mid)) {
598             for (p = machbuf; *mach && *mach != '.'; mach++)
599               *p++ = *mach;
600             *p = 0;
601             if (oneclu)
602               fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
603                       machbuf, name);
604             else
605               fprintf(out, "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
606                       machbuf, mid);
607         }
608         for (id = mid + 1; id < maxmach; id++) {
609             if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
610                 free(ps);
611                 machs[id] = NULL;
612                 if (mach = hash_lookup(machines, id)) {
613                     for (p = machbuf; *mach && *mach != '.'; mach++)
614                       *p++ = *mach;
615                     *p = 0;
616                     if (oneclu)
617                       fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
618                               machbuf, name);
619                     else
620                       fprintf(out,
621                               "%s.cluster\tHS CNAME mrinternal-%d.cluster\n",
622                               machbuf, mid);
623                 }
624             }
625         }
626         free(ms);
627         machs[mid] = NULL;
628     }
629
630 ##  retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster)
631 ##      where c.clu_id = d.clu_id {
632             strtrim(name);
633             strtrim(label);
634             strtrim(data);
635             fprintf(out, "%s.cluster\tHS %s \"%s %s\"\n",
636                     name, HTYPE, label, data);
637 ##  }
638 ##  end transaction
639     free(machs);
640
641     if (fclose(out)) {
642         fprintf(stderr, "Unsuccessful close of cluster.db\n");
643         exit(MR_CCONFIG);
644     }
645     fix_file(outf);
646     return(1);
647 ##}
648
649
650 do_printcap()
651 ##{
652     FILE *out;
653     char outf[64], outft[64];
654     struct stat sb;
655     time_t ftime;
656 ##  char name[17], rp[17], sd[33], rm[33], rq[33], *filetime;
657 ##  int flag, ka, pc;
658
659     sprintf(outf, "%s/printcap.db", hesiod_dir);
660
661     if (stat(outf, &sb) == 0) {
662         ftime = sb.st_mtime;
663         filetime = ingres_date_and_time(ftime);
664 ##      retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
665 ##          where tblstats.table = "printcap"
666         if (flag < 0) {
667             fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
668             return(0);
669       }
670     }
671
672     sprintf(outft, "%s~", outf);
673     out = fopen(outft, "w");
674     if (!out) {
675         perror("cannot open printcap.db for write");
676         exit(MR_OCONFIG);
677     }
678
679     fprintf(stderr, "Building printcap.db\n");
680
681 ##  range of p is printcap
682 ##  range of m is machine
683 ##  retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name,
684 ##            ka = p.auth, pc = p.price, rq = m.#name)
685 ##    where machine.mach_id = p.mach_id and m.mach_id = p.quotaserver {
686         strtrim(name);
687         strtrim(rp);
688         strtrim(sd);
689         strtrim(rm);
690         strtrim(rq);
691         fprintf(out, "%s.pcap\tHS %s \"%s:rp=%s:rm=%s:sd=%s:ka#%d:pc#%d",
692                 name, HTYPE, name, rp, rm, sd, ka, pc);
693         if (strcmp(rq, "[NONE]"))
694           fprintf(out, ":rq=%s\"\n", rq);
695         else
696           fputs("\"\n", out);
697 ##  }
698
699     if (fclose(out)) {
700         fprintf(stderr, "Unsuccessful close of pcap.db\n");
701         exit(MR_CCONFIG);
702     }
703     fix_file(outf);
704     return(1);
705 ##}
706
707
708 do_palladium()
709 ##{
710     FILE *out;
711     char outf[64], outft[64];
712     struct stat sb;
713     time_t ftime;
714 ##  char name[33], rm[33], trans[129], *filetime;
715 ##  int flag, flag1, ident;
716
717     sprintf(outf, "%s/palladium.db", hesiod_dir);
718
719     if (stat(outf, &sb) == 0) {
720         ftime = sb.st_mtime;
721         filetime = ingres_date_and_time(ftime);
722 ##      retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
723 ##          where tblstats.table = "palladium"
724 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
725 ##          where tblstats.table = "alias"
726         if (flag < 0 && flag1 < 0) {
727             fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
728             return(0);
729       }
730     }
731
732     sprintf(outft, "%s~", outf);
733     out = fopen(outft, "w");
734     if (!out) {
735         perror("cannot open palladium.db for write");
736         exit(MR_OCONFIG);
737     }
738
739     fprintf(stderr, "Building palladium.db\n");
740
741 ##  range of p is palladium
742 ##  retrieve (name = p.#name, ident = p.#ident, rm = machine.#name)
743 ##    where machine.mach_id = p.mach_id {
744         strtrim(name);
745         strtrim(rm);
746         fprintf(out,
747                 "%s.palladium\tHS %s \"%s %d %s interface directory\"\n",
748                 name, HTYPE, rm, ident, name);
749 ##  }
750 ##  range of a is alias
751 ##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "PALLADIUM" {
752         strtrim(name);
753         strtrim(trans);
754         fprintf(out, "%s.palladium\tHS %s \"%s\"\n", name, HTYPE, trans);
755 ##  }
756
757     if (fclose(out)) {
758         fprintf(stderr, "Unsuccessful close of palladium.db\n");
759         exit(MR_CCONFIG);
760     }
761     fix_file(outf);
762     return(1);
763 ##}
764
765
766 do_sloc()
767 ##{
768     FILE *out;
769     char outf[64], outft[64], *mach;
770     struct stat sb;
771     time_t ftime;
772 ##  char service[17], *filetime;
773 ##  int flag1, flag2, id;
774
775     sprintf(outf, "%s/sloc.db", hesiod_dir);
776
777     if (stat(outf, &sb) == 0) {
778         ftime = sb.st_mtime;
779         filetime = ingres_date_and_time(ftime);
780 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
781 ##          where tblstats.table = "serverhosts"
782 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
783 ##          where tblstats.table = "machine"
784         if (flag1 < 0 && flag2 < 0) {
785             fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
786             return(0);
787       }
788     }
789
790     sprintf(outft, "%s~", outf);
791     out = fopen(outft, "w");
792     if (!out) {
793         perror("cannot open sloc.db for write");
794         exit(MR_OCONFIG);
795     }
796
797     fprintf(stderr, "Building sloc.db\n");
798     get_mach();
799
800 ##  range of s is serverhosts
801 ##  retrieve (service = s.#service, id = s.mach_id)
802 ##      sort by #service {
803             strtrim(service);
804             if (mach = hash_lookup(machines, id))
805               fprintf(out, "%s.sloc\tHS %s %s\n", service, HTYPE, mach);
806 ##  }
807
808     if (fclose(out)) {
809         fprintf(stderr, "Unsuccessful close of sloc.db\n");
810         exit(MR_CCONFIG);
811     }
812
813     fix_file(outf);
814     return(1);
815 ##}
816
817 do_service()
818 ##{
819     FILE *out;
820     char outf[64], outft[64];
821     struct stat sb;
822     time_t ftime;
823 ##  char service[33], protocol[9], altserv[129], *filetime;
824 ##  int port, flag1;
825
826     sprintf(outf, "%s/service.db", hesiod_dir);
827
828     if (stat(outf, &sb) == 0) {
829         ftime = sb.st_mtime;
830         filetime = ingres_date_and_time(ftime);
831 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
832 ##          where tblstats.table = "services"
833         if (flag1 < 0) {
834             fprintf(stderr, "File service.db does not need to be rebuilt.\n");
835             return(0);
836       }
837     }
838
839     sprintf(outft, "%s~", outf);
840     out = fopen(outft, "w");
841     if (!out) {
842         perror("cannot open service.db for write");
843         exit(MR_OCONFIG);
844     }
845
846     fprintf(stderr, "Building service.db\n");
847
848 ##  range of s is services
849 ##  retrieve (service = s.name, protocol = lowercase(s.#protocol),
850 ##            port = s.#port) {
851         strtrim(service);
852         strtrim(protocol);
853         fprintf(out, "%s.service\tHS %s \"%s %s %d\"\n",
854                 service, HTYPE, service, protocol, port);
855 ##  }
856
857 ##  range of a is alias
858 ##  retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" {
859         strtrim(service);
860         strtrim(altserv);
861         fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
862 ##    }
863
864     if (fclose(out)) {
865         fprintf(stderr, "Unsuccessful close of service.db\n");
866         exit(MR_CCONFIG);
867     }
868     fix_file(outf);
869     return(1);
870 ##}
This page took 0.112493 seconds and 5 git commands to generate.