]> andersk Git - moira.git/blame - dbck/phase1.pc
build moira_schema.h and moira_schema.c from the schema.sql file.
[moira.git] / dbck / phase1.pc
CommitLineData
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 15EXEC SQL INCLUDE sqlca;
16
7ac48069 17RCSID("$Header$");
68bbc9c3 18
4b9e5c72 19EXEC SQL WHENEVER SQLERROR DO dbmserr();
7ac48069 20int show_user_id(void *user);
21void handle_duplicate_logins(struct save_queue *sq);
22void fix_user_id(void *user);
23void cant_fix(void *id);
24int show_mach_id(void *machine);
25int show_mach_name(void *machine);
26void fix_mach_id(void *machine);
27int show_snet_name(void *subnet);
28int show_clu_id(void *cluster);
29int show_clu_name(void *cluster);
30void fix_clu_id(void *cluster);
31int show_list_id(void *list);
32int show_list_name(void *list);
33void fix_list_id(void *list);
34int show_fs_id(void *filesys);
35void fix_fs_id(void *filesys);
36int show_fs_name(void *fs);
37int show_np_id(void *nfsphys);
38void fix_np_id(void *nfsphys);
39int show_str_id(void *string);
40int print_str_id(void *id);
41void print_dup_map(int key, void *data, void *hint);
42
43int 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 51void 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 101void 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 109void cant_fix(void *id)
68bbc9c3 110{
5eaef520 111 printf("Sorry, don't know how to fix that\n");
68bbc9c3 112}
113
7ac48069 114int 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 121int 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 128void 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 135int 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 142int 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 149int 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 156void 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 162int 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 169int 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 176void 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 182int 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 189void 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 196int 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 203int 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 212void 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 219int 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 226int 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 232void 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 237void phase1(void)
208a4f4a 238{
5eaef520 239 EXEC SQL BEGIN DECLARE SECTION;
240 char name[81], name1[81], last[17], first[17], buf[257];
241 int id, id1, id2, id3, aid, aid2, status;
242 int sid, sid2, sid3, sid4, sid5;
243 EXEC SQL END DECLARE SECTION;
244 int i, q, retval, tmp;
245 struct save_queue *sq;
246 struct user *u;
247 struct machine *m;
248 struct subnet *sn;
249 struct list *l;
250 struct cluster *c;
251 struct string *s;
252 struct filesys *f;
253 struct nfsphys *n;
254
255 printf("Phase 1 - Looking for duplicates\n");
256
257 /* self-join strings table on "string" to get duplicate strings, then
258 build a duplicates table to merge them. */
259
260 dprintf("Looking for duplicate strings...\n");
261 string_dups = create_hash(100);
262 if (!string_dups)
263 out_of_mem("storing duplicate strings");
264
265 EXEC SQL DECLARE csr116 CURSOR FOR
266 SELECT s1.string_id, s2.string_id FROM strings s1, strings s2
267 WHERE s1.string = s2.string and s1.string_id < s2.string_id;
268 EXEC SQL OPEN csr116;
269 /* The SELECT gives us two columns, both with non-negative integers.
270 * The number in the left column is always the smaller of the two,
271 * and each row includes string IDs for identical strings. We use
272 * them to make a mapping from id-to-delete to id-to-keep for all
273 * superflous IDs.
274 */
275 q = 0;
276 while (1)
277 {
278 EXEC SQL FETCH csr116 INTO :id1, :id2;
279 if (sqlca.sqlcode)
280 break;
281 q++;
282 /* If id2 is already stored, skip this row. */
7ac48069 283 i = (int)hash_lookup(string_dups, id2);
5eaef520 284 if (i > 0)
285 continue;
286 /* Follow the chain of id1 equivalent IDs back to the lowest one. */
287 id = id1;
7ac48069 288 while ((tmp = (int)hash_lookup(string_dups, id)) > 0)
5eaef520 289 id = tmp;
7ac48069 290 hash_store(string_dups, id2, (void *)id);
ab05f33a 291 }
5eaef520 292 EXEC SQL CLOSE csr116;
293 dprintf("found %d duplicates\n", q);
7ac48069 294 hash_step(string_dups, print_dup_map, NULL);
5eaef520 295 /* We don't want to delete the duplicates now because if the dbck
296 is cancelled, a LOT of state will be lost. So, we'll just let
297 them not get marked as used and then phase3 will clean them up */
298
299 dprintf("Loading strings...\n");
300 sq = sq_create();
301 strings = create_hash(75000);
302 if (!sq || !strings)
303 out_of_mem("loading strings");
304
305 EXEC SQL DECLARE csr101 CURSOR FOR
306 SELECT string_id, string FROM strings ORDER BY string_id;
307 EXEC SQL OPEN csr101;
308 q = 0;
309 while (1)
310 {
311 EXEC SQL FETCH csr101 INTO :id, :buf;
312 if (sqlca.sqlcode)
313 break;
314 q++;
315 s = malloc(sizeof(struct string));
316 if (!s)
317 out_of_mem("storing strings");
7ac48069 318 s->name = strdup(strtrim(buf));
5eaef520 319 s->string_id = id;
320 s->refc = 0;
321 retval = hash_store(strings, id, s);
322 if (retval == -1)
323 out_of_mem("storing strings in hash table");
324 else if (retval == 1) /* duplicate string_id */
325 {
ab05f33a 326 sq_save_data(sq, hash_lookup(strings, id));
327 sq_save_data(sq, s);
68bbc9c3 328 }
208a4f4a 329 }
5eaef520 330 EXEC SQL CLOSE csr101;
331 /* keep string id 0 (the empty string) even if unreferenced */
332 string_check(0);
333
334 printf("Loaded %d strings\n", q);
335
336 dprintf("Loading users...\n");
337 sq = sq_create();
338 users = create_hash(30000);
339 if (!sq || !users)
340 out_of_mem("loading users");
341
342 EXEC SQL DECLARE csr102 CURSOR FOR
343 SELECT users_id, login, last, first, status, potype, pop_id, box_id,
344 modby, fmodby, pmodby, comments, sigwho FROM users
345 ORDER BY users_id;
346 EXEC SQL OPEN csr102;
347 while (1)
348 {
349 EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status,
350 :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5;
351 if (sqlca.sqlcode)
352 break;
353
354 u = malloc(sizeof(struct user));
355 if (!u)
356 out_of_mem("storing users");
357 strcpy(u->login, strtrim(name));
358 u->potype = buf[0];
359 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
7ac48069 360 u->fullname = strdup(buf);
5eaef520 361 u->status = status;
362 u->users_id = id;
363 u->modby = sid;
364 u->fmodby = sid2;
365 u->pmodby = sid3;
366 u->comment = sid4;
367 u->sigwho = sid5;
368 switch (u->potype)
369 {
68bbc9c3 370 case 'P':
5eaef520 371 u->pobox_id = id2;
372 break;
68bbc9c3 373 case 'S':
5eaef520 374 /* If potype is SMTP, box_id is a string_id for the strings tbl */
375 u->pobox_id = id3;
376 break;
68bbc9c3 377 default:
5eaef520 378 u->pobox_id = 0;
68bbc9c3 379 }
5eaef520 380 retval = hash_store(users, id, u);
381 if (retval == -1)
382 out_of_mem("storing users in hash table");
383 else if (retval == 1)
384 {
385 sq_save_data(sq, hash_lookup(users, id));
386 sq_save_data(sq, u);
68bbc9c3 387 }
208a4f4a 388 }
5eaef520 389 EXEC SQL CLOSE csr102;
390
391 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
392
393 if (!fast)
394 {
395 sq = sq_create();
396 if (!sq)
397 out_of_mem("finding duplicate logins");
398
399 EXEC SQL DECLARE csr103 CURSOR FOR
400 SELECT u1.users_id FROM users u1, users u2
401 WHERE u1.login = u2.login and u1.rowid != u2.rowid;
402 EXEC SQL OPEN csr103;
403 while (1)
404 {
405 EXEC SQL FETCH csr103 INTO :id;
406 if (sqlca.sqlcode)
407 break;
408 sq_save_data(sq, hash_lookup(users, id));
208a4f4a 409 }
5eaef520 410 EXEC SQL CLOSE csr103;
411 handle_duplicate_logins(sq);
68bbc9c3 412 }
413
5eaef520 414 if (!fast)
415 {
416 dprintf("Scanning krbmap...\n");
417
418 EXEC SQL DECLARE csr113 CURSOR FOR
419 SELECT k1.users_id FROM krbmap k1, krbmap k2
420 WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid;
421 EXEC SQL OPEN csr113;
422 while (1)
423 {
424 EXEC SQL FETCH csr113 INTO :id;
425 if (sqlca.sqlcode)
426 break;
ab05f33a 427
5eaef520 428 printf("User %d is in the krbmap more than once!\n", id);
429 printf("Not fixing this error\n");
ab05f33a 430 }
5eaef520 431 EXEC SQL CLOSE csr113;
432
433 EXEC SQL DECLARE csr114 CURSOR FOR
434 SELECT k1.string_id FROM krbmap k1, krbmap k2
435 WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid;
436 EXEC SQL OPEN csr114;
437 while (1)
438 {
439 EXEC SQL FETCH csr114 INTO :id;
440 if (sqlca.sqlcode)
441 break;
442
443 printf("Principal %d is in the krbmap more than once!\n", id);
444 printf("Not fixing this error\n");
ab05f33a 445 }
5eaef520 446 EXEC SQL CLOSE csr114;
ab05f33a 447 }
448
5eaef520 449 dprintf("Loading machines...\n");
450 sq = sq_create();
451 machines = create_hash(20000);
452 if (!sq || !machines)
453 out_of_mem("loading machines");
454
455 EXEC SQL DECLARE csr104 CURSOR FOR
456 SELECT mach_id, name, snet_id, owner_type, owner_id,
457 acomment, ocomment, creator, modby
458 FROM machine ORDER BY mach_id;
459 EXEC SQL OPEN csr104;
460 while (1)
461 {
462 EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2,
463 :sid3, :sid4, :sid;
464 if (sqlca.sqlcode)
465 break;
466
467 m = malloc(sizeof(struct machine));
468 if (!m)
469 out_of_mem("storing machines");
470 strcpy(m->name, strtrim(name));
471 m->owner_type = buf[0];
472 m->owner_id = id3;
473 m->snet_id = id2;
474 m->mach_id = id;
475 m->clucount = 0;
476 m->acomment = sid2;
477 m->ocomment = sid3;
478 m->creator = sid4;
479 m->modby = sid;
480 retval = hash_store(machines, id, m);
481 if (retval == -1)
482 out_of_mem("storing machines in hash table");
483 else if (retval == 1)
484 {
485 sq_save_data(sq, hash_lookup(machines, id));
486 sq_save_data(sq, m);
68bbc9c3 487 }
208a4f4a 488 }
5eaef520 489 EXEC SQL CLOSE csr104;
490 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
491
492 if (!fast)
493 {
494 sq = sq_create();
495 if (!sq)
496 out_of_mem("looking for duplicate machine names");
497
498 EXEC SQL DECLARE csr105 CURSOR FOR
499 SELECT m1.mach_id FROM machine m1, machine m2
500 WHERE m1.name = m2.name AND m1.rowid != m2.rowid;
501 EXEC SQL OPEN csr105;
502 while (1)
503 {
504 EXEC SQL FETCH csr105 INTO :id;
505 if (sqlca.sqlcode)
506 break;
507
508 sq_save_data(sq, hash_lookup(machines, id));
208a4f4a 509 }
5eaef520 510 EXEC SQL CLOSE csr105;
511 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
512
513 EXEC SQL DECLARE csr_hal1 CURSOR FOR
514 SELECT h1.name, m1.mach_id, m2.mach_id
515 FROM hostalias h1, machine m1, hostalias h2, machine m2
516 WHERE h1.name = h2.name AND h1.mach_id != h2.mach_id
517 AND m1.mach_id = h1.mach_id AND m2.mach_id = h2.mach_id;
518 EXEC SQL OPEN csr_hal1;
519 while (1)
520 {
ab05f33a 521 EXEC SQL FETCH csr_hal1 INTO :name, :id1, :id2;
5eaef520 522 if (sqlca.sqlcode)
523 break;
ab05f33a 524 printf("Aliases for machines %d and %d have duplicate name %s\n",
525 id1, id2, strtrim(name));
a8e78b23 526 cant_fix(0);
ab05f33a 527 }
5eaef520 528 EXEC SQL CLOSE csr_hal1;
529
530 EXEC SQL DECLARE csr_hal2 CURSOR FOR
531 SELECT h1.name, m1.mach_id, m2.mach_id
532 FROM hostalias h1, machine m1, machine m2
533 WHERE h1.name = m1.name AND h1.mach_id = m2.mach_id;
534 EXEC SQL OPEN csr_hal2;
535 while (1)
536 {
537 EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2;
538 if (sqlca.sqlcode)
539 break;
540 printf("Machine %d has alias %s that conflicts with machine %d\n",
541 id2, strtrim(name), id1);
a8e78b23 542 cant_fix(0);
5eaef520 543 }
544 EXEC SQL CLOSE csr_hal2;
772b7afc 545 }
235fd664 546
5eaef520 547 dprintf("Loading subnets...\n");
548 subnets = create_hash(254);
549 if (!subnets)
550 out_of_mem("loading subnets");
551
552 EXEC SQL DECLARE csr115 CURSOR FOR
553 SELECT snet_id, name, owner_type, owner_id, modby from subnet;
554 EXEC SQL OPEN csr115;
555 while (1)
556 {
557 EXEC SQL FETCH csr115 INTO :id, :name, :buf, :id2, :sid;
558 if (sqlca.sqlcode)
559 break;
560
561 sn = malloc(sizeof(struct machine));
562 if (!sn)
563 out_of_mem("storing subnets");
564 strcpy(sn->name, strtrim(name));
565 sn->owner_type = buf[0];
566 sn->owner_id = id2;
567 sn->snet_id = id;
568 sn->modby = sid;
569 retval = hash_store(subnets, id, sn);
570 if (retval == -1)
571 out_of_mem("storing subnets in hash table");
572 else if (retval == 1)
573 {
574 printf("Duplicate subnet ID: %d (%s)\n", id, name);
575 /* should add code to delete */
576 cant_fix(0);
577 }
578 }
579 EXEC SQL CLOSE csr115;
580
581 if (!fast)
582 {
583 sq = sq_create();
584 if (!sq)
585 out_of_mem("looking for duplicate subnet names");
586
587 EXEC SQL DECLARE csr117 CURSOR FOR
588 SELECT s1.snet_id FROM subnet s1, subnet s2
589 WHERE s1.name = s2.name AND s1.rowid != s2.rowid;
590 EXEC SQL OPEN csr117;
591 while (1)
592 {
593 EXEC SQL FETCH csr117 INTO :id;
594 if (sqlca.sqlcode)
595 break;
235fd664 596
5eaef520 597 sq_save_data(sq, hash_lookup(subnets, id));
235fd664 598 }
5eaef520 599 EXEC SQL CLOSE csr117;
600 generic_fix(sq, show_snet_name, "Change name", cant_fix, 0);
235fd664 601 }
5eaef520 602
603 dprintf("Loading clusters...\n");
604 sq = sq_create();
605 clusters = create_hash(100);
606 if (!sq || !clusters)
607 out_of_mem("loading clusters");
608
609 EXEC SQL DECLARE csr106 CURSOR FOR
610 SELECT clu_id, name, modby FROM clusters;
611 EXEC SQL OPEN csr106;
612 while (1)
613 {
614 EXEC SQL FETCH csr106 INTO :id, :name, :sid;
615 if (sqlca.sqlcode)
616 break;
617
618 c = malloc(sizeof(struct cluster));
619 if (!c)
620 out_of_mem("storing clusters");
621 strcpy(c->name, strtrim(name));
622 c->clu_id = id;
623 c->modby = sid;
624 retval = hash_store(clusters, id, c);
625 if (retval == -1)
626 out_of_mem("storing clusters in hash table");
627 else if (retval == 1)
628 {
629 sq_save_data(sq, hash_lookup(clusters, id));
630 sq_save_data(sq, c);
68bbc9c3 631 }
208a4f4a 632 }
5eaef520 633 EXEC SQL CLOSE csr106;
634 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
635
636 if (!fast)
637 {
638 sq = sq_create();
639 if (!sq)
640 out_of_mem("looking for duplicate cluster names");
641
642 EXEC SQL DECLARE csr107 CURSOR FOR
643 SELECT c1.clu_id FROM clusters c1, clusters c2
644 WHERE c1.name = c2.name AND c1.rowid != c2.rowid;
645 EXEC SQL OPEN csr107;
646 while (1)
647 {
648 EXEC SQL FETCH csr107 INTO :id;
649 if (sqlca.sqlcode)
650 break;
651
652 sq_save_data(sq, hash_lookup(clusters, id));
208a4f4a 653 }
5eaef520 654 EXEC SQL CLOSE csr107;
655 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
68bbc9c3 656 }
657
5eaef520 658 dprintf("Loading lists...\n");
659 sq = sq_create();
660 lists = create_hash(50000);
661 if (!sq || !lists)
662 out_of_mem("loading lists");
663
664 EXEC SQL DECLARE csr108 CURSOR FOR
665 SELECT list_id, name, acl_id, acl_type, modby FROM list
666 ORDER BY list_id;
667 EXEC SQL OPEN csr108;
668 while (1)
669 {
670 EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid;
671 if (sqlca.sqlcode)
672 break;
673 l = malloc(sizeof(struct list));
674 if (!l)
675 out_of_mem("storing lists");
676 strcpy(l->name, strtrim(name));
677 l->acl_type = buf[0];
678 l->acl_id = aid;
679 l->list_id = id;
680 l->members = 0;
681 retval = hash_store(lists, id, l);
682 if (retval == -1)
683 out_of_mem("storing lists in hash table");
684 else if (retval == 1)
685 {
686 sq_save_data(sq, hash_lookup(lists, id));
687 sq_save_data(sq, l);
68bbc9c3 688 }
208a4f4a 689 }
5eaef520 690 EXEC SQL CLOSE csr108;
691 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
692
693 if (!fast)
694 {
695 sq = sq_create();
696 if (!sq)
697 out_of_mem("looking for duplicate list names");
698
699 EXEC SQL DECLARE csr109 CURSOR FOR
700 SELECT l1.list_id FROM list l1, list l2
701 WHERE l1.name = l2.name AND l1.rowid != l2.rowid;
702 EXEC SQL OPEN csr109;
703 while (1)
704 {
705 EXEC SQL FETCH csr109 INTO :id;
706 if (sqlca.sqlcode)
707 break;
708
709 sq_save_data(sq, hash_lookup(lists, id));
208a4f4a 710 }
5eaef520 711 EXEC SQL CLOSE csr109;
712 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
68bbc9c3 713 }
714
5eaef520 715 dprintf("Loading filesys...\n");
716 sq = sq_create();
717 filesys = create_hash(30000);
718 if (!sq || !filesys)
719 out_of_mem("loading filesys");
720
721 EXEC SQL DECLARE csr110 CURSOR FOR
722 SELECT filsys_id, label, owner, owners, phys_id, mach_id,
723 type, name, modby FROM filesys ORDER BY filsys_id;
724 EXEC SQL OPEN csr110;
725 while (1)
726 {
727 EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3,
728 :buf, :name1, :sid;
729 if (sqlca.sqlcode)
730 break;
731
732 f = malloc(sizeof(struct filesys));
733 if (!f)
734 out_of_mem("storing filesystems");
735 strcpy(f->name, strtrim(name));
736 strcpy(f->dir, strtrim(name1));
737 f->filsys_id = id;
738 f->owner = aid;
739 f->owners = aid2;
740 f->phys_id = id2;
741 f->mach_id = id3;
742 f->type = buf[0];
743 retval = hash_store(filesys, id, f);
744 if (retval == -1)
745 out_of_mem("storing filesys in hash table");
746 else if (retval == 1)
747 {
748 sq_save_data(sq, hash_lookup(filesys, id));
749 sq_save_data(sq, f);
68bbc9c3 750 }
208a4f4a 751 }
5eaef520 752 EXEC SQL CLOSE csr110;
753
754 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
755
756 if (!fast)
757 {
758 sq = sq_create();
759 if (!sq)
760 out_of_mem("looking for duplicate filesys names");
761
762 EXEC SQL DECLARE csr118 CURSOR FOR
763 SELECT fs1.filsys_id FROM filesys fs1, filesys fs2
764 WHERE fs1.label = fs2.label AND fs1.rowid != fs2.rowid;
765 EXEC SQL OPEN csr118;
766 while (1)
767 {
768 EXEC SQL FETCH csr118 INTO :id;
769 if (sqlca.sqlcode)
770 break;
771
772 sq_save_data(sq, hash_lookup(filesys, id));
235fd664 773 }
5eaef520 774 EXEC SQL CLOSE csr118;
775 generic_fix(sq, show_fs_name, "Change name", cant_fix, 0);
235fd664 776 }
777
5eaef520 778 dprintf("Loading nfsphys...\n");
779 sq = sq_create();
780 nfsphys = create_hash(500);
781 if (!sq || !nfsphys)
782 out_of_mem("loading nfsphs");
783
784 EXEC SQL DECLARE csr111 CURSOR FOR
785 SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
786 EXEC SQL OPEN csr111;
787 while (1)
788 {
789 EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid;
790 if (sqlca.sqlcode)
791 break;
792
793 n = malloc(sizeof(struct nfsphys));
794 if (!n)
795 out_of_mem("storing nfsphys");
796 strcpy(n->dir, strtrim(name));
797 n->mach_id = id2;
798 n->nfsphys_id = id;
799 n->allocated = id3;
800 n->count = 0;
801 retval = hash_store(nfsphys, id, n);
802 if (retval == -1)
803 out_of_mem("storing nfsphys in hash table");
804 else if (retval == 1)
805 {
806 sq_save_data(sq, hash_lookup(nfsphys, id));
807 sq_save_data(sq, n);
68bbc9c3 808 }
208a4f4a 809 }
5eaef520 810 EXEC SQL CLOSE csr111;
208a4f4a 811
5eaef520 812 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
68bbc9c3 813
5eaef520 814 dprintf("Checking printcap...\n");
235fd664 815
5eaef520 816 EXEC SQL DECLARE csr119 CURSOR FOR
817 SELECT p1.name FROM printcap p1, printcap p2
818 WHERE p1.name = p2.name AND p1.rowid < p2.rowid;
819 EXEC SQL OPEN csr119;
820 while (1)
821 {
822 EXEC SQL FETCH csr119 INTO :name;
823 if (sqlca.sqlcode)
824 break;
235fd664 825
5eaef520 826 printf("Printer %s has duplicate name\n", name);
827 cant_fix(0);
235fd664 828 }
5eaef520 829 EXEC SQL CLOSE csr119;
208a4f4a 830}
This page took 0.205656 seconds and 5 git commands to generate.