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