]> andersk Git - moira.git/blob - dbck/phase2.dc
Fixed an Imakefile glitch
[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("Cluster %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
54
55
56       FOR
57         SELECT machine.name FROM machine, mcmap
58             WHERE machine.mach_id=mcmap.mach_id AND mcmap.clu_id=:iid;
59     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
60     EXEC SQL OPEN csr202;
61     while(1) {
62         EXEC SQL FETCH csr202 INTO :name;
63         if (sqlca.sqlcode != 0) {
64           ingerr(&sqlca.sqlcode);
65           break;
66         } 
67
68         strtrim(name);
69
70         found = 0;
71         printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
72     }
73     EXEC SQL CLOSE csr202; 
74     return(found);
75 }
76
77 show_hostalias(id)
78 int id;
79 {
80     EXEC SQL BEGIN DECLARE SECTION; 
81     int iid = id, found = 1;
82     char name[33];
83     EXEC SQL END DECLARE SECTION; 
84
85     EXEC SQL DECLARE csr234 CURSOR FOR
86       SELECT name FROM hostalias WHERE mach_id=:iid;
87     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
88     EXEC SQL OPEN csr234;
89     while(1) {
90         EXEC SQL FETCH csr234 INTO :name;
91         if (sqlca.sqlcode != 0) {
92           ingerr(&sqlca.sqlcode);
93           break;
94         } 
95
96         strtrim(name);
97
98         found = 0;
99         printf("Alias %s, non-existant machine %d in hostalias map\n", name, id);
100     }
101     EXEC SQL CLOSE csr234;
102     return(found);
103 }
104
105 show_pcap_mach(id)
106 int id;
107 {
108     EXEC SQL BEGIN DECLARE SECTION; 
109     int iid = id, found = 1;
110     char name[33];
111     EXEC SQL END DECLARE SECTION; 
112
113     EXEC SQL DECLARE csr235 CURSOR FOR
114       SELECT name FROM printcap WHERE mach_id=:iid;
115     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
116     EXEC SQL OPEN csr235;
117     while(1) {
118         EXEC SQL FETCH csr235 INTO :name;
119         if (sqlca.sqlcode != 0) {
120           ingerr(&sqlca.sqlcode);
121           break;
122         } 
123
124         strtrim(name);
125
126         found = 0;
127         printf("Printer %s, non-existant spool machine %d in printcap table\n", name, id);
128     }
129     EXEC SQL CLOSE csr235;
130     return(found);
131 }
132
133 show_pcap_quota(id)
134 int id;
135 {
136     EXEC SQL BEGIN DECLARE SECTION; 
137     int iid = id, found = 1;
138     char name[33];
139     EXEC SQL END DECLARE SECTION; 
140
141     EXEC SQL DECLARE csr236 CURSOR FOR
142       SELECT name FROM printcap WHERE quotaserver=:iid;
143     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
144     EXEC SQL OPEN csr236;
145     while(1) {
146         EXEC SQL FETCH csr236 INTO :name;
147         if (sqlca.sqlcode != 0) {
148           ingerr(&sqlca.sqlcode);
149           break;
150         } 
151
152         strtrim(name);
153
154         found = 0;
155         printf("Printer %s, non-existant quota server %d in printcap table\n", name, id);
156     }
157     EXEC SQL CLOSE csr236;
158     return(found);
159 }
160
161 user_check(id, u, hint)
162      int id;
163      struct user *u;
164      int hint;
165 {
166   u->comment=maybe_fixup_unref_string(u->comment, id, u->login, "users",
167                                       "comment", "users_id");
168
169   u->modby=maybe_fixup_modby(u->modby, id, u->login, "users",
170                              "modby", "users_id");
171
172   u->fmodby=maybe_fixup_modby(u->fmodby, id, u->login, "users",
173                               "fmodby", "users_id");
174
175   u->pmodby=maybe_fixup_modby(u->pmodby, id, u->login, "users",
176                               "pmodby", "users_id");
177
178   u->sigwho=maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
179                                      "sigwho", "users_id");
180   
181   pobox_check(id, u, hint);
182 }
183
184 maybe_fixup_unref_string(sid, oid, oname, table, field, idfield)
185      int sid, oid;
186      char *oname, *table;
187      char *field, *idfield;
188 {
189   int ret=(sid<0)?-sid:sid, doit=0, newid;
190   EXEC SQL BEGIN DECLARE SECTION;
191   int rowcount;
192   char stmt_buf[500];
193   EXEC SQL END DECLARE SECTION;
194   
195   if(newid=int_hash_lookup(string_dups, ret)) {
196     printf("%s entry %s(%d) has a %s with duplicate string %d\n",
197            table, oname, oid, field, ret);
198     if(single_fix("Replace duplicate", 0)){
199       ret = newid;
200       string_check(newid);
201       doit=1;
202     }
203   } else if(!string_check(ret)) {
204     printf("%s entry %s(%d) has a %s with non-existant string %d\n",
205            table, oname, oid, field, ret);
206     if (single_fix("Delete", 1)) {
207       ret=0;
208       doit=1;
209     }
210   }
211
212   if(doit){
213     sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d",
214             table, field, (sid<0)?-ret:ret, idfield, oid);
215     EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
216     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
217     if (rowcount == 1)
218       printf("Fixed\n");
219     else
220       printf("Not fixed, rowcount = %d\n", rowcount);
221     modified(table);
222   }
223
224   return((sid<0)?-ret:ret);
225
226 }
227
228 maybe_fixup_modby(sid, oid, oname, table, field, idfield)
229      int sid, oid;
230      char *oname, *table;
231      char *field, *idfield;
232 {
233   EXEC SQL BEGIN DECLARE SECTION;
234   char stmt_buf[500];
235   int rowcount;
236   EXEC SQL END DECLARE SECTION;
237
238   if(sid<0)
239     return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
240   else {
241     if(!hash_lookup(users, sid)) {
242       printf("%s entry %s(%d) has a %s with non-existant user %d\n",
243              table, oname, oid, field, sid);
244       if (single_fix("Delete", 1)) {
245         sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s=%d",
246                 table, field, 0, idfield, oid);
247         EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
248         EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
249         if (rowcount == 1)
250           printf("Fixed\n");
251         else
252           printf("Not fixed, rowcount = %d\n", rowcount);
253         modified(table);
254       }
255       return 0;
256     }
257   }
258   return sid;
259 }
260
261 maybe_fixup_unref_string2(table, field, cursor, sid)
262      int sid;
263      char *field, *table, *cursor;
264 {
265   int ret=(sid<0)?-sid:sid, doit=0, newid;
266   EXEC SQL BEGIN DECLARE SECTION;
267   int rowcount;
268   char stmt_buf[500];
269   EXEC SQL END DECLARE SECTION;
270   
271   if(newid=int_hash_lookup(string_dups, ret)) {
272     printf("%s entry has a %s with duplicate string %d\n",
273            table, field, ret);
274     if(single_fix("Replace duplicate", 0)){
275       ret = newid;
276       string_check(newid);
277       doit=1;
278     }
279   } else if(!string_check(ret)) {
280     printf("%s entry has a %s with non-existant string %d\n",
281            table, field, ret);
282     if (single_fix("Delete", 1)) {
283       ret=0;
284       doit=1;
285     }
286   }
287
288   if(doit){
289     sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s",
290             table, field, (sid<0)?-ret:ret, cursor);
291     EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
292     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
293     if (rowcount == 1)
294       printf("Fixed\n");
295     else
296       printf("Not fixed, rowcount = %d\n", rowcount);
297     modified(table);
298   }
299   return((sid<0)?-ret:ret);
300 }
301
302 maybe_fixup_modby2(table, field, cursor, id)
303 {
304   EXEC SQL BEGIN DECLARE SECTION;
305   char stmt_buf[500];
306   int rowcount;
307   EXEC SQL END DECLARE SECTION;
308
309   if(id<0) return maybe_fixup_unref_string2(table, field, cursor, id);
310   else {
311     if(!hash_lookup(users, id)) {
312       printf("%s entry has a %s with non-existant user %d\n",
313              table, field, id);
314       if (single_fix("Delete", 1)) {
315         sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s",
316                 table, field, 0, cursor);
317         EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
318         EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
319         if (rowcount == 1)
320           printf("Fixed\n");
321         else
322           printf("Not fixed, rowcount = %d\n", rowcount);
323         modified(table);
324       }
325       return 0;
326     }
327   }
328   return 1;
329 }
330
331 pobox_check(id, u, hint)
332 int id;
333 struct user *u;
334 int hint;
335 {
336   switch (u->potype) {
337   case 'P':
338     if (!hash_lookup(machines, u->pobox_id)) {
339       printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
340              u->login, u->fullname, u->pobox_id);
341       if (single_fix("Delete", 0)) {
342         remove_pobox(u->users_id);
343         u->potype = 'N';
344       }
345     }
346     break;
347   case 'S':
348     if( int_hash_lookup( string_dups, u->pobox_id ) ) {
349       printf("User %s(%s) has P.O.Box with duplicate string %d\n",
350              u->login, u->fullname, u->pobox_id);
351       if(single_fix("Update", 0)){
352         printf("Replacing box_id dup string ID %d with %d\n",
353                u->pobox_id,
354                int_hash_lookup(string_dups, u->pobox_id));
355         u->pobox_id = int_hash_lookup( string_dups, u->pobox_id );
356         fix_smtp_pobox(u->users_id, u->pobox_id);
357         string_check(u->pobox_id);
358       }
359     } else if (!string_check(u->pobox_id)) {
360       printf("User %s(%s) has P.O.Box with non-existant string %d\n",
361              u->login, u->fullname, u->pobox_id);
362       if (single_fix("Delete", 0)) {
363         remove_pobox(u->users_id);
364         u->potype = 'N';
365       }
366     }
367     break;
368   default:
369     ;
370   }
371 }
372
373
374 remove_pobox(id)
375 int id;
376 {
377     EXEC SQL BEGIN DECLARE SECTION; 
378     int rowcount, iid = id;
379     EXEC SQL END DECLARE SECTION; 
380
381     EXEC SQL UPDATE users SET potype='NONE' WHERE users.users_id = :iid;
382     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
383     if (rowcount > 0)
384       printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies");
385     else
386       printf("Not removed\n");
387     modified("users");
388 }
389
390 fix_smtp_pobox(id, sid)
391 int id, sid;
392 {
393     EXEC SQL BEGIN DECLARE SECTION; 
394     int rowcount, iid = id, isid=sid;
395     EXEC SQL END DECLARE SECTION; 
396
397     EXEC SQL UPDATE users SET box_id=:isid WHERE users.users_id = :iid;
398     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
399     if (rowcount > 0)
400       printf("%d entr%s updated\n", rowcount, rowcount==1?"y":"ies");
401     else
402       printf("Not updated\n");
403     modified("users");
404 }
405
406 mach_check(id, m, hint)
407 int id;
408 struct machine *m;
409 int hint;
410 {
411     if (!hash_lookup(subnets, m->snet_id)) {
412         printf("Machine %s is on a non-existant subnet %d\n",
413                m->name, m->snet_id);
414         if (single_fix("Move to null-subnet", 1)) {
415             EXEC SQL BEGIN DECLARE SECTION; 
416             int rowcount, iid = id;
417             EXEC SQL END DECLARE SECTION; 
418
419             EXEC SQL UPDATE machine SET snet_id=0 WHERE mach_id = :iid;
420             EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
421             if (rowcount > 0)
422               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
423             else
424               printf("Not fixed\n");
425             modified("machine");
426         }
427     }
428
429     switch (m->owner_type) {
430     case 'U':
431         if (!hash_lookup(users, m->owner_id)) {
432             printf("Machine %s has non-existant USER owner %d\n",
433                    m->name, m->owner_id);
434             if (single_fix("Set to no owner", 1)) {
435                 clear_mach_owner(m);
436             }
437         }
438         break;
439     case 'L':
440         if (!hash_lookup(lists, m->owner_id)) {
441             printf("Machine %s has non-existant LIST owner %d\n",
442                    m->name, m->owner_id);
443             if (single_fix("Set to no owner", 1)) {
444                 clear_mach_owner(m);
445             }
446         }
447         break;
448     case 'S':
449     case 'K':
450       if(m->owner_id)
451         m->owner_id=maybe_fixup_unref_string(m->owner_id, id, m->name,
452                                              "machine", "owner_id", "mach_id");
453       if(m->owner_id==0)
454         clear_mach_owner(m);
455     }
456
457     if(m->acomment)
458       m->acomment=maybe_fixup_unref_string(m->acomment, id, m->name,
459                                            "machine", "acomment", "mach_id");
460     if(m->ocomment)
461       m->ocomment=maybe_fixup_unref_string(m->ocomment, id, m->name,
462                                            "machine", "ocomment", "mach_id");
463     
464     m->creator=maybe_fixup_modby(m->creator, id, m->name, "machine",
465                                  "creator", "mach_id");
466     m->modby=maybe_fixup_modby(m->modby, id, m->name, "machine",
467                                "modby", "mach_id");
468 }
469
470 subnet_check(id, s, hint)
471 int id;
472 struct subnet *s;
473 int hint;
474 {
475     switch (s->owner_type) {
476     case 'U':
477         if (!hash_lookup(users, s->owner_id)) {
478             printf("Subnet %s has non-existant USER owner %d\n",
479                    s->name, s->owner_id);
480             if (single_fix("Set to no owner", 1)) {
481                 clear_subnet_owner(s);
482             }
483         }
484         break;
485     case 'L':
486         if (!hash_lookup(lists, s->owner_id)) {
487             printf("Machine %s has non-existant LIST owner %d\n",
488                    s->name, s->owner_id);
489             if (single_fix("Set to no owner", 1)) {
490                 clear_subnet_owner(s);
491             }
492         }
493         break;
494     case 'S':
495     case 'K':
496       if(s->owner_id)
497         s->owner_id=maybe_fixup_unref_string(s->owner_id, id, s->name,
498                                              "machine", "owner_id", "mach_id");
499       if(s->owner_id==0)
500         clear_subnet_owner(s);
501     }
502
503     s->modby=maybe_fixup_modby(s->modby, id, s->name, "subnet",
504                                "modby", "snet_id");
505 }
506
507
508 clear_subnet_owner(s)
509 struct subnet *s;
510 {
511     EXEC SQL BEGIN DECLARE SECTION; 
512     int rowcount, id = s->snet_id;
513     EXEC SQL END DECLARE SECTION; 
514
515     EXEC SQL UPDATE subnet SET owner_type='NONE', owner_id=0
516       WHERE snet_id = :id;
517     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
518     if (rowcount > 0)
519       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
520     else
521       printf("Not fixed\n");
522     modified("subnet");
523 }
524
525 clear_mach_owner(m)
526 struct machine *m;
527 {
528     EXEC SQL BEGIN DECLARE SECTION; 
529     int rowcount, id = m->mach_id;
530     EXEC SQL END DECLARE SECTION; 
531
532     EXEC SQL UPDATE machine SET owner_type='NONE', owner_id=0
533       WHERE mach_id = :id;
534     EXEC SQL INQUIRE_SQL(:rowcount = rowcount);
535     if (rowcount > 0)
536       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
537     else
538       printf("Not fixed\n");
539     modified("machine");
540 }
541
542 cluster_check(id, c, hint)
543 int id;
544 struct cluster *c;
545 int hint;
546 {
547     c->modby=maybe_fixup_modby(c->modby, id, c->name, "cluster",
548                                "modby", "clu_id");
549 }
550
551
552
553 show_svc(id)
554 int id;
555 {
556     EXEC SQL BEGIN DECLARE SECTION; 
557     int iid = id, found = 1;
558     char label[17], data[33];
559     EXEC SQL END DECLARE SECTION; 
560
561     EXEC SQL DECLARE csr203 CURSOR FOR
562         SELECT serv_label, serv_cluster FROM svc
563             WHERE clu_id = :iid;
564     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
565     EXEC SQL OPEN csr203;
566     while(1) {
567         EXEC SQL FETCH csr203 INTO :label, :data;
568         if (sqlca.sqlcode != 0) {
569           ingerr(&sqlca.sqlcode);
570           break;
571         }
572
573         strtrim(label);
574         strtrim(data);
575         found = 0;
576         printf("Cluster data [%s] %s for non-existant cluster %d\n",
577                label, data, id);
578     }
579     EXEC SQL CLOSE csr203; 
580     return(found);
581 }
582
583 list_check(id, l, hint)
584 int id;
585 struct list *l;
586 int hint;
587 {
588     switch (l->acl_type) {
589     case 'L':
590         if (!hash_lookup(lists, l->acl_id)) {
591             printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
592             if (single_fix("Patch", 1)) {
593                 fix_list_acl(l->list_id);
594             }
595         }
596         break;
597     case 'U':
598         if (!hash_lookup(users, l->acl_id)) {
599             printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
600             if (single_fix("Patch", 1)) {
601                 fix_list_acl(l->list_id);
602             }
603         }
604         break;
605     case 'K':
606         l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
607                                              "list", "acl_id", "list_id");
608         if (!l->acl_id) {
609             printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id);
610             if(single_fix("Patch", 1)) {
611                 fix_list_acl(l->list_id);
612             }
613         }
614         break;
615     }
616 }
617
618 fix_list_acl(id)
619 int id;
620 {
621     EXEC SQL BEGIN DECLARE SECTION; 
622     int rowcount, iid = id;
623     EXEC SQL END DECLARE SECTION; 
624
625     EXEC SQL UPDATE list SET acl_id = :iid, acl_type='LIST'
626         WHERE list_id = :iid;
627     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
628     if (rowcount > 0)
629       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
630     else
631       printf("Not fixed\n");
632     modified("list");
633 }
634
635
636 show_member_list(id)
637 int id;
638 {
639     EXEC SQL BEGIN DECLARE SECTION; 
640     int mid, iid = id, found = 1;
641     char mtype[9], *name = "";
642     EXEC SQL END DECLARE SECTION;
643
644     EXEC SQL DECLARE csr204 CURSOR FOR
645         SELECT member_type, member_id FROM imembers
646             WHERE list_id = :iid AND direct=1;
647     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
648     EXEC SQL OPEN csr204;
649     while(1) {
650         EXEC SQL FETCH csr204 INTO :mtype, :mid;
651         if (sqlca.sqlcode != 0) {
652           ingerr(&sqlca.sqlcode);
653           break;
654         } 
655
656         strtrim(mtype);
657         found = 0;
658         if (mtype[0] == 'L')
659             name = ((struct list *) hash_lookup(lists, mid))->name;
660         else if (mtype[0] == 'U')
661             name = ((struct user *) hash_lookup(users, mid))->login;
662         else if (mtype[0] == 'S' || mtype[0] == 'K')
663             name = ((struct string *) hash_lookup(strings, mid))->name;
664         printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
665     }
666     EXEC SQL CLOSE csr204; 
667     return(found);
668 }
669
670 show_mem_user(id)
671 int id;
672 {
673     EXEC SQL BEGIN DECLARE SECTION; 
674     int lid, iid = id, found = 1;
675     char name[33];
676     EXEC SQL END DECLARE SECTION; 
677
678     EXEC SQL DECLARE csr205 CURSOR FOR
679       SELECT list_id FROM imembers
680         WHERE member_id = :iid AND member_type='USER' AND direct=1;
681     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
682     EXEC SQL OPEN csr205;
683     while(1) {
684         EXEC SQL FETCH csr205 INTO :lid;
685         if (sqlca.sqlcode != 0) {
686           ingerr(&sqlca.sqlcode);
687           break;
688         }       
689         
690         found = 0;
691         printf("List %s has non-existant user member, id %d\n",
692                ((struct list *)hash_lookup(lists, lid))->name, iid);
693     }
694     EXEC SQL CLOSE csr205;
695     return(found);
696 }
697
698 show_mem_list(id)
699 int id;
700 {
701     EXEC SQL BEGIN DECLARE SECTION; 
702     int lid, iid = id, found = 1;
703     char name[33];
704     EXEC SQL END DECLARE SECTION; 
705
706     EXEC SQL DECLARE csr206 CURSOR FOR
707         SELECT list_id FROM imembers
708             WHERE member_id = :iid AND member_type='LIST' AND direct=1;
709     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
710     EXEC SQL OPEN csr206;
711     while(1) {
712         EXEC SQL FETCH csr206 INTO :lid;
713         if (sqlca.sqlcode != 0) {
714           ingerr(&sqlca.sqlcode);
715           break;
716         } 
717
718         found = 0;
719         printf("List %s has non-existant list member, id %d\n",
720                ((struct list *)hash_lookup(lists, lid))->name, iid);
721     }
722     EXEC SQL CLOSE csr206; 
723     return(found);
724 }
725
726 show_mem_str(id)
727 int id;
728 {
729     EXEC SQL BEGIN DECLARE SECTION; 
730     int lid, iid = id, found = 1;
731     char name[33];
732     EXEC SQL END DECLARE SECTION; 
733
734     EXEC SQL DECLARE csr207 CURSOR FOR
735         SELECT list_id FROM imembers
736             WHERE member_id = :iid AND member_type='STRING' AND direct=1;
737     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
738     EXEC SQL OPEN csr207;
739     while(1) {
740         EXEC SQL FETCH csr207 INTO :lid;
741         if (sqlca.sqlcode != 0) {
742           ingerr(&sqlca.sqlcode);
743           break;
744         } 
745         
746         found = 0;
747         printf("List %s has non-existant string member, id %d\n",
748                ((struct list *)hash_lookup(lists, lid))->name, iid);
749     }
750     EXEC SQL CLOSE csr207; 
751     return(found);
752 }
753
754
755 show_mem_krb(id)
756 int id;
757 {
758     EXEC SQL BEGIN DECLARE SECTION; 
759     int lid, iid = id, found = 1;
760     char name[33];
761     EXEC SQL END DECLARE SECTION; 
762
763     EXEC SQL DECLARE csr208 CURSOR FOR
764         SELECT list_id FROM imembers
765             WHERE member_id = :iid AND member_type='KERBEROS' AND direct=1;
766     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
767     EXEC SQL OPEN csr208;
768     while(1) {
769         EXEC SQL FETCH csr208 INTO :lid;
770         if (sqlca.sqlcode != 0) {
771           ingerr(&sqlca.sqlcode);
772           break;
773         } 
774
775         found = 0;
776         printf("List %s has non-existant kerberos member, id %d\n",
777                ((struct list *)hash_lookup(lists, lid))->name, iid);
778     }
779     EXEC SQL CLOSE csr208; 
780     return(found);
781 }
782
783
784 del_mem_user(id)
785 EXEC SQL BEGIN DECLARE SECTION; 
786 int id;
787 EXEC SQL END DECLARE SECTION; 
788 {
789     EXEC SQL BEGIN DECLARE SECTION; 
790     int rowcount;
791     EXEC SQL END DECLARE SECTION; 
792
793     EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND
794         member_id = :id AND direct = 1;
795     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
796     if (rowcount > 0)
797       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
798     else
799       printf("Not deleted\n");
800     modified("imembers");
801 }
802
803 del_mem_list(id)
804 EXEC SQL BEGIN DECLARE SECTION; 
805 int id;
806 EXEC SQL END DECLARE SECTION; 
807 {
808     EXEC SQL BEGIN DECLARE SECTION; 
809     int rowcount;
810     EXEC SQL END DECLARE SECTION; 
811
812     EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND
813         member_id = :id AND direct=1;
814     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
815     if (rowcount > 0)
816       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
817     else
818       printf("Not deleted\n");
819     modified("imembers");
820 }
821
822 del_mem_str(id)
823 EXEC SQL BEGIN DECLARE SECTION; 
824 int id;
825 EXEC SQL END DECLARE SECTION; 
826 {
827     EXEC SQL BEGIN DECLARE SECTION; 
828     int rowcount;
829     EXEC SQL END DECLARE SECTION; 
830
831     EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND
832         member_id = :id AND direct=1;
833     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
834     if (rowcount > 0)
835       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
836     else
837       printf("Not deleted\n");
838     modified("imembers");
839 }
840
841
842 del_mem_krb(id)
843 EXEC SQL BEGIN DECLARE SECTION; 
844 int id;
845 EXEC SQL END DECLARE SECTION; 
846 {
847     EXEC SQL BEGIN DECLARE SECTION; 
848     int rowcount;
849     EXEC SQL END DECLARE SECTION; 
850
851     EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND
852         member_id = :id AND direct=1;
853     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
854     if (rowcount > 0)
855       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
856     else
857       printf("Not deleted\n");
858     modified("imembers");
859 }
860
861
862 show_sh(id)
863 EXEC SQL BEGIN DECLARE SECTION; 
864 int id;
865 EXEC SQL END DECLARE SECTION; 
866 {
867     EXEC SQL BEGIN DECLARE SECTION; 
868     char name[33];
869     EXEC SQL END DECLARE SECTION; 
870     int found = 1;
871
872     EXEC SQL DECLARE csr209 CURSOR FOR
873         SELECT service FROM serverhosts
874             WHERE mach_id = :id;
875     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
876     EXEC SQL OPEN csr209;
877     while(1) {
878         EXEC SQL FETCH csr209 INTO :name;
879         if (sqlca.sqlcode != 0) {
880           ingerr(&sqlca.sqlcode);
881           break;
882         } 
883
884         found = 0;
885         printf("ServerHost entry for service %s non-existant host %d\n",
886                name, id);
887     }
888     EXEC SQL CLOSE csr209; 
889     return(found);
890 }
891
892 del_sh_mach(id)
893 EXEC SQL BEGIN DECLARE SECTION; 
894 int id;
895 EXEC SQL END DECLARE SECTION; 
896 {
897     EXEC SQL BEGIN DECLARE SECTION; 
898     int rowcount;
899     EXEC SQL END DECLARE SECTION; 
900
901     EXEC SQL DELETE FROM serverhosts WHERE mach_id = :id;
902     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
903     if (rowcount > 0)
904       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
905     else
906       printf("Not deleted\n");
907     modified("serverhosts");
908 }
909
910
911 static int fnchecklen;
912
913 fsmatch(id, n, f)
914 int id;
915 struct nfsphys *n;
916 struct filesys *f;
917 {
918     if (n->mach_id == f->mach_id &&
919         !strncmp(f->dir, n->dir, strlen(n->dir)) &&
920         strlen(n->dir) > fnchecklen) {
921         f->phys_id = id;
922         fnchecklen = strlen(n->dir);
923     }
924 }
925
926
927 check_fs(id, f, hint)
928 EXEC SQL BEGIN DECLARE SECTION; 
929 int id;
930 EXEC SQL END DECLARE SECTION; 
931 register struct filesys *f;
932 int hint;
933 {
934     EXEC SQL BEGIN DECLARE SECTION; 
935     int id1, id2, id3, rowcount;
936     char *dir;
937     EXEC SQL END DECLARE SECTION; 
938     struct nfsphys *n;
939     struct machine *m;
940
941     if (!hash_lookup(machines, f->mach_id)) {
942         printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
943         if (single_fix("Fix", 0)) {
944             EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :id;
945             EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
946             if (rowcount > 0)
947               printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
948             else
949               printf("Not fixed\n");
950             modified("filesys");
951             f->mach_id = 0;
952         }
953     }
954
955     if (!hash_lookup(users, f->owner)) {
956         printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
957         if (single_fix("Fix", 1)) {
958             zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
959             f->owner = 0;
960         }
961     }
962     if (!hash_lookup(lists, f->owners)) {
963         printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
964         if (single_fix("Fix", 1)) {
965             zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
966             f->owners = 0;
967         }
968     }
969
970     if (f->type == 'N') {
971         if (!hash_lookup(nfsphys, f->phys_id)) {
972             m = (struct machine *)hash_lookup(machines, f->mach_id);
973             printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
974             if (single_fix("Fix", 1)) {
975                 fnchecklen = 0;
976                 hash_step(nfsphys, fsmatch, f);
977                 if (fnchecklen != 0) {
978                   id1 = f->phys_id;
979                   id2 = f->filsys_id;
980                   id3 = f->mach_id;
981                   EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2;
982                   EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
983                   if (rowcount > 0)
984                     printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
985                   else
986                     printf("Not fixed\n");
987                   modified("filesys");
988                 } else {
989                     printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
990                     if (single_fix("Create", 0)) {
991                         dir = f->dir;
992                         id1 = f->phys_id;
993                         id2 = f->filsys_id;
994                         id3 = f->mach_id;
995                         if (set_next_object_id("nfsphys_id", "nfsphys") !=
996                                 MR_SUCCESS) {
997                             printf("Unable to assign unique ID\n");
998                             return;
999                         }
1000                         EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues 
1001                             WHERE name='nfsphys_id';
1002                         if (rowcount != 1) {
1003                             printf("Unable to retrieve unique ID\n");
1004                             return;
1005                         }
1006                         EXEC SQL INSERT INTO mfsphys (mfsphys_id, mach_id,
1007                             device, dir, status, allocated, size, modtime,
1008                             modby, modwith) VALUES (:id1, :id3, '???', :dir,
1009                             0, 0, 0, 'now', 0, 'dbck');
1010                         EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1011                         if (rowcount > 0)
1012                           printf("%d entr%s created\n", rowcount,
1013                                  rowcount==1?"y":"ies");
1014                         else
1015                           printf("Not created\n");
1016                         modified("nfsphys");
1017                         n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
1018                         if (n == NULL)
1019                           out_of_mem("storing new nfsphys");
1020                         strcpy(n->dir, dir);
1021                         n->mach_id = id3;
1022                         n->nfsphys_id = id1;
1023                         n->allocated = 0;
1024                         n->count = 0;
1025                         if( hash_store(nfsphys, id1, n) == -1 ) {
1026                           out_of_mem("storing nfsphys in hash table");
1027                         }
1028                         EXEC SQL UPDATE filesys SET phys_id = :id1
1029                             WHERE filsys_id = :id2;
1030                         EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1031                         if (rowcount > 0)
1032                           printf("%d filesys entr%s fixed\n", rowcount,
1033                                  rowcount==1?"y":"ies");
1034                         else
1035                           printf("Not fixed\n");
1036                         modified("filesys");
1037                     }
1038                 }
1039             }
1040         }
1041     }
1042 }
1043
1044
1045 check_nfsphys(id, n, hint)
1046 int id;
1047 struct nfsphys *n;
1048 int hint;
1049 {
1050     if (!hash_lookup(machines, n->mach_id)) {
1051         printf("NFSphys %d(%s) on non-existant machine %d\n",
1052                id, n->dir, n->mach_id);
1053         if (single_fix("Delete", 0))
1054           single_delete("nfsphys", "nfsphys_id", id);
1055     }
1056 }
1057
1058 show_fsg_missing(id)
1059 EXEC SQL BEGIN DECLARE SECTION; 
1060 int id;
1061 EXEC SQL END DECLARE SECTION; 
1062 {
1063     EXEC SQL BEGIN DECLARE SECTION; 
1064     int id1, found = 1;
1065     EXEC SQL END DECLARE SECTION; 
1066     struct filesys *f;
1067
1068     EXEC SQL DECLARE csr210 CURSOR FOR
1069         SELECT filsys_id FROM fsgroup
1070             WHERE group_id = :id;
1071     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1072     EXEC SQL OPEN csr210;
1073     while(1) {
1074         EXEC SQL FETCH csr210 INTO :id1;
1075         if (sqlca.sqlcode != 0) {
1076           ingerr(&sqlca.sqlcode);
1077           break;
1078         } 
1079
1080         found = 0;
1081         if (f = (struct filesys *) hash_lookup(filesys, id1))
1082             printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
1083         else
1084             printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
1085     }
1086     EXEC SQL CLOSE csr210; 
1087     return(found);
1088 }
1089
1090 show_fsg_type(f)
1091 struct filesys *f;
1092 {
1093     char *t;
1094
1095     switch (f->type) {
1096     case 'N':
1097         t = "NFS";
1098         break;
1099     case 'R':
1100         t = "RVD";
1101         break;
1102     case 'A':
1103         t = "AFS";
1104         break;
1105     case 'E':
1106         t = "ERR";
1107         break;
1108     case 'F':
1109         t = "FSGROUP";
1110         break;
1111     case 'M':
1112         t = "MUL";
1113         break;
1114     default:
1115         t = "???";
1116     }
1117     printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1118     return(0);
1119 }
1120
1121 fix_fsg_type(f)
1122 struct filesys *f;
1123 {
1124     EXEC SQL BEGIN DECLARE SECTION; 
1125     int rowcount, id = f->filsys_id;
1126     EXEC SQL END DECLARE SECTION; 
1127
1128     EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id;
1129     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1130     if (rowcount > 0)
1131       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1132     else
1133       printf("Not fixed\n");
1134     modified("filesys");
1135 }
1136
1137 show_fsg_nomember(id)
1138 EXEC SQL BEGIN DECLARE SECTION; 
1139 int id;
1140 EXEC SQL END DECLARE SECTION; 
1141 {
1142     EXEC SQL BEGIN DECLARE SECTION; 
1143     int id1, found = 1;
1144     EXEC SQL END DECLARE SECTION; 
1145     struct filesys *f;
1146
1147     EXEC SQL DECLARE csr211 CURSOR FOR
1148         SELECT group_id FROM fsgroup
1149             WHERE filsys_id = :id;
1150     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1151     EXEC SQL OPEN csr211;
1152     while(1) {
1153         EXEC SQL FETCH csr211 INTO :id1;
1154         if (sqlca.sqlcode != 0) {
1155           ingerr(&sqlca.sqlcode);
1156           break;
1157         } 
1158
1159         found = 0;
1160         if (f = (struct filesys *) hash_lookup(filesys, id1))
1161             printf("FSGroup %s has missing member %d\n", f->name, id);
1162         else
1163             printf("FSGroup %d has missing member %d\n", id1, id);
1164     }
1165     EXEC SQL CLOSE csr211; 
1166     return(found);
1167 }
1168
1169 show_quota_nouser(id)
1170 EXEC SQL BEGIN DECLARE SECTION; 
1171 int id;
1172 EXEC SQL END DECLARE SECTION; 
1173 {
1174     EXEC SQL BEGIN DECLARE SECTION; 
1175     int id1, found = 1;
1176     EXEC SQL END DECLARE SECTION; 
1177
1178     EXEC SQL DECLARE csr212 CURSOR FOR
1179         SELECT filsys_id FROM quota
1180             WHERE entity_id = :id AND type='USER';
1181     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1182     EXEC SQL OPEN csr212;
1183     while(1) {
1184         EXEC SQL FETCH csr212 INTO :id1;
1185         if (sqlca.sqlcode != 0) {
1186           ingerr(&sqlca.sqlcode);
1187           break;
1188         } 
1189
1190         found = 0;
1191         printf("Quota on fs %d for non-existant user %d\n", id1, id);
1192     }
1193     EXEC SQL CLOSE csr212; 
1194     return(found);
1195 }
1196
1197 show_quota_nolist(id)
1198 EXEC SQL BEGIN DECLARE SECTION; 
1199 int id;
1200 EXEC SQL END DECLARE SECTION; 
1201 {
1202     EXEC SQL BEGIN DECLARE SECTION; 
1203     int id1, found = 1;
1204     EXEC SQL END DECLARE SECTION; 
1205
1206     EXEC SQL DECLARE csr213 CURSOR FOR
1207         SELECT filsys_id FROM quota 
1208             WHERE entity_id = :id AND type='GROUP';
1209     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1210     EXEC SQL OPEN csr213;
1211     while(1) {
1212         EXEC SQL FETCH csr213 INTO :id1;
1213         if (sqlca.sqlcode != 0) {
1214           ingerr(&sqlca.sqlcode);
1215           break;
1216         }
1217  
1218         found = 0;
1219         printf("Quota on fs %d for non-existant list %d\n", id1, id);
1220     }
1221     EXEC SQL CLOSE csr213; 
1222     return(found);
1223 }
1224
1225 fix_quota_nouser(id)
1226 EXEC SQL BEGIN DECLARE SECTION; 
1227 int id;
1228 EXEC SQL END DECLARE SECTION; 
1229 {
1230     EXEC SQL BEGIN DECLARE SECTION; 
1231     int rowcount, id1;
1232     EXEC SQL END DECLARE SECTION; 
1233
1234     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1235     EXEC SQL DELETE FROM quota 
1236         WHERE entity_id = :id AND type = 'USER';
1237     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1238     if (rowcount > 0)
1239       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1240     else
1241       printf("Not deleted\n");
1242     modified("quota");
1243 }
1244
1245 fix_quota_nolist(id)
1246 EXEC SQL BEGIN DECLARE SECTION; 
1247 int id;
1248 EXEC SQL END DECLARE SECTION; 
1249 {
1250     EXEC SQL BEGIN DECLARE SECTION; 
1251     int rowcount, id1;
1252     EXEC SQL END DECLARE SECTION; 
1253
1254     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1255     EXEC SQL DELETE FROM quota WHERE entity_id = :id AND type='GROUP';
1256     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1257     if (rowcount > 0)
1258       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1259     else
1260       printf("Not deleted\n");
1261     modified("quota");
1262 }
1263
1264 show_quota_nofs(id)
1265 EXEC SQL BEGIN DECLARE SECTION; 
1266 int id;
1267 EXEC SQL END DECLARE SECTION; 
1268 {
1269     EXEC SQL BEGIN DECLARE SECTION; 
1270     int id1, found = 1;
1271     char type[9];
1272     EXEC SQL END DECLARE SECTION; 
1273
1274     EXEC SQL DECLARE csr214 CURSOR FOR
1275         SELECT entity_id, type FROM quota
1276             WHERE filsys_id = :id;
1277     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1278     EXEC SQL OPEN csr214;
1279     while(1) {
1280         EXEC SQL FETCH csr214 INTO :id1, :type;
1281         if (sqlca.sqlcode != 0) {
1282           ingerr(&sqlca.sqlcode);
1283           break;
1284         } 
1285         
1286         found = 0;
1287         printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
1288     }
1289     EXEC SQL CLOSE csr214;
1290     return(found);
1291 }
1292
1293 fix_quota_nofs(id)
1294 {
1295     single_delete("quota", "filsys_id", id);
1296 }
1297
1298 show_quota_wrongpid(id)
1299 EXEC SQL BEGIN DECLARE SECTION; 
1300 int id;
1301 EXEC SQL END DECLARE SECTION; 
1302 {
1303     EXEC SQL BEGIN DECLARE SECTION; 
1304     int id1, found = 1;
1305     char type[9];
1306     EXEC SQL END DECLARE SECTION; 
1307     struct user *u;
1308     struct filesys *f;
1309
1310     f = (struct filesys *)hash_lookup(filesys, id);
1311     EXEC SQL DECLARE csr215 CURSOR FOR
1312         SELECT entity_id, type FROM quota
1313             WHERE filsys_id = :id;
1314     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1315     EXEC SQL OPEN csr215;
1316     while(1) {
1317         EXEC SQL FETCH csr215 INTO :id1, :type;
1318         if (sqlca.sqlcode != 0) {
1319           ingerr(&sqlca.sqlcode);
1320           break;
1321         } 
1322
1323         found = 0;
1324         printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1325                type, id1, f->name, id);
1326     }
1327     EXEC SQL CLOSE csr215; 
1328     return(found);
1329 }
1330
1331 fix_quota_physid(id)
1332 EXEC SQL BEGIN DECLARE SECTION; 
1333 int id;
1334 EXEC SQL END DECLARE SECTION; 
1335 {
1336     EXEC SQL BEGIN DECLARE SECTION; 
1337     int rowcount, id1;
1338     EXEC SQL END DECLARE SECTION; 
1339
1340     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1341     EXEC SQL UPDATE quota SET phys_id = :id1 
1342         WHERE filsys_id = :id AND phys_id != :id1;
1343     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1344     if (rowcount > 0)
1345       printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
1346     else
1347       printf("Not fixed\n");
1348     modified("quota");
1349 }
1350
1351 show_srv_user(id)
1352 EXEC SQL BEGIN DECLARE SECTION; 
1353 int id;
1354 EXEC SQL END DECLARE SECTION; 
1355 {
1356     EXEC SQL BEGIN DECLARE SECTION; 
1357     char name[33];
1358     EXEC SQL END DECLARE SECTION; 
1359     int found = 1;
1360
1361     EXEC SQL DECLARE csr216 CURSOR FOR
1362         SELECT name FROM servers
1363             WHERE acl_type='USER' and acl_id = :id;
1364     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1365     EXEC SQL OPEN csr216;
1366     while(1) {
1367         EXEC SQL FETCH csr216 INTO :name;
1368         if (sqlca.sqlcode != 0) {
1369           ingerr(&sqlca.sqlcode);
1370           break;
1371         } 
1372         
1373         strtrim(name);
1374         printf("Service %s has acl non-existant user %d\n", name, id);
1375         found = 0;
1376     }
1377     EXEC SQL CLOSE csr216; 
1378     return(found);
1379 }
1380
1381 show_srv_list(id)
1382 EXEC SQL BEGIN DECLARE SECTION; 
1383 int id;
1384 EXEC SQL END DECLARE SECTION; 
1385 {
1386     EXEC SQL BEGIN DECLARE SECTION; 
1387     char name[33];
1388     EXEC SQL END DECLARE SECTION; 
1389     int found = 1;
1390
1391     EXEC SQL DECLARE csr217 CURSOR FOR
1392         SELECT name FROM servers
1393             WHERE acl_type='LIST' AND acl_id = :id;
1394     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1395     EXEC SQL OPEN csr217;
1396     while(1) {
1397         EXEC SQL FETCH csr217 INTO :name;
1398         if (sqlca.sqlcode != 0) {
1399           ingerr(&sqlca.sqlcode);
1400           break;
1401         } 
1402
1403         strtrim(name);
1404         printf("Service %s has acl non-existant list %d\n", name, id);
1405         found = 0;
1406     }
1407     EXEC SQL CLOSE csr217; 
1408     return(found);
1409 }
1410
1411 zero_srv_user(id)
1412 EXEC SQL BEGIN DECLARE SECTION; 
1413 int id;
1414 EXEC SQL END DECLARE SECTION; 
1415 {
1416     EXEC SQL BEGIN DECLARE SECTION; 
1417     int rowcount;
1418     EXEC SQL END DECLARE SECTION; 
1419
1420     EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
1421         acl_type='USER';
1422     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1423     if (rowcount > 0)
1424       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1425     else
1426       printf("Not fixed\n");
1427     modified("servers");
1428 }
1429
1430 zero_srv_list(id)
1431 EXEC SQL BEGIN DECLARE SECTION; 
1432 int id;
1433 EXEC SQL END DECLARE SECTION; 
1434 {
1435     EXEC SQL BEGIN DECLARE SECTION; 
1436     int rowcount;
1437     EXEC SQL END DECLARE SECTION; 
1438
1439     EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
1440         acl_type='LIST';
1441     EXEC SQL INQUIRE_SQL(:rowcount = rowcount); 
1442     if (rowcount > 0)
1443       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1444     else
1445       printf("Not fixed\n");
1446     modified("servers");
1447 }
1448
1449
1450 show_krb_usr(id)
1451 EXEC SQL BEGIN DECLARE SECTION; 
1452 int id;
1453 EXEC SQL END DECLARE SECTION; 
1454 {
1455     EXEC SQL BEGIN DECLARE SECTION; 
1456     int found = 1, id1;
1457     EXEC SQL END DECLARE SECTION; 
1458     struct string *s;
1459     char *ss;
1460
1461     EXEC SQL DECLARE csr218 CURSOR FOR
1462         SELECT string_id FROM krbmap
1463             WHERE users_id = :id ;
1464     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1465     EXEC SQL OPEN csr218;
1466     while(1) {
1467         EXEC SQL FETCH csr218 INTO :id1;
1468         if (sqlca.sqlcode != 0) {
1469           ingerr(&sqlca.sqlcode);
1470           break;
1471         } 
1472
1473         if (s = ((struct string *)hash_lookup(strings, id1)))
1474             ss = s->name;
1475         else
1476             ss = "[unknown]";
1477         found = 0;
1478         printf("Kerberos map for non-existant user %d to principal %s\n",
1479                id, s);
1480     }
1481     EXEC SQL CLOSE csr218; 
1482     return(found);
1483 }
1484
1485
1486 show_krb_str(id)
1487 EXEC SQL BEGIN DECLARE SECTION; 
1488 int id;
1489 EXEC SQL END DECLARE SECTION; 
1490 {
1491     EXEC SQL BEGIN DECLARE SECTION; 
1492     int found = 1, id1;
1493     EXEC SQL END DECLARE SECTION; 
1494     struct user *u;
1495     char *s;
1496
1497     EXEC SQL DECLARE csr219 CURSOR FOR
1498         SELECT users_id FROM krbmap
1499             WHERE string_id = :id;
1500     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1501     EXEC SQL OPEN csr219;
1502     while(1) {
1503         EXEC SQL FETCH csr219 INTO :id1;
1504         if (sqlca.sqlcode != 0) {
1505           ingerr(&sqlca.sqlcode);
1506           break;
1507         } 
1508
1509         if (u = ((struct user *)hash_lookup(users, id1)))
1510             s = u->login;
1511         else
1512             s = "[???]";
1513         found = 0;
1514         printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1515                s, id1, id);
1516         }
1517     EXEC SQL CLOSE csr219; 
1518     return(found);
1519 }
1520
1521
1522 show_pdm_mach(id)
1523 EXEC SQL BEGIN DECLARE SECTION; 
1524 int id;
1525 EXEC SQL END DECLARE SECTION; 
1526 {
1527     EXEC SQL BEGIN DECLARE SECTION; 
1528     char name[33];
1529     EXEC SQL END DECLARE SECTION; 
1530     int found = 1;
1531
1532     EXEC SQL DECLARE csr220 CURSOR FOR
1533         SELECT name FROM palladium
1534             WHERE mach_id = :id;
1535     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1536     EXEC SQL OPEN csr220;
1537     while(1) {
1538         EXEC SQL FETCH csr220 INTO :name;
1539         if (sqlca.sqlcode != 0) {
1540           ingerr(&sqlca.sqlcode);
1541           break;
1542         } 
1543
1544         strtrim(name);
1545         printf("Palladium server/supervisor %s is on non-existant machine %d\n",
1546                name, id);
1547         found = 0;
1548         }
1549     EXEC SQL CLOSE csr220; 
1550     return(found);
1551 }
1552
1553
1554 phase2()
1555 {
1556     EXEC SQL BEGIN DECLARE SECTION; 
1557     int id1, id2, id3, id4, id5;
1558     char type[9], name[33];
1559     EXEC SQL END DECLARE SECTION; 
1560     struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
1561     struct filesys *f;
1562     struct list *l;
1563     struct nfsphys *n;
1564     struct machine *m;
1565
1566     printf("Phase 2 - Checking references\n");
1567
1568     dprintf("Checking users...\n");
1569     hash_step(users, user_check, NULL);
1570
1571     dprintf("Checking machines...\n");
1572     hash_step(machines, mach_check, NULL);
1573
1574     dprintf("Checking subnets...\n");
1575     hash_step(subnets, subnet_check, NULL);
1576
1577     dprintf("Checking clusters...\n");
1578     hash_step(clusters, cluster_check, NULL);
1579
1580     dprintf("Checking mcmap...\n");
1581     sq1 = sq_create();
1582     sq2 = sq_create();
1583     EXEC SQL DECLARE csr221 CURSOR FOR
1584       SELECT mach_id, clu_id FROM mcmap;
1585     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1586     EXEC SQL OPEN csr221;
1587     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1588     while(1) {
1589         EXEC SQL FETCH csr221 INTO :id1, :id2;
1590         if (sqlca.sqlcode != 0) {
1591           ingerr(&sqlca.sqlcode);
1592           break;
1593         } 
1594
1595         if (!(m = (struct machine *)hash_lookup(machines, id1)))
1596             sq_save_unique_data(sq1, id1);
1597         else if (!hash_lookup(clusters, id2))
1598             sq_save_unique_data(sq2, id2);
1599         if (m) m->clucount++;
1600     }
1601     EXEC SQL CLOSE csr221; 
1602     generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1603     generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1604
1605     dprintf("Checking service clusters...\n");
1606     sq1 = sq_create();
1607     EXEC SQL DECLARE csr222 CURSOR FOR
1608       SELECT clu_id FROM svc;
1609     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1610     EXEC SQL OPEN csr222;
1611     while(1) {
1612         EXEC SQL FETCH csr222 INTO :id1;
1613         if (sqlca.sqlcode != 0) {
1614           ingerr(&sqlca.sqlcode);
1615           break;
1616         } 
1617
1618         if (!hash_lookup(clusters, id1))
1619           sq_save_unique_data(sq1, id1);
1620     }
1621     EXEC SQL CLOSE csr222; 
1622     generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1623
1624     dprintf("Checking lists...\n");
1625     hash_step(lists, list_check, NULL);
1626
1627     dprintf("Checking members...\n");
1628     sq1 = sq_create();
1629     sq2 = sq_create();
1630     sq3 = sq_create();
1631     sq4 = sq_create();
1632     sq5 = sq_create();
1633
1634     EXEC SQL DECLARE csr223 CURSOR FOR
1635       SELECT list_id, member_type, member_id, ref_count, direct
1636       FROM imembers FOR DEFERRED UPDATE OF member_id;
1637     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1638     EXEC SQL OPEN csr223;
1639     while(1) {
1640         EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
1641         if (sqlca.sqlcode != 0) {
1642           ingerr(&sqlca.sqlcode);
1643           break;
1644         } 
1645
1646         if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
1647           sq_save_unique_data(sq1, id1);
1648         else if (type[0] == 'U' && !hash_lookup(users, id2))
1649           sq_save_unique_data(sq2, id2);
1650         else if (type[0] == 'L' && !hash_lookup(lists, id2))
1651           sq_save_unique_data(sq3, id2);
1652         else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
1653           sq_save_unique_data(sq4, id2);
1654         else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
1655           sq_save_unique_data(sq5, id2);
1656         else
1657           l->members++;
1658         }
1659     EXEC SQL CLOSE csr223; 
1660     generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1661     generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1662     generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1663     generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1664     generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1665
1666     dprintf("Checking servers...\n");
1667     sq1 = sq_create();
1668     sq2 = sq_create();
1669     EXEC SQL DECLARE csr224 CURSOR FOR
1670       SELECT name, acl_type, acl_id, modby FROM servers
1671       FOR DEFERRED UPDATE of modby;
1672     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1673     EXEC SQL OPEN csr224;
1674     while(1) {
1675         EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2;
1676         if (sqlca.sqlcode != 0) {
1677           ingerr(&sqlca.sqlcode);
1678           break;
1679         } 
1680
1681         maybe_fixup_modby2("servers","modby","csr224",id2);
1682         strtrim(type);
1683         if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
1684             sq_save_data(sq1, id1);
1685         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
1686             sq_save_data(sq2, id1);
1687         }
1688     }
1689     EXEC SQL CLOSE csr224; 
1690     generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
1691     generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
1692
1693     dprintf("Checking serverhosts...\n");
1694     sq = sq_create();
1695     EXEC SQL DECLARE csr225 CURSOR FOR
1696       SELECT mach_id, modby FROM serverhosts
1697       FOR DEFERRED UPDATE OF modby;
1698     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1699     EXEC SQL OPEN csr225;
1700     while(1) {
1701         EXEC SQL FETCH csr225 INTO :id1, :id2;
1702         if (sqlca.sqlcode != 0) {
1703           ingerr(&sqlca.sqlcode);
1704           break;
1705         } 
1706
1707         maybe_fixup_modby2("serverhosts", "modby", "csr225", id2);
1708         if (!hash_lookup(machines, id1))
1709           sq_save_data(sq, id1);
1710         }
1711     EXEC SQL CLOSE csr225; 
1712     generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1713
1714     dprintf("Checking nfsphys...\n");
1715     hash_step(nfsphys, check_nfsphys, NULL);
1716
1717     dprintf("Checking filesys...\n");
1718     hash_step(filesys, check_fs, NULL);
1719
1720     dprintf("Checking filesystem groups...\n");
1721     sq1 = sq_create();
1722     sq2 = sq_create();
1723     sq3 = sq_create();
1724     EXEC SQL DECLARE csr226 CURSOR FOR
1725       SELECT group_id, filsys_id FROM fsgroup;
1726     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1727     EXEC SQL OPEN csr226;
1728     while(1) {
1729         EXEC SQL FETCH csr226 INTO :id1, :id2;
1730         if (sqlca.sqlcode != 0) {
1731           ingerr(&sqlca.sqlcode);
1732           break;
1733         } 
1734
1735         if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
1736           sq_save_data(sq1, id1);
1737         if (!hash_lookup(filesys, id2))
1738           sq_save_data(sq3, id2);
1739     }
1740     EXEC SQL CLOSE csr226; 
1741     generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
1742     generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
1743
1744     dprintf("Checking quotas...\n");
1745     sq1 = sq_create();
1746     sq2 = sq_create();
1747     sq3 = sq_create();
1748     sq4 = sq_create();
1749     EXEC SQL DECLARE csr227 CURSOR FOR
1750       SELECT entity_id, type, filsys_id, phys_id, quota, modby
1751       FROM quota FOR DEFERRED UPDATE OF modby;
1752     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1753     EXEC SQL OPEN csr227;
1754     while(1) {
1755         EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5;
1756         if (sqlca.sqlcode != 0) {
1757           ingerr(&sqlca.sqlcode);
1758           break;
1759         } 
1760
1761         maybe_fixup_modby2("quota", "modby", "csr227", id5);
1762         if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
1763           sq_save_data(sq1, id1);
1764         else if (type[0] == 'G' && !hash_lookup(lists, id1))
1765           sq_save_data(sq4, id1);
1766         else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
1767           sq_save_data(sq2, id2);
1768         else if (id3 != f->phys_id ||
1769             ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) ==
1770             (struct nfsphys *)NULL))
1771           sq_save_data(sq3, id2);
1772         else
1773           n->count += id4;
1774     }
1775     EXEC SQL CLOSE csr227; 
1776     generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
1777     generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
1778     generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
1779     generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
1780
1781     dprintf("Not checking zephyr.\n");
1782
1783     dprintf("Checking hostaccess...\n");
1784     EXEC SQL DECLARE csr228 CURSOR FOR
1785       SELECT mach_id, acl_type, acl_id, modby FROM hostaccess
1786       FOR DEFERRED UPDATE OF modby;
1787     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1788     EXEC SQL OPEN csr228;
1789     while(1) {
1790         EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3;
1791         if (sqlca.sqlcode != 0) {
1792           ingerr(&sqlca.sqlcode);
1793           break;
1794         } 
1795
1796         maybe_fixup_modby2("hostaccess", "modby", "csr228", id3);
1797         strtrim(type);
1798         if (!hash_lookup(machines, id1)) {
1799             printf("Hostaccess for non-existant host %d\n", id1);
1800             printf("Not fixing this error\n");
1801         }
1802         if (!strcmp(type, "USER") && !hash_lookup(users, id2)) {
1803             printf("Hostaccess for %d is non-existant user %d\n", id1, id2);
1804             printf("Not fixing this error\n");
1805         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) {
1806             printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
1807             printf("Not fixing this error\n");
1808         }
1809     }
1810     EXEC SQL CLOSE csr228; 
1811
1812     dprintf("Checking palladium...\n");
1813     sq1 = sq_create();
1814     EXEC SQL DECLARE csr229 CURSOR FOR
1815       SELECT mach_id, modby FROM palladium
1816       FOR DEFERRED UPDATE OF modby;
1817     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1818     EXEC SQL OPEN csr229;
1819     while(1) {
1820         EXEC SQL FETCH csr229 INTO :id1, :id2;
1821         if (sqlca.sqlcode != 0) {
1822           ingerr(&sqlca.sqlcode);
1823           break;
1824         } 
1825
1826         maybe_fixup_modby2("palladium", "modby", "csr229", id2);
1827         if (!hash_lookup(machines, id1)) {
1828             sq_save_unique_data(sq1, id1);
1829         }
1830     }
1831     EXEC SQL CLOSE csr229;
1832     generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
1833
1834     dprintf("Checking krbmap...\n");
1835     sq1 = sq_create();
1836     sq2 = sq_create();
1837     EXEC SQL DECLARE csr230 CURSOR FOR
1838       SELECT users_id, string_id FROM krbmap
1839       FOR DEFERRED UPDATE OF string_id;
1840     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1841     EXEC SQL OPEN csr230;
1842     while(1) {
1843         EXEC SQL FETCH csr230 INTO :id1, :id2;
1844         if (sqlca.sqlcode != 0) {
1845           ingerr(&sqlca.sqlcode);
1846           break;
1847         } 
1848
1849         if (!hash_lookup(users, id1))
1850           sq_save_unique_data(sq1, id1);
1851         else if (!maybe_fixup_unref_string2("krbmap","string_id","csr230",id2))
1852           sq_save_unique_data(sq2, id2);
1853         }
1854     EXEC SQL CLOSE csr230; 
1855     generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
1856     generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
1857
1858     dprintf("Checking capacls...\n");
1859     EXEC SQL DECLARE csr231 CURSOR FOR
1860       SELECT list_id, tag FROM capacls;
1861     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1862     EXEC SQL OPEN csr231;
1863     while(1) {
1864         EXEC SQL FETCH csr231 INTO :id1, :name;
1865         if (sqlca.sqlcode != 0) {
1866           ingerr(&sqlca.sqlcode);
1867           break;
1868         } 
1869
1870         if (!hash_lookup(lists, id1)) {
1871             printf("Capacl for %s is non-existant list %d\n", name, id1);
1872             printf("Not fixing this error\n");
1873         }
1874     }
1875     EXEC SQL CLOSE csr231;
1876
1877     dprintf("Checking hostaliases\n");
1878     sq1 = sq_create();
1879     EXEC SQL DECLARE csr232 CURSOR FOR
1880       SELECT mach_id FROM hostalias;
1881     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1882     EXEC SQL OPEN csr232;
1883     while(1) {
1884         EXEC SQL FETCH csr232 INTO :id1;
1885         if (sqlca.sqlcode != 0) {
1886           ingerr(&sqlca.sqlcode);
1887           break;
1888         } 
1889
1890         if (!hash_lookup(machines, id1))
1891           sq_save_unique_data(sq1, id1);
1892     }
1893     EXEC SQL CLOSE csr232;
1894     generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
1895     
1896     dprintf("Checking printcaps\n");
1897     sq1 = sq_create();
1898     sq2 = sq_create();
1899     EXEC SQL DECLARE csr233 CURSOR FOR
1900       SELECT mach_id, quotaserver, modby FROM printcap;
1901     if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode);
1902     EXEC SQL OPEN csr233;
1903     while(1) {
1904         EXEC SQL FETCH csr233 INTO :id1, :id2, :id3;
1905         if (sqlca.sqlcode != 0) {
1906           ingerr(&sqlca.sqlcode);
1907           break;
1908         } 
1909
1910         maybe_fixup_modby2("printcap", "modby", "csr233", id3);
1911         if (!hash_lookup(machines, id1))
1912           sq_save_unique_data(sq1, id1);
1913         else if(!hash_lookup(machines, id2))
1914           sq_save_unique_data(sq2, id2);
1915     }
1916     EXEC SQL CLOSE csr233;
1917     generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1);
1918     generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1);
1919 }
This page took 0.175841 seconds and 5 git commands to generate.