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