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