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