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