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 void fix_list_memacl(int id);
53 int show_member_list(void *id);
54 int show_mem_user(void *id);
55 int show_mem_list(void *id);
56 int show_mem_str(void *id);
57 int show_mem_krb(void *id);
58 void del_mem_user(void *id);
59 void del_mem_list(void *id);
60 void del_mem_str(void *id);
61 void del_mem_krb(void *id);
62 int show_sh(void *id);
63 void del_sh_mach(void *id);
64 void fsmatch(int id, void *nfsphys, void *filesys);
65 void check_fs(int id, void *filesys, void *hint);
66 void check_nfsphys(int id, void *nfsphys, void *hint);
67 void check_ps(int id, void *printserver, void *hint);
68 int show_fsg_missing(void *id);
69 int show_fsg_type(void *filesys);
70 void fix_fsg_type(void *filesys);
71 int show_fsg_nomember(void *id);
72 int show_quota_nouser(void *id);
73 int show_quota_nolist(void *id);
74 void fix_quota_nouser(void *id);
75 void fix_quota_nolist(void *id);
76 int show_quota_nofs(void *id);
77 void fix_quota_nofs(void *id);
78 int show_quota_wrongpid(void *id);
79 void fix_quota_physid(void *id);
80 int show_srv_user(void *id);
81 int show_srv_list(void *id);
82 void zero_srv_user(void *id);
83 void zero_srv_list(void *id);
84 int show_krb_usr(void *id);
85 int show_krb_str(void *id);
86 int show_pdm_mach(void *id);
88 int show_mcm_mach(void *id)
90 EXEC SQL BEGIN DECLARE SECTION;
91 int iid = (int)id, found = 1;
92 char name[CLUSTERS_NAME_SIZE];
93 EXEC SQL END DECLARE SECTION;
95 EXEC SQL DECLARE csr201 CURSOR FOR
96 SELECT clusters.name FROM clusters, mcmap
97 WHERE clusters.clu_id = mcmap.clu_id AND mcmap.mach_id = :iid;
101 EXEC SQL FETCH csr201 INTO :name;
107 printf("Cluster %s, non-existant machine %d in cluster map\n",
110 EXEC SQL CLOSE csr201;
114 int show_mcm_clu(void *id)
116 EXEC SQL BEGIN DECLARE SECTION;
117 int iid = (int)id, found = 1;
118 char name[MACHINE_NAME_SIZE];
119 EXEC SQL END DECLARE SECTION;
121 EXEC SQL DECLARE csr202 CURSOR FOR
122 SELECT machine.name FROM machine, mcmap
123 WHERE machine.mach_id = mcmap.mach_id AND mcmap.clu_id = :iid;
124 EXEC SQL OPEN csr202;
127 EXEC SQL FETCH csr202 INTO :name;
134 printf("Machine %s, non-existant cluster %d in cluster map\n",
137 EXEC SQL CLOSE csr202;
141 int show_hostalias(void *id)
143 EXEC SQL BEGIN DECLARE SECTION;
144 int iid = (int)id, found = 1;
145 char name[HOSTALIAS_NAME_SIZE];
146 EXEC SQL END DECLARE SECTION;
148 EXEC SQL DECLARE csr234 CURSOR FOR
149 SELECT name FROM hostalias WHERE mach_id = :iid;
150 EXEC SQL OPEN csr234;
153 EXEC SQL FETCH csr234 INTO :name;
160 printf("Alias %s, non-existant machine %d in hostalias map\n",
163 EXEC SQL CLOSE csr234;
167 int show_printer_mach(void *id)
169 EXEC SQL BEGIN DECLARE SECTION;
170 int iid = (int)id, found = 1;
171 char name[PRINTERS_NAME_SIZE];
172 EXEC SQL END DECLARE SECTION;
174 EXEC SQL DECLARE csr235 CURSOR FOR
175 SELECT name FROM printers WHERE mach_id = :iid;
176 EXEC SQL OPEN csr235;
179 EXEC SQL FETCH csr235 INTO :name;
186 printf("Printer %s, non-existant machine %d in printers table\n",
189 EXEC SQL CLOSE csr235;
193 int show_printer_server(void *id)
195 EXEC SQL BEGIN DECLARE SECTION;
196 int iid = (int)id, found = 1;
197 char name[PRINTERS_NAME_SIZE];
198 EXEC SQL END DECLARE SECTION;
200 EXEC SQL DECLARE csr_sps CURSOR FOR
201 SELECT name FROM printers WHERE mach_id = :iid;
202 EXEC SQL OPEN csr_sps;
205 EXEC SQL FETCH csr_sps INTO :name;
212 printf("Printer %s, non-existant printserver %d in printers table\n",
215 EXEC SQL CLOSE csr_sps;
219 int show_printer_loghost(void *id)
221 EXEC SQL BEGIN DECLARE SECTION;
222 int iid = (int)id, found = 1;
223 char name[PRINTERS_NAME_SIZE];
224 EXEC SQL END DECLARE SECTION;
226 EXEC SQL DECLARE csr236 CURSOR FOR
227 SELECT name FROM printers WHERE loghost = :iid;
228 EXEC SQL OPEN csr236;
231 EXEC SQL FETCH csr236 INTO :name;
238 printf("Printer %s, non-existant spool machine %d in printers table\n",
241 EXEC SQL CLOSE csr236;
245 int show_printer_spool(void *id)
247 EXEC SQL BEGIN DECLARE SECTION;
248 int iid = (int)id, found = 1;
249 char name[PRINTERS_NAME_SIZE];
250 EXEC SQL END DECLARE SECTION;
252 EXEC SQL DECLARE csr237 CURSOR FOR
253 SELECT name FROM printers WHERE rm = :iid;
254 EXEC SQL OPEN csr237;
257 EXEC SQL FETCH csr237 INTO :name;
264 printf("Printer %s, non-existant spool machine %d in printers table\n",
267 EXEC SQL CLOSE csr237;
271 int show_printer_quota(void *id)
273 EXEC SQL BEGIN DECLARE SECTION;
274 int iid = (int)id, found = 1;
275 char name[PRINTERS_NAME_SIZE];
276 EXEC SQL END DECLARE SECTION;
278 EXEC SQL DECLARE csr238 CURSOR FOR
279 SELECT name FROM printers WHERE rq = :iid;
280 EXEC SQL OPEN csr238;
283 EXEC SQL FETCH csr238 INTO :name;
290 printf("Printer %s, non-existant quota server %d in printers table\n",
293 EXEC SQL CLOSE csr238;
297 int show_printer_ac(void *id)
299 EXEC SQL BEGIN DECLARE SECTION;
300 int iid = (int)id, found = 1;
301 char name[PRINTERS_NAME_SIZE];
302 EXEC SQL END DECLARE SECTION;
304 EXEC SQL DECLARE csr239 CURSOR FOR
305 SELECT name FROM printers WHERE ac = :iid;
306 EXEC SQL OPEN csr239;
309 EXEC SQL FETCH csr239 INTO :name;
316 printf("Printer %s, non-existant restrict list %d in printers table\n",
319 EXEC SQL CLOSE csr239;
323 int show_printer_lpc_acl(void *id)
325 EXEC SQL BEGIN DECLARE SECTION;
326 int iid = (int)id, found = 1;
327 char name[PRINTERS_NAME_SIZE];
328 EXEC SQL END DECLARE SECTION;
330 EXEC SQL DECLARE csr240 CURSOR FOR
331 SELECT name FROM printers WHERE lpc_acl = :iid;
332 EXEC SQL OPEN csr240;
335 EXEC SQL FETCH csr240 INTO :name;
342 printf("Printer %s, non-existant lpc ACL %d in printers table\n",
345 EXEC SQL CLOSE csr240;
349 void fix_printer_ac(void *id)
351 EXEC SQL BEGIN DECLARE SECTION;
352 int rowcount, iid = (int)id;
353 EXEC SQL END DECLARE SECTION;
355 EXEC SQL UPDATE printers SET ac = 0 WHERE ac = :iid;
356 rowcount = sqlca.sqlerrd[2];
358 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
360 printf("Not fixed\n");
361 modified("printers");
364 void fix_printer_lpc_acl(void *id)
366 EXEC SQL BEGIN DECLARE SECTION;
367 int rowcount, iid = (int)id;
368 EXEC SQL END DECLARE SECTION;
370 EXEC SQL UPDATE printers SET lpc_acl = 0 WHERE lpc_acl = :iid;
371 rowcount = sqlca.sqlerrd[2];
373 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
375 printf("Not fixed\n");
376 modified("printers");
379 void user_check(int id, void *user, void *hint)
381 struct user *u = user;
383 u->comment = maybe_fixup_unref_string(u->comment, id, u->login, "users",
384 "comments", "users_id");
386 u->modby = maybe_fixup_modby(u->modby, id, u->login, "users",
387 "modby", "users_id");
389 u->fmodby = maybe_fixup_modby(u->fmodby, id, u->login, "users",
390 "fmodby", "users_id");
392 u->pmodby = maybe_fixup_modby(u->pmodby, id, u->login, "users",
393 "pmodby", "users_id");
395 u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
396 "sigwho", "users_id");
401 int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
402 char *field, char *idfield)
404 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
405 EXEC SQL BEGIN DECLARE SECTION;
408 EXEC SQL END DECLARE SECTION;
410 if ((newid = (int)hash_lookup(string_dups, ret)))
412 printf("%s entry %s(%d) has a %s with duplicate string %d\n",
413 table, oname, oid, field, ret);
414 if (single_fix("Replace duplicate", 0))
421 else if (!string_check(ret))
423 printf("%s entry %s(%d) has a %s with non-existant string %d\n",
424 table, oname, oid, field, ret);
425 if (single_fix("Delete", 1))
434 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d",
435 table, field, (sid < 0) ? -ret : ret, idfield, oid);
436 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
437 rowcount = sqlca.sqlerrd[2];
441 printf("Not fixed, rowcount = %d\n", rowcount);
445 return (sid < 0) ? -ret : ret;
448 int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
449 char *field, char *idfield)
451 EXEC SQL BEGIN DECLARE SECTION;
454 EXEC SQL END DECLARE SECTION;
457 return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
460 if (!hash_lookup(users, sid))
462 printf("%s entry %s(%d) has a %s with non-existant user %d\n",
463 table, oname, oid, field, sid);
464 if (single_fix("Delete", 1))
466 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d",
467 table, field, idfield, oid);
468 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
469 rowcount = sqlca.sqlerrd[2];
473 printf("Not fixed, rowcount = %d\n", rowcount);
482 int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid)
484 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
485 EXEC SQL BEGIN DECLARE SECTION;
488 EXEC SQL END DECLARE SECTION;
490 if ((newid = (int)hash_lookup(string_dups, ret)))
492 printf("%s entry has a %s with duplicate string %d\n",
494 if (single_fix("Replace duplicate", 0))
501 else if (!string_check(ret))
503 printf("%s entry has a %s with non-existant string %d\n",
505 if (single_fix("Clear", 1))
514 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE rowid = '%s'",
515 table, field, (sid < 0) ? -ret : ret, rowid);
516 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
517 rowcount = sqlca.sqlerrd[2];
521 printf("Not fixed, rowcount = %d\n", rowcount);
524 return (sid < 0) ? -ret : ret;
527 int maybe_fixup_modby2(char *table, char *field, char *rowid, int id)
529 EXEC SQL BEGIN DECLARE SECTION;
532 EXEC SQL END DECLARE SECTION;
535 return maybe_fixup_unref_string2(table, field, rowid, id);
538 if (!hash_lookup(users, id))
540 printf("%s entry has a %s with non-existant user %d\n",
542 if (single_fix("Clear", 1))
544 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE rowid = '%s'",
545 table, field, rowid);
546 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
547 rowcount = sqlca.sqlerrd[2];
551 printf("Not fixed, rowcount = %d\n", rowcount);
560 void pobox_check(int id, struct user *u)
567 if (!hash_lookup(machines, u->pobox_id))
569 printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
570 u->login, u->fullname, u->pobox_id);
571 if (single_fix("Delete", 0))
573 remove_pobox(u->users_id);
580 if (hash_lookup(string_dups, u->pobox_id))
582 printf("User %s(%s) has P.O.Box with duplicate string %d\n",
583 u->login, u->fullname, u->pobox_id);
584 if (single_fix("Update", 0))
586 printf("Replacing box_id dup string ID %d with %d\n",
588 (int)hash_lookup(string_dups, u->pobox_id));
589 u->pobox_id = (int)hash_lookup(string_dups, u->pobox_id);
590 fix_smtp_pobox(u->users_id, u->pobox_id);
591 string_check(u->pobox_id);
594 else if (!string_check(u->pobox_id))
596 printf("User %s(%s) has P.O.Box with non-existant string %d\n",
597 u->login, u->fullname, u->pobox_id);
598 if (single_fix("Delete", 0))
600 remove_pobox(u->users_id);
607 fs = hash_lookup(filesys, u->pobox_id);
610 printf("User %s(%s) has P.O.Box on non-existant filesystem %d\n",
611 u->login, u->fullname, u->pobox_id);
612 if (single_fix("Delete", 0))
614 remove_pobox(u->users_id);
618 else if (fs->type != 'I')
620 printf("User %s(%s) has IMAP P.O.Box on non-IMAP filesystem %s\n",
621 u->login, u->fullname, fs->name);
622 if (single_fix("Delete", 0))
624 remove_pobox(u->users_id);
636 void remove_pobox(int id)
638 EXEC SQL BEGIN DECLARE SECTION;
639 int rowcount, iid = (int)id;
640 EXEC SQL END DECLARE SECTION;
642 EXEC SQL UPDATE users SET potype = 'NONE' WHERE users.users_id = :iid;
643 rowcount = sqlca.sqlerrd[2];
645 printf("%d entr%s removed\n", rowcount, rowcount == 1 ? "y" : "ies");
647 printf("Not removed\n");
651 void fix_smtp_pobox(int id, int sid)
653 EXEC SQL BEGIN DECLARE SECTION;
654 int rowcount, iid = id, isid = sid;
655 EXEC SQL END DECLARE SECTION;
657 EXEC SQL UPDATE users SET box_id = :isid WHERE users.users_id = :iid;
658 rowcount = sqlca.sqlerrd[2];
660 printf("%d entr%s updated\n", rowcount, rowcount == 1 ? "y" : "ies");
662 printf("Not updated\n");
666 void mach_check(int id, void *machine, void *hint)
668 struct machine *m = machine;
670 if (!hash_lookup(subnets, m->snet_id))
672 printf("Machine %s is on a non-existant subnet %d\n",
673 m->name, m->snet_id);
674 if (single_fix("Move to null-subnet", 1))
676 EXEC SQL BEGIN DECLARE SECTION;
677 int rowcount, iid = id;
678 EXEC SQL END DECLARE SECTION;
680 EXEC SQL UPDATE machine SET snet_id = 0 WHERE mach_id = :iid;
681 rowcount = sqlca.sqlerrd[2];
683 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
685 printf("Not fixed\n");
690 switch (m->owner_type)
693 if (!hash_lookup(users, m->owner_id))
695 printf("Machine %s has non-existant USER owner %d\n",
696 m->name, m->owner_id);
697 if (single_fix("Set to no owner", 1))
702 if (!hash_lookup(lists, m->owner_id))
704 printf("Machine %s has non-existant LIST owner %d\n",
705 m->name, m->owner_id);
706 if (single_fix("Set to no owner", 1))
713 m->owner_id = maybe_fixup_unref_string(m->owner_id, id, m->name,
714 "machine", "owner_id",
716 if (m->owner_id == 0)
721 m->acomment = maybe_fixup_unref_string(m->acomment, id, m->name,
722 "machine", "acomment", "mach_id");
724 m->ocomment = maybe_fixup_unref_string(m->ocomment, id, m->name,
725 "machine", "ocomment", "mach_id");
727 m->creator = maybe_fixup_modby(m->creator, id, m->name, "machine",
728 "creator", "mach_id");
729 m->modby = maybe_fixup_modby(m->modby, id, m->name, "machine",
733 void subnet_check(int id, void *subnet, void *hint)
735 struct subnet *s = subnet;
737 switch (s->owner_type)
740 if (!hash_lookup(users, s->owner_id))
742 printf("Subnet %s has non-existant USER owner %d\n",
743 s->name, s->owner_id);
744 if (single_fix("Set to no owner", 1))
745 clear_subnet_owner(s);
749 if (!hash_lookup(lists, s->owner_id))
751 printf("Machine %s has non-existant LIST owner %d\n",
752 s->name, s->owner_id);
753 if (single_fix("Set to no owner", 1))
754 clear_subnet_owner(s);
760 s->owner_id = maybe_fixup_unref_string(s->owner_id, id, s->name,
761 "machine", "owner_id",
763 if (s->owner_id == 0)
764 clear_subnet_owner(s);
767 s->modby = maybe_fixup_modby(s->modby, id, s->name, "subnet",
771 void clear_subnet_owner(struct subnet *s)
773 EXEC SQL BEGIN DECLARE SECTION;
774 int rowcount, id = s->snet_id;
775 EXEC SQL END DECLARE SECTION;
777 EXEC SQL UPDATE subnet SET owner_type = 'NONE', owner_id = 0
779 rowcount = sqlca.sqlerrd[2];
781 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
783 printf("Not fixed\n");
787 void clear_mach_owner(struct machine *m)
789 EXEC SQL BEGIN DECLARE SECTION;
790 int rowcount, id = m->mach_id;
791 EXEC SQL END DECLARE SECTION;
793 EXEC SQL UPDATE machine SET owner_type = 'NONE', owner_id = 0
795 rowcount = sqlca.sqlerrd[2];
797 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
799 printf("Not fixed\n");
803 void cluster_check(int id, void *cluster, void *hint)
805 struct cluster *c = cluster;
807 c->modby = maybe_fixup_modby(c->modby, id, c->name, "clusters",
811 int show_svc(void *id)
813 EXEC SQL BEGIN DECLARE SECTION;
814 int iid = (int)id, found = 1;
815 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
816 EXEC SQL END DECLARE SECTION;
818 EXEC SQL DECLARE csr203 CURSOR FOR
819 SELECT serv_label, serv_cluster FROM svc
821 EXEC SQL OPEN csr203;
824 EXEC SQL FETCH csr203 INTO :label, :data;
831 printf("Cluster data [%s] %s for non-existant cluster %d\n",
834 EXEC SQL CLOSE csr203;
838 void list_check(int id, void *list, void *hint)
840 struct list *l = list;
842 l->modby = maybe_fixup_modby(l->modby, id, l->name, "list",
848 if (!hash_lookup(lists, l->acl_id))
850 printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
851 if (single_fix("Patch", 1))
852 fix_list_acl(l->list_id);
856 if (!hash_lookup(users, l->acl_id))
858 printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
859 if (single_fix("Patch", 1))
860 fix_list_acl(l->list_id);
864 l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
865 "list", "acl_id", "list_id");
868 printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id);
869 if (single_fix("Patch", 1))
870 fix_list_acl(l->list_id);
875 switch (l->memacl_type)
878 if (!hash_lookup(lists, l->memacl_id))
880 printf("List %s has bad LIST memacl %d\n", l->name, l->memacl_id);
881 if (single_fix("Patch", 1))
882 fix_list_memacl(l->list_id);
886 if (!hash_lookup(users, l->memacl_id))
888 printf("List %s has bad USER acl %d\n", l->name, l->memacl_id);
889 if (single_fix("Patch", 1))
890 fix_list_memacl(l->list_id);
894 l->memacl_id = maybe_fixup_unref_string(l->memacl_id, id, l->name,
895 "list", "memacl_id", "list_id");
898 printf("List %s has bad KERBEROS acl %d\n", l->name,
900 if (single_fix("Patch", 1))
901 fix_list_memacl(l->list_id);
907 void fix_list_acl(int id)
909 EXEC SQL BEGIN DECLARE SECTION;
910 int rowcount, iid = (int)id;
911 EXEC SQL END DECLARE SECTION;
913 EXEC SQL UPDATE list SET acl_id = :iid, acl_type = 'LIST'
914 WHERE list_id = :iid;
915 rowcount = sqlca.sqlerrd[2];
917 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
919 printf("Not fixed\n");
923 void fix_list_memacl(int id)
925 EXEC SQL BEGIN DECLARE SECTION;
926 int rowcount, iid = (int)id;
927 EXEC SQL END DECLARE SECTION;
929 EXEC SQL UPDATE list SET memacl_id = 0, memacl_type = 'NONE'
930 WHERE list_id = :iid;
931 rowcount = sqlca.sqlerrd[2];
933 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
935 printf("Not fixed\n");
939 int show_member_list(void *id)
941 EXEC SQL BEGIN DECLARE SECTION;
942 int mid, iid = (int)id, found = 1;
943 char mtype[IMEMBERS_MEMBER_TYPE_SIZE], *name = NULL;
944 EXEC SQL END DECLARE SECTION;
946 EXEC SQL DECLARE csr204 CURSOR FOR
947 SELECT member_type, member_id FROM imembers
948 WHERE list_id = :iid;
949 EXEC SQL OPEN csr204;
952 EXEC SQL FETCH csr204 INTO :mtype, :mid;
960 struct list *l = hash_lookup(lists, mid);
964 else if (mtype[0] == 'U')
966 struct user *u = hash_lookup(users, mid);
970 else if (mtype[0] == 'S' || mtype[0] == 'K')
972 struct string *s = hash_lookup(strings, mid);
977 printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
980 printf("Non-existant list %d has non-existent member %s %d\n",
984 EXEC SQL CLOSE csr204;
988 int show_mem_user(void *id)
990 EXEC SQL BEGIN DECLARE SECTION;
991 int lid, iid = (int)id, found = 1;
992 EXEC SQL END DECLARE SECTION;
995 EXEC SQL DECLARE csr205 CURSOR FOR
996 SELECT list_id FROM imembers
997 WHERE member_id = :iid AND member_type = 'USER';
998 EXEC SQL OPEN csr205;
1001 EXEC SQL FETCH csr205 INTO :lid;
1004 l = hash_lookup(lists, lid);
1009 printf("List %s has non-existant user member, id %d\n", l->name, iid);
1011 EXEC SQL CLOSE csr205;
1015 int show_mem_list(void *id)
1017 EXEC SQL BEGIN DECLARE SECTION;
1018 int lid, iid = (int)id, found = 1;
1019 EXEC SQL END DECLARE SECTION;
1022 EXEC SQL DECLARE csr206 CURSOR FOR
1023 SELECT list_id FROM imembers
1024 WHERE member_id = :iid AND member_type = 'LIST';
1025 EXEC SQL OPEN csr206;
1028 EXEC SQL FETCH csr206 INTO :lid;
1031 l = hash_lookup(lists, lid);
1036 printf("List %s has non-existant list member, id %d\n", l->name, iid);
1038 EXEC SQL CLOSE csr206;
1042 int show_mem_str(void *id)
1044 EXEC SQL BEGIN DECLARE SECTION;
1045 int lid, iid = (int)id, found = 1;
1046 EXEC SQL END DECLARE SECTION;
1049 EXEC SQL DECLARE csr207 CURSOR FOR
1050 SELECT list_id FROM imembers
1051 WHERE member_id = :iid AND member_type = 'STRING';
1052 EXEC SQL OPEN csr207;
1055 EXEC SQL FETCH csr207 INTO :lid;
1058 l = hash_lookup(lists, lid);
1063 printf("List %s has non-existant string member, id %d\n", l->name, iid);
1065 EXEC SQL CLOSE csr207;
1070 int show_mem_krb(void *id)
1072 EXEC SQL BEGIN DECLARE SECTION;
1073 int lid, iid = (int)id, found = 1;
1074 EXEC SQL END DECLARE SECTION;
1077 EXEC SQL DECLARE csr208 CURSOR FOR
1078 SELECT list_id FROM imembers
1079 WHERE member_id = :iid AND member_type = 'KERBEROS';
1080 EXEC SQL OPEN csr208;
1083 EXEC SQL FETCH csr208 INTO :lid;
1086 l = hash_lookup(lists, lid);
1091 printf("List %s has non-existant kerberos member, id %d\n",
1094 EXEC SQL CLOSE csr208;
1099 void del_mem_user(void *id)
1101 EXEC SQL BEGIN DECLARE SECTION;
1102 int iid = (int)id, rowcount;
1103 EXEC SQL END DECLARE SECTION;
1105 EXEC SQL DELETE FROM imembers WHERE member_type = 'USER' AND
1107 rowcount = sqlca.sqlerrd[2];
1109 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1111 printf("Not deleted\n");
1112 modified("imembers");
1115 void del_mem_list(void *id)
1117 EXEC SQL BEGIN DECLARE SECTION;
1118 int iid = (int)id, rowcount;
1119 EXEC SQL END DECLARE SECTION;
1121 EXEC SQL DELETE FROM imembers WHERE member_type = 'LIST' AND
1123 rowcount = sqlca.sqlerrd[2];
1125 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1127 printf("Not deleted\n");
1128 modified("imembers");
1131 void del_mem_str(void *id)
1133 EXEC SQL BEGIN DECLARE SECTION;
1134 int iid = (int)id, rowcount;
1135 EXEC SQL END DECLARE SECTION;
1137 EXEC SQL DELETE FROM imembers WHERE member_type = 'STRING' AND
1139 rowcount = sqlca.sqlerrd[2];
1141 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1143 printf("Not deleted\n");
1144 modified("imembers");
1148 void del_mem_krb(void *id)
1150 EXEC SQL BEGIN DECLARE SECTION;
1151 int iid = (int)id, rowcount;
1152 EXEC SQL END DECLARE SECTION;
1154 EXEC SQL DELETE FROM imembers WHERE member_type = 'KERBEROS' AND
1156 rowcount = sqlca.sqlerrd[2];
1158 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1160 printf("Not deleted\n");
1161 modified("imembers");
1165 int show_sh(void *id)
1167 EXEC SQL BEGIN DECLARE SECTION;
1168 char name[SERVERHOSTS_SERVICE_SIZE];
1170 EXEC SQL END DECLARE SECTION;
1173 EXEC SQL DECLARE csr209 CURSOR FOR
1174 SELECT service FROM serverhosts
1175 WHERE mach_id = :iid;
1176 EXEC SQL OPEN csr209;
1179 EXEC SQL FETCH csr209 INTO :name;
1184 printf("ServerHost entry for service %s non-existant host %d\n",
1187 EXEC SQL CLOSE csr209;
1191 void del_sh_mach(void *id)
1193 EXEC SQL BEGIN DECLARE SECTION;
1194 int iid = (int)id, rowcount;
1195 EXEC SQL END DECLARE SECTION;
1197 EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
1198 rowcount = sqlca.sqlerrd[2];
1200 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1202 printf("Not deleted\n");
1203 modified("serverhosts");
1207 static int fnchecklen;
1209 void fsmatch(int id, void *nfsphys, void *filesys)
1211 struct nfsphys *n = nfsphys;
1212 struct filesys *f = filesys;
1214 if (n->mach_id == f->mach_id &&
1215 !strncmp(f->dir, n->dir, strlen(n->dir)) &&
1216 strlen(n->dir) > fnchecklen)
1219 fnchecklen = strlen(n->dir);
1224 void check_fs(int id, void *filesys, void *hint)
1226 EXEC SQL BEGIN DECLARE SECTION;
1227 int iid = id, id1, id2, id3, rowcount;
1229 EXEC SQL END DECLARE SECTION;
1230 struct filesys *f = filesys;
1234 if (!hash_lookup(machines, f->mach_id))
1236 printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
1237 if (single_fix("Fix", 0))
1239 EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
1240 rowcount = sqlca.sqlerrd[2];
1242 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1244 printf("Not fixed\n");
1245 modified("filesys");
1250 if (!hash_lookup(users, f->owner))
1252 printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
1253 if (single_fix("Fix", 1))
1255 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
1259 if (!hash_lookup(lists, f->owners))
1261 printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
1262 if (single_fix("Fix", 1))
1264 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
1269 if (f->type == 'N' || f->type == 'I')
1271 if (!hash_lookup(nfsphys, f->phys_id))
1273 m = hash_lookup(machines, f->mach_id);
1274 printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
1275 if (single_fix("Fix", 1))
1278 hash_step(nfsphys, fsmatch, f);
1279 if (fnchecklen != 0)
1284 EXEC SQL UPDATE filesys SET phys_id = :id1
1285 WHERE filsys_id = :id2;
1286 rowcount = sqlca.sqlerrd[2];
1288 printf("%d entr%s fixed\n", rowcount,
1289 rowcount == 1 ? "y" : "ies");
1291 printf("Not fixed\n");
1292 modified("filesys");
1296 printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
1297 if (single_fix("Create", 0))
1303 if (set_next_object_id("nfsphys_id", "nfsphys") !=
1306 printf("Unable to assign unique ID\n");
1309 EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
1310 WHERE name = 'nfsphys_id';
1313 printf("Unable to retrieve unique ID\n");
1316 EXEC SQL INSERT INTO nfsphys
1317 (nfsphys_id, mach_id, device, dir, status, allocated,
1318 size, modtime, modby, modwith) VALUES
1319 (:id1, :id3, '\?\?\?', :dir, 0, 0, 0, SYSDATE, 0,
1321 rowcount = sqlca.sqlerrd[2];
1324 printf("%d entr%s created\n", rowcount,
1325 rowcount == 1 ? "y" : "ies");
1328 printf("Not created\n");
1329 modified("nfsphys");
1330 n = malloc(sizeof(struct nfsphys));
1332 out_of_mem("storing new nfsphys");
1333 strcpy(n->dir, dir);
1335 n->nfsphys_id = id1;
1338 if (hash_store(nfsphys, id1, n) == -1)
1339 out_of_mem("storing nfsphys in hash table");
1340 EXEC SQL UPDATE filesys SET phys_id = :id1
1341 WHERE filsys_id = :id2;
1342 rowcount = sqlca.sqlerrd[2];
1345 printf("%d filesys entr%s fixed\n", rowcount,
1346 rowcount == 1 ? "y" : "ies");
1349 printf("Not fixed\n");
1350 modified("filesys");
1358 void check_nfsphys(int id, void *nfsphys, void *hint)
1360 struct nfsphys *n = nfsphys;
1362 n->modby = maybe_fixup_modby(n->modby, id, n->dir, "nfsphys",
1363 "modby", "nfsphys_id");
1365 if (!hash_lookup(machines, n->mach_id))
1367 printf("NFSphys %d(%s) on non-existant machine %d\n",
1368 id, n->dir, n->mach_id);
1369 if (single_fix("Delete", 0))
1370 single_delete("nfsphys", "nfsphys_id", id);
1374 static void clear_ps_owner(struct printserver *ps)
1376 EXEC SQL BEGIN DECLARE SECTION;
1377 int rowcount, id = ps->mach_id;
1378 EXEC SQL END DECLARE SECTION;
1380 EXEC SQL UPDATE printserver SET owner_type = 'NONE', owner_id = 0
1381 WHERE mach_id = :id;
1382 rowcount = sqlca.sqlerrd[2];
1384 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1386 printf("Not fixed\n");
1387 modified("printservers");
1390 static void clear_ps_lpc(struct printserver *ps)
1392 EXEC SQL BEGIN DECLARE SECTION;
1393 int rowcount, id = ps->mach_id;
1394 EXEC SQL END DECLARE SECTION;
1396 EXEC SQL UPDATE printserver SET lpc_acl = 0
1397 WHERE mach_id = :id;
1398 rowcount = sqlca.sqlerrd[2];
1400 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1402 printf("Not fixed\n");
1403 modified("printservers");
1406 void check_ps(int id, void *printserver, void *hint)
1408 struct printserver *ps = printserver;
1412 m = hash_lookup(machines, id);
1415 printf("Printserver on non-existant machine %d\n", id);
1416 if (single_fix("Delete", 0))
1418 single_delete("printservers", "mach_id", id);
1427 ps->modby = maybe_fixup_modby(ps->modby, id, name, "printservers",
1428 "modby", "mach_id");
1429 ps->printer_types = maybe_fixup_unref_string(ps->printer_types, id, name,
1430 "printservers", "printer_types",
1433 switch (ps->owner_type)
1436 if (!hash_lookup(users, ps->owner_id))
1438 printf("Printserver %s has non-existant USER owner %d\n",
1439 name, ps->owner_id);
1440 if (single_fix("Set to no owner", 1))
1445 if (!hash_lookup(lists, ps->owner_id))
1447 printf("Printserver %s has non-existant LIST owner %d\n",
1448 name, ps->owner_id);
1449 if (single_fix("Set to no owner", 1))
1455 ps->owner_id = maybe_fixup_unref_string(ps->owner_id, id, name,
1456 "printserver", "owner_id",
1458 if (ps->owner_id == 0)
1462 if (!hash_lookup(lists, ps->lpc_acl))
1464 printf("Printserver %s has non-existent lpc_acl %d\n",
1466 if (single_fix("Set to no lpc_acl", 1))
1471 int show_fsg_missing(void *id)
1473 EXEC SQL BEGIN DECLARE SECTION;
1474 int iid = (int)id, id1, found = 1;
1475 EXEC SQL END DECLARE SECTION;
1478 EXEC SQL DECLARE csr210 CURSOR FOR
1479 SELECT filsys_id FROM fsgroup
1480 WHERE group_id = :iid;
1481 EXEC SQL OPEN csr210;
1484 EXEC SQL FETCH csr210 INTO :id1;
1489 if ((f = hash_lookup(filesys, id1)))
1490 printf("Missing fsgroup %d has member filesystem %s\n", iid, f->name);
1492 printf("Missing fsgroup %d has member filesystem %d\n", iid, id1);
1494 EXEC SQL CLOSE csr210;
1498 int show_fsg_type(void *filesys)
1500 struct filesys *f = filesys;
1526 printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1530 void fix_fsg_type(void *filesys)
1532 struct filesys *f = filesys;
1533 EXEC SQL BEGIN DECLARE SECTION;
1534 int rowcount, id = f->filsys_id;
1535 EXEC SQL END DECLARE SECTION;
1537 EXEC SQL UPDATE filesys SET type = 'FSGROUP' WHERE filsys_id = :id;
1538 rowcount = sqlca.sqlerrd[2];
1540 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1542 printf("Not fixed\n");
1543 modified("filesys");
1546 int show_fsg_nomember(void *id)
1548 EXEC SQL BEGIN DECLARE SECTION;
1549 int iid = (int)id, id1, found = 1;
1550 EXEC SQL END DECLARE SECTION;
1553 EXEC SQL DECLARE csr211 CURSOR FOR
1554 SELECT group_id FROM fsgroup
1555 WHERE filsys_id = :iid;
1556 EXEC SQL OPEN csr211;
1559 EXEC SQL FETCH csr211 INTO :id1;
1564 if ((f = hash_lookup(filesys, id1)))
1565 printf("FSGroup %s has missing member %d\n", f->name, iid);
1567 printf("FSGroup %d has missing member %d\n", id1, iid);
1569 EXEC SQL CLOSE csr211;
1573 int show_quota_nouser(void *id)
1575 EXEC SQL BEGIN DECLARE SECTION;
1576 int iid = (int)id, id1, found = 1;
1577 EXEC SQL END DECLARE SECTION;
1579 EXEC SQL DECLARE csr212 CURSOR FOR
1580 SELECT filsys_id FROM quota
1581 WHERE entity_id = :iid AND type = 'USER';
1582 EXEC SQL OPEN csr212;
1585 EXEC SQL FETCH csr212 INTO :id1;
1590 printf("Quota on fs %d for non-existant user %d\n", id1, iid);
1592 EXEC SQL CLOSE csr212;
1596 int show_quota_nolist(void *id)
1598 EXEC SQL BEGIN DECLARE SECTION;
1599 int iid = (int)id, id1, found = 1;
1600 EXEC SQL END DECLARE SECTION;
1602 EXEC SQL DECLARE csr213 CURSOR FOR
1603 SELECT filsys_id FROM quota
1604 WHERE entity_id = :iid AND type = 'GROUP';
1605 EXEC SQL OPEN csr213;
1608 EXEC SQL FETCH csr213 INTO :id1;
1613 printf("Quota on fs %d for non-existant list %d\n", id1, iid);
1615 EXEC SQL CLOSE csr213;
1619 void fix_quota_nouser(void *id)
1621 EXEC SQL BEGIN DECLARE SECTION;
1622 int iid = (int)id, rowcount;
1623 EXEC SQL END DECLARE SECTION;
1625 EXEC SQL DELETE FROM quota
1626 WHERE entity_id = :iid AND type = 'USER';
1627 rowcount = sqlca.sqlerrd[2];
1629 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1631 printf("Not deleted\n");
1635 void fix_quota_nolist(void *id)
1637 EXEC SQL BEGIN DECLARE SECTION;
1638 int iid = (int)id, rowcount;
1639 EXEC SQL END DECLARE SECTION;
1641 EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP';
1642 rowcount = sqlca.sqlerrd[2];
1644 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1646 printf("Not deleted\n");
1650 int show_quota_nofs(void *id)
1652 EXEC SQL BEGIN DECLARE SECTION;
1653 int iid = (int)id, id1, found = 1;
1654 char type[QUOTA_TYPE_SIZE];
1655 EXEC SQL END DECLARE SECTION;
1657 EXEC SQL DECLARE csr214 CURSOR FOR
1658 SELECT entity_id, type FROM quota
1659 WHERE filsys_id = :iid;
1660 EXEC SQL OPEN csr214;
1663 EXEC SQL FETCH csr214 INTO :id1, :type;
1668 printf("Quota for %s %d on non-existant filesys %d\n", type, id1, iid);
1670 EXEC SQL CLOSE csr214;
1674 void fix_quota_nofs(void *id)
1676 single_delete("quota", "filsys_id", (int)id);
1679 int show_quota_wrongpid(void *id)
1681 EXEC SQL BEGIN DECLARE SECTION;
1682 int iid = (int)id, id1, found = 1;
1683 char type[QUOTA_TYPE_SIZE];
1684 EXEC SQL END DECLARE SECTION;
1687 f = hash_lookup(filesys, iid);
1688 EXEC SQL DECLARE csr215 CURSOR FOR
1689 SELECT entity_id, type FROM quota
1690 WHERE filsys_id = :iid;
1691 EXEC SQL OPEN csr215;
1694 EXEC SQL FETCH csr215 INTO :id1, :type;
1699 printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1700 type, id1, f->name, iid);
1702 EXEC SQL CLOSE csr215;
1706 void fix_quota_physid(void *id)
1708 EXEC SQL BEGIN DECLARE SECTION;
1709 int iid = (int)id, rowcount, id1;
1710 EXEC SQL END DECLARE SECTION;
1712 id1 = ((struct filesys *)hash_lookup(filesys, iid))->phys_id;
1713 EXEC SQL UPDATE quota SET phys_id = :id1
1714 WHERE filsys_id = :iid AND phys_id != :id1;
1715 rowcount = sqlca.sqlerrd[2];
1717 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1719 printf("Not fixed\n");
1723 int show_srv_user(void *id)
1725 EXEC SQL BEGIN DECLARE SECTION;
1726 char name[SERVERS_NAME_SIZE];
1728 EXEC SQL END DECLARE SECTION;
1731 EXEC SQL DECLARE csr216 CURSOR FOR
1732 SELECT name FROM servers
1733 WHERE acl_type = 'USER' and acl_id = :iid;
1734 EXEC SQL OPEN csr216;
1737 EXEC SQL FETCH csr216 INTO :name;
1742 printf("Service %s has acl non-existant user %d\n", name, iid);
1745 EXEC SQL CLOSE csr216;
1749 int show_srv_list(void *id)
1751 EXEC SQL BEGIN DECLARE SECTION;
1752 char name[SERVERS_NAME_SIZE];
1754 EXEC SQL END DECLARE SECTION;
1757 EXEC SQL DECLARE csr217 CURSOR FOR
1758 SELECT name FROM servers
1759 WHERE acl_type = 'LIST' AND acl_id = :iid;
1760 EXEC SQL OPEN csr217;
1763 EXEC SQL FETCH csr217 INTO :name;
1768 printf("Service %s has acl non-existant list %d\n", name, iid);
1771 EXEC SQL CLOSE csr217;
1775 void zero_srv_user(void *id)
1777 EXEC SQL BEGIN DECLARE SECTION;
1778 int iid = (int)id, rowcount;
1779 EXEC SQL END DECLARE SECTION;
1781 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1783 rowcount = sqlca.sqlerrd[2];
1785 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1787 printf("Not fixed\n");
1788 modified("servers");
1791 void zero_srv_list(void *id)
1793 EXEC SQL BEGIN DECLARE SECTION;
1794 int iid = (int)id, rowcount;
1795 EXEC SQL END DECLARE SECTION;
1797 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1799 rowcount = sqlca.sqlerrd[2];
1801 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1803 printf("Not fixed\n");
1804 modified("servers");
1807 int show_krb_usr(void *id)
1809 EXEC SQL BEGIN DECLARE SECTION;
1810 int iid = (int)id, found = 1, id1;
1811 EXEC SQL END DECLARE SECTION;
1815 EXEC SQL DECLARE csr218 CURSOR FOR
1816 SELECT string_id FROM krbmap
1817 WHERE users_id = :iid;
1818 EXEC SQL OPEN csr218;
1821 EXEC SQL FETCH csr218 INTO :id1;
1825 if ((s = hash_lookup(strings, id1)))
1830 printf("Kerberos map for non-existant user %d to principal %s\n",
1833 EXEC SQL CLOSE csr218;
1837 int show_krb_str(void *id)
1839 EXEC SQL BEGIN DECLARE SECTION;
1840 int iid = (int)id, found = 1, id1;
1841 EXEC SQL END DECLARE SECTION;
1845 EXEC SQL DECLARE csr219 CURSOR FOR
1846 SELECT users_id FROM krbmap
1847 WHERE string_id = :iid;
1848 EXEC SQL OPEN csr219;
1851 EXEC SQL FETCH csr219 INTO :id1;
1855 if ((u = hash_lookup(users, id1)))
1860 printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1863 EXEC SQL CLOSE csr219;
1869 struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5, *sq6;
1876 printf("Phase 2 - Checking references\n");
1878 dprintf("Checking users...\n");
1879 hash_step(users, user_check, NULL);
1881 dprintf("Checking machines...\n");
1882 hash_step(machines, mach_check, NULL);
1884 dprintf("Checking subnets...\n");
1885 hash_step(subnets, subnet_check, NULL);
1887 dprintf("Checking clusters...\n");
1888 hash_step(clusters, cluster_check, NULL);
1890 dprintf("Checking mcmap...\n");
1893 EXEC SQL DECLARE csr221 CURSOR FOR
1894 SELECT mach_id, clu_id FROM mcmap;
1895 EXEC SQL OPEN csr221;
1898 EXEC SQL BEGIN DECLARE SECTION;
1899 int mach_id, clu_id;
1900 EXEC SQL END DECLARE SECTION;
1902 EXEC SQL FETCH csr221 INTO :mach_id, :clu_id;
1906 if (!(m = hash_lookup(machines, mach_id)))
1907 sq_save_unique_data(sq1, (void *)mach_id);
1908 else if (!hash_lookup(clusters, clu_id))
1909 sq_save_unique_data(sq2, (void *)clu_id);
1913 EXEC SQL CLOSE csr221;
1914 generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1915 generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1917 dprintf("Checking service clusters...\n");
1919 EXEC SQL DECLARE csr222 CURSOR FOR
1920 SELECT clu_id FROM svc;
1921 EXEC SQL OPEN csr222;
1924 EXEC SQL BEGIN DECLARE SECTION;
1926 EXEC SQL END DECLARE SECTION;
1928 EXEC SQL FETCH csr222 INTO :clu_id;
1932 if (!hash_lookup(clusters, clu_id))
1933 sq_save_unique_data(sq1, (void *)clu_id);
1935 EXEC SQL CLOSE csr222;
1936 generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1938 dprintf("Checking lists...\n");
1939 hash_step(lists, list_check, NULL);
1941 dprintf("Checking members...\n");
1948 EXEC SQL DECLARE csr223 CURSOR FOR
1949 SELECT list_id, member_type, member_id, tag, ref_count, direct, rowid
1950 FROM imembers FOR UPDATE OF member_id;
1951 EXEC SQL OPEN csr223;
1954 EXEC SQL BEGIN DECLARE SECTION;
1955 int list_id, id, tag, ref_count, direct;
1956 char type[IMEMBERS_MEMBER_TYPE_SIZE];
1957 EXEC SQL END DECLARE SECTION;
1959 EXEC SQL FETCH csr223 INTO :list_id, :type, :id, :tag,
1960 :ref_count, :direct, :rowid;
1965 if (!(l = hash_lookup(lists, list_id)))
1966 sq_save_unique_data(sq1, (void *)list_id);
1967 else if (type[0] == 'U' && !hash_lookup(users, id))
1968 sq_save_unique_data(sq2, (void *)id);
1969 else if (type[0] == 'L' && !hash_lookup(lists, id))
1970 sq_save_unique_data(sq3, (void *)id);
1971 else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
1972 sq_save_unique_data(sq4, (void *)id);
1973 else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
1974 sq_save_unique_data(sq5, (void *)id);
1977 maybe_fixup_unref_string2("imembers", "tag", rowid, tag);
1979 EXEC SQL CLOSE csr223;
1980 generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1981 generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1982 generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1983 generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1984 generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1986 dprintf("Checking servers...\n");
1989 EXEC SQL DECLARE csr224 CURSOR FOR
1990 SELECT name, acl_type, acl_id, modby, rowid FROM servers
1991 FOR UPDATE of modby;
1992 EXEC SQL OPEN csr224;
1995 EXEC SQL BEGIN DECLARE SECTION;
1997 char name[SERVERS_NAME_SIZE], acl_type[SERVERS_ACL_TYPE_SIZE];
1998 EXEC SQL END DECLARE SECTION;
2000 EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby, :rowid;
2004 maybe_fixup_modby2("servers", "modby", strtrim(rowid), modby);
2006 if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
2007 sq_save_data(sq1, (void *)acl_id);
2008 else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
2009 sq_save_data(sq2, (void *)acl_id);
2011 EXEC SQL CLOSE csr224;
2012 generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
2013 generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
2015 dprintf("Checking serverhosts...\n");
2017 EXEC SQL DECLARE csr225 CURSOR FOR
2018 SELECT mach_id, modby, rowid FROM serverhosts
2019 FOR UPDATE OF modby;
2020 EXEC SQL OPEN csr225;
2023 EXEC SQL BEGIN DECLARE SECTION;
2025 EXEC SQL END DECLARE SECTION;
2027 EXEC SQL FETCH csr225 INTO :mach_id, :modby, :rowid;
2031 maybe_fixup_modby2("serverhosts", "modby", strtrim(rowid), modby);
2032 if (!hash_lookup(machines, mach_id))
2033 sq_save_data(sq, (void *)mach_id);
2035 EXEC SQL CLOSE csr225;
2036 generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
2038 dprintf("Checking nfsphys...\n");
2039 hash_step(nfsphys, check_nfsphys, NULL);
2041 dprintf("Checking filesys...\n");
2042 hash_step(filesys, check_fs, NULL);
2044 dprintf("Checking filesystem groups...\n");
2048 EXEC SQL DECLARE csr226 CURSOR FOR
2049 SELECT group_id, filsys_id FROM fsgroup;
2050 EXEC SQL OPEN csr226;
2053 EXEC SQL BEGIN DECLARE SECTION;
2054 int group_id, filsys_id;
2055 EXEC SQL END DECLARE SECTION;
2057 EXEC SQL FETCH csr226 INTO :group_id, :filsys_id;
2061 if (!(f = hash_lookup(filesys, group_id)))
2062 sq_save_data(sq1, (void *)group_id);
2063 if (!hash_lookup(filesys, filsys_id))
2064 sq_save_data(sq3, (void *)filsys_id);
2066 EXEC SQL CLOSE csr226;
2067 generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
2068 generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
2070 dprintf("Checking quotas...\n");
2075 EXEC SQL DECLARE csr227 CURSOR FOR
2076 SELECT entity_id, type, filsys_id, phys_id, quota, modby, rowid
2077 FROM quota FOR UPDATE OF modby;
2078 EXEC SQL OPEN csr227;
2081 EXEC SQL BEGIN DECLARE SECTION;
2082 int entity_id, filsys_id, phys_id, quota, modby;
2083 char type[QUOTA_TYPE_SIZE];
2084 EXEC SQL END DECLARE SECTION;
2086 EXEC SQL FETCH csr227 INTO :entity_id, :type, :filsys_id,
2087 :phys_id, :quota, :modby, :rowid;
2091 maybe_fixup_modby2("quota", "modby", strtrim(rowid), modby);
2092 if (type[0] == 'U' && entity_id != 0 && !hash_lookup(users, entity_id))
2093 sq_save_data(sq1, (void *)entity_id);
2094 else if (type[0] == 'G' && !hash_lookup(lists, entity_id))
2095 sq_save_data(sq4, (void *)entity_id);
2096 else if (!(f = hash_lookup(filesys, filsys_id)))
2097 sq_save_data(sq2, (void *)filsys_id);
2098 else if (phys_id != f->phys_id || !(n = hash_lookup(nfsphys, phys_id)))
2099 sq_save_data(sq3, (void *)phys_id);
2103 EXEC SQL CLOSE csr227;
2104 generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
2105 generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
2106 generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
2107 generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
2109 dprintf("Checking zephyr...\n");
2110 EXEC SQL DECLARE csr_zc CURSOR FOR
2111 SELECT class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id,
2112 iui_type, iui_id, modby FROM zephyr;
2113 EXEC SQL OPEN csr_zc;
2116 EXEC SQL BEGIN DECLARE SECTION;
2117 int xmt_id, sub_id, iws_id, iui_id, modby;
2118 char class[ZEPHYR_CLASS_SIZE];
2119 char xmt_type[ZEPHYR_XMT_TYPE_SIZE];
2120 char sub_type[ZEPHYR_SUB_TYPE_SIZE];
2121 char iws_type[ZEPHYR_IWS_TYPE_SIZE];
2122 char iui_type[ZEPHYR_IUI_TYPE_SIZE];
2123 EXEC SQL END DECLARE SECTION;
2125 EXEC SQL FETCH csr_zc INTO :class, :xmt_type, :xmt_id, :sub_type,
2126 :sub_id, :iws_type, :iws_id, :iui_type, :iui_id, :modby;
2131 maybe_fixup_modby2("zephyr", "modby", strtrim(rowid), modby);
2134 if (!strcmp(xmt_type, "USER") && !hash_lookup(users, xmt_id))
2136 printf("xmt acl for %s is non-existant user %d\n", class, xmt_id);
2137 printf("Not fixing this error\n");
2139 else if (!strcmp(xmt_type, "LIST") && !hash_lookup(lists, xmt_id))
2141 printf("xmt acl for %s is non-existant list %d\n", class, xmt_id);
2142 printf("Not fixing this error\n");
2144 else if (!strcmp(xmt_type, "STRING") || !strcmp(xmt_type, "KERBEROS"))
2145 maybe_fixup_unref_string2("zephyr", "xmt_id", strtrim(rowid), xmt_id);
2148 if (!strcmp(sub_type, "USER") && !hash_lookup(users, sub_id))
2150 printf("sub acl for %s is non-existant user %d\n", class, sub_id);
2151 printf("Not fixing this error\n");
2153 else if (!strcmp(sub_type, "LIST") && !hash_lookup(lists, sub_id))
2155 printf("sub acl for %s is non-existant list %d\n", class, sub_id);
2156 printf("Not fixing this error\n");
2158 else if (!strcmp(sub_type, "STRING") || !strcmp(sub_type, "KERBEROS"))
2159 maybe_fixup_unref_string2("zephyr", "sub_id", strtrim(rowid), sub_id);
2162 if (!strcmp(iws_type, "USER") && !hash_lookup(users, iws_id))
2164 printf("iws acl for %s is non-existant user %d\n", class, iws_id);
2165 printf("Not fixing this error\n");
2167 else if (!strcmp(iws_type, "LIST") && !hash_lookup(lists, iws_id))
2169 printf("iws acl for %s is non-existant list %d\n", class, iws_id);
2170 printf("Not fixing this error\n");
2172 else if (!strcmp(iws_type, "STRING") || !strcmp(iws_type, "KERBEROS"))
2173 maybe_fixup_unref_string2("zephyr", "iws_id", strtrim(rowid), iws_id);
2176 if (!strcmp(iui_type, "USER") && !hash_lookup(users, iui_id))
2178 printf("iui acl for %s is non-existant user %d\n", class, iui_id);
2179 printf("Not fixing this error\n");
2181 else if (!strcmp(iui_type, "LIST") && !hash_lookup(lists, iui_id))
2183 printf("iui acl for %s is non-existant list %d\n", class, iui_id);
2184 printf("Not fixing this error\n");
2186 else if (!strcmp(iui_type, "STRING") || !strcmp(iui_type, "KERBEROS"))
2187 maybe_fixup_unref_string2("zephyr", "iui_id", strtrim(rowid), iui_id);
2190 dprintf("Checking hostaccess...\n");
2191 EXEC SQL DECLARE csr228 CURSOR FOR
2192 SELECT mach_id, acl_type, acl_id, modby, rowid FROM hostaccess
2193 FOR UPDATE OF modby;
2194 EXEC SQL OPEN csr228;
2197 EXEC SQL BEGIN DECLARE SECTION;
2198 int mach_id, acl_id, modby;
2199 char acl_type[HOSTACCESS_ACL_TYPE_SIZE];
2200 EXEC SQL END DECLARE SECTION;
2202 EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby, :rowid;
2206 maybe_fixup_modby2("hostaccess", "modby", strtrim(rowid), modby);
2208 if (!hash_lookup(machines, mach_id))
2210 printf("Hostaccess for non-existant host %d\n", mach_id);
2211 printf("Not fixing this error\n");
2213 if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
2215 printf("Hostaccess for %d is non-existant user %d\n", mach_id, acl_id);
2216 printf("Not fixing this error\n");
2218 else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
2220 printf("Hostaccess for %d is non-existant list %d\n", mach_id, acl_id);
2221 printf("Not fixing this error\n");
2224 EXEC SQL CLOSE csr228;
2226 dprintf("Checking krbmap...\n");
2229 EXEC SQL DECLARE csr230 CURSOR FOR
2230 SELECT users_id, string_id, rowid FROM krbmap
2231 FOR UPDATE OF string_id;
2232 EXEC SQL OPEN csr230;
2235 EXEC SQL BEGIN DECLARE SECTION;
2236 int users_id, string_id;
2237 EXEC SQL END DECLARE SECTION;
2239 EXEC SQL FETCH csr230 INTO :users_id, :string_id, :rowid;
2243 if (!hash_lookup(users, users_id))
2244 sq_save_unique_data(sq1, (void *)users_id);
2245 else if (!maybe_fixup_unref_string2("krbmap", "string_id", strtrim(rowid), string_id))
2246 sq_save_unique_data(sq2, (void *)string_id);
2248 EXEC SQL CLOSE csr230;
2249 generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
2250 generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
2252 dprintf("Checking capacls...\n");
2253 EXEC SQL DECLARE csr231 CURSOR FOR
2254 SELECT list_id, tag FROM capacls;
2255 EXEC SQL OPEN csr231;
2258 EXEC SQL BEGIN DECLARE SECTION;
2260 char tag[CAPACLS_TAG_SIZE];
2261 EXEC SQL END DECLARE SECTION;
2263 EXEC SQL FETCH csr231 INTO :list_id, :tag;
2267 if (!hash_lookup(lists, list_id))
2269 printf("Capacl for %s is non-existant list %d\n", tag, list_id);
2270 printf("Not fixing this error\n");
2273 EXEC SQL CLOSE csr231;
2275 dprintf("Checking hostaliases\n");
2277 EXEC SQL DECLARE csr232 CURSOR FOR
2278 SELECT mach_id FROM hostalias;
2279 EXEC SQL OPEN csr232;
2282 EXEC SQL BEGIN DECLARE SECTION;
2284 EXEC SQL END DECLARE SECTION;
2286 EXEC SQL FETCH csr232 INTO :mach_id;
2290 if (!hash_lookup(machines, mach_id))
2291 sq_save_unique_data(sq1, (void *)mach_id);
2293 EXEC SQL CLOSE csr232;
2294 generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
2296 dprintf("Checking printers\n");
2303 EXEC SQL DECLARE csr233 CURSOR FOR
2304 SELECT mach_id, loghost, rm, rq, ac, lpc_acl, modby, rowid FROM printers;
2305 EXEC SQL OPEN csr233;
2308 EXEC SQL BEGIN DECLARE SECTION;
2309 int mach_id, loghost, rm, rq, ac, lpc_acl, modby;
2310 EXEC SQL END DECLARE SECTION;
2312 EXEC SQL FETCH csr233 INTO :mach_id, :loghost, :rm, :rq, :ac,
2313 :lpc_acl, :modby, :rowid;
2317 maybe_fixup_modby2("printers", "modby", strtrim(rowid), modby);
2318 if (!hash_lookup(machines, mach_id))
2319 sq_save_unique_data(sq1, (void *)mach_id);
2320 else if (!hash_lookup(machines, rm))
2321 sq_save_unique_data(sq2, (void *)rm);
2322 else if (!hash_lookup(printservers, rm))
2323 sq_save_unique_data(sq6, (void *)mach_id);
2324 else if (!hash_lookup(machines, rq))
2325 sq_save_unique_data(sq3, (void *)rq);
2327 if (!hash_lookup(lists, ac))
2328 sq_save_unique_data(sq4, (void *)ac);
2329 if (!hash_lookup(lists, lpc_acl))
2330 sq_save_unique_data(sq5, (void *)lpc_acl);
2331 if (!hash_lookup(machines, loghost))
2333 show_printer_loghost((void *)loghost);
2338 EXEC SQL CLOSE csr233;
2339 generic_delete(sq1, show_printer_mach, "printers", "mach_id", 1);
2340 generic_delete(sq6, show_printer_server, "printers", "mach_id", 1);
2341 generic_delete(sq2, show_printer_spool, "printers", "rm", 1);
2342 generic_delete(sq3, show_printer_quota, "printers", "rq", 1);
2343 generic_fix(sq4, show_printer_ac, "Clear", fix_printer_ac, 1);
2344 generic_fix(sq5, show_printer_lpc_acl, "Clear", fix_printer_lpc_acl, 1);
2346 dprintf("Checking printservers\n");
2347 hash_step(printservers, check_ps, NULL);