]> andersk Git - moira.git/blobdiff - gen/hesiod.qc
added palladium
[moira.git] / gen / hesiod.qc
index 4f0fb7f1abcd8afa63ad34c33b1f348fa930c6dd..9e202241ec21e7fe1f278405bbb2d0d33dc755b5 100644 (file)
@@ -3,8 +3,13 @@
  * 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
+ *  <mit-copyright.h>.
  */
 
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <sms.h>
 #include <sms_app.h>
@@ -48,14 +53,16 @@ char **argv;
     }
 
     IIseterr(ingerr);
+    initialize_sms_error_table ();
 
 ##  ingres sms
+##  set lockmode session where level = table
 
     changed = do_passwd();
-    changed += do_pobox();
     changed += do_filsys();
     changed += do_cluster();
-    changed += do_printers();
+    changed += do_printcap();
+    changed += do_palladium();
     changed += do_sloc();
     changed += do_service();
     changed += do_groups();
@@ -122,25 +129,30 @@ get_mach()
 
 do_passwd()
 ##{
-    FILE *pout, *uout;
-    char poutf[64], uoutf[64], poutft[64], uoutft[64];
-    struct stat psb, usb;
+    FILE *pout, *uout, *bout;
+    char poutf[64], uoutf[64], poutft[64], uoutft[64], boutf[64], boutft[64];
+    struct stat psb, usb, bsb;
     time_t ftime;
     struct user *u;
+    char *mach;
 ##  char login[9], shell[33], fullname[33], oa[17], op[13], hp[17], *filetime;
-##  char nn[17];
-##  int uid, flagid;
+##  char nn[17], ptype[9];
+##  int uid, flag1, flag2, id, pid;
 
     sprintf(poutf, "%s/passwd.db", HESIOD_DIR);
     sprintf(uoutf, "%s/uid.db", HESIOD_DIR);
+    sprintf(boutf, "%s/pobox.db", HESIOD_DIR);
 
-    if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0) {
-       ftime = min(psb.st_mtime, usb.st_mtime);
+    if (stat(poutf, &psb) == 0 && stat(uoutf, &usb) == 0 &&
+       stat(boutf, &bsb) == 0) {
+       ftime = min(min(psb.st_mtime, usb.st_mtime), bsb.st_mtime);
        filetime = ingres_date_and_time(ftime);
-##     retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
+##     retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
 ##         where tblstats.table = "users"
-       if (flag < 0) {
-           fprintf(stderr, "Files passwd.db and uid.db do not need to be rebuilt.\n");
+##     retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
+##         where tblstats.table = "machine"
+       if (flag1 < 0 && flag2 < 0) {
+           fprintf(stderr, "Files passwd.db, uid.db, and pobox.db do not need to be rebuilt.\n");
            return(0);
       }
     }
@@ -157,14 +169,22 @@ do_passwd()
        perror("cannot open uid.db~ for write");
        exit(SMS_OCONFIG);
     }
+    sprintf(boutft, "%s~", boutf);
+    bout = fopen(boutft, "w");
+    if (!bout) {
+       perror("cannot open pobox.db for write");
+       exit(SMS_OCONFIG);
+    }
 
-    fprintf(stderr, "Building passwd.db and uid.db\n");
+    fprintf(stderr, "Building passwd.db, uid.db, and pobox.db\n");
+    get_mach();
 
     users = create_hash(10000);
 ##  range of u is users
 ##  retrieve (login = u.#login, uid = u.#uid, shell = u.#shell,
 ##           fullname = u.#fullname, nn = u.nickname, oa = u.office_addr,
-##           op = u.office_phone, hp = u.home_phone, id = u.users_id)
+##           op = u.office_phone, hp = u.home_phone, id = u.users_id,
+##           pid = u.pop_id, ptype = u.potype)
 ##     where u.status = 1 {
            strtrim(login);
            dequote(fullname);
@@ -180,66 +200,19 @@ do_passwd()
            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);
