]> andersk Git - moira.git/blobdiff - dbck/phase2.pc
Command line printer manipulation client, and build goo.
[moira.git] / dbck / phase2.pc
index 34b5c1908fd7ec70271eba466063cf123f8e596e..de786a3d8da76da680b54f3e9843b3c1c7edca34 100644 (file)
@@ -21,8 +21,11 @@ EXEC SQL WHENEVER SQLERROR DO dbmserr();
 
 int show_mcm_mach(void *id);
 int show_mcm_clu(void *id);
+int show_mcntmap_mach(void *id);
+int show_mcntmap_cnt(void *id);
 int show_hostalias(void *id);
 int show_printer_mach(void *id);
+int show_printer_server(void *id);
 int show_printer_loghost(void *id);
 int show_printer_spool(void *id);
 int show_printer_quota(void *id);
@@ -31,12 +34,13 @@ int show_printer_lpc_acl(void *id);
 void fix_printer_ac(void *id);
 void fix_printer_lpc_acl(void *id);
 void user_check(int id, void *user, void *hint);
+void clear_user_sponsor(struct user *u);
 int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
                             char *field, char *idfield);
 int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
                      char *field, char *idfield);
-int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid);
-int maybe_fixup_modby2(char *table, char *field, char *cursor, int id);
+int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid);
+int maybe_fixup_modby2(char *table, char *field, char *rowid, int id);
 void pobox_check(int id, struct user *u);
 void remove_pobox(int id);
 void fix_smtp_pobox(int id, int sid);
@@ -48,20 +52,27 @@ void cluster_check(int id, void *cluster, void *hint);
 int show_svc(void *id);
 void list_check(int id, void *list, void *hint);
 void fix_list_acl(int id);
+void fix_list_memacl(int id);
 int show_member_list(void *id);
 int show_mem_user(void *id);
 int show_mem_list(void *id);
 int show_mem_str(void *id);
 int show_mem_krb(void *id);
+int show_mem_mach(void *id);
 void del_mem_user(void *id);
 void del_mem_list(void *id);
 void del_mem_str(void *id);
 void del_mem_krb(void *id);
+void del_mem_mach(void *id);
 int show_sh(void *id);
 void del_sh_mach(void *id);
 void fsmatch(int id, void *nfsphys, void *filesys);
 void check_fs(int id, void *filesys, void *hint);
 void check_nfsphys(int id, void *nfsphys, void *hint);
+void check_ps(int id, void *printserver, void *hint);
+void check_container(int id, void *container, void *hint);
+void fix_container_acl(int id);
+void fix_container_memacl(int id);
 int show_fsg_missing(void *id);
 int show_fsg_type(void *filesys);
 void fix_fsg_type(void *filesys);
@@ -135,6 +146,59 @@ int show_mcm_clu(void *id)
   return found;
 }
 
+int show_mcntmap_mach(void *id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int iid = (int)id, found = 1;
+  char name[CONTAINERS_NAME_SIZE];
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL DECLARE csr_show_mcnt_mach CURSOR FOR
+    SELECT cnt.name FROM container cnt, mcntmap mc
+    WHERE cnt.cnt_id = mc.cnt_id AND mc.mach_id = :iid;
+  EXEC SQL OPEN csr_show_mcnt_mach;
+  while (1)
+    {
+      EXEC SQL FETCH csr_show_mcnt_mach INTO :name;
+      if (sqlca.sqlcode)
+       break;
+
+      strtrim(name);
+      found = 0;
+      printf("Container %s, non-existant machine %d in container map\n",
+            name, iid);
+    }
+  EXEC SQL CLOSE csr_show_mcnt_mach;
+  return found;
+}
+
+int show_mcntmap_cnt(void *id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int iid = (int)id, found = 1;
+  char name[MACHINE_NAME_SIZE];
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL DECLARE csr_show_mcnt_cnt CURSOR FOR
+    SELECT m.name FROM machine m, mcntmap mc
+    WHERE m.mach_id = mc.mach_id AND mc.cnt_id = :iid;
+  EXEC SQL OPEN csr_show_mcnt_cnt;
+  while (1)
+    {
+      EXEC SQL FETCH csr_show_mcnt_cnt INTO :name;
+      if (sqlca.sqlcode)
+       break;
+
+      strtrim(name);
+
+      found = 0;
+      printf("Machine %s, non-existant container %d in container map\n",
+            name, iid);
+    }
+  EXEC SQL CLOSE csr_show_mcnt_cnt;
+  return found;
+}
+
 int show_hostalias(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -187,6 +251,32 @@ int show_printer_mach(void *id)
   return found;
 }
 
