3 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
16 EXEC SQL INCLUDE sqlca;
20 EXEC SQL WHENEVER SQLERROR DO dbmserr();
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);
87 int show_mcm_mach(void *id)
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;
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;
100 EXEC SQL FETCH csr201 INTO :name;
106 printf("Cluster %s, non-existant machine %d in cluster map\n",
109 EXEC SQL CLOSE csr201;
113 int show_mcm_clu(void *id)
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;
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;
126 EXEC SQL FETCH csr202 INTO :name;
133 printf("Machine %s, non-existant cluster %d in cluster map\n",
136 EXEC SQL CLOSE csr202;
140 int show_hostalias(void *id)
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;
147 EXEC SQL DECLARE csr234 CURSOR FOR
148 SELECT name FROM hostalias WHERE mach_id = :iid;
149 EXEC SQL OPEN csr234;
152 EXEC SQL FETCH csr234 INTO :name;
159 printf("Alias %s, non-existant machine %d in hostalias map\n",
162 EXEC SQL CLOSE csr234;
166 int show_printer_mach(void *id)
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;
173 EXEC SQL DECLARE csr235 CURSOR FOR
174 SELECT name FROM printers WHERE mach_id = :iid;
175 EXEC SQL OPEN csr235;
178 EXEC SQL FETCH csr235 INTO :name;
185 printf("Printer %s, non-existant machine %d in printers table\n",
188 EXEC SQL CLOSE csr235;
192 int show_printer_server(void *id)
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;
199 EXEC SQL DECLARE csr_sps CURSOR FOR
200 SELECT name FROM printers WHERE mach_id = :iid;
201 EXEC SQL OPEN csr_sps;
204 EXEC SQL FETCH csr_sps INTO :name;
211 printf("Printer %s, non-existant printserver %d in printers table\n",
214 EXEC SQL CLOSE csr_sps;
218 int show_printer_loghost(void *id)
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;
225 EXEC SQL DECLARE csr236 CURSOR FOR
226 SELECT name FROM printers WHERE loghost = :iid;
227 EXEC SQL OPEN csr236;
230 EXEC SQL FETCH csr236 INTO :name;
237 printf("Printer %s, non-existant spool machine %d in printers table\n",
240 EXEC SQL CLOSE csr236;
244 int show_printer_spool(void *id)
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;
251 EXEC SQL DECLARE csr237 CURSOR FOR
252 SELECT name FROM printers WHERE rm = :iid;
253 EXEC SQL OPEN csr237;
256 EXEC SQL FETCH csr237 INTO :name;
263 printf("Printer %s, non-existant spool machine %d in printers table\n",
266 EXEC SQL CLOSE csr237;
270 int show_printer_quota(void *id)
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;
277 EXEC SQL DECLARE csr238 CURSOR FOR
278 SELECT name FROM printers WHERE rq = :iid;
279 EXEC SQL OPEN csr238;
282 EXEC SQL FETCH csr238 INTO :name;
289 printf("Printer %s, non-existant quota server %d in printers table\n",
292 EXEC SQL CLOSE csr238;
296 int show_printer_ac(void *id)
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;
303 EXEC SQL DECLARE csr239 CURSOR FOR
304 SELECT name FROM printers WHERE ac = :iid;
305 EXEC SQL OPEN csr239;
308 EXEC SQL FETCH csr239 INTO :name;
315 printf("Printer %s, non-existant restrict list %d in printers table\n",
318 EXEC SQL CLOSE csr239;
322 int show_printer_lpc_acl(void *id)
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;
329 EXEC SQL DECLARE csr240 CURSOR FOR
330 SELECT name FROM printers WHERE lpc_acl = :iid;
331 EXEC SQL OPEN csr240;
334 EXEC SQL FETCH csr240 INTO :name;
341 printf("Printer %s, non-existant lpc ACL %d in printers table\n",
344 EXEC SQL CLOSE csr240;
348 void fix_printer_ac(void *id)
350 EXEC SQL BEGIN DECLARE SECTION;
351 int rowcount, iid = (int)id;
352 EXEC SQL END DECLARE SECTION;
354 EXEC SQL UPDATE printers SET ac = 0 WHERE ac = :iid;
355 rowcount = sqlca.sqlerrd[2];
357 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
359 printf("Not fixed\n");
360 modified("printers");
363 void fix_printer_lpc_acl(void *id)
365 EXEC SQL BEGIN DECLARE SECTION;
366 int rowcount, iid = (int)id;
367 EXEC SQL END DECLARE SECTION;
369 EXEC SQL UPDATE printers SET lpc_acl = 0 WHERE lpc_acl = :iid;
370 rowcount = sqlca.sqlerrd[2];
372 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
374 printf("Not fixed\n");
375 modified("printers");
378 void user_check(int id, void *user, void *hint)
380 struct user *u = user;
382 u->comment = maybe_fixup_unref_string(u->comment, id, u->login, "users",
383 "comments", "users_id");
385 u->modby = maybe_fixup_modby(u->modby, id, u->login, "users",
386 "modby", "users_id");
388 u->fmodby = maybe_fixup_modby(u->fmodby, id, u->login, "users",
389 "fmodby", "users_id");
391 u->pmodby = maybe_fixup_modby(u->pmodby, id, u->login, "users",
392 "pmodby", "users_id");
394 u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
395 "sigwho", "users_id");
400 int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
401 char *field, char *idfield)
403 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
404 EXEC SQL BEGIN DECLARE SECTION;
407 EXEC SQL END DECLARE SECTION;
409 if ((newid = (int)hash_lookup(string_dups, ret)))
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))
420 else if (!string_check(ret))
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))
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];
440 printf("Not fixed, rowcount = %d\n", rowcount);
444 return (sid < 0) ? -ret : ret;
447 int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
448 char *field, char *idfield)
450 EXEC SQL BEGIN DECLARE SECTION;
453 EXEC SQL END DECLARE SECTION;
456 return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
459 if (!hash_lookup(users, sid))
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))
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];
472 printf("Not fixed, rowcount = %d\n", rowcount);
481 int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid)
483 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
484 EXEC SQL BEGIN DECLARE SECTION;
487 EXEC SQL END DECLARE SECTION;
489 if ((newid = (int)hash_lookup(string_dups, ret)))
491 printf("%s entry has a %s with duplicate string %d\n",
493 if (single_fix("Replace duplicate", 0))
500 else if (!string_check(ret))
502 printf("%s entry has a %s with non-existant string %d\n",
504 if (single_fix("Clear", 1))
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];
520 printf("Not fixed, rowcount = %d\n", rowcount);
523 return (sid < 0) ? -ret : ret;
526 int maybe_fixup_modby2(char *table, char *field, char *rowid, int id)
528 EXEC SQL BEGIN DECLARE SECTION;
531 EXEC SQL END DECLARE SECTION;
534 return maybe_fixup_unref_string2(table, field, rowid, id);
537 if (!hash_lookup(users, id))
539 printf("%s entry has a %s with non-existant user %d\n",
541 if (single_fix("Clear", 1))
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];
550 printf("Not fixed, rowcount = %d\n", rowcount);
559 void pobox_check(int id, struct user *u)
566 if (!hash_lookup(machines, u->pobox_id))
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))
572 remove_pobox(u->users_id);
579 if (hash_lookup(string_dups, u->pobox_id))
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))
585 printf("Replacing box_id dup string ID %d with %d\n",
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);
593 else if (!string_check(u->pobox_id))
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))
599 remove_pobox(u->users_id);
606 fs = hash_lookup(filesys, u->pobox_id);
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))
613 remove_pobox(u->users_id);
617 else if (fs->type != 'I')
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))
623 remove_pobox(u->users_id);
635 void remove_pobox(int id)
637 EXEC SQL BEGIN DECLARE SECTION;
638 int rowcount, iid = (int)id;
639 EXEC SQL END DECLARE SECTION;
641 EXEC SQL UPDATE users SET potype = 'NONE' WHERE users.users_id = :iid;
642 rowcount = sqlca.sqlerrd[2];
644 printf("%d entr%s removed\n", rowcount, rowcount == 1 ? "y" : "ies");
646 printf("Not removed\n");
650 void fix_smtp_pobox(int id, int sid)
652 EXEC SQL BEGIN DECLARE SECTION;
653 int rowcount, iid = id, isid = sid;
654 EXEC SQL END DECLARE SECTION;
656 EXEC SQL UPDATE users SET box_id = :isid WHERE users.users_id = :iid;
657 rowcount = sqlca.sqlerrd[2];
659 printf("%d entr%s updated\n", rowcount, rowcount == 1 ? "y" : "ies");
661 printf("Not updated\n");
665 void mach_check(int id, void *machine, void *hint)
667 struct machine *m = machine;
669 if (!hash_lookup(subnets, m->snet_id))
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))
675 EXEC SQL BEGIN DECLARE SECTION;
676 int rowcount, iid = id;
677 EXEC SQL END DECLARE SECTION;
679 EXEC SQL UPDATE machine SET snet_id = 0 WHERE mach_id = :iid;
680 rowcount = sqlca.sqlerrd[2];
682 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
684 printf("Not fixed\n");
689 switch (m->owner_type)
692 if (!hash_lookup(users, m->owner_id))
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))
701 if (!hash_lookup(lists, m->owner_id))
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))
712 m->owner_id = maybe_fixup_unref_string(m->owner_id, id, m->name,
713 "machine", "owner_id",
715 if (m->owner_id == 0)
720 m->acomment = maybe_fixup_unref_string(m->acomment, id, m->name,
721 "machine", "acomment", "mach_id");
723 m->ocomment = maybe_fixup_unref_string(m->ocomment, id, m->name,
724 "machine", "ocomment", "mach_id");
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",
732 void subnet_check(int id, void *subnet, void *hint)
734 struct subnet *s = subnet;
736 switch (s->owner_type)
739 if (!hash_lookup(users, s->owner_id))
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);
748 if (!hash_lookup(lists, s->owner_id))
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);
759 s->owner_id = maybe_fixup_unref_string(s->owner_id, id, s->name,
760 "machine", "owner_id",
762 if (s->owner_id == 0)
763 clear_subnet_owner(s);
766 s->modby = maybe_fixup_modby(s->modby, id, s->name, "subnet",
770 void clear_subnet_owner(struct subnet *s)
772 EXEC SQL BEGIN DECLARE SECTION;
773 int rowcount, id = s->snet_id;
774 EXEC SQL END DECLARE SECTION;
776 EXEC SQL UPDATE subnet SET owner_type = 'NONE', owner_id = 0
778 rowcount = sqlca.sqlerrd[2];
780 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
782 printf("Not fixed\n");
786 void clear_mach_owner(struct machine *m)
788 EXEC SQL BEGIN DECLARE SECTION;
789 int rowcount, id = m->mach_id;
790 EXEC SQL END DECLARE SECTION;
792 EXEC SQL UPDATE machine SET owner_type = 'NONE', owner_id = 0
794 rowcount = sqlca.sqlerrd[2];
796 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
798 printf("Not fixed\n");
802 void cluster_check(int id, void *cluster, void *hint)
804 struct cluster *c = cluster;
806 c->modby = maybe_fixup_modby(c->modby, id, c->name, "clusters",
810 int show_svc(void *id)
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;
817 EXEC SQL DECLARE csr203 CURSOR FOR
818 SELECT serv_label, serv_cluster FROM svc
820 EXEC SQL OPEN csr203;
823 EXEC SQL FETCH csr203 INTO :label, :data;
830 printf("Cluster data [%s] %s for non-existant cluster %d\n",
833 EXEC SQL CLOSE csr203;
837 void list_check(int id, void *list, void *hint)
839 struct list *l = list;
841 l->modby = maybe_fixup_modby(l->modby, id, l->name, "list",
847 if (!hash_lookup(lists, l->acl_id))
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);
855 if (!hash_lookup(users, l->acl_id))
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);
863 l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
864 "list", "acl_id", "list_id");
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);
875 void fix_list_acl(int id)
877 EXEC SQL BEGIN DECLARE SECTION;
878 int rowcount, iid = (int)id;
879 EXEC SQL END DECLARE SECTION;
881 EXEC SQL UPDATE list SET acl_id = :iid, acl_type = 'LIST'
882 WHERE list_id = :iid;
883 rowcount = sqlca.sqlerrd[2];
885 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
887 printf("Not fixed\n");
891 int show_member_list(void *id)
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;
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;
904 EXEC SQL FETCH csr204 INTO :mtype, :mid;
912 struct list *l = hash_lookup(lists, mid);
916 else if (mtype[0] == 'U')
918 struct user *u = hash_lookup(users, mid);
922 else if (mtype[0] == 'S' || mtype[0] == 'K')
924 struct string *s = hash_lookup(strings, mid);
929 printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
932 printf("Non-existant list %d has non-existent member %s %d\n",
936 EXEC SQL CLOSE csr204;
940 int show_mem_user(void *id)
942 EXEC SQL BEGIN DECLARE SECTION;
943 int lid, iid = (int)id, found = 1;
944 EXEC SQL END DECLARE SECTION;
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;
953 EXEC SQL FETCH csr205 INTO :lid;
956 l = hash_lookup(lists, lid);
961 printf("List %s has non-existant user member, id %d\n", l->name, iid);
963 EXEC SQL CLOSE csr205;
967 int show_mem_list(void *id)
969 EXEC SQL BEGIN DECLARE SECTION;
970 int lid, iid = (int)id, found = 1;
971 EXEC SQL END DECLARE SECTION;
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;
980 EXEC SQL FETCH csr206 INTO :lid;
983 l = hash_lookup(lists, lid);
988 printf("List %s has non-existant list member, id %d\n", l->name, iid);
990 EXEC SQL CLOSE csr206;
994 int show_mem_str(void *id)
996 EXEC SQL BEGIN DECLARE SECTION;
997 int lid, iid = (int)id, found = 1;
998 EXEC SQL END DECLARE SECTION;
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;
1007 EXEC SQL FETCH csr207 INTO :lid;
1010 l = hash_lookup(lists, lid);
1015 printf("List %s has non-existant string member, id %d\n", l->name, iid);
1017 EXEC SQL CLOSE csr207;
1022 int show_mem_krb(void *id)
1024 EXEC SQL BEGIN DECLARE SECTION;
1025 int lid, iid = (int)id, found = 1;
1026 EXEC SQL END DECLARE SECTION;
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;
1035 EXEC SQL FETCH csr208 INTO :lid;
1038 l = hash_lookup(lists, lid);
1043 printf("List %s has non-existant kerberos member, id %d\n",
1046 EXEC SQL CLOSE csr208;
1051 void del_mem_user(void *id)
1053 EXEC SQL BEGIN DECLARE SECTION;
1054 int iid = (int)id, rowcount;
1055 EXEC SQL END DECLARE SECTION;
1057 EXEC SQL DELETE FROM imembers WHERE member_type = 'USER' AND
1059 rowcount = sqlca.sqlerrd[2];
1061 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1063 printf("Not deleted\n");
1064 modified("imembers");
1067 void del_mem_list(void *id)
1069 EXEC SQL BEGIN DECLARE SECTION;
1070 int iid = (int)id, rowcount;
1071 EXEC SQL END DECLARE SECTION;
1073 EXEC SQL DELETE FROM imembers WHERE member_type = 'LIST' AND
1075 rowcount = sqlca.sqlerrd[2];
1077 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1079 printf("Not deleted\n");
1080 modified("imembers");
1083 void del_mem_str(void *id)
1085 EXEC SQL BEGIN DECLARE SECTION;
1086 int iid = (int)id, rowcount;
1087 EXEC SQL END DECLARE SECTION;
1089 EXEC SQL DELETE FROM imembers WHERE member_type = 'STRING' AND
1091 rowcount = sqlca.sqlerrd[2];
1093 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1095 printf("Not deleted\n");
1096 modified("imembers");
1100 void del_mem_krb(void *id)
1102 EXEC SQL BEGIN DECLARE SECTION;
1103 int iid = (int)id, rowcount;
1104 EXEC SQL END DECLARE SECTION;
1106 EXEC SQL DELETE FROM imembers WHERE member_type = 'KERBEROS' AND
1108 rowcount = sqlca.sqlerrd[2];
1110 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1112 printf("Not deleted\n");
1113 modified("imembers");
1117 int show_sh(void *id)
1119 EXEC SQL BEGIN DECLARE SECTION;
1120 char name[SERVERHOSTS_SERVICE_SIZE];
1122 EXEC SQL END DECLARE SECTION;
1125 EXEC SQL DECLARE csr209 CURSOR FOR
1126 SELECT service FROM serverhosts
1127 WHERE mach_id = :iid;
1128 EXEC SQL OPEN csr209;
1131 EXEC SQL FETCH csr209 INTO :name;
1136 printf("ServerHost entry for service %s non-existant host %d\n",
1139 EXEC SQL CLOSE csr209;
1143 void del_sh_mach(void *id)
1145 EXEC SQL BEGIN DECLARE SECTION;
1146 int iid = (int)id, rowcount;
1147 EXEC SQL END DECLARE SECTION;
1149 EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
1150 rowcount = sqlca.sqlerrd[2];
1152 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1154 printf("Not deleted\n");
1155 modified("serverhosts");
1159 static int fnchecklen;
1161 void fsmatch(int id, void *nfsphys, void *filesys)
1163 struct nfsphys *n = nfsphys;
1164 struct filesys *f = filesys;
1166 if (n->mach_id == f->mach_id &&
1167 !strncmp(f->dir, n->dir, strlen(n->dir)) &&
1168 strlen(n->dir) > fnchecklen)
1171 fnchecklen = strlen(n->dir);
1176 void check_fs(int id, void *filesys, void *hint)
1178 EXEC SQL BEGIN DECLARE SECTION;
1179 int iid = id, id1, id2, id3, rowcount;
1181 EXEC SQL END DECLARE SECTION;
1182 struct filesys *f = filesys;
1186 if (!hash_lookup(machines, f->mach_id))
1188 printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
1189 if (single_fix("Fix", 0))
1191 EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
1192 rowcount = sqlca.sqlerrd[2];
1194 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1196 printf("Not fixed\n");
1197 modified("filesys");
1202 if (!hash_lookup(users, f->owner))
1204 printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
1205 if (single_fix("Fix", 1))
1207 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
1211 if (!hash_lookup(lists, f->owners))
1213 printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
1214 if (single_fix("Fix", 1))
1216 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
1221 if (f->type == 'N' || f->type == 'I')
1223 if (!hash_lookup(nfsphys, f->phys_id))
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))
1230 hash_step(nfsphys, fsmatch, f);
1231 if (fnchecklen != 0)
1236 EXEC SQL UPDATE filesys SET phys_id = :id1
1237 WHERE filsys_id = :id2;
1238 rowcount = sqlca.sqlerrd[2];
1240 printf("%d entr%s fixed\n", rowcount,
1241 rowcount == 1 ? "y" : "ies");
1243 printf("Not fixed\n");
1244 modified("filesys");
1248 printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
1249 if (single_fix("Create", 0))
1255 if (set_next_object_id("nfsphys_id", "nfsphys") !=
1258 printf("Unable to assign unique ID\n");
1261 EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
1262 WHERE name = 'nfsphys_id';
1265 printf("Unable to retrieve unique ID\n");
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,
1273 rowcount = sqlca.sqlerrd[2];
1276 printf("%d entr%s created\n", rowcount,
1277 rowcount == 1 ? "y" : "ies");
1280 printf("Not created\n");
1281 modified("nfsphys");
1282 n = malloc(sizeof(struct nfsphys));
1284 out_of_mem("storing new nfsphys");
1285 strcpy(n->dir, dir);
1287 n->nfsphys_id = id1;
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];
1297 printf("%d filesys entr%s fixed\n", rowcount,
1298 rowcount == 1 ? "y" : "ies");
1301 printf("Not fixed\n");
1302 modified("filesys");
1310 void check_nfsphys(int id, void *nfsphys, void *hint)
1312 struct nfsphys *n = nfsphys;
1314 n->modby = maybe_fixup_modby(n->modby, id, n->dir, "nfsphys",
1315 "modby", "nfsphys_id");
1317 if (!hash_lookup(machines, n->mach_id))
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);
1326 static void clear_ps_owner(struct printserver *ps)
1328 EXEC SQL BEGIN DECLARE SECTION;
1329 int rowcount, id = ps->mach_id;
1330 EXEC SQL END DECLARE SECTION;
1332 EXEC SQL UPDATE printserver SET owner_type = 'NONE', owner_id = 0
1333 WHERE mach_id = :id;
1334 rowcount = sqlca.sqlerrd[2];
1336 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1338 printf("Not fixed\n");
1339 modified("printservers");
1342 static void clear_ps_lpc(struct printserver *ps)
1344 EXEC SQL BEGIN DECLARE SECTION;
1345 int rowcount, id = ps->mach_id;
1346 EXEC SQL END DECLARE SECTION;
1348 EXEC SQL UPDATE printserver SET lpc_acl = 0
1349 WHERE mach_id = :id;
1350 rowcount = sqlca.sqlerrd[2];
1352 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1354 printf("Not fixed\n");
1355 modified("printservers");
1358 void check_ps(int id, void *printserver, void *hint)
1360 struct printserver *ps = printserver;
1364 m = hash_lookup(machines, id);
1367 printf("Printserver on non-existant machine %d\n", id);
1368 if (single_fix("Delete", 0))
1370 single_delete("printservers", "mach_id", id);
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",
1385 switch (ps->owner_type)
1388 if (!hash_lookup(users, ps->owner_id))
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))
1397 if (!hash_lookup(lists, ps->owner_id))
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))
1407 ps->owner_id = maybe_fixup_unref_string(ps->owner_id, id, name,
1408 "printserver", "owner_id",
1410 if (ps->owner_id == 0)
1414 if (!hash_lookup(lists, ps->lpc_acl))
1416 printf("Printserver %s has non-existent lpc_acl %d\n",
1418 if (single_fix("Set to no lpc_acl", 1))
1423 int show_fsg_missing(void *id)
1425 EXEC SQL BEGIN DECLARE SECTION;
1426 int iid = (int)id, id1, found = 1;
1427 EXEC SQL END DECLARE SECTION;
1430 EXEC SQL DECLARE csr210 CURSOR FOR
1431 SELECT filsys_id FROM fsgroup
1432 WHERE group_id = :iid;
1433 EXEC SQL OPEN csr210;
1436 EXEC SQL FETCH csr210 INTO :id1;
1441 if ((f = hash_lookup(filesys, id1)))
1442 printf("Missing fsgroup %d has member filesystem %s\n", iid, f->name);
1444 printf("Missing fsgroup %d has member filesystem %d\n", iid, id1);
1446 EXEC SQL CLOSE csr210;
1450 int show_fsg_type(void *filesys)
1452 struct filesys *f = filesys;
1478 printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1482 void fix_fsg_type(void *filesys)
1484 struct filesys *f = filesys;
1485 EXEC SQL BEGIN DECLARE SECTION;
1486 int rowcount, id = f->filsys_id;
1487 EXEC SQL END DECLARE SECTION;
1489 EXEC SQL UPDATE filesys SET type = 'FSGROUP' WHERE filsys_id = :id;
1490 rowcount = sqlca.sqlerrd[2];
1492 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1494 printf("Not fixed\n");
1495 modified("filesys");
1498 int show_fsg_nomember(void *id)
1500 EXEC SQL BEGIN DECLARE SECTION;
1501 int iid = (int)id, id1, found = 1;
1502 EXEC SQL END DECLARE SECTION;
1505 EXEC SQL DECLARE csr211 CURSOR FOR
1506 SELECT group_id FROM fsgroup
1507 WHERE filsys_id = :iid;
1508 EXEC SQL OPEN csr211;
1511 EXEC SQL FETCH csr211 INTO :id1;
1516 if ((f = hash_lookup(filesys, id1)))
1517 printf("FSGroup %s has missing member %d\n", f->name, iid);
1519 printf("FSGroup %d has missing member %d\n", id1, iid);
1521 EXEC SQL CLOSE csr211;
1525 int show_quota_nouser(void *id)
1527 EXEC SQL BEGIN DECLARE SECTION;
1528 int iid = (int)id, id1, found = 1;
1529 EXEC SQL END DECLARE SECTION;
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;
1537 EXEC SQL FETCH csr212 INTO :id1;
1542 printf("Quota on fs %d for non-existant user %d\n", id1, iid);
1544 EXEC SQL CLOSE csr212;
1548 int show_quota_nolist(void *id)
1550 EXEC SQL BEGIN DECLARE SECTION;
1551 int iid = (int)id, id1, found = 1;
1552 EXEC SQL END DECLARE SECTION;
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;
1560 EXEC SQL FETCH csr213 INTO :id1;
1565 printf("Quota on fs %d for non-existant list %d\n", id1, iid);
1567 EXEC SQL CLOSE csr213;
1571 void fix_quota_nouser(void *id)
1573 EXEC SQL BEGIN DECLARE SECTION;
1574 int iid = (int)id, rowcount;
1575 EXEC SQL END DECLARE SECTION;
1577 EXEC SQL DELETE FROM quota
1578 WHERE entity_id = :iid AND type = 'USER';
1579 rowcount = sqlca.sqlerrd[2];
1581 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1583 printf("Not deleted\n");
1587 void fix_quota_nolist(void *id)
1589 EXEC SQL BEGIN DECLARE SECTION;
1590 int iid = (int)id, rowcount;
1591 EXEC SQL END DECLARE SECTION;
1593 EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP';
1594 rowcount = sqlca.sqlerrd[2];
1596 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1598 printf("Not deleted\n");
1602 int show_quota_nofs(void *id)
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;
1609 EXEC SQL DECLARE csr214 CURSOR FOR
1610 SELECT entity_id, type FROM quota
1611 WHERE filsys_id = :iid;
1612 EXEC SQL OPEN csr214;
1615 EXEC SQL FETCH csr214 INTO :id1, :type;
1620 printf("Quota for %s %d on non-existant filesys %d\n", type, id1, iid);
1622 EXEC SQL CLOSE csr214;
1626 void fix_quota_nofs(void *id)
1628 single_delete("quota", "filsys_id", (int)id);
1631 int show_quota_wrongpid(void *id)
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;
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;
1646 EXEC SQL FETCH csr215 INTO :id1, :type;
1651 printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1652 type, id1, f->name, iid);
1654 EXEC SQL CLOSE csr215;
1658 void fix_quota_physid(void *id)
1660 EXEC SQL BEGIN DECLARE SECTION;
1661 int iid = (int)id, rowcount, id1;
1662 EXEC SQL END DECLARE SECTION;
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];
1669 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1671 printf("Not fixed\n");
1675 int show_srv_user(void *id)
1677 EXEC SQL BEGIN DECLARE SECTION;
1678 char name[SERVERS_NAME_SIZE];
1680 EXEC SQL END DECLARE SECTION;
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;
1689 EXEC SQL FETCH csr216 INTO :name;
1694 printf("Service %s has acl non-existant user %d\n", name, iid);
1697 EXEC SQL CLOSE csr216;
1701 int show_srv_list(void *id)
1703 EXEC SQL BEGIN DECLARE SECTION;
1704 char name[SERVERS_NAME_SIZE];
1706 EXEC SQL END DECLARE SECTION;
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;
1715 EXEC SQL FETCH csr217 INTO :name;
1720 printf("Service %s has acl non-existant list %d\n", name, iid);
1723 EXEC SQL CLOSE csr217;
1727 void zero_srv_user(void *id)
1729 EXEC SQL BEGIN DECLARE SECTION;
1730 int iid = (int)id, rowcount;
1731 EXEC SQL END DECLARE SECTION;
1733 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1735 rowcount = sqlca.sqlerrd[2];
1737 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1739 printf("Not fixed\n");
1740 modified("servers");
1743 void zero_srv_list(void *id)
1745 EXEC SQL BEGIN DECLARE SECTION;
1746 int iid = (int)id, rowcount;
1747 EXEC SQL END DECLARE SECTION;
1749 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1751 rowcount = sqlca.sqlerrd[2];
1753 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1755 printf("Not fixed\n");
1756 modified("servers");
1759 int show_krb_usr(void *id)
1761 EXEC SQL BEGIN DECLARE SECTION;
1762 int iid = (int)id, found = 1, id1;
1763 EXEC SQL END DECLARE SECTION;
1767 EXEC SQL DECLARE csr218 CURSOR FOR
1768 SELECT string_id FROM krbmap
1769 WHERE users_id = :iid;
1770 EXEC SQL OPEN csr218;
1773 EXEC SQL FETCH csr218 INTO :id1;
1777 if ((s = hash_lookup(strings, id1)))
1782 printf("Kerberos map for non-existant user %d to principal %s\n",
1785 EXEC SQL CLOSE csr218;
1789 int show_krb_str(void *id)
1791 EXEC SQL BEGIN DECLARE SECTION;
1792 int iid = (int)id, found = 1, id1;
1793 EXEC SQL END DECLARE SECTION;
1797 EXEC SQL DECLARE csr219 CURSOR FOR
1798 SELECT users_id FROM krbmap
1799 WHERE string_id = :iid;
1800 EXEC SQL OPEN csr219;
1803 EXEC SQL FETCH csr219 INTO :id1;
1807 if ((u = hash_lookup(users, id1)))
1812 printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1815 EXEC SQL CLOSE csr219;
1821 struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5, *sq6;
1828 printf("Phase 2 - Checking references\n");
1830 dprintf("Checking users...\n");
1831 hash_step(users, user_check, NULL);
1833 dprintf("Checking machines...\n");
1834 hash_step(machines, mach_check, NULL);
1836 dprintf("Checking subnets...\n");
1837 hash_step(subnets, subnet_check, NULL);
1839 dprintf("Checking clusters...\n");
1840 hash_step(clusters, cluster_check, NULL);
1842 dprintf("Checking mcmap...\n");
1845 EXEC SQL DECLARE csr221 CURSOR FOR
1846 SELECT mach_id, clu_id FROM mcmap;
1847 EXEC SQL OPEN csr221;
1850 EXEC SQL BEGIN DECLARE SECTION;
1851 int mach_id, clu_id;
1852 EXEC SQL END DECLARE SECTION;
1854 EXEC SQL FETCH csr221 INTO :mach_id, :clu_id;
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);
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);
1869 dprintf("Checking service clusters...\n");
1871 EXEC SQL DECLARE csr222 CURSOR FOR
1872 SELECT clu_id FROM svc;
1873 EXEC SQL OPEN csr222;
1876 EXEC SQL BEGIN DECLARE SECTION;
1878 EXEC SQL END DECLARE SECTION;
1880 EXEC SQL FETCH csr222 INTO :clu_id;
1884 if (!hash_lookup(clusters, clu_id))
1885 sq_save_unique_data(sq1, (void *)clu_id);
1887 EXEC SQL CLOSE csr222;
1888 generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1890 dprintf("Checking lists...\n");
1891 hash_step(lists, list_check, NULL);
1893 dprintf("Checking members...\n");
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;
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;
1911 EXEC SQL FETCH csr223 INTO :list_id, :type, :id, :tag,
1912 :ref_count, :direct, :rowid;
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);
1929 maybe_fixup_unref_string2("imembers", "tag", rowid, tag);
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);
1938 dprintf("Checking servers...\n");
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;
1947 EXEC SQL BEGIN DECLARE SECTION;
1949 char name[SERVERS_NAME_SIZE], acl_type[SERVERS_ACL_TYPE_SIZE];
1950 EXEC SQL END DECLARE SECTION;
1952 EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby, :rowid;
1956 maybe_fixup_modby2("servers", "modby", strtrim(rowid), modby);
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);
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);
1967 dprintf("Checking serverhosts...\n");
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;
1975 EXEC SQL BEGIN DECLARE SECTION;
1977 EXEC SQL END DECLARE SECTION;
1979 EXEC SQL FETCH csr225 INTO :mach_id, :modby, :rowid;
1983 maybe_fixup_modby2("serverhosts", "modby", strtrim(rowid), modby);
1984 if (!hash_lookup(machines, mach_id))
1985 sq_save_data(sq, (void *)mach_id);
1987 EXEC SQL CLOSE csr225;
1988 generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1990 dprintf("Checking nfsphys...\n");
1991 hash_step(nfsphys, check_nfsphys, NULL);
1993 dprintf("Checking filesys...\n");
1994 hash_step(filesys, check_fs, NULL);
1996 dprintf("Checking filesystem groups...\n");
2000 EXEC SQL DECLARE csr226 CURSOR FOR
2001 SELECT group_id, filsys_id FROM fsgroup;
2002 EXEC SQL OPEN csr226;
2005 EXEC SQL BEGIN DECLARE SECTION;
2006 int group_id, filsys_id;
2007 EXEC SQL END DECLARE SECTION;
2009 EXEC SQL FETCH csr226 INTO :group_id, :filsys_id;
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);
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);
2022 dprintf("Checking quotas...\n");
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;
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;
2038 EXEC SQL FETCH csr227 INTO :entity_id, :type, :filsys_id,
2039 :phys_id, :quota, :modby, :rowid;
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);
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);
2061 dprintf("Not checking zephyr.\n");
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;
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;
2075 EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby, :rowid;
2079 maybe_fixup_modby2("hostaccess", "modby", strtrim(rowid), modby);
2081 if (!hash_lookup(machines, mach_id))
2083 printf("Hostaccess for non-existant host %d\n", mach_id);
2084 printf("Not fixing this error\n");
2086 if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
2088 printf("Hostaccess for %d is non-existant user %d\n", mach_id, acl_id);
2089 printf("Not fixing this error\n");
2091 else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
2093 printf("Hostaccess for %d is non-existant list %d\n", mach_id, acl_id);
2094 printf("Not fixing this error\n");
2097 EXEC SQL CLOSE csr228;
2099 dprintf("Checking krbmap...\n");
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;
2108 EXEC SQL BEGIN DECLARE SECTION;
2109 int users_id, string_id;
2110 EXEC SQL END DECLARE SECTION;
2112 EXEC SQL FETCH csr230 INTO :users_id, :string_id, :rowid;
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);
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);
2125 dprintf("Checking capacls...\n");
2126 EXEC SQL DECLARE csr231 CURSOR FOR
2127 SELECT list_id, tag FROM capacls;
2128 EXEC SQL OPEN csr231;
2131 EXEC SQL BEGIN DECLARE SECTION;
2133 char tag[CAPACLS_TAG_SIZE];
2134 EXEC SQL END DECLARE SECTION;
2136 EXEC SQL FETCH csr231 INTO :list_id, :tag;
2140 if (!hash_lookup(lists, list_id))
2142 printf("Capacl for %s is non-existant list %d\n", tag, list_id);
2143 printf("Not fixing this error\n");
2146 EXEC SQL CLOSE csr231;
2148 dprintf("Checking hostaliases\n");
2150 EXEC SQL DECLARE csr232 CURSOR FOR
2151 SELECT mach_id FROM hostalias;
2152 EXEC SQL OPEN csr232;
2155 EXEC SQL BEGIN DECLARE SECTION;
2157 EXEC SQL END DECLARE SECTION;
2159 EXEC SQL FETCH csr232 INTO :mach_id;
2163 if (!hash_lookup(machines, mach_id))
2164 sq_save_unique_data(sq1, (void *)mach_id);
2166 EXEC SQL CLOSE csr232;
2167 generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
2169 dprintf("Checking printers\n");
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;
2181 EXEC SQL BEGIN DECLARE SECTION;
2182 int mach_id, loghost, rm, rq, ac, lpc_acl, modby;
2183 EXEC SQL END DECLARE SECTION;
2185 EXEC SQL FETCH csr233 INTO :mach_id, :loghost, :rm, :rq, :ac,
2186 :lpc_acl, :modby, :rowid;
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);
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))
2206 show_printer_loghost((void *)loghost);
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);
2219 dprintf("Checking printservers\n");
2220 hash_step(printservers, check_ps, NULL);