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