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