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