3 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
13 EXEC SQL INCLUDE sqlca;
15 static char phase2_qc_rcsid[] = "$Header$";
17 EXEC SQL WHENEVER SQLERROR DO dbmserr();
19 int show_mcm_mach(int id)
21 EXEC SQL BEGIN DECLARE SECTION;
22 int iid = id, found = 1;
24 EXEC SQL END DECLARE SECTION;
26 EXEC SQL DECLARE csr201 CURSOR FOR
27 SELECT clusters.name FROM clusters, mcmap
28 WHERE clusters.clu_id = mcmap.clu_id AND mcmap.mach_id = :iid;
32 EXEC SQL FETCH csr201 INTO :name;
38 printf("Cluster %s, non-existant machine %d in cluster map\n", name, id);
40 EXEC SQL CLOSE csr201;
44 int show_mcm_clu(int id)
46 EXEC SQL BEGIN DECLARE SECTION;
47 int iid = id, found = 1;
49 EXEC SQL END DECLARE SECTION;
51 EXEC SQL DECLARE csr202 CURSOR FOR
52 SELECT machine.name FROM machine, mcmap
53 WHERE machine.mach_id = mcmap.mach_id AND mcmap.clu_id = :iid;
57 EXEC SQL FETCH csr202 INTO :name;
64 printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
66 EXEC SQL CLOSE csr202;
70 int show_hostalias(int id)
72 EXEC SQL BEGIN DECLARE SECTION;
73 int iid = id, found = 1;
75 EXEC SQL END DECLARE SECTION;
77 EXEC SQL DECLARE csr234 CURSOR FOR
78 SELECT name FROM hostalias WHERE mach_id = :iid;
82 EXEC SQL FETCH csr234 INTO :name;
89 printf("Alias %s, non-existant machine %d in hostalias map\n", name, id);
91 EXEC SQL CLOSE csr234;
95 int show_pcap_mach(int id)
97 EXEC SQL BEGIN DECLARE SECTION;
98 int iid = id, found = 1;
100 EXEC SQL END DECLARE SECTION;
102 EXEC SQL DECLARE csr235 CURSOR FOR
103 SELECT name FROM printcap WHERE mach_id = :iid;
104 EXEC SQL OPEN csr235;
107 EXEC SQL FETCH csr235 INTO :name;
114 printf("Printer %s, non-existant spool machine %d in printcap table\n",
117 EXEC SQL CLOSE csr235;
121 int show_pcap_quota(int id)
123 EXEC SQL BEGIN DECLARE SECTION;
124 int iid = id, found = 1;
126 EXEC SQL END DECLARE SECTION;
128 EXEC SQL DECLARE csr236 CURSOR FOR
129 SELECT name FROM printcap WHERE quotaserver = :iid;
130 EXEC SQL OPEN csr236;
133 EXEC SQL FETCH csr236 INTO :name;
140 printf("Printer %s, non-existant quota server %d in printcap table\n",
143 EXEC SQL CLOSE csr236;
147 user_check(int id, struct user *u, int hint)
149 u->comment = maybe_fixup_unref_string(u->comment, id, u->login, "users",
150 "comments", "users_id");
152 u->modby = maybe_fixup_modby(u->modby, id, u->login, "users",
153 "modby", "users_id");
155 u->fmodby = maybe_fixup_modby(u->fmodby, id, u->login, "users",
156 "fmodby", "users_id");
158 u->pmodby = maybe_fixup_modby(u->pmodby, id, u->login, "users",
159 "pmodby", "users_id");
161 u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
162 "sigwho", "users_id");
164 pobox_check(id, u, hint);
167 int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
168 char *field, char *idfield)
170 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
171 EXEC SQL BEGIN DECLARE SECTION;
174 EXEC SQL END DECLARE SECTION;
176 if (newid = int_hash_lookup(string_dups, ret))
178 printf("%s entry %s(%d) has a %s with duplicate string %d\n",
179 table, oname, oid, field, ret);
180 if (single_fix("Replace duplicate", 0))
187 else if (!string_check(ret))
189 printf("%s entry %s(%d) has a %s with non-existant string %d\n",
190 table, oname, oid, field, ret);
191 if (single_fix("Delete", 1))
200 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d",
201 table, field, (sid < 0) ? -ret : ret, idfield, oid);
202 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
203 rowcount = sqlca.sqlerrd[2];
207 printf("Not fixed, rowcount = %d\n", rowcount);
211 return (sid < 0) ? -ret : ret;
214 int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
215 char *field, char *idfield)
217 EXEC SQL BEGIN DECLARE SECTION;
220 EXEC SQL END DECLARE SECTION;
223 return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
226 if (!hash_lookup(users, sid))
228 printf("%s entry %s(%d) has a %s with non-existant user %d\n",
229 table, oname, oid, field, sid);
230 if (single_fix("Delete", 1))
232 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d",
233 table, field, idfield, oid);
234 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
235 rowcount = sqlca.sqlerrd[2];
239 printf("Not fixed, rowcount = %d\n", rowcount);
248 int maybe_fixup_unref_string2(char *table, char *field, char *cursor, int sid)
250 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
251 EXEC SQL BEGIN DECLARE SECTION;
254 EXEC SQL END DECLARE SECTION;
256 if ((newid = int_hash_lookup(string_dups, ret)))
258 printf("%s entry has a %s with duplicate string %d\n",
260 if (single_fix("Replace duplicate", 0))
267 else if (!string_check(ret))
269 printf("%s entry has a %s with non-existant string %d\n",
271 if (single_fix("Delete", 1))
280 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s",
281 table, field, (sid < 0) ? -ret : ret, cursor);
282 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
283 rowcount = sqlca.sqlerrd[2];
287 printf("Not fixed, rowcount = %d\n", rowcount);
290 return (sid < 0) ? -ret : ret;
293 int maybe_fixup_modby2(char *table, char *field, char *cursor, int id)
295 EXEC SQL BEGIN DECLARE SECTION;
298 EXEC SQL END DECLARE SECTION;
301 return maybe_fixup_unref_string2(table, field, cursor, id);
304 if (!hash_lookup(users, id))
306 printf("%s entry has a %s with non-existant user %d\n",
308 if (single_fix("Delete", 1))
310 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE CURRENT OF %s",
311 table, field, cursor);
312 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
313 rowcount = sqlca.sqlerrd[2];
317 printf("Not fixed, rowcount = %d\n", rowcount);
326 pobox_check(int id, struct user *u, int hint)
331 if (!hash_lookup(machines, u->pobox_id))
333 printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
334 u->login, u->fullname, u->pobox_id);
335 if (single_fix("Delete", 0))
337 remove_pobox(u->users_id);
343 if (int_hash_lookup(string_dups, u->pobox_id))
345 printf("User %s(%s) has P.O.Box with duplicate string %d\n",
346 u->login, u->fullname, u->pobox_id);
347 if (single_fix("Update", 0))
349 printf("Replacing box_id dup string ID %d with %d\n",
351 int_hash_lookup(string_dups, u->pobox_id));
352 u->pobox_id = int_hash_lookup(string_dups, u->pobox_id);
353 fix_smtp_pobox(u->users_id, u->pobox_id);
354 string_check(u->pobox_id);
357 else if (!string_check(u->pobox_id))
359 printf("User %s(%s) has P.O.Box with non-existant string %d\n",
360 u->login, u->fullname, u->pobox_id);
361 if (single_fix("Delete", 0))
363 remove_pobox(u->users_id);
376 EXEC SQL BEGIN DECLARE SECTION;
377 int rowcount, iid = id;
378 EXEC SQL END DECLARE SECTION;
380 EXEC SQL UPDATE users SET potype = 'NONE' WHERE users.users_id = :iid;
381 rowcount = sqlca.sqlerrd[2];
383 printf("%d entr%s removed\n", rowcount, rowcount == 1 ? "y" : "ies");
385 printf("Not removed\n");
389 fix_smtp_pobox(int id, int sid)
391 EXEC SQL BEGIN DECLARE SECTION;
392 int rowcount, iid = id, isid = sid;
393 EXEC SQL END DECLARE SECTION;
395 EXEC SQL UPDATE users SET box_id = :isid WHERE users.users_id = :iid;
396 rowcount = sqlca.sqlerrd[2];
398 printf("%d entr%s updated\n", rowcount, rowcount == 1 ? "y" : "ies");
400 printf("Not updated\n");
404 mach_check(int id, struct machine *m, int hint)
406 if (!hash_lookup(subnets, m->snet_id))
408 printf("Machine %s is on a non-existant subnet %d\n",
409 m->name, m->snet_id);
410 if (single_fix("Move to null-subnet", 1))
412 EXEC SQL BEGIN DECLARE SECTION;
413 int rowcount, iid = id;
414 EXEC SQL END DECLARE SECTION;
416 EXEC SQL UPDATE machine SET snet_id = 0 WHERE mach_id = :iid;
417 rowcount = sqlca.sqlerrd[2];
419 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
421 printf("Not fixed\n");
426 switch (m->owner_type)
429 if (!hash_lookup(users, m->owner_id))
431 printf("Machine %s has non-existant USER owner %d\n",
432 m->name, m->owner_id);
433 if (single_fix("Set to no owner", 1))
438 if (!hash_lookup(lists, m->owner_id))
440 printf("Machine %s has non-existant LIST owner %d\n",
441 m->name, m->owner_id);
442 if (single_fix("Set to no owner", 1))
449 m->owner_id = maybe_fixup_unref_string(m->owner_id, id, m->name,
450 "machine", "owner_id",
452 if (m->owner_id == 0)
457 m->acomment = maybe_fixup_unref_string(m->acomment, id, m->name,
458 "machine", "acomment", "mach_id");
460 m->ocomment = maybe_fixup_unref_string(m->ocomment, id, m->name,
461 "machine", "ocomment", "mach_id");
463 m->creator = maybe_fixup_modby(m->creator, id, m->name, "machine",
464 "creator", "mach_id");
465 m->modby = maybe_fixup_modby(m->modby, id, m->name, "machine",
469 subnet_check(int id, struct subnet *s, int hint)
471 switch (s->owner_type)
474 if (!hash_lookup(users, s->owner_id))
476 printf("Subnet %s has non-existant USER owner %d\n",
477 s->name, s->owner_id);
478 if (single_fix("Set to no owner", 1))
479 clear_subnet_owner(s);
483 if (!hash_lookup(lists, s->owner_id))
485 printf("Machine %s has non-existant LIST owner %d\n",
486 s->name, s->owner_id);
487 if (single_fix("Set to no owner", 1))
488 clear_subnet_owner(s);
494 s->owner_id = maybe_fixup_unref_string(s->owner_id, id, s->name,
495 "machine", "owner_id",
497 if (s->owner_id == 0)
498 clear_subnet_owner(s);
501 s->modby = maybe_fixup_modby(s->modby, id, s->name, "subnet",
505 clear_subnet_owner(struct subnet *s)
507 EXEC SQL BEGIN DECLARE SECTION;
508 int rowcount, id = s->snet_id;
509 EXEC SQL END DECLARE SECTION;
511 EXEC SQL UPDATE subnet SET owner_type = 'NONE', owner_id = 0
513 rowcount = sqlca.sqlerrd[2];
515 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
517 printf("Not fixed\n");
521 clear_mach_owner(struct machine *m)
523 EXEC SQL BEGIN DECLARE SECTION;
524 int rowcount, id = m->mach_id;
525 EXEC SQL END DECLARE SECTION;
527 EXEC SQL UPDATE machine SET owner_type = 'NONE', owner_id = 0
529 rowcount = sqlca.sqlerrd[2];
531 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
533 printf("Not fixed\n");
537 cluster_check(int id, struct cluster *c, int hint)
539 c->modby = maybe_fixup_modby(c->modby, id, c->name, "clusters",
545 EXEC SQL BEGIN DECLARE SECTION;
546 int iid = id, found = 1;
547 char label[17], data[33];
548 EXEC SQL END DECLARE SECTION;
550 EXEC SQL DECLARE csr203 CURSOR FOR
551 SELECT serv_label, serv_cluster FROM svc
553 EXEC SQL OPEN csr203;
556 EXEC SQL FETCH csr203 INTO :label, :data;
563 printf("Cluster data [%s] %s for non-existant cluster %d\n",
566 EXEC SQL CLOSE csr203;
570 list_check(int id, struct list *l, int hint)
575 if (!hash_lookup(lists, l->acl_id))
577 printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
578 if (single_fix("Patch", 1))
579 fix_list_acl(l->list_id);
583 if (!hash_lookup(users, l->acl_id))
585 printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
586 if (single_fix("Patch", 1))
587 fix_list_acl(l->list_id);
591 l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
592 "list", "acl_id", "list_id");
595 printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id);
596 if (single_fix("Patch", 1))
597 fix_list_acl(l->list_id);
605 EXEC SQL BEGIN DECLARE SECTION;
606 int rowcount, iid = id;
607 EXEC SQL END DECLARE SECTION;
609 EXEC SQL UPDATE list SET acl_id = :iid, acl_type = 'LIST'
610 WHERE list_id = :iid;
611 rowcount = sqlca.sqlerrd[2];
613 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
615 printf("Not fixed\n");
619 int show_member_list(int id)
621 EXEC SQL BEGIN DECLARE SECTION;
622 int mid, iid = id, found = 1;
623 char mtype[9], *name = "";
624 EXEC SQL END DECLARE SECTION;
626 EXEC SQL DECLARE csr204 CURSOR FOR
627 SELECT member_type, member_id FROM imembers
628 WHERE list_id = :iid AND direct = 1;
629 EXEC SQL OPEN csr204;
632 EXEC SQL FETCH csr204 INTO :mtype, :mid;
639 name = ((struct list *) hash_lookup(lists, mid))->name;
640 else if (mtype[0] == 'U')
641 name = ((struct user *) hash_lookup(users, mid))->login;
642 else if (mtype[0] == 'S' || mtype[0] == 'K')
643 name = ((struct string *) hash_lookup(strings, mid))->name;
644 printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
646 EXEC SQL CLOSE csr204;
650 int show_mem_user(int id)
652 EXEC SQL BEGIN DECLARE SECTION;
653 int lid, iid = id, found = 1;
655 EXEC SQL END DECLARE SECTION;
657 EXEC SQL DECLARE csr205 CURSOR FOR
658 SELECT list_id FROM imembers
659 WHERE member_id = :iid AND member_type = 'USER' AND direct = 1;
660 EXEC SQL OPEN csr205;
663 EXEC SQL FETCH csr205 INTO :lid;
668 printf("List %s has non-existant user member, id %d\n",
669 ((struct list *)hash_lookup(lists, lid))->name, iid);
671 EXEC SQL CLOSE csr205;
675 int show_mem_list(int id)
677 EXEC SQL BEGIN DECLARE SECTION;
678 int lid, iid = id, found = 1;
680 EXEC SQL END DECLARE SECTION;
682 EXEC SQL DECLARE csr206 CURSOR FOR
683 SELECT list_id FROM imembers
684 WHERE member_id = :iid AND member_type = 'LIST' AND direct = 1;
685 EXEC SQL OPEN csr206;
688 EXEC SQL FETCH csr206 INTO :lid;
693 printf("List %s has non-existant list member, id %d\n",
694 ((struct list *)hash_lookup(lists, lid))->name, iid);
696 EXEC SQL CLOSE csr206;
700 int show_mem_str(int id)
702 EXEC SQL BEGIN DECLARE SECTION;
703 int lid, iid = id, found = 1;
705 EXEC SQL END DECLARE SECTION;
707 EXEC SQL DECLARE csr207 CURSOR FOR
708 SELECT list_id FROM imembers
709 WHERE member_id = :iid AND member_type = 'STRING' AND direct = 1;
710 EXEC SQL OPEN csr207;
713 EXEC SQL FETCH csr207 INTO :lid;
718 printf("List %s has non-existant string member, id %d\n",
719 ((struct list *)hash_lookup(lists, lid))->name, iid);
721 EXEC SQL CLOSE csr207;
726 int show_mem_krb(int id)
728 EXEC SQL BEGIN DECLARE SECTION;
729 int lid, iid = id, found = 1;
731 EXEC SQL END DECLARE SECTION;
733 EXEC SQL DECLARE csr208 CURSOR FOR
734 SELECT list_id FROM imembers
735 WHERE member_id = :iid AND member_type = 'KERBEROS' AND direct = 1;
736 EXEC SQL OPEN csr208;
739 EXEC SQL FETCH csr208 INTO :lid;
744 printf("List %s has non-existant kerberos member, id %d\n",
745 ((struct list *)hash_lookup(lists, lid))->name, iid);
747 EXEC SQL CLOSE csr208;
754 EXEC SQL BEGIN DECLARE SECTION;
755 int iid = id, rowcount;
756 EXEC SQL END DECLARE SECTION;
758 EXEC SQL DELETE FROM imembers WHERE member_type = 'USER' AND
759 member_id = :iid AND direct = 1;
760 rowcount = sqlca.sqlerrd[2];
762 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
764 printf("Not deleted\n");
765 modified("imembers");
770 EXEC SQL BEGIN DECLARE SECTION;
771 int iid = id, rowcount;
772 EXEC SQL END DECLARE SECTION;
774 EXEC SQL DELETE FROM imembers WHERE member_type = 'LIST' AND
775 member_id = :iid AND direct = 1;
776 rowcount = sqlca.sqlerrd[2];
778 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
780 printf("Not deleted\n");
781 modified("imembers");
786 EXEC SQL BEGIN DECLARE SECTION;
787 int iid = id, rowcount;
788 EXEC SQL END DECLARE SECTION;
790 EXEC SQL DELETE FROM imembers WHERE member_type = 'STRING' AND
791 member_id = :iid AND direct = 1;
792 rowcount = sqlca.sqlerrd[2];
794 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
796 printf("Not deleted\n");
797 modified("imembers");
803 EXEC SQL BEGIN DECLARE SECTION;
804 int iid = id, rowcount;
805 EXEC SQL END DECLARE SECTION;
807 EXEC SQL DELETE FROM imembers WHERE member_type = 'KERBEROS' AND
808 member_id = :iid AND direct = 1;
809 rowcount = sqlca.sqlerrd[2];
811 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
813 printf("Not deleted\n");
814 modified("imembers");
820 EXEC SQL BEGIN DECLARE SECTION;
823 EXEC SQL END DECLARE SECTION;
826 EXEC SQL DECLARE csr209 CURSOR FOR
827 SELECT service FROM serverhosts
828 WHERE mach_id = :iid;
829 EXEC SQL OPEN csr209;
832 EXEC SQL FETCH csr209 INTO :name;
837 printf("ServerHost entry for service %s non-existant host %d\n",
840 EXEC SQL CLOSE csr209;
846 EXEC SQL BEGIN DECLARE SECTION;
847 int iid = id, rowcount;
848 EXEC SQL END DECLARE SECTION;
850 EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
851 rowcount = sqlca.sqlerrd[2];
853 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
855 printf("Not deleted\n");
856 modified("serverhosts");
860 static int fnchecklen;
862 fsmatch(int id, struct nfsphys *n, struct filesys *f)
864 if (n->mach_id == f->mach_id &&
865 !strncmp(f->dir, n->dir, strlen(n->dir)) &&
866 strlen(n->dir) > fnchecklen)
869 fnchecklen = strlen(n->dir);
874 check_fs(int id, register struct filesys *f, int hint)
876 EXEC SQL BEGIN DECLARE SECTION;
877 int iid = id, id1, id2, id3, rowcount;
879 EXEC SQL END DECLARE SECTION;
883 if (!hash_lookup(machines, f->mach_id))
885 printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
886 if (single_fix("Fix", 0))
888 EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
889 rowcount = sqlca.sqlerrd[2];
891 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
893 printf("Not fixed\n");
899 if (!hash_lookup(users, f->owner))
901 printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
902 if (single_fix("Fix", 1))
904 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
908 if (!hash_lookup(lists, f->owners))
910 printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
911 if (single_fix("Fix", 1))
913 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
920 if (!hash_lookup(nfsphys, f->phys_id))
922 m = (struct machine *)hash_lookup(machines, f->mach_id);
923 printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
924 if (single_fix("Fix", 1))
927 hash_step(nfsphys, fsmatch, f);
933 EXEC SQL UPDATE filesys SET phys_id = :id1
934 WHERE filsys_id = :id2;
935 rowcount = sqlca.sqlerrd[2];
937 printf("%d entr%s fixed\n", rowcount,
938 rowcount == 1 ? "y" : "ies");
940 printf("Not fixed\n");
945 printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
946 if (single_fix("Create", 0))
952 if (set_next_object_id("nfsphys_id", "nfsphys") !=
955 printf("Unable to assign unique ID\n");
958 EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
959 WHERE name = 'nfsphys_id';
962 printf("Unable to retrieve unique ID\n");
965 EXEC SQL INSERT INTO nfsphys
966 (nfsphys_id, mach_id, device, dir, status, allocated,
967 size, modtime, modby, modwith) VALUES
968 (:id1, :id3, '\?\?\?', :dir, 0, 0, 0, SYSDATE, 0,
970 rowcount = sqlca.sqlerrd[2];
973 printf("%d entr%s created\n", rowcount,
974 rowcount == 1 ? "y" : "ies");
977 printf("Not created\n");
979 n = malloc(sizeof(struct nfsphys));
981 out_of_mem("storing new nfsphys");
987 if (hash_store(nfsphys, id1, n) == -1)
988 out_of_mem("storing nfsphys in hash table");
989 EXEC SQL UPDATE filesys SET phys_id = :id1
990 WHERE filsys_id = :id2;
991 rowcount = sqlca.sqlerrd[2];
994 printf("%d filesys entr%s fixed\n", rowcount,
995 rowcount == 1 ? "y" : "ies");
998 printf("Not fixed\n");
1007 check_nfsphys(int id, struct nfsphys *n, int hint)
1009 if (!hash_lookup(machines, n->mach_id))
1011 printf("NFSphys %d(%s) on non-existant machine %d\n",
1012 id, n->dir, n->mach_id);
1013 if (single_fix("Delete", 0))
1014 single_delete("nfsphys", "nfsphys_id", id);
1018 int show_fsg_missing(int id)
1020 EXEC SQL BEGIN DECLARE SECTION;
1021 int iid = id, id1, found = 1;
1022 EXEC SQL END DECLARE SECTION;
1025 EXEC SQL DECLARE csr210 CURSOR FOR
1026 SELECT filsys_id FROM fsgroup
1027 WHERE group_id = :iid;
1028 EXEC SQL OPEN csr210;
1031 EXEC SQL FETCH csr210 INTO :id1;
1036 if (f = (struct filesys *) hash_lookup(filesys, id1))
1037 printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
1039 printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
1041 EXEC SQL CLOSE csr210;
1045 int show_fsg_type(struct filesys *f)
1072 printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1076 fix_fsg_type(struct filesys *f)
1078 EXEC SQL BEGIN DECLARE SECTION;
1079 int rowcount, id = f->filsys_id;
1080 EXEC SQL END DECLARE SECTION;
1082 EXEC SQL UPDATE filesys SET type = 'FSGROUP' WHERE filsys_id = :id;
1083 rowcount = sqlca.sqlerrd[2];
1085 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1087 printf("Not fixed\n");
1088 modified("filesys");
1091 int show_fsg_nomember(int id)
1093 EXEC SQL BEGIN DECLARE SECTION;
1094 int iid = id, id1, found = 1;
1095 EXEC SQL END DECLARE SECTION;
1098 EXEC SQL DECLARE csr211 CURSOR FOR
1099 SELECT group_id FROM fsgroup
1100 WHERE filsys_id = :iid;
1101 EXEC SQL OPEN csr211;
1104 EXEC SQL FETCH csr211 INTO :id1;
1109 if (f = (struct filesys *) hash_lookup(filesys, id1))
1110 printf("FSGroup %s has missing member %d\n", f->name, id);
1112 printf("FSGroup %d has missing member %d\n", id1, id);
1114 EXEC SQL CLOSE csr211;
1118 int show_quota_nouser(int id)
1120 EXEC SQL BEGIN DECLARE SECTION;
1121 int iid = id, id1, found = 1;
1122 EXEC SQL END DECLARE SECTION;
1124 EXEC SQL DECLARE csr212 CURSOR FOR
1125 SELECT filsys_id FROM quota
1126 WHERE entity_id = :iid AND type = 'USER';
1127 EXEC SQL OPEN csr212;
1130 EXEC SQL FETCH csr212 INTO :id1;
1135 printf("Quota on fs %d for non-existant user %d\n", id1, id);
1137 EXEC SQL CLOSE csr212;
1141 int show_quota_nolist(int id)
1143 EXEC SQL BEGIN DECLARE SECTION;
1144 int iid = id, id1, found = 1;
1145 EXEC SQL END DECLARE SECTION;
1147 EXEC SQL DECLARE csr213 CURSOR FOR
1148 SELECT filsys_id FROM quota
1149 WHERE entity_id = :iid AND type = 'GROUP';
1150 EXEC SQL OPEN csr213;
1153 EXEC SQL FETCH csr213 INTO :id1;
1158 printf("Quota on fs %d for non-existant list %d\n", id1, id);
1160 EXEC SQL CLOSE csr213;
1164 fix_quota_nouser(int id)
1166 EXEC SQL BEGIN DECLARE SECTION;
1167 int iid = id, rowcount, id1;
1168 EXEC SQL END DECLARE SECTION;
1170 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1171 EXEC SQL DELETE FROM quota
1172 WHERE entity_id = :iid AND type = 'USER';
1173 rowcount = sqlca.sqlerrd[2];
1175 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1177 printf("Not deleted\n");
1181 fix_quota_nolist(int id)
1183 EXEC SQL BEGIN DECLARE SECTION;
1184 int iid = id, rowcount, id1;
1185 EXEC SQL END DECLARE SECTION;
1187 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1188 EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP';
1189 rowcount = sqlca.sqlerrd[2];
1191 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1193 printf("Not deleted\n");
1197 int show_quota_nofs(int id)
1199 EXEC SQL BEGIN DECLARE SECTION;
1200 int iid = id, id1, found = 1;
1202 EXEC SQL END DECLARE SECTION;
1204 EXEC SQL DECLARE csr214 CURSOR FOR
1205 SELECT entity_id, type FROM quota
1206 WHERE filsys_id = :iid;
1207 EXEC SQL OPEN csr214;
1210 EXEC SQL FETCH csr214 INTO :id1, :type;
1215 printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
1217 EXEC SQL CLOSE csr214;
1221 fix_quota_nofs(int id)
1223 single_delete("quota", "filsys_id", id);
1226 int show_quota_wrongpid(int id)
1228 EXEC SQL BEGIN DECLARE SECTION;
1229 int iid = id, id1, found = 1;
1231 EXEC SQL END DECLARE SECTION;
1235 f = (struct filesys *)hash_lookup(filesys, id);
1236 EXEC SQL DECLARE csr215 CURSOR FOR
1237 SELECT entity_id, type FROM quota
1238 WHERE filsys_id = :iid;
1239 EXEC SQL OPEN csr215;
1242 EXEC SQL FETCH csr215 INTO :id1, :type;
1247 printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1248 type, id1, f->name, id);
1250 EXEC SQL CLOSE csr215;
1254 fix_quota_physid(int id)
1256 EXEC SQL BEGIN DECLARE SECTION;
1257 int iid = id, rowcount, id1;
1258 EXEC SQL END DECLARE SECTION;
1260 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1261 EXEC SQL UPDATE quota SET phys_id = :id1
1262 WHERE filsys_id = :iid AND phys_id != :id1;
1263 rowcount = sqlca.sqlerrd[2];
1265 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1267 printf("Not fixed\n");
1271 int show_srv_user(int id)
1273 EXEC SQL BEGIN DECLARE SECTION;
1276 EXEC SQL END DECLARE SECTION;
1279 EXEC SQL DECLARE csr216 CURSOR FOR
1280 SELECT name FROM servers
1281 WHERE acl_type = 'USER' and acl_id = :iid;
1282 EXEC SQL OPEN csr216;
1285 EXEC SQL FETCH csr216 INTO :name;
1290 printf("Service %s has acl non-existant user %d\n", name, id);
1293 EXEC SQL CLOSE csr216;
1297 int show_srv_list(int id)
1299 EXEC SQL BEGIN DECLARE SECTION;
1302 EXEC SQL END DECLARE SECTION;
1305 EXEC SQL DECLARE csr217 CURSOR FOR
1306 SELECT name FROM servers
1307 WHERE acl_type = 'LIST' AND acl_id = :iid;
1308 EXEC SQL OPEN csr217;
1311 EXEC SQL FETCH csr217 INTO :name;
1316 printf("Service %s has acl non-existant list %d\n", name, id);
1319 EXEC SQL CLOSE csr217;
1323 zero_srv_user(int id)
1325 EXEC SQL BEGIN DECLARE SECTION;
1326 int iid = id, rowcount;
1327 EXEC SQL END DECLARE SECTION;
1329 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1331 rowcount = sqlca.sqlerrd[2];
1333 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1335 printf("Not fixed\n");
1336 modified("servers");
1339 zero_srv_list(int id)
1341 EXEC SQL BEGIN DECLARE SECTION;
1342 int iid = id, rowcount;
1343 EXEC SQL END DECLARE SECTION;
1345 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
1347 rowcount = sqlca.sqlerrd[2];
1349 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1351 printf("Not fixed\n");
1352 modified("servers");
1355 int show_krb_usr(int id)
1357 EXEC SQL BEGIN DECLARE SECTION;
1358 int iid = id, found = 1, id1;
1359 EXEC SQL END DECLARE SECTION;
1363 EXEC SQL DECLARE csr218 CURSOR FOR
1364 SELECT string_id FROM krbmap
1365 WHERE users_id = :iid;
1366 EXEC SQL OPEN csr218;
1369 EXEC SQL FETCH csr218 INTO :id1;
1373 if ((s = ((struct string *)hash_lookup(strings, id1))))
1378 printf("Kerberos map for non-existant user %d to principal %s\n",
1381 EXEC SQL CLOSE csr218;
1385 int show_krb_str(int id)
1387 EXEC SQL BEGIN DECLARE SECTION;
1388 int iid = id, found = 1, id1;
1389 EXEC SQL END DECLARE SECTION;
1393 EXEC SQL DECLARE csr219 CURSOR FOR
1394 SELECT users_id FROM krbmap
1395 WHERE string_id = :iid;
1396 EXEC SQL OPEN csr219;
1399 EXEC SQL FETCH csr219 INTO :id1;
1403 if ((u = ((struct user *)hash_lookup(users, id1))))
1408 printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1411 EXEC SQL CLOSE csr219;
1415 int show_pdm_mach(int id)
1417 EXEC SQL BEGIN DECLARE SECTION;
1420 EXEC SQL END DECLARE SECTION;
1423 EXEC SQL DECLARE csr220 CURSOR FOR
1424 SELECT name FROM palladium
1425 WHERE mach_id = :iid;
1426 EXEC SQL OPEN csr220;
1429 EXEC SQL FETCH csr220 INTO :name;
1434 printf("Palladium server/supervisor %s is on non-existant machine %d\n",
1438 EXEC SQL CLOSE csr220;
1445 EXEC SQL BEGIN DECLARE SECTION;
1446 int id1, id2, id3, id4, id5;
1447 char type[9], name[33];
1448 EXEC SQL END DECLARE SECTION;
1449 struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
1455 printf("Phase 2 - Checking references\n");
1457 dprintf("Checking users...\n");
1458 hash_step(users, user_check, NULL);
1460 dprintf("Checking machines...\n");
1461 hash_step(machines, mach_check, NULL);
1463 dprintf("Checking subnets...\n");
1464 hash_step(subnets, subnet_check, NULL);
1466 dprintf("Checking clusters...\n");
1467 hash_step(clusters, cluster_check, NULL);
1469 dprintf("Checking mcmap...\n");
1472 EXEC SQL DECLARE csr221 CURSOR FOR
1473 SELECT mach_id, clu_id FROM mcmap;
1474 EXEC SQL OPEN csr221;
1477 EXEC SQL FETCH csr221 INTO :id1, :id2;
1481 if (!(m = (struct machine *)hash_lookup(machines, id1)))
1482 sq_save_unique_data(sq1, id1);
1483 else if (!hash_lookup(clusters, id2))
1484 sq_save_unique_data(sq2, id2);
1488 EXEC SQL CLOSE csr221;
1489 generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1490 generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1492 dprintf("Checking service clusters...\n");
1494 EXEC SQL DECLARE csr222 CURSOR FOR
1495 SELECT clu_id FROM svc;
1496 EXEC SQL OPEN csr222;
1499 EXEC SQL FETCH csr222 INTO :id1;
1503 if (!hash_lookup(clusters, id1))
1504 sq_save_unique_data(sq1, id1);
1506 EXEC SQL CLOSE csr222;
1507 generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1509 dprintf("Checking lists...\n");
1510 hash_step(lists, list_check, NULL);
1512 dprintf("Checking members...\n");
1519 EXEC SQL DECLARE csr223 CURSOR FOR
1520 SELECT list_id, member_type, member_id, ref_count, direct
1521 FROM imembers FOR UPDATE OF member_id;
1522 EXEC SQL OPEN csr223;
1525 EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
1529 if (!(l = (struct list *) hash_lookup(lists, id1)))
1530 sq_save_unique_data(sq1, id1);
1531 else if (type[0] == 'U' && !hash_lookup(users, id2))
1532 sq_save_unique_data(sq2, id2);
1533 else if (type[0] == 'L' && !hash_lookup(lists, id2))
1534 sq_save_unique_data(sq3, id2);
1535 else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id2))
1536 sq_save_unique_data(sq4, id2);
1537 else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id2))
1538 sq_save_unique_data(sq5, id2);
1542 EXEC SQL CLOSE csr223;
1543 generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1544 generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1545 generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1546 generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1547 generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1549 dprintf("Checking servers...\n");
1552 EXEC SQL DECLARE csr224 CURSOR FOR
1553 SELECT name, acl_type, acl_id, modby FROM servers
1554 FOR UPDATE of modby;
1555 EXEC SQL OPEN csr224;
1558 EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2;
1562 maybe_fixup_modby2("servers", "modby", "csr224", id2);
1564 if (!strcmp(type, "USER") && !hash_lookup(users, id1))
1565 sq_save_data(sq1, id1);
1566 else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1))
1567 sq_save_data(sq2, id1);
1569 EXEC SQL CLOSE csr224;
1570 generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
1571 generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
1573 dprintf("Checking serverhosts...\n");
1575 EXEC SQL DECLARE csr225 CURSOR FOR
1576 SELECT mach_id, modby FROM serverhosts
1577 FOR UPDATE OF modby;
1578 EXEC SQL OPEN csr225;
1581 EXEC SQL FETCH csr225 INTO :id1, :id2;
1585 maybe_fixup_modby2("serverhosts", "modby", "csr225", id2);
1586 if (!hash_lookup(machines, id1))
1587 sq_save_data(sq, id1);
1589 EXEC SQL CLOSE csr225;
1590 generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1592 dprintf("Checking nfsphys...\n");
1593 hash_step(nfsphys, check_nfsphys, NULL);
1595 dprintf("Checking filesys...\n");
1596 hash_step(filesys, check_fs, NULL);
1598 dprintf("Checking filesystem groups...\n");
1602 EXEC SQL DECLARE csr226 CURSOR FOR
1603 SELECT group_id, filsys_id FROM fsgroup;
1604 EXEC SQL OPEN csr226;
1607 EXEC SQL FETCH csr226 INTO :id1, :id2;
1611 if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
1612 sq_save_data(sq1, id1);
1613 if (!hash_lookup(filesys, id2))
1614 sq_save_data(sq3, id2);
1616 EXEC SQL CLOSE csr226;
1617 generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
1618 generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
1620 dprintf("Checking quotas...\n");
1625 EXEC SQL DECLARE csr227 CURSOR FOR
1626 SELECT entity_id, type, filsys_id, phys_id, quota, modby
1627 FROM quota FOR UPDATE OF modby;
1628 EXEC SQL OPEN csr227;
1631 EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5;
1635 maybe_fixup_modby2("quota", "modby", "csr227", id5);
1636 if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
1637 sq_save_data(sq1, id1);
1638 else if (type[0] == 'G' && !hash_lookup(lists, id1))
1639 sq_save_data(sq4, id1);
1640 else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
1641 sq_save_data(sq2, id2);
1642 else if (id3 != f->phys_id ||
1643 !(n = (struct nfsphys *) hash_lookup(nfsphys, id3)))
1644 sq_save_data(sq3, id2);
1648 EXEC SQL CLOSE csr227;
1649 generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
1650 generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
1651 generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
1652 generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
1654 dprintf("Not checking zephyr.\n");
1656 dprintf("Checking hostaccess...\n");
1657 EXEC SQL DECLARE csr228 CURSOR FOR
1658 SELECT mach_id, acl_type, acl_id, modby FROM hostaccess
1659 FOR UPDATE OF modby;
1660 EXEC SQL OPEN csr228;
1663 EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3;
1667 maybe_fixup_modby2("hostaccess", "modby", "csr228", id3);
1669 if (!hash_lookup(machines, id1))
1671 printf("Hostaccess for non-existant host %d\n", id1);
1672 printf("Not fixing this error\n");
1674 if (!strcmp(type, "USER") && !hash_lookup(users, id2))
1676 printf("Hostaccess for %d is non-existant user %d\n", id1, id2);
1677 printf("Not fixing this error\n");
1679 else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2))
1681 printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
1682 printf("Not fixing this error\n");
1685 EXEC SQL CLOSE csr228;
1687 dprintf("Checking palladium...\n");
1689 EXEC SQL DECLARE csr229 CURSOR FOR
1690 SELECT mach_id, modby FROM palladium
1691 FOR UPDATE OF modby;
1692 EXEC SQL OPEN csr229;
1695 EXEC SQL FETCH csr229 INTO :id1, :id2;
1699 maybe_fixup_modby2("palladium", "modby", "csr229", id2);
1700 if (!hash_lookup(machines, id1))
1701 sq_save_unique_data(sq1, id1);
1703 EXEC SQL CLOSE csr229;
1704 generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
1706 dprintf("Checking krbmap...\n");
1709 EXEC SQL DECLARE csr230 CURSOR FOR
1710 SELECT users_id, string_id FROM krbmap
1711 FOR UPDATE OF string_id;
1712 EXEC SQL OPEN csr230;
1715 EXEC SQL FETCH csr230 INTO :id1, :id2;
1719 if (!hash_lookup(users, id1))
1720 sq_save_unique_data(sq1, id1);
1721 else if (!maybe_fixup_unref_string2("krbmap", "string_id", "csr230", id2))
1722 sq_save_unique_data(sq2, id2);
1724 EXEC SQL CLOSE csr230;
1725 generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
1726 generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
1728 dprintf("Checking capacls...\n");
1729 EXEC SQL DECLARE csr231 CURSOR FOR
1730 SELECT list_id, tag FROM capacls;
1731 EXEC SQL OPEN csr231;
1734 EXEC SQL FETCH csr231 INTO :id1, :name;
1738 if (!hash_lookup(lists, id1))
1740 printf("Capacl for %s is non-existant list %d\n", name, id1);
1741 printf("Not fixing this error\n");
1744 EXEC SQL CLOSE csr231;
1746 dprintf("Checking hostaliases\n");
1748 EXEC SQL DECLARE csr232 CURSOR FOR
1749 SELECT mach_id FROM hostalias;
1750 EXEC SQL OPEN csr232;
1753 EXEC SQL FETCH csr232 INTO :id1;
1757 if (!hash_lookup(machines, id1))
1758 sq_save_unique_data(sq1, id1);
1760 EXEC SQL CLOSE csr232;
1761 generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
1763 dprintf("Checking printcaps\n");
1766 EXEC SQL DECLARE csr233 CURSOR FOR
1767 SELECT mach_id, quotaserver, modby FROM printcap;
1768 EXEC SQL OPEN csr233;
1771 EXEC SQL FETCH csr233 INTO :id1, :id2, :id3;
1775 maybe_fixup_modby2("printcap", "modby", "csr233", id3);
1776 if (!hash_lookup(machines, id1))
1777 sq_save_unique_data(sq1, id1);
1778 else if (!hash_lookup(machines, id2))
1779 sq_save_unique_data(sq2, id2);
1781 EXEC SQL CLOSE csr233;
1782 generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1);
1783 generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1);