]> andersk Git - moira.git/blame - gen/hesiod.qc
only append .LOCAL to hostname #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
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{
1991abf7 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
185f76ce 142 sprintf(poutf, "%s/passwd.db", hesiod_dir);
143 sprintf(uoutf, "%s/uid.db", hesiod_dir);
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
082f6d97 182 users = create_hash(12001);
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
220do_groups()
221##{
222 FILE *iout, *gout, *lout;
644f2f23 223 char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
bd8a14a5 224 struct hash *groups;
225 register struct bucket *b, **p;
226 struct grp *g;
227 struct user *u;
dfb56d6b 228 struct stat isb, gsb, lsb;
229 time_t ftime;
dfb56d6b 230## char name[33], *filetime;
082f6d97 231## int gid, id, lid, flag1, flag2, flag3;
dfb56d6b 232
233 /* open files */
185f76ce 234 sprintf(ioutf, "%s/gid.db", hesiod_dir);
235 sprintf(goutf, "%s/group.db", hesiod_dir);
236 sprintf(loutf, "%s/grplist.db", hesiod_dir);
dfb56d6b 237
238 if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
239 ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
240 filetime = ingres_date_and_time(ftime);
241## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
242## where tblstats.table = "users"
243## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
244## where tblstats.table = "list"
245## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
5c4da135 246## where tblstats.table = "imembers"
dfb56d6b 247 if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
248 fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
249 return(0);
250 }
251 }
252
f575c498 253 sprintf(buf, "%s~", ioutf);
254 iout = fopen(buf, "w");
dfb56d6b 255 if (!iout) {
256 perror("cannot open gid.db for write");
f575c498 257 exit(SMS_OCONFIG);
dfb56d6b 258 }
f575c498 259 sprintf(buf, "%s~", goutf);
260 gout = fopen(buf, "w");
dfb56d6b 261 if (!gout) {
262 perror("cannot open group.db for write");
f575c498 263 exit(SMS_OCONFIG);
dfb56d6b 264 }
f575c498 265 sprintf(buf, "%s~", loutf);
266 lout = fopen(buf, "w");
dfb56d6b 267 if (!lout) {
268 perror("cannot open grplist.db for write");
f575c498 269 exit(SMS_OCONFIG);
dfb56d6b 270 }
271
272 fprintf(stderr, "Building gid.db, group.db, and grplist.db\n");
273
274 /* make space for group list */
082f6d97 275 groups = create_hash(15001);
dfb56d6b 276
277 /* retrieve simple groups */
bd8a14a5 278## range of l is list
5c4da135 279## range of m is imembers
29904371 280## begin transaction
3b9c758d 281 /* get lock records */
282## retrieve (name = l.modtime) where l.list_id = 0
283## retrieve (name = users.modtime) where users.users_id = 0
284
dfb56d6b 285## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
f575c498 286## where l.group != 0 and l.active != 0 {
bd8a14a5 287 strtrim(name);
dfb56d6b 288 sprintf(buf, "%s:%d", name, gid);
bd8a14a5 289 hash_store(groups, lid, strsave(buf));
dfb56d6b 290 fprintf(iout, "%d.gid\tHS CNAME %s.group\n", gid, name);
291 fprintf(gout, "%s.group\tHS UNSPECA \"%s:*:%d:\"\n",
292 name, name, gid);
293## }
294
f575c498 295 fflush(iout);
296 fflush(gout);
297
dfb56d6b 298 /* now do grplists */
bd8a14a5 299 if (users == NULL) {
082f6d97 300 users = create_hash(12001);
bd8a14a5 301## range of u is users
302## retrieve (id = u.users_id, name = u.login) where u.status = 1 {
303 u = (struct user *) malloc(sizeof(struct user));
304 strcpy(u->name, strtrim(name));
305 u->lists = NULL;
306 hash_store(users, id, u);
dfb56d6b 307## }
dfb56d6b 308 }
bd8a14a5 309
310## repeat retrieve (lid = m.list_id, id = m.member_id)
311## where m.member_type = "USER" {
082f6d97 312 if ((hash_lookup(groups, lid) != NULL) &&
313 (u = (struct user *) hash_lookup(users, id))) {
bd8a14a5 314 g = (struct grp *) malloc(sizeof(struct grp));
315 g->next = u->lists;
316 u->lists = g;
317 g->id = lid;
318 }
319## }
29904371 320## end transaction
bd8a14a5 321
322 for (p = &(users->data[users->size - 1]); p >= users->data; p--) {
323 for (b = *p; b; b = b->next) {
082f6d97 324 if ((g = ((struct user *)b->data)->lists) == NULL)
325 continue;
326 fprintf(lout, "%s.grplist\tHS UNSPECA \"",
bd8a14a5 327 ((struct user *)b->data)->name);
082f6d97 328 for (; g; g = g->next)
1991abf7 329 if (l = hash_lookup(groups, g->id)) {
082f6d97 330 fputs(l, lout);
1991abf7 331 if (g->next)
082f6d97 332 putc(':', lout);
1991abf7 333 }
082f6d97 334 fputs("\"\n", lout);
bd8a14a5 335 }
336 }
337
dfb56d6b 338 if (fclose(iout) || fclose(gout) || fclose(lout)) {
339 fprintf(stderr, "Unsuccessful close of gid.db, group.db, or grplist.db\n");
f575c498 340 exit(SMS_CCONFIG);
dfb56d6b 341 }
f575c498 342 fix_file(ioutf);
343 fix_file(goutf);
344 fix_file(loutf);
dfb56d6b 345 return(1);
346##}
347
348
349do_filsys()
350##{
351 FILE *out;
90647001 352 char outf[64], outft[64], *mach, machbuf[128], *group;
abeed590 353 register char *p;
dfb56d6b 354 struct stat sb;
355 time_t ftime;
90647001 356 struct save_queue *sq, *sq_create();
a30e1c62 357## char name[33], type[9], loc[81], access[2], mount[33], trans[257];
f575c498 358## char *filetime, comments[65];
90647001 359## int flag1, flag2, flag3, flag4, id, fid;
f8508066 360 char *index();
dfb56d6b 361
185f76ce 362 sprintf(outf, "%s/filsys.db", hesiod_dir);
dfb56d6b 363
364 if (stat(outf, &sb) == 0) {
365 ftime = sb.st_mtime;
366 filetime = ingres_date_and_time(ftime);
367## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
368## where tblstats.table = "filesys"
369## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
370## where tblstats.table = "machine"
371## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
372## where tblstats.table = "alias"
90647001 373## retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
374## where tblstats.table = "fsgroup"
375 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
dfb56d6b 376 fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
377 return(0);
378 }
379 }
380
f575c498 381 sprintf(outft, "%s~", outf);
382 out = fopen(outft, "w");
dfb56d6b 383 if (!out) {
384 perror("cannot open filsys.db for write");
f575c498 385 exit(SMS_OCONFIG);
dfb56d6b 386 }
387
388 fprintf(stderr, "Building filsys.db\n");
bd8a14a5 389 get_mach();
90647001 390 sq = sq_create();
dfb56d6b 391
392## range of f is filesys
bd8a14a5 393## retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id,
90647001 394## access = f.#access, mount = f.#mount, comments = f.#comments,
395## fid = f.filsys_id) {
bd8a14a5 396 strtrim(type);
90647001 397 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
abeed590 398 if (mach = hash_lookup(machines, id)) {
399 for (p = machbuf; *mach && *mach != '.'; mach++) {
400 if (isupper(*mach))
401 *p++ = tolower(*mach);
402 else
403 *p++ = *mach;
abeed590 404 }
082f6d97 405 *p = 0;
abeed590 406 fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
082f6d97 407 strtrim(name), type, strtrim(loc), machbuf,
408 strtrim(access), strtrim(mount));
abeed590 409 }
333f7a7f 410 } else if (!strcmp(type, "AFS")) {
333f7a7f 411 fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
082f6d97 412 strtrim(name), strtrim(loc), strtrim(access),
413 strtrim(mount));
90647001 414 } else if (!strcmp(type, "ERR")) {
bd8a14a5 415 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
082f6d97 416 name, strtrim(comments));
90647001 417 } else if (!strcmp(type, "FSGROUP")) {
d652788e 418 sprintf(trans, "%s:%d", strtrim(name), fid);
90647001 419 sq_save_data(sq, strsave(trans));
f575c498 420 }
dfb56d6b 421## }
422
90647001 423## range of g is fsgroup
424 while (sq_get_data(sq, &group)) {
425 fid = atoi(index(group, ':')+1);
426 *index(group, ':') = 0;
427## retrieve (type = f.#type, loc = f.#name, id = f.mach_id,
428## access = f.#access, mount = f.#mount, comments = f.#comments,
429## name = f.#label, trans = g.#key)
430## where f.filsys_id = g.filsys_id and g.group_id = fid
431## sort by #trans, #name {
432 strtrim(type);
433 if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
90647001 434 if (mach = hash_lookup(machines, id)) {
435 for (p = machbuf; *mach && *mach != '.'; mach++) {
436 if (isupper(*mach))
437 *p++ = tolower(*mach);
438 else
439 *p++ = *mach;
90647001 440 }
082f6d97 441 *p = 0;
90647001 442 fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
082f6d97 443 group, type, strtrim(loc), machbuf,
444 strtrim(access), strtrim(mount));
90647001 445 }
333f7a7f 446 } else if (!strcmp(type, "AFS")) {
333f7a7f 447 fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
082f6d97 448 group, strtrim(loc), strtrim(access), strtrim(mount));
90647001 449 } else if (!strcmp(type, "ERR")) {
90647001 450 fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
082f6d97 451 group, strtrim(comments));
90647001 452 }
453## }
454 free(group);
455 }
456 sq_destroy(sq);
29904371 457
dfb56d6b 458## range of a is alias
459## retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
082f6d97 460 fprintf(out, "%s.filsys\tHS CNAME %s.filsys\n",
461 strtrim(name), strtrim(trans));
dfb56d6b 462## }
463
464 if (fclose(out)) {
465 fprintf(stderr, "Unsuccessful close of filsys.db\n");
f575c498 466 exit(SMS_CCONFIG);
dfb56d6b 467 }
f575c498 468 fix_file(outf);
dfb56d6b 469 return(1);
470##}
471
472
473/*
474 * Modified from sys/types.h:
475 */
476int setsize; /* = howmany(setbits, NSETBITS) */
477
478typedef long set_mask;
479#define NSETBITS (sizeof(set_mask) * NBBY) /* bits per mask */
480#ifndef howmany
481#define howmany(x, y) (((x)+((y)-1))/(y))
482#endif
483
484#define SET_SET(n, p) ((p)[(n)/NSETBITS] |= (1 << ((n) % NSETBITS)))
485#define SET_CLR(n, p) ((p)[(n)/NSETBITS] &= ~(1 << ((n) % NSETBITS)))
486#define SET_ISSET(n, p) ((p)[(n)/NSETBITS] & (1 << ((n) % NSETBITS)))
487#define SET_CREATE() ((set_mask *)malloc(setsize * sizeof(set_mask)))
488#define SET_ZERO(p) bzero((char *)(p), setsize * sizeof(set_mask))
489#define SET_CMP(p1, p2) (bcmp((p1), (p2), setsize * sizeof(set_mask)))
490
082f6d97 491int nbitsset(set)
492set_mask *set;
493{
494 int i, ret;
495
496 ret = 0;
497 for (i = 0; i < setsize * NSETBITS; i++)
498 if (SET_ISSET(i, set))
499 ret++;
500 return(ret);
501}
502
dfb56d6b 503
504do_cluster()
505##{
506 FILE *out;
29904371 507 char outf[64], outft[64], *mach, machbuf[33], *p;
dfb56d6b 508 struct stat sb;
509 time_t ftime;
510## int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id;
bd8a14a5 511## char name[33], label[17], data[33], *filetime;
dfb56d6b 512 set_mask **machs, *ms, *ps;
082f6d97 513 int oneclu;
dfb56d6b 514
185f76ce 515 sprintf(outf, "%s/cluster.db", hesiod_dir);
dfb56d6b 516
517 if (stat(outf, &sb) == 0) {
518 ftime = sb.st_mtime;
519 filetime = ingres_date_and_time(ftime);
520## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
521## where tblstats.table = "cluster"
522## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
523## where tblstats.table = "machine"
524## retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
525## where tblstats.table = "mcmap"
526## retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
527## where tblstats.table = "svc"
528 if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
529 fprintf(stderr, "File cluster.db does not need to be rebuilt.\n");
530 return(0);
531 }
532 }
533
f575c498 534 sprintf(outft, "%s~", outf);
535 out = fopen(outft, "w");
dfb56d6b 536 if (!out) {
537 perror("cannot open cluster.db for write");
f575c498 538 exit(SMS_OCONFIG);
dfb56d6b 539 }
540
541 fprintf(stderr, "Building cluster.db\n");
bd8a14a5 542 get_mach();
dfb56d6b 543
544## range of c is cluster
29904371 545## begin transaction
dfb56d6b 546## retrieve (maxclu = max(c.clu_id))
3604fe12 547 maxclu++;
dfb56d6b 548 setsize = howmany(maxclu, NSETBITS);
549## range of m is machine
550## retrieve (maxmach = max(m.mach_id))
3604fe12 551 maxmach++;
dfb56d6b 552 machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **));
553 bzero(machs, (maxmach + 1) * sizeof(int));
554
555## range of p is mcmap
556## retrieve (mid = p.mach_id, cid = p.clu_id) {
557 if (!(ms = machs[mid])) {
558 ms = machs[mid] = SET_CREATE();
559 SET_ZERO(ms);
560 }
561 SET_SET(cid, ms);
562## }
563
564## range of d is svc
565 for (mid = 1; mid < maxmach; mid++) {
566 if (!machs[mid])
567 continue;
568 ms = machs[mid];
082f6d97 569 if (nbitsset(ms) > 1) {
570 oneclu = 0;
571 for (cid = 1; cid < maxclu; cid++) {
572 if (SET_ISSET(cid, ms)) {
573## repeat retrieve (label = d.serv_label, data = d.serv_cluster)
dfb56d6b 574## where d.clu_id = @cid {
082f6d97 575 strtrim(label);
576 strtrim(data);
577 fprintf(out,
578 "smsinternal-%d.cluster\tHS UNSPECA \"%s %s\"\n",
579 mid, label, data);
580## }
581 }
dfb56d6b 582 }
082f6d97 583 } else {
584 oneclu = 1;
585 for (cid = 1; cid < maxclu; cid++)
586 if (SET_ISSET(cid, ms)) break;
587## repeat retrieve (name = c.#name) where c.clu_id = @cid
588 strtrim(name);
dfb56d6b 589 }
590
29904371 591 if (mach = hash_lookup(machines, mid)) {
592 for (p = machbuf; *mach && *mach != '.'; mach++)
593 *p++ = *mach;
594 *p = 0;
082f6d97 595 if (oneclu)
596 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
597 machbuf, name);
598 else
599 fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
600 machbuf, mid);
29904371 601 }
dfb56d6b 602 for (id = mid + 1; id < maxmach; id++) {
603 if ((ps = machs[id]) && !SET_CMP(ms, ps)) {
604 free(ps);
605 machs[id] = NULL;
29904371 606 if (mach = hash_lookup(machines, id)) {
607 for (p = machbuf; *mach && *mach != '.'; mach++)
608 *p++ = *mach;
609 *p = 0;
082f6d97 610 if (oneclu)
611 fprintf(out, "%s.cluster\tHS CNAME %s.cluster\n",
612 machbuf, name);
613 else
614 fprintf(out,
615 "%s.cluster\tHS CNAME smsinternal-%d.cluster\n",
616 machbuf, mid);
29904371 617 }
dfb56d6b 618 }
619 }
620 free(ms);
621 machs[mid] = NULL;
622 }
dfb56d6b 623
624## retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster)
625## where c.clu_id = d.clu_id {
bd8a14a5 626 strtrim(name);
627 strtrim(label);
628 strtrim(data);
dfb56d6b 629 fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n",
630 name, label, data);
631## }
29904371 632## end transaction
633 free(machs);
dfb56d6b 634
635 if (fclose(out)) {
636 fprintf(stderr, "Unsuccessful close of cluster.db\n");
f575c498 637 exit(SMS_CCONFIG);
dfb56d6b 638 }
f575c498 639 fix_file(outf);
dfb56d6b 640 return(1);
641##}
642
643
22208c6c 644do_printcap()
dfb56d6b 645##{
646 FILE *out;
f575c498 647 char outf[64], outft[64];
dfb56d6b 648 struct stat sb;
649 time_t ftime;
29904371 650## char name[17], rp[17], sd[33], rm[33], *filetime;
dfb56d6b 651## int flag;
652
185f76ce 653 sprintf(outf, "%s/printcap.db", hesiod_dir);
dfb56d6b 654
655 if (stat(outf, &sb) == 0) {
656 ftime = sb.st_mtime;
657 filetime = ingres_date_and_time(ftime);
658## retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
659## where tblstats.table = "printcap"
660 if (flag < 0) {
661 fprintf(stderr, "File printcap.db does not need to be rebuilt.\n");
662 return(0);
663 }
664 }
665
f575c498 666 sprintf(outft, "%s~", outf);
667 out = fopen(outft, "w");
dfb56d6b 668 if (!out) {
669 perror("cannot open printcap.db for write");
f575c498 670 exit(SMS_OCONFIG);
dfb56d6b 671 }
672
673 fprintf(stderr, "Building printcap.db\n");
674
675## range of p is printcap
29904371 676## retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name)
677## where machine.mach_id = p.mach_id {
bd8a14a5 678 strtrim(name);
29904371 679 strtrim(rp);
680 strtrim(sd);
681 strtrim(rm);
682 fprintf(out, "%s.pcap\tHS UNSPECA \"%s:rp=%s:rm=%s:sd=%s\"\n",
683 name, name, rp, rm, sd);
dfb56d6b 684## }
685
686 if (fclose(out)) {
687 fprintf(stderr, "Unsuccessful close of pcap.db\n");
f575c498 688 exit(SMS_CCONFIG);
dfb56d6b 689 }
f575c498 690 fix_file(outf);
dfb56d6b 691 return(1);
692##}
693
694
22208c6c 695do_palladium()
696##{
697 FILE *out;
698 char outf[64], outft[64];
699 struct stat sb;
700 time_t ftime;
701## char name[33], rm[33], trans[129], *filetime;
702## int flag, flag1, ident;
703
185f76ce 704 sprintf(outf, "%s/palladium.db", hesiod_dir);
22208c6c 705
706 if (stat(outf, &sb) == 0) {
707 ftime = sb.st_mtime;
708 filetime = ingres_date_and_time(ftime);
709## retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
710## where tblstats.table = "palladium"
711## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
712## where tblstats.table = "alias"
713 if (flag < 0 && flag1 < 0) {
714 fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
715 return(0);
716 }
717 }
718
719 sprintf(outft, "%s~", outf);
720 out = fopen(outft, "w");
721 if (!out) {
722 perror("cannot open palladium.db for write");
723 exit(SMS_OCONFIG);
724 }
725
726 fprintf(stderr, "Building palladium.db\n");
727
728## range of p is palladium
729## retrieve (name = p.#name, ident = p.#ident, rm = machine.#name)
730## where machine.mach_id = p.mach_id {
731 strtrim(name);
732 strtrim(rm);
733 fprintf(out,
734 "%s.palladium\tHS UNSPECA \"%s %d %s interface directory\"\n",
735 name, rm, ident, name);
736## }
737## range of a is alias
738## retrieve (name = a.#name, trans = a.#trans) where a.#type = "PALLADIUM" {
739 strtrim(name);
740 strtrim(trans);
741 fprintf(out, "%s.palladium\tHS UNSPECA \"%s\"\n", name, trans);
742## }
743
744 if (fclose(out)) {
745 fprintf(stderr, "Unsuccessful close of palladium.db\n");
746 exit(SMS_CCONFIG);
747 }
748 fix_file(outf);
749 return(1);
750##}
751
752
f575c498 753do_sloc()
dfb56d6b 754##{
082f6d97 755 FILE *out;
bd8a14a5 756 char outf[64], outft[64], *mach;
dfb56d6b 757 struct stat sb;
758 time_t ftime;
bd8a14a5 759## char service[17], *filetime;
082f6d97 760## int flag1, flag2, id;
dfb56d6b 761
185f76ce 762 sprintf(outf, "%s/sloc.db", hesiod_dir);
dfb56d6b 763
764 if (stat(outf, &sb) == 0) {
765 ftime = sb.st_mtime;
766 filetime = ingres_date_and_time(ftime);
767## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
768## where tblstats.table = "serverhosts"
769## retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
770## where tblstats.table = "machine"
771 if (flag1 < 0 && flag2 < 0) {
772 fprintf(stderr, "File sloc.db does not need to be rebuilt.\n");
f575c498 773 return(0);
dfb56d6b 774 }
775 }
776
f575c498 777 sprintf(outft, "%s~", outf);
778 out = fopen(outft, "w");
dfb56d6b 779 if (!out) {
780 perror("cannot open sloc.db for write");
f575c498 781 exit(SMS_OCONFIG);
dfb56d6b 782 }
783
784 fprintf(stderr, "Building sloc.db\n");
bd8a14a5 785 get_mach();
dfb56d6b 786
787## range of s is serverhosts
bd8a14a5 788## retrieve (service = s.#service, id = s.mach_id)
789## sort by #service {
790 strtrim(service);
791 if (mach = hash_lookup(machines, id))
792 fprintf(out, "%s.sloc\tHS UNSPECA %s\n", service, mach);
dfb56d6b 793## }
794
795 if (fclose(out)) {
796 fprintf(stderr, "Unsuccessful close of sloc.db\n");
f575c498 797 exit(SMS_CCONFIG);
798 }
799
bd8a14a5 800 fix_file(outf);
801 return(1);
f575c498 802##}
803
804do_service()
805##{
806 FILE *out;
807 char outf[64], outft[64];
808 struct stat sb;
809 time_t ftime;
082f6d97 810## char service[33], protocol[9], altserv[129], *filetime;
811## int port, flag1;
dfb56d6b 812
185f76ce 813 sprintf(outf, "%s/service.db", hesiod_dir);
dfb56d6b 814
815 if (stat(outf, &sb) == 0) {
816 ftime = sb.st_mtime;
817 filetime = ingres_date_and_time(ftime);
818## retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
819## where tblstats.table = "services"
820 if (flag1 < 0) {
821 fprintf(stderr, "File service.db does not need to be rebuilt.\n");
822 return(0);
823 }
824 }
825
f575c498 826 sprintf(outft, "%s~", outf);
827 out = fopen(outft, "w");
dfb56d6b 828 if (!out) {
829 perror("cannot open service.db for write");
f575c498 830 exit(SMS_OCONFIG);
dfb56d6b 831 }
832
833 fprintf(stderr, "Building service.db\n");
834
835## range of s is services
836## retrieve (service = s.name, protocol = lowercase(s.#protocol),
837## port = s.#port) {
bd8a14a5 838 strtrim(service);
839 strtrim(protocol);
dfb56d6b 840 fprintf(out, "%s.service\tHS UNSPECA \"%s %s %d\"\n",
841 service, service, protocol, port);
842## }
843
f575c498 844## range of a is alias
845## retrieve (service = a.name, altserv = a.trans) where a.type = "SERVICE" {
bd8a14a5 846 strtrim(service);
847 strtrim(altserv);
f575c498 848 fprintf(out, "%s.service\tHS CNAME %s.service\n", service, altserv);
849## }
850
dfb56d6b 851 if (fclose(out)) {
852 fprintf(stderr, "Unsuccessful close of service.db\n");
f575c498 853 exit(SMS_CCONFIG);
dfb56d6b 854 }
f575c498 855 fix_file(outf);
dfb56d6b 856 return(1);
857##}
This page took 0.205509 seconds and 5 git commands to generate.