+int show_printer_server(void *id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int iid = (int)id, found = 1;
+  char name[PRINTERS_NAME_SIZE];
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL DECLARE csr_sps CURSOR FOR
+    SELECT name FROM printers WHERE mach_id = :iid;
+  EXEC SQL OPEN csr_sps;
+  while (1)
+    {
+      EXEC SQL FETCH csr_sps INTO :name;
+      if (sqlca.sqlcode)
+       break;
+
+      strtrim(name);
+
+      found = 0;
+      printf("Printer %s, non-existant printserver %d in printers table\n",
+            name, iid);
+    }
+  EXEC SQL CLOSE csr_sps;
+  return found;
+}
+
 int show_printer_loghost(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -366,6 +456,36 @@ void user_check(int id, void *user, void *hint)
   u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
                                       "sigwho", "users_id");
 
+  switch (u->sponsor_type)
+    {
+    case 'U':
+      if (!hash_lookup(users, u->sponsor_id))
+       {
+         printf("User %s has non-existant USER sponsor %d\n",
+                u->login, u->sponsor_id);
+         if (single_fix("Set to no sponsor", 1))
+           clear_user_sponsor(u);
+       }
+      break;
+    case 'L':
+      if (!hash_lookup(lists, u->sponsor_id))
+       {
+         printf("User %s has non-existant LIST sponsor %d\n",
+                u->login, u->sponsor_id);
+         if (single_fix("Set to no sponsor", 1))
+           clear_user_sponsor(u);
+       }
+      break;
+    case 'S':
+    case 'K':
+      if (u->sponsor_id)
+       u->sponsor_id = maybe_fixup_unref_string(u->sponsor_id, id, u->login,
+                                              "users", "sponsor_id",
+                                              "users_id");
+      if (u->sponsor_id == 0)
+       clear_user_sponsor(u);
+    }
+
   pobox_check(id, u);
 }
 
@@ -450,7 +570,7 @@ int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
   return sid;
 }
 
-int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid)
+int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid)
 {
   int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
   EXEC SQL BEGIN DECLARE SECTION;
@@ -473,7 +593,7 @@ int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid)
     {
       printf("%s entry has a %s with non-existant string %d\n",
             table, field, ret);
-      if (single_fix("Delete", 1))
+      if (single_fix("Clear", 1))
        {
          ret = 0;
          doit = 1;
@@ -482,8 +602,8 @@ int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid)
 
   if (doit)
     {
-      sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s",
-             table, field, (sid < 0) ? -ret : ret, cursor);
+      sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE rowid = '%s'",
+             table, field, (sid < 0) ? -ret : ret, rowid);
       EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
       rowcount = sqlca.sqlerrd[2];
       if (rowcount == 1)
@@ -495,7 +615,7 @@ int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid)
   return (sid < 0) ? -ret : ret;
 }
 
-int maybe_fixup_modby2(char *table, char *field, char *cursor, int id)
+int maybe_fixup_modby2(char *table, char *field, char *rowid, int id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
   char stmt_buf[500];
@@ -503,17 +623,17 @@ int maybe_fixup_modby2(char *table, char *field, char *cursor, int id)
   EXEC SQL END DECLARE SECTION;
 
   if (id < 0)
-    return maybe_fixup_unref_string2(table, field, cursor, id);
+    return maybe_fixup_unref_string2(table, field, rowid, id);
   else
     {
       if (!hash_lookup(users, id))
        {
          printf("%s entry has a %s with non-existant user %d\n",
                 table, field, id);
-         if (single_fix("Delete", 1))
+         if (single_fix("Clear", 1))
            {
-             sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE CURRENT OF %s",
-                     table, field, cursor);
+             sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE rowid = '%s'",
+                     table, field, rowid);
              EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
              rowcount = sqlca.sqlerrd[2];
              if (rowcount == 1)
@@ -530,6 +650,8 @@ int maybe_fixup_modby2(char *table, char *field, char *cursor, int id)
 
 void pobox_check(int id, struct user *u)
 {
+  struct filesys *fs;
+
   switch (u->potype)
     {
     case 'P':
@@ -544,6 +666,20 @@ void pobox_check(int id, struct user *u)
            }
        }
       break;
+
+    case 'E':
+      if (!hash_lookup(machines, u->pobox_id))
+       {
+         printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
+                u->login, u->fullname, u->pobox_id);
+         if (single_fix("Delete", 0))
+           {
+             remove_pobox(u->users_id);
+             u->potype = 'N';
+           }
+       }
+      break;
+
     case 'S':
       if (hash_lookup(string_dups, u->pobox_id))
        {
@@ -570,6 +706,31 @@ void pobox_check(int id, struct user *u)
            }
        }
       break;
