]> andersk Git - moira.git/commitdiff
Check object IDs for user sponsors.
authorzacheiss <zacheiss>
Mon, 3 Dec 2007 21:22:59 +0000 (21:22 +0000)
committerzacheiss <zacheiss>
Mon, 3 Dec 2007 21:22:59 +0000 (21:22 +0000)
dbck/dbck.h
dbck/phase1.pc
dbck/phase2.pc

index e7a245f1d3275e84d68614f33f3eca3030ca9b82..fdb7c75a285c8154be7a83beb288e859fc8b277c 100644 (file)
@@ -38,6 +38,8 @@ struct user {
   int fmodby;
   int pmodby;
   int sigwho;
+  char sponsor_type;
+  int sponsor_id;
 };
 
 struct machine {
index 0b35abbd2df62531894b4696a93942f3b07e2c79..f89a618df173d7c8764a8e0930cc1c3fb861d922 100644 (file)
@@ -358,22 +358,22 @@ void phase1(void)
 
   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, 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];
+      char potype[USERS_POTYPE_SIZE], sponsor_type[USERS_SPONSOR_TYPE_SIZE];
       int users_id, status, pop_id, box_id, imap_id, modby, fmodby, pmodby;
-      int comments, sigwho;
+      int 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;
+       :pmodby, :comments, :sigwho, :sponsor_type, :sponsor_id;
       if (sqlca.sqlcode)
        break;
 
@@ -391,6 +391,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':
index 6132007830254e91950850a849f9f42db90f75a9..3c6d1a341afdbf81e8890480c1e188e45907fe15 100644 (file)
@@ -34,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,
@@ -455,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);
 }
 
@@ -828,6 +859,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;
This page took 0.119712 seconds and 5 git commands to generate.