]> andersk Git - moira.git/blobdiff - dbck/phase2.pc
Trim whitespace from childname, so we can update a container that
[moira.git] / dbck / phase2.pc
index 89982100b2a18a6dbda05334d03bc1a556519812..39ae152432adf692d65239b78223535ab9c575ba 100644 (file)
@@ -23,6 +23,7 @@ int show_mcm_mach(void *id);
 int show_mcm_clu(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);
@@ -48,6 +49,7 @@ 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);
@@ -62,6 +64,7 @@ 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);
 int show_fsg_missing(void *id);
 int show_fsg_type(void *filesys);
 void fix_fsg_type(void *filesys);
@@ -187,6 +190,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;
@@ -842,6 +871,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)
@@ -860,6 +920,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;
@@ -1295,6 +1371,103 @@ 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);
+    }
+}
+
 int show_fsg_missing(void *id)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -1693,7 +1866,7 @@ 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;
@@ -1773,20 +1946,21 @@ void phase2(void)
   sq5 = sq_create();
 
   EXEC SQL DECLARE csr223 CURSOR FOR
-    SELECT list_id, member_type, member_id, ref_count, direct, rowid
+    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,
+      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);
@@ -1794,12 +1968,13 @@ 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", strtrim(rowid), 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", strtrim(rowid), id))
+      else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
        sq_save_unique_data(sq5, (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);
@@ -1931,7 +2106,86 @@ 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
@@ -2045,6 +2299,7 @@ void phase2(void)
   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, rowid FROM printers;
   EXEC SQL OPEN csr233;
@@ -2064,6 +2319,8 @@ void phase2(void)
        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 {
@@ -2080,9 +2337,13 @@ 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);
 }
  
This page took 0.722811 seconds and 4 git commands to generate.