]> andersk Git - moira.git/blobdiff - dbck/phase2.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / dbck / phase2.qc
index ac36040f832fd2375966b0f4bb36350ce7cdb6a8..9a0840d650199d2c6e76ac972fb0a4f42f8e8dc9 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <mit-copyright.h>
 #include <stdio.h>
-#include <sms.h>
+#include <moira.h>
 #include "dbck.h"
 
 static char phase2_qc_rcsid[] = "$Header$";
@@ -148,18 +148,18 @@ show_member_list(id)
 int id;
 ##{
 ##  int mid, iid = id, found = 1;
-##  char mtype[9], *name;
+##  char mtype[9], *name = "";
 
-##  retrieve (mtype = member.member_type, mid = member.member_id)
-##     where member.list_id = iid {
+##  retrieve (mtype = imembers.member_type, mid = imembers.member_id)
+##     where imembers.list_id = iid and imembers.direct = 1 {
       strtrim(mtype);
       found = 0;
       if (mtype[0] == 'L')
-       strcpy(name, ((struct list *) hash_lookup(lists, mid))->name);
+       name = ((struct list *) hash_lookup(lists, mid))->name;
       else if (mtype[0] == 'U')
-       strcpy(name, ((struct user *) hash_lookup(users, mid))->login);
-      else if (mtype[0] == 'S')
-       strcpy(name, ((struct string *) hash_lookup(strings, mid))->name);
+       name = ((struct user *) hash_lookup(users, mid))->login;
+      else if (mtype[0] == 'S' || mtype[0] == 'K')
+       name = ((struct string *) hash_lookup(strings, mid))->name;
       printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
 ##  }
     return(found);
@@ -171,8 +171,9 @@ int id;
 ##  int lid, iid = id, found = 1;
 ##  char name[33];
 
-##  retrieve (lid = members.list_id)
-##     where members.member_id = iid and members.member_type = "USER" {
+##  retrieve (lid = imembers.list_id)
+##     where imembers.member_id = iid and imembers.member_type = "USER" and
+##           imembers.direct = 1 {
       found = 0;
       printf("List %s has non-existant user member, id %d\n",
             ((struct list *)hash_lookup(lists, lid))->name, iid);
@@ -186,8 +187,9 @@ int id;
 ##  int lid, iid = id, found = 1;
 ##  char name[33];
 
-##  retrieve (lid = members.list_id)
-##     where members.member_id = iid and members.member_type = "LIST" {
+##  retrieve (lid = imembers.list_id)
+##     where imembers.member_id = iid and imembers.member_type = "LIST" and
+##           imembers.direct = 1 {
       found = 0;
       printf("List %s has non-existant list member, id %d\n",
             ((struct list *)hash_lookup(lists, lid))->name, iid);
@@ -201,8 +203,9 @@ int id;
 ##  int lid, iid = id, found = 1;
 ##  char name[33];
 
-##  retrieve (lid = members.list_id)
-##     where members.member_id = iid and members.member_type = "STRING" {
+##  retrieve (lid = imembers.list_id)
+##     where imembers.member_id = iid and imembers.member_type = "STRING" and
+##           imembers.direct = 1 {
       found = 0;
       printf("List %s has non-existant string member, id %d\n",
             ((struct list *)hash_lookup(lists, lid))->name, iid);
@@ -211,19 +214,36 @@ int id;
 ##}
 
 
+show_mem_krb(id)
+int id;
+##{
+##  int lid, iid = id, found = 1;
+##  char name[33];
+
+##  retrieve (lid = imembers.list_id)
+##     where imembers.member_id = iid and imembers.member_type = "KERBEROS" and
+##           imembers.direct = 1 {
+      found = 0;
+      printf("List %s has non-existant kerberos member, id %d\n",
+            ((struct list *)hash_lookup(lists, lid))->name, iid);
+##  }
+    return(found);
+##}
+
+
 ##del_mem_user(id)
 ##int id;
 ##{
 ##  int rowcount;
 
