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