]> andersk Git - moira.git/blob - dbck/phase2.pc
Rewrite functions to avoid having SQL DECLARE SECTIONs around function
[moira.git] / dbck / phase2.pc
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 = 0 WHERE %s = %d",
224                 table, field, 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 = 0 WHERE CURRENT OF %s",
294                 table, field, 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 int id;
740 {
741     EXEC SQL BEGIN DECLARE SECTION; 
742     int iid = id, rowcount;
743     EXEC SQL END DECLARE SECTION; 
744
745     EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND
746         member_id = :iid AND direct = 1;
747     rowcount = sqlca.sqlerrd[2];
748     if (rowcount > 0)
749       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
750     else
751       printf("Not deleted\n");
752     modified("imembers");
753 }
754
755 del_mem_list(id)
756 int id;
757 {
758     EXEC SQL BEGIN DECLARE SECTION; 
759     int iid = id, rowcount;
760     EXEC SQL END DECLARE SECTION; 
761
762     EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND
763         member_id = :iid AND direct=1;
764     rowcount = sqlca.sqlerrd[2];
765     if (rowcount > 0)
766       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
767     else
768       printf("Not deleted\n");
769     modified("imembers");
770 }
771
772 del_mem_str(id)
773 int id;
774 {
775     EXEC SQL BEGIN DECLARE SECTION; 
776     int iid = id, rowcount;
777     EXEC SQL END DECLARE SECTION; 
778
779     EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND
780         member_id = :iid AND direct=1;
781     rowcount = sqlca.sqlerrd[2];
782     if (rowcount > 0)
783       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
784     else
785       printf("Not deleted\n");
786     modified("imembers");
787 }
788
789
790 del_mem_krb(id)
791 int id;
792 {
793     EXEC SQL BEGIN DECLARE SECTION; 
794     int iid = id, rowcount;
795     EXEC SQL END DECLARE SECTION; 
796
797     EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND
798         member_id = :iid AND direct=1;
799     rowcount = sqlca.sqlerrd[2];
800     if (rowcount > 0)
801       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
802     else
803       printf("Not deleted\n");
804     modified("imembers");
805 }
806
807
808 show_sh(id)
809 int id;
810 {
811     EXEC SQL BEGIN DECLARE SECTION; 
812     char name[33];
813     int iid = id;
814     EXEC SQL END DECLARE SECTION; 
815     int found = 1;
816
817     EXEC SQL DECLARE csr209 CURSOR FOR
818         SELECT service FROM serverhosts
819             WHERE mach_id = :iid;
820     EXEC SQL OPEN csr209;
821     while(1) {
822         EXEC SQL FETCH csr209 INTO :name;
823         if (sqlca.sqlcode != 0) break; 
824
825         found = 0;
826         printf("ServerHost entry for service %s non-existant host %d\n",
827                name, id);
828     }
829     EXEC SQL CLOSE csr209; 
830     return(found);
831 }
832
833 del_sh_mach(id)
834 int id;
835 {
836     EXEC SQL BEGIN DECLARE SECTION; 
837     int iid = id, rowcount;
838     EXEC SQL END DECLARE SECTION; 
839
840     EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
841     rowcount = sqlca.sqlerrd[2];
842     if (rowcount > 0)
843       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
844     else
845       printf("Not deleted\n");
846     modified("serverhosts");
847 }
848
849
850 static int fnchecklen;
851
852 fsmatch(id, n, f)
853 int id;
854 struct nfsphys *n;
855 struct filesys *f;
856 {
857     if (n->mach_id == f->mach_id &&
858         !strncmp(f->dir, n->dir, strlen(n->dir)) &&
859         strlen(n->dir) > fnchecklen) {
860         f->phys_id = id;
861         fnchecklen = strlen(n->dir);
862     }
863 }
864
865
866 check_fs(id, f, hint)
867 int id;
868 register struct filesys *f;
869 int hint;
870 {
871     EXEC SQL BEGIN DECLARE SECTION; 
872     int iid = id, id1, id2, id3, rowcount;
873     char *dir;
874     EXEC SQL END DECLARE SECTION; 
875     struct nfsphys *n;
876     struct machine *m;
877
878     if (!hash_lookup(machines, f->mach_id)) {
879         printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
880         if (single_fix("Fix", 0)) {
881             EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
882             rowcount = sqlca.sqlerrd[2];
883             if (rowcount > 0)
884               printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
885             else
886               printf("Not fixed\n");
887             modified("filesys");
888             f->mach_id = 0;
889         }
890     }
891
892     if (!hash_lookup(users, f->owner)) {
893         printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
894         if (single_fix("Fix", 1)) {
895             zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
896             f->owner = 0;
897         }
898     }
899     if (!hash_lookup(lists, f->owners)) {
900         printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
901         if (single_fix("Fix", 1)) {
902             zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
903             f->owners = 0;
904         }
905     }
906
907     if (f->type == 'N') {
908         if (!hash_lookup(nfsphys, f->phys_id)) {
909             m = (struct machine *)hash_lookup(machines, f->mach_id);
910             printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
911             if (single_fix("Fix", 1)) {
912                 fnchecklen = 0;
913                 hash_step(nfsphys, fsmatch, f);
914                 if (fnchecklen != 0) {
915                   id1 = f->phys_id;
916                   id2 = f->filsys_id;
917                   id3 = f->mach_id;
918                   EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2;
919                   rowcount = sqlca.sqlerrd[2];
920                   if (rowcount > 0)
921                     printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
922                   else
923                     printf("Not fixed\n");
924                   modified("filesys");
925                 } else {
926                     printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
927                     if (single_fix("Create", 0)) {
928                         dir = f->dir;
929                         id1 = f->phys_id;
930                         id2 = f->filsys_id;
931                         id3 = f->mach_id;
932                         if (set_next_object_id("nfsphys_id", "nfsphys") !=
933                                 MR_SUCCESS) {
934                             printf("Unable to assign unique ID\n");
935                             return;
936                         }
937                         EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues 
938                             WHERE name='nfsphys_id';
939                         if (rowcount != 1) {
940                             printf("Unable to retrieve unique ID\n");
941                             return;
942                         }
943                         EXEC SQL INSERT INTO nfsphys (nfsphys_id, mach_id,
944                             device, dir, status, allocated, size, modtime,
945                             modby, modwith) VALUES (:id1, :id3, '\?\?\?', :dir,
946                             0, 0, 0, SYSDATE, 0, 'dbck');
947                         rowcount = sqlca.sqlerrd[2];
948                         if (rowcount > 0)
949                           printf("%d entr%s created\n", rowcount,
950                                  rowcount==1?"y":"ies");
951                         else
952                           printf("Not created\n");
953                         modified("nfsphys");
954                         n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
955                         if (n == NULL)
956                           out_of_mem("storing new nfsphys");
957                         strcpy(n->dir, dir);
958                         n->mach_id = id3;
959                         n->nfsphys_id = id1;
960                         n->allocated = 0;
961                         n->count = 0;
962                         if( hash_store(nfsphys, id1, n) == -1 ) {
963                           out_of_mem("storing nfsphys in hash table");
964                         }
965                         EXEC SQL UPDATE filesys SET phys_id = :id1
966                             WHERE filsys_id = :id2;
967                         rowcount = sqlca.sqlerrd[2];
968                         if (rowcount > 0)
969                           printf("%d filesys entr%s fixed\n", rowcount,
970                                  rowcount==1?"y":"ies");
971                         else
972                           printf("Not fixed\n");
973                         modified("filesys");
974                     }
975                 }
976             }
977         }
978     }
979 }
980
981
982 check_nfsphys(id, n, hint)
983 int id;
984 struct nfsphys *n;
985 int hint;
986 {
987     if (!hash_lookup(machines, n->mach_id)) {
988         printf("NFSphys %d(%s) on non-existant machine %d\n",
989                id, n->dir, n->mach_id);
990         if (single_fix("Delete", 0))
991           single_delete("nfsphys", "nfsphys_id", id);
992     }
993 }
994
995 show_fsg_missing(id)
996 int id;
997 {
998     EXEC SQL BEGIN DECLARE SECTION; 
999     int iid = id, id1, found = 1;
1000     EXEC SQL END DECLARE SECTION; 
1001     struct filesys *f;
1002
1003     EXEC SQL DECLARE csr210 CURSOR FOR
1004         SELECT filsys_id FROM fsgroup
1005             WHERE group_id = :iid;
1006     EXEC SQL OPEN csr210;
1007     while(1) {
1008         EXEC SQL FETCH csr210 INTO :id1;
1009         if (sqlca.sqlcode != 0) break; 
1010
1011         found = 0;
1012         if (f = (struct filesys *) hash_lookup(filesys, id1))
1013             printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
1014         else
1015             printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
1016     }
1017     EXEC SQL CLOSE csr210; 
1018     return(found);
1019 }
1020
1021 show_fsg_type(f)
1022 struct filesys *f;
1023 {
1024     char *t;
1025
1026     switch (f->type) {
1027     case 'N':
1028         t = "NFS";
1029         break;
1030     case 'R':
1031         t = "RVD";
1032         break;
1033     case 'A':
1034         t = "AFS";
1035         break;
1036     case 'E':
1037         t = "ERR";
1038         break;
1039     case 'F':
1040         t = "FSGROUP";
1041         break;
1042     case 'M':
1043         t = "MUL";
1044         break;
1045     default:
1046         t = "\?\?\?";
1047     }
1048     printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1049     return(0);
1050 }
1051
1052 fix_fsg_type(f)
1053 struct filesys *f;
1054 {
1055     EXEC SQL BEGIN DECLARE SECTION; 
1056     int rowcount, id = f->filsys_id;
1057     EXEC SQL END DECLARE SECTION; 
1058
1059     EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id;
1060     rowcount = sqlca.sqlerrd[2];
1061     if (rowcount > 0)
1062       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1063     else
1064       printf("Not fixed\n");
1065     modified("filesys");
1066 }
1067
1068 show_fsg_nomember(id)
1069 int id;
1070 {
1071     EXEC SQL BEGIN DECLARE SECTION; 
1072     int iid = id, id1, found = 1;
1073     EXEC SQL END DECLARE SECTION; 
1074     struct filesys *f;
1075
1076     EXEC SQL DECLARE csr211 CURSOR FOR
1077         SELECT group_id FROM fsgroup
1078             WHERE filsys_id = :iid;
1079     EXEC SQL OPEN csr211;
1080     while(1) {
1081         EXEC SQL FETCH csr211 INTO :id1;
1082         if (sqlca.sqlcode != 0) break; 
1083
1084         found = 0;
1085         if (f = (struct filesys *) hash_lookup(filesys, id1))
1086             printf("FSGroup %s has missing member %d\n", f->name, id);
1087         else
1088             printf("FSGroup %d has missing member %d\n", id1, id);
1089     }
1090     EXEC SQL CLOSE csr211; 
1091     return(found);
1092 }
1093
1094 show_quota_nouser(id)
1095 int id;
1096 {
1097     EXEC SQL BEGIN DECLARE SECTION; 
1098     int iid = id, id1, found = 1;
1099     EXEC SQL END DECLARE SECTION; 
1100
1101     EXEC SQL DECLARE csr212 CURSOR FOR
1102         SELECT filsys_id FROM quota
1103             WHERE entity_id = :iid AND type='USER';
1104     EXEC SQL OPEN csr212;
1105     while(1) {
1106         EXEC SQL FETCH csr212 INTO :id1;
1107         if (sqlca.sqlcode != 0) break; 
1108
1109         found = 0;
1110         printf("Quota on fs %d for non-existant user %d\n", id1, id);
1111     }
1112     EXEC SQL CLOSE csr212; 
1113     return(found);
1114 }
1115
1116 show_quota_nolist(id)
1117 int id;
1118 {
1119     EXEC SQL BEGIN DECLARE SECTION; 
1120     int iid = id, id1, found = 1;
1121     EXEC SQL END DECLARE SECTION; 
1122
1123     EXEC SQL DECLARE csr213 CURSOR FOR
1124         SELECT filsys_id FROM quota 
1125             WHERE entity_id = :iid AND type='GROUP';
1126     EXEC SQL OPEN csr213;
1127     while(1) {
1128         EXEC SQL FETCH csr213 INTO :id1;
1129         if (sqlca.sqlcode != 0) break;
1130  
1131         found = 0;
1132         printf("Quota on fs %d for non-existant list %d\n", id1, id);
1133     }
1134     EXEC SQL CLOSE csr213; 
1135     return(found);
1136 }
1137
1138 fix_quota_nouser(id)
1139 int id;
1140 {
1141     EXEC SQL BEGIN DECLARE SECTION; 
1142     int iid = id, rowcount, id1;
1143     EXEC SQL END DECLARE SECTION; 
1144
1145     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1146     EXEC SQL DELETE FROM quota 
1147         WHERE entity_id = :iid AND type = 'USER';
1148     rowcount = sqlca.sqlerrd[2];
1149     if (rowcount > 0)
1150       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1151     else
1152       printf("Not deleted\n");
1153     modified("quota");
1154 }
1155
1156 fix_quota_nolist(id)
1157 int id;
1158 {
1159     EXEC SQL BEGIN DECLARE SECTION; 
1160     int iid = id, rowcount, id1;
1161     EXEC SQL END DECLARE SECTION; 
1162
1163     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1164     EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type='GROUP';
1165     rowcount = sqlca.sqlerrd[2];
1166     if (rowcount > 0)
1167       printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1168     else
1169       printf("Not deleted\n");
1170     modified("quota");
1171 }
1172
1173 show_quota_nofs(id)
1174 int id;
1175 {
1176     EXEC SQL BEGIN DECLARE SECTION; 
1177     int iid = id, id1, found = 1;
1178     char type[9];
1179     EXEC SQL END DECLARE SECTION; 
1180
1181     EXEC SQL DECLARE csr214 CURSOR FOR
1182         SELECT entity_id, type FROM quota
1183             WHERE filsys_id = :iid;
1184     EXEC SQL OPEN csr214;
1185     while(1) {
1186         EXEC SQL FETCH csr214 INTO :id1, :type;
1187         if (sqlca.sqlcode != 0) break; 
1188         
1189         found = 0;
1190         printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
1191     }
1192     EXEC SQL CLOSE csr214;
1193     return(found);
1194 }
1195
1196 fix_quota_nofs(id)
1197 {
1198     single_delete("quota", "filsys_id", id);
1199 }
1200
1201 show_quota_wrongpid(id)
1202 int id;
1203 {
1204     EXEC SQL BEGIN DECLARE SECTION; 
1205     int iid = id, id1, found = 1;
1206     char type[9];
1207     EXEC SQL END DECLARE SECTION; 
1208     struct user *u;
1209     struct filesys *f;
1210
1211     f = (struct filesys *)hash_lookup(filesys, id);
1212     EXEC SQL DECLARE csr215 CURSOR FOR
1213         SELECT entity_id, type FROM quota
1214             WHERE filsys_id = :iid;
1215     EXEC SQL OPEN csr215;
1216     while(1) {
1217         EXEC SQL FETCH csr215 INTO :id1, :type;
1218         if (sqlca.sqlcode != 0) break; 
1219
1220         found = 0;
1221         printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1222                type, id1, f->name, id);
1223     }
1224     EXEC SQL CLOSE csr215; 
1225     return(found);
1226 }
1227
1228 fix_quota_physid(id)
1229 int id;
1230 {
1231     EXEC SQL BEGIN DECLARE SECTION; 
1232     int iid = id, rowcount, id1;
1233     EXEC SQL END DECLARE SECTION; 
1234
1235     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1236     EXEC SQL UPDATE quota SET phys_id = :id1 
1237         WHERE filsys_id = :iid AND phys_id != :id1;
1238     rowcount = sqlca.sqlerrd[2];
1239     if (rowcount > 0)
1240       printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
1241     else
1242       printf("Not fixed\n");
1243     modified("quota");
1244 }
1245
1246 show_srv_user(id)
1247 int id;
1248 {
1249     EXEC SQL BEGIN DECLARE SECTION; 
1250     char name[33];
1251     int iid = id;
1252     EXEC SQL END DECLARE SECTION; 
1253     int found = 1;
1254
1255     EXEC SQL DECLARE csr216 CURSOR FOR
1256         SELECT name FROM servers
1257             WHERE acl_type='USER' and acl_id = :iid;
1258     EXEC SQL OPEN csr216;
1259     while(1) {
1260         EXEC SQL FETCH csr216 INTO :name;
1261         if (sqlca.sqlcode != 0) break; 
1262         
1263         strtrim(name);
1264         printf("Service %s has acl non-existant user %d\n", name, id);
1265         found = 0;
1266     }
1267     EXEC SQL CLOSE csr216; 
1268     return(found);
1269 }
1270
1271 show_srv_list(id)
1272 int id;
1273 {
1274     EXEC SQL BEGIN DECLARE SECTION; 
1275     char name[33];
1276     int iid = id;
1277     EXEC SQL END DECLARE SECTION; 
1278     int found = 1;
1279
1280     EXEC SQL DECLARE csr217 CURSOR FOR
1281         SELECT name FROM servers
1282             WHERE acl_type='LIST' AND acl_id = :iid;
1283     EXEC SQL OPEN csr217;
1284     while(1) {
1285         EXEC SQL FETCH csr217 INTO :name;
1286         if (sqlca.sqlcode != 0) break; 
1287
1288         strtrim(name);
1289         printf("Service %s has acl non-existant list %d\n", name, id);
1290         found = 0;
1291     }
1292     EXEC SQL CLOSE csr217; 
1293     return(found);
1294 }
1295
1296 zero_srv_user(id)
1297 int id;
1298 {
1299     EXEC SQL BEGIN DECLARE SECTION; 
1300     int iid = id, rowcount;
1301     EXEC SQL END DECLARE SECTION; 
1302
1303     EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :iid AND
1304         acl_type='USER';
1305     rowcount = sqlca.sqlerrd[2];
1306     if (rowcount > 0)
1307       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1308     else
1309       printf("Not fixed\n");
1310     modified("servers");
1311 }
1312
1313 zero_srv_list(id)
1314 int id;
1315 {
1316     EXEC SQL BEGIN DECLARE SECTION; 
1317     int iid = id, rowcount;
1318     EXEC SQL END DECLARE SECTION; 
1319
1320     EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :iid AND
1321         acl_type='LIST';
1322     rowcount = sqlca.sqlerrd[2];
1323     if (rowcount > 0)
1324       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1325     else
1326       printf("Not fixed\n");
1327     modified("servers");
1328 }
1329
1330
1331 show_krb_usr(id)
1332 int id;
1333 {
1334     EXEC SQL BEGIN DECLARE SECTION; 
1335     int iid = id, found = 1, id1;
1336     EXEC SQL END DECLARE SECTION; 
1337     struct string *s;
1338     char *ss;
1339
1340     EXEC SQL DECLARE csr218 CURSOR FOR
1341         SELECT string_id FROM krbmap
1342             WHERE users_id = :iid ;
1343     EXEC SQL OPEN csr218;
1344     while(1) {
1345         EXEC SQL FETCH csr218 INTO :id1;
1346         if (sqlca.sqlcode != 0) break; 
1347
1348         if (s = ((struct string *)hash_lookup(strings, id1)))
1349             ss = s->name;
1350         else
1351             ss = "[unknown]";
1352         found = 0;
1353         printf("Kerberos map for non-existant user %d to principal %s\n",
1354                id, s);
1355     }
1356     EXEC SQL CLOSE csr218; 
1357     return(found);
1358 }
1359
1360
1361 show_krb_str(id)
1362 int id;
1363 {
1364     EXEC SQL BEGIN DECLARE SECTION; 
1365     int iid = id, found = 1, id1;
1366     EXEC SQL END DECLARE SECTION; 
1367     struct user *u;
1368     char *s;
1369
1370     EXEC SQL DECLARE csr219 CURSOR FOR
1371         SELECT users_id FROM krbmap
1372             WHERE string_id = :iid;
1373     EXEC SQL OPEN csr219;
1374     while(1) {
1375         EXEC SQL FETCH csr219 INTO :id1;
1376         if (sqlca.sqlcode != 0) break; 
1377
1378         if (u = ((struct user *)hash_lookup(users, id1)))
1379             s = u->login;
1380         else
1381             s = "[\?\?\?]";
1382         found = 0;
1383         printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1384                s, id1, id);
1385         }
1386     EXEC SQL CLOSE csr219; 
1387     return(found);
1388 }
1389
1390
1391 show_pdm_mach(id)
1392 int id;
1393 {
1394     EXEC SQL BEGIN DECLARE SECTION; 
1395     char name[33];
1396     int iid = id;
1397     EXEC SQL END DECLARE SECTION; 
1398     int found = 1;
1399
1400     EXEC SQL DECLARE csr220 CURSOR FOR
1401         SELECT name FROM palladium
1402             WHERE mach_id = :iid;
1403     EXEC SQL OPEN csr220;
1404     while(1) {
1405         EXEC SQL FETCH csr220 INTO :name;
1406         if (sqlca.sqlcode != 0) break; 
1407
1408         strtrim(name);
1409         printf("Palladium server/supervisor %s is on non-existant machine %d\n",
1410                name, id);
1411         found = 0;
1412         }
1413     EXEC SQL CLOSE csr220; 
1414     return(found);
1415 }
1416
1417
1418 phase2()
1419 {
1420     EXEC SQL BEGIN DECLARE SECTION; 
1421     int id1, id2, id3, id4, id5;
1422     char type[9], name[33];
1423     EXEC SQL END DECLARE SECTION; 
1424     struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
1425     struct filesys *f;
1426     struct list *l;
1427     struct nfsphys *n;
1428     struct machine *m;
1429
1430     printf("Phase 2 - Checking references\n");
1431
1432     dprintf("Checking users...\n");
1433     hash_step(users, user_check, NULL);
1434
1435     dprintf("Checking machines...\n");
1436     hash_step(machines, mach_check, NULL);
1437
1438     dprintf("Checking subnets...\n");
1439     hash_step(subnets, subnet_check, NULL);
1440
1441     dprintf("Checking clusters...\n");
1442     hash_step(clusters, cluster_check, NULL);
1443
1444     dprintf("Checking mcmap...\n");
1445     sq1 = sq_create();
1446     sq2 = sq_create();
1447     EXEC SQL DECLARE csr221 CURSOR FOR
1448       SELECT mach_id, clu_id FROM mcmap;
1449     EXEC SQL OPEN csr221;
1450     while(1) {
1451         EXEC SQL FETCH csr221 INTO :id1, :id2;
1452         if (sqlca.sqlcode != 0) break; 
1453
1454         if (!(m = (struct machine *)hash_lookup(machines, id1)))
1455             sq_save_unique_data(sq1, id1);
1456         else if (!hash_lookup(clusters, id2))
1457             sq_save_unique_data(sq2, id2);
1458         if (m) m->clucount++;
1459     }
1460     EXEC SQL CLOSE csr221; 
1461     generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1462     generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1463
1464     dprintf("Checking service clusters...\n");
1465     sq1 = sq_create();
1466     EXEC SQL DECLARE csr222 CURSOR FOR
1467       SELECT clu_id FROM svc;
1468     EXEC SQL OPEN csr222;
1469     while(1) {
1470         EXEC SQL FETCH csr222 INTO :id1;
1471         if (sqlca.sqlcode != 0) break; 
1472
1473         if (!hash_lookup(clusters, id1))
1474           sq_save_unique_data(sq1, id1);
1475     }
1476     EXEC SQL CLOSE csr222; 
1477     generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1478
1479     dprintf("Checking lists...\n");
1480     hash_step(lists, list_check, NULL);
1481
1482     dprintf("Checking members...\n");
1483     sq1 = sq_create();
1484     sq2 = sq_create();
1485     sq3 = sq_create();
1486     sq4 = sq_create();
1487     sq5 = sq_create();
1488
1489     EXEC SQL DECLARE csr223 CURSOR FOR
1490       SELECT list_id, member_type, member_id, ref_count, direct
1491       FROM imembers FOR UPDATE OF member_id;
1492     EXEC SQL OPEN csr223;
1493     while(1) {
1494         EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
1495         if (sqlca.sqlcode != 0) break; 
1496
1497         if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
1498           sq_save_unique_data(sq1, id1);
1499         else if (type[0] == 'U' && !hash_lookup(users, id2))
1500           sq_save_unique_data(sq2, id2);
1501         else if (type[0] == 'L' && !hash_lookup(lists, id2))
1502           sq_save_unique_data(sq3, id2);
1503         else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
1504           sq_save_unique_data(sq4, id2);
1505         else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
1506           sq_save_unique_data(sq5, id2);
1507         else
1508           l->members++;
1509         }
1510     EXEC SQL CLOSE csr223; 
1511     generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1512     generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1513     generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1514     generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1515     generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1516
1517     dprintf("Checking servers...\n");
1518     sq1 = sq_create();
1519     sq2 = sq_create();
1520     EXEC SQL DECLARE csr224 CURSOR FOR
1521       SELECT name, acl_type, acl_id, modby FROM servers
1522       FOR UPDATE of modby;
1523     EXEC SQL OPEN csr224;
1524     while(1) {
1525         EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2;
1526         if (sqlca.sqlcode != 0) break; 
1527
1528         maybe_fixup_modby2("servers","modby","csr224",id2);
1529         strtrim(type);
1530         if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
1531             sq_save_data(sq1, id1);
1532         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
1533             sq_save_data(sq2, id1);
1534         }
1535     }
1536     EXEC SQL CLOSE csr224; 
1537     generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
1538     generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
1539
1540     dprintf("Checking serverhosts...\n");
1541     sq = sq_create();
1542     EXEC SQL DECLARE csr225 CURSOR FOR
1543       SELECT mach_id, modby FROM serverhosts
1544       FOR UPDATE OF modby;
1545     EXEC SQL OPEN csr225;
1546     while(1) {
1547         EXEC SQL FETCH csr225 INTO :id1, :id2;
1548         if (sqlca.sqlcode != 0) break; 
1549
1550         maybe_fixup_modby2("serverhosts", "modby", "csr225", id2);
1551         if (!hash_lookup(machines, id1))
1552           sq_save_data(sq, id1);
1553         }
1554     EXEC SQL CLOSE csr225; 
1555     generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1556
1557     dprintf("Checking nfsphys...\n");
1558     hash_step(nfsphys, check_nfsphys, NULL);
1559
1560     dprintf("Checking filesys...\n");
1561     hash_step(filesys, check_fs, NULL);
1562
1563     dprintf("Checking filesystem groups...\n");
1564     sq1 = sq_create();
1565     sq2 = sq_create();
1566     sq3 = sq_create();
1567     EXEC SQL DECLARE csr226 CURSOR FOR
1568       SELECT group_id, filsys_id FROM fsgroup;
1569     EXEC SQL OPEN csr226;
1570     while(1) {
1571         EXEC SQL FETCH csr226 INTO :id1, :id2;
1572         if (sqlca.sqlcode != 0) break; 
1573
1574         if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
1575           sq_save_data(sq1, id1);
1576         if (!hash_lookup(filesys, id2))
1577           sq_save_data(sq3, id2);
1578     }
1579     EXEC SQL CLOSE csr226; 
1580     generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
1581     generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
1582
1583     dprintf("Checking quotas...\n");
1584     sq1 = sq_create();
1585     sq2 = sq_create();
1586     sq3 = sq_create();
1587     sq4 = sq_create();
1588     EXEC SQL DECLARE csr227 CURSOR FOR
1589       SELECT entity_id, type, filsys_id, phys_id, quota, modby
1590       FROM quota FOR UPDATE OF modby;
1591     EXEC SQL OPEN csr227;
1592     while(1) {
1593         EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5;
1594         if (sqlca.sqlcode != 0) break; 
1595
1596         maybe_fixup_modby2("quota", "modby", "csr227", id5);
1597         if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
1598           sq_save_data(sq1, id1);
1599         else if (type[0] == 'G' && !hash_lookup(lists, id1))
1600           sq_save_data(sq4, id1);
1601         else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
1602           sq_save_data(sq2, id2);
1603         else if (id3 != f->phys_id ||
1604             ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) ==
1605             (struct nfsphys *)NULL))
1606           sq_save_data(sq3, id2);
1607         else
1608           n->count += id4;
1609     }
1610     EXEC SQL CLOSE csr227; 
1611     generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
1612     generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
1613     generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
1614     generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
1615
1616     dprintf("Not checking zephyr.\n");
1617
1618     dprintf("Checking hostaccess...\n");
1619     EXEC SQL DECLARE csr228 CURSOR FOR
1620       SELECT mach_id, acl_type, acl_id, modby FROM hostaccess
1621       FOR UPDATE OF modby;
1622     EXEC SQL OPEN csr228;
1623     while(1) {
1624         EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3;
1625         if (sqlca.sqlcode != 0) break; 
1626
1627         maybe_fixup_modby2("hostaccess", "modby", "csr228", id3);
1628         strtrim(type);
1629         if (!hash_lookup(machines, id1)) {
1630             printf("Hostaccess for non-existant host %d\n", id1);
1631             printf("Not fixing this error\n");
1632         }
1633         if (!strcmp(type, "USER") && !hash_lookup(users, id2)) {
1634             printf("Hostaccess for %d is non-existant user %d\n", id1, id2);
1635             printf("Not fixing this error\n");
1636         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) {
1637             printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
1638             printf("Not fixing this error\n");
1639         }
1640     }
1641     EXEC SQL CLOSE csr228; 
1642
1643     dprintf("Checking palladium...\n");
1644     sq1 = sq_create();
1645     EXEC SQL DECLARE csr229 CURSOR FOR
1646       SELECT mach_id, modby FROM palladium
1647       FOR UPDATE OF modby;
1648     EXEC SQL OPEN csr229;
1649     while(1) {
1650         EXEC SQL FETCH csr229 INTO :id1, :id2;
1651         if (sqlca.sqlcode != 0) break; 
1652
1653         maybe_fixup_modby2("palladium", "modby", "csr229", id2);
1654         if (!hash_lookup(machines, id1)) {
1655             sq_save_unique_data(sq1, id1);
1656         }
1657     }
1658     EXEC SQL CLOSE csr229;
1659     generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
1660
1661     dprintf("Checking krbmap...\n");
1662     sq1 = sq_create();
1663     sq2 = sq_create();
1664     EXEC SQL DECLARE csr230 CURSOR FOR
1665       SELECT users_id, string_id FROM krbmap
1666       FOR UPDATE OF string_id;
1667     EXEC SQL OPEN csr230;
1668     while(1) {
1669         EXEC SQL FETCH csr230 INTO :id1, :id2;
1670         if (sqlca.sqlcode != 0) break; 
1671
1672         if (!hash_lookup(users, id1))
1673           sq_save_unique_data(sq1, id1);
1674         else if (!maybe_fixup_unref_string2("krbmap","string_id","csr230",id2))
1675           sq_save_unique_data(sq2, id2);
1676         }
1677     EXEC SQL CLOSE csr230; 
1678     generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
1679     generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
1680
1681     dprintf("Checking capacls...\n");
1682     EXEC SQL DECLARE csr231 CURSOR FOR
1683       SELECT list_id, tag FROM capacls;
1684     EXEC SQL OPEN csr231;
1685     while(1) {
1686         EXEC SQL FETCH csr231 INTO :id1, :name;
1687         if (sqlca.sqlcode != 0) break; 
1688
1689         if (!hash_lookup(lists, id1)) {
1690             printf("Capacl for %s is non-existant list %d\n", name, id1);
1691             printf("Not fixing this error\n");
1692         }
1693     }
1694     EXEC SQL CLOSE csr231;
1695
1696     dprintf("Checking hostaliases\n");
1697     sq1 = sq_create();
1698     EXEC SQL DECLARE csr232 CURSOR FOR
1699       SELECT mach_id FROM hostalias;
1700     EXEC SQL OPEN csr232;
1701     while(1) {
1702         EXEC SQL FETCH csr232 INTO :id1;
1703         if (sqlca.sqlcode != 0) break; 
1704
1705         if (!hash_lookup(machines, id1))
1706           sq_save_unique_data(sq1, id1);
1707     }
1708     EXEC SQL CLOSE csr232;
1709     generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
1710     
1711     dprintf("Checking printcaps\n");
1712     sq1 = sq_create();
1713     sq2 = sq_create();
1714     EXEC SQL DECLARE csr233 CURSOR FOR
1715       SELECT mach_id, quotaserver, modby FROM printcap;
1716     EXEC SQL OPEN csr233;
1717     while(1) {
1718         EXEC SQL FETCH csr233 INTO :id1, :id2, :id3;
1719         if (sqlca.sqlcode != 0) break; 
1720
1721         maybe_fixup_modby2("printcap", "modby", "csr233", id3);
1722         if (!hash_lookup(machines, id1))
1723           sq_save_unique_data(sq1, id1);
1724         else if(!hash_lookup(machines, id2))
1725           sq_save_unique_data(sq2, id2);
1726     }
1727     EXEC SQL CLOSE csr233;
1728     generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1);
1729     generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1);
1730 }
This page took 0.191775 seconds and 5 git commands to generate.