]> andersk Git - moira.git/blame - dbck/phase1.qc
changed exit/cleanup code, interrupt handler, & added tblstat modtime
[moira.git] / dbck / phase1.qc
CommitLineData
d2543f8c 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
12show_user_id(u)
13struct user *u;
14{
15 printf("User %s (%s, status %d) has duplicate ID\n",
16 u->login, u->fullname, u->status);
17 return(0);
18}
19
20handle_duplicate_logins(sq)
21struct save_queue *sq;
22{
23 struct user *u, *uu, *tmp;
24
25 uu = (struct user *)0;
26 while (sq_get_data(sq, &u)) {
27 if (!strcmp(u->login, uu->login)) {
28 if (uu->status == 1 || u->status == 0) {
29 tmp = u;
30 u = uu;
31 uu = tmp;
32 }
33 printf("User %s (%s, status %d) and\n",
34 u->login, u->fullname, u->status);
35 printf("User %s (%s, status %d) have duplicate logins\n",
36 uu->login, uu->fullname, uu->status);
37 if (!strcmp(u->fullname, uu->fullname) &&
38 single_fix("Delete the second one")) {
39 single_delete("users", "users_id", uu->users_id);
40 } else if (single_fix("Unregister the second one"))
41## {
42## int id = uu->users_id, rowcount;
43
44## replace users (login = "#"+text(users.uid), status = 0)
45## where users.users_id = id
46## inquire_equel(rowcount = "rowcount")
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 } else {
53 uu = u;
54 }
55 }
56}
57
58fix_user_id(u)
59struct user *u;
60{
61 u->users_id = generic_fix_id("users", "users_id", "login",
62 u->users_id, u->login);
63}
64
65
66cant_fix(id)
67int id;
68{
69 printf("Sorry, don't know how to fix that\n");
70}
71
72show_mach_id(m)
73struct machine *m;
74{
75 printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id);
76 return(0);
77}
78
79show_mach_name(m)
80struct machine *m;
81{
82 printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id);
83 return(0);
84}
85
86fix_mach_id(m)
87struct machine *m;
88{
89 m->mach_id = generic_fix_id("machine", "mach_id", "name",
90 m->mach_id, m->name);
91}
92
93show_clu_id(c)
94struct cluster *c;
95{
96 printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id);
97 return(0);
98}
99
100show_clu_name(c)
101struct cluster *c;
102{
103 printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id);
104 return(0);
105}
106
107fix_clu_id(c)
108struct cluster *c;
109{
110 c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name);
111}
112
113show_list_id(l)
114struct list *l;
115{
116 printf("List %s has duplicate ID %d\n", l->name, l->list_id);
117 return(0);
118}
119
120show_list_name(l)
121struct list *l;
122{
123 printf("List %s (%d) has duplicate name\n", l->name, l->list_id);
124 return(0);
125}
126
127fix_list_id(l)
128struct list *l;
129{
130 l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name);
131}
132
133show_fs_id(f)
134struct filesys *f;
135{
136 printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id);
137 return(0);
138}
139
140fix_fs_id(f)
141struct filesys *f;
142{
143 f->filsys_id = generic_fix_id("filesys", "filsys_id", "label",
144 f->filsys_id, f->name);
145}
146
147
148show_np_id(n)
149struct nfsphys *n;
150{
151 printf("NfsPhys %s:%s has duplicate ID %d\n",
152 ((struct machine *)hash_lookup(machines, n->mach_id))->name,
153 n->dir, n->nfsphys_id);
154 return(0);
155}
156
157fix_np_id(n)
158struct nfsphys *n;
159{
160 n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir",
161 n->nfsphys_id, n->dir);
162}
163
164show_str_id(s)
165struct string *s;
166{
167 printf("String %s has duplicate ID %d\n", s->name, s->string_id);
168 return(0);
169}
170
171
172phase1()
173##{
174## char name[33], name1[33], last[17], first[17], buf[257];
175## int id, id2, id3, aid, aid2, status;
176 struct save_queue *sq;
177 struct user *u;
178 struct machine *m;
179 struct list *l;
180 struct cluster *c;
181 struct string *s;
182 struct filesys *f;
183 struct nfsphys *n;
184
185 printf("Phase 1 - Looking for duplicates\n");
186
187 dprintf("Loading users...\n");
188 sq = sq_create();
189 users = create_hash(10000);
190## range of u is users
191## retrieve (id = u.users_id, name = u.login, last = u.#last,
192## first = u.#first, status = u.#status, buf = u.potype,
193## id2 = u.pop_id, id3 = u.box_id) {
194 u = (struct user *) malloc(sizeof(struct user));
195 strcpy(u->login, strtrim(name));
196 u->potype = buf[0];
197 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
198 u->fullname = strsave(buf);
199 u->status = status;
200 u->users_id = id;
201 switch (u->potype) {
202 case 'P':
203 u->pobox_id = id2;
204 break;
205 case 'S':
206 u->pobox_id = id3;
207 break;
208 default:
209 u->pobox_id = 0;
210 }
211 if (hash_store(users, id, u)) {
212 sq_save_data(sq, hash_lookup(users, id));
213 sq_save_data(sq, u);
214 }
215## }
216 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
217
218 if (!fast) {
219 sq = sq_create();
220## retrieve (id = u.users_id)
221## where u.login = users.login and u.tid != users.tid {
222 sq_save_data(sq, hash_lookup(users, id));
223## }
224 handle_duplicate_logins(sq);
225 }
226
227 dprintf("Loading machines...\n");
228 machines = create_hash(1000);
229 sq = sq_create();
230## range of m is machine
231## retrieve (id = m.mach_id, name = m.#name) {
232 m = (struct machine *) malloc(sizeof(struct machine));
233 strcpy(m->name, strtrim(name));
234 m->mach_id = id;
235 m->clucount = 0;
236 if (hash_store(machines, id, m)) {
237 sq_save_data(sq, hash_lookup(machines, id));
238 sq_save_data(sq, m);
239 }
240## }
241 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
242
243 if (!fast) {
244 sq = sq_create();
245## retrieve (id = m.mach_id)
246## where m.#name = machine.#name and m.tid != machine.tid {
247 sq_save_data(sq, hash_lookup(machines, id));
248## }
249 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
250 }
251
252 dprintf("Loading clusters...\n");
253 sq = sq_create();
254 clusters = create_hash(100);
255## range of c is cluster
256## retrieve (id = cluster.clu_id, name = cluster.#name) {
257 c = (struct cluster *) malloc(sizeof(struct cluster));
258 strcpy(c->name, strtrim(name));
259 c->clu_id = id;
260 if (hash_store(clusters, id, c)) {
261 sq_save_data(sq, hash_lookup(clusters, id));
262 sq_save_data(sq, c);
263 }
264## }
265 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
266
267 if (!fast) {
268 sq = sq_create();
269## retrieve (id = c.clu_id)
270## where c.#name = cluster.#name and c.tid != cluster.tid {
271 sq_save_data(sq, hash_lookup(clusters, id));
272## }
273 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
274 }
275
276 dprintf("Loading lists...\n");
277 sq = sq_create();
278 lists = create_hash(10000);
279## range of l is list
280## retrieve (id = l.list_id, name = l.#name,
281## aid = l.acl_id, buf = l.acl_type) {
282 l = (struct list *) malloc(sizeof(struct list));
283 strcpy(l->name, strtrim(name));
284 l->acl_type = buf[0];
285 l->acl_id = aid;
286 l->list_id = id;
287 l->members = 0;
288 if (hash_store(lists, id, l)) {
289 sq_save_data(sq, hash_lookup(lists, id));
290 sq_save_data(sq, l);
291 }
292## }
293 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
294
295 if (!fast) {
296 sq = sq_create();
297## retrieve (id = l.list_id)
298## where l.#name = list.#name and l.tid != list.tid {
299 sq_save_data(sq, hash_lookup(lists, id));
300## }
301 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
302 }
303
304 dprintf("Loading filesys...\n");
305 sq = sq_create();
306 filesys = create_hash(10000);
307## retrieve (id = filesys.filsys_id, name = filesys.label, aid = filesys.owner,
308## aid2 = filesys.owners, id2 = filesys.phys_id,
309## id3 = filesys.mach_id, buf = filesys.type,
310## name1 = filesys.#name) {
311 f = (struct filesys *) malloc(sizeof(struct filesys));
312 strcpy(f->name, strtrim(name));
313 strcpy(f->dir, strtrim(name1));
314 f->filsys_id = id;
315 f->owner = aid;
316 f->owners = aid2;
317 f->phys_id = id2;
318 f->mach_id = id3;
319 f->type = buf[0];
320 if (hash_store(filesys, id, f)) {
321 sq_save_data(sq, hash_lookup(filesys, id));
322 sq_save_data(sq, f);
323 }
324## }
325 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
326
327 dprintf("Loading nfsphys...\n");
328 sq = sq_create();
329 nfsphys = create_hash(500);
330## retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
331## id2 = nfsphys.mach_id, id3 = nfsphys.allocated) {
332 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
333 strcpy(n->dir, strtrim(name));
334 n->mach_id = id2;
335 n->nfsphys_id = id;
336 n->allocated = id3;
337 n->count = 0;
338 if (hash_store(nfsphys, id, n)) {
339 sq_save_data(sq, hash_lookup(nfsphys, id));
340 sq_save_data(sq, n);
341 }
342## }
343 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
344
345 dprintf("Loading strings...\n");
346 sq = sq_create();
347 strings = create_hash(5000);
348## range of s is strings
349## retrieve (id = s.string_id, buf = s.string) {
350 s = (struct string *) malloc(sizeof(struct string));
351 s->name = strsave(strtrim(buf));
352 s->string_id = id;
353 s->refc = 0;
354 if (hash_store(strings, id, s)) {
355 sq_save_data(sq, hash_lookup(strings, id));
356 sq_save_data(sq, s);
357 }
358## }
359 generic_delete(sq, show_str_id, "strings", "string_id", 0);
360
361 if (!fast) {
362## retrieve (id = s.string_id, buf = s.string)
363## where s.string = strings.string and s.tid != strings.tid {
364 printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
365## }
366 }
367##}
368
This page took 0.243018 seconds and 5 git commands to generate.