]> andersk Git - moira.git/blob - dbck/phase4.qc
Initial revision
[moira.git] / dbck / phase4.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 "dbck.h"
10
11 static char phase4_qc_rcsid[] = "$Header$";
12
13
14 count_boxes(id, u, boxes)
15 int id;
16 struct user *u;
17 struct hash *boxes;
18 {
19     int i;
20
21     if (u->potype == 'P') {
22         if (i = (int) hash_lookup(boxes, u->pobox_id))
23           hash_store(boxes, u->pobox_id, i+1);
24         else {
25           printf("User %s(%s) has pobox on non-POP server %d\n",
26                  u->fullname, u->login, u->pobox_id);
27           printf("Not fixing this error\n");
28         }
29     }
30 }
31
32
33 ##check_box_counts(id, cnt, counts)
34 ##int id, cnt;
35 struct hash *counts;
36 ##{
37 ##  int oldval, rowcount;
38
39     oldval = (int) hash_lookup(counts, id);
40     cnt--;
41     if (oldval != cnt) {
42         printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
43                ((struct machine *) hash_lookup(machines, id))->name,
44                oldval, cnt);
45         if (single_fix("Update", 1)) {
46 ##          range of s is serverhosts
47 ##          replace s (value1 = cnt) where
48 ##              s.service = "POP" and s.mach_id = id
49 ##          inquire_equel(rowcount = "rowcount")
50             if (rowcount > 0)
51               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
52             else
53               printf("Not fixed\n");
54             modified("serverhosts");
55         }
56     }
57 ##}
58
59
60 ##check_nfs_counts(id, n, hint)
61 ##int id, hint;
62 struct nfsphys *n;
63 ##{
64 ##  int val, rowcount;
65
66     val = n->count;
67     if (n->allocated != val) {
68         printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
69                ((struct machine *) hash_lookup(machines, n->mach_id))->name,
70                n->dir, n->allocated, val);
71         if (single_fix("Update", 1)) {
72 ##          replace nfsphys (allocated = val) where nfsphys.nfsphys_id = id
73 ##          inquire_equel(rowcount = "rowcount")
74             if (rowcount > 0)
75               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
76             else
77               printf("Not fixed\n");
78             modified("nfsphys");
79         }
80     }
81 ##}
82
83
84 phase4()
85 ##{
86     struct hash *boxes, *counts;
87 ##  int id, cnt;
88
89     printf("Phase 4 - Checking counts\n");
90
91     dprintf("Doing POBoxes...\n");
92     boxes = create_hash(10);
93     counts = create_hash(10);
94 ##  retrieve (id = serverhosts.mach_id, cnt = serverhosts.value1)
95 ##      where serverhosts.service = "POP" {
96       hash_store(boxes, id, 1);
97       hash_store(counts, id, cnt);
98 ##  }
99     hash_step(users, count_boxes, boxes);
100     hash_step(boxes, check_box_counts, counts);
101
102     dprintf("Doing NFSphys...\n");
103     hash_step(nfsphys, check_nfs_counts, 0);
104 ##}
105
106
107 count_only_setup()
108 ##{
109 ##  int id, status, id2, id3;
110 ##  char name[33], last[17], first[17], buf[257];
111     struct save_queue *sq;
112     struct user *u;
113     struct nfsphys *n;
114     struct machine *m;
115
116     dprintf("Loading users...\n");
117     users = create_hash(10000);
118 ##  range of u is users
119 ##  retrieve (id = u.users_id, name = u.login, last = u.#last,
120 ##            first = u.#first, status = u.#status, buf = u.potype,
121 ##            id2 = u.pop_id, id3 = u.box_id) 
122 ##    where u.potype = "POP" {
123         u = (struct user *) malloc(sizeof(struct user));
124         strcpy(u->login, strtrim(name));
125         u->potype = buf[0];
126         sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
127         u->fullname = strsave(buf);
128         u->status = status;
129         u->users_id = id;
130         switch (u->potype) {
131         case 'P':
132             u->pobox_id = id2;
133             break;
134         case 'S':
135             u->pobox_id = id3;
136             break;
137         default:
138             u->pobox_id = 0;
139         }
140         hash_store(users, id, u);
141 ##  }
142
143     dprintf("Loading machines...\n");
144     machines = create_hash(1000);
145 ##  range of m is machine
146 ##  retrieve (id = m.mach_id, name = m.#name) {
147         m = (struct machine *) malloc(sizeof(struct machine));
148         strcpy(m->name, strtrim(name));
149         m->mach_id = id;
150         hash_store(machines, id, m);
151 ##  }
152
153     dprintf("Loading nfsphys...\n");
154     nfsphys = create_hash(500);
155 ##  retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
156 ##            id2 = nfsphys.mach_id, id3 = nfsphys.allocated) {
157         n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
158         strcpy(n->dir, strtrim(name));
159         n->mach_id = id2;
160         n->nfsphys_id = id;
161         n->allocated = id3;
162         n->count = 0;
163         hash_store(nfsphys, id, n);
164 ##  }
165
166     dprintf("Counting quotas...\n");
167 ##  retrieve (id = nfsquota.phys_id, id2 = nfsquota.quota) {
168         if (n = (struct nfsphys  *) hash_lookup(nfsphys, id)) {
169             n->count += id2;
170         }
171 ##  }
172 ##}
This page took 0.773452 seconds and 5 git commands to generate.