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