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