]> andersk Git - moira.git/blob - dbck/phase2.qc
fixed preen mode to not ask any questions.
[moira.git] / dbck / phase2.qc
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 <sms.h>
11 #include "dbck.h"
12
13 static char phase2_qc_rcsid[] = "$Header$";
14
15
16 show_mcm_mach(id)
17 int id;
18 ##{
19 ##  int iid = id, found = 1;
20 ##  char name[33];
21
22 ##  retrieve (name = cluster.#name) where cluster.clu_id = mcmap.clu_id
23 ##      and mcmap.mach_id = iid {
24       strtrim(name);
25       found = 0;
26       printf("Cluster %s, non-existant machine %d in cluster map\n", name, id);
27 ##  }
28     return(found);
29 ##}
30
31 show_mcm_clu(id)
32 int id;
33 ##{
34 ##  int iid = id, found = 1;
35 ##  char name[33];
36
37 ##  retrieve (name = machine.#name) where machine.mach_id = mcmap.mach_id
38 ##      and mcmap.clu_id = iid {
39       strtrim(name);
40       found = 0;
41       printf("Machine %s, non-existant cluster %d in cluster map\n", name, id);
42 ##  }
43     return(found);
44 ##}
45
46 pobox_check(id, u, hint)
47 int id;
48 struct user *u;
49 int hint;
50 {
51     switch (u->potype) {
52     case 'P':
53         if (!hash_lookup(machines, u->pobox_id)) {
54             printf("User %s(%s) has P.O.Box on non-existant machine %d\n",
55                    u->login, u->fullname, u->pobox_id);
56             if (single_fix("Delete", 0)) {
57                 remove_pobox(u->users_id);
58                 u->potype = 'N';
59             }
60         }
61         break;
62     case 'S':
63         if (!string_check(u->pobox_id)) {
64             printf("User %s(%s) has P.O.Box with non-existant string %d\n",
65                    u->login, u->fullname, u->pobox_id);
66             if (single_fix("Delete", 0)) {
67                 remove_pobox(u->users_id);
68                 u->potype = 'N';
69             }
70         }
71         break;
72     default:
73         ;
74     }
75 }
76
77
78 remove_pobox(id)
79 int id;
80 ##{
81 ##  int rowcount, iid = id;
82 ##  replace users (potype = "NONE") where users.users_id = iid
83 ##  inquire_equel(rowcount = "rowcount")
84     if (rowcount > 0)
85       printf("%d entr%s removed\n", rowcount, rowcount==1?"y":"ies");
86     else
87       printf("Not removed\n");
88     modified("users");
89 ##}
90
91 show_svc(id)
92 int id;
93 ##{
94 ##  int iid = id, found = 1;
95 ##  char label[17], data[33];
96
97 ##  retrieve (label = svc.serv_label, data = svc.serv_cluster) 
98 ##      where svc.clu_id = iid {
99       strtrim(label);
100       strtrim(data);
101       found = 0;
102       printf("Cluster data [%s] %s for non-existant cluster %d\n",
103              label, data, id);
104 ##  }
105     return(found);
106 ##}
107
108 list_check(id, l, hint)
109 int id;
110 struct list *l;
111 int hint;
112 {
113     switch (l->acl_type) {
114     case 'L':
115         if (!hash_lookup(lists, l->acl_id)) {
116             printf("List %s has bad LIST acl %d\n", l->name, l->acl_id);
117             if (single_fix("Patch", 1)) {
118                 fix_list_acl(l->list_id);
119             }
120         }
121         break;
122     case 'U':
123         if (!hash_lookup(users, l->acl_id)) {
124             printf("List %s has bad USER acl %d\n", l->name, l->acl_id);
125             if (single_fix("Patch", 1)) {
126                 fix_list_acl(l->list_id);
127             }
128         }
129         break;
130     }
131 }
132
133 fix_list_acl(id)
134 int id;
135 ##{
136 ##  int rowcount, iid = id;
137 ##  replace list (acl_id = iid, acl_type = "LIST") where list.list_id = iid
138 ##  inquire_equel(rowcount = "rowcount")
139     if (rowcount > 0)
140       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
141     else
142       printf("Not fixed\n");
143     modified("list");
144 ##}
145
146
147 show_member_list(id)
148 int id;
149 ##{
150 ##  int mid, iid = id, found = 1;
151 ##  char mtype[9], *name;
152
153 ##  retrieve (mtype = member.member_type, mid = member.member_id)
154 ##      where member.list_id = iid {
155       strtrim(mtype);
156       found = 0;
157       if (mtype[0] == 'L')
158         strcpy(name, ((struct list *) hash_lookup(lists, mid))->name);
159       else if (mtype[0] == 'U')
160         strcpy(name, ((struct user *) hash_lookup(users, mid))->login);
161       else if (mtype[0] == 'S')
162         strcpy(name, ((struct string *) hash_lookup(strings, mid))->name);
163       printf("Non-existant list %d has member %s %s\n", iid, mtype, name);
164 ##  }
165     return(found);
166 ##}
167
168 show_mem_user(id)
169 int id;
170 ##{
171 ##  int lid, iid = id, found = 1;
172 ##  char name[33];
173
174 ##  retrieve (lid = members.list_id)
175 ##      where members.member_id = iid and members.member_type = "USER" {
176       found = 0;
177       printf("List %s has non-existant user member, id %d\n",
178              ((struct list *)hash_lookup(lists, lid))->name, iid);
179 ##  }
180     return(found);
181 ##}
182
183 show_mem_list(id)
184 int id;
185 ##{
186 ##  int lid, iid = id, found = 1;
187 ##  char name[33];
188
189 ##  retrieve (lid = members.list_id)
190 ##      where members.member_id = iid and members.member_type = "LIST" {
191       found = 0;
192       printf("List %s has non-existant list member, id %d\n",
193              ((struct list *)hash_lookup(lists, lid))->name, iid);
194 ##  }
195     return(found);
196 ##}
197
198 show_mem_str(id)
199 int id;
200 ##{
201 ##  int lid, iid = id, found = 1;
202 ##  char name[33];
203
204 ##  retrieve (lid = members.list_id)
205 ##      where members.member_id = iid and members.member_type = "STRING" {
206       found = 0;
207       printf("List %s has non-existant string member, id %d\n",
208              ((struct list *)hash_lookup(lists, lid))->name, iid);
209 ##  }
210     return(found);
211 ##}
212
213
214 ##del_mem_user(id)
215 ##int id;
216 ##{
217 ##  int rowcount;
218
219 ##  delete members where members.member_type = "USER" and
220 ##      members.member_id = id
221 ##  inquire_equel(rowcount = "rowcount");
222     if (rowcount > 0)
223       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
224     else
225       printf("Not deleted\n");
226     modified("members");
227 ##}
228
229 ##del_mem_list(id)
230 ##int id;
231 ##{
232 ##  int rowcount;
233
234 ##  delete members where members.member_type = "LIST" and
235 ##      members.member_id = id
236 ##  inquire_equel(rowcount = "rowcount");
237     if (rowcount > 0)
238       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
239     else
240       printf("Not deleted\n");
241     modified("members");
242 ##}
243
244 ##del_mem_str(id)
245 ##int id;
246 ##{
247 ##  int rowcount;
248
249 ##  delete members where members.member_type = "STRING" and
250 ##      members.member_id = id
251 ##  inquire_equel(rowcount = "rowcount");
252     if (rowcount > 0)
253       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
254     else
255       printf("Not deleted\n");
256     modified("members");
257 ##}
258
259
260 ##show_sh(id)
261 ##int id;
262 ##{
263 ##  char name[33];
264     int found = 1;
265
266 ##  retrieve (name = serverhosts.service) where serverhosts.mach_id = id {
267       found = 0;
268       printf("ServerHost entry for service %s non-existant host %d\n",
269              name, id);
270 ##  }
271     return(found);
272 ##}
273
274 ##del_sh_mach(id)
275 ##int id;
276 ##{
277 ##  int rowcount;
278
279 ##  delete serverhosts where serverhosts.mach_id = id
280 ##  inquire_equel(rowcount = "rowcount");
281     if (rowcount > 0)
282       printf("%d entr%s deleted\n", rowcount, rowcount==1?"y":"ies");
283     else
284       printf("Not deleted\n");
285     modified("serverhosts");
286 ##}
287
288
289 static int fnchecklen;
290
291 fsmatch(id, n, f)
292 int id;
293 struct nfsphys *n;
294 struct filesys *f;
295 {
296     if (n->mach_id == f->mach_id &&
297         !strncmp(f->dir, n->dir, strlen(n->dir)) &&
298         strlen(n->dir) > fnchecklen) {
299         f->phys_id = id;
300         fnchecklen = strlen(n->dir);
301     }
302 }
303
304
305 ##check_fs(id, f, hint)
306 ##int id;
307 register struct filesys *f;
308 int hint;
309 ##{
310 ##  int id1, id2, id3, rowcount;
311 ##  char *dir;
312     struct nfsphys *n;
313     struct machine *m;
314
315     if (f->type == 'N' || f->type == 'R') {
316         if (!hash_lookup(machines, f->mach_id)) {
317             printf("Filesys %s with bad machine %d\n", f->name, f->mach_id);
318             if (single_fix("Fix", 0)) {
319 ##              replace filesys (mach_id = 0) where filesys.filsys_id = id
320 ##              inquire_equel(rowcount = "rowcount")
321                 if (rowcount > 0)
322                   printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
323                 else
324                   printf("Not fixed\n");
325                 modified("filesys");
326                 f->mach_id = 0;
327             }
328         }
329         if (!hash_lookup(users, f->owner)) {
330             printf("Filesys %s with bad owning user %d\n", f->name, f->owner);
331             if (single_fix("Fix", 1)) {
332                 zero_fix("filesys", "owner", "filsys_id", f->filsys_id);
333                 f->owner = 0;
334             }
335         }
336         if (!hash_lookup(lists, f->owners)) {
337             printf("Filesys %s with bad owning group %d\n", f->name, f->owners);
338             if (single_fix("Fix", 1)) {
339                 zero_fix("filesys", "owners", "filsys_id", f->filsys_id);
340                 f->owners = 0;
341             }
342         }
343     }
344
345     if (f->type == 'N') {
346         if (!hash_lookup(nfsphys, f->phys_id)) {
347             m = (struct machine *)hash_lookup(machines, f->mach_id);
348             printf("Filesys %s with bad phys_id %d\n", f->name, f->phys_id);
349             if (single_fix("Fix", 1)) {
350                 fnchecklen = 0;
351                 hash_step(nfsphys, fsmatch, f);
352                 if (fnchecklen != 0) {
353                   id1 = f->phys_id;
354                   id2 = f->filsys_id;
355                   id3 = f->mach_id;
356 ##                replace filesys (phys_id = id1) where filesys.filsys_id = id2
357 ##                inquire_equel(rowcount = "rowcount")
358                   if (rowcount > 0)
359                     printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
360                   else
361                     printf("Not fixed\n");
362                   modified("filesys");
363                 } else {
364                     printf("No NFSphys exsits for %s:%s\n", m->name, f->dir);
365                     if (single_fix("Create", 0)) {
366                         dir = f->dir;
367                         id1 = f->phys_id;
368                         id2 = f->filsys_id;
369                         id3 = f->mach_id;
370                         if (set_next_object_id("nfsphys_id", "nfsphys") !=
371                                 SMS_SUCCESS) {
372                             printf("Unable to assign unique ID\n");
373                             return;
374                         }
375 ##                      retrieve (id1 = values.value)
376 ##                        where values.name = "nfsphys_id"
377 ##                      inquire_equel(rowcount = "rowcount")
378                         if (rowcount != 1) {
379                             printf("Unable to retrieve unique ID\n");
380                             return;
381                         }
382 ##                      append nfsphys (nfsphys_id = id1, mach_id = id3,
383 ##                                      device = "???", #dir = dir, status = 0,
384 ##                                      allocated = 0, size = 0,
385 ##                                      modtime = "now", modby = 0,
386 ##                                      modwith = "dbck")
387 ##                      inquire_equel(rowcount = "rowcount")
388                         if (rowcount > 0)
389                           printf("%d entr%s created\n", rowcount,
390                                  rowcount==1?"y":"ies");
391                         else
392                           printf("Not created\n");
393                         modified("nfsphys");
394                         n = (struct nfsphys *)malloc(sizeof(struct nfsphys));
395                         strcpy(n->dir, dir);
396                         n->mach_id = id3;
397                         n->nfsphys_id = id1;
398                         n->allocated = 0;
399                         n->count = 0;
400                         hash_store(nfsphys, id1, n);
401 ##                      replace filesys (phys_id = id1)
402 ##                        where filesys.filsys_id = id2
403 ##                      inquire_equel(rowcount = "rowcount")
404                         if (rowcount > 0)
405                           printf("%d filesys entr%s fixed\n", rowcount,
406                                  rowcount==1?"y":"ies");
407                         else
408                           printf("Not fixed\n");
409                         modified("filesys");
410                     }
411                 }
412             }
413         }
414     }
415 ##}
416
417
418 check_nfsphys(id, n, hint)
419 int id;
420 struct nfsphys *n;
421 int hint;
422 {
423     if (!hash_lookup(machines, n->mach_id)) {
424         printf("NFSphys %d(%s) on non-existant machine %d\n",
425                id, n->dir, n->mach_id);
426         if (single_fix("Delete", 0))
427           single_delete("nfsphys", "nfsphys_id", id);
428     }
429 }
430
431 ##show_quota_nouser(id)
432 ##int id;
433 ##{
434 ##  int id1, found = 1;
435
436 ##  retrieve (id1 = nfsquota.filsys_id) where nfsquota.users_id = id {
437       found = 0;
438       printf("NFSquota on fs %d for non-existant user %d\n", id1, id);
439 ##  }
440     return(found);
441 ##}
442
443 fix_quota_nouser(id)
444 {
445     single_delete("nfsquota", "users_id", id);
446 }
447
448 ##show_quota_nofs(id)
449 ##int id;
450 ##{
451 ##  int id1, found = 1;
452     struct user *u;
453
454 ##  retrieve (id1 = nfsquota.users_id) where nfsquota.filsys_id = id {
455       u = (struct user *)hash_lookup(users, id1);
456       found = 0;
457       printf("NFSquota for user %s on non-existant filesys %d\n", u->login, id);
458 ##  }
459     return(found);
460 ##}
461
462 fix_quota_nofs(id)
463 {
464     single_delete("nfsquota", "filsys_id", id);
465 }
466
467 ##show_quota_wrongpid(id)
468 ##int id;
469 ##{
470 ##  int id1, found = 1;
471     struct user *u;
472     struct filesys *f;
473
474     f = (struct filesys *)hash_lookup(filesys, id);
475 ##  retrieve (id1 = nfsquota.users_id) where nfsquota.filsys_id = id {
476       u = (struct user *)hash_lookup(users, id1);
477       found = 0;
478       printf("NFSquota for user %s on filesys %s has wrong phys_id %d\n",
479              u->login, f->name, id);
480 ##  }
481     return(found);
482 ##}
483
484 ##fix_quota_physid(id)
485 ##int id;
486 ##{
487 ##  int rowcount, id1;
488
489     id1 = ((struct filesys *)hash_lookup(filesys, id))->phys_id;
490 ##  replace nfsquota (phys_id = id1) where nfsquota.filsys_id = id and
491 ##      nfsquota.phys_id != id1 
492 ##  inquire_equel(rowcount = "rowcount")
493     if (rowcount > 0)
494       printf("%d entr%s fixed\n",rowcount, rowcount==1?"y":"ies");
495     else
496       printf("Not fixed\n");
497     modified("nfsquota");
498 ##}
499
500 ##show_srv_user(id)
501 ##int id;
502 ##{
503 ##  char name[33];
504     int found = 1;
505
506 ##  retrieve (name = s.#name) where s.acl_type = "USER" and s.acl_id = id {
507         strtrim(name);
508         printf("Service %s has acl non-existant user %d\n", name, id);
509         found = 0;
510 ##  }
511     return(found);
512 ##}
513
514 ##show_srv_list(id)
515 ##int id;
516 ##{
517 ##  char name[33];
518     int found = 1;
519
520 ##  retrieve (name = s.#name) where s.acl_type = "LIST" and s.acl_id = id {
521         strtrim(name);
522         printf("Service %s has acl non-existant list %d\n", name, id);
523         found = 0;
524 ##  }
525     return(found);
526 ##}
527
528 ##zero_srv_user(id)
529 ##int id;
530 ##{
531 ##  int rowcount;
532
533 ##  replace servers (acl_id = 0) where servers.acl_id = id and
534 ##      servers.acl_type = "USER"
535 ##  inquire_equel(rowcount = "rowcount")
536     if (rowcount > 0)
537       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
538     else
539       printf("Not fixed\n");
540     modified("servers");
541 ##}
542
543 ##zero_srv_list(id)
544 ##int id;
545 ##{
546 ##  int rowcount;
547
548 ##  replace servers (acl_id = 0) where servers.acl_id = id and
549 ##      servers.acl_type = "LIST"
550 ##  inquire_equel(rowcount = "rowcount")
551     if (rowcount > 0)
552       printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
553     else
554       printf("Not fixed\n");
555     modified("servers");
556 ##}
557
558
559
560 phase2()
561 ##{
562 ##  int id1, id2, id3, id4, id5;
563 ##  char type[9], name[33];
564     struct save_queue *sq, *sq1, *sq2, *sq3, *sq4;
565     struct filesys *f;
566     struct list *l;
567     struct nfsphys *n;
568     struct machine *m;
569
570     printf("Phase 2 - Checking references\n");
571
572     dprintf("Checking users...\n");
573     hash_step(users, pobox_check, NULL);
574
575     dprintf("Checking mcmap...\n");
576     sq1 = sq_create();
577     sq2 = sq_create();
578 ##  retrieve (id1 = mcmap.mach_id, id2 = mcmap.clu_id) {
579         if (!(m = (struct machine *)hash_lookup(machines, id1)))
580           sq_save_unique_data(sq1, id1);
581         if (!hash_lookup(clusters, id2))
582           sq_save_unique_data(sq2, id2);
583         m->clucount++;
584 ##  }
585     generic_delete(sq1, show_mcm_mach, "mcmap", "mach_id", 1);
586     generic_delete(sq2, show_mcm_clu, "mcmap", "clu_id", 1);
587
588     dprintf("Checking service clusters...\n");
589     sq1 = sq_create();
590 ##  retrieve (id1 = svc.clu_id) {
591         if (!hash_lookup(clusters, id1))
592           sq_save_unique_data(sq1, id1);
593 ##  }
594     generic_delete(sq1, show_svc, "svc", "clu_id", 1);
595
596     dprintf("Checking lists...\n");
597     hash_step(lists, list_check, NULL);
598
599     dprintf("Checking members...\n");
600     sq1 = sq_create();
601     sq2 = sq_create();
602     sq3 = sq_create();
603     sq4 = sq_create();
604 ##  range of m is members
605 ##  retrieve (id1 = m.list_id, type = m.member_type, id2 = m.member_id) {
606         strtrim(type);
607         if ((l = (struct list *) hash_lookup(lists, id1)) == NULL)
608           sq_save_unique_data(sq1, id1);
609         l->members++;
610         if (!strcmp(type, "USER") && !hash_lookup(users, id2))
611           sq_save_unique_data(sq2, id2);
612         else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2))
613           sq_save_unique_data(sq3, id2);
614         else if (!strcmp(type, "STRING") && !string_check(id2))
615           sq_save_unique_data(sq4, id2);
616 ##  }
617     generic_delete(sq1, show_member_list, "members", "list_id", 1);
618     generic_fix(sq2, show_mem_user, "Delete", del_mem_user, 1);
619     generic_fix(sq3, show_mem_list, "Delete", del_mem_list, 1);
620     generic_fix(sq4, show_mem_str, "Delete", del_mem_str, 1);
621
622     dprintf("Checking servers...\n");
623     sq1 = sq_create();
624     sq2 = sq_create();
625 ##  range of s is servers
626 ##  retrieve (name = s.#name, type = s.acl_type, id1 = s.acl_id) {
627         strtrim(type);
628         if (!strcmp(type, "USER") && !hash_lookup(users, id1)) {
629             sq_save_data(sq1, id1);
630         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) {
631             sq_save_data(sq2, id1);
632         }
633 ##  }
634     generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1);
635     generic_fix(sq2, show_srv_list, "Fix", zero_srv_list, 1);
636
637     dprintf("Checking servershosts...\n");
638     sq = sq_create();
639 ##  retrieve (id1 = serverhosts.mach_id) {
640         if (!hash_lookup(machines, id1))
641           sq_save_data(sq, id1);
642 ##  }
643     generic_fix(sq, show_sh, "Delete", del_sh_mach, 0);
644
645     dprintf("Checking nfsphys...\n");
646     hash_step(nfsphys, check_nfsphys, NULL);
647
648     dprintf("Checking filesys...\n");
649     hash_step(filesys, check_fs, NULL);
650
651     dprintf("Checking nfsquota...\n");
652     sq1 = sq_create();
653     sq2 = sq_create();
654     sq3 = sq_create();
655 ##  retrieve (id1 = nfsquota.users_id, id2 = nfsquota.filsys_id,
656 ##            id3 = nfsquota.phys_id, id4 = nfsquota.quota) {
657         if (!hash_lookup(users, id1))
658           sq_save_data(sq1, id1);
659         else if (!(f = (struct filesys *) hash_lookup(filesys, id2)))
660           sq_save_data(sq2, id2);
661         else if (id3 != f->phys_id ||
662             ((n = (struct nfsphys*) hash_lookup(nfsphys, id3)) ==
663             (struct nfsphys *)NULL))
664           sq_save_data(sq3, id2);
665         else
666           n->count += id4;
667 ##  }
668     generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1);
669     generic_fix(sq2, show_quota_nofs, "Delete", fix_quota_nofs, 0);
670     generic_fix(sq3, show_quota_wrongpid, "Fix", fix_quota_physid, 1);
671
672     dprintf("Not checking zephyr.\n");
673
674     dprintf("Checking hostaccess...\n");
675 ##  range of h is hostaccess
676 ##  retrieve (id1 = h.mach_id, type = h.acl_type, id2 = h.acl_id) {
677         strtrim(type);
678         if (!hash_lookup(machines, id1)) {
679             printf("Hostaccess for non-existant host %d\n", id1);
680             printf("Not fixing this error\n");
681         }
682         if (!strcmp(type, "USER") && !hash_lookup(users, id2)) {
683             printf("Hostaccess for %d is non-existant user %d\n", id1, id2);
684             printf("Not fixing this error\n");
685         } else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) {
686             printf("Hostaccess for %d is non-existant list %d\n", id1, id2);
687             printf("Not fixing this error\n");
688         }
689 ##  }
690
691     dprintf("Checking capacls...\n");
692 ##  retrieve (id1 = capacls.list_id, name = capacls.tag) {
693         if (!hash_lookup(lists, id1)) {
694             printf("Capacl for %s is non-existant list %d\n", name, id1);
695             printf("Not fixing this error\n");
696         }
697 ##  }
698
699 ##}
700
This page took 0.160417 seconds and 5 git commands to generate.