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