-##  delete members where members.member_type = "USER" and
-##     members.member_id = id
+##  delete imembers where imembers.member_type = "USER" and
+##     imembers.member_id = id and imembers.direct = 1
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
-    modified("members");
+    modified("imembers");
 ##}
 
 ##del_mem_list(id)
@@ -231,14 +251,14 @@ int id;
 ##{
 ##  int rowcount;
 
-##  delete members where members.member_type = "LIST" and
-##     members.member_id = id
+##  delete imembers where imembers.member_type = "LIST" and
+##     imembers.member_id = id and imembers.direct = 1
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
-    modified("members");
+    modified("imembers");
 ##}
 
 ##del_mem_str(id)
@@ -246,14 +266,30 @@ int id;
 ##{
 ##  int rowcount;
 
-##  delete members where members.member_type = "STRING" and
-##     members.member_id = id
+##  delete imembers where imembers.member_type = "STRING" and
+##     imembers.member_id = id and imembers.direct = 1
+##  inquire_equel(rowcount = "rowcount");
+    if (rowcount > 0)
+      printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
+    else
+      printf("Not deleted\n");
+    modified("imembers");
+##}
+
+
+##del_mem_krb(id)
+##int id;
+##{
+##  int rowcount;
+
+##  delete imembers where imembers.member_type = "KERBEROS" and
+##     imembers.member_id = id and imembers.direct = 1
 ##  inquire_equel(rowcount = "rowcount");
     if (rowcount > 0)
       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
     else
       printf("Not deleted\n");
-    modified("members");
+    modified("imembers");
 ##}
 
 
@@ -312,33 +348,32 @@ int hint;
     struct nfsphys *n;
     struct machine *m;
 
