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