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