]> andersk Git - moira.git/blob - gen/hesiod.qc
added palladium
[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 #define HESIOD_DIR      "/u1/sms/dcm/hesiod"
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
58 ##  ingres sms
59 ##  set lockmode session where level = table
60
61     changed = do_passwd();
62     changed += do_filsys();
63     changed += do_cluster();
64     changed += do_printcap();
65     changed += do_palladium();
66     changed += do_sloc();
67     changed += do_service();
68     changed += do_groups();
69
70 ##  exit
71
72     if (!changed) {
73         fprintf(stderr, "No files updated.\n");
74         if (argc == 2 && stat(argv[1], &sb) == 0)
75           exit(SMS_NO_CHANGE);
76     }
77
78     if (argc == 2) {
79         fprintf(stderr, "Building tar file.\n");
80         sprintf(cmd, "cd %s; tar cf %s .", HESIOD_DIR, argv[1]);
81         if (system(cmd))
82           exit(SMS_TAR_FAIL);
83     }
84
85     exit(SMS_SUCCESS);
86 }
87
88
89 /*
90  * ingerr: (supposedly) called when Ingres indicates an error.
91  * I have not yet been able to get this to work to intercept a
92  * database open error.
93  */
94 #define INGRES_DEADLOCK 4700
95
96 static int ingerr(num)
97     int *num;
98 {
99     char buf[256];
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(10000);
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 /************************************************************************
221  * WARNING: this routine mallocs a large amount of memory which it never frees.
222  * This is considered OK only because main has been arranged to call this
223  * last, so the process will exit shortly after we return.
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     register struct save_queue *sq;
237     struct save_queue *sq_create();
238     register int i;
239 ##  char name[33], *filetime;
240 ##  int gid, id, lid, flag1, flag2, flag3, maxid;
241
242     /* open files */
243     sprintf(ioutf, "%s/gid.db", HESIOD_DIR);
244     sprintf(goutf, "%s/group.db", HESIOD_DIR);
245     sprintf(loutf, "%s/grplist.db", HESIOD_DIR);
246
247     if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
248         ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
249         filetime = ingres_date_and_time(ftime);
250 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
251 ##          where tblstats.table = "users"
252 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
253 ##          where tblstats.table = "list"
254 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
255 ##          where tblstats.table = "imembers"
256         if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
257             fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
258             return(0);
259       }
260     }
261
262     sprintf(buf, "%s~", ioutf);
263     iout = fopen(buf, "w");
264     if (!iout) {
265         perror("cannot open gid.db for write");
266         exit(SMS_OCONFIG);
267     }
268     sprintf(buf, "%s~", goutf);
269     gout = fopen(buf, "w");
270     if (!gout) {
271         perror("cannot open group.db for write");
272         exit(SMS_OCONFIG);
273     }
274     sprintf(buf, "%s~", loutf);
275     lout = fopen(buf, "w");
276     if (!lout) {
277         perror("cannot open grplist.db for write");
278         exit(SMS_OCONFIG);
279     }
280
281     fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
282
283     /* make space for group list */
284     groups = create_hash(15000);
285
286     /* retrieve simple groups */
287 ##  range of l is list
288 ##  range of m is imembers
289 ##  begin transaction
290     /* get lock records */
291 ##  retrieve (name = l.modtime) where l.list_id = 0
292 ##  retrieve (name = users.modtime) where users.users_id = 0
293
294 ##  retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
295 ##      where l.group != 0 and l.active != 0 {
296             strtrim(name);
297             sprintf(buf, "%s:%d", name, gid);
298             hash_store(groups, lid, strsave(buf));
299             fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
300             fprintf(gout, "%s.group\tHS UNSPECA \"%s:*:%d:\"\n",
301                     name, name, gid);
302 ##  }
303
304     fflush(iout);
305     fflush(gout);
306
307     /* now do grplists */
308     if (users == NULL) {
309         users = create_hash(10000);
310 ##      range of u is users
311 ##      retrieve (id = u.users_id, name = u.login) where u.status = 1 {
312           u = (struct user *) malloc(sizeof(struct user));
313           strcpy(u->name, strtrim(name));
314           u->lists = NULL;
315           hash_store(users, id, u);
316 ##      }
317     }
318
319 ##  repeat retrieve (lid = m.list_id, id = m.member_id)
320 ##      where m.member_type = "USER" {
321       if ((u = (struct user *) hash_lookup(users, id)) &&
322           (hash_lookup(groups, lid) != NULL)) {
323           g = (struct grp *) malloc(sizeof(struct grp));
324           g->next = u->lists;
325           u->lists = g;
326           g->id = lid;
327       }
328 ##  }
329 ##  end transaction
330
331     for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
332         for (b = *p; b; b = b->next) {
333             i = 0;
334             sprintf(buf, "%s.grplist\tHS UNSPECA \"",
335                     ((struct user *)b->data)->name);
336             for (g = ((struct user *)b->data)->lists; g; g = g->next)
337               if (l = hash_lookup(groups, g->id)) {
338                   i++;
339                   strcat(buf, l);
340                   if (g->next)
341                     strcat(buf, ":");
342               }
343             strcat(buf, "\"\n");
344             if (i > 0)
345                 fputs(buf, lout);
346         }
347     }
348
349 #ifdef notdef
350 /* This is commented out because it takes on the order of 30 minutes to 
351  * run.  Instead, we never free the memory, but the program will exit
352  * shortly anyway.
353  */
354     sq_destroy(sq);
355     {
356         register char **p;
357         for (p = &groups[maxid-1]; p >= groups; p--)
358           if (*p)
359             free(*p);
360     }
361     free(groups);
362 #endif
363
364     if (fclose(iout) || fclose(gout) || fclose(lout)) {
365         fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
366         exit(SMS_CCONFIG);
367     }
368     fix_file(ioutf);
369     fix_file(goutf);
370     fix_file(loutf);
371     return(1);
372 ##}
373
374
375 do_filsys()
376 ##{
377     FILE *out;
378     char outf[64], outft[64], *mach, machbuf[128], *group;
379     register char *p;
380     struct stat sb;
381     time_t ftime;
382     struct save_queue *sq, *sq_create();
383 ##  char name[33], type[9], loc[81], access[2], mount[33], trans[257];
384 ##  char *filetime, comments[65];
385 ##  int flag1, flag2, flag3, flag4, id, fid;
386     char *index();
387
388     sprintf(outf, "%s/filsys.db", HESIOD_DIR);
389
390     if (stat(outf, &sb) == 0) {
391         ftime = sb.st_mtime;
392         filetime = ingres_date_and_time(ftime);
393 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
394 ##          where tblstats.table = "filesys"
395 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
396 ##          where tblstats.table = "machine"
397 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
398 ##          where tblstats.table = "alias"
399 ##      retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
400 ##          where tblstats.table = "fsgroup"
401         if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
402             fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
403             return(0);
404       }
405     }
406
407     sprintf(outft, "%s~", outf);
408     out = fopen(outft, "w");
409     if (!out) {
410         perror("cannot open filsys.db for write");
411         exit(SMS_OCONFIG);
412     }
413
414     fprintf(stderr, "Building filsys.db\n");
415     get_mach();
416     sq = sq_create();
417
418 ##  range of f is filesys
419 ##  retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id,
420 ##            access = f.#access, mount = f.#mount, comments = f.#comments,
421 ##            fid = f.filsys_id) {
422             strtrim(name);
423             strtrim(type);
424             if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
425                 strtrim(loc);
426                 strtrim(access);
427                 strtrim(mount);
428                 if (mach = hash_lookup(machines, id)) {
429                     for (p = machbuf; *mach && *mach != '.'; mach++) {
430                         if (isupper(*mach))
431                           *p++ = tolower(*mach);
432                         else
433                           *p++ = *mach;
434                         *p = 0;
435                     }
436                     fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
437                             name, type, loc, machbuf, access, mount);
438                 }
439             } else if (!strcmp(type, "AFS")) {
440                 strtrim(loc);
441                 strtrim(access);
442                 strtrim(mount);
443                 fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
444                         name, loc, access, mount);
445             } else if (!strcmp(type, "ERR")) {
446                 strtrim(comments);
447                 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
448                         name, comments);
449             } else if (!strcmp(type, "FSGROUP")) {
450                 sprintf(trans, "%s:%d", name, fid);
451                 sq_save_data(sq, strsave(trans));
452             }
453 ##  }
454
455 ##  range of g is fsgroup
456     while (sq_get_data(sq, &group)) {
457         fid = atoi(index(group, ':')+1);
458         *index(group, ':') = 0;
459 ##      retrieve (type = f.#type, loc = f.#name, id = f.mach_id,
460 ##                access = f.#access, mount = f.#mount, comments = f.#comments,
461 ##                name = f.#label, trans = g.#key)
462 ##            where f.filsys_id = g.filsys_id and g.group_id = fid
463 ##            sort by #trans, #name {
464             strtrim(type);
465             if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
466                 strtrim(loc);
467                 strtrim(access);
468                 strtrim(mount);
469                 if (mach = hash_lookup(machines, id)) {
470                     for (p = machbuf; *mach && *mach != '.'; mach++) {
471                         if (isupper(*mach))
472                           *p++ = tolower(*mach);
473                         else
474                           *p++ = *mach;
475                         *p = 0;
476                     }
477                     fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
478                             group, type, loc, machbuf, access, mount);
479                 }
480             } else if (!strcmp(type, "AFS")) {
481                 strtrim(loc);
482                 strtrim(access);
483                 strtrim(mount);
484                 fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
485                         group, loc, access, mount);
486             } else if (!strcmp(type, "ERR")) {
487                 strtrim(comments);
488                 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
489                         group, comments);
490             }
491 ##      }
492         free(group);
493     }
494     sq_destroy(sq);
495
496 ##  range of a is alias
497 ##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
498         strtrim(name);
499         strtrim(trans);
500         fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n", name, trans);
501 ##  }
502
503     if (fclose(out)) {
504         fprintf(stderr, "Unsuccessful close of filsys.db\n");
505         exit(SMS_CCONFIG);
506     }
507     fix_file(outf);
508     return(1);
509 ##}
510
511
512 /*
513  * Modified from sys/types.h:
514  */
515 int setsize;    /* = howmany(setbits, NSETBITS) */
516
517 typedef long    set_mask;
518 #define NSETBITS        (sizeof(set_mask) * NBBY)       /* bits per mask */
519 #ifndef howmany
520 #define howmany(x, y)   (((x)+((y)-1))/(y))
521 #endif
522
523 #define SET_SET(n, p)   ((p)[(n)/NSETBITS] |=  (1 << ((n) % NSETBITS)))
524 #define SET_CLR(n, p)   ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
525 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] &   (1 << ((n) % NSETBITS)))
526 #define SET_CREATE()    ((set_mask *)malloc(setsize * sizeof(set_mask)))
527 #define SET_ZERO(p)     bzero((char *)(p), setsize * sizeof(set_mask))
528 #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
529
530
531 do_cluster()
532 ##{
533     FILE *out;
534     char outf[64], outft[64], *mach, machbuf[33], *p;
535     struct stat sb;
536     time_t ftime;
537 ##  int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
538 ##  char name[33], label[17], data[33], *filetime;
539     set_mask **machs, *ms, *ps;
540
541     sprintf(outf, "%s/cluster.db", HESIOD_DIR);
542
543     if (stat(outf, &sb) == 0) {
544         ftime = sb.st_mtime;
545         filetime = ingres_date_and_time(ftime);
546 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
547 ##          where tblstats.table = "cluster"
548 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
549 ##          where tblstats.table = "machine"
550 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
551 ##          where tblstats.table = "mcmap"
552 ##      retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
553 ##          where tblstats.table = "svc"
554         if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
555             fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
556             return(0);
557       }
558     }
559
560     sprintf(outft, "%s~", outf);
561     out = fopen(outft, "w");
562     if (!out) {
563         perror("cannot open cluster.db for write");
564         exit(SMS_OCONFIG);
565     }
566
567     fprintf(stderr, "Building cluster.db\n");
568     get_mach();
569
570 ##  range of c is cluster
571 ##  begin transaction
572 ##  retrieve (maxclu = max(c.clu_id))
573     maxclu++;
574     setsize = howmany(maxclu, NSETBITS);
575 ##  range of m is machine
576 ##  retrieve (maxmach = max(m.mach_id))
577     maxmach++;
578     machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
579     bzero(machs, (maxmach + 1) * sizeof(int));
580
581 ##  range of p is mcmap
582 ##  retrieve (mid = p.mach_id, cid = p.clu_id) {
583         if (!(ms = machs[mid])) {
584             ms = machs[mid] = SET_CREATE();
585             SET_ZERO(ms);
586         }
587         SET_SET(cid, ms);
588 ##  }
589
590 ##  range of d is svc
591     for (mid = 1; mid < maxmach; mid++) {
592         if (!machs[mid])
593           continue;
594         ms = machs[mid];
595         for (cid = 1; cid < maxclu; cid++) {
596             if (SET_ISSET(cid, ms)) {
597 ##              repeat retrieve (label = d.serv_label, data = d.serv_cluster)
598 ##                  where d.clu_id = @cid {
599                     strtrim(label);
600                     strtrim(data);
601                     fprintf(out,
602                             "smsinternal-%d.cluster\tHS UNSPECA \"%s %s\"\n",
603                             mid, label, data);
604 ##              }
605             }
606         }
607
608         if (mach = hash_lookup(machines, mid)) {
609             for (p = machbuf; *mach && *mach != '.'; mach++)
610               *p++ = *mach;
611             *p = 0;
612             fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
613                     machbuf, mid);
614         }
615         for (id = mid + 1; id < maxmach; id++) {
616             if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
617                 free(ps);
618                 machs[id] = NULL;
619                 if (mach = hash_lookup(machines, id)) {
620                     for (p = machbuf; *mach && *mach != '.'; mach++)
621                       *p++ = *mach;
622                     *p = 0;
623                     fprintf(out,"%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
624                             machbuf, mid);
625                 }
626             }
627         }
628         free(ms);
629         machs[mid] = NULL;
630     }
631
632 ##  retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster)
633 ##      where c.clu_id = d.clu_id {
634             strtrim(name);
635             strtrim(label);
636             strtrim(data);
637             fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n",
638                     name, label, data);
639 ##  }
640 ##  end transaction
641     free(machs);
642
643     if (fclose(out)) {
644         fprintf(stderr, "Unsuccessful close of cluster.db\n");
645         exit(SMS_CCONFIG);
646     }
647     fix_file(outf);
648     return(1);
649 ##}
650
651
652 do_printcap()
653 ##{
654     FILE *out;
655     char outf[64], outft[64];
656     struct stat sb;
657     time_t ftime;
658 ##  char name[17], rp[17], sd[33], rm[33], *filetime;
659 ##  int flag;
660
661     sprintf(outf, "%s/printcap.db", HESIOD_DIR);
662
663     if (stat(outf, &sb) == 0) {
664         ftime = sb.st_mtime;
665         filetime = ingres_date_and_time(ftime);
666 ##      retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
667 ##          where tblstats.table = "printcap"
668         if (flag < 0) {
669             fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
670             return(0);
671       }
672     }
673
674     sprintf(outft, "%s~", outf);
675     out = fopen(outft, "w");
676     if (!out) {
677         perror("cannot open printcap.db for write");
678         exit(SMS_OCONFIG);
679     }
680
681     fprintf(stderr, "Building printcap.db\n");
682
683 ##  range of p is printcap
684 ##  retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name)
685 ##    where machine.mach_id = p.mach_id {
686         strtrim(name);
687         strtrim(rp);
688         strtrim(sd);
689         strtrim(rm);
690         fprintf(out, "%s.pcap\tHS UNSPECA \"%s:rp=%s:rm=%s:sd=%s\"\n",
691                 name, name, rp, rm, sd);
692 ##  }
693
694     if (fclose(out)) {
695         fprintf(stderr, "Unsuccessful close of pcap.db\n");
696         exit(SMS_CCONFIG);
697     }
698     fix_file(outf);
699     return(1);
700 ##}
701
702
703 do_palladium()
704 ##{
705     FILE *out;
706     char outf[64], outft[64];
707     struct stat sb;
708     time_t ftime;
709 ##  char name[33], rm[33], trans[129], *filetime;
710 ##  int flag, flag1, ident;
711
712     sprintf(outf, "%s/palladium.db", HESIOD_DIR);
713
714     if (stat(outf, &sb) == 0) {
715         ftime = sb.st_mtime;
716         filetime = ingres_date_and_time(ftime);
717 ##      retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
718 ##          where tblstats.table = "palladium"
719 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
720 ##          where tblstats.table = "alias"
721         if (flag < 0 && flag1 < 0) {
722             fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
723             return(0);
724       }
725     }
726
727     sprintf(outft, "%s~", outf);
728     out = fopen(outft, "w");
729     if (!out) {
730         perror("cannot open palladium.db for write");
731         exit(SMS_OCONFIG);
732     }
733
734     fprintf(stderr, "Building palladium.db\n");
735
736 ##  range of p is palladium
737 ##  retrieve (name = p.#name, ident = p.#ident, rm = machine.#name)
738 ##    where machine.mach_id = p.mach_id {
739         strtrim(name);
740         strtrim(rm);
741         fprintf(out,
742                 "%s.palladium\tHS UNSPECA \"%s %d %s interface directory\"\n",
743                 name, rm, ident, name);
744 ##  }
745 ##  range of a is alias
746 ##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "PALLADIUM" {
747         strtrim(name);
748         strtrim(trans);
749         fprintf(out, "%s.palladium\tHS UNSPECA \"%s\"\n", name, trans);
750 ##  }
751
752     if (fclose(out)) {
753         fprintf(stderr, "Unsuccessful close of palladium.db\n");
754         exit(SMS_CCONFIG);
755     }
756     fix_file(outf);
757     return(1);
758 ##}
759
760
761 do_sloc()
762 ##{
763     FILE *out, *old, *new;
764     char outf[64], outft[64], *mach;
765     struct stat sb;
766     time_t ftime;
767     register int c;
768 ##  char service[17], *filetime;
769 ##  int port, flag1, flag2, id;
770
771     sprintf(outf, "%s/sloc.db", HESIOD_DIR);
772
773     if (stat(outf, &sb) == 0) {
774         ftime = sb.st_mtime;
775         filetime = ingres_date_and_time(ftime);
776 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
777 ##          where tblstats.table = "serverhosts"
778 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
779 ##          where tblstats.table = "machine"
780         if (flag1 < 0 && flag2 < 0) {
781             fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
782             return(0);
783       }
784     }
785
786     sprintf(outft, "%s~", outf);
787     out = fopen(outft, "w");
788     if (!out) {
789         perror("cannot open sloc.db for write");
790         exit(SMS_OCONFIG);
791     }
792
793     fprintf(stderr, "Building sloc.db\n");
794     get_mach();
795
796 ##  range of s is serverhosts
797 ##  retrieve (service = s.#service, id = s.mach_id)
798 ##      sort by #service {
799             strtrim(service);
800             if (mach = hash_lookup(machines, id))
801               fprintf(out, "%s.sloc\tHS UNSPECA %s\n", service, mach);
802 ##  }
803
804     if (fclose(out)) {
805         fprintf(stderr, "Unsuccessful close of sloc.db\n");
806         exit(SMS_CCONFIG);
807     }
808
809     fix_file(outf);
810     return(1);
811 ##}
812
813 do_service()
814 ##{
815     FILE *out;
816     char outf[64], outft[64];
817     struct stat sb;
818     time_t ftime;
819 ##  char mach[33], service[33], protocol[9], altserv[129], *filetime;
820 ##  int port, flag1, flag2;
821
822     sprintf(outf, "%s/service.db", HESIOD_DIR);
823
824     if (stat(outf, &sb) == 0) {
825         ftime = sb.st_mtime;
826         filetime = ingres_date_and_time(ftime);
827 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
828 ##          where tblstats.table = "services"
829         if (flag1 < 0) {
830             fprintf(stderr, "File service.db does not need to be rebuilt.\n");
831             return(0);
832       }
833     }
834
835     sprintf(outft, "%s~", outf);
836     out = fopen(outft, "w");
837     if (!out) {
838         perror("cannot open service.db for write");
839         exit(SMS_OCONFIG);
840     }
841
842     fprintf(stderr, "Building service.db\n");
843
844 ##  range of s is services
845 ##  retrieve (service = s.name, protocol = lowercase(s.#protocol),
846 ##            port = s.#port) {
847         strtrim(service);
848         strtrim(protocol);
849         fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n",
850                 service, service, protocol, port);
851 ##  }
852
853 ##  range of a is alias
854 ##  retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" {
855         strtrim(service);
856         strtrim(altserv);
857         fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
858 ##    }
859
860     if (fclose(out)) {
861         fprintf(stderr, "Unsuccessful close of service.db\n");
862         exit(SMS_CCONFIG);
863     }
864     fix_file(outf);
865     return(1);
866 ##}
This page took 0.928632 seconds and 5 git commands to generate.