+
+    case 'I':
+      fs = hash_lookup(filesys, u->pobox_id);
+      if (!fs)
+       {
+         printf("User %s(%s) has P.O.Box on non-existant filesystem %d\n",
+                u->login, u->fullname, u->pobox_id);
+         if (single_fix("Delete", 0))
+           {
+             remove_pobox(u->users_id);
+             u->potype = 'N';
+           }
+       }
+      else if (fs->type != 'I')
+       {
+         printf("User %s(%s) has IMAP P.O.Box on non-IMAP filesystem %s\n",
+                u->login, u->fullname, fs->name);
+         if (single_fix("Delete", 0))
+           {
+             remove_pobox(u->users_id);
+             u->potype = 'N';
+           }
+       }
+      break;
+
     default:
       ;
     }
@@ -711,6 +872,22 @@ void subnet_check(int id, void *subnet, void *hint)
                               "modby", "snet_id");
 }
 
+void clear_user_sponsor(struct user *u)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, id = u->users_id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE users SET sponsor_type = 'NONE', sponsor_id = 0
+    WHERE users_id = :id;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("users");
+}
+
 void clear_subnet_owner(struct subnet *s)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -814,6 +991,37 @@ void list_check(int id, void *list, void *hint)
        }
       break;
     }
+
+  switch (l->memacl_type)
+    {
+    case 'L':
+      if (!hash_lookup(lists, l->memacl_id))
+       {
+         printf("List %s has bad LIST memacl %d\n", l->name, l->memacl_id);
+         if (single_fix("Patch", 1))
+           fix_list_memacl(l->list_id);
+       }
+      break;
+    case 'U':
+      if (!hash_lookup(users, l->memacl_id))
+       {
+         printf("List %s has bad USER acl %d\n", l->name, l->memacl_id);
+         if (single_fix("Patch", 1))
+           fix_list_memacl(l->list_id);
+       }
+      break;
+    case 'K':
+      l->memacl_id = maybe_fixup_unref_string(l->memacl_id, id, l->name,
+                                             "list", "memacl_id", "list_id");
+         if (!l->memacl_id)
+           {
+             printf("List %s has bad KERBEROS acl %d\n", l->name, 
+                    l->memacl_id);
+             if (single_fix("Patch", 1))
+               fix_list_memacl(l->list_id);
+           }
+         break;
+    }
 }
 
 void fix_list_acl(int id)
@@ -832,6 +1040,22 @@ void fix_list_acl(int id)
   modified("list");
 }
 
+void fix_list_memacl(int id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, iid = (int)id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE list SET memacl_id = 0, memacl_type = 'NONE'
+    WHERE list_id = :iid;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("list");
+}
+
 int show_member_list(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -991,6 +1215,33 @@ int show_mem_krb(void *id)
   return found;
 }
 
+int show_mem_mach(void *id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int lid, iid = (int)id, found = 1;
+  EXEC SQL END DECLARE SECTION;
+  struct list *l; 
+
+  EXEC SQL DECLARE csr208a CURSOR FOR
+    SELECT list_id FROM imembers
+    WHERE member_id = :iid AND member_type = 'MACHINE';
+  EXEC SQL OPEN csr208a;
+  while (1)
+    {
+      EXEC SQL FETCH csr208a INTO :lid;
+      if (sqlca.sqlcode)
+       break;
+      l = hash_lookup(lists, lid);
+      if (!l)
+       continue;
+
+      found = 0;
+      printf("List %s has nonexistant machine member, id %d\n",
+            l->name, iid);
+    }
+  EXEC SQL CLOSE csr208a;
+  return found;
+}
 
 void del_mem_user(void *id)
 {
@@ -1057,6 +1308,21 @@ void del_mem_krb(void *id)
   modified("imembers");
 }
 
+void del_mem_mach(void *id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int iid = (int)id, rowcount;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL DELETE FROM imembers WHERE member_type = 'MACHINE' AND
+    member_id = :iid;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not deleted\n");
+  modified("imembers");
+}
 
 int show_sh(void *id)
 {
@@ -1162,7 +1428,7 @@ void check_fs(int id, void *filesys, void *hint)
        }
     }
 
