]> andersk Git - moira.git/blob - dbck/phase4.qc
5c2727f830ba67802ab2b70f84f8978d5287d287
[moira.git] / dbck / phase4.qc
1 /* $Header$
2  *
3  *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
4  *  For copying and distribution information, please see the file
5  *  <mit-copyright.h>.
6  */
7
8 #include <mit-copyright.h>
9 #include <sms.h>
10 #include "dbck.h"
11
12 static char phase4_qc_rcsid[] = "$Header$";
13
14
15 count_boxes(id, u, boxes)
16 int id;
17 struct user *u;
18 struct hash *boxes;
19 {
20     int i;
21
22     if (u->potype == 'P') {
23         if (i = (int) hash_lookup(boxes, u->pobox_id))
24           hash_store(boxes, u->pobox_id, i+1);
25         else {
26           printf("User %s(%s) has pobox on non-POP server %d\n",
27                  u->fullname, u->login, u->pobox_id);
28           printf("Not fixing this error\n");
29         }
30     }
31 }
32
33
34 ##check_box_counts(id, cnt, counts)
35 ##int id, cnt;
36 struct hash *counts;
37 ##{
38 ##  int oldval, rowcount;
39
40     oldval = (int) hash_lookup(counts, id);
41     cnt--;
42     if (oldval != cnt) {
43         printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
44                ((struct machine *) hash_lookup(machines, id))->name,
45                oldval, cnt);
46         if (single_fix("Update", 1)) {
47 ##          range of s is serverhosts
48 ##          replace s (value1 = cnt) where
49 ##              s.service = "POP" and s.mach_id = id
50 ##          inquire_equel(rowcount = "rowcount")
51             if (rowcount > 0)
52               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
53             else
54               printf("Not fixed\n");
55             modified("serverhosts");
56         }
57     }
58 ##}
59
60
61 ##check_nfs_counts(id, n, hint)
62 ##int id, hint;
63 struct nfsphys *n;
64 ##{
65 ##  int val, rowcount;
66
67     val = n->count;
68     if (n->allocated != val) {
69         printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
70                ((struct machine *) hash_lookup(machines, n->mach_id))->name,
71                n->dir, n->allocated, val);
72         if (single_fix("Update", 1)) {
73 ##          replace nfsphys (allocated = val) where nfsphys.nfsphys_id = id
74 ##          inquire_equel(rowcount = "rowcount")
75             if (rowcount > 0)
76               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
77             else
78               printf("Not fixed\n");
79             modified("nfsphys");
80         }
81     }
82 ##}
83
84
85 phase4()
86 ##{
87     struct hash *boxes, *counts;
88 ##  int id, cnt;
89
90     printf("Phase 4 - Checking counts\n");
91
92     dprintf("Doing POBoxes...\n");
93     boxes = create_hash(10);
94     counts = create_hash(10);
95 ##  retrieve (id = serverhosts.mach_id, cnt = serverhosts.value1)
96 ##      where serverhosts.service = "POP" {
97       hash_store(boxes, id, 1);
98       hash_store(counts, id, cnt);
99 ##  }
100     hash_step(users, count_boxes, boxes);
101     hash_step(boxes, check_box_counts, counts);
102
103     dprintf("Doing NFSphys...\n");
104     hash_step(nfsphys, check_nfs_counts, 0);
105 ##}
106
107
108 count_only_setup()
109 ##{
110 ##  int id, status, id2, id3;
111 ##  char name[33], last[17], first[17], buf[257];
112     struct save_queue *sq;
113     struct user *u;
114     struct nfsphys *n;
115     struct machine *m;
116
117     dprintf("Loading users...\n");
118     users = create_hash(10000);
119 ##  range of u is users
120 ##  retrieve (id = u.users_id, name = u.login, last = u.#last,
121 ##            first = u.#first, status = u.#status, buf = u.potype,
122 ##            id2 = u.pop_id, id3 = u.box_id) 
123 ##    where u.potype = "POP" {
124         u = (struct user *) malloc(sizeof(struct user));
125         strcpy(u->login, strtrim(name));
126         u->potype = buf[0];
127         sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
128         u->fullname = strsave(buf);
129         u->status = status;
130         u->users_id = id;
131         switch (u->potype) {
132         case 'P':
133             u->pobox_id = id2;
134             break;
135         case 'S':
136             u->pobox_id = id3;
137             break;
138         default:
139             u->pobox_id = 0;
140         }
141         hash_store(users, id, u);
142 ##  }
143
144     dprintf("Loading machines...\n");
145     machines = create_hash(1000);
146 ##  range of m is machine
147 ##  retrieve (id = m.mach_id, name = m.#name) {
148         m = (struct machine *) malloc(sizeof(struct machine));
149         strcpy(m->name, strtrim(name));
150         m->mach_id = id;
151         hash_store(machines, id, m);
152 ##  }
153
154     dprintf("Loading nfsphys...\n");
155     nfsphys = create_hash(500);
156 ##  retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
157 ##            id2 = nfsphys.mach_id, id3 = nfsphys.allocated) {
158         n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
159         strcpy(n->dir, strtrim(name));
160         n->mach_id = id2;
161         n->nfsphys_id = id;
162         n->allocated = id3;
163         n->count = 0;
164         hash_store(nfsphys, id, n);
165 ##  }
166
167     dprintf("Counting quotas...\n");
168 ##  retrieve (id = nfsquota.phys_id, id2 = nfsquota.quota) {
169         if (n = (struct nfsphys  *) hash_lookup(nfsphys, id)) {
170             n->count += id2;
171         }
172 ##  }
173 ##}
This page took 0.079874 seconds and 3 git commands to generate.