]> andersk Git - moira.git/blobdiff - gen/hesiod.qc
make sure we clear sms_errcode between queries
[moira.git] / gen / hesiod.qc
index 7b0208c88c2b792fd415bf7b8a80a4d49089d258..7726e1cd5e64143038f2b0ee7edbec99a4f6c176 100644 (file)
@@ -19,7 +19,7 @@
 #include <ctype.h>
 
 
-#define HESIOD_DIR     "/u1/sms/dcm/hesiod"
+char hesiod_dir[64];
 
 #define min(x,y)       ((x) < (y) ? (x) : (y))
 struct hash *machines = NULL;
@@ -53,6 +53,8 @@ char **argv;
     }
 
     IIseterr(ingerr);
+    initialize_sms_error_table ();
+    sprintf(hesiod_dir, "%s/hesiod", DCM_DIR);
 
 ##  ingres sms
 ##  set lockmode session where level = table
@@ -60,7 +62,8 @@ char **argv;
     changed = do_passwd();
     changed += do_filsys();
     changed += do_cluster();
-    changed += do_printers();
+    changed += do_printcap();
+    changed += do_palladium();
     changed += do_sloc();
     changed += do_service();
     changed += do_groups();
@@ -75,7 +78,7 @@ char **argv;
 
     if (argc == 2) {
        fprintf(stderr, "Building tar file.\n");
-       sprintf(cmd, "cd %s; tar cf %s .", HESIOD_DIR, argv[1]);
+       sprintf(cmd, "cd %s; tar cf %s .", hesiod_dir, argv[1]);
        if (system(cmd))
          exit(SMS_TAR_FAIL);
     }
@@ -137,9 +140,9 @@ do_passwd()
 ##  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);
+    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 &&
        stat(boutf, &bsb) == 0) {
@@ -238,9 +241,9 @@ do_groups()
 ##  int gid, id, lid, flag1, flag2, flag3, maxid;
 
     /* open files */
-    sprintf(ioutf, "%s/gid.db", HESIOD_DIR);
-    sprintf(goutf, "%s/group.db", HESIOD_DIR);
-    sprintf(loutf, "%s/grplist.db", HESIOD_DIR);
+    sprintf(ioutf, "%s/gid.db", hesiod_dir);
+    sprintf(goutf, "%s/group.db", hesiod_dir);
+    sprintf(loutf, "%s/grplist.db", hesiod_dir);
 
     if (stat(ioutf, &isb) == 0 && stat(goutf, &gsb) == 0 && stat(loutf, &lsb) == 0) {
        ftime = min(isb.st_mtime, min(gsb.st_mtime, lsb.st_mtime));
@@ -250,7 +253,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);
@@ -283,6 +286,7 @@ 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
@@ -301,41 +305,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);
@@ -373,10 +342,6 @@ do_groups()
                    strcat(buf, ":");
              }
            strcat(buf, "\"\n");
-           /* Do duplicate detection here */
-           if (i > 1) {
-               remove_duplicate_groups(buf);
-           }
            if (i > 0)
                fputs(buf, lout);
        }
@@ -408,39 +373,6 @@ 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;
@@ -449,11 +381,12 @@ do_filsys()
     struct stat sb;
     time_t ftime;
     struct save_queue *sq, *sq_create();
-##  char name[33], type[9], loc[33], access[2], mount[33], trans[257];
+##  char name[33], type[9], loc[81], access[2], mount[33], trans[257];
 ##  char *filetime, comments[65];
 ##  int flag1, flag2, flag3, flag4, id, fid;
+    char *index();
 
-    sprintf(outf, "%s/filsys.db", HESIOD_DIR);
+    sprintf(outf, "%s/filsys.db", hesiod_dir);
 
     if (stat(outf, &sb) == 0) {
        ftime = sb.st_mtime;
@@ -606,7 +539,7 @@ do_cluster()
 ##  char name[33], label[17], data[33], *filetime;
     set_mask **machs, *ms, *ps;
 
-    sprintf(outf, "%s/cluster.db", HESIOD_DIR);
+    sprintf(outf, "%s/cluster.db", hesiod_dir);
 
     if (stat(outf, &sb) == 0) {
        ftime = sb.st_mtime;
@@ -717,7 +650,7 @@ do_cluster()
 ##}
 
 
-do_printers()
+do_printcap()
 ##{
     FILE *out;
     char outf[64], outft[64];
@@ -726,7 +659,7 @@ do_printers()
 ##  char name[17], rp[17], sd[33], rm[33], *filetime;
 ##  int flag;
 
-    sprintf(outf, "%s/printcap.db", HESIOD_DIR);
+    sprintf(outf, "%s/printcap.db", hesiod_dir);
 
     if (stat(outf, &sb) == 0) {
        ftime = sb.st_mtime;
@@ -768,6 +701,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;
@@ -778,7 +769,7 @@ do_sloc()
 ##  char service[17], *filetime;
 ##  int port, flag1, flag2, id;
 
-    sprintf(outf, "%s/sloc.db", HESIOD_DIR);
+    sprintf(outf, "%s/sloc.db", hesiod_dir);
 
     if (stat(outf, &sb) == 0) {
        ftime = sb.st_mtime;
@@ -829,7 +820,7 @@ do_service()
 ##  char mach[33], service[33], protocol[9], altserv[129], *filetime;
 ##  int port, flag1, flag2;
 
-    sprintf(outf, "%s/service.db", HESIOD_DIR);
+    sprintf(outf, "%s/service.db", hesiod_dir);
 
     if (stat(outf, &sb) == 0) {
        ftime = sb.st_mtime;
This page took 0.060946 seconds and 4 git commands to generate.