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