X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/blobdiff_plain/bd8a14a59819b8ccd39dbfa8f4273f6dbe7a2fc7..05e591e391d5034ceaf49f56713db28e5c22e727:/gen/hesiod.qc diff --git a/gen/hesiod.qc b/gen/hesiod.qc index b80179ec..0c96955c 100644 --- a/gen/hesiod.qc +++ b/gen/hesiod.qc @@ -3,14 +3,20 @@ * This generates the zone files necessary to load a hesiod server. * The following zones are generated: passwd, uid, pobox, group, * grplist, gid, filsys, cluster, pcap, sloc, service. + * + * (c) Copyright 1988 by the Massachusetts Institute of Technology. + * For copying and distribution information, please see the file + * . */ +#include #include #include #include #include #include #include +#include #define HESIOD_DIR "/u1/sms/dcm/hesiod" @@ -18,6 +24,7 @@ #define min(x,y) ((x) < (y) ? (x) : (y)) struct hash *machines = NULL; struct hash *users = NULL; +char *whoami = "hesiod.gen"; struct grp { struct grp *next; @@ -38,15 +45,17 @@ char **argv; char cmd[64]; struct stat sb; int changed = 0; + int ingerr(); if (argc > 2) { fprintf(stderr, "usage: %s [outfile]\n", argv[0]); exit(SMS_ARGS); } + IIseterr(ingerr); + ## ingres sms -## begin transaction changed = do_passwd(); changed += do_pobox(); changed += do_filsys(); @@ -55,7 +64,6 @@ char **argv; changed += do_sloc(); changed += do_service(); changed += do_groups(); -## end transaction ## exit @@ -76,6 +84,32 @@ char **argv; } +/* + * ingerr: (supposedly) called when Ingres indicates an error. + * I have not yet been able to get this to work to intercept a + * database open error. + */ +#define INGRES_DEADLOCK 4700 + +static int ingerr(num) + int *num; +{ + char buf[256]; + int ingres_errno; + + switch (*num) { + case INGRES_DEADLOCK: + ingres_errno = SMS_DEADLOCK; + break; + default: + ingres_errno = SMS_INGRES_ERR; + } + com_err(whoami, SMS_INGRES_ERR, " code %d\n", *num); + critical_alert("DCM", "Hesiod build encountered INGRES ERROR %d", *num); + exit(ingres_errno); +} + + get_mach() ##{ ## int id; @@ -99,6 +133,7 @@ do_passwd() time_t ftime; struct user *u; ## char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime; +## char nn[17]; ## int uid, flag, id; sprintf(poutf, "%s/passwd.db", HESIOD_DIR); @@ -133,21 +168,22 @@ do_passwd() users = create_hash(10000); ## range of u is users ## retrieve (login = u.#login, uid = u.#uid, shell = u.#shell, -## fullname = u.#fullname, oa = u.office_addr, +## fullname = u.#fullname, nn = u.nickname, oa = u.office_addr, ## op = u.office_phone, hp = u.home_phone, id = u.users_id) ## where u.status = 1 { strtrim(login); - strtrim(fullname); - strtrim(oa); - strtrim(op); - strtrim(hp); - strtrim(shell); + dequote(fullname); + dequote(nn); + dequote(oa); + dequote(op); + dequote(hp); + dequote(shell); u = (struct user *) malloc(sizeof(struct user)); strcpy(u->name, login); u->lists = NULL; hash_store(users, id, u); - fprintf(pout, "%s.passwd\tHS UNSPECA \"%s:*:%d:101:%s,%s,%s,%s:/mit/%s:%s\"\n", - login, login, uid, fullname, oa, op, hp, login, shell); + fprintf(pout, "%s.passwd\tHS UNSPECA \"%s:*:%d:101:%s,%s,%s,%s,%s:/mit/%s:%s\"\n", + login, login, uid, fullname, nn, oa, op, hp, login, shell); fprintf(uout, "%d.uid\tHS CNAME %s.passwd\n", uid, login); ## } @@ -222,7 +258,7 @@ do_pobox() do_groups() ##{ FILE *iout, *gout, *lout; - char ioutf[64], goutf[64], loutf[64], buf[256], *l; + char ioutf[64], goutf[64], loutf[64], buf[512], *l; struct hash *groups; register struct bucket *b, **p; struct grp *g; @@ -281,6 +317,7 @@ do_groups() /* retrieve simple groups */ ## range of l is list +## begin transaction ## retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) ## where l.group != 0 and l.active != 0 { strtrim(name); @@ -299,7 +336,7 @@ do_groups() sq = sq_create(); ## range of m is members ## retrieve (name = list.#name, gid = list.#gid, lid = l.list_id) -## where l.group = 0 and l.active != 0 and m.member_type = "LIST" and +## where l.active != 0 and list.active != 0 and m.member_type = "LIST" and ## m.member_id = l.list_id and m.list_id = list.list_id and ## list.group != 0 { strtrim(name); @@ -310,21 +347,20 @@ do_groups() sprintf(buf, "%s:%d", name, gid); } hash_store(groups, lid, strsave(buf)); - sq_save_data(sq, lid); + sq_save_unique_data(sq, lid); ## } while (sq_get_data(sq, &id)) { -## repeat retrieve (name = l.#name, gid = l.#gid, lid = l.list_id) -## where l.group = 0 and m.member_type = "LIST" and -## m.member_id = l.list_id and m.list_id = @id { - strtrim(name); +## repeat retrieve (lid = l.list_id) where m.member_type = "LIST" and +## m.list_id = @id and m.member_id = l.list_id and l.active != 0 { if (l = hash_lookup(groups, lid)) { - sprintf(buf, "%s:%s:%d", l, name, gid); + sprintf(buf, "%s:%s", l, hash_lookup(groups, id)); free(l); + l = strsave(buf); } else { - sprintf(buf, "%s:%d", name, gid); + l = hash_lookup(groups, id); } - hash_store(groups, lid, strsave(buf)); + hash_store(groups, lid, l); sq_save_unique_data(sq, lid); ## } } @@ -344,22 +380,34 @@ do_groups() ## repeat retrieve (lid = m.list_id, id = m.member_id) ## where m.member_type = "USER" { - if (u = (struct user *) hash_lookup(users, id)) { + if ((u = (struct user *) hash_lookup(users, id)) && + (hash_lookup(groups, lid) != NULL)) { g = (struct grp *) malloc(sizeof(struct grp)); g->next = u->lists; u->lists = g; g->id = lid; } ## } +## end transaction for (p = &(users->data[users->size - 1]); p >= users->data; p--) { for (b = *p; b; b = b->next) { - fprintf(lout, "%s.grplist\tHS UNSPECA \"", + i = 0; + sprintf(buf, "%s.grplist\tHS UNSPECA \"", ((struct user *)b->data)->name); for (g = ((struct user *)b->data)->lists; g; g = g->next) - if (l = hash_lookup(groups, g->id)) - fprintf(lout, "%s%s", l, g->next ? ":" : ""); - fputs("\"\n", lout); + if (l = hash_lookup(groups, g->id)) { + i++; + strcat(buf, l); + if (g->next) + strcat(buf, ":"); + } + strcat(buf, "\"\n"); + /* Do duplicate detection here */ + if (i > 1) { + remove_duplicate_groups(buf); + } + fputs(buf, lout); } } @@ -389,10 +437,44 @@ do_groups() ##} +#define MAXGROUPS 256 + +remove_duplicate_groups(p) +register char *p; +{ + register char *pp; + char *index(); + register int *mp; + int memory[MAXGROUPS], i, *mg = &memory[MAXGROUPS-1]; + + bzero(memory, MAXGROUPS * sizeof(int)); + while (p = index(p, ':')) { + i = atoi(++p); + for (mp = memory; *mp && mp < mg; mp++) + if (*mp == i) { + if (p = index(p, ':')) + strcpy(pp, ++p); + else { + strcpy(--pp, "\"\n"); + } + p = pp; + break; + } + if (*mp == i) + continue; + *mp = i; + if (!(p = index(p, ':'))) + return; + pp = ++p; + } +} + + do_filsys() ##{ FILE *out; - char outf[64], outft[64], *mach; + char outf[64], outft[64], *mach, machbuf[128]; + register char *p; struct stat sb; time_t ftime; ## char name[33], type[9], loc[33], access[2], mount[33], trans[257]; @@ -435,9 +517,17 @@ do_filsys() strtrim(loc); strtrim(access); strtrim(mount); - if (mach = hash_lookup(machines, id)) - fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n", - name, type, loc, mach, access, mount); + if (mach = hash_lookup(machines, id)) { + for (p = machbuf; *mach && *mach != '.'; mach++) { + if (isupper(*mach)) + *p++ = tolower(*mach); + else + *p++ = *mach; + *p = 0; + } + fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n", + name, type, loc, machbuf, access, mount); + } } else { strtrim(comments); fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n", @@ -445,6 +535,8 @@ do_filsys() } ## } + + ## range of a is alias ## retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" { strtrim(name); @@ -483,7 +575,7 @@ typedef long set_mask; do_cluster() ##{ FILE *out; - char outf[64], outft[64], *mach; + char outf[64], outft[64], *mach, machbuf[33], *p; struct stat sb; time_t ftime; ## int flag1, flag2, flag3, flag4, maxmach, maxclu, mid, cid, id; @@ -520,10 +612,13 @@ do_cluster() get_mach(); ## range of c is cluster +## begin transaction ## retrieve (maxclu = max(c.clu_id)) + maxclu++; setsize = howmany(maxclu, NSETBITS); ## range of m is machine ## retrieve (maxmach = max(m.mach_id)) + maxmach++; machs = (set_mask **)malloc((maxmach + 1) * sizeof(set_mask **)); bzero(machs, (maxmach + 1) * sizeof(int)); @@ -554,22 +649,29 @@ do_cluster() } } - if (mach = hash_lookup(machines, mid)) - fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n", - mach, mid); + if (mach = hash_lookup(machines, mid)) { + for (p = machbuf; *mach && *mach != '.'; mach++) + *p++ = *mach; + *p = 0; + fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n", + machbuf, mid); + } for (id = mid + 1; id < maxmach; id++) { if ((ps = machs[id]) && !SET_CMP(ms, ps)) { free(ps); machs[id] = NULL; - if (mach = hash_lookup(machines, id)) - fprintf(out, "%s.cluster\tHS CNAME smsinternal-%d.cluster\n", - mach, mid); + if (mach = hash_lookup(machines, id)) { + for (p = machbuf; *mach && *mach != '.'; mach++) + *p++ = *mach; + *p = 0; + fprintf(out,"%s.cluster\tHS CNAME smsinternal-%d.cluster\n", + machbuf, mid); + } } } free(ms); machs[mid] = NULL; } - free(machs); ## retrieve (name = c.#name, label = d.serv_label, data = d.serv_cluster) ## where c.clu_id = d.clu_id { @@ -579,6 +681,8 @@ do_cluster() fprintf(out, "%s.cluster\tHS UNSPECA \"%s %s\"\n", name, label, data); ## } +## end transaction + free(machs); if (fclose(out)) { fprintf(stderr, "Unsuccessful close of cluster.db\n"); @@ -595,7 +699,7 @@ do_printers() char outf[64], outft[64]; struct stat sb; time_t ftime; -## char name[33], pcap[513], *filetime; +## char name[17], rp[17], sd[33], rm[33], *filetime; ## int flag; sprintf(outf, "%s/printcap.db", HESIOD_DIR); @@ -621,10 +725,14 @@ do_printers() fprintf(stderr, "Building printcap.db\n"); ## range of p is printcap -## retrieve (name = p.#name, pcap = p.#pcap) { +## retrieve (name = p.#name, rp = p.#rp, sd = p.dir, rm = machine.#name) +## where machine.mach_id = p.mach_id { strtrim(name); - strtrim(pcap); - fprintf(out, "%s.pcap\tHS UNSPECA \"%s\"\n", name, pcap); + strtrim(rp); + strtrim(sd); + strtrim(rm); + fprintf(out, "%s.pcap\tHS UNSPECA \"%s:rp=%s:rm=%s:sd=%s\"\n", + name, name, rp, rm, sd); ## } if (fclose(out)) {