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