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