-    if (f->type == 'N' || f->type == 'R') {
-       if (!hash_lookup(machines, f->mach_id)) {
-           printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
-           if (single_fix("Fix", 0)) {
-##             replace filesys (mach_id = 0) where filesys.filsys_id = id
-##             inquire_equel(rowcount = "rowcount")
-               if (rowcount > 0)
-                 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
-               else
-                 printf("Not fixed\n");
-               modified("filesys");
-               f->mach_id = 0;
-           }
+    if (!hash_lookup(machines, f->mach_id)) {
+       printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
+       if (single_fix("Fix", 0)) {
+##         replace filesys (mach_id = 0) where filesys.filsys_id = id
+##         inquire_equel(rowcount = "rowcount")
+           if (rowcount > 0)
+             printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
+           else
+             printf("Not fixed\n");
+           modified("filesys");
+           f->mach_id = 0;
        }
-       if (!hash_lookup(users, f->owner)) {
-           printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
-           if (single_fix("Fix", 1)) {
-               zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
-               f->owner = 0;
-           }
+    }
+
+    if (!hash_lookup(users, f->owner)) {
+       printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
+       if (single_fix("Fix", 1)) {
+           zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
+           f->owner = 0;
        }
-       if (!hash_lookup(lists, f->owners)) {
-           printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
-           if (single_fix("Fix", 1)) {
-               zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
-               f->owners = 0;
-           }
+    }
+    if (!hash_lookup(lists, f->owners)) {
+       printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
+       if (single_fix("Fix", 1)) {
+           zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
+           f->owners = 0;
        }
     }
 
@@ -368,7 +403,7 @@ int hint;
                        id2 = f->filsys_id;
                        id3 = f->mach_id;
                        if (set_next_object_id("nfsphys_id", "nfsphys") !=
-                               SMS_SUCCESS) {
+                               MR_SUCCESS) {
                            printf("Unable to assign unique ID\n");
                            return;
                        }
@@ -392,6 +427,8 @@ int hint;
                          printf("Not created\n");
                        modified("nfsphys");
                        n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
+                       if (n == NULL)
+                         out_of_mem("storing new nfsphys");
                        strcpy(n->dir, dir);
                        n->mach_id = id3;
                        n->nfsphys_id = id1;
@@ -428,55 +465,172 @@ int hint;
     }
 }
 
-##show_quota_nouser(id)
+##show_fsg_missing(id)
 ##int id;
 ##{
 ##  int id1, found = 1;
+    struct filesys *f;
 
-##  retrieve (id1 = nfsquota.filsys_id) where nfsquota.users_id = id {
+##  retrieve (id1 = fsgroup.filsys_id) where fsgroup.group_id = id {
       found = 0;
-      printf("NFSquota on fs %d for non-existant user %d\n", id1, id);
+      if (f = (struct filesys *) hash_lookup(filesys, id1))
+       printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
+      else
+       printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
 ##  }
     return(found);
 ##}
 
-fix_quota_nouser(id)
+show_fsg_type(f)
+struct filesys *f;
 {
-    single_delete("nfsquota", "users_id", id);
+    char *t;
+
+    switch (f->type) {
+    case 'N':
+       t = "NFS";
+       break;
+    case 'R':
+       t = "RVD";
+       break;
+    case 'A':
+       t = "AFS";
+       break;
+    case 'E':
+       t = "ERR";
+       break;
+    case 'F':
+       t = "FSGROUP";
+       break;
+    case 'M':
+       t = "MUL";
+       break;
+    default:
+       t = "???";
+    }
+    printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
+    return(0);
 }
 
+fix_fsg_type(f)
+struct filesys *f;
+##{
+##  int rowcount, id = f->filsys_id;
+
+##  replace filesys (type = "FSGROUP") where filesys.filsys_id = id
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount > 0)
+      printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
+    else
+      printf("Not fixed\n");
+    modified("filesys");
+##}
+
+##show_fsg_nomember(id)
+##int id;
+##{
+##  int id1, found = 1;
+    struct filesys *f;
+
+##  retrieve (id1 = fsgroup.group_id) where fsgroup.filsys_id = id {
+      found = 0;
+      if (f = (struct filesys *) hash_lookup(filesys, id1))
+       printf("FSGroup %s has missing member %d\n", f->name, id);
+      else
+       printf("FSGroup %d has missing member %d\n", id1, id);
+##  }
+    return(found);
+##}
+
+##show_quota_nouser(id)
+##int id;
+##{
+##  int id1, found = 1;
+
+##  retrieve (id1 = quota.filsys_id) where quota.entity_id = id and
+##     quota.type = "USER" {
+      found = 0;
+      printf("Quota on fs %d for non-existant user %d\n", id1, id);
+##  }
+    return(found);
+##}
+
+##show_quota_nolist(id)
+##int id;
+##{
+##  int id1, found = 1;
+
+##  retrieve (id1 = quota.filsys_id) where quota.entity_id = id and
+##     quota.type = "GROUP" {
+      found = 0;
+      printf("Quota on fs %d for non-existant list %d\n", id1, id);
+##  }
+    return(found);
+##}
+
+##fix_quota_nouser(id)
+##int id;
+##{
+##  int rowcount, id1;
+
+    id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
+##  delete quota where quota.entity_id = id and quota.type = "USER"
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount > 0)
+      printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
+    else
+      printf("Not deleted\n");
+    modified("quota");
+##}
+
+##fix_quota_nolist(id)
+##int id;
+##{
+##  int rowcount, id1;
+
+    id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
+##  delete quota where quota.entity_id = id and quota.type = "GROUP"
+##  inquire_equel(rowcount = "rowcount")
+    if (rowcount > 0)
+      printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
+    else
+      printf("Not deleted\n");
+    modified("quota");
+##}
+
 ##show_quota_nofs(id)
 ##int id;
 ##{
 ##  int id1, found = 1;
-    struct user *u;
+##  char type[9];
 
-##  retrieve (id1 = nfsquota.users_id) where nfsquota.filsys_id = id {
-      u = (struct user *)hash_lookup(users, id1);
+##  retrieve (id1 = quota.entity_id, type = quota.#type)
+##     where quota.filsys_id = id {
       found = 0;
