]> andersk Git - moira.git/blame - dbck/phase1.dc
fix leftover bug in usage message (s/-server/-database)
[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>
10#include "dbck.h"
208a4f4a 11EXEC SQL INCLUDE sqlca;
12
68bbc9c3 13
14static char phase1_qc_rcsid[] = "$Header$";
15
16
17show_user_id(u)
18struct user *u;
19{
20 printf("User %s (%s, status %d) has duplicate ID\n",
21 u->login, u->fullname, u->status);
22 return(0);
23}
24
25handle_duplicate_logins(sq)
26struct save_queue *sq;
27{
28 struct user *u, *uu, *tmp;
29
30 uu = (struct user *)0;
208a4f4a 31 if(sq_get_data(sq,&uu)) {
32 while (sq_get_data(sq, &u)) {
68bbc9c3 33 if (!strcmp(u->login, uu->login)) {
34 if (uu->status == 1 || u->status == 0) {
35 tmp = u;
36 u = uu;
37 uu = tmp;
38 }
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"))
208a4f4a 47 {
48 EXEC SQL BEGIN DECLARE SECTION;
49 int id = uu->users_id, rowcount;
50 EXEC SQL END DECLARE SECTION;
51
208a4f4a 52 EXEC SQL UPDATE users SET login = '#'+CHAR(users.uid),
53 status=0 WHERE users_id = :id;
54 EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
68bbc9c3 55 if (rowcount > 0)
56 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
57 else
58 printf("Not fixed\n");
59 modified("users");
208a4f4a 60 }
68bbc9c3 61 } else {
62 uu = u;
63 }
208a4f4a 64 }
68bbc9c3 65 }
66}
67
68fix_user_id(u)
69struct user *u;
70{
71 u->users_id = generic_fix_id("users", "users_id", "login",
72 u->users_id, u->login);
73}
74
75
76cant_fix(id)
77int id;
78{
79 printf("Sorry, don't know how to fix that\n");
80}
81
82show_mach_id(m)
83struct machine *m;
84{
85 printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id);
86 return(0);
87}
88
89show_mach_name(m)
90struct machine *m;
91{
92 printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id);
93 return(0);
94}
95
96fix_mach_id(m)
97struct machine *m;
98{
99 m->mach_id = generic_fix_id("machine", "mach_id", "name",
100 m->mach_id, m->name);
101}
102
103show_clu_id(c)
104struct cluster *c;
105{
106 printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id);
107 return(0);
108}
109
110show_clu_name(c)
111struct cluster *c;
112{
113 printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id);
114 return(0);
115}
116
117fix_clu_id(c)
118struct cluster *c;
119{
120 c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name);
121}
122
123show_list_id(l)
124struct list *l;
125{
126 printf("List %s has duplicate ID %d\n", l->name, l->list_id);
127 return(0);
128}
129
130show_list_name(l)
131struct list *l;
132{
133 printf("List %s (%d) has duplicate name\n", l->name, l->list_id);
134 return(0);
135}
136
137fix_list_id(l)
138struct list *l;
139{
140 l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name);
141}
142
143show_fs_id(f)
144struct filesys *f;
145{
146 printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id);
147 return(0);
148}
149
150fix_fs_id(f)
151struct filesys *f;
152{
153 f->filsys_id = generic_fix_id("filesys", "filsys_id", "label",
154 f->filsys_id, f->name);
155}
156
157
158show_np_id(n)
159struct nfsphys *n;
160{
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);
164 return(0);
165}
166
167fix_np_id(n)
168struct nfsphys *n;
169{
170 n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir",
171 n->nfsphys_id, n->dir);
172}
173
174show_str_id(s)
175struct string *s;
176{
177 printf("String %s has duplicate ID %d\n", s->name, s->string_id);
178 return(0);
179}
180
181
182phase1()
208a4f4a 183{
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;
68bbc9c3 188 struct save_queue *sq;
189 struct user *u;
190 struct machine *m;
191 struct list *l;
192 struct cluster *c;
193 struct string *s;
194 struct filesys *f;
195 struct nfsphys *n;
196
197 printf("Phase 1 - Looking for duplicates\n");
198
199 dprintf("Loading strings...\n");
200 sq = sq_create();
201 strings = create_hash(5000);
7f0899e3 202
208a4f4a 203 EXEC SQL DECLARE csr101 CURSOR FOR
7f0899e3 204 SELECT string_id, string FROM strings ORDER BY string_id;
ced12e61 205 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 206 EXEC SQL OPEN csr101;
207 while(1) {
208 EXEC SQL FETCH csr101 INTO :id, :buf;
7bf0a6f3 209 if (sqlca.sqlcode != 0) {
210 ingerr(&sqlca.sqlcode);
211 break;
212 }
208a4f4a 213
68bbc9c3 214 s = (struct string *) malloc(sizeof(struct string));
215 if (s == NULL)
216 out_of_mem("storing strings");
217 s->name = strsave(strtrim(buf));
218 s->string_id = id;
219 s->refc = 0;
220 if (hash_store(strings, id, s)) {
221 sq_save_data(sq, hash_lookup(strings, id));
222 sq_save_data(sq, s);
223 }
208a4f4a 224 }
225 EXEC SQL CLOSE csr101;
68bbc9c3 226 generic_delete(sq, show_str_id, "strings", "string_id", 0);
227 string_check(0);
228
229 dprintf("Loading users...\n");
230 sq = sq_create();
231 users = create_hash(10000);
7f0899e3 232
208a4f4a 233 EXEC SQL DECLARE csr102 CURSOR FOR
234 SELECT users_id, login, last, first, status, potype, pop_id, box_id,
7f0899e3 235 modby, fmodby, pmodby, comment, sigwho FROM users ORDER BY users_id;
ced12e61 236 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 237 EXEC SQL OPEN csr102;
238 while(1) {
239 EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status,
240 :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5;
7bf0a6f3 241 if (sqlca.sqlcode != 0) {
242 ingerr(&sqlca.sqlcode);
243 break;
244 }
208a4f4a 245
68bbc9c3 246 u = (struct user *) malloc(sizeof(struct user));
247 if (u == NULL)
248 out_of_mem("storing users");
249 strcpy(u->login, strtrim(name));
250 u->potype = buf[0];
251 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
252 u->fullname = strsave(buf);
253 u->status = status;
254 u->users_id = id;
255 switch (u->potype) {
256 case 'P':
257 u->pobox_id = id2;
258 break;
259 case 'S':
260 u->pobox_id = id3;
261 break;
262 default:
263 u->pobox_id = 0;
264 }
265 if (hash_store(users, id, u)) {
266 sq_save_data(sq, hash_lookup(users, id));
267 sq_save_data(sq, u);
268 }
269 if (sid < 0)
270 string_check(-sid);
271 if (sid2 < 0)
272 string_check(-sid2);
273 if (sid3 < 0)
274 string_check(-sid3);
275 if (sid4)
276 string_check(sid4);
277 if (sid5)
278 string_check(sid5);
208a4f4a 279 }
280 EXEC SQL CLOSE csr102;
281
68bbc9c3 282 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
283
284 if (!fast) {
285 sq = sq_create();
7f0899e3 286
208a4f4a 287 EXEC SQL DECLARE csr103 CURSOR FOR
7f0899e3 288 SELECT u1.users_id FROM users u1, users u2
289 WHERE u1.login = u2.login and u1.tid != u2.tid;
ced12e61 290 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 291 EXEC SQL OPEN csr103;
292 while(1) {
293 EXEC SQL FETCH csr103 INTO :id;
7bf0a6f3 294 if (sqlca.sqlcode != 0) {
295 ingerr(&sqlca.sqlcode);
296 break;
297 }
208a4f4a 298 sq_save_data(sq, hash_lookup(users, id));
299 }
300 EXEC SQL CLOSE csr103;
68bbc9c3 301 handle_duplicate_logins(sq);
302 }
303
304 dprintf("Loading machines...\n");
305 machines = create_hash(1000);
306 sq = sq_create();
7f0899e3 307
208a4f4a 308 EXEC SQL DECLARE csr104 CURSOR FOR
772b7afc 309 SELECT mach_id, name, snet_id, owner_type, owner_id,
310 acomment, ocomment, creator, modby
311 FROM machine ORDER BY mach_id;
ced12e61 312 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 313 EXEC SQL OPEN csr104;
314 while(1) {
772b7afc 315 EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2,
316 :sid3, :sid4, :sid;
7bf0a6f3 317 if (sqlca.sqlcode != 0) {
318 ingerr(&sqlca.sqlcode);
319 break;
320 }
208a4f4a 321
68bbc9c3 322 m = (struct machine *) malloc(sizeof(struct machine));
323 if (m == NULL)
324 out_of_mem("storing machines");
325 strcpy(m->name, strtrim(name));
772b7afc 326 m->owner_type = buf[0];
327 m->owner_id = id3;
328 m->snet_id = id2;
68bbc9c3 329 m->mach_id = id;
330 m->clucount = 0;
331 if (hash_store(machines, id, m)) {
332 sq_save_data(sq, hash_lookup(machines, id));
333 sq_save_data(sq, m);
334 }
772b7afc 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);
208a4f4a 339 }
340 EXEC SQL CLOSE csr104;
68bbc9c3 341 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
342
343 if (!fast) {
344 sq = sq_create();
7f0899e3 345
208a4f4a 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;
ced12e61 349 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 350 EXEC SQL OPEN csr105;
351 while(1) {
352 EXEC SQL FETCH csr105 INTO :id;
7bf0a6f3 353 if (sqlca.sqlcode != 0) {
354 ingerr(&sqlca.sqlcode);
355 break;
356 }
208a4f4a 357
358 sq_save_data(sq, hash_lookup(machines, id));
359 }
360 EXEC SQL CLOSE csr105;
68bbc9c3 361 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
362 }
363
772b7afc 364 dprintf("Loading subnets...\n");
365 subnets = create_hash(254);
366
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;
371 while(1) {
372 EXEC SQL FETCH csr115 INTO :id, :name;
373 if (sqlca.sqlcode != 0) {
374 ingerr(&sqlca.sqlcode);
375 break;
376 }
377 if (hash_store(subnets, id, name)) {
378 printf("Duplicate subnet ID: %d (%s)\n", id, name);
379 }
380 }
381 EXEC SQL CLOSE csr115;
382
68bbc9c3 383 dprintf("Loading clusters...\n");
384 sq = sq_create();
385 clusters = create_hash(100);
7f0899e3 386
208a4f4a 387 EXEC SQL DECLARE csr106 CURSOR FOR
388 SELECT clu_id, name, modby FROM cluster;
ced12e61 389 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 390 EXEC SQL OPEN csr106;
391 while(1) {
392 EXEC SQL FETCH csr106 INTO :id, :name, :sid;
7bf0a6f3 393 if (sqlca.sqlcode != 0) {
394 ingerr(&sqlca.sqlcode);
395 break;
396 }
208a4f4a 397
68bbc9c3 398 c = (struct cluster *) malloc(sizeof(struct cluster));
399 if (c == NULL)
400 out_of_mem("storing clusters");
401 strcpy(c->name, strtrim(name));
402 c->clu_id = id;
403 if (hash_store(clusters, id, c)) {
404 sq_save_data(sq, hash_lookup(clusters, id));
405 sq_save_data(sq, c);
406 }
407 if (sid < 0)
408 string_check(-sid);
208a4f4a 409 }
410 EXEC SQL CLOSE csr106;
68bbc9c3 411 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
412
413 if (!fast) {
414 sq = sq_create();
7f0899e3 415
208a4f4a 416 EXEC SQL DECLARE csr107 CURSOR FOR
7bf0a6f3 417 SELECT c1.clu_id FROM cluster c1, cluster c2
208a4f4a 418 WHERE c1.name=c2.name AND c1.tid != c2.tid;
ced12e61 419 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 420 EXEC SQL OPEN csr107;
421 while(1) {
422 EXEC SQL FETCH csr107 INTO :id;
7bf0a6f3 423 if (sqlca.sqlcode != 0) {
424 ingerr(&sqlca.sqlcode);
425 break;
426 }
208a4f4a 427
428 sq_save_data(sq, hash_lookup(clusters, id));
429 }
430 EXEC SQL CLOSE csr107;
68bbc9c3 431 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
432 }
433
434 dprintf("Loading lists...\n");
435 sq = sq_create();
436 lists = create_hash(10000);
7f0899e3 437
208a4f4a 438 EXEC SQL DECLARE csr108 CURSOR FOR
7f0899e3 439 SELECT list_id, name, acl_id, acl_type, modby FROM list
440 ORDER BY list_id;
ced12e61 441 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 442 EXEC SQL OPEN csr108;
443 while(1) {
444 EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid;
7bf0a6f3 445 if (sqlca.sqlcode != 0) {
446 ingerr(&sqlca.sqlcode);
447 break;
448 }
68bbc9c3 449 l = (struct list *) malloc(sizeof(struct list));
450 if (l == NULL)
451 out_of_mem("storing lists");
452 strcpy(l->name, strtrim(name));
453 l->acl_type = buf[0];
454 l->acl_id = aid;
455 l->list_id = id;
456 l->members = 0;
457 if (hash_store(lists, id, l)) {
458 sq_save_data(sq, hash_lookup(lists, id));
459 sq_save_data(sq, l);
460 }
461 if (sid < 0)
462 string_check(-sid);
208a4f4a 463 }
464 EXEC SQL CLOSE csr108;
68bbc9c3 465 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
466
467 if (!fast) {
468 sq = sq_create();
7f0899e3 469
208a4f4a 470 EXEC SQL DECLARE csr109 CURSOR FOR
7bf0a6f3 471 SELECT l1.list_id FROM list l1, list l2
208a4f4a 472 WHERE l1.name=l2.name AND l1.tid != l2.tid;
ced12e61 473 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 474 EXEC SQL OPEN csr109;
475 while(1) {
476 EXEC SQL FETCH csr109 INTO :id;
7bf0a6f3 477 if (sqlca.sqlcode != 0) {
478 ingerr(&sqlca.sqlcode);
479 break;
480 }
208a4f4a 481
482 sq_save_data(sq, hash_lookup(lists, id));
483 }
484 EXEC SQL CLOSE csr109;
68bbc9c3 485 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
486 }
487
488 dprintf("Loading filesys...\n");
489 sq = sq_create();
490 filesys = create_hash(10000);
7f0899e3 491
208a4f4a 492 EXEC SQL DECLARE csr110 CURSOR FOR
493 SELECT filsys_id, label, owner, owners, phys_id, mach_id,
7f0899e3 494 type, name, modby FROM filesys ORDER BY filsys_id;
ced12e61 495 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 496 EXEC SQL OPEN csr110;
497 while(1) {
498 EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3,
499 :buf, :name1, :sid;
7bf0a6f3 500 if (sqlca.sqlcode != 0) {
501 ingerr(&sqlca.sqlcode);
502 break;
503 }
208a4f4a 504
68bbc9c3 505 f = (struct filesys *) malloc(sizeof(struct filesys));
506 if (f == NULL)
507 out_of_mem("storing filesystems");
508 strcpy(f->name, strtrim(name));
509 strcpy(f->dir, strtrim(name1));
510 f->filsys_id = id;
511 f->owner = aid;
512 f->owners = aid2;
513 f->phys_id = id2;
514 f->mach_id = id3;
515 f->type = buf[0];
516 if (hash_store(filesys, id, f)) {
517 sq_save_data(sq, hash_lookup(filesys, id));
518 sq_save_data(sq, f);
519 }
520 if (sid < 0)
521 string_check(-sid);
208a4f4a 522 }
523 EXEC SQL CLOSE csr110;
524
68bbc9c3 525 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
526
527 dprintf("Loading nfsphys...\n");
528 sq = sq_create();
529 nfsphys = create_hash(500);
7f0899e3 530
208a4f4a 531 EXEC SQL DECLARE csr111 CURSOR FOR
532 SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
ced12e61 533 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 534 EXEC SQL OPEN csr111;
535 while(1) {
536 EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid;
7bf0a6f3 537 if (sqlca.sqlcode != 0) {
538 ingerr(&sqlca.sqlcode);
539 break;
540 }
208a4f4a 541
68bbc9c3 542 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
543 if (n == NULL)
544 out_of_mem("storing nfsphys");
545 strcpy(n->dir, strtrim(name));
546 n->mach_id = id2;
547 n->nfsphys_id = id;
548 n->allocated = id3;
549 n->count = 0;
550 if (hash_store(nfsphys, id, n)) {
551 sq_save_data(sq, hash_lookup(nfsphys, id));
552 sq_save_data(sq, n);
553 }
554 if (sid < 0)
555 string_check(-sid);
208a4f4a 556 }
557 EXEC SQL CLOSE csr111;
558
68bbc9c3 559 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
560
561 if (!fast) {
7f0899e3 562
1b49ecc0 563 dprintf("Checking for duplicate strings...\n");
208a4f4a 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;
ced12e61 567 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 568 EXEC SQL OPEN csr112;
569 while(1) {
570 EXEC SQL FETCH csr112 INTO :id, :buf;
7bf0a6f3 571 if (sqlca.sqlcode != 0) {
572 ingerr(&sqlca.sqlcode);
573 break;
574 }
208a4f4a 575
576 printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
577 printf("Not fixing this error\n");
578 }
579 EXEC SQL CLOSE csr112;
68bbc9c3 580 }
581
582 if (!fast) {
583 dprintf("Scanning krbmap...\n");
7f0899e3 584
208a4f4a 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;
ced12e61 588 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 589 EXEC SQL OPEN csr113;
590 while(1) {
591 EXEC SQL FETCH csr113 INTO :id;
7bf0a6f3 592 if (sqlca.sqlcode != 0) {
593 ingerr(&sqlca.sqlcode);
594 break;
595 }
208a4f4a 596
597 printf("User %d is in the krbmap more than once!\n", id);
598 printf("Not fixing this error\n");
599 }
600 EXEC SQL CLOSE csr113;
68bbc9c3 601
208a4f4a 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;
ced12e61 605 if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
208a4f4a 606 EXEC SQL OPEN csr114;
607 while(1) {
608 EXEC SQL FETCH csr114 INTO :id;
7bf0a6f3 609 if (sqlca.sqlcode != 0) {
610 ingerr(&sqlca.sqlcode);
611 break;
612 }
208a4f4a 613
614 printf("Principal %d is in the krbmap more than once!\n", id);
615 printf("Not fixing this error\n");
616 }
617 EXEC SQL CLOSE csr114;
618 }
619}
This page took 0.143939 seconds and 5 git commands to generate.