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