]> andersk Git - moira.git/blob - dbck/phase2.dc
check new hosttable info
[moira.git] / dbck / phase2.dc
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 <stdio.h>
10 #include <moira.h>
11 #include "dbck.h"
12 EXEC SQL INCLUDE sqlca;
13
14 static char phase2_qc_rcsid[] = "$Header$";
15
16
17 show_mcm_mach(id)
18 int id;
19 {
20     EXEC SQL BEGIN DECLARE SECTION; 
21     int iid = id, found = 1;
22     char name[33];
23     EXEC SQL END DECLARE SECTION; 
24
25     EXEC SQL DECLARE csr201 CURSOR FOR
26       SELECT cluster.name FROM cluster, mcmap
27         WHERE cluster.clu_id=mcmap.clu_id AND mcmap.mach_id = :iid;
28     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
29     EXEC SQL OPEN csr201;
30     while(1) {
31         EXEC SQL FETCH csr201 INTO :name;
32         if (sqlca.sqlcode != 0) {
33           ingerr(&sqlca.sqlcode);
34           break;
35         } 
36
37         strtrim(name);
38         found = 0;
39         printf("Clusqter %s, non-existant machine %d in cluster map\n", name, id);
40     }
41     EXEC SQL CLOSE csr201; 
42     return(found);
43 }
44
45 show_mcm_clu(id)
46 int id;
47 {
48     EXEC SQL BEGIN DECLARE SECTION; 
49     int iid = id, found = 1;
50     char name[33];
51     EXEC SQL END DECLARE SECTION; 
52
53     EXEC SQL DECLARE csr202 CURSOR FOR
54         SELECT machine.name FROM machine, mcmap
55             WHERE machine.mach_id=mcmap.mach_id AND mcmap.clu_id=:iid;
56     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
57     EXEC SQL OPEN csr202;
58     while(1) {
59         EXEC SQL FETCH csr202 INTO :name;
60         if (sqlca.sqlcode != 0) {
61           ingerr(&sqlca.sqlcode);
62           break;
63         } 
64
65         strtrim(name);
66         found = 0;
67         printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
68     }
69     EXEC SQL CLOSE csr202; 
70     return(found);
71 }
72
73 pobox_check(id, u, hint)
74 int id;
75 struct user *u;
76 int hint;
77 {
78     switch (u->potype) {
79     case 'P':
80         if (!hash_lookup(machines, u->pobox_id)) {
81             printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
82                    u->login, u->fullname, u->pobox_id);
83             if (single_fix("Delete", 0)) {
84                 remove_pobox(u->users_id);
85                 u->potype = 'N';
86             }
87         }
88         break;
89     case 'S':
90         if (!string_check(u->pobox_id)) {
91             printf("User %s(%s) has P.O.Box with non-existant string %d\n",
92                    u->login, u->fullname, u->pobox_id);
93             if (single_fix("Delete", 0)) {
94                 remove_pobox(u->users_id);
95                 u->potype = 'N';
96             }
97         }
98         break;
99     default:
100         ;
101     }
102 }
103
104
105 remove_pobox(id)
106 int id;
107 {
108     EXEC SQL BEGIN DECLARE SECTION; 
109     int rowcount, iid = id;
110     EXEC SQL END DECLARE SECTION; 
111
112     EXEC SQL UPDATE users SET potype='NONE' WHERE users.users_id = :iid;
113     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
114     if (rowcount > 0)
115       printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies");
116     else
117       printf("Not removed\n");
118     modified("users");
119 }
120
121
122 mach_check(id, m, hint)
123 int id;
124 struct machine *m;
125 int hint;
126 {
127     if (!hash_lookup(subnets, m->snet_id)) {
128         printf("Machine %s is on a non-existant subnet %d\n",
129                m->name, m->snet_id);
130         if (single_fix("Move to null-subnet", 1)) {
131             EXEC SQL BEGIN DECLARE SECTION; 
132             int rowcount, iid = id;
133             EXEC SQL END DECLARE SECTION; 
134
135             EXEC SQL UPDATE machine SET snet_id=0 WHERE mach_id = :iid;
136             EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
137             if (rowcount > 0)
138               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
139             else
140               printf("Not fixed\n");
141             modified("machine");
142         }
143     }
144
145     switch (m->owner_type) {
146     case 'U':
147         if (!hash_lookup(users, m->owner_id)) {
148             printf("Machine %s has non-existant USER owner %d\n",
149                    m->name, m->owner_id);
150             if (single_fix("Set to no owner", 1)) {
151                 clear_mach_owner(m);
152             }
153         }
154         break;
155     case 'L':
156         if (!hash_lookup(lists, m->owner_id)) {
157             printf("Machine %s has non-existant LIST owner %d\n",
158                    m->name, m->owner_id);
159             if (single_fix("Set to no owner", 1)) {
160                 clear_mach_owner(m);
161             }
162         }
163         break;
164     }
165 }
166
167
168 clear_mach_owner(m)
169 struct machine *m;
170 {
171     EXEC SQL BEGIN DECLARE SECTION; 
172     int rowcount, id = m->mach_id;
173     EXEC SQL END DECLARE SECTION; 
174
175     EXEC SQL UPDATE machine SET owner_type='NONE', owner_id=0
176       WHERE mach_id = :id;
177     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
178     if (rowcount > 0)
179       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
180     else
181       printf("Not fixed\n");
182     modified("machine");
183 }
184
185
186 show_svc(id)
187 int id;
188 {
189     EXEC SQL BEGIN DECLARE SECTION; 
190     int iid = id, found = 1;
191     char label[17], data[33];
192     EXEC SQL END DECLARE SECTION; 
193
194     EXEC SQL DECLARE csr203 CURSOR FOR
195         SELECT serv_label, serv_cluster FROM svc
196             WHERE clu_id = :iid;
197     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
198     EXEC SQL OPEN csr203;
199     while(1) {
200         EXEC SQL FETCH csr203 INTO :label, :data;
201         if (sqlca.sqlcode != 0) {
202           ingerr(&sqlca.sqlcode);
203           break;
204         }
205
206         strtrim(label);
207         strtrim(data);
208         found = 0;
209         printf("Cluster data [%s] %s for non-existant cluster %d\n",
210                label, data, id);
211     }
212     EXEC SQL CLOSE csr203; 
213     return(found);
214 }
215
216 list_check(id, l, hint)
217 int id;
218 struct list *l;
219 int hint;
220 {
221     switch (l->acl_type) {
222     case 'L':
223         if (!hash_lookup(lists, l->acl_id)) {
224             printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
225             if (single_fix("Patch", 1)) {
226                 fix_list_acl(l->list_id);
227             }
228         }
229         break;
230     case 'U':
231         if (!hash_lookup(users, l->acl_id)) {
232             printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
233             if (single_fix("Patch", 1)) {
234                 fix_list_acl(l->list_id);
235             }
236         }
237         break;
238     }
239 }
240
241 fix_list_acl(id)
242 int id;
243 {
244     EXEC SQL BEGIN DECLARE SECTION; 
245     int rowcount, iid = id;
246     EXEC SQL END DECLARE SECTION; 
247
248     EXEC SQL UPDATE list SET acl_id = :iid, acl_type='LIST'
249         WHERE list_id = :iid;
250     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
251     if (rowcount > 0)
252       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
253     else
254       printf("Not fixed\n");
255     modified("list");
256 }
257
258
259 show_member_list(id)
260 int id;
261 {
262     EXEC SQL BEGIN DECLARE SECTION; 
263     int mid, iid = id, found = 1;
264     char mtype[9], *name = "";
265     EXEC SQL END DECLARE SECTION;
266
267     EXEC SQL DECLARE csr204 CURSOR FOR
268         SELECT member_type, member_id FROM imembers
269             WHERE list_id = :iid AND direct=1;
270     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
271     EXEC SQL OPEN csr204;
272     while(1) {
273         EXEC SQL FETCH csr204 INTO :mtype, :mid;
274         if (sqlca.sqlcode != 0) {
275           ingerr(&sqlca.sqlcode);
276           break;
277         } 
278
279         strtrim(mtype);
280         found = 0;
281         if (mtype[0] == 'L')
282             name = ((struct list *) hash_lookup(lists, mid))->name;
283         else if (mtype[0] == 'U')
284             name = ((struct user *) hash_lookup(users, mid))->login;
285         else if (mtype[0] == 'S' || mtype[0] == 'K')
286             name = ((struct string *) hash_lookup(strings, mid))->name;
287         printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
288     }
289     EXEC SQL CLOSE csr204; 
290     return(found);
291 }
292
293 show_mem_user(id)
294 int id;
295 {
296     EXEC SQL BEGIN DECLARE SECTION; 
297     int lid, iid = id, found = 1;
298     char name[33];
299     EXEC SQL END DECLARE SECTION; 
300
301     EXEC SQL DECLARE csr205 CURSOR FOR
302       SELECT list_id FROM imembers
303         WHERE member_id = :iid AND member_type='USER' AND direct=1;
304     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
305     EXEC SQL OPEN csr205;
306     while(1) {
307         EXEC SQL FETCH csr205 INTO :lid;
308         if (sqlca.sqlcode != 0) {
309           ingerr(&sqlca.sqlcode);
310           break;
311         }       
312         
313         found = 0;
314         printf("List %s has non-existant user member, id %d\n",
315                ((struct list *)hash_lookup(lists, lid))->name, iid);
316     }
317     EXEC SQL CLOSE csr205;
318     return(found);
319 }
320
321 show_mem_list(id)
322 int id;
323 {
324     EXEC SQL BEGIN DECLARE SECTION; 
325     int lid, iid = id, found = 1;
326     char name[33];
327     EXEC SQL END DECLARE SECTION; 
328
329     EXEC SQL DECLARE csr206 CURSOR FOR
330         SELECT list_id FROM imembers
331             WHERE member_id = :iid AND member_type='LIST' AND direct=1;
332     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
333     EXEC SQL OPEN csr206;
334     while(1) {
335         EXEC SQL FETCH csr206 INTO :lid;
336         if (sqlca.sqlcode != 0) {
337           ingerr(&sqlca.sqlcode);
338           break;
339         } 
340
341         found = 0;
342         printf("List %s has non-existant list member, id %d\n",
343                ((struct list *)hash_lookup(lists, lid))->name, iid);
344     }
345     EXEC SQL CLOSE csr206; 
346     return(found);
347 }
348
349 show_mem_str(id)
350 int id;
351 {
352     EXEC SQL BEGIN DECLARE SECTION; 
353     int lid, iid = id, found = 1;
354     char name[33];
355     EXEC SQL END DECLARE SECTION; 
356
357     EXEC SQL DECLARE csr207 CURSOR FOR
358         SELECT list_id FROM imembers
359             WHERE member_id = :iid AND member_type='STRING' AND direct=1;
360     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
361     EXEC SQL OPEN csr207;
362     while(1) {
363         EXEC SQL FETCH csr207 INTO :lid;
364         if (sqlca.sqlcode != 0) {
365           ingerr(&sqlca.sqlcode);
366           break;
367         } 
368         
369         found = 0;
370         printf("List %s has non-existant string member, id %d\n",
371                ((struct list *)hash_lookup(lists, lid))->name, iid);
372     }
373     EXEC SQL CLOSE csr207; 
374     return(found);
375 }
376
377
378 show_mem_krb(id)
379 int id;
380 {
381     EXEC SQL BEGIN DECLARE SECTION; 
382     int lid, iid = id, found = 1;
383     char name[33];
384     EXEC SQL END DECLARE SECTION; 
385
386     EXEC SQL DECLARE csr208 CURSOR FOR
387         SELECT list_id FROM imembers
388             WHERE member_id = :iid AND member_type='KERBEROS' AND direct=1;
389     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
390     EXEC SQL OPEN csr208;
391     while(1) {
392         EXEC SQL FETCH csr208 INTO :lid;
393         if (sqlca.sqlcode != 0) {
394           ingerr(&sqlca.sqlcode);
395           break;
396         } 
397
398         found = 0;
399         printf("List %s has non-existant kerberos member, id %d\n",
400                ((struct list *)hash_lookup(lists, lid))->name, iid);
401     }
402     EXEC SQL CLOSE csr208; 
403     return(found);
404 }
405
406
407 del_mem_user(id)
408 EXEC SQL BEGIN DECLARE SECTION; 
409 int id;
410 EXEC SQL END DECLARE SECTION; 
411 {
412     EXEC SQL BEGIN DECLARE SECTION; 
413     int rowcount;
414     EXEC SQL END DECLARE SECTION; 
415
416     EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND
417         member_id = :id AND direct = 1;
418     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
419     if (rowcount > 0)
420       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
421     else
422       printf("Not deleted\n");
423     modified("imembers");
424 }
425
426 del_mem_list(id)
427 EXEC SQL BEGIN DECLARE SECTION; 
428 int id;
429 EXEC SQL END DECLARE SECTION; 
430 {
431     EXEC SQL BEGIN DECLARE SECTION; 
432     int rowcount;
433     EXEC SQL END DECLARE SECTION; 
434
435     EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND
436         member_id = :id AND direct=1;
437     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
438     if (rowcount > 0)
439       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
440     else
441       printf("Not deleted\n");
442     modified("imembers");
443 }
444
445 del_mem_str(id)
446 EXEC SQL BEGIN DECLARE SECTION; 
447 int id;
448 EXEC SQL END DECLARE SECTION; 
449 {
450     EXEC SQL BEGIN DECLARE SECTION; 
451     int rowcount;
452     EXEC SQL END DECLARE SECTION; 
453
454     EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND
455         member_id = :id AND direct=1;
456     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
457     if (rowcount > 0)
458       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
459     else
460       printf("Not deleted\n");
461     modified("imembers");
462 }
463
464
465 del_mem_krb(id)
466 EXEC SQL BEGIN DECLARE SECTION; 
467 int id;
468 EXEC SQL END DECLARE SECTION; 
469 {
470     EXEC SQL BEGIN DECLARE SECTION; 
471     int rowcount;
472     EXEC SQL END DECLARE SECTION; 
473
474     EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND
475         member_id = :id AND direct=1;
476     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
477     if (rowcount > 0)
478       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
479     else
480       printf("Not deleted\n");
481     modified("imembers");
482 }
483
484
485 show_sh(id)
486 EXEC SQL BEGIN DECLARE SECTION; 
487 int id;
488 EXEC SQL END DECLARE SECTION; 
489 {
490     EXEC SQL BEGIN DECLARE SECTION; 
491     char name[33];
492     EXEC SQL END DECLARE SECTION; 
493     int found = 1;
494
495     EXEC SQL DECLARE csr209 CURSOR FOR
496         SELECT service FROM serverhosts
497             WHERE mach_id = :id;
498     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
499     EXEC SQL OPEN csr209;
500     while(1) {
501         EXEC SQL FETCH csr209 INTO :name;
502         if (sqlca.sqlcode != 0) {
503           ingerr(&sqlca.sqlcode);
504           break;
505         } 
506
507         found = 0;
508         printf("ServerHost entry for service %s non-existant host %d\n",
509                name, id);
510     }
511     EXEC SQL CLOSE csr209; 
512     return(found);
513 }
514
515 del_sh_mach(id)
516 EXEC SQL BEGIN DECLARE SECTION; 
517 int id;
518 EXEC SQL END DECLARE SECTION; 
519 {
520     EXEC SQL BEGIN DECLARE SECTION; 
521     int rowcount;
522     EXEC SQL END DECLARE SECTION; 
523
524     EXEC SQL DELETE FROM serverhosts WHERE mach_id = :id;
525     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
526     if (rowcount > 0)
527       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
528     else
529       printf("Not deleted\n");
530     modified("serverhosts");
531 }
532
533
534 static int fnchecklen;
535
536 fsmatch(id, n, f)
537 int id;
538 struct nfsphys *n;
539 struct filesys *f;
540 {
541     if (n->mach_id == f->mach_id &&
542         !strncmp(f->dir, n->dir, strlen(n->dir)) &&
543         strlen(n->dir) > fnchecklen) {
544         f->phys_id = id;
545         fnchecklen = strlen(n->dir);
546     }
547 }
548
549
550 check_fs(id, f, hint)
551 EXEC SQL BEGIN DECLARE SECTION; 
552 int id;
553 EXEC SQL END DECLARE SECTION; 
554 register struct filesys *f;
555 int hint;
556 {
557     EXEC SQL BEGIN DECLARE SECTION; 
558     int id1, id2, id3, rowcount;
559     char *dir;
560     EXEC SQL END DECLARE SECTION; 
561     struct nfsphys *n;
562     struct machine *m;
563
564     if (!hash_lookup(machines, f->mach_id)) {
565         printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
566         if (single_fix("Fix", 0)) {
567             EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :id;
568             EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
569             if (rowcount > 0)
570               printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
571             else
572               printf("Not fixed\n");
573             modified("filesys");
574             f->mach_id = 0;
575         }
576     }
577
578     if (!hash_lookup(users, f->owner)) {
579         printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
580         if (single_fix("Fix", 1)) {
581             zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
582             f->owner = 0;
583         }
584     }
585     if (!hash_lookup(lists, f->owners)) {
586         printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
587         if (single_fix("Fix", 1)) {
588             zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
589             f->owners = 0;
590         }
591     }
592
593     if (f->type == 'N') {
594         if (!hash_lookup(nfsphys, f->phys_id)) {
595             m = (struct machine *)hash_lookup(machines, f->mach_id);
596             printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
597             if (single_fix("Fix", 1)) {
598                 fnchecklen = 0;
599                 hash_step(nfsphys, fsmatch, f);
600                 if (fnchecklen != 0) {
601                   id1 = f->phys_id;
602                   id2 = f->filsys_id;
603                   id3 = f->mach_id;
604                   EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2;
605                   EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
606                   if (rowcount > 0)
607                     printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
608                   else
609                     printf("Not fixed\n");
610                   modified("filesys");
611                 } else {
612                     printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
613                     if (single_fix("Create", 0)) {
614                         dir = f->dir;
615                         id1 = f->phys_id;
616                         id2 = f->filsys_id;
617                         id3 = f->mach_id;
618                         if (set_next_object_id("nfsphys_id", "nfsphys") !=
619                                 MR_SUCCESS) {
620                             printf("Unable to assign unique ID\n");
621                             return;
622                         }
623                         EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues 
624                             WHERE name='nfsphys_id';
625                         if (rowcount != 1) {
626                             printf("Unable to retrieve unique ID\n");
627                             return;
628                         }
629                         EXEC SQL INSERT INTO mfsphys (mfsphys_id, mach_id,
630                             device, dir, status, allocated, size, modtime,
631                             modby, modwith) VALUES (:id1, :id3, '???', :dir,
632                             0, 0, 0, 'now', 0, 'dbck');
633                         EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
634                         if (rowcount > 0)
635                           printf("%d entr%s created\n", rowcount,
636                                  rowcount==1?"y":"ies");
637                         else
638                           printf("Not created\n");
639                         modified("nfsphys");
640                         n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
641                         if (n == NULL)
642                           out_of_mem("storing new nfsphys");
643                         strcpy(n->dir, dir);
644                         n->mach_id = id3;
645                         n->nfsphys_id = id1;
646                         n->allocated = 0;
647                         n->count = 0;
648                         hash_store(nfsphys, id1, n);
649                         EXEC SQL UPDATE filesys SET phys_id = :id1
650                             WHERE filsys_id = :id2;
651                         EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
652                         if (rowcount > 0)
653                           printf("%d filesys entr%s fixed\n", rowcount,
654                                  rowcount==1?"y":"ies");
655                         else
656                           printf("Not fixed\n");
657                         modified("filesys");
658                     }
659                 }
660             }
661         }
662     }
663 }
664
665
666 check_nfsphys(id, n, hint)
667 int id;
668 struct nfsphys *n;
669 int hint;
670 {
671     if (!hash_lookup(machines, n->mach_id)) {
672         printf("NFSphys %d(%s) on non-existant machine %d\n",
673                id, n->dir, n->mach_id);
674         if (single_fix("Delete", 0))
675           single_delete("nfsphys", "nfsphys_id", id);
676     }
677 }
678
679 show_fsg_missing(id)
680 EXEC SQL BEGIN DECLARE SECTION; 
681 int id;
682 EXEC SQL END DECLARE SECTION; 
683 {
684     EXEC SQL BEGIN DECLARE SECTION; 
685     int id1, found = 1;
686     EXEC SQL END DECLARE SECTION; 
687     struct filesys *f;
688
689     EXEC SQL DECLARE csr210 CURSOR FOR
690         SELECT filsys_id FROM fsgroup
691             WHERE group_id = :id;
692     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
693     EXEC SQL OPEN csr210;
694     while(1) {
695         EXEC SQL FETCH csr210 INTO :id1;
696         if (sqlca.sqlcode != 0) {
697           ingerr(&sqlca.sqlcode);
698           break;
699         } 
700
701         found = 0;
702         if (f = (struct filesys *) hash_lookup(filesys, id1))
703             printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
704         else
705             printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
706     }
707     EXEC SQL CLOSE csr210; 
708     return(found);
709 }
710
711 show_fsg_type(f)
712 struct filesys *f;
713 {
714     char *t;
715
716     switch (f->type) {
717     case 'N':
718         t = "NFS";
719         break;
720     case 'R':
721         t = "RVD";
722         break;
723     case 'A':
724         t = "AFS";
725         break;
726     case 'E':
727         t = "ERR";
728         break;
729     case 'F':
730         t = "FSGROUP";
731         break;
732     case 'M':
733         t = "MUL";
734         break;
735     default:
736         t = "???";
737     }
738     printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
739     return(0);
740 }
741
742 fix_fsg_type(f)
743 struct filesys *f;
744 {
745     EXEC SQL BEGIN DECLARE SECTION; 
746     int rowcount, id = f->filsys_id;
747     EXEC SQL END DECLARE SECTION; 
748
749     EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id;
750     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
751     if (rowcount > 0)
752       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
753     else
754       printf("Not fixed\n");
755     modified("filesys");
756 }
757
758 show_fsg_nomember(id)
759 EXEC SQL BEGIN DECLARE SECTION; 
760 int id;
761 EXEC SQL END DECLARE SECTION; 
762 {
763     EXEC SQL BEGIN DECLARE SECTION; 
764     int id1, found = 1;
765     EXEC SQL END DECLARE SECTION; 
766     struct filesys *f;
767
768     EXEC SQL DECLARE csr211 CURSOR FOR
769         SELECT group_id FROM fsgroup
770             WHERE filsys_id = :id;
771     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
772     EXEC SQL OPEN csr211;
773     while(1) {
774         EXEC SQL FETCH csr211 INTO :id1;
775         if (sqlca.sqlcode != 0) {
776           ingerr(&sqlca.sqlcode);
777           break;
778         } 
779
780         found = 0;
781         if (f = (struct filesys *) hash_lookup(filesys, id1))
782             printf("FSGroup %s has missing member %d\n", f->name, id);
783         else
784             printf("FSGroup %d has missing member %d\n", id1, id);
785     }
786     EXEC SQL CLOSE csr211; 
787     return(found);
788 }
789
790 show_quota_nouser(id)
791 EXEC SQL BEGIN DECLARE SECTION; 
792 int id;
793 EXEC SQL END DECLARE SECTION; 
794 {
795     EXEC SQL BEGIN DECLARE SECTION; 
796     int id1, found = 1;
797     EXEC SQL END DECLARE SECTION; 
798
799     EXEC SQL DECLARE csr212 CURSOR FOR
800         SELECT filsys_id FROM quota
801             WHERE entity_id = :id AND type='USER';
802     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
803     EXEC SQL OPEN csr212;
804     while(1) {
805         EXEC SQL FETCH csr212 INTO :id1;
806         if (sqlca.sqlcode != 0) {
807           ingerr(&sqlca.sqlcode);
808           break;
809         } 
810
811         found = 0;
812         printf("Quota on fs %d for non-existant user %d\n", id1, id);
813     }
814     EXEC SQL CLOSE csr212; 
815     return(found);
816 }
817
818 show_quota_nolist(id)
819 EXEC SQL BEGIN DECLARE SECTION; 
820 int id;
821 EXEC SQL END DECLARE SECTION; 
822 {
823     EXEC SQL BEGIN DECLARE SECTION; 
824     int id1, found = 1;
825     EXEC SQL END DECLARE SECTION; 
826
827     EXEC SQL DECLARE csr213 CURSOR FOR
828         SELECT filsys_id FROM quota 
829             WHERE entity_id = :id AND type='GROUP';
830     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
831     EXEC SQL OPEN csr213;
832     while(1) {
833         EXEC SQL FETCH csr213 INTO :id1;
834         if (sqlca.sqlcode != 0) {
835           ingerr(&sqlca.sqlcode);
836           break;
837         }
838  
839         found = 0;
840         printf("Quota on fs %d for non-existant list %d\n", id1, id);
841     }
842     EXEC SQL CLOSE csr213; 
843     return(found);
844 }
845
846 fix_quota_nouser(id)
847 EXEC SQL BEGIN DECLARE SECTION; 
848 int id;
849 EXEC SQL END DECLARE SECTION; 
850 {
851     EXEC SQL BEGIN DECLARE SECTION; 
852     int rowcount, id1;
853     EXEC SQL END DECLARE SECTION; 
854
855     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
856     EXEC SQL DELETE FROM quota 
857         WHERE entity_id = :id AND type = 'USER';
858     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
859     if (rowcount > 0)
860       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
861     else
862       printf("Not deleted\n");
863     modified("quota");
864 }
865
866 fix_quota_nolist(id)
867 EXEC SQL BEGIN DECLARE SECTION; 
868 int id;
869 EXEC SQL END DECLARE SECTION; 
870 {
871     EXEC SQL BEGIN DECLARE SECTION; 
872     int rowcount, id1;
873     EXEC SQL END DECLARE SECTION; 
874
875     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
876     EXEC SQL DELETE FROM quota WHERE entity_id = :id AND type='GROUP';
877     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
878     if (rowcount > 0)
879       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
880     else
881       printf("Not deleted\n");
882     modified("quota");
883 }
884
885 show_quota_nofs(id)
886 EXEC SQL BEGIN DECLARE SECTION; 
887 int id;
888 EXEC SQL END DECLARE SECTION; 
889 {
890     EXEC SQL BEGIN DECLARE SECTION; 
891     int id1, found = 1;
892     char type[9];
893     EXEC SQL END DECLARE SECTION; 
894
895     EXEC SQL DECLARE csr214 CURSOR FOR
896         SELECT entity_id, type FROM quota
897             WHERE filsys_id = :id;
898     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
899     EXEC SQL OPEN csr214;
900     while(1) {
901         EXEC SQL FETCH csr214 INTO :id1, :type;
902         if (sqlca.sqlcode != 0) {
903           ingerr(&sqlca.sqlcode);
904           break;
905         } 
906         
907         found = 0;
908         printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
909     }
910     EXEC SQL CLOSE csr214;
911     return(found);
912 }
913
914 fix_quota_nofs(id)
915 {
916     single_delete("quota", "filsys_id", id);
917 }
918
919 show_quota_wrongpid(id)
920 EXEC SQL BEGIN DECLARE SECTION; 
921 int id;
922 EXEC SQL END DECLARE SECTION; 
923 {
924     EXEC SQL BEGIN DECLARE SECTION; 
925     int id1, found = 1;
926     char type[9];
927     EXEC SQL END DECLARE SECTION; 
928     struct user *u;
929     struct filesys *f;
930
931     f = (struct filesys *)hash_lookup(filesys, id);
932     EXEC SQL DECLARE csr215 CURSOR FOR
933         SELECT entity_id, type FROM quota
934             WHERE filsys_id = :id;
935     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
936     EXEC SQL OPEN csr215;
937     while(1) {
938         EXEC SQL FETCH csr215 INTO :id1, :type;
939         if (sqlca.sqlcode != 0) {
940           ingerr(&sqlca.sqlcode);
941           break;
942         } 
943
944         found = 0;
945         printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
946                type, id1, f->name, id);
947     }
948     EXEC SQL CLOSE csr215; 
949     return(found);
950 }
951
952 fix_quota_physid(id)
953 EXEC SQL BEGIN DECLARE SECTION; 
954 int id;
955 EXEC SQL END DECLARE SECTION; 
956 {
957     EXEC SQL BEGIN DECLARE SECTION; 
958     int rowcount, id1;
959     EXEC SQL END DECLARE SECTION; 
960
961     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
962     EXEC SQL UPDATE quota SET phys_id = :id1 
963         WHERE filsys_id = :id AND phys_id != :id1;
964     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
965     if (rowcount > 0)
966       printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
967     else
968       printf("Not fixed\n");
969     modified("quota");
970 }
971
972 show_srv_user(id)
973 EXEC SQL BEGIN DECLARE SECTION; 
974 int id;
975 EXEC SQL END DECLARE SECTION; 
976 {
977     EXEC SQL BEGIN DECLARE SECTION; 
978     char name[33];
979     EXEC SQL END DECLARE SECTION; 
980     int found = 1;
981
982     EXEC SQL DECLARE csr216 CURSOR FOR
983         SELECT name FROM servers
984             WHERE acl_type='USER' and acl_id = :id;
985     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
986     EXEC SQL OPEN csr216;
987     while(1) {
988         EXEC SQL FETCH csr216 INTO :name;
989         if (sqlca.sqlcode != 0) {
990           ingerr(&sqlca.sqlcode);
991           break;
992         } 
993         
994         strtrim(name);
995         printf("Service %s has acl non-existant user %d\n", name, id);
996         found = 0;
997     }
998     EXEC SQL CLOSE csr216; 
999     return(found);
1000 }
1001
1002 show_srv_list(id)
1003 EXEC SQL BEGIN DECLARE SECTION; 
1004 int id;
1005 EXEC SQL END DECLARE SECTION; 
1006 {
1007     EXEC SQL BEGIN DECLARE SECTION; 
1008     char name[33];
1009     EXEC SQL END DECLARE SECTION; 
1010     int found = 1;
1011
1012     EXEC SQL DECLARE csr217 CURSOR FOR
1013         SELECT name FROM servers
1014             WHERE acl_type='LIST' AND acl_id = :id;
1015     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1016     EXEC SQL OPEN csr217;
1017     while(1) {
1018         EXEC SQL FETCH csr217 INTO :name;
1019         if (sqlca.sqlcode != 0) {
1020           ingerr(&sqlca.sqlcode);
1021           break;
1022         } 
1023
1024         strtrim(name);
1025         printf("Service %s has acl non-existant list %d\n", name, id);
1026         found = 0;
1027     }
1028     EXEC SQL CLOSE csr217; 
1029     return(found);
1030 }
1031
1032 zero_srv_user(id)
1033 EXEC SQL BEGIN DECLARE SECTION; 
1034 int id;
1035 EXEC SQL END DECLARE SECTION; 
1036 {
1037     EXEC SQL BEGIN DECLARE SECTION; 
1038     int rowcount;
1039     EXEC SQL END DECLARE SECTION; 
1040
1041     EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
1042         acl_type='USER';
1043     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1044     if (rowcount > 0)
1045       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1046     else
1047       printf("Not fixed\n");
1048     modified("servers");
1049 }
1050
1051 zero_srv_list(id)
1052 EXEC SQL BEGIN DECLARE SECTION; 
1053 int id;
1054 EXEC SQL END DECLARE SECTION; 
1055 {
1056     EXEC SQL BEGIN DECLARE SECTION; 
1057     int rowcount;
1058     EXEC SQL END DECLARE SECTION; 
1059
1060     EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
1061         acl_type='LIST';
1062     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1063     if (rowcount > 0)
1064       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1065     else
1066       printf("Not fixed\n");
1067     modified("servers");
1068 }
1069
1070
1071 show_krb_usr(id)
1072 EXEC SQL BEGIN DECLARE SECTION; 
1073 int id;
1074 EXEC SQL END DECLARE SECTION; 
1075 {
1076     EXEC SQL BEGIN DECLARE SECTION; 
1077     int found = 1, id1;
1078     EXEC SQL END DECLARE SECTION; 
1079     struct string *s;
1080     char *ss;
1081
1082     EXEC SQL DECLARE csr218 CURSOR FOR
1083         SELECT string_id FROM krbmap
1084             WHERE users_id = :id ;
1085     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1086     EXEC SQL OPEN csr218;
1087     while(1) {
1088         EXEC SQL FETCH csr218 INTO :id1;
1089         if (sqlca.sqlcode != 0) {
1090           ingerr(&sqlca.sqlcode);
1091           break;
1092         } 
1093
1094         if (s = ((struct string *)hash_lookup(strings, id1)))
1095             ss = s->name;
1096         else
1097             ss = "[unknown]";
1098         found = 0;
1099         printf("Kerberos map for non-existant user %d to principal %s\n",
1100                id, s);
1101     }
1102     EXEC SQL CLOSE csr218; 
1103     return(found);
1104 }
1105
1106
1107 show_krb_str(id)
1108 EXEC SQL BEGIN DECLARE SECTION; 
1109 int id;
1110 EXEC SQL END DECLARE SECTION; 
1111 {
1112     EXEC SQL BEGIN DECLARE SECTION; 
1113     int found = 1, id1;
1114     EXEC SQL END DECLARE SECTION; 
1115     struct user *u;
1116     char *s;
1117
1118     EXEC SQL DECLARE csr219 CURSOR FOR
1119         SELECT users_id FROM krbmap
1120             WHERE string_id = :id;
1121     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1122     EXEC SQL OPEN csr219;
1123     while(1) {
1124         EXEC SQL FETCH csr219 INTO :id1;
1125         if (sqlca.sqlcode != 0) {
1126           ingerr(&sqlca.sqlcode);
1127           break;
1128         } 
1129
1130         if (u = ((struct user *)hash_lookup(users, id1)))
1131             s = u->login;
1132         else
1133             s = "[???]";
1134         found = 0;
1135         printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1136                s, id1, id);
1137         }
1138     EXEC SQL CLOSE csr219; 
1139     return(found);
1140 }
1141
1142
1143 show_pdm_mach(id)
1144 EXEC SQL BEGIN DECLARE SECTION; 
1145 int id;
1146 EXEC SQL END DECLARE SECTION; 
1147 {
1148     EXEC SQL BEGIN DECLARE SECTION; 
1149     char name[33];
1150     EXEC SQL END DECLARE SECTION; 
1151     int found = 1;
1152
1153     EXEC SQL DECLARE csr220 CURSOR FOR
1154         SELECT name FROM palladium
1155             WHERE mach_id = :id;
1156     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1157     EXEC SQL OPEN csr220;
1158     while(1) {
1159         EXEC SQL FETCH csr220 INTO :name;
1160         if (sqlca.sqlcode != 0) {
1161           ingerr(&sqlca.sqlcode);
1162           break;
1163         } 
1164
1165         strtrim(name);
1166         printf("Palladium server/supervisor %s is on non-existant machine %d\n",
1167                name, id);
1168         found = 0;
1169         }
1170     EXEC SQL CLOSE csr220; 
1171     return(found);
1172 }
1173
1174
1175 phase2()
1176 {
1177     EXEC SQL BEGIN DECLARE SECTION; 
1178     int id1, id2, id3, id4, id5;
1179     char type[9], name[33];
1180     EXEC SQL END DECLARE SECTION; 
1181     struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
1182     struct filesys *f;
1183     struct list *l;
1184     struct nfsphys *n;
1185     struct machine *m;
1186
1187     printf("Phase 2 - Checking references\n");
1188
1189     dprintf("Checking users...\n");
1190     hash_step(users, pobox_check, NULL);
1191
1192     dprintf("Checking machines...\n");
1193     hash_step(machines, mach_check, NULL);
1194
1195     dprintf("Checking mcmap...\n");
1196     sq1 = sq_create();
1197     sq2 = sq_create();
1198     EXEC SQL DECLARE csr221 CURSOR FOR
1199         SELECT mach_id, clu_id FROM mcmap;
1200     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1201     EXEC SQL OPEN csr221;
1202     while(1) {
1203         EXEC SQL FETCH csr221 INTO :id1, :id2;
1204         if (sqlca.sqlcode != 0) {
1205           ingerr(&sqlca.sqlcode);
1206           break;
1207         } 
1208
1209         if (!(m = (struct machine *)hash_lookup(machines, id1)))
1210             sq_save_unique_data(sq1, id1);
1211         if (!hash_lookup(clusters, id2))
1212             sq_save_unique_data(sq2, id2);
1213         if (m) m->clucount++;
1214         }
1215     EXEC SQL CLOSE csr221; 
1216     generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1217     generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1218
1219     dprintf("Checking service clusters...\n");
1220     sq1 = sq_create();
1221     EXEC SQL DECLARE csr222 CURSOR FOR
1222         SELECT clu_id FROM svc;
1223     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1224     EXEC SQL OPEN csr222;
1225     while(1) {
1226         EXEC SQL FETCH csr222 INTO :id1;
1227         if (sqlca.sqlcode != 0) {
1228           ingerr(&sqlca.sqlcode);
1229           break;
1230         } 
1231
1232         if (!hash_lookup(clusters, id1))
1233           sq_save_unique_data(sq1, id1);
1234     }
1235     EXEC SQL CLOSE csr222; 
1236     generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1237
1238     dprintf("Checking lists...\n");
1239     hash_step(lists, list_check, NULL);
1240
1241     dprintf("Checking members...\n");
1242     sq1 = sq_create();
1243     sq2 = sq_create();
1244     sq3 = sq_create();
1245     sq4 = sq_create();
1246     sq5 = sq_create();
1247
1248     EXEC SQL DECLARE csr223 CURSOR FOR
1249         SELECT list_id, member_type, member_id, ref_count, direct 
1250         FROM imembers ORDER BY list_id;
1251     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1252     EXEC SQL OPEN csr223;
1253     while(1) {
1254         EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
1255         if (sqlca.sqlcode != 0) {
1256           ingerr(&sqlca.sqlcode);
1257           break;
1258         } 
1259
1260         if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
1261           sq_save_unique_data(sq1, id1);
1262         else if (type[0] == 'U' && !hash_lookup(users, id2))
1263           sq_save_unique_data(sq2, id2);
1264         else if (type[0] == 'L' && !hash_lookup(lists, id2))
1265           sq_save_unique_data(sq3, id2);
1266         else if (type[0] == 'S' && !string_check(id2))
1267           sq_save_unique_data(sq4, id2);
1268         else if (type[0] == 'K' && !string_check(id2))
1269           sq_save_unique_data(sq5, id2);
1270         else
1271           l->members++;
1272         }
1273     EXEC SQL CLOSE csr223; 
1274     generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1275     generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1276     generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1277     generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1278     generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1279
1280     dprintf("Checking servers...\n");
1281     sq1 = sq_create();
1282     sq2 = sq_create();
1283     EXEC SQL DECLARE csr224 CURSOR FOR
1284         SELECT name, acl_type, acl_id FROM servers;
1285     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1286     EXEC SQL OPEN csr224;
1287     while(1) {
1288         EXEC SQL FETCH csr224 INTO :name, :type, :id1;
1289         if (sqlca.sqlcode != 0) {
1290           ingerr(&sqlca.sqlcode);
1291           break;
1292         } 
1293
1294         strtrim(type);
1295         if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
1296             sq_save_data(sq1, id1);
1297         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
1298             sq_save_data(sq2, id1);
1299         }
1300     }
1301     EXEC SQL CLOSE csr224; 
1302     generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
1303     generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
1304
1305     dprintf("Checking serverhosts...\n");
1306     sq = sq_create();
1307     EXEC SQL DECLARE csr225 CURSOR FOR
1308         SELECT mach_id FROM serverhosts;
1309     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1310     EXEC SQL OPEN csr225;
1311     while(1) {
1312         EXEC SQL FETCH csr225 INTO :id1;
1313         if (sqlca.sqlcode != 0) {
1314           ingerr(&sqlca.sqlcode);
1315           break;
1316         } 
1317
1318         if (!hash_lookup(machines, id1))
1319           sq_save_data(sq, id1);
1320         }
1321     EXEC SQL CLOSE csr225; 
1322     generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1323
1324     dprintf("Checking nfsphys...\n");
1325     hash_step(nfsphys, check_nfsphys, NULL);
1326
1327     dprintf("Checking filesys...\n");
1328     hash_step(filesys, check_fs, NULL);
1329
1330     dprintf("Checking filesystem groups...\n");
1331     sq1 = sq_create();
1332     sq2 = sq_create();
1333     sq3 = sq_create();
1334     EXEC SQL DECLARE csr226 CURSOR FOR
1335         SELECT group_id, filsys_id FROM fsgroup;
1336     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1337     EXEC SQL OPEN csr226;
1338     while(1) {
1339         EXEC SQL FETCH csr226 INTO :id1, :id2;
1340         if (sqlca.sqlcode != 0) {
1341           ingerr(&sqlca.sqlcode);
1342           break;
1343         } 
1344
1345         if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
1346           sq_save_data(sq1, id1);
1347         if (!hash_lookup(filesys, id2))
1348           sq_save_data(sq3, id2);
1349     }
1350     EXEC SQL CLOSE csr226; 
1351     generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
1352     generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
1353
1354     dprintf("Checking quotas...\n");
1355     sq1 = sq_create();
1356     sq2 = sq_create();
1357     sq3 = sq_create();
1358     sq4 = sq_create();
1359     EXEC SQL DECLARE csr227 CURSOR FOR
1360         SELECT entity_id, type, filsys_id, phys_id, quota FROM quota;
1361     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1362     EXEC SQL OPEN csr227;
1363     while(1) {
1364         EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4;
1365         if (sqlca.sqlcode != 0) {
1366           ingerr(&sqlca.sqlcode);
1367           break;
1368         } 
1369
1370         if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
1371           sq_save_data(sq1, id1);
1372         else if (type[0] == 'G' && !hash_lookup(lists, id1))
1373           sq_save_data(sq4, id1);
1374         else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
1375           sq_save_data(sq2, id2);
1376         else if (id3 != f->phys_id ||
1377             ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) ==
1378             (struct nfsphys *)NULL))
1379           sq_save_data(sq3, id2);
1380         else
1381           n->count += id4;
1382     }
1383     EXEC SQL CLOSE csr227; 
1384     generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
1385     generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
1386     generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
1387     generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
1388
1389     dprintf("Not checking zephyr.\n");
1390
1391     dprintf("Checking hostaccess...\n");
1392     EXEC SQL DECLARE csr228 CURSOR FOR
1393         SELECT mach_id, acl_type, acl_id FROM hostaccess;
1394     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1395     EXEC SQL OPEN csr228;
1396     while(1) {
1397         EXEC SQL FETCH csr228 INTO :id1, :type, :id2;
1398         if (sqlca.sqlcode != 0) {
1399           ingerr(&sqlca.sqlcode);
1400           break;
1401         } 
1402
1403         strtrim(type);
1404         if (!hash_lookup(machines, id1)) {
1405             printf("Hostaccess for non-existant host %d\n", id1);
1406             printf("Not fixing this error\n");
1407         }
1408         if (!strcmp(type, "USER") && !hash_lookup(users, id2)) {
1409             printf("Hostaccess for %d is non-existant user %d\n", id1, id2);
1410             printf("Not fixing this error\n");
1411         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) {
1412             printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
1413             printf("Not fixing this error\n");
1414         }
1415     }
1416     EXEC SQL CLOSE csr228; 
1417
1418     dprintf("Checking palladium...\n");
1419     sq1 = sq_create();
1420     EXEC SQL DECLARE csr229 CURSOR FOR
1421         SELECT mach_id FROM palladium;
1422     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1423     EXEC SQL OPEN csr229;
1424     while(1) {
1425         EXEC SQL FETCH csr229 INTO :id1;
1426         if (sqlca.sqlcode != 0) {
1427           ingerr(&sqlca.sqlcode);
1428           break;
1429         } 
1430
1431         if (!hash_lookup(machines, id1)) {
1432             sq_save_unique_data(sq1, id1);
1433         }
1434     }
1435     EXEC SQL CLOSE csr229;
1436     generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
1437
1438     dprintf("Checking krbmap...\n");
1439     sq1 = sq_create();
1440     sq2 = sq_create();
1441     EXEC SQL DECLARE csr230 CURSOR FOR
1442         SELECT users_id, string_id FROM krbmap;
1443     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1444     EXEC SQL OPEN csr230;
1445     while(1) {
1446         EXEC SQL FETCH csr230 INTO :id1, :id2;
1447         if (sqlca.sqlcode != 0) {
1448           ingerr(&sqlca.sqlcode);
1449           break;
1450         } 
1451
1452         if (!hash_lookup(users, id1))
1453           sq_save_unique_data(sq1, id1);
1454         if (!string_check(id2))
1455           sq_save_unique_data(sq2, id2);
1456         }
1457     EXEC SQL CLOSE csr230; 
1458     generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
1459     generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
1460
1461     dprintf("Checking capacls...\n");
1462     EXEC SQL DECLARE csr231 CURSOR FOR
1463         SELECT list_id, tag FROM capacls;
1464     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1465     EXEC SQL OPEN csr231;
1466     while(1) {
1467         EXEC SQL FETCH csr231 INTO :id1, :name;
1468         if (sqlca.sqlcode != 0) {
1469           ingerr(&sqlca.sqlcode);
1470           break;
1471         } 
1472
1473         if (!hash_lookup(lists, id1)) {
1474             printf("Capacl for %s is non-existant list %d\n", name, id1);
1475             printf("Not fixing this error\n");
1476         }
1477     }
1478     EXEC SQL CLOSE csr231; 
1479
1480 }
1481
This page took 0.163713 seconds and 5 git commands to generate.