+           if (ptype[0] == 'P' && (mach = hash_lookup(machines, pid))) {
+               fprintf(bout, "%s.pobox\tHS UNSPECA \"POP %s %s\"\n",
+                       login, mach, login);
+           }
 ##  }
 
-    if (fclose(pout) || fclose(uout)) {
-       fprintf(stderr, "Unsuccessful file close of passwd.db or uid.db\n");
+    if (fclose(pout) || fclose(uout) || fclose(bout)) {
+       fprintf(stderr, "Unsuccessful file close of passwd.db, uid.db, or pobox.db\n");
        exit(SMS_CCONFIG);
     }
     fix_file(poutf);
     fix_file(uoutf);
-    return(1);
-##}
-
-
-do_pobox()
-##{
-    FILE *out;
-    char outf[64], outft[64], *mach;
-    struct stat sb;
-    time_t ftime;
-##  char login[9], *filetime;
-##  int flag1, flag2, id;
-
-    sprintf(outf, "%s/pobox.db", HESIOD_DIR);
-
-    if (stat(outf, &sb) == 0) {
-       ftime = sb.st_mtime;
-       filetime = ingres_date_and_time(ftime);
-##     retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
-##         where tblstats.table = "users"
-##     retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
-##         where tblstats.table = "machine"
-       if (flag1 < 0 && flag2 < 0) {
-           fprintf(stderr,"File pobox.db does not need to be rebuilt.\n");
-           return(0);
-      }
-    }
-
-    sprintf(outft, "%s~", outf);
-    out = fopen(outft, "w");
-    if (!out) {
-       perror("cannot open pobox.db for write");
-       exit(SMS_OCONFIG);
-    }
-
-    fprintf(stderr, "Building pobox.db\n");
-    get_mach();
-
-##  range of u is users
-##  retrieve (login = u.#login, id = u.pop_id)
-##     where u.status = 1 and u.potype = "POP" {
-           strtrim(login);
-           if (mach = hash_lookup(machines, id))
-             fprintf(out, "%s.pobox\tHS UNSPECA \"POP %s %s\"\n",
-                     login, mach, login);
-##  }
-
-    if (fclose(out)) {
-       fprintf(stderr, "Unsuccessful close of pobox.db\n");
-       exit(SMS_CCONFIG);
-    }
-    fix_file(outf);
+    fix_file(boutf);
     return(1);
 ##}
 
@@ -253,7 +226,7 @@ do_pobox()
 do_groups()
 ##{
     FILE *iout, *gout, *lout;
-    char ioutf[64], goutf[64], loutf[64], buf[512], *l;
+    char ioutf[64], goutf[64], loutf[64], buf[2048], *l;
     struct hash *groups;
     register struct bucket *b, **p;
     struct grp *g;
@@ -279,7 +252,7 @@ do_groups()
 ##     retrieve (flag2 = int4(interval("min", tblstats.modtime - filetime)))
 ##         where tblstats.table = "list"
 ##     retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
-##         where tblstats.table = "members"
+##         where tblstats.table = "imembers"
        if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
            fprintf(stderr, "Files gid.db, group.db and grplist.db do not need to be rebuilt.\n");
            return(0);
@@ -312,7 +285,12 @@ do_groups()
 
     /* retrieve simple groups */
 ##  range of l is list
+##  range of m is imembers
 ##  begin transaction
+    /* get lock records */
+##  retrieve (name = l.modtime) where l.list_id = 0
+##  retrieve (name = users.modtime) where users.users_id = 0
+
 ##  retrieve (name = l.#name, gid = l.#gid, lid = l.list_id)
 ##     where l.group != 0 and l.active != 0 {
            strtrim(name);
@@ -326,41 +304,6 @@ do_groups()
     fflush(iout);
     fflush(gout);
 
-    /* get special cases: lists that aren't groups themselves but are
-     * members of groups. */
-    sq = sq_create();
-##  range of m is members
-##  retrieve (name = list.#name, gid = list.#gid, lid = l.list_id)
-##     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);
-       if (l = hash_lookup(groups, lid)) {
-           sprintf(buf, "%s:%s:%d", l, name, gid);
-           free(l);
-       } else {
-           sprintf(buf, "%s:%d", name, gid);
-       }
-       hash_store(groups, lid, strsave(buf));
-       sq_save_unique_data(sq, lid);
-##  }
-
-    while (sq_get_data(sq, &id)) {
-##     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", l, hash_lookup(groups, id));
-               free(l);
-               l = strsave(buf);
-           } else {
-               l = hash_lookup(groups, id);
-           }
-           hash_store(groups, lid, l);
-           sq_save_unique_data(sq, lid);
-##     }
-    }
-    sq_destroy(sq);
-
     /* now do grplists */
     if (users == NULL) {
        users = create_hash(10000);
@@ -398,11 +341,8 @@ do_groups()
                    strcat(buf, ":");
              }
            strcat(buf, "\"\n");
