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