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