-           /* Do duplicate detection here */
-           if (i > 1) {
-               remove_duplicate_groups(buf);
-           }
-           fputs(buf, lout);
+           if (i > 0)
+               fputs(buf, lout);
        }
     }
 
@@ -432,49 +372,18 @@ 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, machbuf[128];
+    char outf[64], outft[64], *mach, machbuf[128], *group;
     register char *p;
     struct stat sb;
     time_t ftime;
-##  char name[33], type[9], loc[33], access[2], mount[33], trans[257];
+    struct save_queue *sq, *sq_create();
+##  char name[33], type[9], loc[81], access[2], mount[33], trans[257];
 ##  char *filetime, comments[65];
-##  int flag1, flag2, flag3, id;
+##  int flag1, flag2, flag3, flag4, id, fid;
+    char *index();
 
     sprintf(outf, "%s/filsys.db", HESIOD_DIR);
 
@@ -487,7 +396,9 @@ do_filsys()
 ##         where tblstats.table = "machine"
 ##     retrieve (flag3 = int4(interval("min", tblstats.modtime - filetime)))
 ##         where tblstats.table = "alias"
-       if (flag1 < 0 && flag2 < 0 && flag3 < 0) {
+##     retrieve (flag4 = int4(interval("min", tblstats.modtime - filetime)))
+##         where tblstats.table = "fsgroup"
+       if (flag1 < 0 && flag2 < 0 && flag3 < 0 && flag4 < 0) {
            fprintf(stderr, "File filsys.db does not need to be rebuilt.\n");
            return(0);
       }
@@ -502,13 +413,15 @@ do_filsys()
 
     fprintf(stderr, "Building filsys.db\n");
     get_mach();
+    sq = sq_create();
 
 ##  range of f is filesys
 ##  retrieve (name = f.label, type = f.#type, loc = f.#name, id = f.mach_id,
-##           access = f.#access, mount = f.#mount, comments = f.#comments) {
+##           access = f.#access, mount = f.#mount, comments = f.#comments,
+##           fid = f.filsys_id) {
            strtrim(name);
            strtrim(type);
-           if (strcmp(type, "ERR")) {
+           if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
                strtrim(loc);
                strtrim(access);
                strtrim(mount);
@@ -523,14 +436,62 @@ do_filsys()
                    fprintf(out, "%s.filsys\tHS UNSPECA \"%s %s %s %s %s\"\n",
                            name, type, loc, machbuf, access, mount);
                }
-           } else {
+           } else if (!strcmp(type, "AFS")) {
+               strtrim(loc);
+               strtrim(access);
+               strtrim(mount);
+               fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
+                       name, loc, access, mount);
+           } else if (!strcmp(type, "ERR")) {
                strtrim(comments);
                fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
                        name, comments);
+           } else if (!strcmp(type, "FSGROUP")) {
+               sprintf(trans, "%s:%d", name, fid);
+               sq_save_data(sq, strsave(trans));
            }
 ##  }
 
