]> andersk Git - moira.git/blame - gen/hesiod.qc
changed server host from "dodo.mit.edu" to "sms.mit.edu"
[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;
0a48a760 100## char nn[17];
bd8a14a5 101## int uid, flag, id;
dfb56d6b 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
f575c498 117 sprintf(poutft, "%s~", poutf);
118 pout = fopen(poutft, "w");
dfb56d6b 119 if (!pout) {
f575c498 120 perror("cannot open passwd.db~ for write");
121 exit(SMS_OCONFIG);
dfb56d6b 122 }
f575c498 123 sprintf(uoutft, "%s~", uoutf);
124 uout = fopen(uoutft, "w");
dfb56d6b 125 if (!uout) {
f575c498 126 perror("cannot open uid.db~ for write");
127 exit(SMS_OCONFIG);
dfb56d6b 128 }
129
130 fprintf(stderr, "Building passwd.db and uid.db\n");
131
bd8a14a5 132 users = create_hash(10000);
dfb56d6b 133## range of u is users
134## retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
0a48a760 135## fullname = u.#fullname, nn = u.nickname, oa = u.office_addr,
bd8a14a5 136## op = u.office_phone, hp = u.home_phone, id = u.users_id)
137## where u.status = 1 {
138 strtrim(login);
29904371 139 dequote(fullname);
0a48a760 140 dequote(nn);
29904371 141 dequote(oa);
142 dequote(op);
143 dequote(hp);
144 dequote(shell);
bd8a14a5 145 u = (struct user *) malloc(sizeof(struct user));
146 strcpy(u->name, login);
147 u->lists = NULL;
148 hash_store(users, id, u);
0a48a760 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);
dfb56d6b 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");
f575c498 156 exit(SMS_CCONFIG);
dfb56d6b 157 }
f575c498 158 fix_file(poutf);
159 fix_file(uoutf);
dfb56d6b 160 return(1);
161##}
162
163
164do_pobox()
165##{
166 FILE *out;
bd8a14a5 167 char outf[64], outft[64], *mach;
dfb56d6b 168 struct stat sb;
169 time_t ftime;
bd8a14a5 170## char login[9], *filetime;
171## int flag1, flag2, id;
dfb56d6b 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
f575c498 188 sprintf(outft, "%s~", outf);
189 out = fopen(outft, "w");
dfb56d6b 190 if (!out) {
191 perror("cannot open pobox.db for write");
f575c498 192 exit(SMS_OCONFIG);
dfb56d6b 193 }
194
195 fprintf(stderr, "Building pobox.db\n");
bd8a14a5 196 get_mach();
dfb56d6b 197
198## range of u is users
bd8a14a5 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);
dfb56d6b 205## }
206
207 if (fclose(out)) {
208 fprintf(stderr, "Unsuccessful close of pobox.db\n");
f575c498 209 exit(SMS_CCONFIG);
dfb56d6b 210 }
f575c498 211 fix_file(outf);
dfb56d6b 212 return(1);
213##}
214
215
f575c498 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
dfb56d6b 222do_groups()
223##{
224 FILE *iout, *gout, *lout;
bd8a14a5 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;
dfb56d6b 230 struct stat isb, gsb, lsb;
231 time_t ftime;
f575c498 232 register struct save_queue *sq;
233 struct save_queue *sq_create();
bd8a14a5 234 register int i;
dfb56d6b 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
f575c498 258 sprintf(buf, "%s~", ioutf);
259 iout = fopen(buf, "w");
dfb56d6b 260 if (!iout) {
261 perror("cannot open gid.db for write");
f575c498 262 exit(SMS_OCONFIG);
dfb56d6b 263 }
f575c498 264 sprintf(buf, "%s~", goutf);
265 gout = fopen(buf, "w");
dfb56d6b 266 if (!gout) {
267 perror("cannot open group.db for write");
f575c498 268 exit(SMS_OCONFIG);
dfb56d6b 269 }
f575c498 270 sprintf(buf, "%s~", loutf);
271 lout = fopen(buf, "w");
dfb56d6b 272 if (!lout) {
273 perror("cannot open grplist.db for write");
f575c498 274 exit(SMS_OCONFIG);
dfb56d6b 275 }
276
277 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
278
279 /* make space for group list */
bd8a14a5 280 groups = create_hash(15000);
dfb56d6b 281
282 /* retrieve simple groups */
bd8a14a5 283## range of l is list
29904371 284## begin transaction
dfb56d6b 285## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
f575c498 286## where l.group != 0 and l.active != 0 {
bd8a14a5 287 strtrim(name);
dfb56d6b 288 sprintf(buf, "%s:%d", name, gid);
bd8a14a5 289 hash_store(groups, lid, strsave(buf));
dfb56d6b 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
f575c498 295 fflush(iout);
296 fflush(gout);
297
dfb56d6b 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
f575c498 302## retrieve (name = list.#name, gid = list.#gid, lid = l.list_id)
bd8a14a5 303## where l.group = 0 and l.active != 0 and m.member_type = "LIST" and
dfb56d6b 304## m.member_id = l.list_id and m.list_id = list.list_id and
305## list.group != 0 {
bd8a14a5 306 strtrim(name);
307 if (l = hash_lookup(groups, lid)) {
308 sprintf(buf, "%s:%s:%d", l, name, gid);
309 free(l);
f575c498 310 } else {
311 sprintf(buf, "%s:%d", name, gid);
312 }
bd8a14a5 313 hash_store(groups, lid, strsave(buf));
dfb56d6b 314 sq_save_data(sq, lid);
315## }
f575c498 316
dfb56d6b 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 {
bd8a14a5 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));
dfb56d6b 329 sq_save_unique_data(sq, lid);
330## }
331 }
332 sq_destroy(sq);
333
334 /* now do grplists */
bd8a14a5 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);
dfb56d6b 343## }
dfb56d6b 344 }
bd8a14a5 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## }
29904371 355## end transaction
bd8a14a5 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
f575c498 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 */
dfb56d6b 373 sq_destroy(sq);
bd8a14a5 374 {
375 register char **p;
376 for (p = &groups[maxid-1]; p >= groups; p--)
377 if (*p)
378 free(*p);
379 }
dfb56d6b 380 free(groups);
f575c498 381#endif
dfb56d6b 382
383 if (fclose(iout) || fclose(gout) || fclose(lout)) {
384 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
f575c498 385 exit(SMS_CCONFIG);
dfb56d6b 386 }
f575c498 387 fix_file(ioutf);
388 fix_file(goutf);
389 fix_file(loutf);
dfb56d6b 390 return(1);
391##}
392
393
394do_filsys()
395##{
396 FILE *out;
bd8a14a5 397 char outf[64], outft[64], *mach;
dfb56d6b 398 struct stat sb;
399 time_t ftime;
bd8a14a5 400## char name[33], type[9], loc[33], access[2], mount[33], trans[257];
f575c498 401## char *filetime, comments[65];
bd8a14a5 402## int flag1, flag2, flag3, id;
dfb56d6b 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
f575c498 421 sprintf(outft, "%s~", outf);
422 out = fopen(outft, "w");
dfb56d6b 423 if (!out) {
424 perror("cannot open filsys.db for write");
f575c498 425 exit(SMS_OCONFIG);
dfb56d6b 426 }
427
428 fprintf(stderr, "Building filsys.db\n");
bd8a14a5 429 get_mach();
dfb56d6b 430
431## range of f is filesys
bd8a14a5 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);
f575c498 436 if (strcmp(type, "ERR")) {
bd8a14a5 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);
f575c498 443 } else {
bd8a14a5 444 strtrim(comments);
445 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
446 name, comments);
f575c498 447 }
dfb56d6b 448## }
449
29904371 450
451
dfb56d6b 452## range of a is alias
453## retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
bd8a14a5 454 strtrim(name);
455 strtrim(trans);
dfb56d6b 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");
f575c498 461 exit(SMS_CCONFIG);
dfb56d6b 462 }
f575c498 463 fix_file(outf);
dfb56d6b 464 return(1);
465##}
466
467
468/*
469 * Modified from sys/types.h:
470 */
471int setsize; /* = howmany(setbits, NSETBITS) */
472
473typedef 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
487do_cluster()
488##{
489 FILE *out;
29904371 490 char outf[64], outft[64], *mach, machbuf[33], *p;
dfb56d6b 491 struct stat sb;
492 time_t ftime;
493## int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
bd8a14a5 494## char name[33], label[17], data[33], *filetime;
dfb56d6b 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
f575c498 516 sprintf(outft, "%s~", outf);
517 out = fopen(outft, "w");
dfb56d6b 518 if (!out) {
519 perror("cannot open cluster.db for write");
f575c498 520 exit(SMS_OCONFIG);
dfb56d6b 521 }
522
523 fprintf(stderr, "Building cluster.db\n");
bd8a14a5 524 get_mach();
dfb56d6b 525
526## range of c is cluster
29904371 527## begin transaction
dfb56d6b 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];
dfb56d6b 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 {
bd8a14a5 553 strtrim(label);
554 strtrim(data);
f575c498 555 fprintf(out,
556 "smsinternal-%d.cluster\tHS UNSPECA \"%s %s\"\n",
557 mid, label, data);
dfb56d6b 558## }
559 }
560 }
561
29904371 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 }
dfb56d6b 569 for (id = mid + 1; id < maxmach; id++) {
570 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
571 free(ps);
572 machs[id] = NULL;
29904371 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 }
dfb56d6b 580 }
581 }
582 free(ms);
583 machs[mid] = NULL;
584 }
dfb56d6b 585
586## retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster)
587## where c.clu_id = d.clu_id {
bd8a14a5 588 strtrim(name);
589 strtrim(label);
590 strtrim(data);
dfb56d6b 591 fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n",
592 name, label, data);
593## }
29904371 594## end transaction
595 free(machs);
dfb56d6b 596
597 if (fclose(out)) {
598 fprintf(stderr, "Unsuccessful close of cluster.db\n");
f575c498 599 exit(SMS_CCONFIG);
dfb56d6b 600 }
f575c498 601 fix_file(outf);
dfb56d6b 602 return(1);
603##}
604
605
606do_printers()
607##{
608 FILE *out;
f575c498 609 char outf[64], outft[64];
dfb56d6b 610 struct stat sb;
611 time_t ftime;
29904371 612## char name[17], rp[17], sd[33], rm[33], *filetime;
dfb56d6b 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
f575c498 628 sprintf(outft, "%s~", outf);
629 out = fopen(outft, "w");
dfb56d6b 630 if (!out) {
631 perror("cannot open printcap.db for write");
f575c498 632 exit(SMS_OCONFIG);
dfb56d6b 633 }
634
635 fprintf(stderr, "Building printcap.db\n");
636
637## range of p is printcap
29904371 638## retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name)
639## where machine.mach_id = p.mach_id {
bd8a14a5 640 strtrim(name);
29904371 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);
dfb56d6b 646## }
647
648 if (fclose(out)) {
649 fprintf(stderr, "Unsuccessful close of pcap.db\n");
f575c498 650 exit(SMS_CCONFIG);
dfb56d6b 651 }
f575c498 652 fix_file(outf);
dfb56d6b 653 return(1);
654##}
655
656
f575c498 657do_sloc()
dfb56d6b 658##{
f575c498 659 FILE *out, *old, *new;
bd8a14a5 660 char outf[64], outft[64], *mach;
dfb56d6b 661 struct stat sb;
662 time_t ftime;
f575c498 663 register int c;
bd8a14a5 664## char service[17], *filetime;
665## int port, flag1, flag2, id;
dfb56d6b 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");
f575c498 678 return(0);
dfb56d6b 679 }
680 }
681
f575c498 682 sprintf(outft, "%s~", outf);
683 out = fopen(outft, "w");
dfb56d6b 684 if (!out) {
685 perror("cannot open sloc.db for write");
f575c498 686 exit(SMS_OCONFIG);
dfb56d6b 687 }
688
689 fprintf(stderr, "Building sloc.db\n");
bd8a14a5 690 get_mach();
dfb56d6b 691
692## range of s is serverhosts
bd8a14a5 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);
dfb56d6b 698## }
699
700 if (fclose(out)) {
701 fprintf(stderr, "Unsuccessful close of sloc.db\n");
f575c498 702 exit(SMS_CCONFIG);
703 }
704
bd8a14a5 705 fix_file(outf);
706 return(1);
f575c498 707##}
708
709do_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;
dfb56d6b 717
dfb56d6b 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
f575c498 731 sprintf(outft, "%s~", outf);
732 out = fopen(outft, "w");
dfb56d6b 733 if (!out) {
734 perror("cannot open service.db for write");
f575c498 735 exit(SMS_OCONFIG);
dfb56d6b 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) {
bd8a14a5 743 strtrim(service);
744 strtrim(protocol);
dfb56d6b 745 fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n",
746 service, service, protocol, port);
747## }
748
f575c498 749## range of a is alias
750## retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" {
bd8a14a5 751 strtrim(service);
752 strtrim(altserv);
f575c498 753 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
754## }
755
dfb56d6b 756 if (fclose(out)) {
757 fprintf(stderr, "Unsuccessful close of service.db\n");
f575c498 758 exit(SMS_CCONFIG);
dfb56d6b 759 }
f575c498 760 fix_file(outf);
dfb56d6b 761 return(1);
762##}
This page took 0.215541 seconds and 5 git commands to generate.