]>
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 | ||
a7a7a3cc | 11 | static char phase1_qc_rcsid[] = "$Header$"; |
12 | ||
d2543f8c | 13 | |
14 | show_user_id(u) | |
15 | struct user *u; | |
16 | { | |
17 | printf("User %s (%s, status %d) has duplicate ID\n", | |
18 | u->login, u->fullname, u->status); | |
19 | return(0); | |
20 | } | |
21 | ||
22 | handle_duplicate_logins(sq) | |
23 | struct save_queue *sq; | |
24 | { | |
25 | struct user *u, *uu, *tmp; | |
26 | ||
27 | uu = (struct user *)0; | |
28 | while (sq_get_data(sq, &u)) { | |
29 | if (!strcmp(u->login, uu->login)) { | |
30 | if (uu->status == 1 || u->status == 0) { | |
31 | tmp = u; | |
32 | u = uu; | |
33 | uu = tmp; | |
34 | } | |
35 | printf("User %s (%s, status %d) and\n", | |
36 | u->login, u->fullname, u->status); | |
37 | printf("User %s (%s, status %d) have duplicate logins\n", | |
38 | uu->login, uu->fullname, uu->status); | |
39 | if (!strcmp(u->fullname, uu->fullname) && | |
40 | single_fix("Delete the second one")) { | |
41 | single_delete("users", "users_id", uu->users_id); | |
42 | } else if (single_fix("Unregister the second one")) | |
43 | ## { | |
44 | ## int id = uu->users_id, rowcount; | |
45 | ||
46 | ## replace users (login = "#"+text(users.uid), status = 0) | |
47 | ## where users.users_id = id | |
48 | ## inquire_equel(rowcount = "rowcount") | |
49 | if (rowcount > 0) | |
50 | printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); | |
51 | else | |
52 | printf("Not fixed\n"); | |
a7a7a3cc | 53 | modified("users"); |
d2543f8c | 54 | ## } |
55 | } else { | |
56 | uu = u; | |
57 | } | |
58 | } | |
59 | } | |
60 | ||
61 | fix_user_id(u) | |
62 | struct user *u; | |
63 | { | |
64 | u->users_id = generic_fix_id("users", "users_id", "login", | |
65 | u->users_id, u->login); | |
66 | } | |
67 | ||
68 | ||
69 | cant_fix(id) | |
70 | int id; | |
71 | { | |
72 | printf("Sorry, don't know how to fix that\n"); | |
73 | } | |
74 | ||
75 | show_mach_id(m) | |
76 | struct machine *m; | |
77 | { | |
78 | printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id); | |
79 | return(0); | |
80 | } | |
81 | ||
82 | show_mach_name(m) | |
83 | struct machine *m; | |
84 | { | |
85 | printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id); | |
86 | return(0); | |
87 | } | |
88 | ||
89 | fix_mach_id(m) | |
90 | struct machine *m; | |
91 | { | |
92 | m->mach_id = generic_fix_id("machine", "mach_id", "name", | |
93 | m->mach_id, m->name); | |
94 | } | |
95 | ||
96 | show_clu_id(c) | |
97 | struct cluster *c; | |
98 | { | |
99 | printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id); | |
100 | return(0); | |
101 | } | |
102 | ||
103 | show_clu_name(c) | |
104 | struct cluster *c; | |
105 | { | |
106 | printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id); | |
107 | return(0); | |
108 | } | |
109 | ||
110 | fix_clu_id(c) | |
111 | struct cluster *c; | |
112 | { | |
113 | c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name); | |
114 | } | |
115 | ||
116 | show_list_id(l) | |
117 | struct list *l; | |
118 | { | |
119 | printf("List %s has duplicate ID %d\n", l->name, l->list_id); | |
120 | return(0); | |
121 | } | |
122 | ||
123 | show_list_name(l) | |
124 | struct list *l; | |
125 | { | |
126 | printf("List %s (%d) has duplicate name\n", l->name, l->list_id); | |
127 | return(0); | |
128 | } | |
129 | ||
130 | fix_list_id(l) | |
131 | struct list *l; | |
132 | { | |
133 | l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name); | |
134 | } | |
135 | ||
136 | show_fs_id(f) | |
137 | struct filesys *f; | |
138 | { | |
139 | printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id); | |
140 | return(0); | |
141 | } | |
142 | ||
143 | fix_fs_id(f) | |
144 | struct filesys *f; | |
145 | { | |
146 | f->filsys_id = generic_fix_id("filesys", "filsys_id", "label", | |
147 | f->filsys_id, f->name); | |
148 | } | |
149 | ||
150 | ||
151 | show_np_id(n) | |
152 | struct nfsphys *n; | |
153 | { | |
154 | printf("NfsPhys %s:%s has duplicate ID %d\n", | |
155 | ((struct machine *)hash_lookup(machines, n->mach_id))->name, | |
156 | n->dir, n->nfsphys_id); | |
157 | return(0); | |
158 | } | |
159 | ||
160 | fix_np_id(n) | |
161 | struct nfsphys *n; | |
162 | { | |
163 | n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir", | |
164 | n->nfsphys_id, n->dir); | |
165 | } | |
166 | ||
167 | show_str_id(s) | |
168 | struct string *s; | |
169 | { | |
170 | printf("String %s has duplicate ID %d\n", s->name, s->string_id); | |
171 | return(0); | |
172 | } | |
173 | ||
174 | ||
175 | phase1() | |
176 | ##{ | |
177 | ## char name[33], name1[33], last[17], first[17], buf[257]; | |
178 | ## int id, id2, id3, aid, aid2, status; | |
179 | struct save_queue *sq; | |
180 | struct user *u; | |
181 | struct machine *m; | |
182 | struct list *l; | |
183 | struct cluster *c; | |
184 | struct string *s; | |
185 | struct filesys *f; | |
186 | struct nfsphys *n; | |
187 | ||
188 | printf("Phase 1 - Looking for duplicates\n"); | |
189 | ||
190 | dprintf("Loading users...\n"); | |
191 | sq = sq_create(); | |
192 | users = create_hash(10000); | |
193 | ## range of u is users | |
194 | ## retrieve (id = u.users_id, name = u.login, last = u.#last, | |
195 | ## first = u.#first, status = u.#status, buf = u.potype, | |
196 | ## id2 = u.pop_id, id3 = u.box_id) { | |
197 | u = (struct user *) malloc(sizeof(struct user)); | |
198 | strcpy(u->login, strtrim(name)); | |
199 | u->potype = buf[0]; | |
200 | sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); | |
201 | u->fullname = strsave(buf); | |
202 | u->status = status; | |
203 | u->users_id = id; | |
204 | switch (u->potype) { | |
205 | case 'P': | |
206 | u->pobox_id = id2; | |
207 | break; | |
208 | case 'S': | |
209 | u->pobox_id = id3; | |
210 | break; | |
211 | default: | |
212 | u->pobox_id = 0; | |
213 | } | |
214 | if (hash_store(users, id, u)) { | |
215 | sq_save_data(sq, hash_lookup(users, id)); | |
216 | sq_save_data(sq, u); | |
217 | } | |
218 | ## } | |
219 | generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0); | |
220 | ||
221 | if (!fast) { | |
222 | sq = sq_create(); | |
223 | ## retrieve (id = u.users_id) | |
224 | ## where u.login = users.login and u.tid != users.tid { | |
225 | sq_save_data(sq, hash_lookup(users, id)); | |
226 | ## } | |
227 | handle_duplicate_logins(sq); | |
228 | } | |
229 | ||
230 | dprintf("Loading machines...\n"); | |
231 | machines = create_hash(1000); | |
232 | sq = sq_create(); | |
233 | ## range of m is machine | |
234 | ## retrieve (id = m.mach_id, name = m.#name) { | |
235 | m = (struct machine *) malloc(sizeof(struct machine)); | |
236 | strcpy(m->name, strtrim(name)); | |
237 | m->mach_id = id; | |
238 | m->clucount = 0; | |
239 | if (hash_store(machines, id, m)) { | |
240 | sq_save_data(sq, hash_lookup(machines, id)); | |
241 | sq_save_data(sq, m); | |
242 | } | |
243 | ## } | |
244 | generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0); | |
245 | ||
246 | if (!fast) { | |
247 | sq = sq_create(); | |
248 | ## retrieve (id = m.mach_id) | |
249 | ## where m.#name = machine.#name and m.tid != machine.tid { | |
250 | sq_save_data(sq, hash_lookup(machines, id)); | |
251 | ## } | |
252 | generic_fix(sq, show_mach_name, "Change name", cant_fix, 0); | |
253 | } | |
254 | ||
255 | dprintf("Loading clusters...\n"); | |
256 | sq = sq_create(); | |
257 | clusters = create_hash(100); | |
258 | ## range of c is cluster | |
259 | ## retrieve (id = cluster.clu_id, name = cluster.#name) { | |
260 | c = (struct cluster *) malloc(sizeof(struct cluster)); | |
261 | strcpy(c->name, strtrim(name)); | |
262 | c->clu_id = id; | |
263 | if (hash_store(clusters, id, c)) { | |
264 | sq_save_data(sq, hash_lookup(clusters, id)); | |
265 | sq_save_data(sq, c); | |
266 | } | |
267 | ## } | |
268 | generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0); | |
269 | ||
270 | if (!fast) { | |
271 | sq = sq_create(); | |
272 | ## retrieve (id = c.clu_id) | |
273 | ## where c.#name = cluster.#name and c.tid != cluster.tid { | |
274 | sq_save_data(sq, hash_lookup(clusters, id)); | |
275 | ## } | |
276 | generic_fix(sq, show_clu_name, "Change name", cant_fix, 0); | |
277 | } | |
278 | ||
279 | dprintf("Loading lists...\n"); | |
280 | sq = sq_create(); | |
281 | lists = create_hash(10000); | |
282 | ## range of l is list | |
283 | ## retrieve (id = l.list_id, name = l.#name, | |
284 | ## aid = l.acl_id, buf = l.acl_type) { | |
285 | l = (struct list *) malloc(sizeof(struct list)); | |
286 | strcpy(l->name, strtrim(name)); | |
287 | l->acl_type = buf[0]; | |
288 | l->acl_id = aid; | |
289 | l->list_id = id; | |
290 | l->members = 0; | |
291 | if (hash_store(lists, id, l)) { | |
292 | sq_save_data(sq, hash_lookup(lists, id)); | |
293 | sq_save_data(sq, l); | |
294 | } | |
295 | ## } | |
296 | generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0); | |
297 | ||
298 | if (!fast) { | |
299 | sq = sq_create(); | |
300 | ## retrieve (id = l.list_id) | |
301 | ## where l.#name = list.#name and l.tid != list.tid { | |
302 | sq_save_data(sq, hash_lookup(lists, id)); | |
303 | ## } | |
304 | generic_fix(sq, show_list_name, "Change name", cant_fix, 0); | |
305 | } | |
306 | ||
307 | dprintf("Loading filesys...\n"); | |
308 | sq = sq_create(); | |
309 | filesys = create_hash(10000); | |
310 | ## retrieve (id = filesys.filsys_id, name = filesys.label, aid = filesys.owner, | |
311 | ## aid2 = filesys.owners, id2 = filesys.phys_id, | |
312 | ## id3 = filesys.mach_id, buf = filesys.type, | |
313 | ## name1 = filesys.#name) { | |
314 | f = (struct filesys *) malloc(sizeof(struct filesys)); | |
315 | strcpy(f->name, strtrim(name)); | |
316 | strcpy(f->dir, strtrim(name1)); | |
317 | f->filsys_id = id; | |
318 | f->owner = aid; | |
319 | f->owners = aid2; | |
320 | f->phys_id = id2; | |
321 | f->mach_id = id3; | |
322 | f->type = buf[0]; | |
323 | if (hash_store(filesys, id, f)) { | |
324 | sq_save_data(sq, hash_lookup(filesys, id)); | |
325 | sq_save_data(sq, f); | |
326 | } | |
327 | ## } | |
328 | generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0); | |
329 | ||
330 | dprintf("Loading nfsphys...\n"); | |
331 | sq = sq_create(); | |
332 | nfsphys = create_hash(500); | |
333 | ## retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir, | |
334 | ## id2 = nfsphys.mach_id, id3 = nfsphys.allocated) { | |
335 | n = (struct nfsphys *) malloc(sizeof(struct nfsphys)); | |
336 | strcpy(n->dir, strtrim(name)); | |
337 | n->mach_id = id2; | |
338 | n->nfsphys_id = id; | |
339 | n->allocated = id3; | |
340 | n->count = 0; | |
341 | if (hash_store(nfsphys, id, n)) { | |
342 | sq_save_data(sq, hash_lookup(nfsphys, id)); | |
343 | sq_save_data(sq, n); | |
344 | } | |
345 | ## } | |
346 | generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0); | |
347 | ||
348 | dprintf("Loading strings...\n"); | |
349 | sq = sq_create(); | |
350 | strings = create_hash(5000); | |
351 | ## range of s is strings | |
352 | ## retrieve (id = s.string_id, buf = s.string) { | |
353 | s = (struct string *) malloc(sizeof(struct string)); | |
354 | s->name = strsave(strtrim(buf)); | |
355 | s->string_id = id; | |
356 | s->refc = 0; | |
357 | if (hash_store(strings, id, s)) { | |
358 | sq_save_data(sq, hash_lookup(strings, id)); | |
359 | sq_save_data(sq, s); | |
360 | } | |
361 | ## } | |
362 | generic_delete(sq, show_str_id, "strings", "string_id", 0); | |
363 | ||
364 | if (!fast) { | |
365 | ## retrieve (id = s.string_id, buf = s.string) | |
366 | ## where s.string = strings.string and s.tid != strings.tid { | |
367 | printf("String %s(%d) is a duplicate!\n", strtrim(buf), id); | |
38e6880d | 368 | printf("Not fixing this error\n"); |
d2543f8c | 369 | ## } |
370 | } | |
371 | ##} | |
372 |