3 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
11 EXEC SQL INCLUDE sqlca;
14 static char phase1_qc_rcsid[] = "$Header$";
20 printf("User %s (%s, status %d) has duplicate ID\n",
21 u->login, u->fullname, u->status);
25 handle_duplicate_logins(sq)
26 struct save_queue *sq;
28 struct user *u, *uu, *tmp;
30 uu = (struct user *)0;
31 if(sq_get_data(sq,&uu)) {
32 while (sq_get_data(sq, &u)) {
33 if (!strcmp(u->login, uu->login)) {
34 if (uu->status == 1 || u->status == 0) {
39 printf("User %s (%s, status %d) and\n",
40 u->login, u->fullname, u->status);
41 printf("User %s (%s, status %d) have duplicate logins\n",
42 uu->login, uu->fullname, uu->status);
43 if (!strcmp(u->fullname, uu->fullname) &&
44 single_fix("Delete the second one")) {
45 single_delete("users", "users_id", uu->users_id);
46 } else if (single_fix("Unregister the second one"))
48 EXEC SQL BEGIN DECLARE SECTION;
49 int id = uu->users_id, rowcount;
50 EXEC SQL END DECLARE SECTION;
52 EXEC SQL UPDATE users SET login = '#'+CHAR(users.uid),
53 status=0 WHERE users_id = :id;
54 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
56 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
58 printf("Not fixed\n");
71 u->users_id = generic_fix_id("users", "users_id", "login",
72 u->users_id, u->login);
79 printf("Sorry, don't know how to fix that\n");
85 printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id);
92 printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id);
99 m->mach_id = generic_fix_id("machine", "mach_id", "name",
100 m->mach_id, m->name);
106 printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id);
113 printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id);
120 c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name);
126 printf("List %s has duplicate ID %d\n", l->name, l->list_id);
133 printf("List %s (%d) has duplicate name\n", l->name, l->list_id);
140 l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name);
146 printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id);
153 f->filsys_id = generic_fix_id("filesys", "filsys_id", "label",
154 f->filsys_id, f->name);
161 printf("NfsPhys %s:%s has duplicate ID %d\n",
162 ((struct machine *)hash_lookup(machines, n->mach_id))->name,
163 n->dir, n->nfsphys_id);
170 n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir",
171 n->nfsphys_id, n->dir);
177 printf("String %s has duplicate ID %d\n", s->name, s->string_id);
184 EXEC SQL BEGIN DECLARE SECTION;
185 char name[81], name1[81], last[17], first[17], buf[257];
186 int id, id2, id3, aid, aid2, status, sid, sid2, sid3, sid4, sid5;
187 EXEC SQL END DECLARE SECTION;
188 struct save_queue *sq;
197 printf("Phase 1 - Looking for duplicates\n");
199 dprintf("Loading strings...\n");
201 strings = create_hash(5000);
203 EXEC SQL DECLARE csr101 CURSOR FOR
204 SELECT string_id, string FROM strings ORDER BY string_id;
205 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
206 EXEC SQL OPEN csr101;
208 EXEC SQL FETCH csr101 INTO :id, :buf;
209 if (sqlca.sqlcode != 0) {
210 ingerr(&sqlca.sqlcode);
214 s = (struct string *) malloc(sizeof(struct string));
216 out_of_mem("storing strings");
217 s->name = strsave(strtrim(buf));
220 if (hash_store(strings, id, s)) {
221 sq_save_data(sq, hash_lookup(strings, id));
225 EXEC SQL CLOSE csr101;
226 generic_delete(sq, show_str_id, "strings", "string_id", 0);
229 dprintf("Loading users...\n");
231 users = create_hash(10000);
233 EXEC SQL DECLARE csr102 CURSOR FOR
234 SELECT users_id, login, last, first, status, potype, pop_id, box_id,
235 modby, fmodby, pmodby, comment, sigwho FROM users ORDER BY users_id;
236 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
237 EXEC SQL OPEN csr102;
239 EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status,
240 :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5;
241 if (sqlca.sqlcode != 0) {
242 ingerr(&sqlca.sqlcode);
246 u = (struct user *) malloc(sizeof(struct user));
248 out_of_mem("storing users");
249 strcpy(u->login, strtrim(name));
251 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
252 u->fullname = strsave(buf);
265 if (hash_store(users, id, u)) {
266 sq_save_data(sq, hash_lookup(users, id));
280 EXEC SQL CLOSE csr102;
282 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
287 EXEC SQL DECLARE csr103 CURSOR FOR
288 SELECT u1.users_id FROM users u1, users u2
289 WHERE u1.login = u2.login and u1.tid != u2.tid;
290 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
291 EXEC SQL OPEN csr103;
293 EXEC SQL FETCH csr103 INTO :id;
294 if (sqlca.sqlcode != 0) {
295 ingerr(&sqlca.sqlcode);
298 sq_save_data(sq, hash_lookup(users, id));
300 EXEC SQL CLOSE csr103;
301 handle_duplicate_logins(sq);
304 dprintf("Loading machines...\n");
305 machines = create_hash(1000);
308 EXEC SQL DECLARE csr104 CURSOR FOR
309 SELECT mach_id, name, snet_id, owner_type, owner_id,
310 acomment, ocomment, creator, modby
311 FROM machine ORDER BY mach_id;
312 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
313 EXEC SQL OPEN csr104;
315 EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2,
317 if (sqlca.sqlcode != 0) {
318 ingerr(&sqlca.sqlcode);
322 m = (struct machine *) malloc(sizeof(struct machine));
324 out_of_mem("storing machines");
325 strcpy(m->name, strtrim(name));
326 m->owner_type = buf[0];
331 if (hash_store(machines, id, m)) {
332 sq_save_data(sq, hash_lookup(machines, id));
335 if (sid2) string_check(sid2);
336 if (sid3) string_check(sid3);
337 if (sid4 < 0) string_check(-sid4);
338 if (sid < 0) string_check(-sid);
340 EXEC SQL CLOSE csr104;
341 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
346 EXEC SQL DECLARE csr105 CURSOR FOR
347 SELECT m1.mach_id FROM machine m1, machine m2
348 WHERE m1.name = m2.name AND m1.tid != m2.tid;
349 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
350 EXEC SQL OPEN csr105;
352 EXEC SQL FETCH csr105 INTO :id;
353 if (sqlca.sqlcode != 0) {
354 ingerr(&sqlca.sqlcode);
358 sq_save_data(sq, hash_lookup(machines, id));
360 EXEC SQL CLOSE csr105;
361 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
364 dprintf("Loading subnets...\n");
365 subnets = create_hash(254);
367 EXEC SQL DECLARE csr115 CURSOR FOR
368 SELECT snet_id, name from subnet;
369 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
370 EXEC SQL OPEN csr115;
372 EXEC SQL FETCH csr115 INTO :id, :name;
373 if (sqlca.sqlcode != 0) {
374 ingerr(&sqlca.sqlcode);
377 if (hash_store(subnets, id, name)) {
378 printf("Duplicate subnet ID: %d (%s)\n", id, name);
381 EXEC SQL CLOSE csr115;
383 dprintf("Loading clusters...\n");
385 clusters = create_hash(100);
387 EXEC SQL DECLARE csr106 CURSOR FOR
388 SELECT clu_id, name, modby FROM cluster;
389 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
390 EXEC SQL OPEN csr106;
392 EXEC SQL FETCH csr106 INTO :id, :name, :sid;
393 if (sqlca.sqlcode != 0) {
394 ingerr(&sqlca.sqlcode);
398 c = (struct cluster *) malloc(sizeof(struct cluster));
400 out_of_mem("storing clusters");
401 strcpy(c->name, strtrim(name));
403 if (hash_store(clusters, id, c)) {
404 sq_save_data(sq, hash_lookup(clusters, id));
410 EXEC SQL CLOSE csr106;
411 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
416 EXEC SQL DECLARE csr107 CURSOR FOR
417 SELECT c1.clu_id FROM cluster c1, cluster c2
418 WHERE c1.name=c2.name AND c1.tid != c2.tid;
419 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
420 EXEC SQL OPEN csr107;
422 EXEC SQL FETCH csr107 INTO :id;
423 if (sqlca.sqlcode != 0) {
424 ingerr(&sqlca.sqlcode);
428 sq_save_data(sq, hash_lookup(clusters, id));
430 EXEC SQL CLOSE csr107;
431 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
434 dprintf("Loading lists...\n");
436 lists = create_hash(10000);
438 EXEC SQL DECLARE csr108 CURSOR FOR
439 SELECT list_id, name, acl_id, acl_type, modby FROM list
441 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
442 EXEC SQL OPEN csr108;
444 EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid;
445 if (sqlca.sqlcode != 0) {
446 ingerr(&sqlca.sqlcode);
449 l = (struct list *) malloc(sizeof(struct list));
451 out_of_mem("storing lists");
452 strcpy(l->name, strtrim(name));
453 l->acl_type = buf[0];
457 if (hash_store(lists, id, l)) {
458 sq_save_data(sq, hash_lookup(lists, id));
464 EXEC SQL CLOSE csr108;
465 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
470 EXEC SQL DECLARE csr109 CURSOR FOR
471 SELECT l1.list_id FROM list l1, list l2
472 WHERE l1.name=l2.name AND l1.tid != l2.tid;
473 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
474 EXEC SQL OPEN csr109;
476 EXEC SQL FETCH csr109 INTO :id;
477 if (sqlca.sqlcode != 0) {
478 ingerr(&sqlca.sqlcode);
482 sq_save_data(sq, hash_lookup(lists, id));
484 EXEC SQL CLOSE csr109;
485 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
488 dprintf("Loading filesys...\n");
490 filesys = create_hash(10000);
492 EXEC SQL DECLARE csr110 CURSOR FOR
493 SELECT filsys_id, label, owner, owners, phys_id, mach_id,
494 type, name, modby FROM filesys ORDER BY filsys_id;
495 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
496 EXEC SQL OPEN csr110;
498 EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3,
500 if (sqlca.sqlcode != 0) {
501 ingerr(&sqlca.sqlcode);
505 f = (struct filesys *) malloc(sizeof(struct filesys));
507 out_of_mem("storing filesystems");
508 strcpy(f->name, strtrim(name));
509 strcpy(f->dir, strtrim(name1));
516 if (hash_store(filesys, id, f)) {
517 sq_save_data(sq, hash_lookup(filesys, id));
523 EXEC SQL CLOSE csr110;
525 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
527 dprintf("Loading nfsphys...\n");
529 nfsphys = create_hash(500);
531 EXEC SQL DECLARE csr111 CURSOR FOR
532 SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
533 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
534 EXEC SQL OPEN csr111;
536 EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid;
537 if (sqlca.sqlcode != 0) {
538 ingerr(&sqlca.sqlcode);
542 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
544 out_of_mem("storing nfsphys");
545 strcpy(n->dir, strtrim(name));
550 if (hash_store(nfsphys, id, n)) {
551 sq_save_data(sq, hash_lookup(nfsphys, id));
557 EXEC SQL CLOSE csr111;
559 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
563 dprintf("Checking for duplicate strings...\n");
564 EXEC SQL DECLARE csr112 CURSOR FOR
565 SELECT s1.string_id, s1.string FROM strings s1, strings s2
566 WHERE s1.string=s2.string AND s1.tid != s2.tid;
567 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
568 EXEC SQL OPEN csr112;
570 EXEC SQL FETCH csr112 INTO :id, :buf;
571 if (sqlca.sqlcode != 0) {
572 ingerr(&sqlca.sqlcode);
576 printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
577 printf("Not fixing this error\n");
579 EXEC SQL CLOSE csr112;
583 dprintf("Scanning krbmap...\n");
585 EXEC SQL DECLARE csr113 CURSOR FOR
586 SELECT k1.users_id FROM krbmap k1, krbmap k2
587 WHERE k1.users_id = k2.users_id AND k1.tid != k2.tid;
588 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
589 EXEC SQL OPEN csr113;
591 EXEC SQL FETCH csr113 INTO :id;
592 if (sqlca.sqlcode != 0) {
593 ingerr(&sqlca.sqlcode);
597 printf("User %d is in the krbmap more than once!\n", id);
598 printf("Not fixing this error\n");
600 EXEC SQL CLOSE csr113;
602 EXEC SQL DECLARE csr114 CURSOR FOR
603 SELECT k1.string_id FROM krbmap k1, krbmap k2
604 WHERE k1.string_id = k2.string_id AND k1.tid != k2.tid;
605 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
606 EXEC SQL OPEN csr114;
608 EXEC SQL FETCH csr114 INTO :id;
609 if (sqlca.sqlcode != 0) {
610 ingerr(&sqlca.sqlcode);
614 printf("Principal %d is in the krbmap more than once!\n", id);
615 printf("Not fixing this error\n");
617 EXEC SQL CLOSE csr114;