]>
Commit | Line | Data |
---|---|---|
68bbc9c3 | 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 <moira.h> | |
ab05f33a | 10 | #include <stdio.h> |
5eaef520 | 11 | #include <stdlib.h> |
68bbc9c3 | 12 | #include "dbck.h" |
208a4f4a | 13 | EXEC SQL INCLUDE sqlca; |
14 | ||
68bbc9c3 | 15 | static char phase1_qc_rcsid[] = "$Header$"; |
16 | ||
4b9e5c72 | 17 | EXEC SQL WHENEVER SQLERROR DO dbmserr(); |
68bbc9c3 | 18 | |
5eaef520 | 19 | int show_user_id(struct user *u) |
68bbc9c3 | 20 | { |
5eaef520 | 21 | printf("User %s (%s, status %d) has duplicate ID\n", |
22 | u->login, u->fullname, u->status); | |
23 | return 0; | |
68bbc9c3 | 24 | } |
25 | ||
5eaef520 | 26 | handle_duplicate_logins(struct save_queue *sq) |
68bbc9c3 | 27 | { |
5eaef520 | 28 | struct user *u, *uu, *tmp; |
29 | ||
30 | uu = NULL; | |
31 | if (sq_get_data(sq, &uu)) | |
32 | { | |
33 | while (sq_get_data(sq, &u)) | |
34 | { | |
35 | if (!strcmp(u->login, uu->login)) | |
36 | { | |
37 | if (uu->status == 1 || u->status == 0) | |
38 | { | |
39 | tmp = u; | |
40 | u = uu; | |
41 | uu = tmp; | |
42 | } | |
43 | printf("User %s (%s, status %d) and\n", | |
44 | u->login, u->fullname, u->status); | |
45 | printf("User %s (%s, status %d) have duplicate logins\n", | |
46 | uu->login, uu->fullname, uu->status); | |
47 | if (!strcmp(u->fullname, uu->fullname) && | |
48 | single_fix("Delete the second one")) | |
68bbc9c3 | 49 | single_delete("users", "users_id", uu->users_id); |
5eaef520 | 50 | else if (single_fix("Unregister the second one")) |
51 | { | |
52 | EXEC SQL BEGIN DECLARE SECTION; | |
53 | int id = uu->users_id, rowcount; | |
54 | EXEC SQL END DECLARE SECTION; | |
55 | ||
56 | EXEC SQL UPDATE users | |
57 | SET login = '#' || CHAR(users.unix_uid), status = 0 | |
58 | WHERE users_id = :id; | |
59 | rowcount = sqlca.sqlerrd[2]; | |
60 | if (rowcount > 0) | |
61 | { | |
62 | printf("%d entr%s fixed\n", rowcount, | |
63 | rowcount == 1 ? "y" : "ies"); | |
64 | } | |
65 | else | |
66 | printf("Not fixed\n"); | |
67 | modified("users"); | |
68 | } | |
69 | } | |
70 | else | |
68bbc9c3 | 71 | uu = u; |
72 | } | |
73 | } | |
74 | } | |
75 | ||
5eaef520 | 76 | fix_user_id(struct user *u) |
68bbc9c3 | 77 | { |
5eaef520 | 78 | u->users_id = generic_fix_id("users", "users_id", "login", |
79 | u->users_id, u->login); | |
68bbc9c3 | 80 | } |
81 | ||
82 | ||
5eaef520 | 83 | cant_fix(int id) |
68bbc9c3 | 84 | { |
5eaef520 | 85 | printf("Sorry, don't know how to fix that\n"); |
68bbc9c3 | 86 | } |
87 | ||
5eaef520 | 88 | int show_mach_id(struct machine *m) |
68bbc9c3 | 89 | { |
5eaef520 | 90 | printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id); |
91 | return 0; | |
68bbc9c3 | 92 | } |
93 | ||
5eaef520 | 94 | int show_mach_name(struct machine *m) |
68bbc9c3 | 95 | { |
5eaef520 | 96 | printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id); |
97 | return 0; | |
68bbc9c3 | 98 | } |
99 | ||
5eaef520 | 100 | fix_mach_id(struct machine *m) |
68bbc9c3 | 101 | { |
5eaef520 | 102 | m->mach_id = generic_fix_id("machine", "mach_id", "name", |
103 | m->mach_id, m->name); | |
68bbc9c3 | 104 | } |
105 | ||
5eaef520 | 106 | int show_snet_name(struct subnet *s) |
235fd664 | 107 | { |
5eaef520 | 108 | printf("Subnet %s (%d) has duplicate name\n", s->name, s->snet_id); |
109 | return 0; | |
235fd664 | 110 | } |
111 | ||
5eaef520 | 112 | int show_clu_id(struct cluster *c) |
68bbc9c3 | 113 | { |
5eaef520 | 114 | printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id); |
115 | return 0; | |
68bbc9c3 | 116 | } |
117 | ||
5eaef520 | 118 | int show_clu_name(struct cluster *c) |
68bbc9c3 | 119 | { |
5eaef520 | 120 | printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id); |
121 | return 0; | |
68bbc9c3 | 122 | } |
123 | ||
5eaef520 | 124 | fix_clu_id(struct cluster *c) |
68bbc9c3 | 125 | { |
5eaef520 | 126 | c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name); |
68bbc9c3 | 127 | } |
128 | ||
5eaef520 | 129 | int show_list_id(struct list *l) |
68bbc9c3 | 130 | { |
5eaef520 | 131 | printf("List %s has duplicate ID %d\n", l->name, l->list_id); |
132 | return 0; | |
68bbc9c3 | 133 | } |
134 | ||
5eaef520 | 135 | int show_list_name(struct list *l) |
68bbc9c3 | 136 | { |
5eaef520 | 137 | printf("List %s (%d) has duplicate name\n", l->name, l->list_id); |
138 | return 0; | |
68bbc9c3 | 139 | } |
140 | ||
5eaef520 | 141 | fix_list_id(struct list *l) |
68bbc9c3 | 142 | { |
5eaef520 | 143 | l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name); |
68bbc9c3 | 144 | } |
145 | ||
5eaef520 | 146 | int show_fs_id(struct filesys *f) |
68bbc9c3 | 147 | { |
5eaef520 | 148 | printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id); |
149 | return 0; | |
68bbc9c3 | 150 | } |
151 | ||
5eaef520 | 152 | fix_fs_id(struct filesys *f) |
68bbc9c3 | 153 | { |
5eaef520 | 154 | f->filsys_id = generic_fix_id("filesys", "filsys_id", "label", |
155 | f->filsys_id, f->name); | |
68bbc9c3 | 156 | } |
157 | ||
5eaef520 | 158 | int show_fs_name(struct filesys *fs) |
235fd664 | 159 | { |
5eaef520 | 160 | printf("Filesys %s (%d) has duplicate name\n", fs->name, fs->filsys_id); |
161 | return 0; | |
235fd664 | 162 | } |
163 | ||
5eaef520 | 164 | int show_np_id(struct nfsphys *n) |
68bbc9c3 | 165 | { |
5eaef520 | 166 | printf("NfsPhys %s:%s has duplicate ID %d\n", |
167 | ((struct machine *)hash_lookup(machines, n->mach_id))->name, | |
168 | n->dir, n->nfsphys_id); | |
169 | return 0; | |
68bbc9c3 | 170 | } |
171 | ||
5eaef520 | 172 | fix_np_id(struct nfsphys *n) |
68bbc9c3 | 173 | { |
5eaef520 | 174 | n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir", |
175 | n->nfsphys_id, n->dir); | |
68bbc9c3 | 176 | } |
177 | ||
5eaef520 | 178 | int show_str_id(struct string *s) |
68bbc9c3 | 179 | { |
5eaef520 | 180 | printf("String %s has duplicate ID %d\n", s->name, s->string_id); |
181 | return 0; | |
68bbc9c3 | 182 | } |
183 | ||
5eaef520 | 184 | int print_str_id(int id) |
ab05f33a | 185 | { |
186 | printf("String %d is a duplicate\n", id); | |
5eaef520 | 187 | return 0; |
ab05f33a | 188 | } |
189 | ||
5eaef520 | 190 | print_dup_map(int key, int data, char *hint) |
ab05f33a | 191 | { |
5eaef520 | 192 | printf("String %d is a duplicate of string %d\n", key, data); |
ab05f33a | 193 | } |
68bbc9c3 | 194 | |
5eaef520 | 195 | phase1(void) |
208a4f4a | 196 | { |
5eaef520 | 197 | EXEC SQL BEGIN DECLARE SECTION; |
198 | char name[81], name1[81], last[17], first[17], buf[257]; | |
199 | int id, id1, id2, id3, aid, aid2, status; | |
200 | int sid, sid2, sid3, sid4, sid5; | |
201 | EXEC SQL END DECLARE SECTION; | |
202 | int i, q, retval, tmp; | |
203 | struct save_queue *sq; | |
204 | struct user *u; | |
205 | struct machine *m; | |
206 | struct subnet *sn; | |
207 | struct list *l; | |
208 | struct cluster *c; | |
209 | struct string *s; | |
210 | struct filesys *f; | |
211 | struct nfsphys *n; | |
212 | ||
213 | printf("Phase 1 - Looking for duplicates\n"); | |
214 | ||
215 | /* self-join strings table on "string" to get duplicate strings, then | |
216 | build a duplicates table to merge them. */ | |
217 | ||
218 | dprintf("Looking for duplicate strings...\n"); | |
219 | string_dups = create_hash(100); | |
220 | if (!string_dups) | |
221 | out_of_mem("storing duplicate strings"); | |
222 | ||
223 | EXEC SQL DECLARE csr116 CURSOR FOR | |
224 | SELECT s1.string_id, s2.string_id FROM strings s1, strings s2 | |
225 | WHERE s1.string = s2.string and s1.string_id < s2.string_id; | |
226 | EXEC SQL OPEN csr116; | |
227 | /* The SELECT gives us two columns, both with non-negative integers. | |
228 | * The number in the left column is always the smaller of the two, | |
229 | * and each row includes string IDs for identical strings. We use | |
230 | * them to make a mapping from id-to-delete to id-to-keep for all | |
231 | * superflous IDs. | |
232 | */ | |
233 | q = 0; | |
234 | while (1) | |
235 | { | |
236 | EXEC SQL FETCH csr116 INTO :id1, :id2; | |
237 | if (sqlca.sqlcode) | |
238 | break; | |
239 | q++; | |
240 | /* If id2 is already stored, skip this row. */ | |
241 | i = int_hash_lookup(string_dups, id2); | |
242 | if (i > 0) | |
243 | continue; | |
244 | /* Follow the chain of id1 equivalent IDs back to the lowest one. */ | |
245 | id = id1; | |
246 | while ((tmp = int_hash_lookup(string_dups, id)) > 0) | |
247 | id = tmp; | |
248 | int_hash_store(string_dups, id2, id); | |
ab05f33a | 249 | } |
5eaef520 | 250 | EXEC SQL CLOSE csr116; |
251 | dprintf("found %d duplicates\n", q); | |
252 | int_hash_step(string_dups, print_dup_map, NULL); | |
253 | /* We don't want to delete the duplicates now because if the dbck | |
254 | is cancelled, a LOT of state will be lost. So, we'll just let | |
255 | them not get marked as used and then phase3 will clean them up */ | |
256 | ||
257 | dprintf("Loading strings...\n"); | |
258 | sq = sq_create(); | |
259 | strings = create_hash(75000); | |
260 | if (!sq || !strings) | |
261 | out_of_mem("loading strings"); | |
262 | ||
263 | EXEC SQL DECLARE csr101 CURSOR FOR | |
264 | SELECT string_id, string FROM strings ORDER BY string_id; | |
265 | EXEC SQL OPEN csr101; | |
266 | q = 0; | |
267 | while (1) | |
268 | { | |
269 | EXEC SQL FETCH csr101 INTO :id, :buf; | |
270 | if (sqlca.sqlcode) | |
271 | break; | |
272 | q++; | |
273 | s = malloc(sizeof(struct string)); | |
274 | if (!s) | |
275 | out_of_mem("storing strings"); | |
276 | s->name = strsave(strtrim(buf)); | |
277 | s->string_id = id; | |
278 | s->refc = 0; | |
279 | retval = hash_store(strings, id, s); | |
280 | if (retval == -1) | |
281 | out_of_mem("storing strings in hash table"); | |
282 | else if (retval == 1) /* duplicate string_id */ | |
283 | { | |
ab05f33a | 284 | sq_save_data(sq, hash_lookup(strings, id)); |
285 | sq_save_data(sq, s); | |
68bbc9c3 | 286 | } |
208a4f4a | 287 | } |
5eaef520 | 288 | EXEC SQL CLOSE csr101; |
289 | /* keep string id 0 (the empty string) even if unreferenced */ | |
290 | string_check(0); | |
291 | ||
292 | printf("Loaded %d strings\n", q); | |
293 | ||
294 | dprintf("Loading users...\n"); | |
295 | sq = sq_create(); | |
296 | users = create_hash(30000); | |
297 | if (!sq || !users) | |
298 | out_of_mem("loading users"); | |
299 | ||
300 | EXEC SQL DECLARE csr102 CURSOR FOR | |
301 | SELECT users_id, login, last, first, status, potype, pop_id, box_id, | |
302 | modby, fmodby, pmodby, comments, sigwho FROM users | |
303 | ORDER BY users_id; | |
304 | EXEC SQL OPEN csr102; | |
305 | while (1) | |
306 | { | |
307 | EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status, | |
308 | :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5; | |
309 | if (sqlca.sqlcode) | |
310 | break; | |
311 | ||
312 | u = malloc(sizeof(struct user)); | |
313 | if (!u) | |
314 | out_of_mem("storing users"); | |
315 | strcpy(u->login, strtrim(name)); | |
316 | u->potype = buf[0]; | |
317 | sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); | |
318 | u->fullname = strsave(buf); | |
319 | u->status = status; | |
320 | u->users_id = id; | |
321 | u->modby = sid; | |
322 | u->fmodby = sid2; | |
323 | u->pmodby = sid3; | |
324 | u->comment = sid4; | |
325 | u->sigwho = sid5; | |
326 | switch (u->potype) | |
327 | { | |
68bbc9c3 | 328 | case 'P': |
5eaef520 | 329 | u->pobox_id = id2; |
330 | break; | |
68bbc9c3 | 331 | case 'S': |
5eaef520 | 332 | /* If potype is SMTP, box_id is a string_id for the strings tbl */ |
333 | u->pobox_id = id3; | |
334 | break; | |
68bbc9c3 | 335 | default: |
5eaef520 | 336 | u->pobox_id = 0; |
68bbc9c3 | 337 | } |
5eaef520 | 338 | retval = hash_store(users, id, u); |
339 | if (retval == -1) | |
340 | out_of_mem("storing users in hash table"); | |
341 | else if (retval == 1) | |
342 | { | |
343 | sq_save_data(sq, hash_lookup(users, id)); | |
344 | sq_save_data(sq, u); | |
68bbc9c3 | 345 | } |
208a4f4a | 346 | } |
5eaef520 | 347 | EXEC SQL CLOSE csr102; |
348 | ||
349 | generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0); | |
350 | ||
351 | if (!fast) | |
352 | { | |
353 | sq = sq_create(); | |
354 | if (!sq) | |
355 | out_of_mem("finding duplicate logins"); | |
356 | ||
357 | EXEC SQL DECLARE csr103 CURSOR FOR | |
358 | SELECT u1.users_id FROM users u1, users u2 | |
359 | WHERE u1.login = u2.login and u1.rowid != u2.rowid; | |
360 | EXEC SQL OPEN csr103; | |
361 | while (1) | |
362 | { | |
363 | EXEC SQL FETCH csr103 INTO :id; | |
364 | if (sqlca.sqlcode) | |
365 | break; | |
366 | sq_save_data(sq, hash_lookup(users, id)); | |
208a4f4a | 367 | } |
5eaef520 | 368 | EXEC SQL CLOSE csr103; |
369 | handle_duplicate_logins(sq); | |
68bbc9c3 | 370 | } |
371 | ||
5eaef520 | 372 | if (!fast) |
373 | { | |
374 | dprintf("Scanning krbmap...\n"); | |
375 | ||
376 | EXEC SQL DECLARE csr113 CURSOR FOR | |
377 | SELECT k1.users_id FROM krbmap k1, krbmap k2 | |
378 | WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid; | |
379 | EXEC SQL OPEN csr113; | |
380 | while (1) | |
381 | { | |
382 | EXEC SQL FETCH csr113 INTO :id; | |
383 | if (sqlca.sqlcode) | |
384 | break; | |
ab05f33a | 385 | |
5eaef520 | 386 | printf("User %d is in the krbmap more than once!\n", id); |
387 | printf("Not fixing this error\n"); | |
ab05f33a | 388 | } |
5eaef520 | 389 | EXEC SQL CLOSE csr113; |
390 | ||
391 | EXEC SQL DECLARE csr114 CURSOR FOR | |
392 | SELECT k1.string_id FROM krbmap k1, krbmap k2 | |
393 | WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid; | |
394 | EXEC SQL OPEN csr114; | |
395 | while (1) | |
396 | { | |
397 | EXEC SQL FETCH csr114 INTO :id; | |
398 | if (sqlca.sqlcode) | |
399 | break; | |
400 | ||
401 | printf("Principal %d is in the krbmap more than once!\n", id); | |
402 | printf("Not fixing this error\n"); | |
ab05f33a | 403 | } |
5eaef520 | 404 | EXEC SQL CLOSE csr114; |
ab05f33a | 405 | } |
406 | ||
5eaef520 | 407 | dprintf("Loading machines...\n"); |
408 | sq = sq_create(); | |
409 | machines = create_hash(20000); | |
410 | if (!sq || !machines) | |
411 | out_of_mem("loading machines"); | |
412 | ||
413 | EXEC SQL DECLARE csr104 CURSOR FOR | |
414 | SELECT mach_id, name, snet_id, owner_type, owner_id, | |
415 | acomment, ocomment, creator, modby | |
416 | FROM machine ORDER BY mach_id; | |
417 | EXEC SQL OPEN csr104; | |
418 | while (1) | |
419 | { | |
420 | EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2, | |
421 | :sid3, :sid4, :sid; | |
422 | if (sqlca.sqlcode) | |
423 | break; | |
424 | ||
425 | m = malloc(sizeof(struct machine)); | |
426 | if (!m) | |
427 | out_of_mem("storing machines"); | |
428 | strcpy(m->name, strtrim(name)); | |
429 | m->owner_type = buf[0]; | |
430 | m->owner_id = id3; | |
431 | m->snet_id = id2; | |
432 | m->mach_id = id; | |
433 | m->clucount = 0; | |
434 | m->acomment = sid2; | |
435 | m->ocomment = sid3; | |
436 | m->creator = sid4; | |
437 | m->modby = sid; | |
438 | retval = hash_store(machines, id, m); | |
439 | if (retval == -1) | |
440 | out_of_mem("storing machines in hash table"); | |
441 | else if (retval == 1) | |
442 | { | |
443 | sq_save_data(sq, hash_lookup(machines, id)); | |
444 | sq_save_data(sq, m); | |
68bbc9c3 | 445 | } |
208a4f4a | 446 | } |
5eaef520 | 447 | EXEC SQL CLOSE csr104; |
448 | generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0); | |
449 | ||
450 | if (!fast) | |
451 | { | |
452 | sq = sq_create(); | |
453 | if (!sq) | |
454 | out_of_mem("looking for duplicate machine names"); | |
455 | ||
456 | EXEC SQL DECLARE csr105 CURSOR FOR | |
457 | SELECT m1.mach_id FROM machine m1, machine m2 | |
458 | WHERE m1.name = m2.name AND m1.rowid != m2.rowid; | |
459 | EXEC SQL OPEN csr105; | |
460 | while (1) | |
461 | { | |
462 | EXEC SQL FETCH csr105 INTO :id; | |
463 | if (sqlca.sqlcode) | |
464 | break; | |
465 | ||
466 | sq_save_data(sq, hash_lookup(machines, id)); | |
208a4f4a | 467 | } |
5eaef520 | 468 | EXEC SQL CLOSE csr105; |
469 | generic_fix(sq, show_mach_name, "Change name", cant_fix, 0); | |
470 | ||
471 | EXEC SQL DECLARE csr_hal1 CURSOR FOR | |
472 | SELECT h1.name, m1.mach_id, m2.mach_id | |
473 | FROM hostalias h1, machine m1, hostalias h2, machine m2 | |
474 | WHERE h1.name = h2.name AND h1.mach_id != h2.mach_id | |
475 | AND m1.mach_id = h1.mach_id AND m2.mach_id = h2.mach_id; | |
476 | EXEC SQL OPEN csr_hal1; | |
477 | while (1) | |
478 | { | |
ab05f33a | 479 | EXEC SQL FETCH csr_hal1 INTO :name, :id1, :id2; |
5eaef520 | 480 | if (sqlca.sqlcode) |
481 | break; | |
ab05f33a | 482 | printf("Aliases for machines %d and %d have duplicate name %s\n", |
483 | id1, id2, strtrim(name)); | |
a8e78b23 | 484 | cant_fix(0); |
ab05f33a | 485 | } |
5eaef520 | 486 | EXEC SQL CLOSE csr_hal1; |
487 | ||
488 | EXEC SQL DECLARE csr_hal2 CURSOR FOR | |
489 | SELECT h1.name, m1.mach_id, m2.mach_id | |
490 | FROM hostalias h1, machine m1, machine m2 | |
491 | WHERE h1.name = m1.name AND h1.mach_id = m2.mach_id; | |
492 | EXEC SQL OPEN csr_hal2; | |
493 | while (1) | |
494 | { | |
495 | EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2; | |
496 | if (sqlca.sqlcode) | |
497 | break; | |
498 | printf("Machine %d has alias %s that conflicts with machine %d\n", | |
499 | id2, strtrim(name), id1); | |
a8e78b23 | 500 | cant_fix(0); |
5eaef520 | 501 | } |
502 | EXEC SQL CLOSE csr_hal2; | |
772b7afc | 503 | } |
235fd664 | 504 | |
5eaef520 | 505 | dprintf("Loading subnets...\n"); |
506 | subnets = create_hash(254); | |
507 | if (!subnets) | |
508 | out_of_mem("loading subnets"); | |
509 | ||
510 | EXEC SQL DECLARE csr115 CURSOR FOR | |
511 | SELECT snet_id, name, owner_type, owner_id, modby from subnet; | |
512 | EXEC SQL OPEN csr115; | |
513 | while (1) | |
514 | { | |
515 | EXEC SQL FETCH csr115 INTO :id, :name, :buf, :id2, :sid; | |
516 | if (sqlca.sqlcode) | |
517 | break; | |
518 | ||
519 | sn = malloc(sizeof(struct machine)); | |
520 | if (!sn) | |
521 | out_of_mem("storing subnets"); | |
522 | strcpy(sn->name, strtrim(name)); | |
523 | sn->owner_type = buf[0]; | |
524 | sn->owner_id = id2; | |
525 | sn->snet_id = id; | |
526 | sn->modby = sid; | |
527 | retval = hash_store(subnets, id, sn); | |
528 | if (retval == -1) | |
529 | out_of_mem("storing subnets in hash table"); | |
530 | else if (retval == 1) | |
531 | { | |
532 | printf("Duplicate subnet ID: %d (%s)\n", id, name); | |
533 | /* should add code to delete */ | |
534 | cant_fix(0); | |
535 | } | |
536 | } | |
537 | EXEC SQL CLOSE csr115; | |
538 | ||
539 | if (!fast) | |
540 | { | |
541 | sq = sq_create(); | |
542 | if (!sq) | |
543 | out_of_mem("looking for duplicate subnet names"); | |
544 | ||
545 | EXEC SQL DECLARE csr117 CURSOR FOR | |
546 | SELECT s1.snet_id FROM subnet s1, subnet s2 | |
547 | WHERE s1.name = s2.name AND s1.rowid != s2.rowid; | |
548 | EXEC SQL OPEN csr117; | |
549 | while (1) | |
550 | { | |
551 | EXEC SQL FETCH csr117 INTO :id; | |
552 | if (sqlca.sqlcode) | |
553 | break; | |
235fd664 | 554 | |
5eaef520 | 555 | sq_save_data(sq, hash_lookup(subnets, id)); |
235fd664 | 556 | } |
5eaef520 | 557 | EXEC SQL CLOSE csr117; |
558 | generic_fix(sq, show_snet_name, "Change name", cant_fix, 0); | |
235fd664 | 559 | } |
5eaef520 | 560 | |
561 | dprintf("Loading clusters...\n"); | |
562 | sq = sq_create(); | |
563 | clusters = create_hash(100); | |
564 | if (!sq || !clusters) | |
565 | out_of_mem("loading clusters"); | |
566 | ||
567 | EXEC SQL DECLARE csr106 CURSOR FOR | |
568 | SELECT clu_id, name, modby FROM clusters; | |
569 | EXEC SQL OPEN csr106; | |
570 | while (1) | |
571 | { | |
572 | EXEC SQL FETCH csr106 INTO :id, :name, :sid; | |
573 | if (sqlca.sqlcode) | |
574 | break; | |
575 | ||
576 | c = malloc(sizeof(struct cluster)); | |
577 | if (!c) | |
578 | out_of_mem("storing clusters"); | |
579 | strcpy(c->name, strtrim(name)); | |
580 | c->clu_id = id; | |
581 | c->modby = sid; | |
582 | retval = hash_store(clusters, id, c); | |
583 | if (retval == -1) | |
584 | out_of_mem("storing clusters in hash table"); | |
585 | else if (retval == 1) | |
586 | { | |
587 | sq_save_data(sq, hash_lookup(clusters, id)); | |
588 | sq_save_data(sq, c); | |
68bbc9c3 | 589 | } |
208a4f4a | 590 | } |
5eaef520 | 591 | EXEC SQL CLOSE csr106; |
592 | generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0); | |
593 | ||
594 | if (!fast) | |
595 | { | |
596 | sq = sq_create(); | |
597 | if (!sq) | |
598 | out_of_mem("looking for duplicate cluster names"); | |
599 | ||
600 | EXEC SQL DECLARE csr107 CURSOR FOR | |
601 | SELECT c1.clu_id FROM clusters c1, clusters c2 | |
602 | WHERE c1.name = c2.name AND c1.rowid != c2.rowid; | |
603 | EXEC SQL OPEN csr107; | |
604 | while (1) | |
605 | { | |
606 | EXEC SQL FETCH csr107 INTO :id; | |
607 | if (sqlca.sqlcode) | |
608 | break; | |
609 | ||
610 | sq_save_data(sq, hash_lookup(clusters, id)); | |
208a4f4a | 611 | } |
5eaef520 | 612 | EXEC SQL CLOSE csr107; |
613 | generic_fix(sq, show_clu_name, "Change name", cant_fix, 0); | |
68bbc9c3 | 614 | } |
615 | ||
5eaef520 | 616 | dprintf("Loading lists...\n"); |
617 | sq = sq_create(); | |
618 | lists = create_hash(50000); | |
619 | if (!sq || !lists) | |
620 | out_of_mem("loading lists"); | |
621 | ||
622 | EXEC SQL DECLARE csr108 CURSOR FOR | |
623 | SELECT list_id, name, acl_id, acl_type, modby FROM list | |
624 | ORDER BY list_id; | |
625 | EXEC SQL OPEN csr108; | |
626 | while (1) | |
627 | { | |
628 | EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid; | |
629 | if (sqlca.sqlcode) | |
630 | break; | |
631 | l = malloc(sizeof(struct list)); | |
632 | if (!l) | |
633 | out_of_mem("storing lists"); | |
634 | strcpy(l->name, strtrim(name)); | |
635 | l->acl_type = buf[0]; | |
636 | l->acl_id = aid; | |
637 | l->list_id = id; | |
638 | l->members = 0; | |
639 | retval = hash_store(lists, id, l); | |
640 | if (retval == -1) | |
641 | out_of_mem("storing lists in hash table"); | |
642 | else if (retval == 1) | |
643 | { | |
644 | sq_save_data(sq, hash_lookup(lists, id)); | |
645 | sq_save_data(sq, l); | |
68bbc9c3 | 646 | } |
208a4f4a | 647 | } |
5eaef520 | 648 | EXEC SQL CLOSE csr108; |
649 | generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0); | |
650 | ||
651 | if (!fast) | |
652 | { | |
653 | sq = sq_create(); | |
654 | if (!sq) | |
655 | out_of_mem("looking for duplicate list names"); | |
656 | ||
657 | EXEC SQL DECLARE csr109 CURSOR FOR | |
658 | SELECT l1.list_id FROM list l1, list l2 | |
659 | WHERE l1.name = l2.name AND l1.rowid != l2.rowid; | |
660 | EXEC SQL OPEN csr109; | |
661 | while (1) | |
662 | { | |
663 | EXEC SQL FETCH csr109 INTO :id; | |
664 | if (sqlca.sqlcode) | |
665 | break; | |
666 | ||
667 | sq_save_data(sq, hash_lookup(lists, id)); | |
208a4f4a | 668 | } |
5eaef520 | 669 | EXEC SQL CLOSE csr109; |
670 | generic_fix(sq, show_list_name, "Change name", cant_fix, 0); | |
68bbc9c3 | 671 | } |
672 | ||
5eaef520 | 673 | dprintf("Loading filesys...\n"); |
674 | sq = sq_create(); | |
675 | filesys = create_hash(30000); | |
676 | if (!sq || !filesys) | |
677 | out_of_mem("loading filesys"); | |
678 | ||
679 | EXEC SQL DECLARE csr110 CURSOR FOR | |
680 | SELECT filsys_id, label, owner, owners, phys_id, mach_id, | |
681 | type, name, modby FROM filesys ORDER BY filsys_id; | |
682 | EXEC SQL OPEN csr110; | |
683 | while (1) | |
684 | { | |
685 | EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3, | |
686 | :buf, :name1, :sid; | |
687 | if (sqlca.sqlcode) | |
688 | break; | |
689 | ||
690 | f = malloc(sizeof(struct filesys)); | |
691 | if (!f) | |
692 | out_of_mem("storing filesystems"); | |
693 | strcpy(f->name, strtrim(name)); | |
694 | strcpy(f->dir, strtrim(name1)); | |
695 | f->filsys_id = id; | |
696 | f->owner = aid; | |
697 | f->owners = aid2; | |
698 | f->phys_id = id2; | |
699 | f->mach_id = id3; | |
700 | f->type = buf[0]; | |
701 | retval = hash_store(filesys, id, f); | |
702 | if (retval == -1) | |
703 | out_of_mem("storing filesys in hash table"); | |
704 | else if (retval == 1) | |
705 | { | |
706 | sq_save_data(sq, hash_lookup(filesys, id)); | |
707 | sq_save_data(sq, f); | |
68bbc9c3 | 708 | } |
208a4f4a | 709 | } |
5eaef520 | 710 | EXEC SQL CLOSE csr110; |
711 | ||
712 | generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0); | |
713 | ||
714 | if (!fast) | |
715 | { | |
716 | sq = sq_create(); | |
717 | if (!sq) | |
718 | out_of_mem("looking for duplicate filesys names"); | |
719 | ||
720 | EXEC SQL DECLARE csr118 CURSOR FOR | |
721 | SELECT fs1.filsys_id FROM filesys fs1, filesys fs2 | |
722 | WHERE fs1.label = fs2.label AND fs1.rowid != fs2.rowid; | |
723 | EXEC SQL OPEN csr118; | |
724 | while (1) | |
725 | { | |
726 | EXEC SQL FETCH csr118 INTO :id; | |
727 | if (sqlca.sqlcode) | |
728 | break; | |
729 | ||
730 | sq_save_data(sq, hash_lookup(filesys, id)); | |
235fd664 | 731 | } |
5eaef520 | 732 | EXEC SQL CLOSE csr118; |
733 | generic_fix(sq, show_fs_name, "Change name", cant_fix, 0); | |
235fd664 | 734 | } |
735 | ||
5eaef520 | 736 | dprintf("Loading nfsphys...\n"); |
737 | sq = sq_create(); | |
738 | nfsphys = create_hash(500); | |
739 | if (!sq || !nfsphys) | |
740 | out_of_mem("loading nfsphs"); | |
741 | ||
742 | EXEC SQL DECLARE csr111 CURSOR FOR | |
743 | SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys; | |
744 | EXEC SQL OPEN csr111; | |
745 | while (1) | |
746 | { | |
747 | EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid; | |
748 | if (sqlca.sqlcode) | |
749 | break; | |
750 | ||
751 | n = malloc(sizeof(struct nfsphys)); | |
752 | if (!n) | |
753 | out_of_mem("storing nfsphys"); | |
754 | strcpy(n->dir, strtrim(name)); | |
755 | n->mach_id = id2; | |
756 | n->nfsphys_id = id; | |
757 | n->allocated = id3; | |
758 | n->count = 0; | |
759 | retval = hash_store(nfsphys, id, n); | |
760 | if (retval == -1) | |
761 | out_of_mem("storing nfsphys in hash table"); | |
762 | else if (retval == 1) | |
763 | { | |
764 | sq_save_data(sq, hash_lookup(nfsphys, id)); | |
765 | sq_save_data(sq, n); | |
68bbc9c3 | 766 | } |
208a4f4a | 767 | } |
5eaef520 | 768 | EXEC SQL CLOSE csr111; |
208a4f4a | 769 | |
5eaef520 | 770 | generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0); |
68bbc9c3 | 771 | |
5eaef520 | 772 | dprintf("Checking printcap...\n"); |
235fd664 | 773 | |
5eaef520 | 774 | EXEC SQL DECLARE csr119 CURSOR FOR |
775 | SELECT p1.name FROM printcap p1, printcap p2 | |
776 | WHERE p1.name = p2.name AND p1.rowid < p2.rowid; | |
777 | EXEC SQL OPEN csr119; | |
778 | while (1) | |
779 | { | |
780 | EXEC SQL FETCH csr119 INTO :name; | |
781 | if (sqlca.sqlcode) | |
782 | break; | |
235fd664 | 783 | |
5eaef520 | 784 | printf("Printer %s has duplicate name\n", name); |
785 | cant_fix(0); | |
235fd664 | 786 | } |
5eaef520 | 787 | EXEC SQL CLOSE csr119; |
208a4f4a | 788 | } |