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