-  if (f->type == 'N')
+  if (f->type == 'N' || f->type == 'I')
     {
       if (!hash_lookup(nfsphys, f->phys_id))
        {
@@ -1267,6 +1533,232 @@ void check_nfsphys(int id, void *nfsphys, void *hint)
     }
 }
 
+static void clear_ps_owner(struct printserver *ps)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, id = ps->mach_id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE printserver SET owner_type = 'NONE', owner_id = 0
+    WHERE mach_id = :id;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("printservers");
+}
+
+static void clear_ps_lpc(struct printserver *ps)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, id = ps->mach_id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE printserver SET lpc_acl = 0
+    WHERE mach_id = :id;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("printservers");
+}
+
+void check_ps(int id, void *printserver, void *hint)
+{
+  struct printserver *ps = printserver;
+  struct machine *m;
+  char *name;
+
+  m = hash_lookup(machines, id);
+  if (!m)
+    {
+      printf("Printserver on non-existant machine %d\n", id);
+      if (single_fix("Delete", 0))
+       {
+         single_delete("printservers", "mach_id", id);
+         return;
+       }
+      else
+       name = "[UNKNOWN]";
+    }
+  else
+    name = m->name;      
+
+  ps->modby = maybe_fixup_modby(ps->modby, id, name, "printservers",
+                               "modby", "mach_id");
+  ps->printer_types = maybe_fixup_unref_string(ps->printer_types, id, name,
+                                              "printservers", "printer_types",
+                                              "mach_id");
+
+  switch (ps->owner_type)
+    {
+    case 'U':
+      if (!hash_lookup(users, ps->owner_id))
+       {
+         printf("Printserver %s has non-existant USER owner %d\n",
+                name, ps->owner_id);
+         if (single_fix("Set to no owner", 1))
+           clear_ps_owner(ps);
+       }
+      break;
+    case 'L':
+      if (!hash_lookup(lists, ps->owner_id))
+       {
+         printf("Printserver %s has non-existant LIST owner %d\n",
+                name, ps->owner_id);
+         if (single_fix("Set to no owner", 1))
+           clear_ps_owner(ps);
+       }
+      break;
+    case 'K':
+      if (ps->owner_id)
+       ps->owner_id = maybe_fixup_unref_string(ps->owner_id, id, name,
+                                              "printserver", "owner_id",
+                                              "mach_id");
+      if (ps->owner_id == 0)
+       clear_ps_owner(ps);
+    }
+
+  if (!hash_lookup(lists, ps->lpc_acl))
+    {
+      printf("Printserver %s has non-existent lpc_acl %d\n",
+            name, ps->lpc_acl);
+      if (single_fix("Set to no lpc_acl", 1))
+       clear_ps_lpc(ps);
+    }
+}
+
+static void clear_container_list(struct container *cnt)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, id = cnt->cnt_id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE containers SET list_id = 0
+    WHERE cnt_id = :id;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("containers");
+}
+
+void fix_container_acl(int id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, iid = (int)id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE containers SET acl_id = 0, acl_type = 'NONE'
+    WHERE cnt_id = :iid;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("containers");
+}
+
+void fix_container_memacl(int id)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  int rowcount, iid = (int)id;
+  EXEC SQL END DECLARE SECTION;
+
+  EXEC SQL UPDATE containers SET memacl_id = 0, memacl_type = 'NONE'
+    WHERE cnt_id = :iid;
+  rowcount = sqlca.sqlerrd[2];
+  if (rowcount > 0)
+    printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
+  else
+    printf("Not fixed\n");
+  modified("containers");
+}
+
+void check_container(int id, void *container, void *hint)
+{
+  struct container *cnt = container;
+
+  if (!hash_lookup(lists, cnt->list_id))
+    {
+      printf("Container %s has non-existent associated list_id %d\n",
+            cnt->name, cnt->list_id);
+      if (single_fix("Set to no associated list", 1))
+       clear_container_list(cnt);
+    }
+
+  switch (cnt->acl_type)
+    {
+    case 'L':
+      if (!hash_lookup(lists, cnt->acl_id))
+       {
+         printf("Container %s has bad LIST acl %d\n", cnt->name, cnt->acl_id);
+         if (single_fix("Patch", 1))
+           fix_container_acl(cnt->cnt_id);
+       }
+      break;
+    case 'U':
+      if (!hash_lookup(users, cnt->acl_id))
+       {
+         printf("Container %s has bad USER acl %d\n", cnt->name, cnt->acl_id);
+         if (single_fix("Patch", 1))
+           fix_container_acl(cnt->cnt_id);
+       }
+      break;
+    case 'K':
+      cnt->acl_id = maybe_fixup_unref_string(cnt->acl_id, id, cnt->name,
+                                            "container", "acl_id", "cnt_id");
+      if (!cnt->acl_id)
+       {
+         printf("Container %s has bad KERBEROS acl %d\n", cnt->name,
+                cnt->acl_id);
+         if (single_fix("Patch", 1))
+           fix_container_acl(cnt->cnt_id);
+       }
+      break;
+    }
+
+ switch (cnt->memacl_type)
+    {
+    case 'L':
+      if (!hash_lookup(lists, cnt->memacl_id))
+       {
+         printf("Container %s has bad LIST memacl %d\n", cnt->name,
+                cnt->memacl_id);
+         if (single_fix("Patch", 1))
+           fix_container_memacl(cnt->cnt_id);
+       }
+      break;
+    case 'U':
+      if (!hash_lookup(users, cnt->memacl_id))
+       {
+         printf("Container %s has bad USER memacl %d\n", cnt->name,
+                cnt->memacl_id);
+         if (single_fix("Patch", 1))
+           fix_container_memacl(cnt->cnt_id);
+       }
+      break;
+    case 'K':
+      cnt->memacl_id = maybe_fixup_unref_string(cnt->memacl_id, id, cnt->name,
+                                            "container", "memacl_id",
+                                               "cnt_id");
+      if (!cnt->memacl_id)
+       {
+         printf("Container %s has bad KERBEROS memacl %d\n", cnt->name,
+                cnt->memacl_id);
+         if (single_fix("Patch", 1))
+           fix_container_memacl(cnt->cnt_id);
+       }
+      break;
+    }  
+
+  cnt->modby = maybe_fixup_modby(cnt->modby, id, cnt->name, "containers",
+                                "modby", "cnt_id");
+}
+
 int show_fsg_missing(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -1418,10 +1910,9 @@ int show_quota_nolist(void *id)
 void fix_quota_nouser(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int iid = (int)id, rowcount, id1;
+  int iid = (int)id, rowcount;
   EXEC SQL END DECLARE SECTION;
 
-  id1 = ((struct filesys *)hash_lookup(filesys, iid))->phys_id;
   EXEC SQL DELETE FROM quota
     WHERE entity_id = :iid AND type = 'USER';
   rowcount = sqlca.sqlerrd[2];
@@ -1435,10 +1926,9 @@ void fix_quota_nouser(void *id)
 void fix_quota_nolist(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  int iid = (int)id, rowcount, id1;
+  int iid = (int)id, rowcount;
   EXEC SQL END DECLARE SECTION;
 
-  id1 = ((struct filesys *)hash_lookup(filesys, iid))->phys_id;
   EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP';
   rowcount = sqlca.sqlerrd[2];
   if (rowcount > 0)
@@ -1667,11 +2157,12 @@ int show_krb_str(void *id)
 
 void phase2(void)
 {
-  struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
+  struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5, *sq6;
   struct filesys *f;
   struct list *l;
   struct nfsphys *n;
   struct machine *m;
+  char rowid[32];
 
   printf("Phase 2 - Checking references\n");
 
@@ -1744,22 +2235,24 @@ void phase2(void)
   sq3 = sq_create();
   sq4 = sq_create();
   sq5 = sq_create();
+  sq6 = sq_create();
 
   EXEC SQL DECLARE csr223 CURSOR FOR
-    SELECT list_id, member_type, member_id, ref_count, direct
+    SELECT list_id, member_type, member_id, tag, ref_count, direct, rowid
     FROM imembers FOR UPDATE OF member_id;
   EXEC SQL OPEN csr223;
   while (1)
     {
       EXEC SQL BEGIN DECLARE SECTION;
-      int list_id, id, ref_count, direct;
+      int list_id, id, tag, ref_count, direct;
       char type[IMEMBERS_MEMBER_TYPE_SIZE];
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr223 INTO :list_id, :type, :id,
-       :ref_count, :direct;
+      EXEC SQL FETCH csr223 INTO :list_id, :type, :id, :tag,
+       :ref_count, :direct, :rowid;
       if (sqlca.sqlcode)
        break;
+      strtrim(rowid);
 
       if (!(l = hash_lookup(lists, list_id)))
        sq_save_unique_data(sq1, (void *)list_id);
@@ -1767,12 +2260,15 @@ void phase2(void)
        sq_save_unique_data(sq2, (void *)id);
       else if (type[0] == 'L' && !hash_lookup(lists, id))
        sq_save_unique_data(sq3, (void *)id);
-      else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id))
+      else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
        sq_save_unique_data(sq4, (void *)id);
-      else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id))
+      else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
        sq_save_unique_data(sq5, (void *)id);
+      else if (type[0] == 'M' && !hash_lookup(machines, id))
+       sq_save_unique_data(sq6, (void *)id);
       else
        l->members++;
+      maybe_fixup_unref_string2("imembers", "tag", rowid, tag);
     }
   EXEC SQL CLOSE csr223;
   generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
