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>
11 EXEC SQL INCLUDE sqlca;
13 static char phase4_qc_rcsid[] = "$Header$";
16 count_boxes(id, u, boxes)
23 if (u->potype == 'P') {
24 if (i = (int) hash_lookup(boxes, u->pobox_id))
25 hash_store(boxes, u->pobox_id, i+1);
27 printf("User %s(%s) has pobox on non-POP server %d\n",
28 u->fullname, u->login, u->pobox_id);
29 printf("Not fixing this error\n");
35 check_box_counts(id, cnt, counts)
36 EXEC SQL BEGIN DECLARE SECTION;
38 EXEC SQL END DECLARE SECTION;
41 EXEC SQL BEGIN DECLARE SECTION;
43 EXEC SQL END DECLARE SECTION;
45 oldval = (int) hash_lookup(counts, id);
48 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
49 ((struct machine *) hash_lookup(machines, id))->name,
51 if (single_fix("Update", 1)) {
52 EXEC SQL UPDATE serverhosts SET value1 = :cnt
53 WHERE service='POP' AND mach_id = :id;
54 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
56 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
58 printf("Not fixed\n");
59 modified("serverhosts");
65 check_nfs_counts(id, n, hint)
66 EXEC SQL BEGIN DECLARE SECTION;
68 EXEC SQL END DECLARE SECTION;
71 EXEC SQL BEGIN DECLARE SECTION;
73 EXEC SQL END DECLARE SECTION;
76 if (n->allocated != val) {
77 printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
78 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
79 n->dir, n->allocated, val);
80 if (single_fix("Update", 1)) {
81 EXEC SQL UPDATE nfsphys SET allocated = :val
82 WHERE nfsphys_id = :id;
83 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
85 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
87 printf("Not fixed\n");
96 struct hash *boxes, *counts;
97 EXEC SQL BEGIN DECLARE SECTION;
99 EXEC SQL END DECLARE SECTION;
101 printf("Phase 4 - Checking counts\n");
103 dprintf("Doing POBoxes...\n");
104 boxes = create_hash(10);
105 counts = create_hash(10);
106 EXEC SQL DECLARE csr401 CURSOR FOR
107 SELECT mach_id, value1 FROM serverhosts
109 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
110 EXEC SQL OPEN csr401;
112 EXEC SQL FETCH csr401 INTO :id, :cnt;
113 if (sqlca.sqlcode != 0) {
114 ingerr(&sqlca.sqlcode);
118 hash_store(boxes, id, 1);
119 hash_store(counts, id, cnt);
121 EXEC SQL CLOSE csr401;
122 hash_step(users, count_boxes, boxes);
123 hash_step(boxes, check_box_counts, counts);
125 dprintf("Doing NFSphys...\n");
126 hash_step(nfsphys, check_nfs_counts, 0);
132 EXEC SQL BEGIN DECLARE SECTION;
133 int id, status, id2, id3;
134 char name[33], last[17], first[17], buf[257];
135 EXEC SQL END DECLARE SECTION;
136 struct save_queue *sq;
141 dprintf("Loading users...\n");
142 users = create_hash(10000);
143 EXEC SQL DECLARE csr402 CURSOR FOR
144 SELECT users_id, login, last, first, status,
145 potype, pop_id, box_id FROM users
147 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
148 EXEC SQL OPEN csr402;
150 EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status,
152 if (sqlca.sqlcode != 0) {
153 ingerr(&sqlca.sqlcode);
157 u = (struct user *) malloc(sizeof(struct user));
159 out_of_mem("storing users");
160 strcpy(u->login, strtrim(name));
162 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
163 u->fullname = strsave(buf);
176 hash_store(users, id, u);
178 EXEC SQL CLOSE csr402;
180 dprintf("Loading machines...\n");
181 machines = create_hash(1000);
182 EXEC SQL DECLARE csr403 CURSOR FOR
183 SELECT mach_id, name FROM machine;
184 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
185 EXEC SQL OPEN csr403;
187 EXEC SQL FETCH csr403 INTO :id, :name;
188 if (sqlca.sqlcode != 0) {
189 ingerr(&sqlca.sqlcode);
193 m = (struct machine *) malloc(sizeof(struct machine));
195 out_of_mem("storing machines");
196 strcpy(m->name, strtrim(name));
198 hash_store(machines, id, m);
200 EXEC SQL CLOSE csr403;
202 dprintf("Loading nfsphys...\n");
203 nfsphys = create_hash(500);
204 EXEC SQL DECLARE csr404 CURSOR FOR
205 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
206 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
207 EXEC SQL OPEN csr404;
209 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
210 if (sqlca.sqlcode != 0) {
211 ingerr(&sqlca.sqlcode);
215 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
217 out_of_mem("storing nfsphys");
218 strcpy(n->dir, strtrim(name));
223 hash_store(nfsphys, id, n);
225 EXEC SQL CLOSE csr404;
227 dprintf("Counting quotas...\n");
228 EXEC SQL DECLARE csr405 CURSOR FOR
229 SELECT phys_id, quota FROM quota;
230 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
231 EXEC SQL OPEN csr405;
233 EXEC SQL FETCH csr405 INTO :id, :id2;
234 if (sqlca.sqlcode != 0) {
235 ingerr(&sqlca.sqlcode);
239 if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) {
243 EXEC SQL CLOSE csr405;