-      printf("NFSquota for user %s on non-existant filesys %d\n", u->login, id);
+      printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
 ##  }
     return(found);
 ##}
 
 fix_quota_nofs(id)
 {
-    single_delete("nfsquota", "filsys_id", id);
+    single_delete("quota", "filsys_id", id);
 }
 
 ##show_quota_wrongpid(id)
 ##int id;
 ##{
 ##  int id1, found = 1;
+##  char type[9];
     struct user *u;
     struct filesys *f;
 
     f = (struct filesys *)hash_lookup(filesys, id);
-##  retrieve (id1 = nfsquota.users_id) where nfsquota.filsys_id = id {
-      u = (struct user *)hash_lookup(users, id1);
+##  retrieve (id1 = quota.entity_id, type = quota.#type)
+##     where quota.filsys_id = id {
       found = 0;
-      printf("NFSquota for user %s on filesys %s has wrong phys_id %d\n",
-            u->login, f->name, id);
+      printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
+            type, id1, f->name, id);
 ##  }
     return(found);
 ##}
@@ -487,14 +641,14 @@ fix_quota_nofs(id)
 ##  int rowcount, id1;
 
     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
-##  replace nfsquota (phys_id = id1) where nfsquota.filsys_id = id and
-##     nfsquota.phys_id != id1 
+##  replace quota (phys_id = id1) where quota.filsys_id = id and
+##     quota.phys_id != id1    
 ##  inquire_equel(rowcount = "rowcount")
     if (rowcount > 0)
       printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
     else
       printf("Not fixed\n");
-    modified("nfsquota");
+    modified("quota");
 ##}
 
 ##show_srv_user(id)
@@ -556,12 +710,67 @@ fix_quota_nofs(id)
 ##}
 
 
+##show_krb_usr(id)
+##int id;
+##{
+##  int found = 1, id1;
+    struct string *s;
+    char *ss;
+
+##  retrieve (id1 = krbmap.string_id) where krbmap.users_id = id {
+       if (s = ((struct string *)hash_lookup(strings, id1)))
+         ss = s->name;
+       else
+         ss = "[unknown]";
+       found = 0;
+       printf("Kerberos map for non-existant user %d to principal %s\n",
+              id, s);
+##  }
+    return(found);
+##}
+
+
+##show_krb_str(id)
+##int id;
+##{
+##  int found = 1, id1;
+    struct user *u;
+    char *s;
+
+##  retrieve (id1 = krbmap.users_id) where krbmap.string_id = id {
+       if (u = ((struct user *)hash_lookup(users, id1)))
+         s = u->login;
+       else
+         s = "[???]";
+       found = 0;
+       printf("Kerberos map for user %s (%d) to non-existant string %d\n",
+              s, id1, id);
+##  }
+    return(found);
+##}
+
+
+##show_pdm_mach(id)
+##int id;
+##{
+##  char name[33];
+    int found = 1;
+
+##  retrieve (name = palladium.#name) where palladium.mach_id = id {
+       strtrim(name);
+        printf("Palladium server/supervisor %s is on non-existant machine %d\n",
+              name, id);
+       found = 0;
+##  }
+    return(found);
+##}
+
 
 phase2()
 ##{
 ##  int id1, id2, id3, id4, id5;
 ##  char type[9], name[33];
-    struct save_queue *sq, *sq1, *sq2, *sq3, *sq4;
+    struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
     struct filesys *f;
     struct list *l;
     struct nfsphys *n;
@@ -580,7 +789,7 @@ phase2()
          sq_save_unique_data(sq1, id1);
        if (!hash_lookup(clusters, id2))
          sq_save_unique_data(sq2, id2);
-       m->clucount++;
+       if (m) m->clucount++;
 ##  }
     generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
     generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
@@ -601,23 +810,28 @@ phase2()
     sq2 = sq_create();
     sq3 = sq_create();
     sq4 = sq_create();
