]> andersk Git - moira.git/blobdiff - dbck/phase1.pc
Support EXCHANGE poboxes.
[moira.git] / dbck / phase1.pc
index 5a1c15de6d0c6b6819605394ad2247ff5bfc5678..d1c432b9388061ec9235ea33a84804c851801bda 100644 (file)
@@ -39,6 +39,7 @@ void fix_np_id(void *nfsphys);
 int show_str_id(void *string);
 int print_str_id(void *id);
 void print_dup_map(int key, void *data, void *hint);
+int show_cnt_name(void *cnt);
 
 int show_user_id(void *user)
 {
@@ -234,6 +235,13 @@ void print_dup_map(int key, void *data, void *hint)
   printf("String %d is a duplicate of string %d\n", key, (int)data);
 }
 
+int show_cnt_name(void *container)
+{
+  struct container *cnt = container;
+  printf("Container %s (%d) has duplicate name\n", cnt->name, cnt->cnt_id);
+  return 0;
+}
+
 void phase1(void)
 {
   EXEC SQL BEGIN DECLARE SECTION;
@@ -250,6 +258,7 @@ void phase1(void)
   struct filesys *f;
   struct nfsphys *n;
   struct printserver *ps;
+  struct container *cnt;
 
   printf("Phase 1 - Looking for duplicates\n");
 
@@ -343,28 +352,29 @@ void phase1(void)
 
   dprintf("Loading users...\n");
   sq = sq_create();
-  users = create_hash(30000);
+  users = create_hash(65000);
   if (!sq || !users)
     out_of_mem("loading users");
 
   EXEC SQL DECLARE csr102 CURSOR FOR
     SELECT users_id, login, last, first, status, potype, pop_id, box_id,
-    imap_id, modby, fmodby, pmodby, comments, sigwho FROM users
-    ORDER BY users_id;
+    imap_id, exchange_id, modby, fmodby, pmodby, comments, sigwho, 
+    sponsor_type, sponsor_id
+    FROM users ORDER BY users_id;
   EXEC SQL OPEN csr102;
   while (1)
     {
       EXEC SQL BEGIN DECLARE SECTION;
       char login[USERS_LOGIN_SIZE], nbuf[USERS_FIRST_SIZE + USERS_LAST_SIZE];
       char last[USERS_LAST_SIZE], first[USERS_FIRST_SIZE];
-      char potype[USERS_POTYPE_SIZE];
-      int users_id, status, pop_id, box_id, imap_id, modby, fmodby, pmodby;
-      int comments, sigwho;
+      char potype[USERS_POTYPE_SIZE], sponsor_type[USERS_SPONSOR_TYPE_SIZE];
+      int users_id, status, pop_id, box_id, imap_id, exchange_id, modby;
+      int fmodby, pmodby, comments, sigwho, sponsor_id;
       EXEC SQL END DECLARE SECTION;
 
       EXEC SQL FETCH csr102 INTO :users_id, :login, :last, :first,
-       :status, :potype, :pop_id, :box_id, :imap_id, :modby, :fmodby,
-       :pmodby, :comments, :sigwho;
+       :status, :potype, :pop_id, :box_id, :imap_id, :exchange_id, :modby, 
+       :fmodby, :pmodby, :comments, :sigwho, :sponsor_type, :sponsor_id;
       if (sqlca.sqlcode)
        break;
 
@@ -382,6 +392,8 @@ void phase1(void)
       u->pmodby = pmodby;
       u->comment = comments;
       u->sigwho = sigwho;
+      u->sponsor_type = sponsor_type[0];
+      u->sponsor_id = sponsor_id;
       switch (u->potype)
        {
        case 'P':
@@ -394,6 +406,8 @@ void phase1(void)
        case 'I':
          u->pobox_id = imap_id;
          break;
+       case 'E':
+         u->pobox_id = exchange_id;
        default:
          u->pobox_id = 0;
        }
@@ -703,17 +717,20 @@ void phase1(void)
     out_of_mem("loading lists");
 
   EXEC SQL DECLARE csr108 CURSOR FOR
-    SELECT list_id, name, acl_id, acl_type, modby  FROM list
+    SELECT list_id, name, acl_id, acl_type, memacl_id, memacl_type, modby
+    FROM list
     ORDER BY list_id;
   EXEC SQL OPEN csr108;
   while (1)
     {
       EXEC SQL BEGIN DECLARE SECTION;
-      int list_id, acl_id, modby;
+      int list_id, acl_id, memacl_id, modby;
       char name[LIST_NAME_SIZE], acl_type[LIST_ACL_TYPE_SIZE];
+      char memacl_type[LIST_ACL_TYPE_SIZE];
       EXEC SQL END DECLARE SECTION;
 
-      EXEC SQL FETCH csr108 INTO :list_id, :name, :acl_id, :acl_type, :modby;
+      EXEC SQL FETCH csr108 INTO :list_id, :name, :acl_id, :acl_type, 
+       :memacl_id, :memacl_type, :modby;
       if (sqlca.sqlcode)
        break;
       l = malloc(sizeof(struct list));
@@ -722,6 +739,8 @@ void phase1(void)
       strcpy(l->name, strtrim(name));
       l->acl_type = acl_type[0];
       l->acl_id = acl_id;
+      l->memacl_type = memacl_type[0];
+      l->memacl_id = memacl_id;
       l->list_id = list_id;
       l->modby = modby;
       l->members = 0;
@@ -835,13 +854,14 @@ void phase1(void)
     out_of_mem("loading nfsphs");
 
   EXEC SQL DECLARE csr111 CURSOR FOR
-    SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
+    SELECT nfsphys_id, dir, mach_id, TO_CHAR(allocated), modby FROM nfsphys;
   EXEC SQL OPEN csr111;
   while (1)
     {
       EXEC SQL BEGIN DECLARE SECTION;
-      int nfsphys_id, mach_id, allocated, modby;
+      int nfsphys_id, mach_id, modby;
       char dir[NFSPHYS_DIR_SIZE];
+      char allocated[39];
       EXEC SQL END DECLARE SECTION;
 
       EXEC SQL FETCH csr111 INTO :nfsphys_id, :dir, :mach_id,
@@ -855,7 +875,7 @@ void phase1(void)
       strcpy(n->dir, strtrim(dir));
       n->mach_id = mach_id;
       n->nfsphys_id = nfsphys_id;
-      n->allocated = allocated;
+      n->allocated = strtoull(allocated, NULL, 0);
       n->modby = modby;
       n->count = 0;
       retval = hash_store(nfsphys, nfsphys_id, n);
@@ -921,6 +941,7 @@ void phase1(void)
       if (!ps)
        out_of_mem("storing printserver");
       ps->mach_id = mach_id;
+      ps->printer_types = printer_types;
       ps->owner_type = owner_type[0];
       ps->owner_id = owner_id;
       ps->lpc_acl = lpc_acl;
@@ -934,5 +955,96 @@ void phase1(void)
          cant_fix(0);
        }
     }
-  EXEC SQL CLOSE csr111;
+  EXEC SQL CLOSE csr_ps;
+
+  if (!fast)
+    {
+      dprintf("Checking zephyr...\n");
+      
+      EXEC SQL DECLARE csr120 CURSOR FOR
+       SELECT z1.class FROM zephyr z1, zephyr z2
+       WHERE (z1.class = z2.class AND z1.rowid < z1.rowid);
+      EXEC SQL OPEN csr120;
+      while (1)
+       {
+         EXEC SQL BEGIN DECLARE SECTION;
+         char class[ZEPHYR_CLASS_SIZE];
+         EXEC SQL END DECLARE SECTION;
+
+         EXEC SQL FETCH csr120 INTO :class;
+         if (sqlca.sqlcode)
+           break;
+
+         printf("Zephyr class %s has duplicate name\n", class);
+         cant_fix(0);
+       }
+      EXEC SQL CLOSE csr120;
+    }
+
+  dprintf("Loading containers...\n");
+  containers = create_hash(1000);
+  if (!containers)
+    out_of_mem("loading containers");
+
+  EXEC SQL DECLARE csr_cnts CURSOR FOR
+    SELECT name, cnt_id, list_id, acl_type, acl_id, memacl_type, memacl_id,
+    modby FROM containers;
+  EXEC SQL OPEN csr_cnts;
+  while (1)
+    {
+      EXEC SQL BEGIN DECLARE SECTION;
+      int cnt_id, list_id, acl_id, memacl_id, modby;
+      char name[CONTAINERS_NAME_SIZE];
+      char acl_type[CONTAINERS_ACL_TYPE_SIZE];
+      char memacl_type[CONTAINERS_MEMACL_TYPE_SIZE];
+      EXEC SQL END DECLARE SECTION;
+
+      EXEC SQL FETCH csr_cnts INTO :name, :cnt_id, :list_id, :acl_type,
+       :acl_id, :memacl_type, :memacl_id, :modby;
+      if (sqlca.sqlcode)
+       break;
+
+      cnt = malloc(sizeof(struct container));
+      if (!cnt)
+       out_of_mem("storing container");
+      strcpy(cnt->name, strtrim(name));
+      cnt->cnt_id = cnt_id;
+      cnt->list_id = list_id;
+      cnt->acl_type = acl_type[0];
+      cnt->acl_id = acl_id;
+      cnt->memacl_type = memacl_type[0];
+      cnt->memacl_id = memacl_id;
+      cnt->modby = modby;
+      retval = hash_store(containers, cnt_id, cnt);
+      if (retval == -1)
+       out_of_mem("storing container in hash table");
+      else if (retval == 1)
+       {
+         printf("Duplicate container cnt_id %d\n", cnt_id);
+         cant_fix(0);
+       }
+    }
+  EXEC SQL CLOSE csr_cnts;
+
+  if (!fast)
+    {
+      sq = sq_create();
+      if (!sq)
+       out_of_mem("looking for duplicate container names");
+
+      EXEC SQL DECLARE csr121 CURSOR FOR
+       SELECT cnt1.cnt_id FROM containers cnt1, containers cnt2
+       WHERE cnt1.name = cnt2.name AND cnt1.cnt_id != cnt2.cnt_id;
+      EXEC SQL OPEN csr121;
+      while (1)
+       {
+         EXEC SQL FETCH csr121 INTO :id;
+         if (sqlca.sqlcode)
+           break;
+
+         sq_save_data(sq, hash_lookup(containers, id));
+       }
+      EXEC SQL CLOSE csr121;
+      generic_fix(sq, show_cnt_name, "Change name", cant_fix, 0);
+    }
 }
This page took 0.044102 seconds and 4 git commands to generate.