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