]> andersk Git - moira.git/blob - dbck/phase4.pc
Remove `delete_user_by_uid' since it's never been used in any logs we have,
[moira.git] / dbck / phase4.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 <moira.h>
10 #include "dbck.h"
11 EXEC SQL INCLUDE sqlca;
12
13 static char phase4_qc_rcsid[] = "$Header$";
14
15 EXEC SQL WHENEVER SQLERROR DO dbmserr();
16
17 count_boxes(id, u, boxes)
18 int id;
19 struct user *u;
20 struct hash *boxes;
21 {
22     int i;
23
24     if (u->potype == 'P') {
25       if (i = (int) hash_lookup(boxes, u->pobox_id)) {
26           if( hash_store(boxes, u->pobox_id, i+1) == -1 ) {
27             out_of_mem("storing poboxes in hash table");
28           }
29       } else {
30           printf("User %s(%s) has pobox on non-POP server %d\n",
31                  u->fullname, u->login, u->pobox_id);
32           printf("Not fixing this error\n");
33       }
34     }
35 }
36
37
38 check_box_counts(id, cnt, counts)
39 EXEC SQL BEGIN DECLARE SECTION; 
40 int id, cnt;
41 EXEC SQL END DECLARE SECTION; 
42 struct hash *counts;
43 {
44     EXEC SQL BEGIN DECLARE SECTION; 
45     int oldval, rowcount;
46     EXEC SQL END DECLARE SECTION; 
47
48     oldval = (int) hash_lookup(counts, id);
49     cnt--;
50     if (oldval != cnt) {
51         printf("Count wrong on POBox machine %s; is %d in db, counted %d\n",
52                ((struct machine *) hash_lookup(machines, id))->name,
53                oldval, cnt);
54         if (single_fix("Update", 1)) {
55             EXEC SQL UPDATE serverhosts SET value1 = :cnt
56                 WHERE service='POP' AND mach_id = :id;
57             rowcount = sqlca.sqlerrd[2];
58             if (rowcount > 0)
59               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
60             else
61               printf("Not fixed\n");
62             modified("serverhosts");
63         }
64     }
65 }
66
67
68 check_nfs_counts(id, n, hint)
69 EXEC SQL BEGIN DECLARE SECTION; 
70 int id, hint;
71 EXEC SQL END DECLARE SECTION; 
72 struct nfsphys *n;
73 {
74     EXEC SQL BEGIN DECLARE SECTION; 
75     int val, rowcount;
76     EXEC SQL END DECLARE SECTION; 
77
78     val = n->count;
79     if (n->allocated != val) {
80         printf("Count wrong on NFSphys %s:%s; is %d in db, counted %d\n",
81                ((struct machine *) hash_lookup(machines, n->mach_id))->name,
82                n->dir, n->allocated, val);
83         if (single_fix("Update", 1)) {
84             EXEC SQL UPDATE nfsphys SET allocated = :val 
85                 WHERE nfsphys_id = :id;
86             rowcount = sqlca.sqlerrd[2];
87             if (rowcount > 0)
88               printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies");
89             else
90               printf("Not fixed\n");
91             modified("nfsphys");
92         }
93     }
94 }
95
96
97 phase4()
98 {
99     struct hash *boxes, *counts;
100     EXEC SQL BEGIN DECLARE SECTION; 
101     int id, cnt;
102     EXEC SQL END DECLARE SECTION; 
103
104     printf("Phase 4 - Checking counts\n");
105
106     dprintf("Doing POBoxes...\n");
107     boxes = create_hash(10);
108     counts = create_hash(10);
109     EXEC SQL DECLARE csr401 CURSOR FOR
110         SELECT mach_id, value1 FROM serverhosts
111             WHERE service='POP';
112     EXEC SQL OPEN csr401;
113     while(1) {
114         EXEC SQL FETCH csr401 INTO :id, :cnt;
115         if (sqlca.sqlcode != 0) break;
116         
117         if( hash_store(boxes, id, 1) == -1 ) {
118             out_of_mem("storing poboxes");
119         }
120         if( hash_store(counts, id, cnt) == -1 ) {
121             out_of_mem("storing pobox counts? in hash table");
122         }
123     }
124     EXEC SQL CLOSE csr401; 
125     hash_step(users, count_boxes, boxes);
126     hash_step(boxes, check_box_counts, counts);
127
128     dprintf("Doing NFSphys...\n");
129     hash_step(nfsphys, check_nfs_counts, 0);
130 }
131
132
133 count_only_setup()
134 {
135     EXEC SQL BEGIN DECLARE SECTION; 
136     int id, status, id2, id3;
137     char name[33], last[17], first[17], buf[257];
138     EXEC SQL END DECLARE SECTION; 
139     struct save_queue *sq;
140     struct user *u;
141     struct nfsphys *n;
142     struct machine *m;
143
144     dprintf("Loading users...\n");
145     users = create_hash(30000);
146     EXEC SQL DECLARE csr402 CURSOR FOR
147         SELECT users_id, login, last, first, status, 
148                potype, pop_id, box_id FROM users
149             WHERE potype='POP';
150     EXEC SQL OPEN csr402;
151     while(1) {
152         EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status, 
153             :buf, :id2, :id3;
154         if (sqlca.sqlcode != 0) break;
155
156         u = (struct user *) malloc(sizeof(struct user));
157         if (u == NULL)
158           out_of_mem("storing users");
159         strcpy(u->login, strtrim(name));
160         u->potype = buf[0];
161         sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
162         u->fullname = strsave(buf);
163         u->status = status;
164         u->users_id = id;
165         switch (u->potype) {
166         case 'P':
167             u->pobox_id = id2;
168             break;
169         case 'S':
170             u->pobox_id = id3;
171             break;
172         default:
173             u->pobox_id = 0;
174         }
175         if( hash_store(users, id, u) == -1 ) {
176           out_of_mem("storing users in hash table");
177         }
178     }
179     EXEC SQL CLOSE csr402; 
180
181     dprintf("Loading machines...\n");
182     machines = create_hash(20000);
183     EXEC SQL DECLARE csr403 CURSOR FOR
184         SELECT mach_id, name FROM machine;
185     EXEC SQL OPEN csr403;
186     while(1) {
187         EXEC SQL FETCH csr403 INTO :id, :name;
188         if (sqlca.sqlcode != 0) break;
189
190         m = (struct machine *) malloc(sizeof(struct machine));
191         if (m == NULL)
192           out_of_mem("storing machines");
193         strcpy(m->name, strtrim(name));
194         m->mach_id = id;
195         if( hash_store(machines, id, m) == -1 ) {
196           out_of_mem("storing users in hash table");
197         }
198     }
199     EXEC SQL CLOSE csr403; 
200
201     dprintf("Loading nfsphys...\n");
202     nfsphys = create_hash(500);
203     EXEC SQL DECLARE csr404 CURSOR FOR
204         SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys;
205     EXEC SQL OPEN csr404;
206     while(1) {
207         EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3;
208         if (sqlca.sqlcode != 0) break;
209
210         n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
211         if (n == NULL)
212           out_of_mem("storing nfsphys");
213         strcpy(n->dir, strtrim(name));
214         n->mach_id = id2;
215         n->nfsphys_id = id;
216         n->allocated = id3;
217         n->count = 0;
218         if( hash_store(nfsphys, id, n) == -1 ) {
219           out_of_mem("storing nfsphys in hash table");
220         }
221         }
222     EXEC SQL CLOSE csr404; 
223
224     dprintf("Counting quotas...\n");
225     EXEC SQL DECLARE csr405 CURSOR FOR
226         SELECT phys_id, quota FROM quota;
227     EXEC SQL OPEN csr405;
228     while(1) {
229         EXEC SQL FETCH csr405 INTO :id, :id2;
230         if (sqlca.sqlcode != 0) break;
231         
232         if (n = (struct nfsphys  *) hash_lookup(nfsphys, id)) {
233             n->count += id2;
234         }
235     }
236     EXEC SQL CLOSE csr405; 
237 }
This page took 0.062923 seconds and 5 git commands to generate.