]> andersk Git - moira.git/blob - gen/hesiod.qc
57cae3c8def84bda2bc0bf5dbbb384d3ed0f2910
[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     char *index();
386
387     sprintf(outf, "%s/filsys.db", HESIOD_DIR);
388
389     if (stat(outf, &sb) == 0) {
390         ftime = sb.st_mtime;
391         filetime = ingres_date_and_time(ftime);
392 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
393 ##          where tblstats.table = "filesys"
394 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
395 ##          where tblstats.table = "machine"
396 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
397 ##          where tblstats.table = "alias"
398 ##      retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
399 ##          where tblstats.table = "fsgroup"
400         if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
401             fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
402             return(0);
403       }
404     }
405
406     sprintf(outft, "%s~", outf);
407     out = fopen(outft, "w");
408     if (!out) {
409         perror("cannot open filsys.db for write");
410         exit(SMS_OCONFIG);
411     }
412
413     fprintf(stderr, "Building filsys.db\n");
414     get_mach();
415     sq = sq_create();
416
417 ##  range of f is filesys
418 ##  retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id,
419 ##            access = f.#access, mount = f.#mount, comments = f.#comments,
420 ##            fid = f.filsys_id) {
421             strtrim(name);
422             strtrim(type);
423             if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
424                 strtrim(loc);
425                 strtrim(access);
426                 strtrim(mount);
427                 if (mach = hash_lookup(machines, id)) {
428                     for (p = machbuf; *mach && *mach != '.'; mach++) {
429                         if (isupper(*mach))
430                           *p++ = tolower(*mach);
431                         else
432                           *p++ = *mach;
433                         *p = 0;
434                     }
435                     fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
436                             name, type, loc, machbuf, access, mount);
437                 }
438             } else if (!strcmp(type, "AFS")) {
439                 strtrim(loc);
440                 strtrim(access);
441                 strtrim(mount);
442                 fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
443                         name, loc, access, mount);
444             } else if (!strcmp(type, "ERR")) {
445                 strtrim(comments);
446                 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
447                         name, comments);
448             } else if (!strcmp(type, "FSGROUP")) {
449                 sprintf(trans, "%s:%d", name, fid);
450                 sq_save_data(sq, strsave(trans));
451             }
452 ##  }
453
454 ##  range of g is fsgroup
455     while (sq_get_data(sq, &group)) {
456         fid = atoi(index(group, ':')+1);
457         *index(group, ':') = 0;
458 ##      retrieve (type = f.#type, loc = f.#name, id = f.mach_id,
459 ##                access = f.#access, mount = f.#mount, comments = f.#comments,
460 ##                name = f.#label, trans = g.#key)
461 ##            where f.filsys_id = g.filsys_id and g.group_id = fid
462 ##            sort by #trans, #name {
463             strtrim(type);
464             if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
465                 strtrim(loc);
466                 strtrim(access);
467                 strtrim(mount);
468                 if (mach = hash_lookup(machines, id)) {
469                     for (p = machbuf; *mach && *mach != '.'; mach++) {
470                         if (isupper(*mach))
471                           *p++ = tolower(*mach);
472                         else
473                           *p++ = *mach;
474                         *p = 0;
475                     }
476                     fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
477                             group, type, loc, machbuf, access, mount);
478                 }
479             } else if (!strcmp(type, "AFS")) {
480                 strtrim(loc);
481                 strtrim(access);
482                 strtrim(mount);
483                 fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
484                         group, loc, access, mount);
485             } else if (!strcmp(type, "ERR")) {
486                 strtrim(comments);
487                 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
488                         group, comments);
489             }
490 ##      }
491         free(group);
492     }
493     sq_destroy(sq);
494
495 ##  range of a is alias
496 ##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
497         strtrim(name);
498         strtrim(trans);
499         fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n", name, trans);
500 ##  }
501
502     if (fclose(out)) {
503         fprintf(stderr, "Unsuccessful close of filsys.db\n");
504         exit(SMS_CCONFIG);
505     }
506     fix_file(outf);
507     return(1);
508 ##}
509
510
511 /*
512  * Modified from sys/types.h:
513  */
514 int setsize;    /* = howmany(setbits, NSETBITS) */
515
516 typedef long    set_mask;
517 #define NSETBITS        (sizeof(set_mask) * NBBY)       /* bits per mask */
518 #ifndef howmany
519 #define howmany(x, y)   (((x)+((y)-1))/(y))
520 #endif
521
522 #define SET_SET(n, p)   ((p)[(n)/NSETBITS] |=  (1 << ((n) % NSETBITS)))
523 #define SET_CLR(n, p)   ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
524 #define SET_ISSET(n, p) ((p)[(n)/NSETBITS] &   (1 << ((n) % NSETBITS)))
525 #define SET_CREATE()    ((set_mask *)malloc(setsize * sizeof(set_mask)))
526 #define SET_ZERO(p)     bzero((char *)(p), setsize * sizeof(set_mask))
527 #define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
528
529
530 do_cluster()
531 ##{
532     FILE *out;
533     char outf[64], outft[64], *mach, machbuf[33], *p;
534     struct stat sb;
535     time_t ftime;
536 ##  int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
537 ##  char name[33], label[17], data[33], *filetime;
538     set_mask **machs, *ms, *ps;
539
540     sprintf(outf, "%s/cluster.db", HESIOD_DIR);
541
542     if (stat(outf, &sb) == 0) {
543         ftime = sb.st_mtime;
544         filetime = ingres_date_and_time(ftime);
545 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
546 ##          where tblstats.table = "cluster"
547 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
548 ##          where tblstats.table = "machine"
549 ##      retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
550 ##          where tblstats.table = "mcmap"
551 ##      retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
552 ##          where tblstats.table = "svc"
553         if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
554             fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
555             return(0);
556       }
557     }
558
559     sprintf(outft, "%s~", outf);
560     out = fopen(outft, "w");
561     if (!out) {
562         perror("cannot open cluster.db for write");
563         exit(SMS_OCONFIG);
564     }
565
566     fprintf(stderr, "Building cluster.db\n");
567     get_mach();
568
569 ##  range of c is cluster
570 ##  begin transaction
571 ##  retrieve (maxclu = max(c.clu_id))
572     maxclu++;
573     setsize = howmany(maxclu, NSETBITS);
574 ##  range of m is machine
575 ##  retrieve (maxmach = max(m.mach_id))
576     maxmach++;
577     machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
578     bzero(machs, (maxmach + 1) * sizeof(int));
579
580 ##  range of p is mcmap
581 ##  retrieve (mid = p.mach_id, cid = p.clu_id) {
582         if (!(ms = machs[mid])) {
583             ms = machs[mid] = SET_CREATE();
584             SET_ZERO(ms);
585         }
586         SET_SET(cid, ms);
587 ##  }
588
589 ##  range of d is svc
590     for (mid = 1; mid < maxmach; mid++) {
591         if (!machs[mid])
592           continue;
593         ms = machs[mid];
594         for (cid = 1; cid < maxclu; cid++) {
595             if (SET_ISSET(cid, ms)) {
596 ##              repeat retrieve (label = d.serv_label, data = d.serv_cluster)
597 ##                  where d.clu_id = @cid {
598                     strtrim(label);
599                     strtrim(data);
600                     fprintf(out,
601                             "smsinternal-%d.cluster\tHS UNSPECA \"%s %s\"\n",
602                             mid, label, data);
603 ##              }
604             }
605         }
606
607         if (mach = hash_lookup(machines, mid)) {
608             for (p = machbuf; *mach && *mach != '.'; mach++)
609               *p++ = *mach;
610             *p = 0;
611             fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
612                     machbuf, mid);
613         }
614         for (id = mid + 1; id < maxmach; id++) {
615             if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
616                 free(ps);
617                 machs[id] = NULL;
618                 if (mach = hash_lookup(machines, id)) {
619                     for (p = machbuf; *mach && *mach != '.'; mach++)
620                       *p++ = *mach;
621                     *p = 0;
622                     fprintf(out,"%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
623                             machbuf, mid);
624                 }
625             }
626         }
627         free(ms);
628         machs[mid] = NULL;
629     }
630
631 ##  retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster)
632 ##      where c.clu_id = d.clu_id {
633             strtrim(name);
634             strtrim(label);
635             strtrim(data);
636             fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n",
637                     name, label, data);
638 ##  }
639 ##  end transaction
640     free(machs);
641
642     if (fclose(out)) {
643         fprintf(stderr, "Unsuccessful close of cluster.db\n");
644         exit(SMS_CCONFIG);
645     }
646     fix_file(outf);
647     return(1);
648 ##}
649
650
651 do_printers()
652 ##{
653     FILE *out;
654     char outf[64], outft[64];
655     struct stat sb;
656     time_t ftime;
657 ##  char name[17], rp[17], sd[33], rm[33], *filetime;
658 ##  int flag;
659
660     sprintf(outf, "%s/printcap.db", HESIOD_DIR);
661
662     if (stat(outf, &sb) == 0) {
663         ftime = sb.st_mtime;
664         filetime = ingres_date_and_time(ftime);
665 ##      retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
666 ##          where tblstats.table = "printcap"
667         if (flag < 0) {
668             fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
669             return(0);
670       }
671     }
672
673     sprintf(outft, "%s~", outf);
674     out = fopen(outft, "w");
675     if (!out) {
676         perror("cannot open printcap.db for write");
677         exit(SMS_OCONFIG);
678     }
679
680     fprintf(stderr, "Building printcap.db\n");
681
682 ##  range of p is printcap
683 ##  retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name)
684 ##    where machine.mach_id = p.mach_id {
685         strtrim(name);
686         strtrim(rp);
687         strtrim(sd);
688         strtrim(rm);
689         fprintf(out, "%s.pcap\tHS UNSPECA \"%s:rp=%s:rm=%s:sd=%s\"\n",
690                 name, name, rp, rm, sd);
691 ##  }
692
693     if (fclose(out)) {
694         fprintf(stderr, "Unsuccessful close of pcap.db\n");
695         exit(SMS_CCONFIG);
696     }
697     fix_file(outf);
698     return(1);
699 ##}
700
701
702 do_sloc()
703 ##{
704     FILE *out, *old, *new;
705     char outf[64], outft[64], *mach;
706     struct stat sb;
707     time_t ftime;
708     register int c;
709 ##  char service[17], *filetime;
710 ##  int port, flag1, flag2, id;
711
712     sprintf(outf, "%s/sloc.db", HESIOD_DIR);
713
714     if (stat(outf, &sb) == 0) {
715         ftime = sb.st_mtime;
716         filetime = ingres_date_and_time(ftime);
717 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
718 ##          where tblstats.table = "serverhosts"
719 ##      retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
720 ##          where tblstats.table = "machine"
721         if (flag1 < 0 && flag2 < 0) {
722             fprintf(stderr, "File sloc.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 sloc.db for write");
731         exit(SMS_OCONFIG);
732     }
733
734     fprintf(stderr, "Building sloc.db\n");
735     get_mach();
736
737 ##  range of s is serverhosts
738 ##  retrieve (service = s.#service, id = s.mach_id)
739 ##      sort by #service {
740             strtrim(service);
741             if (mach = hash_lookup(machines, id))
742               fprintf(out, "%s.sloc\tHS UNSPECA %s\n", service, mach);
743 ##  }
744
745     if (fclose(out)) {
746         fprintf(stderr, "Unsuccessful close of sloc.db\n");
747         exit(SMS_CCONFIG);
748     }
749
750     fix_file(outf);
751     return(1);
752 ##}
753
754 do_service()
755 ##{
756     FILE *out;
757     char outf[64], outft[64];
758     struct stat sb;
759     time_t ftime;
760 ##  char mach[33], service[33], protocol[9], altserv[129], *filetime;
761 ##  int port, flag1, flag2;
762
763     sprintf(outf, "%s/service.db", HESIOD_DIR);
764
765     if (stat(outf, &sb) == 0) {
766         ftime = sb.st_mtime;
767         filetime = ingres_date_and_time(ftime);
768 ##      retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
769 ##          where tblstats.table = "services"
770         if (flag1 < 0) {
771             fprintf(stderr, "File service.db does not need to be rebuilt.\n");
772             return(0);
773       }
774     }
775
776     sprintf(outft, "%s~", outf);
777     out = fopen(outft, "w");
778     if (!out) {
779         perror("cannot open service.db for write");
780         exit(SMS_OCONFIG);
781     }
782
783     fprintf(stderr, "Building service.db\n");
784
785 ##  range of s is services
786 ##  retrieve (service = s.name, protocol = lowercase(s.#protocol),
787 ##            port = s.#port) {
788         strtrim(service);
789         strtrim(protocol);
790         fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n",
791                 service, service, protocol, port);
792 ##  }
793
794 ##  range of a is alias
795 ##  retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" {
796         strtrim(service);
797         strtrim(altserv);
798         fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
799 ##    }
800
801     if (fclose(out)) {
802         fprintf(stderr, "Unsuccessful close of service.db\n");
803         exit(SMS_CCONFIG);
804     }
805     fix_file(outf);
806     return(1);
807 ##}
This page took 0.101148 seconds and 3 git commands to generate.