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