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