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