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 /* replace users (login = "#"+text(users.uid), status = 0)
53 * where users.users_id = id */
54 EXEC SQL UPDATE users SET login = '#'+CHAR(users.uid),
55 status=0 WHERE users_id = :id;
56 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
58 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
60 printf("Not fixed\n");
73 u->users_id = generic_fix_id("users", "users_id", "login",
74 u->users_id, u->login);
81 printf("Sorry, don't know how to fix that\n");
87 printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id);
94 printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id);
101 m->mach_id = generic_fix_id("machine", "mach_id", "name",
102 m->mach_id, m->name);
108 printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id);
115 printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id);
122 c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name);
128 printf("List %s has duplicate ID %d\n", l->name, l->list_id);
135 printf("List %s (%d) has duplicate name\n", l->name, l->list_id);
142 l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name);
148 printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id);
155 f->filsys_id = generic_fix_id("filesys", "filsys_id", "label",
156 f->filsys_id, f->name);
163 printf("NfsPhys %s:%s has duplicate ID %d\n",
164 ((struct machine *)hash_lookup(machines, n->mach_id))->name,
165 n->dir, n->nfsphys_id);
172 n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir",
173 n->nfsphys_id, n->dir);
179 printf("String %s has duplicate ID %d\n", s->name, s->string_id);
186 EXEC SQL BEGIN DECLARE SECTION;
187 char name[81], name1[81], last[17], first[17], buf[257];
188 int id, id2, id3, aid, aid2, status, sid, sid2, sid3, sid4, sid5;
189 EXEC SQL END DECLARE SECTION;
190 struct save_queue *sq;
199 printf("Phase 1 - Looking for duplicates\n");
201 dprintf("Loading strings...\n");
203 strings = create_hash(5000);
205 EXEC SQL DECLARE csr101 CURSOR FOR
206 SELECT string_id, string FROM strings ORDER BY string_id;
207 EXEC SQL OPEN csr101;
209 EXEC SQL FETCH csr101 INTO :id, :buf;
210 if(sqlca.sqlcode != 0) break;
212 s = (struct string *) malloc(sizeof(struct string));
214 out_of_mem("storing strings");
215 s->name = strsave(strtrim(buf));
218 if (hash_store(strings, id, s)) {
219 sq_save_data(sq, hash_lookup(strings, id));
223 EXEC SQL CLOSE csr101;
224 generic_delete(sq, show_str_id, "strings", "string_id", 0);
227 dprintf("Loading users...\n");
229 users = create_hash(10000);
231 EXEC SQL DECLARE csr102 CURSOR FOR
232 SELECT users_id, login, last, first, status, potype, pop_id, box_id,
233 modby, fmodby, pmodby, comment, sigwho FROM users ORDER BY users_id;
234 EXEC SQL OPEN csr102;
236 EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status,
237 :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5;
238 if(sqlca.sqlcode != 0) break;
240 u = (struct user *) malloc(sizeof(struct user));
242 out_of_mem("storing users");
243 strcpy(u->login, strtrim(name));
245 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
246 u->fullname = strsave(buf);
259 if (hash_store(users, id, u)) {
260 sq_save_data(sq, hash_lookup(users, id));
274 EXEC SQL CLOSE csr102;
276 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
281 EXEC SQL DECLARE csr103 CURSOR FOR
282 SELECT u1.users_id FROM users u1, users u2
283 WHERE u1.login = u2.login and u1.tid != u2.tid;
284 EXEC SQL OPEN csr103;
286 EXEC SQL FETCH csr103 INTO :id;
287 if(sqlca.sqlcode != 0) break;
288 sq_save_data(sq, hash_lookup(users, id));
290 EXEC SQL CLOSE csr103;
291 handle_duplicate_logins(sq);
294 dprintf("Loading machines...\n");
295 machines = create_hash(1000);
298 EXEC SQL DECLARE csr104 CURSOR FOR
299 SELECT mach_id, name, modby FROM machine ORDER BY mach_id;
300 EXEC SQL OPEN csr104;
302 EXEC SQL FETCH csr104 INTO :id, :name, :sid;
303 if(sqlca.sqlcode != 0) break;
305 m = (struct machine *) malloc(sizeof(struct machine));
307 out_of_mem("storing machines");
308 strcpy(m->name, strtrim(name));
311 if (hash_store(machines, id, m)) {
312 sq_save_data(sq, hash_lookup(machines, id));
318 EXEC SQL CLOSE csr104;
319 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
324 EXEC SQL DECLARE csr105 CURSOR FOR
325 SELECT m1.mach_id FROM machine m1, machine m2
326 WHERE m1.name = m2.name AND m1.tid != m2.tid;
327 EXEC SQL OPEN csr105;
329 EXEC SQL FETCH csr105 INTO :id;
330 if(sqlca.sqlcode != 0) break;
332 sq_save_data(sq, hash_lookup(machines, id));
334 EXEC SQL CLOSE csr105;
335 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
338 dprintf("Loading clusters...\n");
340 clusters = create_hash(100);
342 EXEC SQL DECLARE csr106 CURSOR FOR
343 SELECT clu_id, name, modby FROM cluster;
344 EXEC SQL OPEN csr106;
346 EXEC SQL FETCH csr106 INTO :id, :name, :sid;
347 if(sqlca.sqlcode != 0) break;
349 c = (struct cluster *) malloc(sizeof(struct cluster));
351 out_of_mem("storing clusters");
352 strcpy(c->name, strtrim(name));
354 if (hash_store(clusters, id, c)) {
355 sq_save_data(sq, hash_lookup(clusters, id));
361 EXEC SQL CLOSE csr106;
362 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
367 EXEC SQL DECLARE csr107 CURSOR FOR
368 SELECT clu_id FROM cluster c1, cluster c2
369 WHERE c1.name=c2.name AND c1.tid != c2.tid;
370 EXEC SQL OPEN csr107;
372 EXEC SQL FETCH csr107 INTO :id;
373 if(sqlca.sqlcode != 0) break;
375 sq_save_data(sq, hash_lookup(clusters, id));
377 EXEC SQL CLOSE csr107;
378 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
381 dprintf("Loading lists...\n");
383 lists = create_hash(10000);
385 EXEC SQL DECLARE csr108 CURSOR FOR
386 SELECT list_id, name, acl_id, acl_type, modby FROM list
388 EXEC SQL OPEN csr108;
390 EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid;
391 if (sqlca.sqlcode != 0) break;
392 l = (struct list *) malloc(sizeof(struct list));
394 out_of_mem("storing lists");
395 strcpy(l->name, strtrim(name));
396 l->acl_type = buf[0];
400 if (hash_store(lists, id, l)) {
401 sq_save_data(sq, hash_lookup(lists, id));
407 EXEC SQL CLOSE csr108;
408 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
413 EXEC SQL DECLARE csr109 CURSOR FOR
414 SELECT list_id FROM list l1, list l2
415 WHERE l1.name=l2.name AND l1.tid != l2.tid;
416 EXEC SQL OPEN csr109;
418 EXEC SQL FETCH csr109 INTO :id;
419 if(sqlca.sqlcode != 0) break;
421 sq_save_data(sq, hash_lookup(lists, id));
423 EXEC SQL CLOSE csr109;
424 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
427 dprintf("Loading filesys...\n");
429 filesys = create_hash(10000);
431 EXEC SQL DECLARE csr110 CURSOR FOR
432 SELECT filsys_id, label, owner, owners, phys_id, mach_id,
433 type, name, modby FROM filesys ORDER BY filsys_id;
434 EXEC SQL OPEN csr110;
436 EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3,
438 if(sqlca.sqlcode != 0) break;
440 f = (struct filesys *) malloc(sizeof(struct filesys));
442 out_of_mem("storing filesystems");
443 strcpy(f->name, strtrim(name));
444 strcpy(f->dir, strtrim(name1));
451 if (hash_store(filesys, id, f)) {
452 sq_save_data(sq, hash_lookup(filesys, id));
458 EXEC SQL CLOSE csr110;
460 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
462 dprintf("Loading nfsphys...\n");
464 nfsphys = create_hash(500);
466 EXEC SQL DECLARE csr111 CURSOR FOR
467 SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
468 EXEC SQL OPEN csr111;
470 EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid;
471 if(sqlca.sqlcode != 0) break;
473 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
475 out_of_mem("storing nfsphys");
476 strcpy(n->dir, strtrim(name));
481 if (hash_store(nfsphys, id, n)) {
482 sq_save_data(sq, hash_lookup(nfsphys, id));
488 EXEC SQL CLOSE csr111;
490 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
494 EXEC SQL DECLARE csr112 CURSOR FOR
495 SELECT s1.string_id, s1.string FROM strings s1, strings s2
496 WHERE s1.string=s2.string AND s1.tid != s2.tid;
497 EXEC SQL OPEN csr112;
499 EXEC SQL FETCH csr112 INTO :id, :buf;
500 if(sqlca.sqlcode != 0) break;
502 printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
503 printf("Not fixing this error\n");
505 EXEC SQL CLOSE csr112;
509 dprintf("Scanning krbmap...\n");
511 EXEC SQL DECLARE csr113 CURSOR FOR
512 SELECT k1.users_id FROM krbmap k1, krbmap k2
513 WHERE k1.users_id = k2.users_id AND k1.tid != k2.tid;
514 EXEC SQL OPEN csr113;
516 EXEC SQL FETCH csr113 INTO :id;
517 if(sqlca.sqlcode != 0) break;
519 printf("User %d is in the krbmap more than once!\n", id);
520 printf("Not fixing this error\n");
522 EXEC SQL CLOSE csr113;
524 EXEC SQL DECLARE csr114 CURSOR FOR
525 SELECT k1.string_id FROM krbmap k1, krbmap k2
526 WHERE k1.string_id = k2.string_id AND k1.tid != k2.tid;
527 EXEC SQL OPEN csr114;
529 EXEC SQL FETCH csr114 INTO :id;
530 if(sqlca.sqlcode != 0) break;
532 printf("Principal %d is in the krbmap more than once!\n", id);
533 printf("Not fixing this error\n");
535 EXEC SQL CLOSE csr114;