@@ -1780,12 +2276,13 @@ void phase2(void)
   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);
+  generic_fix(sq6, show_mem_mach, "Delete", del_mem_mach, 1);
 
   dprintf("Checking servers...\n");
   sq1 = sq_create();
   sq2 = sq_create();
   EXEC SQL DECLARE csr224 CURSOR FOR
-    SELECT name, acl_type, acl_id, modby FROM servers
+    SELECT name, acl_type, acl_id, modby, rowid FROM servers
     FOR UPDATE of modby;
   EXEC SQL OPEN csr224;
   while (1)
@@ -1795,11 +2292,11 @@ void phase2(void)
       char name[SERVERS_NAME_SIZE], acl_type[SERVERS_ACL_TYPE_SIZE];
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby;
+      EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby, :rowid;
       if (sqlca.sqlcode)
        break;
 
-      maybe_fixup_modby2("servers", "modby", "csr224", modby);
+      maybe_fixup_modby2("servers", "modby", strtrim(rowid), modby);
       strtrim(acl_type);
       if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
        sq_save_data(sq1, (void *)acl_id);
@@ -1813,7 +2310,7 @@ void phase2(void)
   dprintf("Checking serverhosts...\n");
   sq = sq_create();
   EXEC SQL DECLARE csr225 CURSOR FOR