-##  range of m is members
-##  retrieve (id1 = m.list_id, type = m.member_type, id2 = m.member_id) {
-       strtrim(type);
+    sq5 = sq_create();
+##  range of m is imembers
+##  retrieve (id1 = m.list_id, type = m.member_type, id2 = m.member_id,
+##           id3 = m.ref_count, id4 = m.direct) {
        if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
          sq_save_unique_data(sq1, id1);
-       l->members++;
-       if (!strcmp(type, "USER") && !hash_lookup(users, id2))
+       else if (type[0] == 'U' && !hash_lookup(users, id2))
          sq_save_unique_data(sq2, id2);
-       else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2))
+       else if (type[0] == 'L' && !hash_lookup(lists, id2))
          sq_save_unique_data(sq3, id2);
-       else if (!strcmp(type, "STRING") && !string_check(id2))
+       else if (type[0] == 'S' && !string_check(id2))
          sq_save_unique_data(sq4, id2);
+       else if (type[0] == 'K' && !string_check(id2))
+         sq_save_unique_data(sq5, id2);
+       else
+         l->members++;
 ##  }
-    generic_delete(sq1, show_member_list, "members", "list_id", 1);
+    generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
     generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
     generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
     generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
+    generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
 
     dprintf("Checking servers...\n");
     sq1 = sq_create();
@@ -648,14 +862,30 @@ phase2()
     dprintf("Checking filesys...\n");
     hash_step(filesys, check_fs, NULL);
 
-    dprintf("Checking nfsquota...\n");
+    dprintf("Checking filesystem groups...\n");
     sq1 = sq_create();
     sq2 = sq_create();
     sq3 = sq_create();
-##  retrieve (id1 = nfsquota.users_id, id2 = nfsquota.filsys_id,
-##           id3 = nfsquota.phys_id, id4 = nfsquota.quota) {
-       if (!hash_lookup(users, id1))
+##  retrieve (id1 = fsgroup.group_id, id2 = fsgroup.filsys_id) {
+       if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
          sq_save_data(sq1, id1);
+       if (!hash_lookup(filesys, id2))
+         sq_save_data(sq3, id2);
+##  }
+    generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
+    generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
+
+    dprintf("Checking quotas...\n");
+    sq1 = sq_create();
+    sq2 = sq_create();
+    sq3 = sq_create();
+    sq4 = sq_create();
+##  retrieve (id1 = quota.entity_id, type = quota.#type, id2 = quota.filsys_id,
+##           id3 = quota.phys_id, id4 = quota.quota) {
+       if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
+         sq_save_data(sq1, id1);
+       else if (type[0] == 'G' && !hash_lookup(lists, id1))
+         sq_save_data(sq4, id1);
        else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
          sq_save_data(sq2, id2);
        else if (id3 != f->phys_id ||
@@ -668,6 +898,7 @@ phase2()
     generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
     generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
     generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
+    generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
 
     dprintf("Not checking zephyr.\n");
 
@@ -688,6 +919,29 @@ phase2()
        }
 ##  }
 
+    dprintf("Checking palladium...\n");
+    sq1 = sq_create();
+##  range of p is palladium
+##  retrieve (id1 = p.mach_id) {
+       if (!hash_lookup(machines, id1)) {
+           sq_save_unique_data(sq1, id1);
+       }
+##  }
+    generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
+
+    dprintf("Checking krbmap...\n");
+    sq1 = sq_create();
+    sq2 = sq_create();
+##  range of k is krbmap
+##  retrieve (id1 = k.users_id, id2 = k.string_id) {
+       if (!hash_lookup(users, id1))
+         sq_save_unique_data(sq1, id1);
+       if (!string_check(id2))
+         sq_save_unique_data(sq2, id2);
+##  }
+    generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
+    generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
+
     dprintf("Checking capacls...\n");
 ##  retrieve (id1 = capacls.list_id, name = capacls.tag) {
        if (!hash_lookup(lists, id1)) {
This page took 1.863489 seconds and 4 git commands to generate.