]> andersk Git - moira.git/blame - dbck/phase2.pc
.dc -> .pc
[moira.git] / dbck / phase2.pc
CommitLineData
68bbc9c3 1/* $Header$
2 *
3 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
5 * <mit-copyright.h>.
6 */
7
8#include <mit-copyright.h>
9#include <stdio.h>
10#include <moira.h>
11#include "dbck.h"
208a4f4a 12EXEC SQL INCLUDE sqlca;
68bbc9c3 13
14static char phase2_qc_rcsid[] = "$Header$";
15
4b9e5c72 16EXEC SQL WHENEVER SQLERROR DO dbmserr();
68bbc9c3 17
18show_mcm_mach(id)
19int id;
208a4f4a 20{
21 EXEC SQL BEGIN DECLARE SECTION;
22 int iid = id, found = 1;
23 char name[33];
24 EXEC SQL END DECLARE SECTION;
25
208a4f4a 26 EXEC SQL DECLARE csr201 CURSOR FOR
4b9e5c72 27 SELECT clusters.name FROM clusters, mcmap
28 WHERE clusters.clu_id=mcmap.clu_id AND mcmap.mach_id = :iid;
208a4f4a 29 EXEC SQL OPEN csr201;
30 while(1) {
31 EXEC SQL FETCH csr201 INTO :name;
4b9e5c72 32 if (sqlca.sqlcode != 0) break;
68bbc9c3 33
208a4f4a 34 strtrim(name);
35 found = 0;
ab05f33a 36 printf("Cluster %s, non-existant machine %d in cluster map\n", name, id);
208a4f4a 37 }
38 EXEC SQL CLOSE csr201;
68bbc9c3 39 return(found);
208a4f4a 40}
68bbc9c3 41
42show_mcm_clu(id)
43int id;
208a4f4a 44{
45 EXEC SQL BEGIN DECLARE SECTION;
46 int iid = id, found = 1;
47 char name[33];
48 EXEC SQL END DECLARE SECTION;
49
4b9e5c72 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;
208a4f4a 53 EXEC SQL OPEN csr202;
54 while(1) {
55 EXEC SQL FETCH csr202 INTO :name;
4b9e5c72 56 if (sqlca.sqlcode != 0) break;
68bbc9c3 57
208a4f4a 58 strtrim(name);
ab05f33a 59
208a4f4a 60 found = 0;
61 printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
62 }
63 EXEC SQL CLOSE csr202;
68bbc9c3 64 return(found);
208a4f4a 65}
68bbc9c3 66
ab05f33a 67show_hostalias(id)
68int id;
69{
70 EXEC SQL BEGIN DECLARE SECTION;
71 int iid = id, found = 1;
72 char name[33];
73 EXEC SQL END DECLARE SECTION;
74
75 EXEC SQL DECLARE csr234 CURSOR FOR
76 SELECT name FROM hostalias WHERE mach_id=:iid;
ab05f33a 77 EXEC SQL OPEN csr234;
78 while(1) {
79 EXEC SQL FETCH csr234 INTO :name;
4b9e5c72 80 if (sqlca.sqlcode != 0) break;
ab05f33a 81
82 strtrim(name);
83
84 found = 0;
85 printf("Alias %s, non-existant machine %d in hostalias map\n", name, id);
86 }
87 EXEC SQL CLOSE csr234;
88 return(found);
89}
90
91show_pcap_mach(id)
92int id;
93{
94 EXEC SQL BEGIN DECLARE SECTION;
95 int iid = id, found = 1;
96 char name[33];
97 EXEC SQL END DECLARE SECTION;
98
99 EXEC SQL DECLARE csr235 CURSOR FOR
100 SELECT name FROM printcap WHERE mach_id=:iid;
ab05f33a 101 EXEC SQL OPEN csr235;
102 while(1) {
103 EXEC SQL FETCH csr235 INTO :name;
4b9e5c72 104 if (sqlca.sqlcode != 0) break;
ab05f33a 105
106 strtrim(name);
107
108 found = 0;
109 printf("Printer %s, non-existant spool machine %d in printcap table\n", name, id);
110 }
111 EXEC SQL CLOSE csr235;
112 return(found);
113}
114
115show_pcap_quota(id)
116int id;
117{
118 EXEC SQL BEGIN DECLARE SECTION;
119 int iid = id, found = 1;
120 char name[33];
121 EXEC SQL END DECLARE SECTION;
122
123 EXEC SQL DECLARE csr236 CURSOR FOR
124 SELECT name FROM printcap WHERE quotaserver=:iid;
ab05f33a 125 EXEC SQL OPEN csr236;
126 while(1) {
127 EXEC SQL FETCH csr236 INTO :name;
4b9e5c72 128 if (sqlca.sqlcode != 0) break;
ab05f33a 129
130 strtrim(name);
131
132 found = 0;
133 printf("Printer %s, non-existant quota server %d in printcap table\n", name, id);
134 }
135 EXEC SQL CLOSE csr236;
136 return(found);
137}
138
139user_check(id, u, hint)
140 int id;
141 struct user *u;
142 int hint;
143{
144 u->comment=maybe_fixup_unref_string(u->comment, id, u->login, "users",
4b9e5c72 145 "comments", "users_id");
ab05f33a 146
147 u->modby=maybe_fixup_modby(u->modby, id, u->login, "users",
148 "modby", "users_id");
149
150 u->fmodby=maybe_fixup_modby(u->fmodby, id, u->login, "users",
151 "fmodby", "users_id");
152
153 u->pmodby=maybe_fixup_modby(u->pmodby, id, u->login, "users",
154 "pmodby", "users_id");
155
156 u->sigwho=maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
157 "sigwho", "users_id");
158
159 pobox_check(id, u, hint);
160}
161
162maybe_fixup_unref_string(sid, oid, oname, table, field, idfield)
163 int sid, oid;
164 char *oname, *table;
165 char *field, *idfield;
166{
167 int ret=(sid<0)?-sid:sid, doit=0, newid;
168 EXEC SQL BEGIN DECLARE SECTION;
169 int rowcount;
170 char stmt_buf[500];
171 EXEC SQL END DECLARE SECTION;
172
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)){
177 ret = newid;
178 string_check(newid);
179 doit=1;
180 }
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)) {
185 ret=0;
186 doit=1;
187 }
188 }
189
190 if(doit){
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;
4b9e5c72 194 rowcount = sqlca.sqlerrd[2];
ab05f33a 195 if (rowcount == 1)
196 printf("Fixed\n");
197 else
198 printf("Not fixed, rowcount = %d\n", rowcount);
199 modified(table);
200 }
201
202 return((sid<0)?-ret:ret);
203
204}
205
206maybe_fixup_modby(sid, oid, oname, table, field, idfield)
207 int sid, oid;
208 char *oname, *table;
209 char *field, *idfield;
210{
211 EXEC SQL BEGIN DECLARE SECTION;
212 char stmt_buf[500];
213 int rowcount;
214 EXEC SQL END DECLARE SECTION;
215
216 if(sid<0)
217 return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
218 else {
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 = %d WHERE %s=%d",
224 table, field, 0, idfield, oid);
225 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
4b9e5c72 226 rowcount = sqlca.sqlerrd[2];
ab05f33a 227 if (rowcount == 1)
228 printf("Fixed\n");
229 else
230 printf("Not fixed, rowcount = %d\n", rowcount);
231 modified(table);
232 }
233 return 0;
234 }
235 }
236 return sid;
237}
238
239maybe_fixup_unref_string2(table, field, cursor, sid)
240 int sid;
241 char *field, *table, *cursor;
242{
243 int ret=(sid<0)?-sid:sid, doit=0, newid;
244 EXEC SQL BEGIN DECLARE SECTION;
245 int rowcount;
246 char stmt_buf[500];
247 EXEC SQL END DECLARE SECTION;
248
249 if(newid=int_hash_lookup(string_dups, ret)) {
250 printf("%s entry has a %s with duplicate string %d\n",
251 table, field, ret);
252 if(single_fix("Replace duplicate", 0)){
253 ret = newid;
254 string_check(newid);
255 doit=1;
256 }
257 } else if(!string_check(ret)) {
258 printf("%s entry has a %s with non-existant string %d\n",
259 table, field, ret);
260 if (single_fix("Delete", 1)) {
261 ret=0;
262 doit=1;
263 }
264 }
265
266 if(doit){
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;
4b9e5c72 270 rowcount = sqlca.sqlerrd[2];
ab05f33a 271 if (rowcount == 1)
272 printf("Fixed\n");
273 else
274 printf("Not fixed, rowcount = %d\n", rowcount);
275 modified(table);
276 }
277 return((sid<0)?-ret:ret);
278}
279
280maybe_fixup_modby2(table, field, cursor, id)
281{
282 EXEC SQL BEGIN DECLARE SECTION;
283 char stmt_buf[500];
284 int rowcount;
285 EXEC SQL END DECLARE SECTION;
286
287 if(id<0) return maybe_fixup_unref_string2(table, field, cursor, id);
288 else {
289 if(!hash_lookup(users, id)) {
290 printf("%s entry has a %s with non-existant user %d\n",
291 table, field, id);
292 if (single_fix("Delete", 1)) {
293 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE CURRENT OF %s",
294 table, field, 0, cursor);
295 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
4b9e5c72 296 rowcount = sqlca.sqlerrd[2];
ab05f33a 297 if (rowcount == 1)
298 printf("Fixed\n");
299 else
300 printf("Not fixed, rowcount = %d\n", rowcount);
301 modified(table);
302 }
303 return 0;
304 }
305 }
306 return 1;
307}
308
68bbc9c3 309pobox_check(id, u, hint)
310int id;
311struct user *u;
312int hint;
313{
ab05f33a 314 switch (u->potype) {
315 case 'P':
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);
321 u->potype = 'N';
322 }
323 }
324 break;
325 case 'S':
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",
331 u->pobox_id,
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);
336 }
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);
342 u->potype = 'N';
343 }
68bbc9c3 344 }
ab05f33a 345 break;
346 default:
347 ;
348 }
68bbc9c3 349}
350
351
352remove_pobox(id)
353int id;
208a4f4a 354{
355 EXEC SQL BEGIN DECLARE SECTION;
356 int rowcount, iid = id;
357 EXEC SQL END DECLARE SECTION;
7bf0a6f3 358
208a4f4a 359 EXEC SQL UPDATE users SET potype='NONE' WHERE users.users_id = :iid;
4b9e5c72 360 rowcount = sqlca.sqlerrd[2];
68bbc9c3 361 if (rowcount > 0)
362 printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies");
363 else
364 printf("Not removed\n");
365 modified("users");
208a4f4a 366}
68bbc9c3 367
ab05f33a 368fix_smtp_pobox(id, sid)
369int id, sid;
370{
371 EXEC SQL BEGIN DECLARE SECTION;
372 int rowcount, iid = id, isid=sid;
373 EXEC SQL END DECLARE SECTION;
374
375 EXEC SQL UPDATE users SET box_id=:isid WHERE users.users_id = :iid;
4b9e5c72 376 rowcount = sqlca.sqlerrd[2];
ab05f33a 377 if (rowcount > 0)
378 printf("%d entr%s updated\n", rowcount, rowcount==1?"y":"ies");
379 else
380 printf("Not updated\n");
381 modified("users");
382}
772b7afc 383
384mach_check(id, m, hint)
385int id;
386struct machine *m;
387int hint;
388{
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;
396
397 EXEC SQL UPDATE machine SET snet_id=0 WHERE mach_id = :iid;
4b9e5c72 398 rowcount = sqlca.sqlerrd[2];
772b7afc 399 if (rowcount > 0)
400 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
401 else
402 printf("Not fixed\n");
403 modified("machine");
404 }
405 }
406
407 switch (m->owner_type) {
408 case 'U':
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)) {
413 clear_mach_owner(m);
414 }
415 }
416 break;
417 case 'L':
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)) {
422 clear_mach_owner(m);
423 }
424 }
425 break;
ab05f33a 426 case 'S':
427 case 'K':
428 if(m->owner_id)
429 m->owner_id=maybe_fixup_unref_string(m->owner_id, id, m->name,
430 "machine", "owner_id", "mach_id");
431 if(m->owner_id==0)
432 clear_mach_owner(m);
772b7afc 433 }
ab05f33a 434
435 if(m->acomment)
436 m->acomment=maybe_fixup_unref_string(m->acomment, id, m->name,
437 "machine", "acomment", "mach_id");
438 if(m->ocomment)
439 m->ocomment=maybe_fixup_unref_string(m->ocomment, id, m->name,
440 "machine", "ocomment", "mach_id");
441
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",
445 "modby", "mach_id");
772b7afc 446}
447
ab05f33a 448subnet_check(id, s, hint)
449int id;
450struct subnet *s;
451int hint;
452{
453 switch (s->owner_type) {
454 case 'U':
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);
460 }
461 }
462 break;
463 case 'L':
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);
469 }
470 }
471 break;
472 case 'S':
473 case 'K':
474 if(s->owner_id)
475 s->owner_id=maybe_fixup_unref_string(s->owner_id, id, s->name,
476 "machine", "owner_id", "mach_id");
477 if(s->owner_id==0)
478 clear_subnet_owner(s);
479 }
480
481 s->modby=maybe_fixup_modby(s->modby, id, s->name, "subnet",
482 "modby", "snet_id");
483}
484
485
486clear_subnet_owner(s)
487struct subnet *s;
488{
489 EXEC SQL BEGIN DECLARE SECTION;
490 int rowcount, id = s->snet_id;
491 EXEC SQL END DECLARE SECTION;
492
493 EXEC SQL UPDATE subnet SET owner_type='NONE', owner_id=0
494 WHERE snet_id = :id;
4b9e5c72 495 rowcount = sqlca.sqlerrd[2];
ab05f33a 496 if (rowcount > 0)
497 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
498 else
499 printf("Not fixed\n");
500 modified("subnet");
501}
772b7afc 502
503clear_mach_owner(m)
504struct machine *m;
505{
506 EXEC SQL BEGIN DECLARE SECTION;
507 int rowcount, id = m->mach_id;
508 EXEC SQL END DECLARE SECTION;
509
510 EXEC SQL UPDATE machine SET owner_type='NONE', owner_id=0
511 WHERE mach_id = :id;
4b9e5c72 512 rowcount = sqlca.sqlerrd[2];
772b7afc 513 if (rowcount > 0)
514 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
515 else
516 printf("Not fixed\n");
517 modified("machine");
518}
519
ab05f33a 520cluster_check(id, c, hint)
521int id;
522struct cluster *c;
523int hint;
524{
4b9e5c72 525 c->modby=maybe_fixup_modby(c->modby, id, c->name, "clusters",
ab05f33a 526 "modby", "clu_id");
527}
528
529
772b7afc 530
68bbc9c3 531show_svc(id)
532int id;
208a4f4a 533{
534 EXEC SQL BEGIN DECLARE SECTION;
535 int iid = id, found = 1;
536 char label[17], data[33];
537 EXEC SQL END DECLARE SECTION;
538
208a4f4a 539 EXEC SQL DECLARE csr203 CURSOR FOR
540 SELECT serv_label, serv_cluster FROM svc
541 WHERE clu_id = :iid;
542 EXEC SQL OPEN csr203;
543 while(1) {
544 EXEC SQL FETCH csr203 INTO :label, :data;
4b9e5c72 545 if (sqlca.sqlcode != 0) break;
208a4f4a 546
547 strtrim(label);
548 strtrim(data);
549 found = 0;
550 printf("Cluster data [%s] %s for non-existant cluster %d\n",
551 label, data, id);
552 }
553 EXEC SQL CLOSE csr203;
68bbc9c3 554 return(found);
208a4f4a 555}
68bbc9c3 556
557list_check(id, l, hint)
558int id;
559struct list *l;
560int hint;
561{
562 switch (l->acl_type) {
563 case 'L':
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);
568 }
569 }
570 break;
571 case 'U':
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);
576 }
577 }
578 break;
ab05f33a 579 case 'K':
580 l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
581 "list", "acl_id", "list_id");
582 if (!l->acl_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);
586 }
587 }
588 break;
68bbc9c3 589 }
590}
591
592fix_list_acl(id)
593int id;
208a4f4a 594{
595 EXEC SQL BEGIN DECLARE SECTION;
596 int rowcount, iid = id;
597 EXEC SQL END DECLARE SECTION;
598
208a4f4a 599 EXEC SQL UPDATE list SET acl_id = :iid, acl_type='LIST'
600 WHERE list_id = :iid;
4b9e5c72 601 rowcount = sqlca.sqlerrd[2];
68bbc9c3 602 if (rowcount > 0)
603 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
604 else
605 printf("Not fixed\n");
606 modified("list");
208a4f4a 607}
68bbc9c3 608
609
610show_member_list(id)
611int id;
208a4f4a 612{
613 EXEC SQL BEGIN DECLARE SECTION;
614 int mid, iid = id, found = 1;
615 char mtype[9], *name = "";
616 EXEC SQL END DECLARE SECTION;
617
208a4f4a 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;
622 while(1) {
623 EXEC SQL FETCH csr204 INTO :mtype, :mid;
4b9e5c72 624 if (sqlca.sqlcode != 0) break;
208a4f4a 625
626 strtrim(mtype);
627 found = 0;
628 if (mtype[0] == 'L')
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);
635 }
636 EXEC SQL CLOSE csr204;
68bbc9c3 637 return(found);
208a4f4a 638}
68bbc9c3 639
640show_mem_user(id)
641int id;
208a4f4a 642{
643 EXEC SQL BEGIN DECLARE SECTION;
644 int lid, iid = id, found = 1;
645 char name[33];
646 EXEC SQL END DECLARE SECTION;
647
208a4f4a 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;
652 while(1) {
653 EXEC SQL FETCH csr205 INTO :lid;
4b9e5c72 654 if (sqlca.sqlcode != 0) break;
208a4f4a 655
656 found = 0;
657 printf("List %s has non-existant user member, id %d\n",
658 ((struct list *)hash_lookup(lists, lid))->name, iid);
659 }
660 EXEC SQL CLOSE csr205;
68bbc9c3 661 return(found);
208a4f4a 662}
68bbc9c3 663
664show_mem_list(id)
665int id;
208a4f4a 666{
667 EXEC SQL BEGIN DECLARE SECTION;
668 int lid, iid = id, found = 1;
669 char name[33];
670 EXEC SQL END DECLARE SECTION;
671
208a4f4a 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;
676 while(1) {
677 EXEC SQL FETCH csr206 INTO :lid;
4b9e5c72 678 if (sqlca.sqlcode != 0) break;
208a4f4a 679
680 found = 0;
681 printf("List %s has non-existant list member, id %d\n",
682 ((struct list *)hash_lookup(lists, lid))->name, iid);
683 }
684 EXEC SQL CLOSE csr206;
68bbc9c3 685 return(found);
208a4f4a 686}
68bbc9c3 687
688show_mem_str(id)
689int id;
208a4f4a 690{
691 EXEC SQL BEGIN DECLARE SECTION;
692 int lid, iid = id, found = 1;
693 char name[33];
694 EXEC SQL END DECLARE SECTION;
695
208a4f4a 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;
700 while(1) {
701 EXEC SQL FETCH csr207 INTO :lid;
4b9e5c72 702 if (sqlca.sqlcode != 0) break;
208a4f4a 703
704 found = 0;
705 printf("List %s has non-existant string member, id %d\n",
706 ((struct list *)hash_lookup(lists, lid))->name, iid);
707 }
708 EXEC SQL CLOSE csr207;
68bbc9c3 709 return(found);
208a4f4a 710}
68bbc9c3 711
712
713show_mem_krb(id)
714int id;
208a4f4a 715{
716 EXEC SQL BEGIN DECLARE SECTION;
717 int lid, iid = id, found = 1;
718 char name[33];
719 EXEC SQL END DECLARE SECTION;
720
208a4f4a 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;
725 while(1) {
726 EXEC SQL FETCH csr208 INTO :lid;
4b9e5c72 727 if (sqlca.sqlcode != 0) break;
68bbc9c3 728
208a4f4a 729 found = 0;
730 printf("List %s has non-existant kerberos member, id %d\n",
731 ((struct list *)hash_lookup(lists, lid))->name, iid);
732 }
733 EXEC SQL CLOSE csr208;
734 return(found);
735}
68bbc9c3 736
68bbc9c3 737
208a4f4a 738del_mem_user(id)
739EXEC SQL BEGIN DECLARE SECTION;
740int id;
741EXEC SQL END DECLARE SECTION;
742{
743 EXEC SQL BEGIN DECLARE SECTION;
744 int rowcount;
745 EXEC SQL END DECLARE SECTION;
746
208a4f4a 747 EXEC SQL DELETE FROM imembers WHERE member_type='USER' AND
748 member_id = :id AND direct = 1;
4b9e5c72 749 rowcount = sqlca.sqlerrd[2];
68bbc9c3 750 if (rowcount > 0)
751 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
752 else
753 printf("Not deleted\n");
754 modified("imembers");
208a4f4a 755}
68bbc9c3 756
208a4f4a 757del_mem_list(id)
758EXEC SQL BEGIN DECLARE SECTION;
759int id;
760EXEC SQL END DECLARE SECTION;
761{
762 EXEC SQL BEGIN DECLARE SECTION;
763 int rowcount;
764 EXEC SQL END DECLARE SECTION;
765
208a4f4a 766 EXEC SQL DELETE FROM imembers WHERE member_type='LIST' AND
767 member_id = :id AND direct=1;
4b9e5c72 768 rowcount = sqlca.sqlerrd[2];
68bbc9c3 769 if (rowcount > 0)
770 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
771 else
772 printf("Not deleted\n");
773 modified("imembers");
208a4f4a 774}
68bbc9c3 775
208a4f4a 776del_mem_str(id)
777EXEC SQL BEGIN DECLARE SECTION;
778int id;
779EXEC SQL END DECLARE SECTION;
780{
781 EXEC SQL BEGIN DECLARE SECTION;
782 int rowcount;
783 EXEC SQL END DECLARE SECTION;
784
208a4f4a 785 EXEC SQL DELETE FROM imembers WHERE member_type='STRING' AND
786 member_id = :id AND direct=1;
4b9e5c72 787 rowcount = sqlca.sqlerrd[2];
68bbc9c3 788 if (rowcount > 0)
789 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
790 else
791 printf("Not deleted\n");
792 modified("imembers");
208a4f4a 793}
68bbc9c3 794
68bbc9c3 795
208a4f4a 796del_mem_krb(id)
797EXEC SQL BEGIN DECLARE SECTION;
798int id;
799EXEC SQL END DECLARE SECTION;
800{
801 EXEC SQL BEGIN DECLARE SECTION;
802 int rowcount;
803 EXEC SQL END DECLARE SECTION;
804
208a4f4a 805 EXEC SQL DELETE FROM imembers WHERE member_type='KERBEROS' AND
806 member_id = :id AND direct=1;
4b9e5c72 807 rowcount = sqlca.sqlerrd[2];
68bbc9c3 808 if (rowcount > 0)
809 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
810 else
811 printf("Not deleted\n");
812 modified("imembers");
208a4f4a 813}
68bbc9c3 814
815
208a4f4a 816show_sh(id)
817EXEC SQL BEGIN DECLARE SECTION;
818int id;
819EXEC SQL END DECLARE SECTION;
820{
821 EXEC SQL BEGIN DECLARE SECTION;
822 char name[33];
823 EXEC SQL END DECLARE SECTION;
68bbc9c3 824 int found = 1;
825
208a4f4a 826 EXEC SQL DECLARE csr209 CURSOR FOR
827 SELECT service FROM serverhosts
828 WHERE mach_id = :id;
829 EXEC SQL OPEN csr209;
830 while(1) {
831 EXEC SQL FETCH csr209 INTO :name;
4b9e5c72 832 if (sqlca.sqlcode != 0) break;
208a4f4a 833
834 found = 0;
835 printf("ServerHost entry for service %s non-existant host %d\n",
836 name, id);
837 }
838 EXEC SQL CLOSE csr209;
68bbc9c3 839 return(found);
208a4f4a 840}
68bbc9c3 841
208a4f4a 842del_sh_mach(id)
843EXEC SQL BEGIN DECLARE SECTION;
844int id;
845EXEC SQL END DECLARE SECTION;
846{
847 EXEC SQL BEGIN DECLARE SECTION;
848 int rowcount;
849 EXEC SQL END DECLARE SECTION;
68bbc9c3 850
208a4f4a 851 EXEC SQL DELETE FROM serverhosts WHERE mach_id = :id;
4b9e5c72 852 rowcount = sqlca.sqlerrd[2];
68bbc9c3 853 if (rowcount > 0)
854 printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
855 else
856 printf("Not deleted\n");
857 modified("serverhosts");
208a4f4a 858}
68bbc9c3 859
860
861static int fnchecklen;
862
863fsmatch(id, n, f)
864int id;
865struct nfsphys *n;
866struct filesys *f;
867{
868 if (n->mach_id == f->mach_id &&
869 !strncmp(f->dir, n->dir, strlen(n->dir)) &&
870 strlen(n->dir) > fnchecklen) {
871 f->phys_id = id;
872 fnchecklen = strlen(n->dir);
873 }
874}
875
876
208a4f4a 877check_fs(id, f, hint)
878EXEC SQL BEGIN DECLARE SECTION;
879int id;
880EXEC SQL END DECLARE SECTION;
68bbc9c3 881register struct filesys *f;
882int hint;
208a4f4a 883{
884 EXEC SQL BEGIN DECLARE SECTION;
885 int id1, id2, id3, rowcount;
886 char *dir;
887 EXEC SQL END DECLARE SECTION;
68bbc9c3 888 struct nfsphys *n;
889 struct machine *m;
890
891 if (!hash_lookup(machines, f->mach_id)) {
892 printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
893 if (single_fix("Fix", 0)) {
208a4f4a 894 EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :id;
4b9e5c72 895 rowcount = sqlca.sqlerrd[2];
68bbc9c3 896 if (rowcount > 0)
897 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
898 else
899 printf("Not fixed\n");
900 modified("filesys");
901 f->mach_id = 0;
902 }
903 }
904
905 if (!hash_lookup(users, f->owner)) {
906 printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
907 if (single_fix("Fix", 1)) {
908 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
909 f->owner = 0;
910 }
911 }
912 if (!hash_lookup(lists, f->owners)) {
913 printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
914 if (single_fix("Fix", 1)) {
915 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
916 f->owners = 0;
917 }
918 }
919
920 if (f->type == 'N') {
921 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)) {
925 fnchecklen = 0;
926 hash_step(nfsphys, fsmatch, f);
927 if (fnchecklen != 0) {
928 id1 = f->phys_id;
929 id2 = f->filsys_id;
930 id3 = f->mach_id;
208a4f4a 931 EXEC SQL UPDATE filesys SET phys_id = :id1 WHERE filsys_id = :id2;
4b9e5c72 932 rowcount = sqlca.sqlerrd[2];
68bbc9c3 933 if (rowcount > 0)
934 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
935 else
936 printf("Not fixed\n");
937 modified("filesys");
938 } else {
939 printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
940 if (single_fix("Create", 0)) {
941 dir = f->dir;
942 id1 = f->phys_id;
943 id2 = f->filsys_id;
944 id3 = f->mach_id;
945 if (set_next_object_id("nfsphys_id", "nfsphys") !=
946 MR_SUCCESS) {
947 printf("Unable to assign unique ID\n");
948 return;
949 }
208a4f4a 950 EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
951 WHERE name='nfsphys_id';
68bbc9c3 952 if (rowcount != 1) {
953 printf("Unable to retrieve unique ID\n");
954 return;
955 }
208a4f4a 956 EXEC SQL INSERT INTO mfsphys (mfsphys_id, mach_id,
957 device, dir, status, allocated, size, modtime,
4b9e5c72 958 modby, modwith) VALUES (:id1, :id3, '\?\?\?', :dir,
959 0, 0, 0, SYSDATE, 0, 'dbck');
960 rowcount = sqlca.sqlerrd[2];
68bbc9c3 961 if (rowcount > 0)
962 printf("%d entr%s created\n", rowcount,
963 rowcount==1?"y":"ies");
964 else
965 printf("Not created\n");
966 modified("nfsphys");
967 n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
968 if (n == NULL)
969 out_of_mem("storing new nfsphys");
970 strcpy(n->dir, dir);
971 n->mach_id = id3;
972 n->nfsphys_id = id1;
973 n->allocated = 0;
974 n->count = 0;
ab05f33a 975 if( hash_store(nfsphys, id1, n) == -1 ) {
976 out_of_mem("storing nfsphys in hash table");
977 }
208a4f4a 978 EXEC SQL UPDATE filesys SET phys_id = :id1
979 WHERE filsys_id = :id2;
4b9e5c72 980 rowcount = sqlca.sqlerrd[2];
68bbc9c3 981 if (rowcount > 0)
982 printf("%d filesys entr%s fixed\n", rowcount,
983 rowcount==1?"y":"ies");
984 else
985 printf("Not fixed\n");
986 modified("filesys");
987 }
988 }
989 }
990 }
991 }
208a4f4a 992}
68bbc9c3 993
994
995check_nfsphys(id, n, hint)
996int id;
997struct nfsphys *n;
998int hint;
999{
1000 if (!hash_lookup(machines, n->mach_id)) {
1001 printf("NFSphys %d(%s) on non-existant machine %d\n",
1002 id, n->dir, n->mach_id);
1003 if (single_fix("Delete", 0))
1004 single_delete("nfsphys", "nfsphys_id", id);
1005 }
1006}
1007
208a4f4a 1008show_fsg_missing(id)
1009EXEC SQL BEGIN DECLARE SECTION;
1010int id;
1011EXEC SQL END DECLARE SECTION;
1012{
1013 EXEC SQL BEGIN DECLARE SECTION;
1014 int id1, found = 1;
1015 EXEC SQL END DECLARE SECTION;
68bbc9c3 1016 struct filesys *f;
1017
208a4f4a 1018 EXEC SQL DECLARE csr210 CURSOR FOR
1019 SELECT filsys_id FROM fsgroup
1020 WHERE group_id = :id;
1021 EXEC SQL OPEN csr210;
1022 while(1) {
1023 EXEC SQL FETCH csr210 INTO :id1;
4b9e5c72 1024 if (sqlca.sqlcode != 0) break;
208a4f4a 1025
1026 found = 0;
1027 if (f = (struct filesys *) hash_lookup(filesys, id1))
1028 printf("Missing fsgroup %d has member filesystem %s\n", id, f->name);
1029 else
1030 printf("Missing fsgroup %d has member filesystem %d\n", id, id1);
1031 }
1032 EXEC SQL CLOSE csr210;
68bbc9c3 1033 return(found);
208a4f4a 1034}
68bbc9c3 1035
1036show_fsg_type(f)
1037struct filesys *f;
1038{
1039 char *t;
1040
1041 switch (f->type) {
1042 case 'N':
1043 t = "NFS";
1044 break;
1045 case 'R':
1046 t = "RVD";
1047 break;
1048 case 'A':
1049 t = "AFS";
1050 break;
1051 case 'E':
1052 t = "ERR";
1053 break;
1054 case 'F':
1055 t = "FSGROUP";
1056 break;
1057 case 'M':
1058 t = "MUL";
1059 break;
1060 default:
4b9e5c72 1061 t = "\?\?\?";
68bbc9c3 1062 }
1063 printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1064 return(0);
1065}
1066
1067fix_fsg_type(f)
1068struct filesys *f;
208a4f4a 1069{
1070 EXEC SQL BEGIN DECLARE SECTION;
1071 int rowcount, id = f->filsys_id;
1072 EXEC SQL END DECLARE SECTION;
68bbc9c3 1073
208a4f4a 1074 EXEC SQL UPDATE filesys SET type='FSGROUP' WHERE filsys_id = :id;
4b9e5c72 1075 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1076 if (rowcount > 0)
1077 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1078 else
1079 printf("Not fixed\n");
1080 modified("filesys");
208a4f4a 1081}
68bbc9c3 1082
208a4f4a 1083show_fsg_nomember(id)
1084EXEC SQL BEGIN DECLARE SECTION;
1085int id;
1086EXEC SQL END DECLARE SECTION;
1087{
1088 EXEC SQL BEGIN DECLARE SECTION;
1089 int id1, found = 1;
1090 EXEC SQL END DECLARE SECTION;
68bbc9c3 1091 struct filesys *f;
1092
208a4f4a 1093 EXEC SQL DECLARE csr211 CURSOR FOR
1094 SELECT group_id FROM fsgroup
1095 WHERE filsys_id = :id;
1096 EXEC SQL OPEN csr211;
1097 while(1) {
1098 EXEC SQL FETCH csr211 INTO :id1;
4b9e5c72 1099 if (sqlca.sqlcode != 0) break;
208a4f4a 1100
1101 found = 0;
1102 if (f = (struct filesys *) hash_lookup(filesys, id1))
1103 printf("FSGroup %s has missing member %d\n", f->name, id);
1104 else
1105 printf("FSGroup %d has missing member %d\n", id1, id);
1106 }
1107 EXEC SQL CLOSE csr211;
68bbc9c3 1108 return(found);
208a4f4a 1109}
1110
1111show_quota_nouser(id)
1112EXEC SQL BEGIN DECLARE SECTION;
1113int id;
1114EXEC SQL END DECLARE SECTION;
1115{
1116 EXEC SQL BEGIN DECLARE SECTION;
1117 int id1, found = 1;
1118 EXEC SQL END DECLARE SECTION;
1119
208a4f4a 1120 EXEC SQL DECLARE csr212 CURSOR FOR
1121 SELECT filsys_id FROM quota
1122 WHERE entity_id = :id AND type='USER';
1123 EXEC SQL OPEN csr212;
1124 while(1) {
1125 EXEC SQL FETCH csr212 INTO :id1;
4b9e5c72 1126 if (sqlca.sqlcode != 0) break;
208a4f4a 1127
1128 found = 0;
1129 printf("Quota on fs %d for non-existant user %d\n", id1, id);
1130 }
1131 EXEC SQL CLOSE csr212;
68bbc9c3 1132 return(found);
208a4f4a 1133}
1134
1135show_quota_nolist(id)
1136EXEC SQL BEGIN DECLARE SECTION;
1137int id;
1138EXEC SQL END DECLARE SECTION;
1139{
1140 EXEC SQL BEGIN DECLARE SECTION;
1141 int id1, found = 1;
1142 EXEC SQL END DECLARE SECTION;
1143
208a4f4a 1144 EXEC SQL DECLARE csr213 CURSOR FOR
1145 SELECT filsys_id FROM quota
1146 WHERE entity_id = :id AND type='GROUP';
1147 EXEC SQL OPEN csr213;
1148 while(1) {
1149 EXEC SQL FETCH csr213 INTO :id1;
4b9e5c72 1150 if (sqlca.sqlcode != 0) break;
208a4f4a 1151
1152 found = 0;
1153 printf("Quota on fs %d for non-existant list %d\n", id1, id);
1154 }
1155 EXEC SQL CLOSE csr213;
68bbc9c3 1156 return(found);
208a4f4a 1157}
68bbc9c3 1158
208a4f4a 1159fix_quota_nouser(id)
1160EXEC SQL BEGIN DECLARE SECTION;
1161int id;
1162EXEC SQL END DECLARE SECTION;
1163{
1164 EXEC SQL BEGIN DECLARE SECTION;
1165 int rowcount, id1;
1166 EXEC SQL END DECLARE SECTION;
68bbc9c3 1167
1168 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
208a4f4a 1169 EXEC SQL DELETE FROM quota
1170 WHERE entity_id = :id AND type = 'USER';
4b9e5c72 1171 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1172 if (rowcount > 0)
1173 printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1174 else
1175 printf("Not deleted\n");
1176 modified("quota");
208a4f4a 1177}
68bbc9c3 1178
208a4f4a 1179fix_quota_nolist(id)
1180EXEC SQL BEGIN DECLARE SECTION;
1181int id;
1182EXEC SQL END DECLARE SECTION;
1183{
1184 EXEC SQL BEGIN DECLARE SECTION;
1185 int rowcount, id1;
1186 EXEC SQL END DECLARE SECTION;
68bbc9c3 1187
1188 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
208a4f4a 1189 EXEC SQL DELETE FROM quota WHERE entity_id = :id AND type='GROUP';
4b9e5c72 1190 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1191 if (rowcount > 0)
1192 printf("%d entr%s deleted\n",rowcount, rowcount==1?"y":"ies");
1193 else
1194 printf("Not deleted\n");
1195 modified("quota");
208a4f4a 1196}
1197
1198show_quota_nofs(id)
1199EXEC SQL BEGIN DECLARE SECTION;
1200int id;
1201EXEC SQL END DECLARE SECTION;
1202{
1203 EXEC SQL BEGIN DECLARE SECTION;
1204 int id1, found = 1;
1205 char type[9];
1206 EXEC SQL END DECLARE SECTION;
1207
208a4f4a 1208 EXEC SQL DECLARE csr214 CURSOR FOR
1209 SELECT entity_id, type FROM quota
1210 WHERE filsys_id = :id;
1211 EXEC SQL OPEN csr214;
1212 while(1) {
1213 EXEC SQL FETCH csr214 INTO :id1, :type;
4b9e5c72 1214 if (sqlca.sqlcode != 0) break;
208a4f4a 1215
1216 found = 0;
1217 printf("Quota for %s %d on non-existant filesys %d\n", type, id1, id);
1218 }
1219 EXEC SQL CLOSE csr214;
68bbc9c3 1220 return(found);
208a4f4a 1221}
68bbc9c3 1222
1223fix_quota_nofs(id)
1224{
1225 single_delete("quota", "filsys_id", id);
1226}
1227
208a4f4a 1228show_quota_wrongpid(id)
1229EXEC SQL BEGIN DECLARE SECTION;
1230int id;
1231EXEC SQL END DECLARE SECTION;
1232{
1233 EXEC SQL BEGIN DECLARE SECTION;
1234 int id1, found = 1;
1235 char type[9];
1236 EXEC SQL END DECLARE SECTION;
68bbc9c3 1237 struct user *u;
1238 struct filesys *f;
1239
1240 f = (struct filesys *)hash_lookup(filesys, id);
208a4f4a 1241 EXEC SQL DECLARE csr215 CURSOR FOR
1242 SELECT entity_id, type FROM quota
1243 WHERE filsys_id = :id;
1244 EXEC SQL OPEN csr215;
1245 while(1) {
1246 EXEC SQL FETCH csr215 INTO :id1, :type;
4b9e5c72 1247 if (sqlca.sqlcode != 0) break;
208a4f4a 1248
1249 found = 0;
1250 printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
1251 type, id1, f->name, id);
1252 }
1253 EXEC SQL CLOSE csr215;
68bbc9c3 1254 return(found);
208a4f4a 1255}
68bbc9c3 1256
208a4f4a 1257fix_quota_physid(id)
1258EXEC SQL BEGIN DECLARE SECTION;
1259int id;
1260EXEC SQL END DECLARE SECTION;
1261{
1262 EXEC SQL BEGIN DECLARE SECTION;
1263 int rowcount, id1;
1264 EXEC SQL END DECLARE SECTION;
68bbc9c3 1265
1266 id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
208a4f4a 1267 EXEC SQL UPDATE quota SET phys_id = :id1
1268 WHERE filsys_id = :id AND phys_id != :id1;
4b9e5c72 1269 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1270 if (rowcount > 0)
1271 printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
1272 else
1273 printf("Not fixed\n");
1274 modified("quota");
208a4f4a 1275}
68bbc9c3 1276
208a4f4a 1277show_srv_user(id)
1278EXEC SQL BEGIN DECLARE SECTION;
1279int id;
1280EXEC SQL END DECLARE SECTION;
1281{
1282 EXEC SQL BEGIN DECLARE SECTION;
1283 char name[33];
1284 EXEC SQL END DECLARE SECTION;
68bbc9c3 1285 int found = 1;
1286
208a4f4a 1287 EXEC SQL DECLARE csr216 CURSOR FOR
1288 SELECT name FROM servers
1289 WHERE acl_type='USER' and acl_id = :id;
1290 EXEC SQL OPEN csr216;
1291 while(1) {
1292 EXEC SQL FETCH csr216 INTO :name;
4b9e5c72 1293 if (sqlca.sqlcode != 0) break;
208a4f4a 1294
68bbc9c3 1295 strtrim(name);
1296 printf("Service %s has acl non-existant user %d\n", name, id);
1297 found = 0;
208a4f4a 1298 }
1299 EXEC SQL CLOSE csr216;
68bbc9c3 1300 return(found);
208a4f4a 1301}
68bbc9c3 1302
208a4f4a 1303show_srv_list(id)
1304EXEC SQL BEGIN DECLARE SECTION;
1305int id;
1306EXEC SQL END DECLARE SECTION;
1307{
1308 EXEC SQL BEGIN DECLARE SECTION;
1309 char name[33];
1310 EXEC SQL END DECLARE SECTION;
68bbc9c3 1311 int found = 1;
1312
208a4f4a 1313 EXEC SQL DECLARE csr217 CURSOR FOR
1314 SELECT name FROM servers
1315 WHERE acl_type='LIST' AND acl_id = :id;
1316 EXEC SQL OPEN csr217;
1317 while(1) {
1318 EXEC SQL FETCH csr217 INTO :name;
4b9e5c72 1319 if (sqlca.sqlcode != 0) break;
208a4f4a 1320
68bbc9c3 1321 strtrim(name);
1322 printf("Service %s has acl non-existant list %d\n", name, id);
1323 found = 0;
208a4f4a 1324 }
1325 EXEC SQL CLOSE csr217;
68bbc9c3 1326 return(found);
208a4f4a 1327}
68bbc9c3 1328
208a4f4a 1329zero_srv_user(id)
1330EXEC SQL BEGIN DECLARE SECTION;
1331int id;
1332EXEC SQL END DECLARE SECTION;
1333{
1334 EXEC SQL BEGIN DECLARE SECTION;
1335 int rowcount;
1336 EXEC SQL END DECLARE SECTION;
1337
208a4f4a 1338 EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
1339 acl_type='USER';
4b9e5c72 1340 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1341 if (rowcount > 0)
1342 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1343 else
1344 printf("Not fixed\n");
1345 modified("servers");
208a4f4a 1346}
68bbc9c3 1347
208a4f4a 1348zero_srv_list(id)
1349EXEC SQL BEGIN DECLARE SECTION;
1350int id;
1351EXEC SQL END DECLARE SECTION;
1352{
1353 EXEC SQL BEGIN DECLARE SECTION;
1354 int rowcount;
1355 EXEC SQL END DECLARE SECTION;
1356
208a4f4a 1357 EXEC SQL UPDATE servers SET acl_id=0 WHERE acl_id = :id AND
1358 acl_type='LIST';
4b9e5c72 1359 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1360 if (rowcount > 0)
1361 printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
1362 else
1363 printf("Not fixed\n");
1364 modified("servers");
208a4f4a 1365}
68bbc9c3 1366
1367
208a4f4a 1368show_krb_usr(id)
1369EXEC SQL BEGIN DECLARE SECTION;
1370int id;
1371EXEC SQL END DECLARE SECTION;
1372{
1373 EXEC SQL BEGIN DECLARE SECTION;
1374 int found = 1, id1;
1375 EXEC SQL END DECLARE SECTION;
68bbc9c3 1376 struct string *s;
1377 char *ss;
1378
208a4f4a 1379 EXEC SQL DECLARE csr218 CURSOR FOR
1380 SELECT string_id FROM krbmap
1381 WHERE users_id = :id ;
1382 EXEC SQL OPEN csr218;
1383 while(1) {
1384 EXEC SQL FETCH csr218 INTO :id1;
4b9e5c72 1385 if (sqlca.sqlcode != 0) break;
208a4f4a 1386
68bbc9c3 1387 if (s = ((struct string *)hash_lookup(strings, id1)))
208a4f4a 1388 ss = s->name;
68bbc9c3 1389 else
208a4f4a 1390 ss = "[unknown]";
68bbc9c3 1391 found = 0;
1392 printf("Kerberos map for non-existant user %d to principal %s\n",
1393 id, s);
208a4f4a 1394 }
1395 EXEC SQL CLOSE csr218;
68bbc9c3 1396 return(found);
208a4f4a 1397}
68bbc9c3 1398
1399
208a4f4a 1400show_krb_str(id)
1401EXEC SQL BEGIN DECLARE SECTION;
1402int id;
1403EXEC SQL END DECLARE SECTION;
1404{
1405 EXEC SQL BEGIN DECLARE SECTION;
1406 int found = 1, id1;
1407 EXEC SQL END DECLARE SECTION;
68bbc9c3 1408 struct user *u;
1409 char *s;
1410
208a4f4a 1411 EXEC SQL DECLARE csr219 CURSOR FOR
1412 SELECT users_id FROM krbmap
1413 WHERE string_id = :id;
1414 EXEC SQL OPEN csr219;
1415 while(1) {
1416 EXEC SQL FETCH csr219 INTO :id1;
4b9e5c72 1417 if (sqlca.sqlcode != 0) break;
208a4f4a 1418
68bbc9c3 1419 if (u = ((struct user *)hash_lookup(users, id1)))
208a4f4a 1420 s = u->login;
68bbc9c3 1421 else
4b9e5c72 1422 s = "[\?\?\?]";
68bbc9c3 1423 found = 0;
1424 printf("Kerberos map for user %s (%d) to non-existant string %d\n",
1425 s, id1, id);
208a4f4a 1426 }
1427 EXEC SQL CLOSE csr219;
68bbc9c3 1428 return(found);
208a4f4a 1429}
68bbc9c3 1430
1431
208a4f4a 1432show_pdm_mach(id)
1433EXEC SQL BEGIN DECLARE SECTION;
1434int id;
1435EXEC SQL END DECLARE SECTION;
1436{
1437 EXEC SQL BEGIN DECLARE SECTION;
1438 char name[33];
1439 EXEC SQL END DECLARE SECTION;
68bbc9c3 1440 int found = 1;
1441
208a4f4a 1442 EXEC SQL DECLARE csr220 CURSOR FOR
1443 SELECT name FROM palladium
1444 WHERE mach_id = :id;
1445 EXEC SQL OPEN csr220;
1446 while(1) {
1447 EXEC SQL FETCH csr220 INTO :name;
4b9e5c72 1448 if (sqlca.sqlcode != 0) break;
208a4f4a 1449
68bbc9c3 1450 strtrim(name);
1451 printf("Palladium server/supervisor %s is on non-existant machine %d\n",
1452 name, id);
1453 found = 0;
208a4f4a 1454 }
1455 EXEC SQL CLOSE csr220;
68bbc9c3 1456 return(found);
208a4f4a 1457}
68bbc9c3 1458
1459
1460phase2()
208a4f4a 1461{
1462 EXEC SQL BEGIN DECLARE SECTION;
1463 int id1, id2, id3, id4, id5;
1464 char type[9], name[33];
1465 EXEC SQL END DECLARE SECTION;
68bbc9c3 1466 struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5;
1467 struct filesys *f;
1468 struct list *l;
1469 struct nfsphys *n;
1470 struct machine *m;
1471
1472 printf("Phase 2 - Checking references\n");
1473
1474 dprintf("Checking users...\n");
ab05f33a 1475 hash_step(users, user_check, NULL);
68bbc9c3 1476
772b7afc 1477 dprintf("Checking machines...\n");
1478 hash_step(machines, mach_check, NULL);
1479
ab05f33a 1480 dprintf("Checking subnets...\n");
1481 hash_step(subnets, subnet_check, NULL);
1482
1483 dprintf("Checking clusters...\n");
1484 hash_step(clusters, cluster_check, NULL);
1485
68bbc9c3 1486 dprintf("Checking mcmap...\n");
1487 sq1 = sq_create();
1488 sq2 = sq_create();
208a4f4a 1489 EXEC SQL DECLARE csr221 CURSOR FOR
ab05f33a 1490 SELECT mach_id, clu_id FROM mcmap;
208a4f4a 1491 EXEC SQL OPEN csr221;
1492 while(1) {
1493 EXEC SQL FETCH csr221 INTO :id1, :id2;
4b9e5c72 1494 if (sqlca.sqlcode != 0) break;
208a4f4a 1495
68bbc9c3 1496 if (!(m = (struct machine *)hash_lookup(machines, id1)))
208a4f4a 1497 sq_save_unique_data(sq1, id1);
ab05f33a 1498 else if (!hash_lookup(clusters, id2))
208a4f4a 1499 sq_save_unique_data(sq2, id2);
68bbc9c3 1500 if (m) m->clucount++;
ab05f33a 1501 }
208a4f4a 1502 EXEC SQL CLOSE csr221;
68bbc9c3 1503 generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
1504 generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
1505
1506 dprintf("Checking service clusters...\n");
1507 sq1 = sq_create();
208a4f4a 1508 EXEC SQL DECLARE csr222 CURSOR FOR
ab05f33a 1509 SELECT clu_id FROM svc;
208a4f4a 1510 EXEC SQL OPEN csr222;
1511 while(1) {
1512 EXEC SQL FETCH csr222 INTO :id1;
4b9e5c72 1513 if (sqlca.sqlcode != 0) break;
208a4f4a 1514
68bbc9c3 1515 if (!hash_lookup(clusters, id1))
1516 sq_save_unique_data(sq1, id1);
208a4f4a 1517 }
1518 EXEC SQL CLOSE csr222;
68bbc9c3 1519 generic_delete(sq1, show_svc, "svc", "clu_id", 1);
1520
1521 dprintf("Checking lists...\n");
1522 hash_step(lists, list_check, NULL);
1523
1524 dprintf("Checking members...\n");
1525 sq1 = sq_create();
1526 sq2 = sq_create();
1527 sq3 = sq_create();
1528 sq4 = sq_create();
1529 sq5 = sq_create();
64842aba 1530
208a4f4a 1531 EXEC SQL DECLARE csr223 CURSOR FOR
ab05f33a 1532 SELECT list_id, member_type, member_id, ref_count, direct
4b9e5c72 1533 FROM imembers FOR UPDATE OF member_id;
208a4f4a 1534 EXEC SQL OPEN csr223;
1535 while(1) {
1536 EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4;
4b9e5c72 1537 if (sqlca.sqlcode != 0) break;
208a4f4a 1538
68bbc9c3 1539 if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
1540 sq_save_unique_data(sq1, id1);
1541 else if (type[0] == 'U' && !hash_lookup(users, id2))
1542 sq_save_unique_data(sq2, id2);
1543 else if (type[0] == 'L' && !hash_lookup(lists, id2))
1544 sq_save_unique_data(sq3, id2);
ab05f33a 1545 else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
68bbc9c3 1546 sq_save_unique_data(sq4, id2);
ab05f33a 1547 else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers","member_id","csr223",id2))
68bbc9c3 1548 sq_save_unique_data(sq5, id2);
1549 else
1550 l->members++;
208a4f4a 1551 }
1552 EXEC SQL CLOSE csr223;
68bbc9c3 1553 generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
1554 generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
1555 generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
1556 generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
1557 generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
1558
1559 dprintf("Checking servers...\n");
1560 sq1 = sq_create();
1561 sq2 = sq_create();
208a4f4a 1562 EXEC SQL DECLARE csr224 CURSOR FOR
ab05f33a 1563 SELECT name, acl_type, acl_id, modby FROM servers
4b9e5c72 1564 FOR UPDATE of modby;
208a4f4a 1565 EXEC SQL OPEN csr224;
1566 while(1) {
ab05f33a 1567 EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2;
4b9e5c72 1568 if (sqlca.sqlcode != 0) break;
208a4f4a 1569
ab05f33a 1570 maybe_fixup_modby2("servers","modby","csr224",id2);
68bbc9c3 1571 strtrim(type);
1572 if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
1573 sq_save_data(sq1, id1);
1574 } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
1575 sq_save_data(sq2, id1);
1576 }
208a4f4a 1577 }
1578 EXEC SQL CLOSE csr224;
68bbc9c3 1579 generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
1580 generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
1581
7bf0a6f3 1582 dprintf("Checking serverhosts...\n");
68bbc9c3 1583 sq = sq_create();
208a4f4a 1584 EXEC SQL DECLARE csr225 CURSOR FOR
ab05f33a 1585 SELECT mach_id, modby FROM serverhosts
4b9e5c72 1586 FOR UPDATE OF modby;
208a4f4a 1587 EXEC SQL OPEN csr225;
1588 while(1) {
ab05f33a 1589 EXEC SQL FETCH csr225 INTO :id1, :id2;
4b9e5c72 1590 if (sqlca.sqlcode != 0) break;
208a4f4a 1591
ab05f33a 1592 maybe_fixup_modby2("serverhosts", "modby", "csr225", id2);
68bbc9c3 1593 if (!hash_lookup(machines, id1))
1594 sq_save_data(sq, id1);
208a4f4a 1595 }
1596 EXEC SQL CLOSE csr225;
68bbc9c3 1597 generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
1598
1599 dprintf("Checking nfsphys...\n");
1600 hash_step(nfsphys, check_nfsphys, NULL);
1601
1602 dprintf("Checking filesys...\n");
1603 hash_step(filesys, check_fs, NULL);
1604
1605 dprintf("Checking filesystem groups...\n");
1606 sq1 = sq_create();
1607 sq2 = sq_create();
1608 sq3 = sq_create();
208a4f4a 1609 EXEC SQL DECLARE csr226 CURSOR FOR
ab05f33a 1610 SELECT group_id, filsys_id FROM fsgroup;
208a4f4a 1611 EXEC SQL OPEN csr226;
1612 while(1) {
1613 EXEC SQL FETCH csr226 INTO :id1, :id2;
4b9e5c72 1614 if (sqlca.sqlcode != 0) break;
208a4f4a 1615
68bbc9c3 1616 if (!(f = (struct filesys *) hash_lookup(filesys, id1)))
1617 sq_save_data(sq1, id1);
1618 if (!hash_lookup(filesys, id2))
1619 sq_save_data(sq3, id2);
208a4f4a 1620 }
1621 EXEC SQL CLOSE csr226;
68bbc9c3 1622 generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
1623 generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
1624
1625 dprintf("Checking quotas...\n");
1626 sq1 = sq_create();
1627 sq2 = sq_create();
1628 sq3 = sq_create();
1629 sq4 = sq_create();
208a4f4a 1630 EXEC SQL DECLARE csr227 CURSOR FOR
ab05f33a 1631 SELECT entity_id, type, filsys_id, phys_id, quota, modby
4b9e5c72 1632 FROM quota FOR UPDATE OF modby;
208a4f4a 1633 EXEC SQL OPEN csr227;
1634 while(1) {
ab05f33a 1635 EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5;
4b9e5c72 1636 if (sqlca.sqlcode != 0) break;
208a4f4a 1637
ab05f33a 1638 maybe_fixup_modby2("quota", "modby", "csr227", id5);
68bbc9c3 1639 if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1))
1640 sq_save_data(sq1, id1);
1641 else if (type[0] == 'G' && !hash_lookup(lists, id1))
1642 sq_save_data(sq4, id1);
1643 else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
1644 sq_save_data(sq2, id2);
1645 else if (id3 != f->phys_id ||
1646 ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) ==
1647 (struct nfsphys *)NULL))
1648 sq_save_data(sq3, id2);
1649 else
1650 n->count += id4;
208a4f4a 1651 }
1652 EXEC SQL CLOSE csr227;
68bbc9c3 1653 generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
1654 generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
1655 generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
1656 generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
1657
1658 dprintf("Not checking zephyr.\n");
1659
1660 dprintf("Checking hostaccess...\n");
208a4f4a 1661 EXEC SQL DECLARE csr228 CURSOR FOR
ab05f33a 1662 SELECT mach_id, acl_type, acl_id, modby FROM hostaccess
4b9e5c72 1663 FOR UPDATE OF modby;
208a4f4a 1664 EXEC SQL OPEN csr228;
1665 while(1) {
ab05f33a 1666 EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3;
4b9e5c72 1667 if (sqlca.sqlcode != 0) break;
208a4f4a 1668
ab05f33a 1669 maybe_fixup_modby2("hostaccess", "modby", "csr228", id3);
68bbc9c3 1670 strtrim(type);
1671 if (!hash_lookup(machines, id1)) {
1672 printf("Hostaccess for non-existant host %d\n", id1);
1673 printf("Not fixing this error\n");
1674 }
1675 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");
1678 } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) {
1679 printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
1680 printf("Not fixing this error\n");
1681 }
208a4f4a 1682 }
1683 EXEC SQL CLOSE csr228;
68bbc9c3 1684
1685 dprintf("Checking palladium...\n");
1686 sq1 = sq_create();
208a4f4a 1687 EXEC SQL DECLARE csr229 CURSOR FOR
ab05f33a 1688 SELECT mach_id, modby FROM palladium
4b9e5c72 1689 FOR UPDATE OF modby;
208a4f4a 1690 EXEC SQL OPEN csr229;
1691 while(1) {
ab05f33a 1692 EXEC SQL FETCH csr229 INTO :id1, :id2;
4b9e5c72 1693 if (sqlca.sqlcode != 0) break;
208a4f4a 1694
ab05f33a 1695 maybe_fixup_modby2("palladium", "modby", "csr229", id2);
68bbc9c3 1696 if (!hash_lookup(machines, id1)) {
1697 sq_save_unique_data(sq1, id1);
1698 }
208a4f4a 1699 }
1700 EXEC SQL CLOSE csr229;
68bbc9c3 1701 generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1);
1702
1703 dprintf("Checking krbmap...\n");
1704 sq1 = sq_create();
1705 sq2 = sq_create();
208a4f4a 1706 EXEC SQL DECLARE csr230 CURSOR FOR
ab05f33a 1707 SELECT users_id, string_id FROM krbmap
4b9e5c72 1708 FOR UPDATE OF string_id;
208a4f4a 1709 EXEC SQL OPEN csr230;
1710 while(1) {
1711 EXEC SQL FETCH csr230 INTO :id1, :id2;
4b9e5c72 1712 if (sqlca.sqlcode != 0) break;
208a4f4a 1713
68bbc9c3 1714 if (!hash_lookup(users, id1))
1715 sq_save_unique_data(sq1, id1);
ab05f33a 1716 else if (!maybe_fixup_unref_string2("krbmap","string_id","csr230",id2))
68bbc9c3 1717 sq_save_unique_data(sq2, id2);
208a4f4a 1718 }
1719 EXEC SQL CLOSE csr230;
68bbc9c3 1720 generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
1721 generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
1722
1723 dprintf("Checking capacls...\n");
208a4f4a 1724 EXEC SQL DECLARE csr231 CURSOR FOR
ab05f33a 1725 SELECT list_id, tag FROM capacls;
208a4f4a 1726 EXEC SQL OPEN csr231;
1727 while(1) {
1728 EXEC SQL FETCH csr231 INTO :id1, :name;
4b9e5c72 1729 if (sqlca.sqlcode != 0) break;
208a4f4a 1730
68bbc9c3 1731 if (!hash_lookup(lists, id1)) {
1732 printf("Capacl for %s is non-existant list %d\n", name, id1);
1733 printf("Not fixing this error\n");
1734 }
208a4f4a 1735 }
ab05f33a 1736 EXEC SQL CLOSE csr231;
68bbc9c3 1737
ab05f33a 1738 dprintf("Checking hostaliases\n");
1739 sq1 = sq_create();
1740 EXEC SQL DECLARE csr232 CURSOR FOR
1741 SELECT mach_id FROM hostalias;
ab05f33a 1742 EXEC SQL OPEN csr232;
1743 while(1) {
1744 EXEC SQL FETCH csr232 INTO :id1;
4b9e5c72 1745 if (sqlca.sqlcode != 0) break;
68bbc9c3 1746
ab05f33a 1747 if (!hash_lookup(machines, id1))
1748 sq_save_unique_data(sq1, id1);
1749 }
1750 EXEC SQL CLOSE csr232;
1751 generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
1752
1753 dprintf("Checking printcaps\n");
1754 sq1 = sq_create();
1755 sq2 = sq_create();
1756 EXEC SQL DECLARE csr233 CURSOR FOR
1757 SELECT mach_id, quotaserver, modby FROM printcap;
ab05f33a 1758 EXEC SQL OPEN csr233;
1759 while(1) {
1760 EXEC SQL FETCH csr233 INTO :id1, :id2, :id3;
4b9e5c72 1761 if (sqlca.sqlcode != 0) break;
ab05f33a 1762
1763 maybe_fixup_modby2("printcap", "modby", "csr233", id3);
1764 if (!hash_lookup(machines, id1))
1765 sq_save_unique_data(sq1, id1);
1766 else if(!hash_lookup(machines, id2))
1767 sq_save_unique_data(sq2, id2);
1768 }
1769 EXEC SQL CLOSE csr233;
1770 generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1);
1771 generic_delete(sq2, show_pcap_quota, "printcap", "quotaserver", 1);
1772}
This page took 0.350962 seconds and 5 git commands to generate.