-    SELECT mach_id, modby FROM serverhosts
+    SELECT mach_id, modby, rowid FROM serverhosts
     FOR UPDATE OF modby;
   EXEC SQL OPEN csr225;
   while (1)
@@ -1822,11 +2319,11 @@ void phase2(void)
       int mach_id, modby;
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr225 INTO :mach_id, :modby;
+      EXEC SQL FETCH csr225 INTO :mach_id, :modby, :rowid;
       if (sqlca.sqlcode)
        break;
 
-      maybe_fixup_modby2("serverhosts", "modby", "csr225", modby);
+      maybe_fixup_modby2("serverhosts", "modby", strtrim(rowid), modby);
       if (!hash_lookup(machines, mach_id))
        sq_save_data(sq, (void *)mach_id);
     }
@@ -1871,7 +2368,7 @@ void phase2(void)
   sq3 = sq_create();
   sq4 = sq_create();
   EXEC SQL DECLARE csr227 CURSOR FOR
-    SELECT entity_id, type, filsys_id, phys_id, quota, modby
+    SELECT entity_id, type, filsys_id, phys_id, quota, modby, rowid
     FROM quota FOR UPDATE OF modby;
   EXEC SQL OPEN csr227;
   while (1)
@@ -1882,11 +2379,11 @@ void phase2(void)
       EXEC SQL END DECLARE SECTION;
 
       EXEC SQL FETCH csr227 INTO :entity_id, :type, :filsys_id,
-       :phys_id, :quota, :modby;
+       :phys_id, :quota, :modby, :rowid;
       if (sqlca.sqlcode)
        break;
 
-      maybe_fixup_modby2("quota", "modby", "csr227", modby);
+      maybe_fixup_modby2("quota", "modby", strtrim(rowid), modby);
       if (type[0] == 'U' && entity_id != 0 && !hash_lookup(users, entity_id))
        sq_save_data(sq1, (void *)entity_id);
       else if (type[0] == 'G' && !hash_lookup(lists, entity_id))
@@ -1904,11 +2401,90 @@ void phase2(void)
   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");
