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