]> andersk Git - moira.git/blame - dbck/phase1.qc
include sms.h to stop lint complaints
[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>
65ddeaac 9#include <sms.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##{
178## char name[33], name1[33], last[17], first[17], buf[257];
179## int id, id2, id3, aid, aid2, status;
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 users...\n");
192 sq = sq_create();
193 users = create_hash(10000);
194## range of u is users
195## retrieve (id = u.users_id, name = u.login, last = u.#last,
196## first = u.#first, status = u.#status, buf = u.potype,
197## id2 = u.pop_id, id3 = u.box_id) {
198 u = (struct user *) malloc(sizeof(struct user));
199 strcpy(u->login, strtrim(name));
200 u->potype = buf[0];
201 sprintf(buf, "%s, %s", strtrim(last), strtrim(first));
202 u->fullname = strsave(buf);
203 u->status = status;
204 u->users_id = id;
205 switch (u->potype) {
206 case 'P':
207 u->pobox_id = id2;
208 break;
209 case 'S':
210 u->pobox_id = id3;
211 break;
212 default:
213 u->pobox_id = 0;
214 }
215 if (hash_store(users, id, u)) {
216 sq_save_data(sq, hash_lookup(users, id));
217 sq_save_data(sq, u);
218 }
219## }
220 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
221
222 if (!fast) {
223 sq = sq_create();
224## retrieve (id = u.users_id)
225## where u.login = users.login and u.tid != users.tid {
226 sq_save_data(sq, hash_lookup(users, id));
227## }
228 handle_duplicate_logins(sq);
229 }
230
231 dprintf("Loading machines...\n");
232 machines = create_hash(1000);
233 sq = sq_create();
234## range of m is machine
235## retrieve (id = m.mach_id, name = m.#name) {
236 m = (struct machine *) malloc(sizeof(struct machine));
237 strcpy(m->name, strtrim(name));
238 m->mach_id = id;
239 m->clucount = 0;
240 if (hash_store(machines, id, m)) {
241 sq_save_data(sq, hash_lookup(machines, id));
242 sq_save_data(sq, m);
243 }
244## }
245 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
246
247 if (!fast) {
248 sq = sq_create();
249## retrieve (id = m.mach_id)
250## where m.#name = machine.#name and m.tid != machine.tid {
251 sq_save_data(sq, hash_lookup(machines, id));
252## }
253 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
254 }
255
256 dprintf("Loading clusters...\n");
257 sq = sq_create();
258 clusters = create_hash(100);
259## range of c is cluster
260## retrieve (id = cluster.clu_id, name = cluster.#name) {
261 c = (struct cluster *) malloc(sizeof(struct cluster));
262 strcpy(c->name, strtrim(name));
263 c->clu_id = id;
264 if (hash_store(clusters, id, c)) {
265 sq_save_data(sq, hash_lookup(clusters, id));
266 sq_save_data(sq, c);
267 }
268## }
269 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
270
271 if (!fast) {
272 sq = sq_create();
273## retrieve (id = c.clu_id)
274## where c.#name = cluster.#name and c.tid != cluster.tid {
275 sq_save_data(sq, hash_lookup(clusters, id));
276## }
277 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
278 }
279
280 dprintf("Loading lists...\n");
281 sq = sq_create();
282 lists = create_hash(10000);
283## range of l is list
284## retrieve (id = l.list_id, name = l.#name,
285## aid = l.acl_id, buf = l.acl_type) {
286 l = (struct list *) malloc(sizeof(struct list));
287 strcpy(l->name, strtrim(name));
288 l->acl_type = buf[0];
289 l->acl_id = aid;
290 l->list_id = id;
291 l->members = 0;
292 if (hash_store(lists, id, l)) {
293 sq_save_data(sq, hash_lookup(lists, id));
294 sq_save_data(sq, l);
295 }
296## }
297 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
298
299 if (!fast) {
300 sq = sq_create();
301## retrieve (id = l.list_id)
302## where l.#name = list.#name and l.tid != list.tid {
303 sq_save_data(sq, hash_lookup(lists, id));
304## }
305 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
306 }
307
308 dprintf("Loading filesys...\n");
309 sq = sq_create();
310 filesys = create_hash(10000);
311## retrieve (id = filesys.filsys_id, name = filesys.label, aid = filesys.owner,
312## aid2 = filesys.owners, id2 = filesys.phys_id,
313## id3 = filesys.mach_id, buf = filesys.type,
314## name1 = filesys.#name) {
315 f = (struct filesys *) malloc(sizeof(struct filesys));
316 strcpy(f->name, strtrim(name));
317 strcpy(f->dir, strtrim(name1));
318 f->filsys_id = id;
319 f->owner = aid;
320 f->owners = aid2;
321 f->phys_id = id2;
322 f->mach_id = id3;
323 f->type = buf[0];
324 if (hash_store(filesys, id, f)) {
325 sq_save_data(sq, hash_lookup(filesys, id));
326 sq_save_data(sq, f);
327 }
328## }
329 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
330
331 dprintf("Loading nfsphys...\n");
332 sq = sq_create();
333 nfsphys = create_hash(500);
334## retrieve (id = nfsphys.nfsphys_id, name = nfsphys.dir,
335## id2 = nfsphys.mach_id, id3 = nfsphys.allocated) {
336 n = (struct nfsphys *) malloc(sizeof(struct nfsphys));
337 strcpy(n->dir, strtrim(name));
338 n->mach_id = id2;
339 n->nfsphys_id = id;
340 n->allocated = id3;
341 n->count = 0;
342 if (hash_store(nfsphys, id, n)) {
343 sq_save_data(sq, hash_lookup(nfsphys, id));
344 sq_save_data(sq, n);
345 }
346## }
347 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
348
349 dprintf("Loading strings...\n");
350 sq = sq_create();
351 strings = create_hash(5000);
352## range of s is strings
353## retrieve (id = s.string_id, buf = s.string) {
354 s = (struct string *) malloc(sizeof(struct string));
355 s->name = strsave(strtrim(buf));
356 s->string_id = id;
357 s->refc = 0;
358 if (hash_store(strings, id, s)) {
359 sq_save_data(sq, hash_lookup(strings, id));
360 sq_save_data(sq, s);
361 }
362## }
363 generic_delete(sq, show_str_id, "strings", "string_id", 0);
364
365 if (!fast) {
366## retrieve (id = s.string_id, buf = s.string)
367## where s.string = strings.string and s.tid != strings.tid {
368 printf("String %s(%d) is a duplicate!\n", strtrim(buf), id);
38e6880d 369 printf("Not fixing this error\n");
d2543f8c 370## }
371 }
372##}
373
This page took 0.116715 seconds and 5 git commands to generate.