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