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