]> andersk Git - moira.git/blame - dbck/phase1.qc
string check user comments & signature
[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];
30ad4a19 179## int id, id2, id3, aid, aid2, status, sid, sid2, sid3, sid4, sid5;
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);
30ad4a19 208 string_check(0);
a3b4927d 209
d2543f8c 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,
a3b4927d 216## id2 = u.pop_id, id3 = u.box_id, sid = u.modby, sid2 = u.fmodby,
30ad4a19 217## sid3 = u.pmodby, sid4 = u.comment, sid5 = u.sigwho) {
d2543f8c 218 u = (struct user *) malloc(sizeof(struct user));
a3b4927d 219 if (u == NULL)
220 out_of_mem("storing users");
d2543f8c 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 }
a3b4927d 241 if (sid < 0)
242 string_check(-sid);
243 if (sid2 < 0)
244 string_check(-sid2);
245 if (sid3 < 0)
246 string_check(-sid3);
30ad4a19 247 if (sid4)
248 string_check(sid4);
249 if (sid5)
250 string_check(sid5);
d2543f8c 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
a3b4927d 267## retrieve (id = m.mach_id, name = m.#name, sid = m.modby) {
d2543f8c 268 m = (struct machine *) malloc(sizeof(struct machine));
a3b4927d 269 if (m == NULL)
270 out_of_mem("storing machines");
d2543f8c 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 }
a3b4927d 278 if (sid < 0)
279 string_check(-sid);
d2543f8c 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
a3b4927d 296## retrieve (id = c.clu_id, name = c.#name, sid = c.modby) {
d2543f8c 297 c = (struct cluster *) malloc(sizeof(struct cluster));
a3b4927d 298 if (c == NULL)
299 out_of_mem("storing clusters");
d2543f8c 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 }
a3b4927d 306 if (sid < 0)
307 string_check(-sid);
d2543f8c 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,
a3b4927d 325## aid = l.acl_id, buf = l.acl_type, sid = l.modby) {
d2543f8c 326 l = (struct list *) malloc(sizeof(struct list));
a3b4927d 327 if (l == NULL)
328 out_of_mem("storing lists");
d2543f8c 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 }
a3b4927d 338 if (sid < 0)
339 string_check(-sid);
d2543f8c 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,
a3b4927d 358## name1 = filesys.#name, sid = filesys.modby) {
d2543f8c 359 f = (struct filesys *) malloc(sizeof(struct filesys));
a3b4927d 360 if (f == NULL)
361 out_of_mem("storing filesystems");
d2543f8c 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 }
a3b4927d 374 if (sid < 0)
375 string_check(-sid);
d2543f8c 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,
a3b4927d 383## id2 = nfsphys.mach_id, id3 = nfsphys.allocated,
384## sid = nfsphys.modby) {
d2543f8c 385 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
a3b4927d 386 if (n == NULL)
387 out_of_mem("storing nfsphys");
d2543f8c 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 }
a3b4927d 397 if (sid < 0)
398 string_check(-sid);
d2543f8c 399## }
400 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
401
d2543f8c 402 if (!fast) {
a3b4927d 403## range of s is strings
d2543f8c 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);
38e6880d 407 printf("Not fixing this error\n");
a3b4927d 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");
d2543f8c 423## }
424 }
425##}
426
This page took 0.129144 seconds and 5 git commands to generate.