]> andersk Git - moira.git/blame - gen/hesiod.qc
fix misspelling
[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.
0a5ff702 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>.
dfb56d6b 10 */
11
0a5ff702 12#include <mit-copyright.h>
dfb56d6b 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>
abeed590 19#include <ctype.h>
dfb56d6b 20
bd8a14a5 21
dfb56d6b 22#define HESIOD_DIR "/u1/sms/dcm/hesiod"
23
24#define min(x,y) ((x) < (y) ? (x) : (y))
bd8a14a5 25struct hash *machines = NULL;
26struct hash *users = NULL;
1991abf7 27char *whoami = "hesiod.gen";
bd8a14a5 28
29struct grp {
30 struct grp *next;
31 int id;
32};
33struct user {
34 char name[9];
35 struct grp *lists;
36};
dfb56d6b 37
38char *malloc(), *strsave();
39char *ingres_date_and_time(), *ingres_time(), *ingres_date();
40
41main(argc, argv)
42int argc;
43char **argv;
44{
45 char cmd[64];
46 struct stat sb;
47 int changed = 0;
1991abf7 48 int ingerr();
dfb56d6b 49
50 if (argc > 2) {
51 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
f575c498 52 exit(SMS_ARGS);
dfb56d6b 53 }
54
1991abf7 55 IIseterr(ingerr);
56
dfb56d6b 57## ingres sms
dfb56d6b 58
59 changed = do_passwd();
60 changed += do_pobox();
dfb56d6b 61 changed += do_filsys();
62 changed += do_cluster();
63 changed += do_printers();
f575c498 64 changed += do_sloc();
65 changed += do_service();
66 changed += do_groups();
dfb56d6b 67
68## exit
69
70 if (!changed) {
71 fprintf(stderr, "No files updated.\n");
72 if (argc == 2 && stat(argv[1], &sb) == 0)
f575c498 73 exit(SMS_NO_CHANGE);
dfb56d6b 74 }
75
76 if (argc == 2) {
bd8a14a5 77 fprintf(stderr, "Building tar file.\n");
dfb56d6b 78 sprintf(cmd, "cd %s; tar cf %s .", HESIOD_DIR, argv[1]);
f575c498 79 if (system(cmd))
80 exit(SMS_TAR_FAIL);
dfb56d6b 81 }
82
f575c498 83 exit(SMS_SUCCESS);
dfb56d6b 84}
85
86
1991abf7 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
94static 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
bd8a14a5 113get_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
dfb56d6b 128do_passwd()
129##{
130 FILE *pout, *uout;
f575c498 131 char poutf[64], uoutf[64], poutft[64], uoutft[64];
dfb56d6b 132 struct stat psb, usb;
133 time_t ftime;
bd8a14a5 134 struct user *u;
dfb56d6b 135## char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime;
0a48a760 136## char nn[17];
bd8a14a5 137## int uid, flag, id;
dfb56d6b 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
f575c498 153 sprintf(poutft, "%s~", poutf);
154 pout = fopen(poutft, "w");
dfb56d6b 155 if (!pout) {
f575c498 156 perror("cannot open passwd.db~ for write");
157 exit(SMS_OCONFIG);
dfb56d6b 158 }
f575c498 159 sprintf(uoutft, "%s~", uoutf);
160 uout = fopen(uoutft, "w");
dfb56d6b 161 if (!uout) {
f575c498 162 perror("cannot open uid.db~ for write");
163 exit(SMS_OCONFIG);
dfb56d6b 164 }
165
166 fprintf(stderr, "Building passwd.db and uid.db\n");
167
bd8a14a5 168 users = create_hash(10000);
dfb56d6b 169## range of u is users
170## retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
0a48a760 171## fullname = u.#fullname, nn = u.nickname, oa = u.office_addr,
bd8a14a5 172## op = u.office_phone, hp = u.home_phone, id = u.users_id)
173## where u.status = 1 {
174 strtrim(login);
29904371 175 dequote(fullname);
0a48a760 176 dequote(nn);
29904371 177 dequote(oa);
178 dequote(op);
179 dequote(hp);
180 dequote(shell);
bd8a14a5 181 u = (struct user *) malloc(sizeof(struct user));
182 strcpy(u->name, login);
183 u->lists = NULL;
184 hash_store(users, id, u);
0a48a760 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);
dfb56d6b 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");
f575c498 192 exit(SMS_CCONFIG);
dfb56d6b 193 }
f575c498 194 fix_file(poutf);
195 fix_file(uoutf);
dfb56d6b 196 return(1);
197##}
198
199
200do_pobox()
201##{
202 FILE *out;
bd8a14a5 203 char outf[64], outft[64], *mach;
dfb56d6b 204 struct stat sb;
205 time_t ftime;
bd8a14a5 206## char login[9], *filetime;
207## int flag1, flag2, id;
dfb56d6b 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
f575c498 224 sprintf(outft, "%s~", outf);
225 out = fopen(outft, "w");
dfb56d6b 226 if (!out) {
227 perror("cannot open pobox.db for write");
f575c498 228 exit(SMS_OCONFIG);
dfb56d6b 229 }
230
231 fprintf(stderr, "Building pobox.db\n");
bd8a14a5 232 get_mach();
dfb56d6b 233
234## range of u is users
bd8a14a5 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);
dfb56d6b 241## }
242
243 if (fclose(out)) {
244 fprintf(stderr, "Unsuccessful close of pobox.db\n");
f575c498 245 exit(SMS_CCONFIG);
dfb56d6b 246 }
f575c498 247 fix_file(outf);
dfb56d6b 248 return(1);
249##}
250
251
f575c498 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
dfb56d6b 258do_groups()
259##{
260 FILE *iout, *gout, *lout;
1991abf7 261 char ioutf[64], goutf[64], loutf[64], buf[512], *l;
bd8a14a5 262 struct hash *groups;
263 register struct bucket *b, **p;
264 struct grp *g;
265 struct user *u;
dfb56d6b 266 struct stat isb, gsb, lsb;
267 time_t ftime;
f575c498 268 register struct save_queue *sq;
269 struct save_queue *sq_create();
bd8a14a5 270 register int i;
dfb56d6b 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
f575c498 294 sprintf(buf, "%s~", ioutf);
295 iout = fopen(buf, "w");
dfb56d6b 296 if (!iout) {
297 perror("cannot open gid.db for write");
f575c498 298 exit(SMS_OCONFIG);
dfb56d6b 299 }
f575c498 300 sprintf(buf, "%s~", goutf);
301 gout = fopen(buf, "w");
dfb56d6b 302 if (!gout) {
303 perror("cannot open group.db for write");
f575c498 304 exit(SMS_OCONFIG);
dfb56d6b 305 }
f575c498 306 sprintf(buf, "%s~", loutf);
307 lout = fopen(buf, "w");
dfb56d6b 308 if (!lout) {
309 perror("cannot open grplist.db for write");
f575c498 310 exit(SMS_OCONFIG);
dfb56d6b 311 }
312
313 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
314
315 /* make space for group list */
bd8a14a5 316 groups = create_hash(15000);
dfb56d6b 317
318 /* retrieve simple groups */
bd8a14a5 319## range of l is list
29904371 320## begin transaction
dfb56d6b 321## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
f575c498 322## where l.group != 0 and l.active != 0 {
bd8a14a5 323 strtrim(name);
dfb56d6b 324 sprintf(buf, "%s:%d", name, gid);
bd8a14a5 325 hash_store(groups, lid, strsave(buf));
dfb56d6b 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
f575c498 331 fflush(iout);
332 fflush(gout);
333
dfb56d6b 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
f575c498 338## retrieve (name = list.#name, gid = list.#gid, lid = l.list_id)
1991abf7 339## where l.active != 0 and list.active != 0 and m.member_type = "LIST" and
dfb56d6b 340## m.member_id = l.list_id and m.list_id = list.list_id and
341## list.group != 0 {
bd8a14a5 342 strtrim(name);
343 if (l = hash_lookup(groups, lid)) {
344 sprintf(buf, "%s:%s:%d", l, name, gid);
345 free(l);
f575c498 346 } else {
347 sprintf(buf, "%s:%d", name, gid);
348 }
bd8a14a5 349 hash_store(groups, lid, strsave(buf));
1991abf7 350 sq_save_unique_data(sq, lid);
dfb56d6b 351## }
f575c498 352
dfb56d6b 353 while (sq_get_data(sq, &id)) {
1991abf7 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 {
bd8a14a5 356 if (l = hash_lookup(groups, lid)) {
1991abf7 357 sprintf(buf, "%s:%s", l, hash_lookup(groups, id));
bd8a14a5 358 free(l);
1991abf7 359 l = strsave(buf);
bd8a14a5 360 } else {
1991abf7 361 l = hash_lookup(groups, id);
bd8a14a5 362 }
1991abf7 363 hash_store(groups, lid, l);
dfb56d6b 364 sq_save_unique_data(sq, lid);
365## }
366 }
367 sq_destroy(sq);
368
369 /* now do grplists */
bd8a14a5 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);
dfb56d6b 378## }
dfb56d6b 379 }
bd8a14a5 380
381## repeat retrieve (lid = m.list_id, id = m.member_id)
382## where m.member_type = "USER" {
1991abf7 383 if ((u = (struct user *) hash_lookup(users, id)) &&
384 (hash_lookup(groups, lid) != NULL)) {
bd8a14a5 385 g = (struct grp *) malloc(sizeof(struct grp));
386 g->next = u->lists;
387 u->lists = g;
388 g->id = lid;
389 }
390## }
29904371 391## end transaction
bd8a14a5 392
393 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
394 for (b = *p; b; b = b->next) {
1991abf7 395 i = 0;
396 sprintf(buf, "%s.grplist\tHS UNSPECA \"",
bd8a14a5 397 ((struct user *)b->data)->name);
398 for (g = ((struct user *)b->data)->lists; g; g = g->next)
1991abf7 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);
bd8a14a5 411 }
412 }
413
f575c498 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 */
dfb56d6b 419 sq_destroy(sq);
bd8a14a5 420 {
421 register char **p;
422 for (p = &groups[maxid-1]; p >= groups; p--)
423 if (*p)
424 free(*p);
425 }
dfb56d6b 426 free(groups);
f575c498 427#endif
dfb56d6b 428
429 if (fclose(iout) || fclose(gout) || fclose(lout)) {
430 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
f575c498 431 exit(SMS_CCONFIG);
dfb56d6b 432 }
f575c498 433 fix_file(ioutf);
434 fix_file(goutf);
435 fix_file(loutf);
dfb56d6b 436 return(1);
437##}
438
439
1991abf7 440#define MAXGROUPS 256
441
442remove_duplicate_groups(p)
443register 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
dfb56d6b 473do_filsys()
474##{
475 FILE *out;
abeed590 476 char outf[64], outft[64], *mach, machbuf[128];
477 register char *p;
dfb56d6b 478 struct stat sb;
479 time_t ftime;
bd8a14a5 480## char name[33], type[9], loc[33], access[2], mount[33], trans[257];
f575c498 481## char *filetime, comments[65];
bd8a14a5 482## int flag1, flag2, flag3, id;
dfb56d6b 483
484 sprintf(outf, "%s/filsys.db", HESIOD_DIR);
485
486 if (stat(outf, &sb) == 0) {
487 ftime = sb.st_mtime;
488 filetime = ingres_date_and_time(ftime);
489## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
490## where tblstats.table = "filesys"
491## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
492## where tblstats.table = "machine"
493## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
494## where tblstats.table = "alias"
495 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
496 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
497 return(0);
498 }
499 }
500
f575c498 501 sprintf(outft, "%s~", outf);
502 out = fopen(outft, "w");
dfb56d6b 503 if (!out) {
504 perror("cannot open filsys.db for write");
f575c498 505 exit(SMS_OCONFIG);
dfb56d6b 506 }
507
508 fprintf(stderr, "Building filsys.db\n");
bd8a14a5 509 get_mach();
dfb56d6b 510
511## range of f is filesys
bd8a14a5 512## retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id,
513## access = f.#access, mount = f.#mount, comments = f.#comments) {
514 strtrim(name);
515 strtrim(type);
f575c498 516 if (strcmp(type, "ERR")) {
bd8a14a5 517 strtrim(loc);
518 strtrim(access);
519 strtrim(mount);
abeed590 520 if (mach = hash_lookup(machines, id)) {
521 for (p = machbuf; *mach && *mach != '.'; mach++) {
522 if (isupper(*mach))
523 *p++ = tolower(*mach);
524 else
525 *p++ = *mach;
526 *p = 0;
527 }
528 fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
529 name, type, loc, machbuf, access, mount);
530 }
f575c498 531 } else {
bd8a14a5 532 strtrim(comments);
533 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
534 name, comments);
f575c498 535 }
dfb56d6b 536## }
537
29904371 538
539
dfb56d6b 540## range of a is alias
541## retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
bd8a14a5 542 strtrim(name);
543 strtrim(trans);
dfb56d6b 544 fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n", name, trans);
545## }
546
547 if (fclose(out)) {
548 fprintf(stderr, "Unsuccessful close of filsys.db\n");
f575c498 549 exit(SMS_CCONFIG);
dfb56d6b 550 }
f575c498 551 fix_file(outf);
dfb56d6b 552 return(1);
553##}
554
555
556/*
557 * Modified from sys/types.h:
558 */
559int setsize; /* = howmany(setbits, NSETBITS) */
560
561typedef long set_mask;
562#define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
563#ifndef howmany
564#define howmany(x, y) (((x)+((y)-1))/(y))
565#endif
566
567#define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
568#define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
569#define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
570#define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
571#define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask))
572#define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
573
574
575do_cluster()
576##{
577 FILE *out;
29904371 578 char outf[64], outft[64], *mach, machbuf[33], *p;
dfb56d6b 579 struct stat sb;
580 time_t ftime;
581## int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
bd8a14a5 582## char name[33], label[17], data[33], *filetime;
dfb56d6b 583 set_mask **machs, *ms, *ps;
584
585 sprintf(outf, "%s/cluster.db", HESIOD_DIR);
586
587 if (stat(outf, &sb) == 0) {
588 ftime = sb.st_mtime;
589 filetime = ingres_date_and_time(ftime);
590## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
591## where tblstats.table = "cluster"
592## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
593## where tblstats.table = "machine"
594## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
595## where tblstats.table = "mcmap"
596## retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
597## where tblstats.table = "svc"
598 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
599 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
600 return(0);
601 }
602 }
603
f575c498 604 sprintf(outft, "%s~", outf);
605 out = fopen(outft, "w");
dfb56d6b 606 if (!out) {
607 perror("cannot open cluster.db for write");
f575c498 608 exit(SMS_OCONFIG);
dfb56d6b 609 }
610
611 fprintf(stderr, "Building cluster.db\n");
bd8a14a5 612 get_mach();
dfb56d6b 613
614## range of c is cluster
29904371 615## begin transaction
dfb56d6b 616## retrieve (maxclu = max(c.clu_id))
3604fe12 617 maxclu++;
dfb56d6b 618 setsize = howmany(maxclu, NSETBITS);
619## range of m is machine
620## retrieve (maxmach = max(m.mach_id))
3604fe12 621 maxmach++;
dfb56d6b 622 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
623 bzero(machs, (maxmach + 1) * sizeof(int));
624
625## range of p is mcmap
626## retrieve (mid = p.mach_id, cid = p.clu_id) {
627 if (!(ms = machs[mid])) {
628 ms = machs[mid] = SET_CREATE();
629 SET_ZERO(ms);
630 }
631 SET_SET(cid, ms);
632## }
633
634## range of d is svc
635 for (mid = 1; mid < maxmach; mid++) {
636 if (!machs[mid])
637 continue;
638 ms = machs[mid];
dfb56d6b 639 for (cid = 1; cid < maxclu; cid++) {
640 if (SET_ISSET(cid, ms)) {
641## repeat retrieve (label = d.serv_label, data = d.serv_cluster)
642## where d.clu_id = @cid {
bd8a14a5 643 strtrim(label);
644 strtrim(data);
f575c498 645 fprintf(out,
646 "smsinternal-%d.cluster\tHS UNSPECA \"%s %s\"\n",
647 mid, label, data);
dfb56d6b 648## }
649 }
650 }
651
29904371 652 if (mach = hash_lookup(machines, mid)) {
653 for (p = machbuf; *mach && *mach != '.'; mach++)
654 *p++ = *mach;
655 *p = 0;
656 fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
657 machbuf, mid);
658 }
dfb56d6b 659 for (id = mid + 1; id < maxmach; id++) {
660 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
661 free(ps);
662 machs[id] = NULL;
29904371 663 if (mach = hash_lookup(machines, id)) {
664 for (p = machbuf; *mach && *mach != '.'; mach++)
665 *p++ = *mach;
666 *p = 0;
667 fprintf(out,"%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
668 machbuf, mid);
669 }
dfb56d6b 670 }
671 }
672 free(ms);
673 machs[mid] = NULL;
674 }
dfb56d6b 675
676## retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster)
677## where c.clu_id = d.clu_id {
bd8a14a5 678 strtrim(name);
679 strtrim(label);
680 strtrim(data);
dfb56d6b 681 fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n",
682 name, label, data);
683## }
29904371 684## end transaction
685 free(machs);
dfb56d6b 686
687 if (fclose(out)) {
688 fprintf(stderr, "Unsuccessful close of cluster.db\n");
f575c498 689 exit(SMS_CCONFIG);
dfb56d6b 690 }
f575c498 691 fix_file(outf);
dfb56d6b 692 return(1);
693##}
694
695
696do_printers()
697##{
698 FILE *out;
f575c498 699 char outf[64], outft[64];
dfb56d6b 700 struct stat sb;
701 time_t ftime;
29904371 702## char name[17], rp[17], sd[33], rm[33], *filetime;
dfb56d6b 703## int flag;
704
705 sprintf(outf, "%s/printcap.db", HESIOD_DIR);
706
707 if (stat(outf, &sb) == 0) {
708 ftime = sb.st_mtime;
709 filetime = ingres_date_and_time(ftime);
710## retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
711## where tblstats.table = "printcap"
712 if (flag < 0) {
713 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
714 return(0);
715 }
716 }
717
f575c498 718 sprintf(outft, "%s~", outf);
719 out = fopen(outft, "w");
dfb56d6b 720 if (!out) {
721 perror("cannot open printcap.db for write");
f575c498 722 exit(SMS_OCONFIG);
dfb56d6b 723 }
724
725 fprintf(stderr, "Building printcap.db\n");
726
727## range of p is printcap
29904371 728## retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name)
729## where machine.mach_id = p.mach_id {
bd8a14a5 730 strtrim(name);
29904371 731 strtrim(rp);
732 strtrim(sd);
733 strtrim(rm);
734 fprintf(out, "%s.pcap\tHS UNSPECA \"%s:rp=%s:rm=%s:sd=%s\"\n",
735 name, name, rp, rm, sd);
dfb56d6b 736## }
737
738 if (fclose(out)) {
739 fprintf(stderr, "Unsuccessful close of pcap.db\n");
f575c498 740 exit(SMS_CCONFIG);
dfb56d6b 741 }
f575c498 742 fix_file(outf);
dfb56d6b 743 return(1);
744##}
745
746
f575c498 747do_sloc()
dfb56d6b 748##{
f575c498 749 FILE *out, *old, *new;
bd8a14a5 750 char outf[64], outft[64], *mach;
dfb56d6b 751 struct stat sb;
752 time_t ftime;
f575c498 753 register int c;
bd8a14a5 754## char service[17], *filetime;
755## int port, flag1, flag2, id;
dfb56d6b 756
757 sprintf(outf, "%s/sloc.db", HESIOD_DIR);
758
759 if (stat(outf, &sb) == 0) {
760 ftime = sb.st_mtime;
761 filetime = ingres_date_and_time(ftime);
762## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
763## where tblstats.table = "serverhosts"
764## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
765## where tblstats.table = "machine"
766 if (flag1 < 0 && flag2 < 0) {
767 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
f575c498 768 return(0);
dfb56d6b 769 }
770 }
771
f575c498 772 sprintf(outft, "%s~", outf);
773 out = fopen(outft, "w");
dfb56d6b 774 if (!out) {
775 perror("cannot open sloc.db for write");
f575c498 776 exit(SMS_OCONFIG);
dfb56d6b 777 }
778
779 fprintf(stderr, "Building sloc.db\n");
bd8a14a5 780 get_mach();
dfb56d6b 781
782## range of s is serverhosts
bd8a14a5 783## retrieve (service = s.#service, id = s.mach_id)
784## sort by #service {
785 strtrim(service);
786 if (mach = hash_lookup(machines, id))
787 fprintf(out, "%s.sloc\tHS UNSPECA %s\n", service, mach);
dfb56d6b 788## }
789
790 if (fclose(out)) {
791 fprintf(stderr, "Unsuccessful close of sloc.db\n");
f575c498 792 exit(SMS_CCONFIG);
793 }
794
bd8a14a5 795 fix_file(outf);
796 return(1);
f575c498 797##}
798
799do_service()
800##{
801 FILE *out;
802 char outf[64], outft[64];
803 struct stat sb;
804 time_t ftime;
805## char mach[33], service[33], protocol[9], altserv[129], *filetime;
806## int port, flag1, flag2;
dfb56d6b 807
dfb56d6b 808 sprintf(outf, "%s/service.db", HESIOD_DIR);
809
810 if (stat(outf, &sb) == 0) {
811 ftime = sb.st_mtime;
812 filetime = ingres_date_and_time(ftime);
813## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
814## where tblstats.table = "services"
815 if (flag1 < 0) {
816 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
817 return(0);
818 }
819 }
820
f575c498 821 sprintf(outft, "%s~", outf);
822 out = fopen(outft, "w");
dfb56d6b 823 if (!out) {
824 perror("cannot open service.db for write");
f575c498 825 exit(SMS_OCONFIG);
dfb56d6b 826 }
827
828 fprintf(stderr, "Building service.db\n");
829
830## range of s is services
831## retrieve (service = s.name, protocol = lowercase(s.#protocol),
832## port = s.#port) {
bd8a14a5 833 strtrim(service);
834 strtrim(protocol);
dfb56d6b 835 fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n",
836 service, service, protocol, port);
837## }
838
f575c498 839## range of a is alias
840## retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" {
bd8a14a5 841 strtrim(service);
842 strtrim(altserv);
f575c498 843 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
844## }
845
dfb56d6b 846 if (fclose(out)) {
847 fprintf(stderr, "Unsuccessful close of service.db\n");
f575c498 848 exit(SMS_CCONFIG);
dfb56d6b 849 }
f575c498 850 fix_file(outf);
dfb56d6b 851 return(1);
852##}
This page took 2.634693 seconds and 5 git commands to generate.