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>
12 EXEC SQL INCLUDE sqlca;
14 static char phase2_qc_rcsid[] = "$Header$";
16 EXEC SQL WHENEVER SQLERROR DO dbmserr();
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;
31 EXEC SQL FETCH csr201 INTO :name;
32 if (sqlca.sqlcode != 0) break;
36 printf("Cluster %s, non-existant machine %d in cluster map\n", name, id);
38 EXEC SQL CLOSE csr201;
45 EXEC SQL BEGIN DECLARE SECTION;
46 int iid = id, found = 1;
48 EXEC SQL END DECLARE SECTION;
50 EXEC SQL DECLARE csr202 CURSOR FOR
51 SELECT machine.name FROM machine, mcmap
52 WHERE machine.mach_id=mcmap.mach_id AND mcmap.clu_id=:iid;
55 EXEC SQL FETCH csr202 INTO :name;
56 if (sqlca.sqlcode != 0) break;
61 printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
63 EXEC SQL CLOSE csr202;
70 EXEC SQL BEGIN DECLARE SECTION;
71 int iid = id, found = 1;
73 EXEC SQL END DECLARE SECTION;
75 EXEC SQL DECLARE csr234 CURSOR FOR
76 SELECT name FROM hostalias WHERE mach_id=:iid;
79 EXEC SQL FETCH csr234 INTO :name;
80 if (sqlca.sqlcode != 0) break;
85 printf("Alias %s, non-existant machine %d in hostalias map\n", name, id);
87 EXEC SQL CLOSE csr234;
94 EXEC SQL BEGIN DECLARE SECTION;
95 int iid = id, found = 1;
97 EXEC SQL END DECLARE SECTION;
99 EXEC SQL DECLARE csr235 CURSOR FOR
100 SELECT name FROM printcap WHERE mach_id=:iid;
101 EXEC SQL OPEN csr235;
103 EXEC SQL FETCH csr235 INTO :name;
104 if (sqlca.sqlcode != 0) break;
109 printf("Printer %s, non-existant spool machine %d in printcap table\n", name, id);
111 EXEC SQL CLOSE csr235;
118 EXEC SQL BEGIN DECLARE SECTION;
119 int iid = id, found = 1;
121 EXEC SQL END DECLARE SECTION;
123 EXEC SQL DECLARE csr236 CURSOR FOR
124 SELECT name FROM printcap WHERE quotaserver=:iid;
125 EXEC SQL OPEN csr236;
127 EXEC SQL FETCH csr236 INTO :name;
128 if (sqlca.sqlcode != 0) break;
133 printf("Printer %s, non-existant quota server %d in printcap table\n", name, id);
135 EXEC SQL CLOSE csr236;
139 user_check(id, u, hint)
144 u->comment=maybe_fixup_unref_string(u->comment, id, u->login, "users",
145 "comments", "users_id");
147 u->modby=maybe_fixup_modby(u->modby, id, u->login, "users",
148 "modby", "users_id");
150 u->fmodby=maybe_fixup_modby(u->fmodby, id, u->login, "users",
151 "fmodby", "users_id");
153 u->pmodby=maybe_fixup_modby(u->pmodby, id, u->login, "users",
154 "pmodby", "users_id");
156 u->sigwho=maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
157 "sigwho", "users_id");
159 pobox_check(id, u, hint);
162 maybe_fixup_unref_string(sid, oid, oname, table, field, idfield)
165 char *field, *idfield;
167 int ret=(sid<0)?-sid:sid, doit=0, newid;
168 EXEC SQL BEGIN DECLARE SECTION;
171 EXEC SQL END DECLARE SECTION;
173 if(newid=int_hash_lookup(string_dups, ret)) {
174 printf("%s entry %s(%d) has a %s with duplicate string %d\n",
175 table, oname, oid, field, ret);
176 if(single_fix("Replace duplicate", 0)){
181 } else if(!string_check(ret)) {
182 printf("%s entry %s(%d) has a %s with non-existant string %d\n",
183 table, oname, oid, field, ret);
184 if (single_fix("Delete", 1)) {
191 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d",
192 table, field, (sid<0)?-ret:ret, idfield, oid);
193 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
194 rowcount = sqlca.sqlerrd[2];
198 printf("Not fixed, rowcount = %d\n", rowcount);
202 return((sid<0)?-ret:ret);
206 maybe_fixup_modby(sid, oid, oname, table, field, idfield)
209 char *field, *idfield;
211 EXEC SQL BEGIN DECLARE SECTION;
214 EXEC SQL END DECLARE SECTION;
217 return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
219 if(!hash_lookup(users, sid)) {
220 printf("%s entry %s(%d) has a %s with non-existant user %d\n",
221 table, oname, oid, field, sid);
222 if (single_fix("Delete", 1)) {
223 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d",
224 table, field, idfield, oid);
225 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
226 rowcount = sqlca.sqlerrd[2];
230 printf("Not fixed, rowcount = %d\n", rowcount);
239 maybe_fixup_unref_string2(table, field, cursor, sid)
241 char *field, *table, *cursor;
243 int ret=(sid<0)?-sid:sid, doit=0, newid;
244 EXEC SQL BEGIN DECLARE SECTION;
247 EXEC SQL END DECLARE SECTION;
249 if(newid=int_hash_lookup(string_dups, ret)) {
250 printf("%s entry has a %s with duplicate string %d\n",
252 if(single_fix("Replace duplicate", 0)){
257 } else if(!string_check(ret)) {
258 printf("%s entry has a %s with non-existant string %d\n",
260 if (single_fix("Delete", 1)) {
267 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s",
268 table, field, (sid<0)?-ret:ret, cursor);
269 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
270 rowcount = sqlca.sqlerrd[2];
274 printf("Not fixed, rowcount = %d\n", rowcount);
277 return((sid<0)?-ret:ret);
280 maybe_fixup_modby2(table, field, cursor, id)
282 EXEC SQL BEGIN DECLARE SECTION;
285 EXEC SQL END DECLARE SECTION;
287 if(id<0) return maybe_fixup_unref_string2(table, field, cursor, id);
289 if(!hash_lookup(users, id)) {
290 printf("%s entry has a %s with non-existant user %d\n",
292 if (single_fix("Delete", 1)) {
293 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE CURRENT OF %s",
294 table, field, cursor);
295 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
296 rowcount = sqlca.sqlerrd[2];
300 printf("Not fixed, rowcount = %d\n", rowcount);
309 pobox_check(id, u, hint)
316 if (!hash_lookup(machines, u->pobox_id)) {
317 printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
318 u->login, u->fullname, u->pobox_id);
319 if (single_fix("Delete", 0)) {
320 remove_pobox(u->users_id);
326 if( int_hash_lookup( string_dups, u->pobox_id ) ) {
327 printf("User %s(%s) has P.O.Box with duplicate string %d\n",
328 u->login, u->fullname, u->pobox_id);
329 if(single_fix("Update", 0)){
330 printf("Replacing box_id dup string ID %d with %d\n",
332 int_hash_lookup(string_dups, u->pobox_id));
333 u->pobox_id = int_hash_lookup( string_dups, u->pobox_id );
334 fix_smtp_pobox(u->users_id, u->pobox_id);
335 string_check(u->pobox_id);
337 } else if (!string_check(u->pobox_id)) {
338 printf("User %s(%s) has P.O.Box with non-existant string %d\n",
339 u->login, u->fullname, u->pobox_id);
340 if (single_fix("Delete", 0)) {
341 remove_pobox(u->users_id);
355 EXEC SQL BEGIN DECLARE SECTION;
356 int rowcount, iid = id;
357 EXEC SQL END DECLARE SECTION;
359 EXEC SQL UPDATE users SET potype='NONE' WHERE users.users_id = :iid;
360 rowcount = sqlca.sqlerrd[2];
362 printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies");
364 printf("Not removed\n");
368 fix_smtp_pobox(id, sid)
371 EXEC SQL BEGIN DECLARE SECTION;
372 int rowcount, iid = id, isid=sid;
373 EXEC SQL END DECLARE SECTION;
375 EXEC SQL UPDATE users SET box_id=:isid WHERE users.users_id = :iid;
376 rowcount = sqlca.sqlerrd[2];
378 printf("%d entr%s updated\n", rowcount, rowcount==1?"y":"ies");
380 printf("Not updated\n");
384 mach_check(id, m, hint)
389 if (!hash_lookup(subnets, m->snet_id)) {
390 printf("Machine %s is on a non-existant subnet %d\n",
391 m->name, m->snet_id);
392 if (single_fix("Move to null-subnet", 1)) {
393 EXEC SQL BEGIN DECLARE SECTION;
394 int rowcount, iid = id;
395 EXEC SQL END DECLARE SECTION;
397 EXEC SQL UPDATE machine SET snet_id=0 WHERE mach_id = :iid;
398 rowcount = sqlca.sqlerrd[2];
400 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
402 printf("Not fixed\n");
407 switch (m->owner_type) {
409 if (!hash_lookup(users, m->owner_id)) {
410 printf("Machine %s has non-existant USER owner %d\n",
411 m->name, m->owner_id);
412 if (single_fix("Set to no owner", 1)) {
418 if (!hash_lookup(lists, m->owner_id)) {
419 printf("Machine %s has non-existant LIST owner %d\n",
420 m->name, m->owner_id);
421 if (single_fix("Set to no owner", 1)) {
429 m->owner_id=maybe_fixup_unref_string(m->owner_id, id, m->name,
430 "machine", "owner_id", "mach_id");
436 m->acomment=maybe_fixup_unref_string(m->acomment, id, m->name,
437 "machine", "acomment", "mach_id");
439 m->ocomment=maybe_fixup_unref_string(m->ocomment, id, m->name,
440 "machine", "ocomment", "mach_id");
442 m->creator=maybe_fixup_modby(m->creator, id, m->name, "machine",
443 "creator", "mach_id");
444 m->modby=maybe_fixup_modby(m->modby, id, m->name, "machine",
448 subnet_check(id, s, hint)
453 switch (s->owner_type) {
455 if (!hash_lookup(users, s->owner_id)) {
456 printf("Subnet %s has non-existant USER owner %d\n",
457 s->name, s->owner_id);
458 if (single_fix("Set to no owner", 1)) {
459 clear_subnet_owner(s);
464 if (!hash_lookup(lists, s->owner_id)) {
465 printf("Machine %s has non-existant LIST owner %d\n",
466 s->name, s->owner_id);
467 if (single_fix("Set to no owner", 1)) {
468 clear_subnet_owner(s);
475 s->owner_id=maybe_fixup_unref_string(s->owner_id, id, s->name,
476 "machine", "owner_id", "mach_id");
478 clear_subnet_owner(s);
481 s->modby=maybe_fixup_modby(s->modby, id, s->name, "subnet",
486 clear_subnet_owner(s)
489 EXEC SQL BEGIN DECLARE SECTION;
490 int rowcount, id = s->snet_id;
491 EXEC SQL END DECLARE SECTION;
493 EXEC SQL UPDATE subnet SET owner_type='NONE', owner_id=0
495 rowcount = sqlca.sqlerrd[2];
497 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
499 printf("Not fixed\n");
506 EXEC SQL BEGIN DECLARE SECTION;
507 int rowcount, id = m->mach_id;
508 EXEC SQL END DECLARE SECTION;
510 EXEC SQL UPDATE machine SET owner_type='NONE', owner_id=0
512 rowcount = sqlca.sqlerrd[2];
514 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
516 printf("Not fixed\n");
520 cluster_check(id, c, hint)
525 c->modby=maybe_fixup_modby(c->modby, id, c->name, "clusters",
534 EXEC SQL BEGIN DECLARE SECTION;
535 int iid = id, found = 1;
536 char label[17], data[33];
537 EXEC SQL END DECLARE SECTION;
539 EXEC SQL DECLARE csr203 CURSOR FOR
540 SELECT serv_label, serv_cluster FROM svc
542 EXEC SQL OPEN csr203;
544 EXEC SQL FETCH csr203 INTO :label, :data;
545 if (sqlca.sqlcode != 0) break;
550 printf("Cluster data [%s] %s for non-existant cluster %d\n",
553 EXEC SQL CLOSE csr203;
557 list_check(id, l, hint)
562 switch (l->acl_type) {
564 if (!hash_lookup(lists, l->acl_id)) {
565 printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
566 if (single_fix("Patch", 1)) {
567 fix_list_acl(l->list_id);
572 if (!hash_lookup(users, l->acl_id)) {
573 printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
574 if (single_fix("Patch", 1)) {
575 fix_list_acl(l->list_id);
580 l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
581 "list", "acl_id", "list_id");
583 printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id);
584 if(single_fix("Patch", 1)) {
585 fix_list_acl(l->list_id);
595 EXEC SQL BEGIN DECLARE SECTION;
596 int rowcount, iid = id;
597 EXEC SQL END DECLARE SECTION;
599 EXEC SQL UPDATE list SET acl_id = :iid, acl_type='LIST'
600 WHERE list_id = :iid;
601 rowcount = sqlca.sqlerrd[2];
603 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
605 printf("Not fixed\n");
613 EXEC SQL BEGIN DECLARE SECTION;
614 int mid, iid = id, found = 1;
615 char mtype[9], *name = "";
616 EXEC SQL END DECLARE SECTION;
618 EXEC SQL DECLARE csr204 CURSOR FOR
619 SELECT member_type, member_id FROM imembers
620 WHERE list_id = :iid AND direct=1;
621 EXEC SQL OPEN csr204;
623 EXEC SQL FETCH csr204 INTO :mtype, :mid;
624 if (sqlca.sqlcode != 0) break;
629 name = ((struct list *) hash_lookup(lists, mid))->name;
630 else if (mtype[0] == 'U')
631 name = ((struct user *) hash_lookup(users, mid))->login;
632 else if (mtype[0] == 'S' || mtype[0] == 'K')
633 name = ((struct string *) hash_lookup(strings, mid))->name;
634 printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
636 EXEC SQL CLOSE csr204;
643 EXEC SQL BEGIN DECLARE SECTION;
644 int lid, iid = id, found = 1;
646 EXEC SQL END DECLARE SECTION;
648 EXEC SQL DECLARE csr205 CURSOR FOR
649 SELECT list_id FROM imembers
650 WHERE member_id = :iid AND member_type='USER' AND direct=1;
651 EXEC SQL OPEN csr205;
653 EXEC SQL FETCH csr205 INTO :lid;
654 if (sqlca.sqlcode != 0) break;
657 printf("List %s has non-existant user member, id %d\n",
658 ((struct list *)hash_lookup(lists, lid))->name, iid);
660 EXEC SQL CLOSE csr205;
667 EXEC SQL BEGIN DECLARE SECTION;
668 int lid, iid = id, found = 1;
670 EXEC SQL END DECLARE SECTION;
672 EXEC SQL DECLARE csr206 CURSOR FOR
673 SELECT list_id FROM imembers
674 WHERE member_id = :iid AND member_type='LIST' AND direct=1;
675 EXEC SQL OPEN csr206;
677 EXEC SQL FETCH csr206 INTO :lid;
678 if (sqlca.sqlcode != 0) break;
681 printf("List %s has non-existant list member, id %d\n",
682 ((struct list *)hash_lookup(lists, lid))->name, iid);
684 EXEC SQL CLOSE csr206;
691 EXEC SQL BEGIN DECLARE SECTION;
692 int lid, iid = id, found = 1;
694 EXEC SQL END DECLARE SECTION;
696 EXEC SQL DECLARE csr207 CURSOR FOR
697 SELECT list_id FROM imembers
698 WHERE member_id = :iid AND member_type='STRING' AND direct=1;
699 EXEC SQL OPEN csr207;
701 EXEC SQL FETCH csr207 INTO :lid;
702 if (sqlca.sqlcode != 0) break;
705 printf("List %s has non-existant string member, id %d\n",
706 ((struct list *)hash_lookup(lists, lid))->name, iid);
708 EXEC SQL CLOSE csr207;
716 EXEC SQL BEGIN DECLARE SECTION;
717 int lid, iid = id, found = 1;
719 EXEC SQL END DECLARE SECTION;
721 EXEC SQL DECLARE csr208 CURSOR FOR
722 SELECT list_id FROM imembers
723 WHERE member_id = :iid AND member_type='KERBEROS' AND direct=1;
724 EXEC SQL OPEN csr208;
726 EXEC SQL FETCH csr208 INTO :lid;
727 if (sqlca.sqlcode != 0) break;
730 printf("List %s has non-existant kerberos member, id %d\n",
731 ((struct list *)hash_lookup(lists, lid))->name, iid);
733 EXEC SQL CLOSE csr208;
741 EXEC SQL BEGIN DECLARE SECTION;
742 int iid = id, rowcount;
743 EXEC SQL END DECLARE SECTION;
745 EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND
746 member_id = :iid AND direct = 1;
747 rowcount = sqlca.sqlerrd[2];
749 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
751 printf("Not deleted\n");
752 modified("imembers");
758 EXEC SQL BEGIN DECLARE SECTION;
759 int iid = id, rowcount;
760 EXEC SQL END DECLARE SECTION;
762 EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND
763 member_id = :iid AND direct=1;
764 rowcount = sqlca.sqlerrd[2];
766 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
768 printf("Not deleted\n");
769 modified("imembers");
775 EXEC SQL BEGIN DECLARE SECTION;
776 int iid = id, rowcount;
777 EXEC SQL END DECLARE SECTION;
779 EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND
780 member_id = :iid AND direct=1;
781 rowcount = sqlca.sqlerrd[2];
783 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
785 printf("Not deleted\n");
786 modified("imembers");
793 EXEC SQL BEGIN DECLARE SECTION;
794 int iid = id, rowcount;
795 EXEC SQL END DECLARE SECTION;
797 EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND
798 member_id = :iid AND direct=1;
799 rowcount = sqlca.sqlerrd[2];
801 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
803 printf("Not deleted\n");
804 modified("imembers");
811 EXEC SQL BEGIN DECLARE SECTION;
814 EXEC SQL END DECLARE SECTION;
817 EXEC SQL DECLARE csr209 CURSOR FOR
818 SELECT service FROM serverhosts
819 WHERE mach_id = :iid;
820 EXEC SQL OPEN csr209;
822 EXEC SQL FETCH csr209 INTO :name;
823 if (sqlca.sqlcode != 0) break;
826 printf("ServerHost entry for service %s non-existant host %d\n",
829 EXEC SQL CLOSE csr209;
836 EXEC SQL BEGIN DECLARE SECTION;
837 int iid = id, rowcount;
838 EXEC SQL END DECLARE SECTION;
840 EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
841 rowcount = sqlca.sqlerrd[2];
843 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
845 printf("Not deleted\n");
846 modified("serverhosts");
850 static int fnchecklen;
857 if (n->mach_id == f->mach_id &&
858 !strncmp(f->dir, n->dir, strlen(n->dir)) &&
859 strlen(n->dir) > fnchecklen) {
861 fnchecklen = strlen(n->dir);
866 check_fs(id, f, hint)
868 register struct filesys *f;
871 EXEC SQL BEGIN DECLARE SECTION;
872 int iid = id, id1, id2, id3, rowcount;
874 EXEC SQL END DECLARE SECTION;
878 if (!hash_lookup(machines, f->mach_id)) {
879 printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
880 if (single_fix("Fix", 0)) {
881 EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
882 rowcount = sqlca.sqlerrd[2];
884 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
886 printf("Not fixed\n");
892 if (!hash_lookup(users, f->owner)) {
893 printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
894 if (single_fix("Fix", 1)) {
895 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
899 if (!hash_lookup(lists, f->owners)) {
900 printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
901 if (single_fix("Fix", 1)) {
902 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
907 if (f->type == 'N') {
908 if (!hash_lookup(nfsphys, f->phys_id)) {
909 m = (struct machine *)hash_lookup(machines, f->mach_id);
910 printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
911 if (single_fix("Fix", 1)) {
913 hash_step(nfsphys, fsmatch, f);
914 if (fnchecklen != 0) {
918 EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2;
919 rowcount = sqlca.sqlerrd[2];
921 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
923 printf("Not fixed\n");
926 printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
927 if (single_fix("Create", 0)) {
932 if (set_next_object_id("nfsphys_id", "nfsphys") !=
934 printf("Unable to assign unique ID\n");
937 EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
938 WHERE name='nfsphys_id';
940 printf("Unable to retrieve unique ID\n");
943 EXEC SQL INSERT INTO nfsphys (nfsphys_id, mach_id,
944 device, dir, status, allocated, size, modtime,
945 modby, modwith) VALUES (:id1, :id3, '\?\?\?', :dir,
946 0, 0, 0, SYSDATE, 0, 'dbck');
947 rowcount = sqlca.sqlerrd[2];
949 printf("%d entr%s created\n", rowcount,
950 rowcount==1?"y":"ies");
952 printf("Not created\n");
954 n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
956 out_of_mem("storing new nfsphys");
962 if( hash_store(nfsphys, id1, n) == -1 ) {
963 out_of_mem("storing nfsphys in hash table");
965 EXEC SQL UPDATE filesys SET phys_id = :id1
966 WHERE filsys_id = :id2;
967 rowcount = sqlca.sqlerrd[2];
969 printf("%d filesys entr%s fixed\n", rowcount,
970 rowcount==1?"y":"ies");
972 printf("Not fixed\n");
982 check_nfsphys(id, n, hint)
987 if (!hash_lookup(machines, n->mach_id)) {
988 printf("NFSphys %d(%s) on non-existant machine %d\n",
989 id, n->dir, n->mach_id);
990 if (single_fix("Delete", 0))
991 single_delete("nfsphys", "nfsphys_id", id);
998 EXEC SQL BEGIN DECLARE SECTION;
999 int iid = id, id1, found = 1;
1000 EXEC SQL END DECLARE SECTION;
1003 EXEC SQL DECLARE csr210 CURSOR FOR
1004 SELECT filsys_id FROM fsgroup
1005 WHERE group_id = :iid;
1006 EXEC SQL OPEN csr210;
1008 EXEC SQL FETCH csr210 INTO :id1;
1009 if (sqlca.sqlcode != 0) break;
1012 if (f = (struct filesys *) hash_lookup(filesys, id1))
1013 printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
1015 printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
1017 EXEC SQL CLOSE csr210;
1048 printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1055 EXEC SQL BEGIN DECLARE SECTION;
1056 int rowcount, id = f->filsys_id;
1057 EXEC SQL END DECLARE SECTION;
1059 EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id;
1060 rowcount = sqlca.sqlerrd[2];
1062 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1064 printf("Not fixed\n");
1065 modified("filesys");
1068 show_fsg_nomember(id)
1071 EXEC SQL BEGIN DECLARE SECTION;
1072 int iid = id, id1, found = 1;
1073 EXEC SQL END DECLARE SECTION;
1076 EXEC SQL DECLARE csr211 CURSOR FOR
1077 SELECT group_id FROM fsgroup
1078 WHERE filsys_id = :iid;
1079 EXEC SQL OPEN csr211;
1081 EXEC SQL FETCH csr211 INTO :id1;
1082 if (sqlca.sqlcode != 0) break;
1085 if (f = (struct filesys *) hash_lookup(filesys, id1))
1086 printf("FSGroup %s has missing member %d\n", f->name, id);
1088 printf("FSGroup %d has missing member %d\n", id1, id);
1090 EXEC SQL CLOSE csr211;
1094 show_quota_nouser(id)
1097 EXEC SQL BEGIN DECLARE SECTION;
1098 int iid = id, id1, found = 1;
1099 EXEC SQL END DECLARE SECTION;
1101 EXEC SQL DECLARE csr212 CURSOR FOR
1102 SELECT filsys_id FROM quota
1103 WHERE entity_id = :iid AND type='USER';
1104 EXEC SQL OPEN csr212;
1106 EXEC SQL FETCH csr212 INTO :id1;
1107 if (sqlca.sqlcode != 0) break;
1110 printf("Quota on fs %d for non-existant user %d\n", id1, id);
1112 EXEC SQL CLOSE csr212;
1116 show_quota_nolist(id)
1119 EXEC SQL BEGIN DECLARE SECTION;
1120 int iid = id, id1, found = 1;
1121 EXEC SQL END DECLARE SECTION;
1123 EXEC SQL DECLARE csr213 CURSOR FOR
1124 SELECT filsys_id FROM quota
1125 WHERE entity_id = :iid AND type='GROUP';
1126 EXEC SQL OPEN csr213;
1128 EXEC SQL FETCH csr213 INTO :id1;
1129 if (sqlca.sqlcode != 0) break;
1132 printf("Quota on fs %d for non-existant list %d\n", id1, id);
1134 EXEC SQL CLOSE csr213;
1138 fix_quota_nouser(id)
1141 EXEC SQL BEGIN DECLARE SECTION;
1142 int iid = id, rowcount, id1;
1143 EXEC SQL END DECLARE SECTION;
1145 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1146 EXEC SQL DELETE FROM quota
1147 WHERE entity_id = :iid AND type = 'USER';
1148 rowcount = sqlca.sqlerrd[2];
1150 printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1152 printf("Not deleted\n");
1156 fix_quota_nolist(id)
1159 EXEC SQL BEGIN DECLARE SECTION;
1160 int iid = id, rowcount, id1;
1161 EXEC SQL END DECLARE SECTION;
1163 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1164 EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type='GROUP';
1165 rowcount = sqlca.sqlerrd[2];
1167 printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1169 printf("Not deleted\n");
1176 EXEC SQL BEGIN DECLARE SECTION;
1177 int iid = id, id1, found = 1;
1179 EXEC SQL END DECLARE SECTION;
1181 EXEC SQL DECLARE csr214 CURSOR FOR
1182 SELECT entity_id, type FROM quota
1183 WHERE filsys_id = :iid;
1184 EXEC SQL OPEN csr214;
1186 EXEC SQL FETCH csr214 INTO :id1, :type;
1187 if (sqlca.sqlcode != 0) break;
1190 printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
1192 EXEC SQL CLOSE csr214;
1198 single_delete("quota", "filsys_id", id);
1201 show_quota_wrongpid(id)
1204 EXEC SQL BEGIN DECLARE SECTION;
1205 int iid = id, id1, found = 1;
1207 EXEC SQL END DECLARE SECTION;
1211 f = (struct filesys *)hash_lookup(filesys, id);
1212 EXEC SQL DECLARE csr215 CURSOR FOR
1213 SELECT entity_id, type FROM quota
1214 WHERE filsys_id = :iid;
1215 EXEC SQL OPEN csr215;
1217 EXEC SQL FETCH csr215 INTO :id1, :type;
1218 if (sqlca.sqlcode != 0) break;
1221 printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1222 type, id1, f->name, id);
1224 EXEC SQL CLOSE csr215;
1228 fix_quota_physid(id)
1231 EXEC SQL BEGIN DECLARE SECTION;
1232 int iid = id, rowcount, id1;
1233 EXEC SQL END DECLARE SECTION;
1235 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
1236 EXEC SQL UPDATE quota SET phys_id = :id1
1237 WHERE filsys_id = :iid AND phys_id != :id1;
1238 rowcount = sqlca.sqlerrd[2];
1240 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
1242 printf("Not fixed\n");
1249 EXEC SQL BEGIN DECLARE SECTION;
1252 EXEC SQL END DECLARE SECTION;
1255 EXEC SQL DECLARE csr216 CURSOR FOR
1256 SELECT name FROM servers
1257 WHERE acl_type='USER' and acl_id = :iid;
1258 EXEC SQL OPEN csr216;
1260 EXEC SQL FETCH csr216 INTO :name;
1261 if (sqlca.sqlcode != 0) break;
1264 printf("Service %s has acl non-existant user %d\n", name, id);
1267 EXEC SQL CLOSE csr216;
1274 EXEC SQL BEGIN DECLARE SECTION;
1277 EXEC SQL END DECLARE SECTION;
1280 EXEC SQL DECLARE csr217 CURSOR FOR
1281 SELECT name FROM servers
1282 WHERE acl_type='LIST' AND acl_id = :iid;
1283 EXEC SQL OPEN csr217;
1285 EXEC SQL FETCH csr217 INTO :name;
1286 if (sqlca.sqlcode != 0) break;
1289 printf("Service %s has acl non-existant list %d\n", name, id);
1292 EXEC SQL CLOSE csr217;
1299 EXEC SQL BEGIN DECLARE SECTION;
1300 int iid = id, rowcount;
1301 EXEC SQL END DECLARE SECTION;
1303 EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :iid AND
1305 rowcount = sqlca.sqlerrd[2];
1307 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1309 printf("Not fixed\n");
1310 modified("servers");
1316 EXEC SQL BEGIN DECLARE SECTION;
1317 int iid = id, rowcount;
1318 EXEC SQL END DECLARE SECTION;
1320 EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :iid AND
1322 rowcount = sqlca.sqlerrd[2];
1324 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1326 printf("Not fixed\n");
1327 modified("servers");
1334 EXEC SQL BEGIN DECLARE SECTION;
1335 int iid = id, found = 1, id1;
1336 EXEC SQL END DECLARE SECTION;
1340 EXEC SQL DECLARE csr218 CURSOR FOR
1341 SELECT string_id FROM krbmap
1342 WHERE users_id = :iid ;
1343 EXEC SQL OPEN csr218;
1345 EXEC SQL FETCH csr218 INTO :id1;
1346 if (sqlca.sqlcode != 0) break;
1348 if (s = ((struct string *)hash_lookup(strings, id1)))
1353 printf("Kerberos map for non-existant user %d to principal %s\n",
1356 EXEC SQL CLOSE csr218;
1364 EXEC SQL BEGIN DECLARE SECTION;
1365 int iid = id, found = 1, id1;
1366 EXEC SQL END DECLARE SECTION;
1370 EXEC SQL DECLARE csr219 CURSOR FOR
1371 SELECT users_id FROM krbmap
1372 WHERE string_id = :iid;
1373 EXEC SQL OPEN csr219;
1375 EXEC SQL FETCH csr219 INTO :id1;
1376 if (sqlca.sqlcode != 0) break;
1378 if (u = ((struct user *)hash_lookup(users, id1)))
1383 printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1386 EXEC SQL CLOSE csr219;
1394 EXEC SQL BEGIN DECLARE SECTION;
1397 EXEC SQL END DECLARE SECTION;
1400 EXEC SQL DECLARE csr220 CURSOR FOR
1401 SELECT name FROM palladium
1402 WHERE mach_id = :iid;
1403 EXEC SQL OPEN csr220;
1405 EXEC SQL FETCH csr220 INTO :name;
1406 if (sqlca.sqlcode != 0) break;
1409 printf("Palladium server/supervisor %s is on non-existant machine %d\n",
1413 EXEC SQL CLOSE csr220;
1420 EXEC SQL BEGIN DECLARE SECTION;
1421 int id1, id2, id3, id4, id5;
1422 char type[9], name[33];
1423 EXEC SQL END DECLARE SECTION;
1424 struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
1430 printf("Phase 2 - Checking references\n");
1432 dprintf("Checking users...\n");
1433 hash_step(users, user_check, NULL);
1435 dprintf("Checking machines...\n");
1436 hash_step(machines, mach_check, NULL);
1438 dprintf("Checking subnets...\n");
1439 hash_step(subnets, subnet_check, NULL);
1441 dprintf("Checking clusters...\n");
1442 hash_step(clusters, cluster_check, NULL);
1444 dprintf("Checking mcmap...\n");
1447 EXEC SQL DECLARE csr221 CURSOR FOR
1448 SELECT mach_id, clu_id FROM mcmap;
1449 EXEC SQL OPEN csr221;
1451 EXEC SQL FETCH csr221 INTO :id1, :id2;
1452 if (sqlca.sqlcode != 0) break;
1454 if (!(m = (struct machine *)hash_lookup(machines, id1)))
1455 sq_save_unique_data(sq1, id1);
1456 else if (!hash_lookup(clusters, id2))
1457 sq_save_unique_data(sq2, id2);
1458 if (m) m->clucount++;
1460 EXEC SQL CLOSE csr221;
1461 generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1462 generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1464 dprintf("Checking service clusters...\n");
1466 EXEC SQL DECLARE csr222 CURSOR FOR
1467 SELECT clu_id FROM svc;
1468 EXEC SQL OPEN csr222;
1470 EXEC SQL FETCH csr222 INTO :id1;
1471 if (sqlca.sqlcode != 0) break;
1473 if (!hash_lookup(clusters, id1))
1474 sq_save_unique_data(sq1, id1);
1476 EXEC SQL CLOSE csr222;
1477 generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1479 dprintf("Checking lists...\n");
1480 hash_step(lists, list_check, NULL);
1482 dprintf("Checking members...\n");
1489 EXEC SQL DECLARE csr223 CURSOR FOR
1490 SELECT list_id, member_type, member_id, ref_count, direct
1491 FROM imembers FOR UPDATE OF member_id;
1492 EXEC SQL OPEN csr223;
1494 EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
1495 if (sqlca.sqlcode != 0) break;
1497 if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
1498 sq_save_unique_data(sq1, id1);
1499 else if (type[0] == 'U' && !hash_lookup(users, id2))
1500 sq_save_unique_data(sq2, id2);
1501 else if (type[0] == 'L' && !hash_lookup(lists, id2))
1502 sq_save_unique_data(sq3, id2);
1503 else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
1504 sq_save_unique_data(sq4, id2);
1505 else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
1506 sq_save_unique_data(sq5, id2);
1510 EXEC SQL CLOSE csr223;
1511 generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1512 generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1513 generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1514 generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1515 generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1517 dprintf("Checking servers...\n");
1520 EXEC SQL DECLARE csr224 CURSOR FOR
1521 SELECT name, acl_type, acl_id, modby FROM servers
1522 FOR UPDATE of modby;
1523 EXEC SQL OPEN csr224;
1525 EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2;
1526 if (sqlca.sqlcode != 0) break;
1528 maybe_fixup_modby2("servers","modby","csr224",id2);
1530 if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
1531 sq_save_data(sq1, id1);
1532 } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
1533 sq_save_data(sq2, id1);
1536 EXEC SQL CLOSE csr224;
1537 generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
1538 generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
1540 dprintf("Checking serverhosts...\n");
1542 EXEC SQL DECLARE csr225 CURSOR FOR
1543 SELECT mach_id, modby FROM serverhosts
1544 FOR UPDATE OF modby;
1545 EXEC SQL OPEN csr225;
1547 EXEC SQL FETCH csr225 INTO :id1, :id2;
1548 if (sqlca.sqlcode != 0) break;
1550 maybe_fixup_modby2("serverhosts", "modby", "csr225", id2);
1551 if (!hash_lookup(machines, id1))
1552 sq_save_data(sq, id1);
1554 EXEC SQL CLOSE csr225;
1555 generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1557 dprintf("Checking nfsphys...\n");
1558 hash_step(nfsphys, check_nfsphys, NULL);
1560 dprintf("Checking filesys...\n");
1561 hash_step(filesys, check_fs, NULL);
1563 dprintf("Checking filesystem groups...\n");
1567 EXEC SQL DECLARE csr226 CURSOR FOR
1568 SELECT group_id, filsys_id FROM fsgroup;
1569 EXEC SQL OPEN csr226;
1571 EXEC SQL FETCH csr226 INTO :id1, :id2;
1572 if (sqlca.sqlcode != 0) break;
1574 if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
1575 sq_save_data(sq1, id1);
1576 if (!hash_lookup(filesys, id2))
1577 sq_save_data(sq3, id2);
1579 EXEC SQL CLOSE csr226;
1580 generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
1581 generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
1583 dprintf("Checking quotas...\n");
1588 EXEC SQL DECLARE csr227 CURSOR FOR
1589 SELECT entity_id, type, filsys_id, phys_id, quota, modby
1590 FROM quota FOR UPDATE OF modby;
1591 EXEC SQL OPEN csr227;
1593 EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5;
1594 if (sqlca.sqlcode != 0) break;
1596 maybe_fixup_modby2("quota", "modby", "csr227", id5);
1597 if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
1598 sq_save_data(sq1, id1);
1599 else if (type[0] == 'G' && !hash_lookup(lists, id1))
1600 sq_save_data(sq4, id1);
1601 else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
1602 sq_save_data(sq2, id2);
1603 else if (id3 != f->phys_id ||
1604 ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) ==
1605 (struct nfsphys *)NULL))
1606 sq_save_data(sq3, id2);
1610 EXEC SQL CLOSE csr227;
1611 generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
1612 generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
1613 generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
1614 generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
1616 dprintf("Not checking zephyr.\n");
1618 dprintf("Checking hostaccess...\n");
1619 EXEC SQL DECLARE csr228 CURSOR FOR
1620 SELECT mach_id, acl_type, acl_id, modby FROM hostaccess
1621 FOR UPDATE OF modby;
1622 EXEC SQL OPEN csr228;
1624 EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3;
1625 if (sqlca.sqlcode != 0) break;
1627 maybe_fixup_modby2("hostaccess", "modby", "csr228", id3);
1629 if (!hash_lookup(machines, id1)) {
1630 printf("Hostaccess for non-existant host %d\n", id1);
1631 printf("Not fixing this error\n");
1633 if (!strcmp(type, "USER") && !hash_lookup(users, id2)) {
1634 printf("Hostaccess for %d is non-existant user %d\n", id1, id2);
1635 printf("Not fixing this error\n");
1636 } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) {
1637 printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
1638 printf("Not fixing this error\n");
1641 EXEC SQL CLOSE csr228;
1643 dprintf("Checking palladium...\n");
1645 EXEC SQL DECLARE csr229 CURSOR FOR
1646 SELECT mach_id, modby FROM palladium
1647 FOR UPDATE OF modby;
1648 EXEC SQL OPEN csr229;
1650 EXEC SQL FETCH csr229 INTO :id1, :id2;
1651 if (sqlca.sqlcode != 0) break;
1653 maybe_fixup_modby2("palladium", "modby", "csr229", id2);
1654 if (!hash_lookup(machines, id1)) {
1655 sq_save_unique_data(sq1, id1);
1658 EXEC SQL CLOSE csr229;
1659 generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
1661 dprintf("Checking krbmap...\n");
1664 EXEC SQL DECLARE csr230 CURSOR FOR
1665 SELECT users_id, string_id FROM krbmap
1666 FOR UPDATE OF string_id;
1667 EXEC SQL OPEN csr230;
1669 EXEC SQL FETCH csr230 INTO :id1, :id2;
1670 if (sqlca.sqlcode != 0) break;
1672 if (!hash_lookup(users, id1))
1673 sq_save_unique_data(sq1, id1);
1674 else if (!maybe_fixup_unref_string2("krbmap","string_id","csr230",id2))
1675 sq_save_unique_data(sq2, id2);
1677 EXEC SQL CLOSE csr230;
1678 generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
1679 generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
1681 dprintf("Checking capacls...\n");
1682 EXEC SQL DECLARE csr231 CURSOR FOR
1683 SELECT list_id, tag FROM capacls;
1684 EXEC SQL OPEN csr231;
1686 EXEC SQL FETCH csr231 INTO :id1, :name;
1687 if (sqlca.sqlcode != 0) break;
1689 if (!hash_lookup(lists, id1)) {
1690 printf("Capacl for %s is non-existant list %d\n", name, id1);
1691 printf("Not fixing this error\n");
1694 EXEC SQL CLOSE csr231;
1696 dprintf("Checking hostaliases\n");
1698 EXEC SQL DECLARE csr232 CURSOR FOR
1699 SELECT mach_id FROM hostalias;
1700 EXEC SQL OPEN csr232;
1702 EXEC SQL FETCH csr232 INTO :id1;
1703 if (sqlca.sqlcode != 0) break;
1705 if (!hash_lookup(machines, id1))
1706 sq_save_unique_data(sq1, id1);
1708 EXEC SQL CLOSE csr232;
1709 generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
1711 dprintf("Checking printcaps\n");
1714 EXEC SQL DECLARE csr233 CURSOR FOR
1715 SELECT mach_id, quotaserver, modby FROM printcap;
1716 EXEC SQL OPEN csr233;
1718 EXEC SQL FETCH csr233 INTO :id1, :id2, :id3;
1719 if (sqlca.sqlcode != 0) break;
1721 maybe_fixup_modby2("printcap", "modby", "csr233", id3);
1722 if (!hash_lookup(machines, id1))
1723 sq_save_unique_data(sq1, id1);
1724 else if(!hash_lookup(machines, id2))
1725 sq_save_unique_data(sq2, id2);
1727 EXEC SQL CLOSE csr233;
1728 generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1);
1729 generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1);