]> andersk Git - moira.git/blobdiff - dbck/phase2.pc
Command line printer manipulation client, and build goo.
[moira.git] / dbck / phase2.pc
index 5a4017987a666c35b3418dd6a8af64ad65dd0cd5..de786a3d8da76da680b54f3e9843b3c1c7edca34 100644 (file)
@@ -21,6 +21,8 @@ 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);
@@ -32,6 +34,7 @@ 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,
@@ -67,6 +70,9 @@ 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);
@@ -140,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;
@@ -397,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);
 }
 
@@ -578,6 +667,19 @@ 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))
        {
@@ -770,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;
@@ -1512,6 +1630,135 @@ void check_ps(int id, void *printserver, void *hint)
     }
 }
 
+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;
@@ -2017,7 +2264,7 @@ void phase2(void)
        sq_save_unique_data(sq4, (void *)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' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
+      else if (type[0] == 'M' && !hash_lookup(machines, id))
        sq_save_unique_data(sq6, (void *)id);
       else
        l->members++;
@@ -2320,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;
@@ -2341,7 +2588,7 @@ 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();
@@ -2391,7 +2638,36 @@ void phase2(void)
   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");
+  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.043192 seconds and 4 git commands to generate.