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$";
15 EXEC SQL WHENEVER SQLERROR DO dbmserr();
17 count_boxes(id, u, boxes)
24 if (u->potype == 'P') {
25 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");
30 printf("User %s(%s) has pobox on non-POP server %d\n",
31 u->fullname, u->login, u->pobox_id);
32 printf("Not fixing this error\n");
38 check_box_counts(id, cnt, counts)
39 EXEC SQL BEGIN DECLARE SECTION;
41 EXEC SQL END DECLARE SECTION;
44 EXEC SQL BEGIN DECLARE SECTION;
46 EXEC SQL END DECLARE SECTION;
48 oldval = (int) hash_lookup(counts, id);
51 printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
52 ((struct machine *) hash_lookup(machines, id))->name,
54 if (single_fix("Update", 1)) {
55 EXEC SQL UPDATE serverhosts SET value1 = :cnt
56 WHERE service='POP' AND mach_id = :id;
57 rowcount = sqlca.sqlerrd[2];
59 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
61 printf("Not fixed\n");
62 modified("serverhosts");
68 check_nfs_counts(id, n, hint)
69 EXEC SQL BEGIN DECLARE SECTION;
71 EXEC SQL END DECLARE SECTION;
74 EXEC SQL BEGIN DECLARE SECTION;
76 EXEC SQL END DECLARE SECTION;
79 if (n->allocated != val) {
80 printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
81 ((struct machine *) hash_lookup(machines, n->mach_id))->name,
82 n->dir, n->allocated, val);
83 if (single_fix("Update", 1)) {
84 EXEC SQL UPDATE nfsphys SET allocated = :val
85 WHERE nfsphys_id = :id;
86 rowcount = sqlca.sqlerrd[2];
88 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
90 printf("Not fixed\n");
99 struct hash *boxes, *counts;
100 EXEC SQL BEGIN DECLARE SECTION;
102 EXEC SQL END DECLARE SECTION;
104 printf("Phase 4 - Checking counts\n");
106 dprintf("Doing POBoxes...\n");
107 boxes = create_hash(10);
108 counts = create_hash(10);
109 EXEC SQL DECLARE csr401 CURSOR FOR
110 SELECT mach_id, value1 FROM serverhosts
112 EXEC SQL OPEN csr401;
114 EXEC SQL FETCH csr401 INTO :id, :cnt;
115 if (sqlca.sqlcode != 0) break;
117 if( hash_store(boxes, id, 1) == -1 ) {
118 out_of_mem("storing poboxes");
120 if( hash_store(counts, id, cnt) == -1 ) {
121 out_of_mem("storing pobox counts? in hash table");
124 EXEC SQL CLOSE csr401;
125 hash_step(users, count_boxes, boxes);
126 hash_step(boxes, check_box_counts, counts);
128 dprintf("Doing NFSphys...\n");
129 hash_step(nfsphys, check_nfs_counts, 0);
135 EXEC SQL BEGIN DECLARE SECTION;
136 int id, status, id2, id3;
137 char name[33], last[17], first[17], buf[257];
138 EXEC SQL END DECLARE SECTION;
139 struct save_queue *sq;
144 dprintf("Loading users...\n");
145 users = create_hash(30000);
146 EXEC SQL DECLARE csr402 CURSOR FOR
147 SELECT users_id, login, last, first, status,
148 potype, pop_id, box_id FROM users
150 EXEC SQL OPEN csr402;
152 EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status,
154 if (sqlca.sqlcode != 0) break;
156 u = (struct user *) malloc(sizeof(struct user));
158 out_of_mem("storing users");
159 strcpy(u->login, strtrim(name));
161 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
162 u->fullname = strsave(buf);
175 if( hash_store(users, id, u) == -1 ) {
176 out_of_mem("storing users in hash table");
179 EXEC SQL CLOSE csr402;
181 dprintf("Loading machines...\n");
182 machines = create_hash(20000);
183 EXEC SQL DECLARE csr403 CURSOR FOR
184 SELECT mach_id, name FROM machine;
185 EXEC SQL OPEN csr403;
187 EXEC SQL FETCH csr403 INTO :id, :name;
188 if (sqlca.sqlcode != 0) break;
190 m = (struct machine *) malloc(sizeof(struct machine));
192 out_of_mem("storing machines");
193 strcpy(m->name, strtrim(name));
195 if( hash_store(machines, id, m) == -1 ) {
196 out_of_mem("storing users in hash table");
199 EXEC SQL CLOSE csr403;
201 dprintf("Loading nfsphys...\n");
202 nfsphys = create_hash(500);
203 EXEC SQL DECLARE csr404 CURSOR FOR
204 SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
205 EXEC SQL OPEN csr404;
207 EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
208 if (sqlca.sqlcode != 0) break;
210 n = (struct nfsphys *) 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");
222 EXEC SQL CLOSE csr404;
224 dprintf("Counting quotas...\n");
225 EXEC SQL DECLARE csr405 CURSOR FOR
226 SELECT phys_id, quota FROM quota;
227 EXEC SQL OPEN csr405;
229 EXEC SQL FETCH csr405 INTO :id, :id2;
230 if (sqlca.sqlcode != 0) break;
232 if (n = (struct nfsphys *) hash_lookup(nfsphys, id)) {
236 EXEC SQL CLOSE csr405;