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