3 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
12 EXEC SQL INCLUDE sqlca;
14 static char phase4_qc_rcsid[] = "$Header$";
16 EXEC SQL WHENEVER SQLERROR DO dbmserr();
18 count_boxes(int id, struct user *u, struct hash *boxes)
24 if ((i = (int) hash_lookup(boxes, u->pobox_id)))
26 if (hash_store(boxes, u->pobox_id, i + 1) == -1)
27 out_of_mem("storing poboxes in hash table");
31 printf("User %s(%s) has pobox on non-POP server %d\n",
32 u->fullname, u->login, u->pobox_id);
33 printf("Not fixing this error\n");
39 check_box_counts(int id, int cnt, struct hash *counts)
41 EXEC SQL BEGIN DECLARE SECTION;
42 int oldval, rowcount, iid = id, icnt = cnt;
43 EXEC SQL END DECLARE SECTION;
45 oldval = (int) hash_lookup(counts, id);
49 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
50 ((struct machine *) hash_lookup(machines, id))->name,
52 if (single_fix("Update", 1))
54 EXEC SQL UPDATE serverhosts SET value1 = :icnt
55 WHERE service = 'POP' AND mach_id = :iid;
56 rowcount = sqlca.sqlerrd[2];
58 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
60 printf("Not fixed\n");
61 modified("serverhosts");
67 check_nfs_counts(int id, struct nfsphys *n, int hint)
69 EXEC SQL BEGIN DECLARE SECTION;
70 int iid = id, val, rowcount;
71 EXEC SQL END DECLARE SECTION;
74 if (n->allocated != val)
76 printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
77 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
78 n->dir, n->allocated, val);
79 if (single_fix("Update", 1))
81 EXEC SQL UPDATE nfsphys SET allocated = :val
82 WHERE nfsphys_id = :iid;
83 rowcount = sqlca.sqlerrd[2];
85 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
87 printf("Not fixed\n");
96 struct hash *boxes, *counts;
99 printf("Phase 4 - Checking counts\n");
101 dprintf("Doing POBoxes...\n");
102 boxes = create_hash(10);
103 counts = create_hash(10);
104 EXEC SQL DECLARE csr401 CURSOR FOR
105 SELECT mach_id, value1 FROM serverhosts
106 WHERE service = 'POP';
107 EXEC SQL OPEN csr401;
110 EXEC SQL FETCH csr401 INTO :id, :cnt;
114 if (hash_store(boxes, id, 1) == -1)
115 out_of_mem("storing poboxes");
116 if (hash_store(counts, id, cnt) == -1)
117 out_of_mem("storing pobox counts in hash table");
119 EXEC SQL CLOSE csr401;
120 hash_step(users, count_boxes, boxes);
121 hash_step(boxes, check_box_counts, counts);
123 dprintf("Doing NFSphys...\n");
124 hash_step(nfsphys, check_nfs_counts, 0);
128 count_only_setup(void)
130 EXEC SQL BEGIN DECLARE SECTION;
131 int id, status, id2, id3;
132 char name[33], last[17], first[17], buf[257];
133 EXEC SQL END DECLARE SECTION;
134 struct save_queue *sq;
139 dprintf("Loading users...\n");
140 users = create_hash(30000);
141 EXEC SQL DECLARE csr402 CURSOR FOR
142 SELECT users_id, login, last, first, status,
143 potype, pop_id, box_id FROM users
144 WHERE potype = 'POP';
145 EXEC SQL OPEN csr402;
148 EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status,
153 u = malloc(sizeof(struct user));
155 out_of_mem("storing users");
156 strcpy(u->login, strtrim(name));
158 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
159 u->fullname = strsave(buf);
173 if (hash_store(users, id, u) == -1)
174 out_of_mem("storing users in hash table");
176 EXEC SQL CLOSE csr402;
178 dprintf("Loading machines...\n");
179 machines = create_hash(20000);
180 EXEC SQL DECLARE csr403 CURSOR FOR
181 SELECT mach_id, name FROM machine;
182 EXEC SQL OPEN csr403;
185 EXEC SQL FETCH csr403 INTO :id, :name;
189 m = malloc(sizeof(struct machine));
191 out_of_mem("storing machines");
192 strcpy(m->name, strtrim(name));
194 if (hash_store(machines, id, m) == -1)
195 out_of_mem("storing users in hash table");
197 EXEC SQL CLOSE csr403;
199 dprintf("Loading nfsphys...\n");
200 nfsphys = create_hash(500);
201 EXEC SQL DECLARE csr404 CURSOR FOR
202 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
203 EXEC SQL OPEN csr404;
206 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
210 n = malloc(sizeof(struct nfsphys));
212 out_of_mem("storing nfsphys");
213 strcpy(n->dir, strtrim(name));
218 if (hash_store(nfsphys, id, n) == -1)
219 out_of_mem("storing nfsphys in hash table");
221 EXEC SQL CLOSE csr404;
223 dprintf("Counting quotas...\n");
224 EXEC SQL DECLARE csr405 CURSOR FOR
225 SELECT phys_id, quota FROM quota;
226 EXEC SQL OPEN csr405;
229 EXEC SQL FETCH csr405 INTO :id, :id2;
233 if (n = (struct nfsphys *) hash_lookup(nfsphys, id))
236 EXEC SQL CLOSE csr405;