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