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