-
+##  range of g is fsgroup
+    while (sq_get_data(sq, &group)) {
+       fid = atoi(index(group, ':')+1);
+       *index(group, ':') = 0;
+##      retrieve (type = f.#type, loc = f.#name, id = f.mach_id,
+##               access = f.#access, mount = f.#mount, comments = f.#comments,
+##               name = f.#label, trans = g.#key)
+##           where f.filsys_id = g.filsys_id and g.group_id = fid
+##           sort by #trans, #name {
+           strtrim(type);
+           if (!strcmp(type, "NFS") || !strcmp(type, "RVD")) {
+               strtrim(loc);
+               strtrim(access);
+               strtrim(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",
+                           group, type, loc, machbuf, access, mount);
+               }
+           } else if (!strcmp(type, "AFS")) {
+               strtrim(loc);
+               strtrim(access);
+               strtrim(mount);
+               fprintf(out, "%s.filsys\tHS UNSPECA \"AFS %s %s %s\"\n",
+                       group, loc, access, mount);
+           } else if (!strcmp(type, "ERR")) {
+               strtrim(comments);
+               fprintf(out, "%s.filsys\tHS UNSPECA \"ERR %s\"\n",
+                       group, comments);
+           }
+##     }
+       free(group);
+    }
+    sq_destroy(sq);
 
 ##  range of a is alias
 ##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "FILESYS" {
@@ -609,9 +570,11 @@ do_cluster()
 ##  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));
 
@@ -686,7 +649,7 @@ do_cluster()
 ##}
 
 
-do_printers()
+do_printcap()
 ##{
     FILE *out;
     char outf[64], outft[64];
@@ -737,6 +700,64 @@ do_printers()
 ##}
 
 
+do_palladium()
+##{
+    FILE *out;
+    char outf[64], outft[64];
+    struct stat sb;
+    time_t ftime;
+##  char name[33], rm[33], trans[129], *filetime;
+##  int flag, flag1, ident;
+
+    sprintf(outf, "%s/palladium.db", HESIOD_DIR);
+
+    if (stat(outf, &sb) == 0) {
+       ftime = sb.st_mtime;
+       filetime = ingres_date_and_time(ftime);
+##     retrieve (flag = int4(interval("min", tblstats.modtime - filetime)))
+##         where tblstats.table = "palladium"
+##     retrieve (flag1 = int4(interval("min", tblstats.modtime - filetime)))
+##         where tblstats.table = "alias"
+       if (flag < 0 && flag1 < 0) {
+           fprintf(stderr, "File palladium.db does not need to be rebuilt.\n");
+           return(0);
+      }
+    }
+
+    sprintf(outft, "%s~", outf);
+    out = fopen(outft, "w");
+    if (!out) {
+       perror("cannot open palladium.db for write");
+       exit(SMS_OCONFIG);
+    }
+
+    fprintf(stderr, "Building palladium.db\n");
+
+##  range of p is palladium
+##  retrieve (name = p.#name, ident = p.#ident, rm = machine.#name)
+##    where machine.mach_id = p.mach_id {
+       strtrim(name);
+       strtrim(rm);
+       fprintf(out,
+               "%s.palladium\tHS UNSPECA \"%s %d %s interface directory\"\n",
+               name, rm, ident, name);
+##  }
+##  range of a is alias
+##  retrieve (name = a.#name, trans = a.#trans) where a.#type = "PALLADIUM" {
+       strtrim(name);
+       strtrim(trans);
+       fprintf(out, "%s.palladium\tHS UNSPECA \"%s\"\n", name, trans);
+##  }
+
+    if (fclose(out)) {
+       fprintf(stderr, "Unsuccessful close of palladium.db\n");
+       exit(SMS_CCONFIG);
+    }
+    fix_file(outf);
+    return(1);
+##}
+
+
 do_sloc()
 ##{
     FILE *out, *old, *new;
This page took 0.073525 seconds and 4 git commands to generate.