]> andersk Git - moira.git/blob - dbck/phase2.pc
break out of case statement, don't fall through.
[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_printer_mach(void *id);
26 int show_printer_server(void *id);
27 int show_printer_loghost(void *id);
28 int show_printer_spool(void *id);
29 int show_printer_quota(void *id);
30 int show_printer_ac(void *id);
31 int show_printer_lpc_acl(void *id);
32 void fix_printer_ac(void *id);
33 void fix_printer_lpc_acl(void *id);
34 void user_check(int id, void *user, void *hint);
35 int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
36                              char *field, char *idfield);
37 int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
38                       char *field, char *idfield);
39 int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid);
40 int maybe_fixup_modby2(char *table, char *field, char *rowid, int id);
41 void pobox_check(int id, struct user *u);
42 void remove_pobox(int id);
43 void fix_smtp_pobox(int id, int sid);
44 void mach_check(int id, void *machine, void *hint);
45 void subnet_check(int id, void *subnet, void *hint);
46 void clear_subnet_owner(struct subnet *s);
47 void clear_mach_owner(struct machine *m);
48 void cluster_check(int id, void *cluster, void *hint);
49 int show_svc(void *id);
50 void list_check(int id, void *list, void *hint);
51 void fix_list_acl(int id);
52 void fix_list_memacl(int id);
53 int show_member_list(void *id);
54 int show_mem_user(void *id);
55 int show_mem_list(void *id);
56 int show_mem_str(void *id);
57 int show_mem_krb(void *id);
58 int show_mem_mach(void *id);
59 void del_mem_user(void *id);
60 void del_mem_list(void *id);
61 void del_mem_str(void *id);
62 void del_mem_krb(void *id);
63 void del_mem_mach(void *id);
64 int show_sh(void *id);
65 void del_sh_mach(void *id);
66 void fsmatch(int id, void *nfsphys, void *filesys);
67 void check_fs(int id, void *filesys, void *hint);
68 void check_nfsphys(int id, void *nfsphys, void *hint);
69 void check_ps(int id, void *printserver, void *hint);
70 int show_fsg_missing(void *id);
71 int show_fsg_type(void *filesys);
72 void fix_fsg_type(void *filesys);
73 int show_fsg_nomember(void *id);
74 int show_quota_nouser(void *id);
75 int show_quota_nolist(void *id);
76 void fix_quota_nouser(void *id);
77 void fix_quota_nolist(void *id);
78 int show_quota_nofs(void *id);
79 void fix_quota_nofs(void *id);
80 int show_quota_wrongpid(void *id);
81 void fix_quota_physid(void *id);
82 int show_srv_user(void *id);
83 int show_srv_list(void *id);
84 void zero_srv_user(void *id);
85 void zero_srv_list(void *id);
86 int show_krb_usr(void *id);
87 int show_krb_str(void *id);
88 int show_pdm_mach(void *id);
89
90 int show_mcm_mach(void *id)
91 {
92   EXEC SQL BEGIN DECLARE SECTION;
93   int iid = (int)id, found = 1;
94   char name[CLUSTERS_NAME_SIZE];
95   EXEC SQL END DECLARE SECTION;
96
97   EXEC SQL DECLARE csr201 CURSOR FOR
98     SELECT clusters.name FROM clusters, mcmap
99     WHERE clusters.clu_id = mcmap.clu_id AND mcmap.mach_id = :iid;
100   EXEC SQL OPEN csr201;
101   while (1)
102     {
103       EXEC SQL FETCH csr201 INTO :name;
104       if (sqlca.sqlcode)
105         break;
106
107       strtrim(name);
108       found = 0;
109       printf("Cluster %s, non-existant machine %d in cluster map\n",
110              name, iid);
111     }
112   EXEC SQL CLOSE csr201;
113   return found;
114 }
115
116 int show_mcm_clu(void *id)
117 {
118   EXEC SQL BEGIN DECLARE SECTION;
119   int iid = (int)id, found = 1;
120   char name[MACHINE_NAME_SIZE];
121   EXEC SQL END DECLARE SECTION;
122
123   EXEC SQL DECLARE csr202 CURSOR FOR
124     SELECT machine.name FROM machine, mcmap
125     WHERE machine.mach_id = mcmap.mach_id AND mcmap.clu_id = :iid;
126   EXEC SQL OPEN csr202;
127   while (1)
128     {
129       EXEC SQL FETCH csr202 INTO :name;
130       if (sqlca.sqlcode)
131         break;
132
133       strtrim(name);
134
135       found = 0;
136       printf("Machine %s, non-existant cluster %d in cluster map\n",
137              name, iid);
138     }
139   EXEC SQL CLOSE csr202;
140   return found;
141 }
142
143 int show_hostalias(void *id)
144 {
145   EXEC SQL BEGIN DECLARE SECTION;
146   int iid = (int)id, found = 1;
147   char name[HOSTALIAS_NAME_SIZE];
148   EXEC SQL END DECLARE SECTION;
149
150   EXEC SQL DECLARE csr234 CURSOR FOR
151     SELECT name FROM hostalias WHERE mach_id = :iid;
152   EXEC SQL OPEN csr234;
153   while (1)
154     {
155       EXEC SQL FETCH csr234 INTO :name;
156       if (sqlca.sqlcode)
157         break;
158
159       strtrim(name);
160
161       found = 0;
162       printf("Alias %s, non-existant machine %d in hostalias map\n",
163              name, iid);
164     }
165   EXEC SQL CLOSE csr234;
166   return found;
167 }
168
169 int show_printer_mach(void *id)
170 {
171   EXEC SQL BEGIN DECLARE SECTION;
172   int iid = (int)id, found = 1;
173   char name[PRINTERS_NAME_SIZE];
174   EXEC SQL END DECLARE SECTION;
175
176   EXEC SQL DECLARE csr235 CURSOR FOR
177     SELECT name FROM printers WHERE mach_id = :iid;
178   EXEC SQL OPEN csr235;
179   while (1)
180     {
181       EXEC SQL FETCH csr235 INTO :name;
182       if (sqlca.sqlcode)
183         break;
184
185       strtrim(name);
186
187       found = 0;
188       printf("Printer %s, non-existant machine %d in printers table\n",
189              name, iid);
190     }
191   EXEC SQL CLOSE csr235;
192   return found;
193 }
194
195 int show_printer_server(void *id)
196 {
197   EXEC SQL BEGIN DECLARE SECTION;
198   int iid = (int)id, found = 1;
199   char name[PRINTERS_NAME_SIZE];
200   EXEC SQL END DECLARE SECTION;
201
202   EXEC SQL DECLARE csr_sps CURSOR FOR
203     SELECT name FROM printers WHERE mach_id = :iid;
204   EXEC SQL OPEN csr_sps;
205   while (1)
206     {
207       EXEC SQL FETCH csr_sps INTO :name;
208       if (sqlca.sqlcode)
209         break;
210
211       strtrim(name);
212
213       found = 0;
214       printf("Printer %s, non-existant printserver %d in printers table\n",
215              name, iid);
216     }
217   EXEC SQL CLOSE csr_sps;
218   return found;
219 }
220
221 int show_printer_loghost(void *id)
222 {
223   EXEC SQL BEGIN DECLARE SECTION;
224   int iid = (int)id, found = 1;
225   char name[PRINTERS_NAME_SIZE];
226   EXEC SQL END DECLARE SECTION;
227
228   EXEC SQL DECLARE csr236 CURSOR FOR
229     SELECT name FROM printers WHERE loghost = :iid;
230   EXEC SQL OPEN csr236;
231   while (1)
232     {
233       EXEC SQL FETCH csr236 INTO :name;
234       if (sqlca.sqlcode)
235         break;
236
237       strtrim(name);
238
239       found = 0;
240       printf("Printer %s, non-existant spool machine %d in printers table\n",
241              name, iid);
242     }
243   EXEC SQL CLOSE csr236;
244   return found;
245 }
246
247 int show_printer_spool(void *id)
248 {
249   EXEC SQL BEGIN DECLARE SECTION;
250   int iid = (int)id, found = 1;
251   char name[PRINTERS_NAME_SIZE];
252   EXEC SQL END DECLARE SECTION;
253
254   EXEC SQL DECLARE csr237 CURSOR FOR
255     SELECT name FROM printers WHERE rm = :iid;
256   EXEC SQL OPEN csr237;
257   while (1)
258     {
259       EXEC SQL FETCH csr237 INTO :name;
260       if (sqlca.sqlcode)
261         break;
262
263       strtrim(name);
264
265       found = 0;
266       printf("Printer %s, non-existant spool machine %d in printers table\n",
267              name, iid);
268     }
269   EXEC SQL CLOSE csr237;
270   return found;
271 }
272
273 int show_printer_quota(void *id)
274 {
275   EXEC SQL BEGIN DECLARE SECTION;
276   int iid = (int)id, found = 1;
277   char name[PRINTERS_NAME_SIZE];
278   EXEC SQL END DECLARE SECTION;
279
280   EXEC SQL DECLARE csr238 CURSOR FOR
281     SELECT name FROM printers WHERE rq = :iid;
282   EXEC SQL OPEN csr238;
283   while (1)
284     {
285       EXEC SQL FETCH csr238 INTO :name;
286       if (sqlca.sqlcode)
287         break;
288
289       strtrim(name);
290
291       found = 0;
292       printf("Printer %s, non-existant quota server %d in printers table\n",
293              name, iid);
294     }
295   EXEC SQL CLOSE csr238;
296   return found;
297 }
298
299 int show_printer_ac(void *id)
300 {
301   EXEC SQL BEGIN DECLARE SECTION;
302   int iid = (int)id, found = 1;
303   char name[PRINTERS_NAME_SIZE];
304   EXEC SQL END DECLARE SECTION;
305
306   EXEC SQL DECLARE csr239 CURSOR FOR
307     SELECT name FROM printers WHERE ac = :iid;
308   EXEC SQL OPEN csr239;
309   while (1)
310     {
311       EXEC SQL FETCH csr239 INTO :name;
312       if (sqlca.sqlcode)
313         break;
314
315       strtrim(name);
316
317       found = 0;
318       printf("Printer %s, non-existant restrict list %d in printers table\n",
319              name, iid);
320     }
321   EXEC SQL CLOSE csr239;
322   return found;
323 }
324
325 int show_printer_lpc_acl(void *id)
326 {
327   EXEC SQL BEGIN DECLARE SECTION;
328   int iid = (int)id, found = 1;
329   char name[PRINTERS_NAME_SIZE];
330   EXEC SQL END DECLARE SECTION;
331
332   EXEC SQL DECLARE csr240 CURSOR FOR
333     SELECT name FROM printers WHERE lpc_acl = :iid;
334   EXEC SQL OPEN csr240;
335   while (1)
336     {
337       EXEC SQL FETCH csr240 INTO :name;
338       if (sqlca.sqlcode)
339         break;
340
341       strtrim(name);
342
343       found = 0;
344       printf("Printer %s, non-existant lpc ACL %d in printers table\n",
345              name, iid);
346     }
347   EXEC SQL CLOSE csr240;
348   return found;
349 }
350
351 void fix_printer_ac(void *id)
352 {
353   EXEC SQL BEGIN DECLARE SECTION;
354   int rowcount, iid = (int)id;
355   EXEC SQL END DECLARE SECTION;
356
357   EXEC SQL UPDATE printers SET ac = 0 WHERE ac = :iid;
358   rowcount = sqlca.sqlerrd[2];
359   if (rowcount > 0)
360     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
361   else
362     printf("Not fixed\n");
363   modified("printers");
364 }
365
366 void fix_printer_lpc_acl(void *id)
367 {
368   EXEC SQL BEGIN DECLARE SECTION;
369   int rowcount, iid = (int)id;
370   EXEC SQL END DECLARE SECTION;
371
372   EXEC SQL UPDATE printers SET lpc_acl = 0 WHERE lpc_acl = :iid;
373   rowcount = sqlca.sqlerrd[2];
374   if (rowcount > 0)
375     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
376   else
377     printf("Not fixed\n");
378   modified("printers");
379 }
380
381 void user_check(int id, void *user, void *hint)
382 {
383   struct user *u = user;
384
385   u->comment = maybe_fixup_unref_string(u->comment, id, u->login, "users",
386                                         "comments", "users_id");
387
388   u->modby = maybe_fixup_modby(u->modby, id, u->login, "users",
389                                "modby", "users_id");
390
391   u->fmodby = maybe_fixup_modby(u->fmodby, id, u->login, "users",
392                                 "fmodby", "users_id");
393
394   u->pmodby = maybe_fixup_modby(u->pmodby, id, u->login, "users",
395                                 "pmodby", "users_id");
396
397   u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
398                                        "sigwho", "users_id");
399
400   pobox_check(id, u);
401 }
402
403 int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
404                              char *field, char *idfield)
405 {
406   int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
407   EXEC SQL BEGIN DECLARE SECTION;
408   int rowcount;
409   char stmt_buf[500];
410   EXEC SQL END DECLARE SECTION;
411
412   if ((newid = (int)hash_lookup(string_dups, ret)))
413     {
414       printf("%s entry %s(%d) has a %s with duplicate string %d\n",
415              table, oname, oid, field, ret);
416       if (single_fix("Replace duplicate", 0))
417         {
418           ret = newid;
419           doit = 1;
420         }
421       string_check(ret);
422     }
423   else if (!string_check(ret))
424     {
425       printf("%s entry %s(%d) has a %s with non-existant string %d\n",
426              table, oname, oid, field, ret);
427       if (single_fix("Delete", 1))
428         {
429           ret = 0;
430           doit = 1;
431         }
432     }
433
434   if (doit)
435     {
436       sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d",
437               table, field, (sid < 0) ? -ret : ret, idfield, oid);
438       EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
439       rowcount = sqlca.sqlerrd[2];
440       if (rowcount == 1)
441         printf("Fixed\n");
442       else
443         printf("Not fixed, rowcount = %d\n", rowcount);
444       modified(table);
445     }
446
447   return (sid < 0) ? -ret : ret;
448 }
449
450 int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
451                       char *field, char *idfield)
452 {
453   EXEC SQL BEGIN DECLARE SECTION;
454   char stmt_buf[500];
455   int rowcount;
456   EXEC SQL END DECLARE SECTION;
457
458   if (sid < 0)
459     return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
460   else
461     {
462       if (!hash_lookup(users, sid))
463         {
464           printf("%s entry %s(%d) has a %s with non-existant user %d\n",
465                  table, oname, oid, field, sid);
466           if (single_fix("Delete", 1))
467             {
468               sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d",
469                       table, field, idfield, oid);
470               EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
471               rowcount = sqlca.sqlerrd[2];
472               if (rowcount == 1)
473                 printf("Fixed\n");
474               else
475                 printf("Not fixed, rowcount = %d\n", rowcount);
476               modified(table);
477             }
478           return 0;
479         }
480     }
481   return sid;
482 }
483
484 int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid)
485 {
486   int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
487   EXEC SQL BEGIN DECLARE SECTION;
488   int rowcount;
489   char stmt_buf[500];
490   EXEC SQL END DECLARE SECTION;
491
492   if ((newid = (int)hash_lookup(string_dups, ret)))
493     {
494       printf("%s entry has a %s with duplicate string %d\n",
495              table, field, ret);
496       if (single_fix("Replace duplicate", 0))
497         {
498           ret = newid;
499           doit = 1;
500         }
501       string_check(ret);
502     }
503   else if (!string_check(ret))
504     {
505       printf("%s entry has a %s with non-existant string %d\n",
506              table, field, ret);
507       if (single_fix("Clear", 1))
508         {
509           ret = 0;
510           doit = 1;
511         }
512     }
513
514   if (doit)
515     {
516       sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE rowid = '%s'",
517               table, field, (sid < 0) ? -ret : ret, rowid);
518       EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
519       rowcount = sqlca.sqlerrd[2];
520       if (rowcount == 1)
521         printf("Fixed\n");
522       else
523         printf("Not fixed, rowcount = %d\n", rowcount);
524       modified(table);
525     }
526   return (sid < 0) ? -ret : ret;
527 }
528
529 int maybe_fixup_modby2(char *table, char *field, char *rowid, int id)
530 {
531   EXEC SQL BEGIN DECLARE SECTION;
532   char stmt_buf[500];
533   int rowcount;
534   EXEC SQL END DECLARE SECTION;
535
536   if (id < 0)
537     return maybe_fixup_unref_string2(table, field, rowid, id);
538   else
539     {
540       if (!hash_lookup(users, id))
541         {
542           printf("%s entry has a %s with non-existant user %d\n",
543                  table, field, id);
544           if (single_fix("Clear", 1))
545             {
546               sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE rowid = '%s'",
547                       table, field, rowid);
548               EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
549               rowcount = sqlca.sqlerrd[2];
550               if (rowcount == 1)
551                 printf("Fixed\n");
552               else
553                 printf("Not fixed, rowcount = %d\n", rowcount);
554               modified(table);
555             }
556           return 0;
557         }
558     }
559   return 1;
560 }
561
562 void pobox_check(int id, struct user *u)
563 {
564   struct filesys *fs;
565
566   switch (u->potype)
567     {
568     case 'P':
569       if (!hash_lookup(machines, u->pobox_id))
570         {
571           printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
572                  u->login, u->fullname, u->pobox_id);
573           if (single_fix("Delete", 0))
574             {
575               remove_pobox(u->users_id);
576               u->potype = 'N';
577             }
578         }
579       break;
580
581     case 'S':
582       if (hash_lookup(string_dups, u->pobox_id))
583         {
584           printf("User %s(%s) has P.O.Box with duplicate string %d\n",
585                  u->login, u->fullname, u->pobox_id);
586           if (single_fix("Update", 0))
587             {
588               printf("Replacing box_id dup string ID %d with %d\n",
589                      u->pobox_id,
590                      (int)hash_lookup(string_dups, u->pobox_id));
591               u->pobox_id = (int)hash_lookup(string_dups, u->pobox_id);
592               fix_smtp_pobox(u->users_id, u->pobox_id);
593               string_check(u->pobox_id);
594             }
595         }
596       else if (!string_check(u->pobox_id))
597         {
598           printf("User %s(%s) has P.O.Box with non-existant string %d\n",
599                  u->login, u->fullname, u->pobox_id);
600           if (single_fix("Delete", 0))
601             {
602               remove_pobox(u->users_id);
603               u->potype = 'N';
604             }
605         }
606       break;
607
608     case 'I':
609       fs = hash_lookup(filesys, u->pobox_id);
610       if (!fs)
611         {
612           printf("User %s(%s) has P.O.Box on non-existant filesystem %d\n",
613                  u->login, u->fullname, u->pobox_id);
614           if (single_fix("Delete", 0))
615             {
616               remove_pobox(u->users_id);
617               u->potype = 'N';
618             }
619         }
620       else if (fs->type != 'I')
621         {
622           printf("User %s(%s) has IMAP P.O.Box on non-IMAP filesystem %s\n",
623                  u->login, u->fullname, fs->name);
624           if (single_fix("Delete", 0))
625             {
626               remove_pobox(u->users_id);
627               u->potype = 'N';
628             }
629         }
630       break;
631
632     default:
633       ;
634     }
635 }
636
637
638 void remove_pobox(int id)
639 {
640   EXEC SQL BEGIN DECLARE SECTION;
641   int rowcount, iid = (int)id;
642   EXEC SQL END DECLARE SECTION;
643
644   EXEC SQL UPDATE users SET potype = 'NONE' WHERE users.users_id = :iid;
645   rowcount = sqlca.sqlerrd[2];
646   if (rowcount > 0)
647     printf("%d entr%s removed\n", rowcount, rowcount == 1 ? "y" : "ies");
648   else
649     printf("Not removed\n");
650   modified("users");
651 }
652
653 void fix_smtp_pobox(int id, int sid)
654 {
655   EXEC SQL BEGIN DECLARE SECTION;
656   int rowcount, iid = id, isid = sid;
657   EXEC SQL END DECLARE SECTION;
658
659   EXEC SQL UPDATE users SET box_id = :isid WHERE users.users_id = :iid;
660   rowcount = sqlca.sqlerrd[2];
661   if (rowcount > 0)
662     printf("%d entr%s updated\n", rowcount, rowcount == 1 ? "y" : "ies");
663   else
664     printf("Not updated\n");
665   modified("users");
666 }
667
668 void mach_check(int id, void *machine, void *hint)
669 {
670   struct machine *m = machine;
671
672   if (!hash_lookup(subnets, m->snet_id))
673     {
674       printf("Machine %s is on a non-existant subnet %d\n",
675              m->name, m->snet_id);
676       if (single_fix("Move to null-subnet", 1))
677         {
678           EXEC SQL BEGIN DECLARE SECTION;
679           int rowcount, iid = id;
680           EXEC SQL END DECLARE SECTION;
681
682           EXEC SQL UPDATE machine SET snet_id = 0 WHERE mach_id = :iid;
683           rowcount = sqlca.sqlerrd[2];
684           if (rowcount > 0)
685             printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
686           else
687             printf("Not fixed\n");
688           modified("machine");
689         }
690     }
691
692   switch (m->owner_type)
693     {
694     case 'U':
695       if (!hash_lookup(users, m->owner_id))
696         {
697           printf("Machine %s has non-existant USER owner %d\n",
698                  m->name, m->owner_id);
699           if (single_fix("Set to no owner", 1))
700             clear_mach_owner(m);
701         }
702       break;
703     case 'L':
704       if (!hash_lookup(lists, m->owner_id))
705         {
706           printf("Machine %s has non-existant LIST owner %d\n",
707                  m->name, m->owner_id);
708           if (single_fix("Set to no owner", 1))
709             clear_mach_owner(m);
710         }
711       break;
712     case 'S':
713     case 'K':
714       if (m->owner_id)
715         m->owner_id = maybe_fixup_unref_string(m->owner_id, id, m->name,
716                                                "machine", "owner_id",
717                                                "mach_id");
718       if (m->owner_id == 0)
719         clear_mach_owner(m);
720     }
721
722   if (m->acomment)
723     m->acomment = maybe_fixup_unref_string(m->acomment, id, m->name,
724                                            "machine", "acomment", "mach_id");
725   if (m->ocomment)
726     m->ocomment = maybe_fixup_unref_string(m->ocomment, id, m->name,
727                                            "machine", "ocomment", "mach_id");
728
729   m->creator = maybe_fixup_modby(m->creator, id, m->name, "machine",
730                                  "creator", "mach_id");
731   m->modby = maybe_fixup_modby(m->modby, id, m->name, "machine",
732                                "modby", "mach_id");
733 }
734
735 void subnet_check(int id, void *subnet, void *hint)
736 {
737   struct subnet *s = subnet;
738
739   switch (s->owner_type)
740     {
741     case 'U':
742       if (!hash_lookup(users, s->owner_id))
743         {
744           printf("Subnet %s has non-existant USER owner %d\n",
745                  s->name, s->owner_id);
746           if (single_fix("Set to no owner", 1))
747             clear_subnet_owner(s);
748         }
749       break;
750     case 'L':
751       if (!hash_lookup(lists, s->owner_id))
752         {
753           printf("Machine %s has non-existant LIST owner %d\n",
754                  s->name, s->owner_id);
755           if (single_fix("Set to no owner", 1))
756             clear_subnet_owner(s);
757         }
758       break;
759     case 'S':
760     case 'K':
761       if (s->owner_id)
762         s->owner_id = maybe_fixup_unref_string(s->owner_id, id, s->name,
763                                                "machine", "owner_id",
764                                                "mach_id");
765       if (s->owner_id == 0)
766         clear_subnet_owner(s);
767     }
768
769   s->modby = maybe_fixup_modby(s->modby, id, s->name, "subnet",
770                                "modby", "snet_id");
771 }
772
773 void clear_subnet_owner(struct subnet *s)
774 {
775   EXEC SQL BEGIN DECLARE SECTION;
776   int rowcount, id = s->snet_id;
777   EXEC SQL END DECLARE SECTION;
778
779   EXEC SQL UPDATE subnet SET owner_type = 'NONE', owner_id = 0
780     WHERE snet_id = :id;
781   rowcount = sqlca.sqlerrd[2];
782   if (rowcount > 0)
783     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
784   else
785     printf("Not fixed\n");
786   modified("subnet");
787 }
788
789 void clear_mach_owner(struct machine *m)
790 {
791   EXEC SQL BEGIN DECLARE SECTION;
792   int rowcount, id = m->mach_id;
793   EXEC SQL END DECLARE SECTION;
794
795   EXEC SQL UPDATE machine SET owner_type = 'NONE', owner_id = 0
796     WHERE mach_id = :id;
797   rowcount = sqlca.sqlerrd[2];
798   if (rowcount > 0)
799     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
800   else
801     printf("Not fixed\n");
802   modified("machine");
803 }
804
805 void cluster_check(int id, void *cluster, void *hint)
806 {
807   struct cluster *c = cluster;
808
809   c->modby = maybe_fixup_modby(c->modby, id, c->name, "clusters",
810                                "modby", "clu_id");
811 }
812
813 int show_svc(void *id)
814 {
815   EXEC SQL BEGIN DECLARE SECTION;
816   int iid = (int)id, found = 1;
817   char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
818   EXEC SQL END DECLARE SECTION;
819
820   EXEC SQL DECLARE csr203 CURSOR FOR
821     SELECT serv_label, serv_cluster FROM svc
822     WHERE clu_id = :iid;
823   EXEC SQL OPEN csr203;
824   while (1)
825     {
826       EXEC SQL FETCH csr203 INTO :label, :data;
827       if (sqlca.sqlcode)
828         break;
829
830       strtrim(label);
831       strtrim(data);
832       found = 0;
833       printf("Cluster data [%s] %s for non-existant cluster %d\n",
834              label, data, iid);
835     }
836   EXEC SQL CLOSE csr203;
837   return found;
838 }
839
840 void list_check(int id, void *list, void *hint)
841 {
842   struct list *l = list;
843
844   l->modby = maybe_fixup_modby(l->modby, id, l->name, "list",
845                                "modby", "list_id");
846
847   switch (l->acl_type)
848     {
849     case 'L':
850       if (!hash_lookup(lists, l->acl_id))
851         {
852           printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
853           if (single_fix("Patch", 1))
854             fix_list_acl(l->list_id);
855         }
856       break;
857     case 'U':
858       if (!hash_lookup(users, l->acl_id))
859         {
860           printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
861           if (single_fix("Patch", 1))
862             fix_list_acl(l->list_id);
863         }
864       break;
865     case 'K':
866       l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
867                                            "list", "acl_id", "list_id");
868       if (!l->acl_id)
869         {
870           printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id);
871           if (single_fix("Patch", 1))
872             fix_list_acl(l->list_id);
873         }
874       break;
875     }
876
877   switch (l->memacl_type)
878     {
879     case 'L':
880       if (!hash_lookup(lists, l->memacl_id))
881         {
882           printf("List %s has bad LIST memacl %d\n", l->name, l->memacl_id);
883           if (single_fix("Patch", 1))
884             fix_list_memacl(l->list_id);
885         }
886       break;
887     case 'U':
888       if (!hash_lookup(users, l->memacl_id))
889         {
890           printf("List %s has bad USER acl %d\n", l->name, l->memacl_id);
891           if (single_fix("Patch", 1))
892             fix_list_memacl(l->list_id);
893         }
894       break;
895     case 'K':
896       l->memacl_id = maybe_fixup_unref_string(l->memacl_id, id, l->name,
897                                               "list", "memacl_id", "list_id");
898           if (!l->memacl_id)
899             {
900               printf("List %s has bad KERBEROS acl %d\n", l->name, 
901                      l->memacl_id);
902               if (single_fix("Patch", 1))
903                 fix_list_memacl(l->list_id);
904             }
905           break;
906     }
907 }
908
909 void fix_list_acl(int id)
910 {
911   EXEC SQL BEGIN DECLARE SECTION;
912   int rowcount, iid = (int)id;
913   EXEC SQL END DECLARE SECTION;
914
915   EXEC SQL UPDATE list SET acl_id = :iid, acl_type = 'LIST'
916     WHERE list_id = :iid;
917   rowcount = sqlca.sqlerrd[2];
918   if (rowcount > 0)
919     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
920   else
921     printf("Not fixed\n");
922   modified("list");
923 }
924
925 void fix_list_memacl(int id)
926 {
927   EXEC SQL BEGIN DECLARE SECTION;
928   int rowcount, iid = (int)id;
929   EXEC SQL END DECLARE SECTION;
930
931   EXEC SQL UPDATE list SET memacl_id = 0, memacl_type = 'NONE'
932     WHERE list_id = :iid;
933   rowcount = sqlca.sqlerrd[2];
934   if (rowcount > 0)
935     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
936   else
937     printf("Not fixed\n");
938   modified("list");
939 }
940
941 int show_member_list(void *id)
942 {
943   EXEC SQL BEGIN DECLARE SECTION;
944   int mid, iid = (int)id, found = 1;
945   char mtype[IMEMBERS_MEMBER_TYPE_SIZE], *name = NULL;
946   EXEC SQL END DECLARE SECTION;
947
948   EXEC SQL DECLARE csr204 CURSOR FOR
949     SELECT member_type, member_id FROM imembers
950     WHERE list_id = :iid;
951   EXEC SQL OPEN csr204;
952   while (1)
953     {
954       EXEC SQL FETCH csr204 INTO :mtype, :mid;
955       if (sqlca.sqlcode)
956         break;
957
958       strtrim(mtype);
959       found = 0;
960       if (mtype[0] == 'L')
961         {
962           struct list *l = hash_lookup(lists, mid);
963           if (l)
964             name = l->name;
965         }
966       else if (mtype[0] == 'U')
967         {
968           struct user *u = hash_lookup(users, mid);
969           if (u)
970             name = u->login;
971         }
972       else if (mtype[0] == 'S' || mtype[0] == 'K')
973         {
974           struct string *s = hash_lookup(strings, mid);
975           if (s)
976             name = s->name;
977         }
978       if (name)
979         printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
980       else
981         {
982           printf("Non-existant list %d has non-existent member %s %d\n",
983                  iid, mtype, mid);
984         }
985     }
986   EXEC SQL CLOSE csr204;
987   return found;
988 }
989
990 int show_mem_user(void *id)
991 {
992   EXEC SQL BEGIN DECLARE SECTION;
993   int lid, iid = (int)id, found = 1;
994   EXEC SQL END DECLARE SECTION;
995   struct list *l;
996
997   EXEC SQL DECLARE csr205 CURSOR FOR
998     SELECT list_id FROM imembers
999     WHERE member_id = :iid AND member_type = 'USER';
1000   EXEC SQL OPEN csr205;
1001   while (1)
1002     {
1003       EXEC SQL FETCH csr205 INTO :lid;
1004       if (sqlca.sqlcode)
1005         break;
1006       l = hash_lookup(lists, lid);
1007       if (!l)
1008         continue;
1009
1010       found = 0;
1011       printf("List %s has non-existant user member, id %d\n", l->name, iid);
1012     }
1013   EXEC SQL CLOSE csr205;
1014   return found;
1015 }
1016
1017 int show_mem_list(void *id)
1018 {
1019   EXEC SQL BEGIN DECLARE SECTION;
1020   int lid, iid = (int)id, found = 1;
1021   EXEC SQL END DECLARE SECTION;
1022   struct list *l;
1023
1024   EXEC SQL DECLARE csr206 CURSOR FOR
1025     SELECT list_id FROM imembers
1026     WHERE member_id = :iid AND member_type = 'LIST';
1027   EXEC SQL OPEN csr206;
1028   while (1)
1029     {
1030       EXEC SQL FETCH csr206 INTO :lid;
1031       if (sqlca.sqlcode)
1032         break;
1033       l = hash_lookup(lists, lid);
1034       if (!l)
1035         continue;
1036
1037       found = 0;
1038       printf("List %s has non-existant list member, id %d\n", l->name, iid);
1039     }
1040   EXEC SQL CLOSE csr206;
1041   return found;
1042 }
1043
1044 int show_mem_str(void *id)
1045 {
1046   EXEC SQL BEGIN DECLARE SECTION;
1047   int lid, iid = (int)id, found = 1;
1048   EXEC SQL END DECLARE SECTION;
1049   struct list *l;
1050
1051   EXEC SQL DECLARE csr207 CURSOR FOR
1052     SELECT list_id FROM imembers
1053     WHERE member_id = :iid AND member_type = 'STRING';
1054   EXEC SQL OPEN csr207;
1055   while (1)
1056     {
1057       EXEC SQL FETCH csr207 INTO :lid;
1058       if (sqlca.sqlcode)
1059         break;
1060       l = hash_lookup(lists, lid);
1061       if (!l)
1062         continue;
1063
1064       found = 0;
1065       printf("List %s has non-existant string member, id %d\n", l->name, iid);
1066     }
1067   EXEC SQL CLOSE csr207;
1068   return found;
1069 }
1070
1071
1072 int show_mem_krb(void *id)
1073 {
1074   EXEC SQL BEGIN DECLARE SECTION;
1075   int lid, iid = (int)id, found = 1;
1076   EXEC SQL END DECLARE SECTION;
1077   struct list *l;
1078
1079   EXEC SQL DECLARE csr208 CURSOR FOR
1080     SELECT list_id FROM imembers
1081     WHERE member_id = :iid AND member_type = 'KERBEROS';
1082   EXEC SQL OPEN csr208;
1083   while (1)
1084     {
1085       EXEC SQL FETCH csr208 INTO :lid;
1086       if (sqlca.sqlcode)
1087         break;
1088       l = hash_lookup(lists, lid);
1089       if (!l)
1090         continue;
1091
1092       found = 0;
1093       printf("List %s has non-existant kerberos member, id %d\n",
1094              l->name, iid);
1095     }
1096   EXEC SQL CLOSE csr208;
1097   return found;
1098 }
1099
1100 int show_mem_mach(void *id)
1101 {
1102   EXEC SQL BEGIN DECLARE SECTION;
1103   int lid, iid = (int)id, found = 1;
1104   EXEC SQL END DECLARE SECTION;
1105   struct list *l; 
1106
1107   EXEC SQL DECLARE csr208a CURSOR FOR
1108     SELECT list_id FROM imembers
1109     WHERE member_id = :iid AND member_type = 'MACHINE';
1110   EXEC SQL OPEN csr208a;
1111   while (1)
1112     {
1113       EXEC SQL FETCH csr208a INTO :lid;
1114       if (sqlca.sqlcode)
1115         break;
1116       l = hash_lookup(lists, lid);
1117       if (!l)
1118         continue;
1119
1120       found = 0;
1121       printf("List %s has nonexistant machine member, id %d\n",
1122              l->name, iid);
1123     }
1124   EXEC SQL CLOSE csr208a;
1125   return found;
1126 }
1127
1128 void del_mem_user(void *id)
1129 {
1130   EXEC SQL BEGIN DECLARE SECTION;
1131   int iid = (int)id, rowcount;
1132   EXEC SQL END DECLARE SECTION;
1133
1134   EXEC SQL DELETE FROM imembers WHERE member_type = 'USER' AND
1135     member_id = :iid;
1136   rowcount = sqlca.sqlerrd[2];
1137   if (rowcount > 0)
1138     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1139   else
1140     printf("Not deleted\n");
1141   modified("imembers");
1142 }
1143
1144 void del_mem_list(void *id)
1145 {
1146   EXEC SQL BEGIN DECLARE SECTION;
1147   int iid = (int)id, rowcount;
1148   EXEC SQL END DECLARE SECTION;
1149
1150   EXEC SQL DELETE FROM imembers WHERE member_type = 'LIST' AND
1151     member_id = :iid;
1152   rowcount = sqlca.sqlerrd[2];
1153   if (rowcount > 0)
1154     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1155   else
1156     printf("Not deleted\n");
1157   modified("imembers");
1158 }
1159
1160 void del_mem_str(void *id)
1161 {
1162   EXEC SQL BEGIN DECLARE SECTION;
1163   int iid = (int)id, rowcount;
1164   EXEC SQL END DECLARE SECTION;
1165
1166   EXEC SQL DELETE FROM imembers WHERE member_type = 'STRING' AND
1167     member_id = :iid;
1168   rowcount = sqlca.sqlerrd[2];
1169   if (rowcount > 0)
1170     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1171   else
1172     printf("Not deleted\n");
1173   modified("imembers");
1174 }
1175
1176
1177 void del_mem_krb(void *id)
1178 {
1179   EXEC SQL BEGIN DECLARE SECTION;
1180   int iid = (int)id, rowcount;
1181   EXEC SQL END DECLARE SECTION;
1182
1183   EXEC SQL DELETE FROM imembers WHERE member_type = 'KERBEROS' AND
1184     member_id = :iid;
1185   rowcount = sqlca.sqlerrd[2];
1186   if (rowcount > 0)
1187     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1188   else
1189     printf("Not deleted\n");
1190   modified("imembers");
1191 }
1192
1193 void del_mem_mach(void *id)
1194 {
1195   EXEC SQL BEGIN DECLARE SECTION;
1196   int iid = (int)id, rowcount;
1197   EXEC SQL END DECLARE SECTION;
1198
1199   EXEC SQL DELETE FROM imembers WHERE member_type = 'MACHINE' AND
1200     member_id = :iid;
1201   rowcount = sqlca.sqlerrd[2];
1202   if (rowcount > 0)
1203     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1204   else
1205     printf("Not deleted\n");
1206   modified("imembers");
1207 }
1208
1209 int show_sh(void *id)
1210 {
1211   EXEC SQL BEGIN DECLARE SECTION;
1212   char name[SERVERHOSTS_SERVICE_SIZE];
1213   int iid = (int)id;
1214   EXEC SQL END DECLARE SECTION;
1215   int found = 1;
1216
1217   EXEC SQL DECLARE csr209 CURSOR FOR
1218     SELECT service FROM serverhosts
1219     WHERE mach_id = :iid;
1220   EXEC SQL OPEN csr209;
1221   while (1)
1222     {
1223       EXEC SQL FETCH csr209 INTO :name;
1224       if (sqlca.sqlcode)
1225         break;
1226
1227       found = 0;
1228       printf("ServerHost entry for service %s non-existant host %d\n",
1229              name, iid);
1230     }
1231   EXEC SQL CLOSE csr209;
1232   return found;
1233 }
1234
1235 void del_sh_mach(void *id)
1236 {
1237   EXEC SQL BEGIN DECLARE SECTION;
1238   int iid = (int)id, rowcount;
1239   EXEC SQL END DECLARE SECTION;
1240
1241   EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
1242   rowcount = sqlca.sqlerrd[2];
1243   if (rowcount > 0)
1244     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1245   else
1246     printf("Not deleted\n");
1247   modified("serverhosts");
1248 }
1249
1250
1251 static int fnchecklen;
1252
1253 void fsmatch(int id, void *nfsphys, void *filesys)
1254 {
1255   struct nfsphys *n = nfsphys;
1256   struct filesys *f = filesys;
1257
1258   if (n->mach_id == f->mach_id &&
1259       !strncmp(f->dir, n->dir, strlen(n->dir)) &&
1260       strlen(n->dir) > fnchecklen)
1261     {
1262       f->phys_id = id;
1263       fnchecklen = strlen(n->dir);
1264     }
1265 }
1266
1267
1268 void check_fs(int id, void *filesys, void *hint)
1269 {
1270   EXEC SQL BEGIN DECLARE SECTION;
1271   int iid = id, id1, id2, id3, rowcount;
1272   char *dir;
1273   EXEC SQL END DECLARE SECTION;
1274   struct filesys *f = filesys;
1275   struct nfsphys *n;
1276   struct machine *m;
1277
1278   if (!hash_lookup(machines, f->mach_id))
1279     {
1280       printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
1281       if (single_fix("Fix", 0))
1282         {
1283           EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
1284           rowcount = sqlca.sqlerrd[2];
1285           if (rowcount > 0)
1286             printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1287           else
1288             printf("Not fixed\n");
1289           modified("filesys");
1290           f->mach_id = 0;
1291         }
1292     }
1293
1294   if (!hash_lookup(users, f->owner))
1295     {
1296       printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
1297       if (single_fix("Fix", 1))
1298         {
1299           zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
1300           f->owner = 0;
1301         }
1302     }
1303   if (!hash_lookup(lists, f->owners))
1304     {
1305       printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
1306       if (single_fix("Fix", 1))
1307         {
1308           zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
1309           f->owners = 0;
1310         }
1311     }
1312
1313   if (f->type == 'N' || f->type == 'I')
1314     {
1315       if (!hash_lookup(nfsphys, f->phys_id))
1316         {
1317           m = hash_lookup(machines, f->mach_id);
1318           printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
1319           if (single_fix("Fix", 1))
1320             {
1321               fnchecklen = 0;
1322               hash_step(nfsphys, fsmatch, f);
1323               if (fnchecklen != 0)
1324                 {
1325                   id1 = f->phys_id;
1326                   id2 = f->filsys_id;
1327                   id3 = f->mach_id;
1328                   EXEC SQL UPDATE filesys SET phys_id = :id1
1329                     WHERE filsys_id = :id2;
1330                   rowcount = sqlca.sqlerrd[2];
1331                   if (rowcount > 0)
1332                     printf("%d entr%s fixed\n", rowcount,
1333                            rowcount == 1 ? "y" : "ies");
1334                   else
1335                     printf("Not fixed\n");
1336                   modified("filesys");
1337                 }
1338               else
1339                 {
1340                   printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
1341                   if (single_fix("Create", 0))
1342                     {
1343                       dir = f->dir;
1344                       id1 = f->phys_id;
1345                       id2 = f->filsys_id;
1346                       id3 = f->mach_id;
1347                       if (set_next_object_id("nfsphys_id", "nfsphys") !=
1348                           MR_SUCCESS)
1349                         {
1350                           printf("Unable to assign unique ID\n");
1351                           return;
1352                         }
1353                       EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
1354                         WHERE name = 'nfsphys_id';
1355                       if (rowcount != 1)
1356                         {
1357                           printf("Unable to retrieve unique ID\n");
1358                           return;
1359                         }
1360                       EXEC SQL INSERT INTO nfsphys
1361                         (nfsphys_id, mach_id, device, dir, status, allocated,
1362                          size, modtime, modby, modwith) VALUES
1363                         (:id1, :id3, '\?\?\?', :dir, 0, 0, 0, SYSDATE, 0,
1364                          'dbck');
1365                         rowcount = sqlca.sqlerrd[2];
1366                         if (rowcount > 0)
1367                           {
1368                             printf("%d entr%s created\n", rowcount,
1369                                    rowcount == 1 ? "y" : "ies");
1370                           }
1371                         else
1372                           printf("Not created\n");
1373                         modified("nfsphys");
1374                         n = malloc(sizeof(struct nfsphys));
1375                         if (!n)
1376                           out_of_mem("storing new nfsphys");
1377                         strcpy(n->dir, dir);
1378                         n->mach_id = id3;
1379                         n->nfsphys_id = id1;
1380                         n->allocated = 0;
1381                         n->count = 0;
1382                         if (hash_store(nfsphys, id1, n) == -1)
1383                           out_of_mem("storing nfsphys in hash table");
1384                         EXEC SQL UPDATE filesys SET phys_id = :id1
1385                           WHERE filsys_id = :id2;
1386                         rowcount = sqlca.sqlerrd[2];
1387                         if (rowcount > 0)
1388                           {
1389                             printf("%d filesys entr%s fixed\n", rowcount,
1390                                    rowcount == 1 ? "y" : "ies");
1391                           }
1392                         else
1393                           printf("Not fixed\n");
1394                         modified("filesys");
1395                     }
1396                 }
1397             }
1398         }
1399     }
1400 }
1401
1402 void check_nfsphys(int id, void *nfsphys, void *hint)
1403 {
1404   struct nfsphys *n = nfsphys;
1405
1406   n->modby = maybe_fixup_modby(n->modby, id, n->dir, "nfsphys",
1407                                "modby", "nfsphys_id");
1408
1409   if (!hash_lookup(machines, n->mach_id))
1410     {
1411       printf("NFSphys %d(%s) on non-existant machine %d\n",
1412              id, n->dir, n->mach_id);
1413       if (single_fix("Delete", 0))
1414         single_delete("nfsphys", "nfsphys_id", id);
1415     }
1416 }
1417
1418 static void clear_ps_owner(struct printserver *ps)
1419 {
1420   EXEC SQL BEGIN DECLARE SECTION;
1421   int rowcount, id = ps->mach_id;
1422   EXEC SQL END DECLARE SECTION;
1423
1424   EXEC SQL UPDATE printserver SET owner_type = 'NONE', owner_id = 0
1425     WHERE mach_id = :id;
1426   rowcount = sqlca.sqlerrd[2];
1427   if (rowcount > 0)
1428     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1429   else
1430     printf("Not fixed\n");
1431   modified("printservers");
1432 }
1433
1434 static void clear_ps_lpc(struct printserver *ps)
1435 {
1436   EXEC SQL BEGIN DECLARE SECTION;
1437   int rowcount, id = ps->mach_id;
1438   EXEC SQL END DECLARE SECTION;
1439
1440   EXEC SQL UPDATE printserver SET lpc_acl = 0
1441     WHERE mach_id = :id;
1442   rowcount = sqlca.sqlerrd[2];
1443   if (rowcount > 0)
1444     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1445   else
1446     printf("Not fixed\n");
1447   modified("printservers");
1448 }
1449
1450 void check_ps(int id, void *printserver, void *hint)
1451 {
1452   struct printserver *ps = printserver;
1453   struct machine *m;
1454   char *name;
1455
1456   m = hash_lookup(machines, id);
1457   if (!m)
1458     {
1459       printf("Printserver on non-existant machine %d\n", id);
1460       if (single_fix("Delete", 0))
1461         {
1462           single_delete("printservers", "mach_id", id);
1463           return;
1464         }
1465       else
1466         name = "[UNKNOWN]";
1467     }
1468   else
1469     name = m->name;      
1470
1471   ps->modby = maybe_fixup_modby(ps->modby, id, name, "printservers",
1472                                 "modby", "mach_id");
1473   ps->printer_types = maybe_fixup_unref_string(ps->printer_types, id, name,
1474                                                "printservers", "printer_types",
1475                                                "mach_id");
1476
1477   switch (ps->owner_type)
1478     {
1479     case 'U':
1480       if (!hash_lookup(users, ps->owner_id))
1481         {
1482           printf("Printserver %s has non-existant USER owner %d\n",
1483                  name, ps->owner_id);
1484           if (single_fix("Set to no owner", 1))
1485             clear_ps_owner(ps);
1486         }
1487       break;
1488     case 'L':
1489       if (!hash_lookup(lists, ps->owner_id))
1490         {
1491           printf("Printserver %s has non-existant LIST owner %d\n",
1492                  name, ps->owner_id);
1493           if (single_fix("Set to no owner", 1))
1494             clear_ps_owner(ps);
1495         }
1496       break;
1497     case 'K':
1498       if (ps->owner_id)
1499         ps->owner_id = maybe_fixup_unref_string(ps->owner_id, id, name,
1500                                                "printserver", "owner_id",
1501                                                "mach_id");
1502       if (ps->owner_id == 0)
1503         clear_ps_owner(ps);
1504     }
1505
1506   if (!hash_lookup(lists, ps->lpc_acl))
1507     {
1508       printf("Printserver %s has non-existent lpc_acl %d\n",
1509              name, ps->lpc_acl);
1510       if (single_fix("Set to no lpc_acl", 1))
1511         clear_ps_lpc(ps);
1512     }
1513 }
1514
1515 int show_fsg_missing(void *id)
1516 {
1517   EXEC SQL BEGIN DECLARE SECTION;
1518   int iid = (int)id, id1, found = 1;
1519   EXEC SQL END DECLARE SECTION;
1520   struct filesys *f;
1521
1522   EXEC SQL DECLARE csr210 CURSOR FOR
1523     SELECT filsys_id FROM fsgroup
1524     WHERE group_id = :iid;
1525   EXEC SQL OPEN csr210;
1526   while (1)
1527     {
1528       EXEC SQL FETCH csr210 INTO :id1;
1529       if (sqlca.sqlcode)
1530         break;
1531
1532       found = 0;
1533       if ((f = hash_lookup(filesys, id1)))
1534         printf("Missing fsgroup %d has member filesystem %s\n", iid, f->name);
1535       else
1536         printf("Missing fsgroup %d has member filesystem %d\n", iid, id1);
1537     }
1538   EXEC SQL CLOSE csr210;
1539   return found;
1540 }
1541
1542 int show_fsg_type(void *filesys)
1543 {
1544   struct filesys *f = filesys;
1545   char *t;
1546
1547   switch (f->type)
1548     {
1549     case 'N':
1550       t = "NFS";
1551       break;
1552     case 'R':
1553       t = "RVD";
1554       break;
1555     case 'A':
1556       t = "AFS";
1557       break;
1558     case 'E':
1559       t = "ERR";
1560       break;
1561     case 'F':
1562       t = "FSGROUP";
1563       break;
1564     case 'M':
1565       t = "MUL";
1566       break;
1567     default:
1568       t = "\?\?\?";
1569     }
1570   printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1571   return 0;
1572 }
1573
1574 void fix_fsg_type(void *filesys)
1575 {
1576   struct filesys *f = filesys;
1577   EXEC SQL BEGIN DECLARE SECTION;
1578   int rowcount, id = f->filsys_id;
1579   EXEC SQL END DECLARE SECTION;
1580
1581   EXEC SQL UPDATE filesys SET type = 'FSGROUP' WHERE filsys_id = :id;
1582   rowcount = sqlca.sqlerrd[2];
1583   if (rowcount > 0)
1584     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1585   else
1586     printf("Not fixed\n");
1587   modified("filesys");
1588 }
1589
1590 int show_fsg_nomember(void *id)
1591 {
1592   EXEC SQL BEGIN DECLARE SECTION;
1593   int iid = (int)id, id1, found = 1;
1594   EXEC SQL END DECLARE SECTION;
1595   struct filesys *f;
1596
1597   EXEC SQL DECLARE csr211 CURSOR FOR
1598     SELECT group_id FROM fsgroup
1599     WHERE filsys_id = :iid;
1600   EXEC SQL OPEN csr211;
1601   while (1)
1602     {
1603       EXEC SQL FETCH csr211 INTO :id1;
1604       if (sqlca.sqlcode)
1605         break;
1606
1607       found = 0;
1608       if ((f = hash_lookup(filesys, id1)))
1609         printf("FSGroup %s has missing member %d\n", f->name, iid);
1610       else
1611         printf("FSGroup %d has missing member %d\n", id1, iid);
1612     }
1613   EXEC SQL CLOSE csr211;
1614   return found;
1615 }
1616
1617 int show_quota_nouser(void *id)
1618 {
1619   EXEC SQL BEGIN DECLARE SECTION;
1620   int iid = (int)id, id1, found = 1;
1621   EXEC SQL END DECLARE SECTION;
1622
1623   EXEC SQL DECLARE csr212 CURSOR FOR
1624     SELECT filsys_id FROM quota
1625     WHERE entity_id = :iid AND type = 'USER';
1626   EXEC SQL OPEN csr212;
1627   while (1)
1628     {
1629       EXEC SQL FETCH csr212 INTO :id1;
1630       if (sqlca.sqlcode)
1631         break;
1632
1633       found = 0;
1634       printf("Quota on fs %d for non-existant user %d\n", id1, iid);
1635     }
1636   EXEC SQL CLOSE csr212;
1637   return found;
1638 }
1639
1640 int show_quota_nolist(void *id)
1641 {
1642   EXEC SQL BEGIN DECLARE SECTION;
1643   int iid = (int)id, id1, found = 1;
1644   EXEC SQL END DECLARE SECTION;
1645
1646   EXEC SQL DECLARE csr213 CURSOR FOR
1647     SELECT filsys_id FROM quota
1648     WHERE entity_id = :iid AND type = 'GROUP';
1649   EXEC SQL OPEN csr213;
1650   while (1)
1651     {
1652       EXEC SQL FETCH csr213 INTO :id1;
1653       if (sqlca.sqlcode)
1654         break;
1655
1656       found = 0;
1657       printf("Quota on fs %d for non-existant list %d\n", id1, iid);
1658     }
1659   EXEC SQL CLOSE csr213;
1660   return found;
1661 }
1662
1663 void fix_quota_nouser(void *id)
1664 {
1665   EXEC SQL BEGIN DECLARE SECTION;
1666   int iid = (int)id, rowcount;
1667   EXEC SQL END DECLARE SECTION;
1668
1669   EXEC SQL DELETE FROM quota
1670     WHERE entity_id = :iid AND type = 'USER';
1671   rowcount = sqlca.sqlerrd[2];
1672   if (rowcount > 0)
1673     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1674   else
1675     printf("Not deleted\n");
1676   modified("quota");
1677 }
1678
1679 void fix_quota_nolist(void *id)
1680 {
1681   EXEC SQL BEGIN DECLARE SECTION;
1682   int iid = (int)id, rowcount;
1683   EXEC SQL END DECLARE SECTION;
1684
1685   EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP';
1686   rowcount = sqlca.sqlerrd[2];
1687   if (rowcount > 0)
1688     printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1689   else
1690     printf("Not deleted\n");
1691   modified("quota");
1692 }
1693
1694 int show_quota_nofs(void *id)
1695 {
1696   EXEC SQL BEGIN DECLARE SECTION;
1697   int iid = (int)id, id1, found = 1;
1698   char type[QUOTA_TYPE_SIZE];
1699   EXEC SQL END DECLARE SECTION;
1700
1701   EXEC SQL DECLARE csr214 CURSOR FOR
1702     SELECT entity_id, type FROM quota
1703     WHERE filsys_id = :iid;
1704   EXEC SQL OPEN csr214;
1705   while (1)
1706     {
1707       EXEC SQL FETCH csr214 INTO :id1, :type;
1708       if (sqlca.sqlcode)
1709         break;
1710
1711       found = 0;
1712       printf("Quota for %s %d on non-existant filesys %d\n", type, id1, iid);
1713     }
1714   EXEC SQL CLOSE csr214;
1715   return found;
1716 }
1717
1718 void fix_quota_nofs(void *id)
1719 {
1720   single_delete("quota", "filsys_id", (int)id);
1721 }
1722
1723 int show_quota_wrongpid(void *id)
1724 {
1725   EXEC SQL BEGIN DECLARE SECTION;
1726   int iid = (int)id, id1, found = 1;
1727   char type[QUOTA_TYPE_SIZE];
1728   EXEC SQL END DECLARE SECTION;
1729   struct filesys *f;
1730
1731   f = hash_lookup(filesys, iid);
1732   EXEC SQL DECLARE csr215 CURSOR FOR
1733     SELECT entity_id, type FROM quota
1734     WHERE filsys_id = :iid;
1735   EXEC SQL OPEN csr215;
1736   while (1)
1737     {
1738       EXEC SQL FETCH csr215 INTO :id1, :type;
1739       if (sqlca.sqlcode)
1740         break;
1741
1742       found = 0;
1743       printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1744              type, id1, f->name, iid);
1745     }
1746   EXEC SQL CLOSE csr215;
1747   return found;
1748 }
1749
1750 void fix_quota_physid(void *id)
1751 {
1752   EXEC SQL BEGIN DECLARE SECTION;
1753   int iid = (int)id, rowcount, id1;
1754   EXEC SQL END DECLARE SECTION;
1755
1756   id1 = ((struct filesys *)hash_lookup(filesys, iid))->phys_id;
1757   EXEC SQL UPDATE quota SET phys_id = :id1
1758     WHERE filsys_id = :iid AND phys_id != :id1;
1759   rowcount = sqlca.sqlerrd[2];
1760   if (rowcount > 0)
1761     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1762   else
1763     printf("Not fixed\n");
1764   modified("quota");
1765 }
1766
1767 int show_srv_user(void *id)
1768 {
1769   EXEC SQL BEGIN DECLARE SECTION;
1770   char name[SERVERS_NAME_SIZE];
1771   int iid = (int)id;
1772   EXEC SQL END DECLARE SECTION;
1773   int found = 1;
1774
1775   EXEC SQL DECLARE csr216 CURSOR FOR
1776     SELECT name FROM servers
1777     WHERE acl_type = 'USER' and acl_id = :iid;
1778   EXEC SQL OPEN csr216;
1779   while (1)
1780     {
1781       EXEC SQL FETCH csr216 INTO :name;
1782       if (sqlca.sqlcode)
1783         break;
1784
1785       strtrim(name);
1786       printf("Service %s has acl non-existant user %d\n", name, iid);
1787       found = 0;
1788     }
1789   EXEC SQL CLOSE csr216;
1790   return found;
1791 }
1792
1793 int show_srv_list(void *id)
1794 {
1795   EXEC SQL BEGIN DECLARE SECTION;
1796   char name[SERVERS_NAME_SIZE];
1797   int iid = (int)id;
1798   EXEC SQL END DECLARE SECTION;
1799   int found = 1;
1800
1801   EXEC SQL DECLARE csr217 CURSOR FOR
1802     SELECT name FROM servers
1803     WHERE acl_type = 'LIST' AND acl_id = :iid;
1804   EXEC SQL OPEN csr217;
1805   while (1)
1806     {
1807       EXEC SQL FETCH csr217 INTO :name;
1808       if (sqlca.sqlcode)
1809         break;
1810
1811       strtrim(name);
1812       printf("Service %s has acl non-existant list %d\n", name, iid);
1813       found = 0;
1814     }
1815   EXEC SQL CLOSE csr217;
1816   return found;
1817 }
1818
1819 void zero_srv_user(void *id)
1820 {
1821   EXEC SQL BEGIN DECLARE SECTION;
1822   int iid = (int)id, rowcount;
1823   EXEC SQL END DECLARE SECTION;
1824
1825   EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1826     acl_type = 'USER';
1827   rowcount = sqlca.sqlerrd[2];
1828   if (rowcount > 0)
1829     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1830   else
1831     printf("Not fixed\n");
1832   modified("servers");
1833 }
1834
1835 void zero_srv_list(void *id)
1836 {
1837   EXEC SQL BEGIN DECLARE SECTION;
1838   int iid = (int)id, rowcount;
1839   EXEC SQL END DECLARE SECTION;
1840
1841   EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1842     acl_type = 'LIST';
1843   rowcount = sqlca.sqlerrd[2];
1844   if (rowcount > 0)
1845     printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1846   else
1847     printf("Not fixed\n");
1848   modified("servers");
1849 }
1850
1851 int show_krb_usr(void *id)
1852 {
1853   EXEC SQL BEGIN DECLARE SECTION;
1854   int iid = (int)id, found = 1, id1;
1855   EXEC SQL END DECLARE SECTION;
1856   struct string *s;
1857   char *ss;
1858
1859   EXEC SQL DECLARE csr218 CURSOR FOR
1860     SELECT string_id FROM krbmap
1861     WHERE users_id = :iid;
1862   EXEC SQL OPEN csr218;
1863   while (1)
1864     {
1865       EXEC SQL FETCH csr218 INTO :id1;
1866       if (sqlca.sqlcode)
1867         break;
1868
1869       if ((s = hash_lookup(strings, id1)))
1870         ss = s->name;
1871       else
1872         ss = "[unknown]";
1873       found = 0;
1874       printf("Kerberos map for non-existant user %d to principal %s\n",
1875              iid, ss);
1876     }
1877   EXEC SQL CLOSE csr218;
1878   return found;
1879 }
1880
1881 int show_krb_str(void *id)
1882 {
1883   EXEC SQL BEGIN DECLARE SECTION;
1884   int iid = (int)id, found = 1, id1;
1885   EXEC SQL END DECLARE SECTION;
1886   struct user *u;
1887   char *s;
1888
1889   EXEC SQL DECLARE csr219 CURSOR FOR
1890     SELECT users_id FROM krbmap
1891     WHERE string_id = :iid;
1892   EXEC SQL OPEN csr219;
1893   while (1)
1894     {
1895       EXEC SQL FETCH csr219 INTO :id1;
1896       if (sqlca.sqlcode)
1897         break;
1898
1899       if ((u = hash_lookup(users, id1)))
1900         s = u->login;
1901       else
1902         s = "[\?\?\?]";
1903       found = 0;
1904       printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1905              s, id1, iid);
1906     }
1907   EXEC SQL CLOSE csr219;
1908   return found;
1909 }
1910
1911 void phase2(void)
1912 {
1913   struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5, *sq6;
1914   struct filesys *f;
1915   struct list *l;
1916   struct nfsphys *n;
1917   struct machine *m;
1918   char rowid[32];
1919
1920   printf("Phase 2 - Checking references\n");
1921
1922   dprintf("Checking users...\n");
1923   hash_step(users, user_check, NULL);
1924
1925   dprintf("Checking machines...\n");
1926   hash_step(machines, mach_check, NULL);
1927
1928   dprintf("Checking subnets...\n");
1929   hash_step(subnets, subnet_check, NULL);
1930
1931   dprintf("Checking clusters...\n");
1932   hash_step(clusters, cluster_check, NULL);
1933
1934   dprintf("Checking mcmap...\n");
1935   sq1 = sq_create();
1936   sq2 = sq_create();
1937   EXEC SQL DECLARE csr221 CURSOR FOR
1938     SELECT mach_id, clu_id FROM mcmap;
1939   EXEC SQL OPEN csr221;
1940   while (1)
1941     {
1942       EXEC SQL BEGIN DECLARE SECTION;
1943       int mach_id, clu_id;
1944       EXEC SQL END DECLARE SECTION;
1945
1946       EXEC SQL FETCH csr221 INTO :mach_id, :clu_id;
1947       if (sqlca.sqlcode)
1948         break;
1949
1950       if (!(m = hash_lookup(machines, mach_id)))
1951         sq_save_unique_data(sq1, (void *)mach_id);
1952       else if (!hash_lookup(clusters, clu_id))
1953         sq_save_unique_data(sq2, (void *)clu_id);
1954       if (m)
1955         m->clucount++;
1956     }
1957   EXEC SQL CLOSE csr221;
1958   generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1959   generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1960
1961   dprintf("Checking service clusters...\n");
1962   sq1 = sq_create();
1963   EXEC SQL DECLARE csr222 CURSOR FOR
1964     SELECT clu_id FROM svc;
1965   EXEC SQL OPEN csr222;
1966   while (1)
1967     {
1968       EXEC SQL BEGIN DECLARE SECTION;
1969       int clu_id;
1970       EXEC SQL END DECLARE SECTION;
1971
1972       EXEC SQL FETCH csr222 INTO :clu_id;
1973       if (sqlca.sqlcode)
1974         break;
1975
1976       if (!hash_lookup(clusters, clu_id))
1977         sq_save_unique_data(sq1, (void *)clu_id);
1978     }
1979   EXEC SQL CLOSE csr222;
1980   generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1981
1982   dprintf("Checking lists...\n");
1983   hash_step(lists, list_check, NULL);
1984
1985   dprintf("Checking members...\n");
1986   sq1 = sq_create();
1987   sq2 = sq_create();
1988   sq3 = sq_create();
1989   sq4 = sq_create();
1990   sq5 = sq_create();
1991   sq6 = sq_create();
1992
1993   EXEC SQL DECLARE csr223 CURSOR FOR
1994     SELECT list_id, member_type, member_id, tag, ref_count, direct, rowid
1995     FROM imembers FOR UPDATE OF member_id;
1996   EXEC SQL OPEN csr223;
1997   while (1)
1998     {
1999       EXEC SQL BEGIN DECLARE SECTION;
2000       int list_id, id, tag, ref_count, direct;
2001       char type[IMEMBERS_MEMBER_TYPE_SIZE];
2002       EXEC SQL END DECLARE SECTION;
2003
2004       EXEC SQL FETCH csr223 INTO :list_id, :type, :id, :tag,
2005         :ref_count, :direct, :rowid;
2006       if (sqlca.sqlcode)
2007         break;
2008       strtrim(rowid);
2009
2010       if (!(l = hash_lookup(lists, list_id)))
2011         sq_save_unique_data(sq1, (void *)list_id);
2012       else if (type[0] == 'U' && !hash_lookup(users, id))
2013         sq_save_unique_data(sq2, (void *)id);
2014       else if (type[0] == 'L' && !hash_lookup(lists, id))
2015         sq_save_unique_data(sq3, (void *)id);
2016       else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
2017         sq_save_unique_data(sq4, (void *)id);
2018       else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
2019         sq_save_unique_data(sq5, (void *)id);
2020       else if (type[0] == 'M' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
2021         sq_save_unique_data(sq6, (void *)id);
2022       else
2023         l->members++;
2024       maybe_fixup_unref_string2("imembers", "tag", rowid, tag);
2025     }
2026   EXEC SQL CLOSE csr223;
2027   generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
2028   generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
2029   generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
2030   generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
2031   generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
2032   generic_fix(sq6, show_mem_mach, "Delete", del_mem_mach, 1);
2033
2034   dprintf("Checking servers...\n");
2035   sq1 = sq_create();
2036   sq2 = sq_create();
2037   EXEC SQL DECLARE csr224 CURSOR FOR
2038     SELECT name, acl_type, acl_id, modby, rowid FROM servers
2039     FOR UPDATE of modby;
2040   EXEC SQL OPEN csr224;
2041   while (1)
2042     {
2043       EXEC SQL BEGIN DECLARE SECTION;
2044       int acl_id, modby;
2045       char name[SERVERS_NAME_SIZE], acl_type[SERVERS_ACL_TYPE_SIZE];
2046       EXEC SQL END DECLARE SECTION;
2047
2048       EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby, :rowid;
2049       if (sqlca.sqlcode)
2050         break;
2051
2052       maybe_fixup_modby2("servers", "modby", strtrim(rowid), modby);
2053       strtrim(acl_type);
2054       if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
2055         sq_save_data(sq1, (void *)acl_id);
2056       else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
2057         sq_save_data(sq2, (void *)acl_id);
2058     }
2059   EXEC SQL CLOSE csr224;
2060   generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
2061   generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
2062
2063   dprintf("Checking serverhosts...\n");
2064   sq = sq_create();
2065   EXEC SQL DECLARE csr225 CURSOR FOR
2066     SELECT mach_id, modby, rowid FROM serverhosts
2067     FOR UPDATE OF modby;
2068   EXEC SQL OPEN csr225;
2069   while (1)
2070     {
2071       EXEC SQL BEGIN DECLARE SECTION;
2072       int mach_id, modby;
2073       EXEC SQL END DECLARE SECTION;
2074
2075       EXEC SQL FETCH csr225 INTO :mach_id, :modby, :rowid;
2076       if (sqlca.sqlcode)
2077         break;
2078
2079       maybe_fixup_modby2("serverhosts", "modby", strtrim(rowid), modby);
2080       if (!hash_lookup(machines, mach_id))
2081         sq_save_data(sq, (void *)mach_id);
2082     }
2083   EXEC SQL CLOSE csr225;
2084   generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
2085
2086   dprintf("Checking nfsphys...\n");
2087   hash_step(nfsphys, check_nfsphys, NULL);
2088
2089   dprintf("Checking filesys...\n");
2090   hash_step(filesys, check_fs, NULL);
2091
2092   dprintf("Checking filesystem groups...\n");
2093   sq1 = sq_create();
2094   sq2 = sq_create();
2095   sq3 = sq_create();
2096   EXEC SQL DECLARE csr226 CURSOR FOR
2097     SELECT group_id, filsys_id FROM fsgroup;
2098   EXEC SQL OPEN csr226;
2099   while (1)
2100     {
2101       EXEC SQL BEGIN DECLARE SECTION;
2102       int group_id, filsys_id;
2103       EXEC SQL END DECLARE SECTION;
2104
2105       EXEC SQL FETCH csr226 INTO :group_id, :filsys_id;
2106       if (sqlca.sqlcode)
2107         break;
2108
2109       if (!(f = hash_lookup(filesys, group_id)))
2110         sq_save_data(sq1, (void *)group_id);
2111       if (!hash_lookup(filesys, filsys_id))
2112         sq_save_data(sq3, (void *)filsys_id);
2113     }
2114   EXEC SQL CLOSE csr226;
2115   generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
2116   generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
2117
2118   dprintf("Checking quotas...\n");
2119   sq1 = sq_create();
2120   sq2 = sq_create();
2121   sq3 = sq_create();
2122   sq4 = sq_create();
2123   EXEC SQL DECLARE csr227 CURSOR FOR
2124     SELECT entity_id, type, filsys_id, phys_id, quota, modby, rowid
2125     FROM quota FOR UPDATE OF modby;
2126   EXEC SQL OPEN csr227;
2127   while (1)
2128     {
2129       EXEC SQL BEGIN DECLARE SECTION;
2130       int entity_id, filsys_id, phys_id, quota, modby;
2131       char type[QUOTA_TYPE_SIZE];
2132       EXEC SQL END DECLARE SECTION;
2133
2134       EXEC SQL FETCH csr227 INTO :entity_id, :type, :filsys_id,
2135         :phys_id, :quota, :modby, :rowid;
2136       if (sqlca.sqlcode)
2137         break;
2138
2139       maybe_fixup_modby2("quota", "modby", strtrim(rowid), modby);
2140       if (type[0] == 'U' && entity_id != 0 && !hash_lookup(users, entity_id))
2141         sq_save_data(sq1, (void *)entity_id);
2142       else if (type[0] == 'G' && !hash_lookup(lists, entity_id))
2143         sq_save_data(sq4, (void *)entity_id);
2144       else if (!(f = hash_lookup(filesys, filsys_id)))
2145         sq_save_data(sq2, (void *)filsys_id);
2146       else if (phys_id != f->phys_id || !(n = hash_lookup(nfsphys, phys_id)))
2147         sq_save_data(sq3, (void *)phys_id);
2148       else
2149         n->count += quota;
2150     }
2151   EXEC SQL CLOSE csr227;
2152   generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
2153   generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
2154   generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
2155   generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
2156
2157   dprintf("Checking zephyr...\n");
2158   EXEC SQL DECLARE csr_zc CURSOR FOR
2159     SELECT class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id,
2160     iui_type, iui_id, modby FROM zephyr;
2161   EXEC SQL OPEN csr_zc;
2162   while(1)
2163     {
2164       EXEC SQL BEGIN DECLARE SECTION;
2165       int xmt_id, sub_id, iws_id, iui_id, modby;
2166       char class[ZEPHYR_CLASS_SIZE];
2167       char xmt_type[ZEPHYR_XMT_TYPE_SIZE];
2168       char sub_type[ZEPHYR_SUB_TYPE_SIZE];
2169       char iws_type[ZEPHYR_IWS_TYPE_SIZE];
2170       char iui_type[ZEPHYR_IUI_TYPE_SIZE];
2171       EXEC SQL END DECLARE SECTION;
2172
2173       EXEC SQL FETCH csr_zc INTO :class, :xmt_type, :xmt_id, :sub_type, 
2174         :sub_id, :iws_type, :iws_id, :iui_type, :iui_id, :modby;
2175
2176       if (sqlca.sqlcode)
2177         break;
2178
2179       maybe_fixup_modby2("zephyr", "modby", strtrim(rowid), modby);
2180
2181       strtrim(xmt_type);
2182       if (!strcmp(xmt_type, "USER") && !hash_lookup(users, xmt_id))
2183         {
2184           printf("xmt acl for %s is non-existant user %d\n", class, xmt_id);
2185           printf("Not fixing this error\n");
2186         }
2187       else if (!strcmp(xmt_type, "LIST") && !hash_lookup(lists, xmt_id))
2188         {
2189           printf("xmt acl for %s is non-existant list %d\n", class, xmt_id);
2190           printf("Not fixing this error\n");
2191         }
2192       else if (!strcmp(xmt_type, "STRING") || !strcmp(xmt_type, "KERBEROS"))
2193         maybe_fixup_unref_string2("zephyr", "xmt_id", strtrim(rowid), xmt_id);
2194
2195       strtrim(sub_type);
2196       if (!strcmp(sub_type, "USER") && !hash_lookup(users, sub_id))
2197         {
2198           printf("sub acl for %s is non-existant user %d\n", class, sub_id);
2199           printf("Not fixing this error\n");
2200         }
2201       else if (!strcmp(sub_type, "LIST") && !hash_lookup(lists, sub_id))
2202         {
2203           printf("sub acl for %s is non-existant list %d\n", class, sub_id);
2204           printf("Not fixing this error\n");
2205         }
2206       else if (!strcmp(sub_type, "STRING") || !strcmp(sub_type, "KERBEROS"))
2207         maybe_fixup_unref_string2("zephyr", "sub_id", strtrim(rowid), sub_id);
2208
2209       strtrim(iws_type);
2210       if (!strcmp(iws_type, "USER") && !hash_lookup(users, iws_id))
2211         {
2212           printf("iws acl for %s is non-existant user %d\n", class, iws_id);
2213           printf("Not fixing this error\n");
2214         }
2215       else if (!strcmp(iws_type, "LIST") && !hash_lookup(lists, iws_id))
2216         {
2217           printf("iws acl for %s is non-existant list %d\n", class, iws_id);
2218           printf("Not fixing this error\n");
2219         }
2220       else if (!strcmp(iws_type, "STRING") || !strcmp(iws_type, "KERBEROS"))
2221         maybe_fixup_unref_string2("zephyr", "iws_id", strtrim(rowid), iws_id);
2222
2223       strtrim(iui_type);
2224       if (!strcmp(iui_type, "USER") && !hash_lookup(users, iui_id))
2225         {
2226           printf("iui acl for %s is non-existant user %d\n", class, iui_id);
2227           printf("Not fixing this error\n");
2228         }
2229       else if (!strcmp(iui_type, "LIST") && !hash_lookup(lists, iui_id))
2230         {
2231           printf("iui acl for %s is non-existant list %d\n", class, iui_id);
2232           printf("Not fixing this error\n");
2233         }
2234       else if (!strcmp(iui_type, "STRING") || !strcmp(iui_type, "KERBEROS"))
2235         maybe_fixup_unref_string2("zephyr", "iui_id", strtrim(rowid), iui_id);
2236     }
2237
2238   dprintf("Checking hostaccess...\n");
2239   EXEC SQL DECLARE csr228 CURSOR FOR
2240     SELECT mach_id, acl_type, acl_id, modby, rowid FROM hostaccess
2241     FOR UPDATE OF modby;
2242   EXEC SQL OPEN csr228;
2243   while (1)
2244     {
2245       EXEC SQL BEGIN DECLARE SECTION;
2246       int mach_id, acl_id, modby;
2247       char acl_type[HOSTACCESS_ACL_TYPE_SIZE];
2248       EXEC SQL END DECLARE SECTION;
2249
2250       EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby, :rowid;
2251       if (sqlca.sqlcode)
2252         break;
2253
2254       maybe_fixup_modby2("hostaccess", "modby", strtrim(rowid), modby);
2255       strtrim(acl_type);
2256       if (!hash_lookup(machines, mach_id))
2257         {
2258           printf("Hostaccess for non-existant host %d\n", mach_id);
2259           printf("Not fixing this error\n");
2260         }
2261       if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
2262         {
2263           printf("Hostaccess for %d is non-existant user %d\n", mach_id, acl_id);
2264           printf("Not fixing this error\n");
2265         }
2266       else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
2267         {
2268           printf("Hostaccess for %d is non-existant list %d\n", mach_id, acl_id);
2269           printf("Not fixing this error\n");
2270         }
2271     }
2272   EXEC SQL CLOSE csr228;
2273
2274   dprintf("Checking krbmap...\n");
2275   sq1 = sq_create();
2276   sq2 = sq_create();
2277   EXEC SQL DECLARE csr230 CURSOR FOR
2278     SELECT users_id, string_id, rowid FROM krbmap
2279     FOR UPDATE OF string_id;
2280   EXEC SQL OPEN csr230;
2281   while (1)
2282     {
2283       EXEC SQL BEGIN DECLARE SECTION;
2284       int users_id, string_id;
2285       EXEC SQL END DECLARE SECTION;
2286
2287       EXEC SQL FETCH csr230 INTO :users_id, :string_id, :rowid;
2288       if (sqlca.sqlcode)
2289         break;
2290
2291       if (!hash_lookup(users, users_id))
2292         sq_save_unique_data(sq1, (void *)users_id);
2293       else if (!maybe_fixup_unref_string2("krbmap", "string_id", strtrim(rowid), string_id))
2294         sq_save_unique_data(sq2, (void *)string_id);
2295     }
2296   EXEC SQL CLOSE csr230;
2297   generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
2298   generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
2299
2300   dprintf("Checking capacls...\n");
2301   EXEC SQL DECLARE csr231 CURSOR FOR
2302     SELECT list_id, tag FROM capacls;
2303   EXEC SQL OPEN csr231;
2304   while (1)
2305     {
2306       EXEC SQL BEGIN DECLARE SECTION;
2307       int list_id;
2308       char tag[CAPACLS_TAG_SIZE];
2309       EXEC SQL END DECLARE SECTION;
2310
2311       EXEC SQL FETCH csr231 INTO :list_id, :tag;
2312       if (sqlca.sqlcode)
2313         break;
2314
2315       if (!hash_lookup(lists, list_id))
2316         {
2317           printf("Capacl for %s is non-existant list %d\n", tag, list_id);
2318           printf("Not fixing this error\n");
2319         }
2320     }
2321   EXEC SQL CLOSE csr231;
2322
2323   dprintf("Checking hostaliases\n");
2324   sq1 = sq_create();
2325   EXEC SQL DECLARE csr232 CURSOR FOR
2326     SELECT mach_id FROM hostalias;
2327   EXEC SQL OPEN csr232;
2328   while (1)
2329     {
2330       EXEC SQL BEGIN DECLARE SECTION;
2331       int mach_id;
2332       EXEC SQL END DECLARE SECTION;
2333
2334       EXEC SQL FETCH csr232 INTO :mach_id;
2335       if (sqlca.sqlcode)
2336         break;
2337
2338       if (!hash_lookup(machines, mach_id))
2339         sq_save_unique_data(sq1, (void *)mach_id);
2340     }
2341   EXEC SQL CLOSE csr232;
2342   generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
2343
2344   dprintf("Checking printers\n");
2345   sq1 = sq_create();
2346   sq2 = sq_create();
2347   sq3 = sq_create();
2348   sq4 = sq_create();
2349   sq5 = sq_create();
2350   sq6 = sq_create();
2351   EXEC SQL DECLARE csr233 CURSOR FOR
2352     SELECT mach_id, loghost, rm, rq, ac, lpc_acl, modby, rowid FROM printers;
2353   EXEC SQL OPEN csr233;
2354   while (1)
2355     {
2356       EXEC SQL BEGIN DECLARE SECTION;
2357       int mach_id, loghost, rm, rq, ac, lpc_acl, modby;
2358       EXEC SQL END DECLARE SECTION;
2359
2360       EXEC SQL FETCH csr233 INTO :mach_id, :loghost, :rm, :rq, :ac,
2361         :lpc_acl, :modby, :rowid;
2362       if (sqlca.sqlcode)
2363         break;
2364
2365       maybe_fixup_modby2("printers", "modby", strtrim(rowid), modby);
2366       if (!hash_lookup(machines, mach_id))
2367         sq_save_unique_data(sq1, (void *)mach_id);
2368       else if (!hash_lookup(machines, rm))
2369         sq_save_unique_data(sq2, (void *)rm);
2370       else if (!hash_lookup(printservers, rm))
2371         sq_save_unique_data(sq6, (void *)mach_id);
2372       else if (!hash_lookup(machines, rq))
2373         sq_save_unique_data(sq3, (void *)rq);
2374       else {
2375         if (!hash_lookup(lists, ac))
2376           sq_save_unique_data(sq4, (void *)ac);
2377         if (!hash_lookup(lists, lpc_acl))
2378           sq_save_unique_data(sq5, (void *)lpc_acl);
2379         if (!hash_lookup(machines, loghost))
2380           {
2381             show_printer_loghost((void *)loghost);
2382             cant_fix();
2383           }
2384       }
2385     }
2386   EXEC SQL CLOSE csr233;
2387   generic_delete(sq1, show_printer_mach, "printers", "mach_id", 1);
2388   generic_delete(sq6, show_printer_server, "printers", "mach_id", 1);
2389   generic_delete(sq2, show_printer_spool, "printers", "rm", 1);
2390   generic_delete(sq3, show_printer_quota, "printers", "rq", 1);
2391   generic_fix(sq4, show_printer_ac, "Clear", fix_printer_ac, 1);
2392   generic_fix(sq5, show_printer_lpc_acl, "Clear", fix_printer_lpc_acl, 1);
2393
2394   dprintf("Checking printservers\n");
2395   hash_step(printservers, check_ps, NULL);
2396 }
2397  
This page took 0.268758 seconds and 5 git commands to generate.