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