]> andersk Git - moira.git/blame - dbck/phase2.pc
Command line printer manipulation client, and build goo.
[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);
cb884d06 24int show_mcntmap_mach(void *id);
25int show_mcntmap_cnt(void *id);
7ac48069 26int show_hostalias(void *id);
dabf20aa 27int show_printer_mach(void *id);
fe0a844a 28int show_printer_server(void *id);
dabf20aa 29int show_printer_loghost(void *id);
30int show_printer_spool(void *id);
31int show_printer_quota(void *id);
32int show_printer_ac(void *id);
33int show_printer_lpc_acl(void *id);
c96b70a5 34void fix_printer_ac(void *id);
35void fix_printer_lpc_acl(void *id);
7ac48069 36void user_check(int id, void *user, void *hint);
8949c781 37void clear_user_sponsor(struct user *u);
7ac48069 38int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
39 char *field, char *idfield);
40int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
41 char *field, char *idfield);
c978c079 42int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid);
43int maybe_fixup_modby2(char *table, char *field, char *rowid, int id);
7ac48069 44void pobox_check(int id, struct user *u);
45void remove_pobox(int id);
46void fix_smtp_pobox(int id, int sid);
47void mach_check(int id, void *machine, void *hint);
48void subnet_check(int id, void *subnet, void *hint);
49void clear_subnet_owner(struct subnet *s);
50void clear_mach_owner(struct machine *m);
51void cluster_check(int id, void *cluster, void *hint);
52int show_svc(void *id);
53void list_check(int id, void *list, void *hint);
54void fix_list_acl(int id);
ad47bcbe 55void fix_list_memacl(int id);
7ac48069 56int show_member_list(void *id);
57int show_mem_user(void *id);
58int show_mem_list(void *id);
59int show_mem_str(void *id);
60int show_mem_krb(void *id);
5f7b0741 61int show_mem_mach(void *id);
7ac48069 62void del_mem_user(void *id);
63void del_mem_list(void *id);
64void del_mem_str(void *id);
65void del_mem_krb(void *id);
5f7b0741 66void del_mem_mach(void *id);
7ac48069 67int show_sh(void *id);
68void del_sh_mach(void *id);
69void fsmatch(int id, void *nfsphys, void *filesys);
70void check_fs(int id, void *filesys, void *hint);
71void check_nfsphys(int id, void *nfsphys, void *hint);
fe0a844a 72void check_ps(int id, void *printserver, void *hint);
cb884d06 73void check_container(int id, void *container, void *hint);
74void fix_container_acl(int id);
75void fix_container_memacl(int id);
7ac48069 76int show_fsg_missing(void *id);
77int show_fsg_type(void *filesys);
78void fix_fsg_type(void *filesys);
79int show_fsg_nomember(void *id);
80int show_quota_nouser(void *id);
81int show_quota_nolist(void *id);
82void fix_quota_nouser(void *id);
83void fix_quota_nolist(void *id);
84int show_quota_nofs(void *id);
85void fix_quota_nofs(void *id);
86int show_quota_wrongpid(void *id);
87void fix_quota_physid(void *id);
88int show_srv_user(void *id);
89int show_srv_list(void *id);
90void zero_srv_user(void *id);
91void zero_srv_list(void *id);
92int show_krb_usr(void *id);
93int show_krb_str(void *id);
94int show_pdm_mach(void *id);
95
96int show_mcm_mach(void *id)
208a4f4a 97{
5eaef520 98 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 99 int iid = (int)id, found = 1;
cfc4f91e 100 char name[CLUSTERS_NAME_SIZE];
5eaef520 101 EXEC SQL END DECLARE SECTION;
102
103 EXEC SQL DECLARE csr201 CURSOR FOR
104 SELECT clusters.name FROM clusters, mcmap
105 WHERE clusters.clu_id = mcmap.clu_id AND mcmap.mach_id = :iid;
106 EXEC SQL OPEN csr201;
107 while (1)
108 {
109 EXEC SQL FETCH csr201 INTO :name;
110 if (sqlca.sqlcode)
111 break;
112
113 strtrim(name);
114 found = 0;
7ac48069 115 printf("Cluster %s, non-existant machine %d in cluster map\n",
116 name, iid);
208a4f4a 117 }
5eaef520 118 EXEC SQL CLOSE csr201;
119 return found;
208a4f4a 120}
68bbc9c3 121
7ac48069 122int show_mcm_clu(void *id)
208a4f4a 123{
5eaef520 124 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 125 int iid = (int)id, found = 1;
cfc4f91e 126 char name[MACHINE_NAME_SIZE];
5eaef520 127 EXEC SQL END DECLARE SECTION;
128
129 EXEC SQL DECLARE csr202 CURSOR FOR
130 SELECT machine.name FROM machine, mcmap
131 WHERE machine.mach_id = mcmap.mach_id AND mcmap.clu_id = :iid;
132 EXEC SQL OPEN csr202;
133 while (1)
134 {
135 EXEC SQL FETCH csr202 INTO :name;
136 if (sqlca.sqlcode)
137 break;
138
139 strtrim(name);
140
141 found = 0;
7ac48069 142 printf("Machine %s, non-existant cluster %d in cluster map\n",
143 name, iid);
208a4f4a 144 }
5eaef520 145 EXEC SQL CLOSE csr202;
146 return found;
208a4f4a 147}
68bbc9c3 148
cb884d06 149int show_mcntmap_mach(void *id)
150{
151 EXEC SQL BEGIN DECLARE SECTION;
152 int iid = (int)id, found = 1;
153 char name[CONTAINERS_NAME_SIZE];
154 EXEC SQL END DECLARE SECTION;
155
156 EXEC SQL DECLARE csr_show_mcnt_mach CURSOR FOR
157 SELECT cnt.name FROM container cnt, mcntmap mc
158 WHERE cnt.cnt_id = mc.cnt_id AND mc.mach_id = :iid;
159 EXEC SQL OPEN csr_show_mcnt_mach;
160 while (1)
161 {
162 EXEC SQL FETCH csr_show_mcnt_mach INTO :name;
163 if (sqlca.sqlcode)
164 break;
165
166 strtrim(name);
167 found = 0;
168 printf("Container %s, non-existant machine %d in container map\n",
169 name, iid);
170 }
171 EXEC SQL CLOSE csr_show_mcnt_mach;
172 return found;
173}
174
175int show_mcntmap_cnt(void *id)
176{
177 EXEC SQL BEGIN DECLARE SECTION;
178 int iid = (int)id, found = 1;
179 char name[MACHINE_NAME_SIZE];
180 EXEC SQL END DECLARE SECTION;
181
182 EXEC SQL DECLARE csr_show_mcnt_cnt CURSOR FOR
183 SELECT m.name FROM machine m, mcntmap mc
184 WHERE m.mach_id = mc.mach_id AND mc.cnt_id = :iid;
185 EXEC SQL OPEN csr_show_mcnt_cnt;
186 while (1)
187 {
188 EXEC SQL FETCH csr_show_mcnt_cnt INTO :name;
189 if (sqlca.sqlcode)
190 break;
191
192 strtrim(name);
193
194 found = 0;
195 printf("Machine %s, non-existant container %d in container map\n",
196 name, iid);
197 }
198 EXEC SQL CLOSE csr_show_mcnt_cnt;
199 return found;
200}
201
7ac48069 202int show_hostalias(void *id)
ab05f33a 203{
5eaef520 204 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 205 int iid = (int)id, found = 1;
cfc4f91e 206 char name[HOSTALIAS_NAME_SIZE];
5eaef520 207 EXEC SQL END DECLARE SECTION;
208
209 EXEC SQL DECLARE csr234 CURSOR FOR
210 SELECT name FROM hostalias WHERE mach_id = :iid;
211 EXEC SQL OPEN csr234;
212 while (1)
213 {
214 EXEC SQL FETCH csr234 INTO :name;
215 if (sqlca.sqlcode)
216 break;
217
218 strtrim(name);
219
220 found = 0;
7ac48069 221 printf("Alias %s, non-existant machine %d in hostalias map\n",
222 name, iid);
ab05f33a 223 }
5eaef520 224 EXEC SQL CLOSE csr234;
225 return found;
ab05f33a 226}
227
dabf20aa 228int show_printer_mach(void *id)
ab05f33a 229{
5eaef520 230 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 231 int iid = (int)id, found = 1;
dabf20aa 232 char name[PRINTERS_NAME_SIZE];
5eaef520 233 EXEC SQL END DECLARE SECTION;
234
235 EXEC SQL DECLARE csr235 CURSOR FOR
dabf20aa 236 SELECT name FROM printers WHERE mach_id = :iid;
5eaef520 237 EXEC SQL OPEN csr235;
238 while (1)
239 {
240 EXEC SQL FETCH csr235 INTO :name;
241 if (sqlca.sqlcode)
242 break;
243
244 strtrim(name);
245
246 found = 0;
dabf20aa 247 printf("Printer %s, non-existant machine %d in printers table\n",
7ac48069 248 name, iid);
ab05f33a 249 }
5eaef520 250 EXEC SQL CLOSE csr235;
251 return found;
ab05f33a 252}
253
fe0a844a 254int show_printer_server(void *id)
255{
256 EXEC SQL BEGIN DECLARE SECTION;
257 int iid = (int)id, found = 1;
258 char name[PRINTERS_NAME_SIZE];
259 EXEC SQL END DECLARE SECTION;
260
261 EXEC SQL DECLARE csr_sps CURSOR FOR
262 SELECT name FROM printers WHERE mach_id = :iid;
263 EXEC SQL OPEN csr_sps;
264 while (1)
265 {
266 EXEC SQL FETCH csr_sps INTO :name;
267 if (sqlca.sqlcode)
268 break;
269
270 strtrim(name);
271
272 found = 0;
273 printf("Printer %s, non-existant printserver %d in printers table\n",
274 name, iid);
275 }
276 EXEC SQL CLOSE csr_sps;
277 return found;
278}
279
dabf20aa 280int show_printer_loghost(void *id)
ab05f33a 281{
5eaef520 282 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 283 int iid = (int)id, found = 1;
dabf20aa 284 char name[PRINTERS_NAME_SIZE];
285 EXEC SQL END DECLARE SECTION;
286
c96b70a5 287 EXEC SQL DECLARE csr236 CURSOR FOR
dabf20aa 288 SELECT name FROM printers WHERE loghost = :iid;
c96b70a5 289 EXEC SQL OPEN csr236;
dabf20aa 290 while (1)
291 {
c96b70a5 292 EXEC SQL FETCH csr236 INTO :name;
dabf20aa 293 if (sqlca.sqlcode)
294 break;
295
296 strtrim(name);
297
298 found = 0;
299 printf("Printer %s, non-existant spool machine %d in printers table\n",
300 name, iid);
301 }
c96b70a5 302 EXEC SQL CLOSE csr236;
dabf20aa 303 return found;
304}
305
306int show_printer_spool(void *id)
307{
308 EXEC SQL BEGIN DECLARE SECTION;
309 int iid = (int)id, found = 1;
310 char name[PRINTERS_NAME_SIZE];
311 EXEC SQL END DECLARE SECTION;
312
c96b70a5 313 EXEC SQL DECLARE csr237 CURSOR FOR
dabf20aa 314 SELECT name FROM printers WHERE rm = :iid;
c96b70a5 315 EXEC SQL OPEN csr237;
dabf20aa 316 while (1)
317 {
c96b70a5 318 EXEC SQL FETCH csr237 INTO :name;
dabf20aa 319 if (sqlca.sqlcode)
320 break;
321
322 strtrim(name);
323
324 found = 0;
325 printf("Printer %s, non-existant spool machine %d in printers table\n",
326 name, iid);
327 }
c96b70a5 328 EXEC SQL CLOSE csr237;
dabf20aa 329 return found;
330}
331
332int show_printer_quota(void *id)
333{
334 EXEC SQL BEGIN DECLARE SECTION;
335 int iid = (int)id, found = 1;
336 char name[PRINTERS_NAME_SIZE];
337 EXEC SQL END DECLARE SECTION;
338
c96b70a5 339 EXEC SQL DECLARE csr238 CURSOR FOR
dabf20aa 340 SELECT name FROM printers WHERE rq = :iid;
c96b70a5 341 EXEC SQL OPEN csr238;
dabf20aa 342 while (1)
343 {
c96b70a5 344 EXEC SQL FETCH csr238 INTO :name;
dabf20aa 345 if (sqlca.sqlcode)
346 break;
347
348 strtrim(name);
349
350 found = 0;
351 printf("Printer %s, non-existant quota server %d in printers table\n",
352 name, iid);
353 }
c96b70a5 354 EXEC SQL CLOSE csr238;
dabf20aa 355 return found;
356}
357
358int show_printer_ac(void *id)
359{
360 EXEC SQL BEGIN DECLARE SECTION;
361 int iid = (int)id, found = 1;
362 char name[PRINTERS_NAME_SIZE];
5eaef520 363 EXEC SQL END DECLARE SECTION;
364
c96b70a5 365 EXEC SQL DECLARE csr239 CURSOR FOR
dabf20aa 366 SELECT name FROM printers WHERE ac = :iid;
c96b70a5 367 EXEC SQL OPEN csr239;
5eaef520 368 while (1)
369 {
c96b70a5 370 EXEC SQL FETCH csr239 INTO :name;
5eaef520 371 if (sqlca.sqlcode)
372 break;
373
374 strtrim(name);
375
376 found = 0;
dabf20aa 377 printf("Printer %s, non-existant restrict list %d in printers table\n",
7ac48069 378 name, iid);
ab05f33a 379 }
c96b70a5 380 EXEC SQL CLOSE csr239;
5eaef520 381 return found;
ab05f33a 382}
383
dabf20aa 384int show_printer_lpc_acl(void *id)
385{
386 EXEC SQL BEGIN DECLARE SECTION;
387 int iid = (int)id, found = 1;
388 char name[PRINTERS_NAME_SIZE];
389 EXEC SQL END DECLARE SECTION;
390
c96b70a5 391 EXEC SQL DECLARE csr240 CURSOR FOR
dabf20aa 392 SELECT name FROM printers WHERE lpc_acl = :iid;
c96b70a5 393 EXEC SQL OPEN csr240;
dabf20aa 394 while (1)
395 {
c96b70a5 396 EXEC SQL FETCH csr240 INTO :name;
dabf20aa 397 if (sqlca.sqlcode)
398 break;
399
400 strtrim(name);
401
402 found = 0;
403 printf("Printer %s, non-existant lpc ACL %d in printers table\n",
404 name, iid);
405 }
c96b70a5 406 EXEC SQL CLOSE csr240;
dabf20aa 407 return found;
408}
409
c96b70a5 410void fix_printer_ac(void *id)
dabf20aa 411{
412 EXEC SQL BEGIN DECLARE SECTION;
413 int rowcount, iid = (int)id;
414 EXEC SQL END DECLARE SECTION;
415
416 EXEC SQL UPDATE printers SET ac = 0 WHERE ac = :iid;
417 rowcount = sqlca.sqlerrd[2];
418 if (rowcount > 0)
419 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
420 else
421 printf("Not fixed\n");
422 modified("printers");
423}
424
c96b70a5 425void fix_printer_lpc_acl(void *id)
dabf20aa 426{
427 EXEC SQL BEGIN DECLARE SECTION;
428 int rowcount, iid = (int)id;
429 EXEC SQL END DECLARE SECTION;
430
431 EXEC SQL UPDATE printers SET lpc_acl = 0 WHERE lpc_acl = :iid;
432 rowcount = sqlca.sqlerrd[2];
433 if (rowcount > 0)
434 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
435 else
436 printf("Not fixed\n");
437 modified("printers");
438}
439
7ac48069 440void user_check(int id, void *user, void *hint)
ab05f33a 441{
7ac48069 442 struct user *u = user;
443
5eaef520 444 u->comment = maybe_fixup_unref_string(u->comment, id, u->login, "users",
445 "comments", "users_id");
446
447 u->modby = maybe_fixup_modby(u->modby, id, u->login, "users",
448 "modby", "users_id");
ab05f33a 449
5eaef520 450 u->fmodby = maybe_fixup_modby(u->fmodby, id, u->login, "users",
451 "fmodby", "users_id");
ab05f33a 452
5eaef520 453 u->pmodby = maybe_fixup_modby(u->pmodby, id, u->login, "users",
454 "pmodby", "users_id");
ab05f33a 455
5eaef520 456 u->sigwho = maybe_fixup_unref_string(u->sigwho, id, u->login, "users",
457 "sigwho", "users_id");
ab05f33a 458
8949c781 459 switch (u->sponsor_type)
460 {
461 case 'U':
462 if (!hash_lookup(users, u->sponsor_id))
463 {
464 printf("User %s has non-existant USER sponsor %d\n",
465 u->login, u->sponsor_id);
466 if (single_fix("Set to no sponsor", 1))
467 clear_user_sponsor(u);
468 }
469 break;
470 case 'L':
471 if (!hash_lookup(lists, u->sponsor_id))
472 {
473 printf("User %s has non-existant LIST sponsor %d\n",
474 u->login, u->sponsor_id);
475 if (single_fix("Set to no sponsor", 1))
476 clear_user_sponsor(u);
477 }
478 break;
479 case 'S':
480 case 'K':
481 if (u->sponsor_id)
482 u->sponsor_id = maybe_fixup_unref_string(u->sponsor_id, id, u->login,
483 "users", "sponsor_id",
484 "users_id");
485 if (u->sponsor_id == 0)
486 clear_user_sponsor(u);
487 }
488
7ac48069 489 pobox_check(id, u);
ab05f33a 490}
491
5eaef520 492int maybe_fixup_unref_string(int sid, int oid, char *oname, char *table,
493 char *field, char *idfield)
ab05f33a 494{
5eaef520 495 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
ab05f33a 496 EXEC SQL BEGIN DECLARE SECTION;
497 int rowcount;
498 char stmt_buf[500];
499 EXEC SQL END DECLARE SECTION;
5eaef520 500
7ac48069 501 if ((newid = (int)hash_lookup(string_dups, ret)))
5eaef520 502 {
503 printf("%s entry %s(%d) has a %s with duplicate string %d\n",
504 table, oname, oid, field, ret);
505 if (single_fix("Replace duplicate", 0))
506 {
507 ret = newid;
5eaef520 508 doit = 1;
509 }
fd3a1fc5 510 string_check(ret);
ab05f33a 511 }
5eaef520 512 else if (!string_check(ret))
513 {
514 printf("%s entry %s(%d) has a %s with non-existant string %d\n",
515 table, oname, oid, field, ret);
516 if (single_fix("Delete", 1))
517 {
518 ret = 0;
519 doit = 1;
520 }
521 }
522
523 if (doit)
524 {
525 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE %s = %d",
526 table, field, (sid < 0) ? -ret : ret, idfield, oid);
527 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
528 rowcount = sqlca.sqlerrd[2];
529 if (rowcount == 1)
530 printf("Fixed\n");
531 else
532 printf("Not fixed, rowcount = %d\n", rowcount);
533 modified(table);
ab05f33a 534 }
ab05f33a 535
5eaef520 536 return (sid < 0) ? -ret : ret;
ab05f33a 537}
538
5eaef520 539int maybe_fixup_modby(int sid, int oid, char *oname, char *table,
540 char *field, char *idfield)
ab05f33a 541{
542 EXEC SQL BEGIN DECLARE SECTION;
543 char stmt_buf[500];
544 int rowcount;
545 EXEC SQL END DECLARE SECTION;
546
5eaef520 547 if (sid < 0)
ab05f33a 548 return maybe_fixup_unref_string(sid, oid, oname, table, field, idfield);
5eaef520 549 else
550 {
551 if (!hash_lookup(users, sid))
552 {
553 printf("%s entry %s(%d) has a %s with non-existant user %d\n",
554 table, oname, oid, field, sid);
555 if (single_fix("Delete", 1))
556 {
557 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE %s = %d",
558 table, field, idfield, oid);
559 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
560 rowcount = sqlca.sqlerrd[2];
561 if (rowcount == 1)
562 printf("Fixed\n");
563 else
564 printf("Not fixed, rowcount = %d\n", rowcount);
565 modified(table);
566 }
567 return 0;
568 }
ab05f33a 569 }
ab05f33a 570 return sid;
571}
572
c978c079 573int maybe_fixup_unref_string2(char *table, char *field, char *rowid, int sid)
ab05f33a 574{
5eaef520 575 int ret = (sid < 0) ? -sid : sid, doit = 0, newid;
ab05f33a 576 EXEC SQL BEGIN DECLARE SECTION;
577 int rowcount;
578 char stmt_buf[500];
579 EXEC SQL END DECLARE SECTION;
5eaef520 580
7ac48069 581 if ((newid = (int)hash_lookup(string_dups, ret)))
5eaef520 582 {
583 printf("%s entry has a %s with duplicate string %d\n",
584 table, field, ret);
585 if (single_fix("Replace duplicate", 0))
586 {
587 ret = newid;
5eaef520 588 doit = 1;
589 }
fd3a1fc5 590 string_check(ret);
5eaef520 591 }
592 else if (!string_check(ret))
593 {
594 printf("%s entry has a %s with non-existant string %d\n",
595 table, field, ret);
11975951 596 if (single_fix("Clear", 1))
5eaef520 597 {
598 ret = 0;
599 doit = 1;
600 }
ab05f33a 601 }
5eaef520 602
603 if (doit)
604 {
c978c079 605 sprintf(stmt_buf, "UPDATE %s SET %s = %d WHERE rowid = '%s'",
606 table, field, (sid < 0) ? -ret : ret, rowid);
5eaef520 607 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
608 rowcount = sqlca.sqlerrd[2];
609 if (rowcount == 1)
610 printf("Fixed\n");
611 else
612 printf("Not fixed, rowcount = %d\n", rowcount);
613 modified(table);
ab05f33a 614 }
5eaef520 615 return (sid < 0) ? -ret : ret;
ab05f33a 616}
617
c978c079 618int maybe_fixup_modby2(char *table, char *field, char *rowid, int id)
ab05f33a 619{
620 EXEC SQL BEGIN DECLARE SECTION;
621 char stmt_buf[500];
622 int rowcount;
623 EXEC SQL END DECLARE SECTION;
624
5eaef520 625 if (id < 0)
c978c079 626 return maybe_fixup_unref_string2(table, field, rowid, id);
5eaef520 627 else
628 {
629 if (!hash_lookup(users, id))
630 {
631 printf("%s entry has a %s with non-existant user %d\n",
632 table, field, id);
11975951 633 if (single_fix("Clear", 1))
5eaef520 634 {
c978c079 635 sprintf(stmt_buf, "UPDATE %s SET %s = 0 WHERE rowid = '%s'",
636 table, field, rowid);
5eaef520 637 EXEC SQL EXECUTE IMMEDIATE :stmt_buf;
638 rowcount = sqlca.sqlerrd[2];
639 if (rowcount == 1)
640 printf("Fixed\n");
641 else
642 printf("Not fixed, rowcount = %d\n", rowcount);
643 modified(table);
644 }
645 return 0;
646 }
ab05f33a 647 }
ab05f33a 648 return 1;
649}
650
7ac48069 651void pobox_check(int id, struct user *u)
68bbc9c3 652{
fc6165db 653 struct filesys *fs;
654
5eaef520 655 switch (u->potype)
656 {
657 case 'P':
658 if (!hash_lookup(machines, u->pobox_id))
659 {
660 printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
661 u->login, u->fullname, u->pobox_id);
662 if (single_fix("Delete", 0))
663 {
664 remove_pobox(u->users_id);
665 u->potype = 'N';
666 }
667 }
668 break;
fc6165db 669
22bbb6f0 670 case 'E':
671 if (!hash_lookup(machines, u->pobox_id))
672 {
673 printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
674 u->login, u->fullname, u->pobox_id);
675 if (single_fix("Delete", 0))
676 {
677 remove_pobox(u->users_id);
678 u->potype = 'N';
679 }
680 }
681 break;
682
5eaef520 683 case 'S':
7ac48069 684 if (hash_lookup(string_dups, u->pobox_id))
5eaef520 685 {
686 printf("User %s(%s) has P.O.Box with duplicate string %d\n",
687 u->login, u->fullname, u->pobox_id);
688 if (single_fix("Update", 0))
689 {
690 printf("Replacing box_id dup string ID %d with %d\n",
691 u->pobox_id,
7ac48069 692 (int)hash_lookup(string_dups, u->pobox_id));
693 u->pobox_id = (int)hash_lookup(string_dups, u->pobox_id);
5eaef520 694 fix_smtp_pobox(u->users_id, u->pobox_id);
695 string_check(u->pobox_id);
696 }
697 }
698 else if (!string_check(u->pobox_id))
699 {
700 printf("User %s(%s) has P.O.Box with non-existant string %d\n",
701 u->login, u->fullname, u->pobox_id);
702 if (single_fix("Delete", 0))
703 {
704 remove_pobox(u->users_id);
705 u->potype = 'N';
706 }
707 }
708 break;
fc6165db 709
710 case 'I':
711 fs = hash_lookup(filesys, u->pobox_id);
712 if (!fs)
713 {
714 printf("User %s(%s) has P.O.Box on non-existant filesystem %d\n",
715 u->login, u->fullname, u->pobox_id);
716 if (single_fix("Delete", 0))
717 {
718 remove_pobox(u->users_id);
719 u->potype = 'N';
720 }
721 }
722 else if (fs->type != 'I')
723 {
724 printf("User %s(%s) has IMAP P.O.Box on non-IMAP filesystem %s\n",
725 u->login, u->fullname, fs->name);
726 if (single_fix("Delete", 0))
727 {
728 remove_pobox(u->users_id);
729 u->potype = 'N';
730 }
731 }
732 break;
733
5eaef520 734 default:
735 ;
68bbc9c3 736 }
737}
738
739
7ac48069 740void remove_pobox(int id)
208a4f4a 741{
5eaef520 742 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 743 int rowcount, iid = (int)id;
5eaef520 744 EXEC SQL END DECLARE SECTION;
745
746 EXEC SQL UPDATE users SET potype = 'NONE' WHERE users.users_id = :iid;
747 rowcount = sqlca.sqlerrd[2];
748 if (rowcount > 0)
749 printf("%d entr%s removed\n", rowcount, rowcount == 1 ? "y" : "ies");
750 else
751 printf("Not removed\n");
752 modified("users");
208a4f4a 753}
68bbc9c3 754
7ac48069 755void fix_smtp_pobox(int id, int sid)
ab05f33a 756{
5eaef520 757 EXEC SQL BEGIN DECLARE SECTION;
758 int rowcount, iid = id, isid = sid;
759 EXEC SQL END DECLARE SECTION;
760
761 EXEC SQL UPDATE users SET box_id = :isid WHERE users.users_id = :iid;
762 rowcount = sqlca.sqlerrd[2];
763 if (rowcount > 0)
764 printf("%d entr%s updated\n", rowcount, rowcount == 1 ? "y" : "ies");
765 else
766 printf("Not updated\n");
767 modified("users");
ab05f33a 768}
772b7afc 769
7ac48069 770void mach_check(int id, void *machine, void *hint)
772b7afc 771{
7ac48069 772 struct machine *m = machine;
773
5eaef520 774 if (!hash_lookup(subnets, m->snet_id))
775 {
776 printf("Machine %s is on a non-existant subnet %d\n",
777 m->name, m->snet_id);
778 if (single_fix("Move to null-subnet", 1))
779 {
780 EXEC SQL BEGIN DECLARE SECTION;
781 int rowcount, iid = id;
782 EXEC SQL END DECLARE SECTION;
783
784 EXEC SQL UPDATE machine SET snet_id = 0 WHERE mach_id = :iid;
785 rowcount = sqlca.sqlerrd[2];
786 if (rowcount > 0)
787 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
788 else
789 printf("Not fixed\n");
790 modified("machine");
772b7afc 791 }
792 }
793
5eaef520 794 switch (m->owner_type)
795 {
772b7afc 796 case 'U':
5eaef520 797 if (!hash_lookup(users, m->owner_id))
798 {
799 printf("Machine %s has non-existant USER owner %d\n",
800 m->name, m->owner_id);
801 if (single_fix("Set to no owner", 1))
802 clear_mach_owner(m);
772b7afc 803 }
5eaef520 804 break;
772b7afc 805 case 'L':
5eaef520 806 if (!hash_lookup(lists, m->owner_id))
807 {
808 printf("Machine %s has non-existant LIST owner %d\n",
809 m->name, m->owner_id);
810 if (single_fix("Set to no owner", 1))
811 clear_mach_owner(m);
772b7afc 812 }
5eaef520 813 break;
ab05f33a 814 case 'S':
815 case 'K':
5eaef520 816 if (m->owner_id)
817 m->owner_id = maybe_fixup_unref_string(m->owner_id, id, m->name,
818 "machine", "owner_id",
819 "mach_id");
820 if (m->owner_id == 0)
ab05f33a 821 clear_mach_owner(m);
772b7afc 822 }
ab05f33a 823
5eaef520 824 if (m->acomment)
825 m->acomment = maybe_fixup_unref_string(m->acomment, id, m->name,
ab05f33a 826 "machine", "acomment", "mach_id");
5eaef520 827 if (m->ocomment)
828 m->ocomment = maybe_fixup_unref_string(m->ocomment, id, m->name,
ab05f33a 829 "machine", "ocomment", "mach_id");
5eaef520 830
831 m->creator = maybe_fixup_modby(m->creator, id, m->name, "machine",
ab05f33a 832 "creator", "mach_id");
5eaef520 833 m->modby = maybe_fixup_modby(m->modby, id, m->name, "machine",
ab05f33a 834 "modby", "mach_id");
772b7afc 835}
836
7ac48069 837void subnet_check(int id, void *subnet, void *hint)
ab05f33a 838{
7ac48069 839 struct subnet *s = subnet;
840
5eaef520 841 switch (s->owner_type)
842 {
ab05f33a 843 case 'U':
5eaef520 844 if (!hash_lookup(users, s->owner_id))
845 {
846 printf("Subnet %s has non-existant USER owner %d\n",
847 s->name, s->owner_id);
848 if (single_fix("Set to no owner", 1))
849 clear_subnet_owner(s);
ab05f33a 850 }
5eaef520 851 break;
ab05f33a 852 case 'L':
5eaef520 853 if (!hash_lookup(lists, s->owner_id))
854 {
855 printf("Machine %s has non-existant LIST owner %d\n",
856 s->name, s->owner_id);
857 if (single_fix("Set to no owner", 1))
858 clear_subnet_owner(s);
ab05f33a 859 }
5eaef520 860 break;
ab05f33a 861 case 'S':
862 case 'K':
5eaef520 863 if (s->owner_id)
864 s->owner_id = maybe_fixup_unref_string(s->owner_id, id, s->name,
865 "machine", "owner_id",
866 "mach_id");
867 if (s->owner_id == 0)
ab05f33a 868 clear_subnet_owner(s);
869 }
870
5eaef520 871 s->modby = maybe_fixup_modby(s->modby, id, s->name, "subnet",
ab05f33a 872 "modby", "snet_id");
873}
874
8949c781 875void clear_user_sponsor(struct user *u)
876{
877 EXEC SQL BEGIN DECLARE SECTION;
878 int rowcount, id = u->users_id;
879 EXEC SQL END DECLARE SECTION;
880
881 EXEC SQL UPDATE users SET sponsor_type = 'NONE', sponsor_id = 0
882 WHERE users_id = :id;
883 rowcount = sqlca.sqlerrd[2];
884 if (rowcount > 0)
885 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
886 else
887 printf("Not fixed\n");
888 modified("users");
889}
890
7ac48069 891void clear_subnet_owner(struct subnet *s)
ab05f33a 892{
5eaef520 893 EXEC SQL BEGIN DECLARE SECTION;
894 int rowcount, id = s->snet_id;
895 EXEC SQL END DECLARE SECTION;
896
897 EXEC SQL UPDATE subnet SET owner_type = 'NONE', owner_id = 0
898 WHERE snet_id = :id;
899 rowcount = sqlca.sqlerrd[2];
900 if (rowcount > 0)
901 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
902 else
903 printf("Not fixed\n");
904 modified("subnet");
ab05f33a 905}
772b7afc 906
7ac48069 907void clear_mach_owner(struct machine *m)
772b7afc 908{
5eaef520 909 EXEC SQL BEGIN DECLARE SECTION;
910 int rowcount, id = m->mach_id;
911 EXEC SQL END DECLARE SECTION;
912
913 EXEC SQL UPDATE machine SET owner_type = 'NONE', owner_id = 0
914 WHERE mach_id = :id;
915 rowcount = sqlca.sqlerrd[2];
916 if (rowcount > 0)
917 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
918 else
919 printf("Not fixed\n");
920 modified("machine");
772b7afc 921}
922
7ac48069 923void cluster_check(int id, void *cluster, void *hint)
ab05f33a 924{
7ac48069 925 struct cluster *c = cluster;
926
5eaef520 927 c->modby = maybe_fixup_modby(c->modby, id, c->name, "clusters",
ab05f33a 928 "modby", "clu_id");
929}
930
7ac48069 931int show_svc(void *id)
5eaef520 932{
933 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 934 int iid = (int)id, found = 1;
cfc4f91e 935 char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE];
5eaef520 936 EXEC SQL END DECLARE SECTION;
ab05f33a 937
5eaef520 938 EXEC SQL DECLARE csr203 CURSOR FOR
939 SELECT serv_label, serv_cluster FROM svc
940 WHERE clu_id = :iid;
941 EXEC SQL OPEN csr203;
942 while (1)
943 {
944 EXEC SQL FETCH csr203 INTO :label, :data;
945 if (sqlca.sqlcode)
946 break;
772b7afc 947
5eaef520 948 strtrim(label);
949 strtrim(data);
950 found = 0;
951 printf("Cluster data [%s] %s for non-existant cluster %d\n",
7ac48069 952 label, data, iid);
208a4f4a 953 }
5eaef520 954 EXEC SQL CLOSE csr203;
955 return found;
208a4f4a 956}
68bbc9c3 957
7ac48069 958void list_check(int id, void *list, void *hint)
68bbc9c3 959{
7ac48069 960 struct list *l = list;
961
cfc4f91e 962 l->modby = maybe_fixup_modby(l->modby, id, l->name, "list",
963 "modby", "list_id");
964
5eaef520 965 switch (l->acl_type)
966 {
68bbc9c3 967 case 'L':
5eaef520 968 if (!hash_lookup(lists, l->acl_id))
969 {
970 printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
971 if (single_fix("Patch", 1))
972 fix_list_acl(l->list_id);
68bbc9c3 973 }
5eaef520 974 break;
68bbc9c3 975 case 'U':
5eaef520 976 if (!hash_lookup(users, l->acl_id))
977 {
978 printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
979 if (single_fix("Patch", 1))
980 fix_list_acl(l->list_id);
68bbc9c3 981 }
5eaef520 982 break;
ab05f33a 983 case 'K':
5eaef520 984 l->acl_id = maybe_fixup_unref_string(l->acl_id, id, l->name,
985 "list", "acl_id", "list_id");
986 if (!l->acl_id)
987 {
988 printf("List %s has bad KERBEROS acl %d\n", l->name, l->acl_id);
989 if (single_fix("Patch", 1))
990 fix_list_acl(l->list_id);
ab05f33a 991 }
5eaef520 992 break;
68bbc9c3 993 }
ad47bcbe 994
995 switch (l->memacl_type)
996 {
997 case 'L':
998 if (!hash_lookup(lists, l->memacl_id))
999 {
1000 printf("List %s has bad LIST memacl %d\n", l->name, l->memacl_id);
1001 if (single_fix("Patch", 1))
1002 fix_list_memacl(l->list_id);
1003 }
1004 break;
1005 case 'U':
1006 if (!hash_lookup(users, l->memacl_id))
1007 {
1008 printf("List %s has bad USER acl %d\n", l->name, l->memacl_id);
1009 if (single_fix("Patch", 1))
1010 fix_list_memacl(l->list_id);
1011 }
1012 break;
1013 case 'K':
1014 l->memacl_id = maybe_fixup_unref_string(l->memacl_id, id, l->name,
1015 "list", "memacl_id", "list_id");
1016 if (!l->memacl_id)
1017 {
1018 printf("List %s has bad KERBEROS acl %d\n", l->name,
1019 l->memacl_id);
1020 if (single_fix("Patch", 1))
1021 fix_list_memacl(l->list_id);
1022 }
1023 break;
1024 }
68bbc9c3 1025}
1026
7ac48069 1027void fix_list_acl(int id)
208a4f4a 1028{
5eaef520 1029 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1030 int rowcount, iid = (int)id;
5eaef520 1031 EXEC SQL END DECLARE SECTION;
68bbc9c3 1032
5eaef520 1033 EXEC SQL UPDATE list SET acl_id = :iid, acl_type = 'LIST'
1034 WHERE list_id = :iid;
1035 rowcount = sqlca.sqlerrd[2];
ad47bcbe 1036 if (rowcount > 0)
1037 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1038 else
1039 printf("Not fixed\n");
1040 modified("list");
1041}
1042
1043void fix_list_memacl(int id)
1044{
1045 EXEC SQL BEGIN DECLARE SECTION;
1046 int rowcount, iid = (int)id;
1047 EXEC SQL END DECLARE SECTION;
1048
1049 EXEC SQL UPDATE list SET memacl_id = 0, memacl_type = 'NONE'
1050 WHERE list_id = :iid;
1051 rowcount = sqlca.sqlerrd[2];
5eaef520 1052 if (rowcount > 0)
1053 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1054 else
1055 printf("Not fixed\n");
1056 modified("list");
1057}
68bbc9c3 1058
7ac48069 1059int show_member_list(void *id)
208a4f4a 1060{
5eaef520 1061 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1062 int mid, iid = (int)id, found = 1;
8d1c466f 1063 char mtype[IMEMBERS_MEMBER_TYPE_SIZE], *name = NULL;
5eaef520 1064 EXEC SQL END DECLARE SECTION;
1065
1066 EXEC SQL DECLARE csr204 CURSOR FOR
1067 SELECT member_type, member_id FROM imembers
8d1c466f 1068 WHERE list_id = :iid;
5eaef520 1069 EXEC SQL OPEN csr204;
1070 while (1)
1071 {
1072 EXEC SQL FETCH csr204 INTO :mtype, :mid;
1073 if (sqlca.sqlcode)
1074 break;
1075
1076 strtrim(mtype);
1077 found = 0;
1078 if (mtype[0] == 'L')
8d1c466f 1079 {
1080 struct list *l = hash_lookup(lists, mid);
1081 if (l)
1082 name = l->name;
1083 }
5eaef520 1084 else if (mtype[0] == 'U')
8d1c466f 1085 {
1086 struct user *u = hash_lookup(users, mid);
1087 if (u)
1088 name = u->login;
1089 }
5eaef520 1090 else if (mtype[0] == 'S' || mtype[0] == 'K')
8d1c466f 1091 {
1092 struct string *s = hash_lookup(strings, mid);
1093 if (s)
1094 name = s->name;
1095 }
1096 if (name)
1097 printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
1098 else
1099 {
1100 printf("Non-existant list %d has non-existent member %s %d\n",
1101 iid, mtype, mid);
1102 }
208a4f4a 1103 }
5eaef520 1104 EXEC SQL CLOSE csr204;
1105 return found;
208a4f4a 1106}
68bbc9c3 1107
7ac48069 1108int show_mem_user(void *id)
208a4f4a 1109{
5eaef520 1110 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1111 int lid, iid = (int)id, found = 1;
5eaef520 1112 EXEC SQL END DECLARE SECTION;
8d1c466f 1113 struct list *l;
5eaef520 1114
1115 EXEC SQL DECLARE csr205 CURSOR FOR
1116 SELECT list_id FROM imembers
8d1c466f 1117 WHERE member_id = :iid AND member_type = 'USER';
5eaef520 1118 EXEC SQL OPEN csr205;
1119 while (1)
1120 {
1121 EXEC SQL FETCH csr205 INTO :lid;
1122 if (sqlca.sqlcode)
1123 break;
8d1c466f 1124 l = hash_lookup(lists, lid);
1125 if (!l)
1126 continue;
5eaef520 1127
1128 found = 0;
8d1c466f 1129 printf("List %s has non-existant user member, id %d\n", l->name, iid);
208a4f4a 1130 }
5eaef520 1131 EXEC SQL CLOSE csr205;
1132 return found;
208a4f4a 1133}
68bbc9c3 1134
7ac48069 1135int show_mem_list(void *id)
208a4f4a 1136{
5eaef520 1137 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1138 int lid, iid = (int)id, found = 1;
5eaef520 1139 EXEC SQL END DECLARE SECTION;
8d1c466f 1140 struct list *l;
5eaef520 1141
1142 EXEC SQL DECLARE csr206 CURSOR FOR
1143 SELECT list_id FROM imembers
8d1c466f 1144 WHERE member_id = :iid AND member_type = 'LIST';
5eaef520 1145 EXEC SQL OPEN csr206;
1146 while (1)
1147 {
1148 EXEC SQL FETCH csr206 INTO :lid;
1149 if (sqlca.sqlcode)
1150 break;
8d1c466f 1151 l = hash_lookup(lists, lid);
1152 if (!l)
1153 continue;
5eaef520 1154
1155 found = 0;
8d1c466f 1156 printf("List %s has non-existant list member, id %d\n", l->name, iid);
208a4f4a 1157 }
5eaef520 1158 EXEC SQL CLOSE csr206;
1159 return found;
208a4f4a 1160}
68bbc9c3 1161
7ac48069 1162int show_mem_str(void *id)
208a4f4a 1163{
5eaef520 1164 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1165 int lid, iid = (int)id, found = 1;
5eaef520 1166 EXEC SQL END DECLARE SECTION;
8d1c466f 1167 struct list *l;
5eaef520 1168
1169 EXEC SQL DECLARE csr207 CURSOR FOR
1170 SELECT list_id FROM imembers
8d1c466f 1171 WHERE member_id = :iid AND member_type = 'STRING';
5eaef520 1172 EXEC SQL OPEN csr207;
1173 while (1)
1174 {
1175 EXEC SQL FETCH csr207 INTO :lid;
1176 if (sqlca.sqlcode)
1177 break;
8d1c466f 1178 l = hash_lookup(lists, lid);
1179 if (!l)
1180 continue;
5eaef520 1181
1182 found = 0;
8d1c466f 1183 printf("List %s has non-existant string member, id %d\n", l->name, iid);
208a4f4a 1184 }
5eaef520 1185 EXEC SQL CLOSE csr207;
1186 return found;
208a4f4a 1187}
68bbc9c3 1188
1189
7ac48069 1190int show_mem_krb(void *id)
208a4f4a 1191{
5eaef520 1192 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1193 int lid, iid = (int)id, found = 1;
5eaef520 1194 EXEC SQL END DECLARE SECTION;
8d1c466f 1195 struct list *l;
5eaef520 1196
1197 EXEC SQL DECLARE csr208 CURSOR FOR
1198 SELECT list_id FROM imembers
8d1c466f 1199 WHERE member_id = :iid AND member_type = 'KERBEROS';
5eaef520 1200 EXEC SQL OPEN csr208;
1201 while (1)
1202 {
1203 EXEC SQL FETCH csr208 INTO :lid;
1204 if (sqlca.sqlcode)
1205 break;
8d1c466f 1206 l = hash_lookup(lists, lid);
1207 if (!l)
1208 continue;
5eaef520 1209
1210 found = 0;
1211 printf("List %s has non-existant kerberos member, id %d\n",
8d1c466f 1212 l->name, iid);
208a4f4a 1213 }
5eaef520 1214 EXEC SQL CLOSE csr208;
1215 return found;
208a4f4a 1216}
68bbc9c3 1217
5f7b0741 1218int show_mem_mach(void *id)
1219{
1220 EXEC SQL BEGIN DECLARE SECTION;
1221 int lid, iid = (int)id, found = 1;
1222 EXEC SQL END DECLARE SECTION;
1223 struct list *l;
1224
1225 EXEC SQL DECLARE csr208a CURSOR FOR
1226 SELECT list_id FROM imembers
1227 WHERE member_id = :iid AND member_type = 'MACHINE';
1228 EXEC SQL OPEN csr208a;
1229 while (1)
1230 {
1231 EXEC SQL FETCH csr208a INTO :lid;
1232 if (sqlca.sqlcode)
1233 break;
1234 l = hash_lookup(lists, lid);
1235 if (!l)
1236 continue;
1237
1238 found = 0;
1239 printf("List %s has nonexistant machine member, id %d\n",
1240 l->name, iid);
1241 }
1242 EXEC SQL CLOSE csr208a;
1243 return found;
1244}
68bbc9c3 1245
7ac48069 1246void del_mem_user(void *id)
208a4f4a 1247{
5eaef520 1248 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1249 int iid = (int)id, rowcount;
5eaef520 1250 EXEC SQL END DECLARE SECTION;
1251
1252 EXEC SQL DELETE FROM imembers WHERE member_type = 'USER' AND
8d1c466f 1253 member_id = :iid;
5eaef520 1254 rowcount = sqlca.sqlerrd[2];
1255 if (rowcount > 0)
1256 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1257 else
1258 printf("Not deleted\n");
1259 modified("imembers");
208a4f4a 1260}
68bbc9c3 1261
7ac48069 1262void del_mem_list(void *id)
208a4f4a 1263{
5eaef520 1264 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1265 int iid = (int)id, rowcount;
5eaef520 1266 EXEC SQL END DECLARE SECTION;
1267
1268 EXEC SQL DELETE FROM imembers WHERE member_type = 'LIST' AND
8d1c466f 1269 member_id = :iid;
5eaef520 1270 rowcount = sqlca.sqlerrd[2];
1271 if (rowcount > 0)
1272 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1273 else
1274 printf("Not deleted\n");
1275 modified("imembers");
208a4f4a 1276}
68bbc9c3 1277
7ac48069 1278void del_mem_str(void *id)
208a4f4a 1279{
5eaef520 1280 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1281 int iid = (int)id, rowcount;
5eaef520 1282 EXEC SQL END DECLARE SECTION;
1283
1284 EXEC SQL DELETE FROM imembers WHERE member_type = 'STRING' AND
8d1c466f 1285 member_id = :iid;
5eaef520 1286 rowcount = sqlca.sqlerrd[2];
1287 if (rowcount > 0)
1288 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1289 else
1290 printf("Not deleted\n");
1291 modified("imembers");
208a4f4a 1292}
68bbc9c3 1293
68bbc9c3 1294
7ac48069 1295void del_mem_krb(void *id)
208a4f4a 1296{
5eaef520 1297 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1298 int iid = (int)id, rowcount;
5eaef520 1299 EXEC SQL END DECLARE SECTION;
1300
1301 EXEC SQL DELETE FROM imembers WHERE member_type = 'KERBEROS' AND
8d1c466f 1302 member_id = :iid;
5eaef520 1303 rowcount = sqlca.sqlerrd[2];
1304 if (rowcount > 0)
1305 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1306 else
1307 printf("Not deleted\n");
1308 modified("imembers");
208a4f4a 1309}
68bbc9c3 1310
5f7b0741 1311void del_mem_mach(void *id)
1312{
1313 EXEC SQL BEGIN DECLARE SECTION;
1314 int iid = (int)id, rowcount;
1315 EXEC SQL END DECLARE SECTION;
1316
1317 EXEC SQL DELETE FROM imembers WHERE member_type = 'MACHINE' AND
1318 member_id = :iid;
1319 rowcount = sqlca.sqlerrd[2];
1320 if (rowcount > 0)
1321 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1322 else
1323 printf("Not deleted\n");
1324 modified("imembers");
1325}
68bbc9c3 1326
7ac48069 1327int show_sh(void *id)
208a4f4a 1328{
5eaef520 1329 EXEC SQL BEGIN DECLARE SECTION;
cfc4f91e 1330 char name[SERVERHOSTS_SERVICE_SIZE];
7ac48069 1331 int iid = (int)id;
5eaef520 1332 EXEC SQL END DECLARE SECTION;
1333 int found = 1;
1334
1335 EXEC SQL DECLARE csr209 CURSOR FOR
1336 SELECT service FROM serverhosts
1337 WHERE mach_id = :iid;
1338 EXEC SQL OPEN csr209;
1339 while (1)
1340 {
1341 EXEC SQL FETCH csr209 INTO :name;
1342 if (sqlca.sqlcode)
1343 break;
1344
1345 found = 0;
1346 printf("ServerHost entry for service %s non-existant host %d\n",
7ac48069 1347 name, iid);
208a4f4a 1348 }
5eaef520 1349 EXEC SQL CLOSE csr209;
1350 return found;
208a4f4a 1351}
68bbc9c3 1352
7ac48069 1353void del_sh_mach(void *id)
208a4f4a 1354{
5eaef520 1355 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1356 int iid = (int)id, rowcount;
5eaef520 1357 EXEC SQL END DECLARE SECTION;
1358
1359 EXEC SQL DELETE FROM serverhosts WHERE mach_id = :iid;
1360 rowcount = sqlca.sqlerrd[2];
1361 if (rowcount > 0)
1362 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1363 else
1364 printf("Not deleted\n");
1365 modified("serverhosts");
208a4f4a 1366}
68bbc9c3 1367
1368
1369static int fnchecklen;
1370
7ac48069 1371void fsmatch(int id, void *nfsphys, void *filesys)
68bbc9c3 1372{
7ac48069 1373 struct nfsphys *n = nfsphys;
1374 struct filesys *f = filesys;
1375
5eaef520 1376 if (n->mach_id == f->mach_id &&
1377 !strncmp(f->dir, n->dir, strlen(n->dir)) &&
1378 strlen(n->dir) > fnchecklen)
1379 {
1380 f->phys_id = id;
1381 fnchecklen = strlen(n->dir);
68bbc9c3 1382 }
1383}
1384
1385
7ac48069 1386void check_fs(int id, void *filesys, void *hint)
208a4f4a 1387{
5eaef520 1388 EXEC SQL BEGIN DECLARE SECTION;
1389 int iid = id, id1, id2, id3, rowcount;
1390 char *dir;
1391 EXEC SQL END DECLARE SECTION;
7ac48069 1392 struct filesys *f = filesys;
5eaef520 1393 struct nfsphys *n;
1394 struct machine *m;
1395
1396 if (!hash_lookup(machines, f->mach_id))
1397 {
1398 printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
1399 if (single_fix("Fix", 0))
1400 {
1401 EXEC SQL UPDATE filesys SET mach_id = 0 WHERE filsys_id = :iid;
1402 rowcount = sqlca.sqlerrd[2];
1403 if (rowcount > 0)
1404 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1405 else
1406 printf("Not fixed\n");
1407 modified("filesys");
1408 f->mach_id = 0;
68bbc9c3 1409 }
1410 }
1411
5eaef520 1412 if (!hash_lookup(users, f->owner))
1413 {
1414 printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
1415 if (single_fix("Fix", 1))
1416 {
1417 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
1418 f->owner = 0;
68bbc9c3 1419 }
1420 }
5eaef520 1421 if (!hash_lookup(lists, f->owners))
1422 {
1423 printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
1424 if (single_fix("Fix", 1))
1425 {
1426 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
1427 f->owners = 0;
68bbc9c3 1428 }
1429 }
1430
fc6165db 1431 if (f->type == 'N' || f->type == 'I')
5eaef520 1432 {
1433 if (!hash_lookup(nfsphys, f->phys_id))
1434 {
7ac48069 1435 m = hash_lookup(machines, f->mach_id);
5eaef520 1436 printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
1437 if (single_fix("Fix", 1))
1438 {
1439 fnchecklen = 0;
1440 hash_step(nfsphys, fsmatch, f);
1441 if (fnchecklen != 0)
1442 {
68bbc9c3 1443 id1 = f->phys_id;
1444 id2 = f->filsys_id;
1445 id3 = f->mach_id;
5eaef520 1446 EXEC SQL UPDATE filesys SET phys_id = :id1
1447 WHERE filsys_id = :id2;
4b9e5c72 1448 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1449 if (rowcount > 0)
5eaef520 1450 printf("%d entr%s fixed\n", rowcount,
1451 rowcount == 1 ? "y" : "ies");
68bbc9c3 1452 else
1453 printf("Not fixed\n");
1454 modified("filesys");
5eaef520 1455 }
1456 else
1457 {
1458 printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
1459 if (single_fix("Create", 0))
1460 {
1461 dir = f->dir;
1462 id1 = f->phys_id;
1463 id2 = f->filsys_id;
1464 id3 = f->mach_id;
1465 if (set_next_object_id("nfsphys_id", "nfsphys") !=
1466 MR_SUCCESS)
1467 {
1468 printf("Unable to assign unique ID\n");
1469 return;
68bbc9c3 1470 }
5eaef520 1471 EXEC SQL SELECT COUNT(*) INTO :rowcount FROM numvalues
1472 WHERE name = 'nfsphys_id';
1473 if (rowcount != 1)
1474 {
1475 printf("Unable to retrieve unique ID\n");
1476 return;
68bbc9c3 1477 }
5eaef520 1478 EXEC SQL INSERT INTO nfsphys
1479 (nfsphys_id, mach_id, device, dir, status, allocated,
1480 size, modtime, modby, modwith) VALUES
1481 (:id1, :id3, '\?\?\?', :dir, 0, 0, 0, SYSDATE, 0,
1482 'dbck');
4b9e5c72 1483 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1484 if (rowcount > 0)
5eaef520 1485 {
1486 printf("%d entr%s created\n", rowcount,
1487 rowcount == 1 ? "y" : "ies");
1488 }
68bbc9c3 1489 else
1490 printf("Not created\n");
1491 modified("nfsphys");
5eaef520 1492 n = malloc(sizeof(struct nfsphys));
1493 if (!n)
68bbc9c3 1494 out_of_mem("storing new nfsphys");
1495 strcpy(n->dir, dir);
1496 n->mach_id = id3;
1497 n->nfsphys_id = id1;
1498 n->allocated = 0;
1499 n->count = 0;
5eaef520 1500 if (hash_store(nfsphys, id1, n) == -1)
ab05f33a 1501 out_of_mem("storing nfsphys in hash table");
208a4f4a 1502 EXEC SQL UPDATE filesys SET phys_id = :id1
5eaef520 1503 WHERE filsys_id = :id2;
4b9e5c72 1504 rowcount = sqlca.sqlerrd[2];
68bbc9c3 1505 if (rowcount > 0)
5eaef520 1506 {
1507 printf("%d filesys entr%s fixed\n", rowcount,
1508 rowcount == 1 ? "y" : "ies");
1509 }
68bbc9c3 1510 else
1511 printf("Not fixed\n");
1512 modified("filesys");
1513 }
1514 }
1515 }
1516 }
1517 }
208a4f4a 1518}
68bbc9c3 1519
7ac48069 1520void check_nfsphys(int id, void *nfsphys, void *hint)
68bbc9c3 1521{
7ac48069 1522 struct nfsphys *n = nfsphys;
1523
cfc4f91e 1524 n->modby = maybe_fixup_modby(n->modby, id, n->dir, "nfsphys",
1525 "modby", "nfsphys_id");
1526
5eaef520 1527 if (!hash_lookup(machines, n->mach_id))
1528 {
1529 printf("NFSphys %d(%s) on non-existant machine %d\n",
1530 id, n->dir, n->mach_id);
1531 if (single_fix("Delete", 0))
1532 single_delete("nfsphys", "nfsphys_id", id);
68bbc9c3 1533 }
1534}
1535
fe0a844a 1536static void clear_ps_owner(struct printserver *ps)
1537{
1538 EXEC SQL BEGIN DECLARE SECTION;
1539 int rowcount, id = ps->mach_id;
1540 EXEC SQL END DECLARE SECTION;
1541
1542 EXEC SQL UPDATE printserver SET owner_type = 'NONE', owner_id = 0
1543 WHERE mach_id = :id;
1544 rowcount = sqlca.sqlerrd[2];
1545 if (rowcount > 0)
1546 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1547 else
1548 printf("Not fixed\n");
1549 modified("printservers");
1550}
1551
1552static void clear_ps_lpc(struct printserver *ps)
1553{
1554 EXEC SQL BEGIN DECLARE SECTION;
1555 int rowcount, id = ps->mach_id;
1556 EXEC SQL END DECLARE SECTION;
1557
1558 EXEC SQL UPDATE printserver SET lpc_acl = 0
1559 WHERE mach_id = :id;
1560 rowcount = sqlca.sqlerrd[2];
1561 if (rowcount > 0)
1562 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1563 else
1564 printf("Not fixed\n");
1565 modified("printservers");
1566}
1567
1568void check_ps(int id, void *printserver, void *hint)
1569{
1570 struct printserver *ps = printserver;
1571 struct machine *m;
1572 char *name;
1573
1574 m = hash_lookup(machines, id);
1575 if (!m)
1576 {
1577 printf("Printserver on non-existant machine %d\n", id);
1578 if (single_fix("Delete", 0))
1579 {
61eec0b8 1580 single_delete("printservers", "mach_id", id);
fe0a844a 1581 return;
1582 }
1583 else
1584 name = "[UNKNOWN]";
1585 }
1586 else
1587 name = m->name;
1588
61eec0b8 1589 ps->modby = maybe_fixup_modby(ps->modby, id, name, "printservers",
fe0a844a 1590 "modby", "mach_id");
1591 ps->printer_types = maybe_fixup_unref_string(ps->printer_types, id, name,
1592 "printservers", "printer_types",
1593 "mach_id");
1594
1595 switch (ps->owner_type)
1596 {
1597 case 'U':
1598 if (!hash_lookup(users, ps->owner_id))
1599 {
1600 printf("Printserver %s has non-existant USER owner %d\n",
1601 name, ps->owner_id);
1602 if (single_fix("Set to no owner", 1))
1603 clear_ps_owner(ps);
1604 }
1605 break;
1606 case 'L':
1607 if (!hash_lookup(lists, ps->owner_id))
1608 {
1609 printf("Printserver %s has non-existant LIST owner %d\n",
1610 name, ps->owner_id);
1611 if (single_fix("Set to no owner", 1))
1612 clear_ps_owner(ps);
1613 }
1614 break;
1615 case 'K':
1616 if (ps->owner_id)
1617 ps->owner_id = maybe_fixup_unref_string(ps->owner_id, id, name,
1618 "printserver", "owner_id",
1619 "mach_id");
1620 if (ps->owner_id == 0)
1621 clear_ps_owner(ps);
1622 }
1623
1624 if (!hash_lookup(lists, ps->lpc_acl))
1625 {
1626 printf("Printserver %s has non-existent lpc_acl %d\n",
1627 name, ps->lpc_acl);
1628 if (single_fix("Set to no lpc_acl", 1))
1629 clear_ps_lpc(ps);
1630 }
1631}
1632
cb884d06 1633static void clear_container_list(struct container *cnt)
1634{
1635 EXEC SQL BEGIN DECLARE SECTION;
1636 int rowcount, id = cnt->cnt_id;
1637 EXEC SQL END DECLARE SECTION;
1638
1639 EXEC SQL UPDATE containers SET list_id = 0
1640 WHERE cnt_id = :id;
1641 rowcount = sqlca.sqlerrd[2];
1642 if (rowcount > 0)
1643 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1644 else
1645 printf("Not fixed\n");
1646 modified("containers");
1647}
1648
1649void fix_container_acl(int id)
1650{
1651 EXEC SQL BEGIN DECLARE SECTION;
1652 int rowcount, iid = (int)id;
1653 EXEC SQL END DECLARE SECTION;
1654
1655 EXEC SQL UPDATE containers SET acl_id = 0, acl_type = 'NONE'
1656 WHERE cnt_id = :iid;
1657 rowcount = sqlca.sqlerrd[2];
1658 if (rowcount > 0)
1659 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1660 else
1661 printf("Not fixed\n");
1662 modified("containers");
1663}
1664
1665void fix_container_memacl(int id)
1666{
1667 EXEC SQL BEGIN DECLARE SECTION;
1668 int rowcount, iid = (int)id;
1669 EXEC SQL END DECLARE SECTION;
1670
1671 EXEC SQL UPDATE containers SET memacl_id = 0, memacl_type = 'NONE'
1672 WHERE cnt_id = :iid;
1673 rowcount = sqlca.sqlerrd[2];
1674 if (rowcount > 0)
1675 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1676 else
1677 printf("Not fixed\n");
1678 modified("containers");
1679}
1680
1681void check_container(int id, void *container, void *hint)
1682{
1683 struct container *cnt = container;
1684
1685 if (!hash_lookup(lists, cnt->list_id))
1686 {
1687 printf("Container %s has non-existent associated list_id %d\n",
1688 cnt->name, cnt->list_id);
1689 if (single_fix("Set to no associated list", 1))
1690 clear_container_list(cnt);
1691 }
1692
1693 switch (cnt->acl_type)
1694 {
1695 case 'L':
1696 if (!hash_lookup(lists, cnt->acl_id))
1697 {
1698 printf("Container %s has bad LIST acl %d\n", cnt->name, cnt->acl_id);
1699 if (single_fix("Patch", 1))
1700 fix_container_acl(cnt->cnt_id);
1701 }
1702 break;
1703 case 'U':
1704 if (!hash_lookup(users, cnt->acl_id))
1705 {
1706 printf("Container %s has bad USER acl %d\n", cnt->name, cnt->acl_id);
1707 if (single_fix("Patch", 1))
1708 fix_container_acl(cnt->cnt_id);
1709 }
1710 break;
1711 case 'K':
1712 cnt->acl_id = maybe_fixup_unref_string(cnt->acl_id, id, cnt->name,
1713 "container", "acl_id", "cnt_id");
1714 if (!cnt->acl_id)
1715 {
1716 printf("Container %s has bad KERBEROS acl %d\n", cnt->name,
1717 cnt->acl_id);
1718 if (single_fix("Patch", 1))
1719 fix_container_acl(cnt->cnt_id);
1720 }
1721 break;
1722 }
1723
1724 switch (cnt->memacl_type)
1725 {
1726 case 'L':
1727 if (!hash_lookup(lists, cnt->memacl_id))
1728 {
1729 printf("Container %s has bad LIST memacl %d\n", cnt->name,
1730 cnt->memacl_id);
1731 if (single_fix("Patch", 1))
1732 fix_container_memacl(cnt->cnt_id);
1733 }
1734 break;
1735 case 'U':
1736 if (!hash_lookup(users, cnt->memacl_id))
1737 {
1738 printf("Container %s has bad USER memacl %d\n", cnt->name,
1739 cnt->memacl_id);
1740 if (single_fix("Patch", 1))
1741 fix_container_memacl(cnt->cnt_id);
1742 }
1743 break;
1744 case 'K':
1745 cnt->memacl_id = maybe_fixup_unref_string(cnt->memacl_id, id, cnt->name,
1746 "container", "memacl_id",
1747 "cnt_id");
1748 if (!cnt->memacl_id)
1749 {
1750 printf("Container %s has bad KERBEROS memacl %d\n", cnt->name,
1751 cnt->memacl_id);
1752 if (single_fix("Patch", 1))
1753 fix_container_memacl(cnt->cnt_id);
1754 }
1755 break;
1756 }
1757
1758 cnt->modby = maybe_fixup_modby(cnt->modby, id, cnt->name, "containers",
1759 "modby", "cnt_id");
1760}
1761
7ac48069 1762int show_fsg_missing(void *id)
208a4f4a 1763{
5eaef520 1764 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1765 int iid = (int)id, id1, found = 1;
5eaef520 1766 EXEC SQL END DECLARE SECTION;
1767 struct filesys *f;
1768
1769 EXEC SQL DECLARE csr210 CURSOR FOR
1770 SELECT filsys_id FROM fsgroup
1771 WHERE group_id = :iid;
1772 EXEC SQL OPEN csr210;
1773 while (1)
1774 {
1775 EXEC SQL FETCH csr210 INTO :id1;
1776 if (sqlca.sqlcode)
1777 break;
1778
1779 found = 0;
7ac48069 1780 if ((f = hash_lookup(filesys, id1)))
1781 printf("Missing fsgroup %d has member filesystem %s\n", iid, f->name);
5eaef520 1782 else
7ac48069 1783 printf("Missing fsgroup %d has member filesystem %d\n", iid, id1);
208a4f4a 1784 }
5eaef520 1785 EXEC SQL CLOSE csr210;
1786 return found;
208a4f4a 1787}
68bbc9c3 1788
7ac48069 1789int show_fsg_type(void *filesys)
68bbc9c3 1790{
7ac48069 1791 struct filesys *f = filesys;
5eaef520 1792 char *t;
68bbc9c3 1793
5eaef520 1794 switch (f->type)
1795 {
68bbc9c3 1796 case 'N':
5eaef520 1797 t = "NFS";
1798 break;
68bbc9c3 1799 case 'R':
5eaef520 1800 t = "RVD";
1801 break;
68bbc9c3 1802 case 'A':
5eaef520 1803 t = "AFS";
1804 break;
68bbc9c3 1805 case 'E':
5eaef520 1806 t = "ERR";
1807 break;
68bbc9c3 1808 case 'F':
5eaef520 1809 t = "FSGROUP";
1810 break;
68bbc9c3 1811 case 'M':
5eaef520 1812 t = "MUL";
1813 break;
68bbc9c3 1814 default:
5eaef520 1815 t = "\?\?\?";
68bbc9c3 1816 }
5eaef520 1817 printf("FSGroup %s has type %s instead of FSGROUP\n", f->name, t);
1818 return 0;
68bbc9c3 1819}
1820
7ac48069 1821void fix_fsg_type(void *filesys)
208a4f4a 1822{
7ac48069 1823 struct filesys *f = filesys;
5eaef520 1824 EXEC SQL BEGIN DECLARE SECTION;
1825 int rowcount, id = f->filsys_id;
1826 EXEC SQL END DECLARE SECTION;
1827
1828 EXEC SQL UPDATE filesys SET type = 'FSGROUP' WHERE filsys_id = :id;
1829 rowcount = sqlca.sqlerrd[2];
1830 if (rowcount > 0)
1831 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
1832 else
1833 printf("Not fixed\n");
1834 modified("filesys");
208a4f4a 1835}
68bbc9c3 1836
7ac48069 1837int show_fsg_nomember(void *id)
208a4f4a 1838{
5eaef520 1839 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1840 int iid = (int)id, id1, found = 1;
5eaef520 1841 EXEC SQL END DECLARE SECTION;
1842 struct filesys *f;
1843
1844 EXEC SQL DECLARE csr211 CURSOR FOR
1845 SELECT group_id FROM fsgroup
1846 WHERE filsys_id = :iid;
1847 EXEC SQL OPEN csr211;
1848 while (1)
1849 {
1850 EXEC SQL FETCH csr211 INTO :id1;
1851 if (sqlca.sqlcode)
1852 break;
1853
1854 found = 0;
7ac48069 1855 if ((f = hash_lookup(filesys, id1)))
1856 printf("FSGroup %s has missing member %d\n", f->name, iid);
5eaef520 1857 else
7ac48069 1858 printf("FSGroup %d has missing member %d\n", id1, iid);
208a4f4a 1859 }
5eaef520 1860 EXEC SQL CLOSE csr211;
1861 return found;
208a4f4a 1862}
1863
7ac48069 1864int show_quota_nouser(void *id)
208a4f4a 1865{
5eaef520 1866 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1867 int iid = (int)id, id1, found = 1;
5eaef520 1868 EXEC SQL END DECLARE SECTION;
1869
1870 EXEC SQL DECLARE csr212 CURSOR FOR
1871 SELECT filsys_id FROM quota
1872 WHERE entity_id = :iid AND type = 'USER';
1873 EXEC SQL OPEN csr212;
1874 while (1)
1875 {
1876 EXEC SQL FETCH csr212 INTO :id1;
1877 if (sqlca.sqlcode)
1878 break;
1879
1880 found = 0;
7ac48069 1881 printf("Quota on fs %d for non-existant user %d\n", id1, iid);
208a4f4a 1882 }
5eaef520 1883 EXEC SQL CLOSE csr212;
1884 return found;
208a4f4a 1885}
1886
7ac48069 1887int show_quota_nolist(void *id)
208a4f4a 1888{
5eaef520 1889 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1890 int iid = (int)id, id1, found = 1;
5eaef520 1891 EXEC SQL END DECLARE SECTION;
1892
1893 EXEC SQL DECLARE csr213 CURSOR FOR
1894 SELECT filsys_id FROM quota
1895 WHERE entity_id = :iid AND type = 'GROUP';
1896 EXEC SQL OPEN csr213;
1897 while (1)
1898 {
1899 EXEC SQL FETCH csr213 INTO :id1;
1900 if (sqlca.sqlcode)
1901 break;
1902
1903 found = 0;
7ac48069 1904 printf("Quota on fs %d for non-existant list %d\n", id1, iid);
208a4f4a 1905 }
5eaef520 1906 EXEC SQL CLOSE csr213;
1907 return found;
208a4f4a 1908}
68bbc9c3 1909
7ac48069 1910void fix_quota_nouser(void *id)
208a4f4a 1911{
5eaef520 1912 EXEC SQL BEGIN DECLARE SECTION;
11975951 1913 int iid = (int)id, rowcount;
5eaef520 1914 EXEC SQL END DECLARE SECTION;
1915
5eaef520 1916 EXEC SQL DELETE FROM quota
1917 WHERE entity_id = :iid AND type = 'USER';
1918 rowcount = sqlca.sqlerrd[2];
1919 if (rowcount > 0)
1920 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1921 else
1922 printf("Not deleted\n");
1923 modified("quota");
208a4f4a 1924}
68bbc9c3 1925
7ac48069 1926void fix_quota_nolist(void *id)
208a4f4a 1927{
5eaef520 1928 EXEC SQL BEGIN DECLARE SECTION;
11975951 1929 int iid = (int)id, rowcount;
5eaef520 1930 EXEC SQL END DECLARE SECTION;
1931
5eaef520 1932 EXEC SQL DELETE FROM quota WHERE entity_id = :iid AND type = 'GROUP';
1933 rowcount = sqlca.sqlerrd[2];
1934 if (rowcount > 0)
1935 printf("%d entr%s deleted\n", rowcount, rowcount == 1 ? "y" : "ies");
1936 else
1937 printf("Not deleted\n");
1938 modified("quota");
208a4f4a 1939}
1940
7ac48069 1941int show_quota_nofs(void *id)
208a4f4a 1942{
5eaef520 1943 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1944 int iid = (int)id, id1, found = 1;
cfc4f91e 1945 char type[QUOTA_TYPE_SIZE];
5eaef520 1946 EXEC SQL END DECLARE SECTION;
1947
1948 EXEC SQL DECLARE csr214 CURSOR FOR
1949 SELECT entity_id, type FROM quota
1950 WHERE filsys_id = :iid;
1951 EXEC SQL OPEN csr214;
1952 while (1)
1953 {
1954 EXEC SQL FETCH csr214 INTO :id1, :type;
1955 if (sqlca.sqlcode)
1956 break;
1957
1958 found = 0;
7ac48069 1959 printf("Quota for %s %d on non-existant filesys %d\n", type, id1, iid);
208a4f4a 1960 }
5eaef520 1961 EXEC SQL CLOSE csr214;
1962 return found;
208a4f4a 1963}
68bbc9c3 1964
7ac48069 1965void fix_quota_nofs(void *id)
68bbc9c3 1966{
7ac48069 1967 single_delete("quota", "filsys_id", (int)id);
68bbc9c3 1968}
1969
7ac48069 1970int show_quota_wrongpid(void *id)
208a4f4a 1971{
5eaef520 1972 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 1973 int iid = (int)id, id1, found = 1;
cfc4f91e 1974 char type[QUOTA_TYPE_SIZE];
5eaef520 1975 EXEC SQL END DECLARE SECTION;
5eaef520 1976 struct filesys *f;
1977
7ac48069 1978 f = hash_lookup(filesys, iid);
5eaef520 1979 EXEC SQL DECLARE csr215 CURSOR FOR
1980 SELECT entity_id, type FROM quota
1981 WHERE filsys_id = :iid;
1982 EXEC SQL OPEN csr215;
1983 while (1)
1984 {
1985 EXEC SQL FETCH csr215 INTO :id1, :type;
1986 if (sqlca.sqlcode)
1987 break;
1988
1989 found = 0;
1990 printf("Quota for %s %d on filesys %s has wrong phys_id %d\n",
7ac48069 1991 type, id1, f->name, iid);
208a4f4a 1992 }
5eaef520 1993 EXEC SQL CLOSE csr215;
1994 return found;
208a4f4a 1995}
68bbc9c3 1996
7ac48069 1997void fix_quota_physid(void *id)
208a4f4a 1998{
5eaef520 1999 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 2000 int iid = (int)id, rowcount, id1;
5eaef520 2001 EXEC SQL END DECLARE SECTION;
2002
7ac48069 2003 id1 = ((struct filesys *)hash_lookup(filesys, iid))->phys_id;
5eaef520 2004 EXEC SQL UPDATE quota SET phys_id = :id1
2005 WHERE filsys_id = :iid AND phys_id != :id1;
2006 rowcount = sqlca.sqlerrd[2];
2007 if (rowcount > 0)
2008 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
2009 else
2010 printf("Not fixed\n");
2011 modified("quota");
208a4f4a 2012}
68bbc9c3 2013
7ac48069 2014int show_srv_user(void *id)
208a4f4a 2015{
5eaef520 2016 EXEC SQL BEGIN DECLARE SECTION;
cfc4f91e 2017 char name[SERVERS_NAME_SIZE];
7ac48069 2018 int iid = (int)id;
5eaef520 2019 EXEC SQL END DECLARE SECTION;
2020 int found = 1;
2021
2022 EXEC SQL DECLARE csr216 CURSOR FOR
2023 SELECT name FROM servers
2024 WHERE acl_type = 'USER' and acl_id = :iid;
2025 EXEC SQL OPEN csr216;
2026 while (1)
2027 {
2028 EXEC SQL FETCH csr216 INTO :name;
2029 if (sqlca.sqlcode)
2030 break;
2031
2032 strtrim(name);
7ac48069 2033 printf("Service %s has acl non-existant user %d\n", name, iid);
5eaef520 2034 found = 0;
208a4f4a 2035 }
5eaef520 2036 EXEC SQL CLOSE csr216;
2037 return found;
208a4f4a 2038}
68bbc9c3 2039
7ac48069 2040int show_srv_list(void *id)
208a4f4a 2041{
5eaef520 2042 EXEC SQL BEGIN DECLARE SECTION;
cfc4f91e 2043 char name[SERVERS_NAME_SIZE];
7ac48069 2044 int iid = (int)id;
5eaef520 2045 EXEC SQL END DECLARE SECTION;
2046 int found = 1;
2047
2048 EXEC SQL DECLARE csr217 CURSOR FOR
2049 SELECT name FROM servers
2050 WHERE acl_type = 'LIST' AND acl_id = :iid;
2051 EXEC SQL OPEN csr217;
2052 while (1)
2053 {
2054 EXEC SQL FETCH csr217 INTO :name;
2055 if (sqlca.sqlcode)
2056 break;
2057
2058 strtrim(name);
7ac48069 2059 printf("Service %s has acl non-existant list %d\n", name, iid);
5eaef520 2060 found = 0;
208a4f4a 2061 }
5eaef520 2062 EXEC SQL CLOSE csr217;
2063 return found;
208a4f4a 2064}
68bbc9c3 2065
7ac48069 2066void zero_srv_user(void *id)
208a4f4a 2067{
5eaef520 2068 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 2069 int iid = (int)id, rowcount;
5eaef520 2070 EXEC SQL END DECLARE SECTION;
2071
2072 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
2073 acl_type = 'USER';
2074 rowcount = sqlca.sqlerrd[2];
2075 if (rowcount > 0)
2076 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
2077 else
2078 printf("Not fixed\n");
2079 modified("servers");
208a4f4a 2080}
68bbc9c3 2081
7ac48069 2082void zero_srv_list(void *id)
208a4f4a 2083{
5eaef520 2084 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 2085 int iid = (int)id, rowcount;
5eaef520 2086 EXEC SQL END DECLARE SECTION;
68bbc9c3 2087
5eaef520 2088 EXEC SQL UPDATE servers SET acl_id = 0 WHERE acl_id = :iid AND
2089 acl_type = 'LIST';
2090 rowcount = sqlca.sqlerrd[2];
2091 if (rowcount > 0)
2092 printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies");
2093 else
2094 printf("Not fixed\n");
2095 modified("servers");
2096}
68bbc9c3 2097
7ac48069 2098int show_krb_usr(void *id)
208a4f4a 2099{
5eaef520 2100 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 2101 int iid = (int)id, found = 1, id1;
5eaef520 2102 EXEC SQL END DECLARE SECTION;
2103 struct string *s;
2104 char *ss;
2105
2106 EXEC SQL DECLARE csr218 CURSOR FOR
2107 SELECT string_id FROM krbmap
2108 WHERE users_id = :iid;
2109 EXEC SQL OPEN csr218;
2110 while (1)
2111 {
2112 EXEC SQL FETCH csr218 INTO :id1;
2113 if (sqlca.sqlcode)
2114 break;
2115
7ac48069 2116 if ((s = hash_lookup(strings, id1)))
5eaef520 2117 ss = s->name;
2118 else
2119 ss = "[unknown]";
2120 found = 0;
2121 printf("Kerberos map for non-existant user %d to principal %s\n",
7ac48069 2122 iid, ss);
208a4f4a 2123 }
5eaef520 2124 EXEC SQL CLOSE csr218;
2125 return found;
208a4f4a 2126}
68bbc9c3 2127
7ac48069 2128int show_krb_str(void *id)
208a4f4a 2129{
5eaef520 2130 EXEC SQL BEGIN DECLARE SECTION;
7ac48069 2131 int iid = (int)id, found = 1, id1;
5eaef520 2132 EXEC SQL END DECLARE SECTION;
2133 struct user *u;
2134 char *s;
2135
2136 EXEC SQL DECLARE csr219 CURSOR FOR
2137 SELECT users_id FROM krbmap
2138 WHERE string_id = :iid;
2139 EXEC SQL OPEN csr219;
2140 while (1)
2141 {
2142 EXEC SQL FETCH csr219 INTO :id1;
2143 if (sqlca.sqlcode)
2144 break;
68bbc9c3 2145
7ac48069 2146 if ((u = hash_lookup(users, id1)))
5eaef520 2147 s = u->login;
2148 else
2149 s = "[\?\?\?]";
2150 found = 0;
2151 printf("Kerberos map for user %s (%d) to non-existant string %d\n",
7ac48069 2152 s, id1, iid);
5eaef520 2153 }
2154 EXEC SQL CLOSE csr219;
2155 return found;
2156}
68bbc9c3 2157
7ac48069 2158void phase2(void)
208a4f4a 2159{
fe0a844a 2160 struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5, *sq6;
5eaef520 2161 struct filesys *f;
2162 struct list *l;
2163 struct nfsphys *n;
2164 struct machine *m;
c978c079 2165 char rowid[32];
5eaef520 2166
2167 printf("Phase 2 - Checking references\n");
2168
2169 dprintf("Checking users...\n");
2170 hash_step(users, user_check, NULL);
2171
2172 dprintf("Checking machines...\n");
2173 hash_step(machines, mach_check, NULL);
2174
2175 dprintf("Checking subnets...\n");
2176 hash_step(subnets, subnet_check, NULL);
2177
2178 dprintf("Checking clusters...\n");
2179 hash_step(clusters, cluster_check, NULL);
2180
2181 dprintf("Checking mcmap...\n");
2182 sq1 = sq_create();
2183 sq2 = sq_create();
2184 EXEC SQL DECLARE csr221 CURSOR FOR
2185 SELECT mach_id, clu_id FROM mcmap;
2186 EXEC SQL OPEN csr221;
2187 while (1)
2188 {
cfc4f91e 2189 EXEC SQL BEGIN DECLARE SECTION;
2190 int mach_id, clu_id;
2191 EXEC SQL END DECLARE SECTION;
2192
2193 EXEC SQL FETCH csr221 INTO :mach_id, :clu_id;
5eaef520 2194 if (sqlca.sqlcode)
2195 break;
2196
cfc4f91e 2197 if (!(m = hash_lookup(machines, mach_id)))
2198 sq_save_unique_data(sq1, (void *)mach_id);
2199 else if (!hash_lookup(clusters, clu_id))
2200 sq_save_unique_data(sq2, (void *)clu_id);
5eaef520 2201 if (m)
2202 m->clucount++;
ab05f33a 2203 }
5eaef520 2204 EXEC SQL CLOSE csr221;
2205 generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
2206 generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
2207
2208 dprintf("Checking service clusters...\n");
2209 sq1 = sq_create();
2210 EXEC SQL DECLARE csr222 CURSOR FOR
2211 SELECT clu_id FROM svc;
2212 EXEC SQL OPEN csr222;
2213 while (1)
2214 {
cfc4f91e 2215 EXEC SQL BEGIN DECLARE SECTION;
2216 int clu_id;
2217 EXEC SQL END DECLARE SECTION;
2218
2219 EXEC SQL FETCH csr222 INTO :clu_id;
5eaef520 2220 if (sqlca.sqlcode)
2221 break;
2222
cfc4f91e 2223 if (!hash_lookup(clusters, clu_id))
2224 sq_save_unique_data(sq1, (void *)clu_id);
208a4f4a 2225 }
5eaef520 2226 EXEC SQL CLOSE csr222;
2227 generic_delete(sq1, show_svc, "svc", "clu_id", 1);
2228
2229 dprintf("Checking lists...\n");
2230 hash_step(lists, list_check, NULL);
2231
2232 dprintf("Checking members...\n");
2233 sq1 = sq_create();
2234 sq2 = sq_create();
2235 sq3 = sq_create();
2236 sq4 = sq_create();
2237 sq5 = sq_create();
5f7b0741 2238 sq6 = sq_create();
5eaef520 2239
2240 EXEC SQL DECLARE csr223 CURSOR FOR
c0a94410 2241 SELECT list_id, member_type, member_id, tag, ref_count, direct, rowid
5eaef520 2242 FROM imembers FOR UPDATE OF member_id;
2243 EXEC SQL OPEN csr223;
2244 while (1)
2245 {
cfc4f91e 2246 EXEC SQL BEGIN DECLARE SECTION;
c0a94410 2247 int list_id, id, tag, ref_count, direct;
cfc4f91e 2248 char type[IMEMBERS_MEMBER_TYPE_SIZE];
2249 EXEC SQL END DECLARE SECTION;
2250
38da5476 2251 EXEC SQL FETCH csr223 INTO :list_id, :type, :id, :tag,
c978c079 2252 :ref_count, :direct, :rowid;
5eaef520 2253 if (sqlca.sqlcode)
2254 break;
c0a94410 2255 strtrim(rowid);
5eaef520 2256
cfc4f91e 2257 if (!(l = hash_lookup(lists, list_id)))
2258 sq_save_unique_data(sq1, (void *)list_id);
2259 else if (type[0] == 'U' && !hash_lookup(users, id))
2260 sq_save_unique_data(sq2, (void *)id);
2261 else if (type[0] == 'L' && !hash_lookup(lists, id))
2262 sq_save_unique_data(sq3, (void *)id);
c0a94410 2263 else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
cfc4f91e 2264 sq_save_unique_data(sq4, (void *)id);
c0a94410 2265 else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", rowid, id))
cfc4f91e 2266 sq_save_unique_data(sq5, (void *)id);
cb884d06 2267 else if (type[0] == 'M' && !hash_lookup(machines, id))
5f7b0741 2268 sq_save_unique_data(sq6, (void *)id);
5eaef520 2269 else
2270 l->members++;
c0a94410 2271 maybe_fixup_unref_string2("imembers", "tag", rowid, tag);
208a4f4a 2272 }
5eaef520 2273 EXEC SQL CLOSE csr223;
2274 generic_delete(sq1, show_member_list, "imembers", "list_id", 1);
2275 generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
2276 generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
2277 generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
2278 generic_fix(sq5, show_mem_krb, "Delete", del_mem_krb, 1);
5f7b0741 2279 generic_fix(sq6, show_mem_mach, "Delete", del_mem_mach, 1);
5eaef520 2280
2281 dprintf("Checking servers...\n");
2282 sq1 = sq_create();
2283 sq2 = sq_create();
2284 EXEC SQL DECLARE csr224 CURSOR FOR
c978c079 2285 SELECT name, acl_type, acl_id, modby, rowid FROM servers
5eaef520 2286 FOR UPDATE of modby;
2287 EXEC SQL OPEN csr224;
2288 while (1)
2289 {
cfc4f91e 2290 EXEC SQL BEGIN DECLARE SECTION;
2291 int acl_id, modby;
2292 char name[SERVERS_NAME_SIZE], acl_type[SERVERS_ACL_TYPE_SIZE];
2293 EXEC SQL END DECLARE SECTION;
2294
c978c079 2295 EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby, :rowid;
5eaef520 2296 if (sqlca.sqlcode)
2297 break;
2298
11975951 2299 maybe_fixup_modby2("servers", "modby", strtrim(rowid), modby);
cfc4f91e 2300 strtrim(acl_type);
2301 if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
2302 sq_save_data(sq1, (void *)acl_id);
2303 else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
2304 sq_save_data(sq2, (void *)acl_id);
5eaef520 2305 }
2306 EXEC SQL CLOSE csr224;
2307 generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
2308 generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
2309
2310 dprintf("Checking serverhosts...\n");
2311 sq = sq_create();
2312 EXEC SQL DECLARE csr225 CURSOR FOR
c978c079 2313 SELECT mach_id, modby, rowid FROM serverhosts
5eaef520 2314 FOR UPDATE OF modby;
2315 EXEC SQL OPEN csr225;
2316 while (1)
2317 {
cfc4f91e 2318 EXEC SQL BEGIN DECLARE SECTION;
2319 int mach_id, modby;
2320 EXEC SQL END DECLARE SECTION;
2321
c978c079 2322 EXEC SQL FETCH csr225 INTO :mach_id, :modby, :rowid;
5eaef520 2323 if (sqlca.sqlcode)
2324 break;
2325
11975951 2326 maybe_fixup_modby2("serverhosts", "modby", strtrim(rowid), modby);
cfc4f91e 2327 if (!hash_lookup(machines, mach_id))
2328 sq_save_data(sq, (void *)mach_id);
5eaef520 2329 }
2330 EXEC SQL CLOSE csr225;
2331 generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
2332
2333 dprintf("Checking nfsphys...\n");
2334 hash_step(nfsphys, check_nfsphys, NULL);
2335
2336 dprintf("Checking filesys...\n");
2337 hash_step(filesys, check_fs, NULL);
2338
2339 dprintf("Checking filesystem groups...\n");
2340 sq1 = sq_create();
2341 sq2 = sq_create();
2342 sq3 = sq_create();
2343 EXEC SQL DECLARE csr226 CURSOR FOR
2344 SELECT group_id, filsys_id FROM fsgroup;
2345 EXEC SQL OPEN csr226;
2346 while (1)
2347 {
cfc4f91e 2348 EXEC SQL BEGIN DECLARE SECTION;
2349 int group_id, filsys_id;
2350 EXEC SQL END DECLARE SECTION;
2351
2352 EXEC SQL FETCH csr226 INTO :group_id, :filsys_id;
5eaef520 2353 if (sqlca.sqlcode)
2354 break;
2355
cfc4f91e 2356 if (!(f = hash_lookup(filesys, group_id)))
2357 sq_save_data(sq1, (void *)group_id);
2358 if (!hash_lookup(filesys, filsys_id))
2359 sq_save_data(sq3, (void *)filsys_id);
208a4f4a 2360 }
5eaef520 2361 EXEC SQL CLOSE csr226;
2362 generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0);
2363 generic_delete(sq3, show_fsg_nomember, "fsgroup", "filsys_id", 1);
2364
2365 dprintf("Checking quotas...\n");
2366 sq1 = sq_create();
2367 sq2 = sq_create();
2368 sq3 = sq_create();
2369 sq4 = sq_create();
2370 EXEC SQL DECLARE csr227 CURSOR FOR
c978c079 2371 SELECT entity_id, type, filsys_id, phys_id, quota, modby, rowid
5eaef520 2372 FROM quota FOR UPDATE OF modby;
2373 EXEC SQL OPEN csr227;
2374 while (1)
2375 {
cfc4f91e 2376 EXEC SQL BEGIN DECLARE SECTION;
2377 int entity_id, filsys_id, phys_id, quota, modby;
2378 char type[QUOTA_TYPE_SIZE];
2379 EXEC SQL END DECLARE SECTION;
2380
2381 EXEC SQL FETCH csr227 INTO :entity_id, :type, :filsys_id,
c978c079 2382 :phys_id, :quota, :modby, :rowid;
5eaef520 2383 if (sqlca.sqlcode)
2384 break;
2385
11975951 2386 maybe_fixup_modby2("quota", "modby", strtrim(rowid), modby);
cfc4f91e 2387 if (type[0] == 'U' && entity_id != 0 && !hash_lookup(users, entity_id))
2388 sq_save_data(sq1, (void *)entity_id);
2389 else if (type[0] == 'G' && !hash_lookup(lists, entity_id))
2390 sq_save_data(sq4, (void *)entity_id);
2391 else if (!(f = hash_lookup(filesys, filsys_id)))
2392 sq_save_data(sq2, (void *)filsys_id);
2393 else if (phys_id != f->phys_id || !(n = hash_lookup(nfsphys, phys_id)))
2394 sq_save_data(sq3, (void *)phys_id);
5eaef520 2395 else
cfc4f91e 2396 n->count += quota;
208a4f4a 2397 }
5eaef520 2398 EXEC SQL CLOSE csr227;
2399 generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
2400 generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
2401 generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
2402 generic_fix(sq4, show_quota_nolist, "Delete", fix_quota_nolist, 1);
2403
37ed4e84 2404 dprintf("Checking zephyr...\n");
2405 EXEC SQL DECLARE csr_zc CURSOR FOR
2406 SELECT class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id,
2407 iui_type, iui_id, modby FROM zephyr;
2408 EXEC SQL OPEN csr_zc;
2409 while(1)
2410 {
2411 EXEC SQL BEGIN DECLARE SECTION;
2412 int xmt_id, sub_id, iws_id, iui_id, modby;
2413 char class[ZEPHYR_CLASS_SIZE];
2414 char xmt_type[ZEPHYR_XMT_TYPE_SIZE];
2415 char sub_type[ZEPHYR_SUB_TYPE_SIZE];
2416 char iws_type[ZEPHYR_IWS_TYPE_SIZE];
2417 char iui_type[ZEPHYR_IUI_TYPE_SIZE];
2418 EXEC SQL END DECLARE SECTION;
2419
2420 EXEC SQL FETCH csr_zc INTO :class, :xmt_type, :xmt_id, :sub_type,
2421 :sub_id, :iws_type, :iws_id, :iui_type, :iui_id, :modby;
2422
2423 if (sqlca.sqlcode)
2424 break;
2425
2426 maybe_fixup_modby2("zephyr", "modby", strtrim(rowid), modby);
2427
2428 strtrim(xmt_type);
2429 if (!strcmp(xmt_type, "USER") && !hash_lookup(users, xmt_id))
2430 {
2431 printf("xmt acl for %s is non-existant user %d\n", class, xmt_id);
2432 printf("Not fixing this error\n");
2433 }
2434 else if (!strcmp(xmt_type, "LIST") && !hash_lookup(lists, xmt_id))
2435 {
2436 printf("xmt acl for %s is non-existant list %d\n", class, xmt_id);
2437 printf("Not fixing this error\n");
2438 }
2439 else if (!strcmp(xmt_type, "STRING") || !strcmp(xmt_type, "KERBEROS"))
2440 maybe_fixup_unref_string2("zephyr", "xmt_id", strtrim(rowid), xmt_id);
2441
2442 strtrim(sub_type);
2443 if (!strcmp(sub_type, "USER") && !hash_lookup(users, sub_id))
2444 {
2445 printf("sub acl for %s is non-existant user %d\n", class, sub_id);
2446 printf("Not fixing this error\n");
2447 }
2448 else if (!strcmp(sub_type, "LIST") && !hash_lookup(lists, sub_id))
2449 {
2450 printf("sub acl for %s is non-existant list %d\n", class, sub_id);
2451 printf("Not fixing this error\n");
2452 }
2453 else if (!strcmp(sub_type, "STRING") || !strcmp(sub_type, "KERBEROS"))
2454 maybe_fixup_unref_string2("zephyr", "sub_id", strtrim(rowid), sub_id);
2455
2456 strtrim(iws_type);
2457 if (!strcmp(iws_type, "USER") && !hash_lookup(users, iws_id))
2458 {
2459 printf("iws acl for %s is non-existant user %d\n", class, iws_id);
2460 printf("Not fixing this error\n");
2461 }
2462 else if (!strcmp(iws_type, "LIST") && !hash_lookup(lists, iws_id))
2463 {
2464 printf("iws acl for %s is non-existant list %d\n", class, iws_id);
2465 printf("Not fixing this error\n");
2466 }
2467 else if (!strcmp(iws_type, "STRING") || !strcmp(iws_type, "KERBEROS"))
2468 maybe_fixup_unref_string2("zephyr", "iws_id", strtrim(rowid), iws_id);
2469
2470 strtrim(iui_type);
2471 if (!strcmp(iui_type, "USER") && !hash_lookup(users, iui_id))
2472 {
2473 printf("iui acl for %s is non-existant user %d\n", class, iui_id);
2474 printf("Not fixing this error\n");
2475 }
2476 else if (!strcmp(iui_type, "LIST") && !hash_lookup(lists, iui_id))
2477 {
2478 printf("iui acl for %s is non-existant list %d\n", class, iui_id);
2479 printf("Not fixing this error\n");
2480 }
2481 else if (!strcmp(iui_type, "STRING") || !strcmp(iui_type, "KERBEROS"))
2482 maybe_fixup_unref_string2("zephyr", "iui_id", strtrim(rowid), iui_id);
2483 }
5eaef520 2484
2485 dprintf("Checking hostaccess...\n");
2486 EXEC SQL DECLARE csr228 CURSOR FOR
c978c079 2487 SELECT mach_id, acl_type, acl_id, modby, rowid FROM hostaccess
5eaef520 2488 FOR UPDATE OF modby;
2489 EXEC SQL OPEN csr228;
2490 while (1)
2491 {
cfc4f91e 2492 EXEC SQL BEGIN DECLARE SECTION;
2493 int mach_id, acl_id, modby;
2494 char acl_type[HOSTACCESS_ACL_TYPE_SIZE];
2495 EXEC SQL END DECLARE SECTION;
2496
c978c079 2497 EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby, :rowid;
5eaef520 2498 if (sqlca.sqlcode)
2499 break;
2500
11975951 2501 maybe_fixup_modby2("hostaccess", "modby", strtrim(rowid), modby);
cfc4f91e 2502 strtrim(acl_type);
2503 if (!hash_lookup(machines, mach_id))
5eaef520 2504 {
cfc4f91e 2505 printf("Hostaccess for non-existant host %d\n", mach_id);
5eaef520 2506 printf("Not fixing this error\n");
68bbc9c3 2507 }
cfc4f91e 2508 if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id))
5eaef520 2509 {
cfc4f91e 2510 printf("Hostaccess for %d is non-existant user %d\n", mach_id, acl_id);
5eaef520 2511 printf("Not fixing this error\n");
68bbc9c3 2512 }
cfc4f91e 2513 else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id))
5eaef520 2514 {
cfc4f91e 2515 printf("Hostaccess for %d is non-existant list %d\n", mach_id, acl_id);
5eaef520 2516 printf("Not fixing this error\n");
68bbc9c3 2517 }
208a4f4a 2518 }
5eaef520 2519 EXEC SQL CLOSE csr228;
2520
5eaef520 2521 dprintf("Checking krbmap...\n");
2522 sq1 = sq_create();
2523 sq2 = sq_create();
2524 EXEC SQL DECLARE csr230 CURSOR FOR
c978c079 2525 SELECT users_id, string_id, rowid FROM krbmap
5eaef520 2526 FOR UPDATE OF string_id;
2527 EXEC SQL OPEN csr230;
2528 while (1)
2529 {
cfc4f91e 2530 EXEC SQL BEGIN DECLARE SECTION;
2531 int users_id, string_id;
2532 EXEC SQL END DECLARE SECTION;
2533
c978c079 2534 EXEC SQL FETCH csr230 INTO :users_id, :string_id, :rowid;
5eaef520 2535 if (sqlca.sqlcode)
2536 break;
2537
cfc4f91e 2538 if (!hash_lookup(users, users_id))
2539 sq_save_unique_data(sq1, (void *)users_id);
11975951 2540 else if (!maybe_fixup_unref_string2("krbmap", "string_id", strtrim(rowid), string_id))
cfc4f91e 2541 sq_save_unique_data(sq2, (void *)string_id);
5eaef520 2542 }
2543 EXEC SQL CLOSE csr230;
2544 generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1);
2545 generic_delete(sq2, show_krb_str, "krbmap", "string_id", 1);
2546
2547 dprintf("Checking capacls...\n");
2548 EXEC SQL DECLARE csr231 CURSOR FOR
2549 SELECT list_id, tag FROM capacls;
2550 EXEC SQL OPEN csr231;
2551 while (1)
2552 {
cfc4f91e 2553 EXEC SQL BEGIN DECLARE SECTION;
2554 int list_id;
2555 char tag[CAPACLS_TAG_SIZE];
2556 EXEC SQL END DECLARE SECTION;
2557
2558 EXEC SQL FETCH csr231 INTO :list_id, :tag;
5eaef520 2559 if (sqlca.sqlcode)
2560 break;
2561
cfc4f91e 2562 if (!hash_lookup(lists, list_id))
5eaef520 2563 {
cfc4f91e 2564 printf("Capacl for %s is non-existant list %d\n", tag, list_id);
5eaef520 2565 printf("Not fixing this error\n");
68bbc9c3 2566 }
208a4f4a 2567 }
5eaef520 2568 EXEC SQL CLOSE csr231;
2569
8ef54684 2570 dprintf("Checking hostaliases...\n");
5eaef520 2571 sq1 = sq_create();
2572 EXEC SQL DECLARE csr232 CURSOR FOR
2573 SELECT mach_id FROM hostalias;
2574 EXEC SQL OPEN csr232;
2575 while (1)
2576 {
cfc4f91e 2577 EXEC SQL BEGIN DECLARE SECTION;
2578 int mach_id;
2579 EXEC SQL END DECLARE SECTION;
2580
2581 EXEC SQL FETCH csr232 INTO :mach_id;
5eaef520 2582 if (sqlca.sqlcode)
2583 break;
2584
cfc4f91e 2585 if (!hash_lookup(machines, mach_id))
2586 sq_save_unique_data(sq1, (void *)mach_id);
ab05f33a 2587 }
5eaef520 2588 EXEC SQL CLOSE csr232;
2589 generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1);
2590
8ef54684 2591 dprintf("Checking printers...\n");
5eaef520 2592 sq1 = sq_create();
2593 sq2 = sq_create();
dabf20aa 2594 sq3 = sq_create();
2595 sq4 = sq_create();
2596 sq5 = sq_create();
fe0a844a 2597 sq6 = sq_create();
5eaef520 2598 EXEC SQL DECLARE csr233 CURSOR FOR
c978c079 2599 SELECT mach_id, loghost, rm, rq, ac, lpc_acl, modby, rowid FROM printers;
5eaef520 2600 EXEC SQL OPEN csr233;
2601 while (1)
2602 {
cfc4f91e 2603 EXEC SQL BEGIN DECLARE SECTION;
c96b70a5 2604 int mach_id, loghost, rm, rq, ac, lpc_acl, modby;
cfc4f91e 2605 EXEC SQL END DECLARE SECTION;
2606
11975951 2607 EXEC SQL FETCH csr233 INTO :mach_id, :loghost, :rm, :rq, :ac,
c978c079 2608 :lpc_acl, :modby, :rowid;
5eaef520 2609 if (sqlca.sqlcode)
2610 break;
2611
11975951 2612 maybe_fixup_modby2("printers", "modby", strtrim(rowid), modby);
cfc4f91e 2613 if (!hash_lookup(machines, mach_id))
2614 sq_save_unique_data(sq1, (void *)mach_id);
dabf20aa 2615 else if (!hash_lookup(machines, rm))
2616 sq_save_unique_data(sq2, (void *)rm);
fe0a844a 2617 else if (!hash_lookup(printservers, rm))
2618 sq_save_unique_data(sq6, (void *)mach_id);
dabf20aa 2619 else if (!hash_lookup(machines, rq))
2620 sq_save_unique_data(sq3, (void *)rq);
2621 else {
2622 if (!hash_lookup(lists, ac))
2623 sq_save_unique_data(sq4, (void *)ac);
2624 if (!hash_lookup(lists, lpc_acl))
2625 sq_save_unique_data(sq5, (void *)lpc_acl);
2626 if (!hash_lookup(machines, loghost))
2627 {
2628 show_printer_loghost((void *)loghost);
c96b70a5 2629 cant_fix();
dabf20aa 2630 }
c96b70a5 2631 }
ab05f33a 2632 }
5eaef520 2633 EXEC SQL CLOSE csr233;
dabf20aa 2634 generic_delete(sq1, show_printer_mach, "printers", "mach_id", 1);
fe0a844a 2635 generic_delete(sq6, show_printer_server, "printers", "mach_id", 1);
dabf20aa 2636 generic_delete(sq2, show_printer_spool, "printers", "rm", 1);
2637 generic_delete(sq3, show_printer_quota, "printers", "rq", 1);
2638 generic_fix(sq4, show_printer_ac, "Clear", fix_printer_ac, 1);
2639 generic_fix(sq5, show_printer_lpc_acl, "Clear", fix_printer_lpc_acl, 1);
fe0a844a 2640
8ef54684 2641 dprintf("Checking printservers...\n");
fe0a844a 2642 hash_step(printservers, check_ps, NULL);
cb884d06 2643
8ef54684 2644 dprintf("Checking containers...\n");
cb884d06 2645 hash_step(containers, check_container, NULL);
2646
8ef54684 2647 dprintf("Checking mcntmap...\n");
cb884d06 2648 sq1 = sq_create();
2649 sq2 = sq_create();
2650 EXEC SQL DECLARE csr_mcntmap CURSOR FOR
2651 SELECT mach_id, cnt_id FROM mcntmap;
2652 EXEC SQL OPEN csr_mcntmap;
2653 while (1)
2654 {
2655 EXEC SQL BEGIN DECLARE SECTION;
2656 int mach_id, cnt_id;
2657 EXEC SQL END DECLARE SECTION;
2658
2659 EXEC SQL FETCH csr_mcntmap INTO :mach_id, :cnt_id;
2660 if (sqlca.sqlcode)
2661 break;
2662
2663 if (!(m = hash_lookup(machines, mach_id)))
2664 sq_save_unique_data(sq1, (void *)mach_id);
2665 else if (!hash_lookup(containers, cnt_id))
2666 sq_save_unique_data(sq2, (void *)cnt_id);
2667 }
2668 EXEC SQL CLOSE csr_mcntmap;
2669 generic_delete(sq1, show_mcntmap_mach, "mcntmap", "mach_id", 1);
2670 generic_delete(sq2, show_mcntmap_cnt, "mcntmap", "cnt_id", 1);
2671
ab05f33a 2672}
c96b70a5 2673
This page took 0.695233 seconds and 5 git commands to generate.