+  dprintf("Checking zephyr...\n");
+  EXEC SQL DECLARE csr_zc CURSOR FOR
+    SELECT class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id,
+    iui_type, iui_id, modby FROM zephyr;
+  EXEC SQL OPEN csr_zc;
+  while(1)
+    {
+      EXEC SQL BEGIN DECLARE SECTION;
+      int xmt_id, sub_id, iws_id, iui_id, modby;
+      char class[ZEPHYR_CLASS_SIZE];
+      char xmt_type[ZEPHYR_XMT_TYPE_SIZE];
+      char sub_type[ZEPHYR_SUB_TYPE_SIZE];
+      char iws_type[ZEPHYR_IWS_TYPE_SIZE];
+      char iui_type[ZEPHYR_IUI_TYPE_SIZE];
+      EXEC SQL END DECLARE SECTION;
+
+      EXEC SQL FETCH csr_zc INTO :class, :xmt_type, :xmt_id, :sub_type, 
+       :sub_id, :iws_type, :iws_id, :iui_type, :iui_id, :modby;
+
+      if (sqlca.sqlcode)
+       break;
+
+      maybe_fixup_modby2("zephyr", "modby", strtrim(rowid), modby);
+
+      strtrim(xmt_type);
+      if (!strcmp(xmt_type, "USER") && !hash_lookup(users, xmt_id))
+       {
+         printf("xmt acl for %s is non-existant user %d\n", class, xmt_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(xmt_type, "LIST") && !hash_lookup(lists, xmt_id))
+       {
+         printf("xmt acl for %s is non-existant list %d\n", class, xmt_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(xmt_type, "STRING") || !strcmp(xmt_type, "KERBEROS"))
+       maybe_fixup_unref_string2("zephyr", "xmt_id", strtrim(rowid), xmt_id);
+
+      strtrim(sub_type);
+      if (!strcmp(sub_type, "USER") && !hash_lookup(users, sub_id))
+       {
+         printf("sub acl for %s is non-existant user %d\n", class, sub_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(sub_type, "LIST") && !hash_lookup(lists, sub_id))
+       {
+         printf("sub acl for %s is non-existant list %d\n", class, sub_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(sub_type, "STRING") || !strcmp(sub_type, "KERBEROS"))
+       maybe_fixup_unref_string2("zephyr", "sub_id", strtrim(rowid), sub_id);
+
+      strtrim(iws_type);
+      if (!strcmp(iws_type, "USER") && !hash_lookup(users, iws_id))
+       {
+         printf("iws acl for %s is non-existant user %d\n", class, iws_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(iws_type, "LIST") && !hash_lookup(lists, iws_id))
+       {
+         printf("iws acl for %s is non-existant list %d\n", class, iws_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(iws_type, "STRING") || !strcmp(iws_type, "KERBEROS"))
+       maybe_fixup_unref_string2("zephyr", "iws_id", strtrim(rowid), iws_id);
+
+      strtrim(iui_type);
+      if (!strcmp(iui_type, "USER") && !hash_lookup(users, iui_id))
+       {
+         printf("iui acl for %s is non-existant user %d\n", class, iui_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(iui_type, "LIST") && !hash_lookup(lists, iui_id))
+       {
+         printf("iui acl for %s is non-existant list %d\n", class, iui_id);
+         printf("Not fixing this error\n");
+       }
+      else if (!strcmp(iui_type, "STRING") || !strcmp(iui_type, "KERBEROS"))
+       maybe_fixup_unref_string2("zephyr", "iui_id", strtrim(rowid), iui_id);
+    }
 
   dprintf("Checking hostaccess...\n");
   EXEC SQL DECLARE csr228 CURSOR FOR
-    SELECT mach_id, acl_type, acl_id, modby FROM hostaccess
+    SELECT mach_id, acl_type, acl_id, modby, rowid FROM hostaccess
     FOR UPDATE OF modby;
   EXEC SQL OPEN csr228;
   while (1)
@@ -1918,11 +2494,11 @@ void phase2(void)
       char acl_type[HOSTACCESS_ACL_TYPE_SIZE];
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby;
+      EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby, :rowid;
       if (sqlca.sqlcode)
        break;
 
-      maybe_fixup_modby2("hostaccess", "modby", "csr228", modby);
+      maybe_fixup_modby2("hostaccess", "modby", strtrim(rowid), modby);
       strtrim(acl_type);
       if (!hash_lookup(machines, mach_id))
        {
@@ -1946,7 +2522,7 @@ void phase2(void)
   sq1 = sq_create();
   sq2 = sq_create();
   EXEC SQL DECLARE csr230 CURSOR FOR
-    SELECT users_id, string_id FROM krbmap
+    SELECT users_id, string_id, rowid FROM krbmap
     FOR UPDATE OF string_id;
   EXEC SQL OPEN csr230;
   while (1)
@@ -1955,13 +2531,13 @@ void phase2(void)
       int users_id, string_id;
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr230 INTO :users_id, :string_id;
+      EXEC SQL FETCH csr230 INTO :users_id, :string_id, :rowid;
       if (sqlca.sqlcode)
        break;
 
       if (!hash_lookup(users, users_id))
        sq_save_unique_data(sq1, (void *)users_id);
-      else if (!maybe_fixup_unref_string2("krbmap", "string_id", "csr230", string_id))
+      else if (!maybe_fixup_unref_string2("krbmap", "string_id", strtrim(rowid), string_id))
        sq_save_unique_data(sq2, (void *)string_id);
     }
   EXEC SQL CLOSE csr230;
@@ -1991,7 +2567,7 @@ void phase2(void)
     }
   EXEC SQL CLOSE csr231;
 
-  dprintf("Checking hostaliases\n");
+  dprintf("Checking hostaliases...\n");
   sq1 = sq_create();
   EXEC SQL DECLARE csr232 CURSOR FOR
     SELECT mach_id FROM hostalias;
@@ -2012,14 +2588,15 @@ void phase2(void)
   EXEC SQL CLOSE csr232;
   generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
 
-  dprintf("Checking printers\n");
+  dprintf("Checking printers...\n");
   sq1 = sq_create();
   sq2 = sq_create();
   sq3 = sq_create();
   sq4 = sq_create();
   sq5 = sq_create();
+  sq6 = sq_create();
   EXEC SQL DECLARE csr233 CURSOR FOR
-    SELECT mach_id, loghost, rm, rq, ac, lpc_acl, modby FROM printers;
+    SELECT mach_id, loghost, rm, rq, ac, lpc_acl, modby, rowid FROM printers;
   EXEC SQL OPEN csr233;
   while (1)
     {
@@ -2027,16 +2604,18 @@ void phase2(void)
       int mach_id, loghost, rm, rq, ac, lpc_acl, modby;
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr233 INTO :mach_id, :loghost, :rm, :rq,
-       :lpc_acl, :modby;
+      EXEC SQL FETCH csr233 INTO :mach_id, :loghost, :rm, :rq, :ac,
+       :lpc_acl, :modby, :rowid;
       if (sqlca.sqlcode)
        break;
 
-      maybe_fixup_modby2("printers", "modby", "csr233", modby);
+      maybe_fixup_modby2("printers", "modby", strtrim(rowid), modby);
       if (!hash_lookup(machines, mach_id))
        sq_save_unique_data(sq1, (void *)mach_id);
       else if (!hash_lookup(machines, rm))
        sq_save_unique_data(sq2, (void *)rm);
+      else if (!hash_lookup(printservers, rm))
+       sq_save_unique_data(sq6, (void *)mach_id);
       else if (!hash_lookup(machines, rq))
        sq_save_unique_data(sq3, (void *)rq);
       else {
@@ -2053,9 +2632,42 @@ void phase2(void)
     }
   EXEC SQL CLOSE csr233;
   generic_delete(sq1, show_printer_mach, "printers", "mach_id", 1);
+  generic_delete(sq6, show_printer_server, "printers", "mach_id", 1);
   generic_delete(sq2, show_printer_spool, "printers", "rm", 1);
   generic_delete(sq3, show_printer_quota, "printers", "rq", 1);
   generic_fix(sq4, show_printer_ac, "Clear", fix_printer_ac, 1);
   generic_fix(sq5, show_printer_lpc_acl, "Clear", fix_printer_lpc_acl, 1);
+
+  dprintf("Checking printservers...\n");
+  hash_step(printservers, check_ps, NULL);
+
+  dprintf("Checking containers...\n");
+  hash_step(containers, check_container, NULL);
+
+  dprintf("Checking mcntmap...\n");
+  sq1 = sq_create();
+  sq2 = sq_create();
+  EXEC SQL DECLARE csr_mcntmap CURSOR FOR
+    SELECT mach_id, cnt_id FROM mcntmap;
+  EXEC SQL OPEN csr_mcntmap;
+  while (1)
+    {
+      EXEC SQL BEGIN DECLARE SECTION;
+      int mach_id, cnt_id;
+      EXEC SQL END DECLARE SECTION;
+
+      EXEC SQL FETCH csr_mcntmap INTO :mach_id, :cnt_id;
+      if (sqlca.sqlcode)
+       break;
+
+      if (!(m = hash_lookup(machines, mach_id)))
+       sq_save_unique_data(sq1, (void *)mach_id);
+      else if (!hash_lookup(containers, cnt_id))
+       sq_save_unique_data(sq2, (void *)cnt_id);
+    }
+  EXEC SQL CLOSE csr_mcntmap;
+  generic_delete(sq1, show_mcntmap_mach, "mcntmap", "mach_id", 1);
+  generic_delete(sq2, show_mcntmap_cnt, "mcntmap", "cnt_id", 1);
+
 }
  
This page took 0.510667 seconds and 4 git commands to generate.