]>
Commit | Line | Data |
---|---|---|
7ac48069 | 1 | /* $Id$ |
68bbc9c3 | 2 | * |
7ac48069 | 3 | * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology. |
4 | * For copying and distribution information, please see the file | |
5 | * <mit-copyright.h>. | |
68bbc9c3 | 6 | */ |
7 | ||
8 | #include <mit-copyright.h> | |
9 | #include <moira.h> | |
7ac48069 | 10 | #include "dbck.h" |
11 | ||
ab05f33a | 12 | #include <stdio.h> |
5eaef520 | 13 | #include <stdlib.h> |
7ac48069 | 14 | #include <string.h> |
208a4f4a | 15 | EXEC SQL INCLUDE sqlca; |
16 | ||
7ac48069 | 17 | RCSID("$Header$"); |
68bbc9c3 | 18 | |
4b9e5c72 | 19 | EXEC SQL WHENEVER SQLERROR DO dbmserr(); |
7ac48069 | 20 | int show_user_id(void *user); |
21 | void handle_duplicate_logins(struct save_queue *sq); | |
22 | void fix_user_id(void *user); | |
23 | void cant_fix(void *id); | |
24 | int show_mach_id(void *machine); | |
25 | int show_mach_name(void *machine); | |
26 | void fix_mach_id(void *machine); | |
27 | int show_snet_name(void *subnet); | |
28 | int show_clu_id(void *cluster); | |
29 | int show_clu_name(void *cluster); | |
30 | void fix_clu_id(void *cluster); | |
31 | int show_list_id(void *list); | |
32 | int show_list_name(void *list); | |
33 | void fix_list_id(void *list); | |
34 | int show_fs_id(void *filesys); | |
35 | void fix_fs_id(void *filesys); | |
36 | int show_fs_name(void *fs); | |
37 | int show_np_id(void *nfsphys); | |
38 | void fix_np_id(void *nfsphys); | |
39 | int show_str_id(void *string); | |
40 | int print_str_id(void *id); | |
41 | void print_dup_map(int key, void *data, void *hint); | |
cb884d06 | 42 | int show_cnt_name(void *cnt); |
7ac48069 | 43 | |
44 | int show_user_id(void *user) | |
68bbc9c3 | 45 | { |
7ac48069 | 46 | struct user *u = user; |
5eaef520 | 47 | printf("User %s (%s, status %d) has duplicate ID\n", |
48 | u->login, u->fullname, u->status); | |
49 | return 0; | |
68bbc9c3 | 50 | } |
51 | ||
7ac48069 | 52 | void handle_duplicate_logins(struct save_queue *sq) |
68bbc9c3 | 53 | { |
5eaef520 | 54 | struct user *u, *uu, *tmp; |
55 | ||
56 | uu = NULL; | |
57 | if (sq_get_data(sq, &uu)) | |
58 | { | |
59 | while (sq_get_data(sq, &u)) | |
60 | { | |
61 | if (!strcmp(u->login, uu->login)) | |
62 | { | |
63 | if (uu->status == 1 || u->status == 0) | |
64 | { | |
65 | tmp = u; | |
66 | u = uu; | |
67 | uu = tmp; | |
68 | } | |
69 | printf("User %s (%s, status %d) and\n", | |
70 | u->login, u->fullname, u->status); | |
71 | printf("User %s (%s, status %d) have duplicate logins\n", | |
72 | uu->login, uu->fullname, uu->status); | |
73 | if (!strcmp(u->fullname, uu->fullname) && | |
7ac48069 | 74 | single_fix("Delete the second one", 0)) |
68bbc9c3 | 75 | single_delete("users", "users_id", uu->users_id); |
7ac48069 | 76 | else if (single_fix("Unregister the second one", 0)) |
5eaef520 | 77 | { |
78 | EXEC SQL BEGIN DECLARE SECTION; | |
79 | int id = uu->users_id, rowcount; | |
80 | EXEC SQL END DECLARE SECTION; | |
81 | ||
82 | EXEC SQL UPDATE users | |
83 | SET login = '#' || CHAR(users.unix_uid), status = 0 | |
84 | WHERE users_id = :id; | |
85 | rowcount = sqlca.sqlerrd[2]; | |
86 | if (rowcount > 0) | |
87 | { | |
88 | printf("%d entr%s fixed\n", rowcount, | |
89 | rowcount == 1 ? "y" : "ies"); | |
90 | } | |
91 | else | |
92 | printf("Not fixed\n"); | |
93 | modified("users"); | |
94 | } | |
95 | } | |
96 | else | |
68bbc9c3 | 97 | uu = u; |
98 | } | |
99 | } | |
100 | } | |
101 | ||
7ac48069 | 102 | void fix_user_id(void *user) |
68bbc9c3 | 103 | { |
7ac48069 | 104 | struct user *u = user; |
5eaef520 | 105 | u->users_id = generic_fix_id("users", "users_id", "login", |
106 | u->users_id, u->login); | |
68bbc9c3 | 107 | } |
108 | ||
109 | ||
7ac48069 | 110 | void cant_fix(void *id) |
68bbc9c3 | 111 | { |
5eaef520 | 112 | printf("Sorry, don't know how to fix that\n"); |
68bbc9c3 | 113 | } |
114 | ||
7ac48069 | 115 | int show_mach_id(void *machine) |
68bbc9c3 | 116 | { |
7ac48069 | 117 | struct machine *m = machine; |
5eaef520 | 118 | printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id); |
119 | return 0; | |
68bbc9c3 | 120 | } |
121 | ||
7ac48069 | 122 | int show_mach_name(void *machine) |
68bbc9c3 | 123 | { |
7ac48069 | 124 | struct machine *m = machine; |
5eaef520 | 125 | printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id); |
126 | return 0; | |
68bbc9c3 | 127 | } |
128 | ||
7ac48069 | 129 | void fix_mach_id(void *machine) |
68bbc9c3 | 130 | { |
7ac48069 | 131 | struct machine *m = machine; |
5eaef520 | 132 | m->mach_id = generic_fix_id("machine", "mach_id", "name", |
133 | m->mach_id, m->name); | |
68bbc9c3 | 134 | } |
135 | ||
7ac48069 | 136 | int show_snet_name(void *subnet) |
235fd664 | 137 | { |
7ac48069 | 138 | struct subnet *s = subnet; |
5eaef520 | 139 | printf("Subnet %s (%d) has duplicate name\n", s->name, s->snet_id); |
140 | return 0; | |
235fd664 | 141 | } |
142 | ||
7ac48069 | 143 | int show_clu_id(void *cluster) |
68bbc9c3 | 144 | { |
7ac48069 | 145 | struct cluster *c = cluster; |
5eaef520 | 146 | printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id); |
147 | return 0; | |
68bbc9c3 | 148 | } |
149 | ||
7ac48069 | 150 | int show_clu_name(void *cluster) |
68bbc9c3 | 151 | { |
7ac48069 | 152 | struct cluster *c = cluster; |
5eaef520 | 153 | printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id); |
154 | return 0; | |
68bbc9c3 | 155 | } |
156 | ||
7ac48069 | 157 | void fix_clu_id(void *cluster) |
68bbc9c3 | 158 | { |
7ac48069 | 159 | struct cluster *c = cluster; |
5eaef520 | 160 | c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name); |
68bbc9c3 | 161 | } |
162 | ||
7ac48069 | 163 | int show_list_id(void *list) |
68bbc9c3 | 164 | { |
7ac48069 | 165 | struct list *l = list; |
5eaef520 | 166 | printf("List %s has duplicate ID %d\n", l->name, l->list_id); |
167 | return 0; | |
68bbc9c3 | 168 | } |
169 | ||
7ac48069 | 170 | int show_list_name(void *list) |
68bbc9c3 | 171 | { |
7ac48069 | 172 | struct list *l = list; |
5eaef520 | 173 | printf("List %s (%d) has duplicate name\n", l->name, l->list_id); |
174 | return 0; | |
68bbc9c3 | 175 | } |
176 | ||
7ac48069 | 177 | void fix_list_id(void *list) |
68bbc9c3 | 178 | { |
7ac48069 | 179 | struct list *l = list; |
5eaef520 | 180 | l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name); |
68bbc9c3 | 181 | } |
182 | ||
7ac48069 | 183 | int show_fs_id(void *filesys) |
68bbc9c3 | 184 | { |
7ac48069 | 185 | struct filesys *f = filesys; |
5eaef520 | 186 | printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id); |
187 | return 0; | |
68bbc9c3 | 188 | } |
189 | ||
7ac48069 | 190 | void fix_fs_id(void *filesys) |
68bbc9c3 | 191 | { |
7ac48069 | 192 | struct filesys *f = filesys; |
5eaef520 | 193 | f->filsys_id = generic_fix_id("filesys", "filsys_id", "label", |
194 | f->filsys_id, f->name); | |
68bbc9c3 | 195 | } |
196 | ||
7ac48069 | 197 | int show_fs_name(void *filesys) |
235fd664 | 198 | { |
7ac48069 | 199 | struct filesys *fs = filesys; |
5eaef520 | 200 | printf("Filesys %s (%d) has duplicate name\n", fs->name, fs->filsys_id); |
201 | return 0; | |
235fd664 | 202 | } |
203 | ||
7ac48069 | 204 | int show_np_id(void *nfsphys) |
68bbc9c3 | 205 | { |
7ac48069 | 206 | struct nfsphys *n = nfsphys; |
5eaef520 | 207 | printf("NfsPhys %s:%s has duplicate ID %d\n", |
208 | ((struct machine *)hash_lookup(machines, n->mach_id))->name, | |
209 | n->dir, n->nfsphys_id); | |
210 | return 0; | |
68bbc9c3 | 211 | } |
212 | ||
7ac48069 | 213 | void fix_np_id(void *nfsphys) |
68bbc9c3 | 214 | { |
7ac48069 | 215 | struct nfsphys *n = nfsphys; |
5eaef520 | 216 | n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir", |
217 | n->nfsphys_id, n->dir); | |
68bbc9c3 | 218 | } |
219 | ||
7ac48069 | 220 | int show_str_id(void *string) |
68bbc9c3 | 221 | { |
7ac48069 | 222 | struct string *s = string; |
5eaef520 | 223 | printf("String %s has duplicate ID %d\n", s->name, s->string_id); |
224 | return 0; | |
68bbc9c3 | 225 | } |
226 | ||
7ac48069 | 227 | int print_str_id(void *id) |
ab05f33a | 228 | { |
7ac48069 | 229 | printf("String %d is a duplicate\n", (int)id); |
5eaef520 | 230 | return 0; |
ab05f33a | 231 | } |
232 | ||
7ac48069 | 233 | void print_dup_map(int key, void *data, void *hint) |
ab05f33a | 234 | { |
7ac48069 | 235 | printf("String %d is a duplicate of string %d\n", key, (int)data); |
ab05f33a | 236 | } |
68bbc9c3 | 237 | |
cb884d06 | 238 | int show_cnt_name(void *container) |
239 | { | |
240 | struct container *cnt = container; | |
241 | printf("Container %s (%d) has duplicate name\n", cnt->name, cnt->cnt_id); | |
242 | return 0; | |
243 | } | |
244 | ||
7ac48069 | 245 | void phase1(void) |
208a4f4a | 246 | { |
5eaef520 | 247 | EXEC SQL BEGIN DECLARE SECTION; |
cfc4f91e | 248 | int id; |
5eaef520 | 249 | EXEC SQL END DECLARE SECTION; |
250 | int i, q, retval, tmp; | |
251 | struct save_queue *sq; | |
252 | struct user *u; | |
253 | struct machine *m; | |
254 | struct subnet *sn; | |
255 | struct list *l; | |
256 | struct cluster *c; | |
257 | struct string *s; | |
258 | struct filesys *f; | |
259 | struct nfsphys *n; | |
fe0a844a | 260 | struct printserver *ps; |
cb884d06 | 261 | struct container *cnt; |
5eaef520 | 262 | |
263 | printf("Phase 1 - Looking for duplicates\n"); | |
264 | ||
265 | /* self-join strings table on "string" to get duplicate strings, then | |
266 | build a duplicates table to merge them. */ | |
267 | ||
268 | dprintf("Looking for duplicate strings...\n"); | |
269 | string_dups = create_hash(100); | |
270 | if (!string_dups) | |
271 | out_of_mem("storing duplicate strings"); | |
272 | ||
273 | EXEC SQL DECLARE csr116 CURSOR FOR | |
274 | SELECT s1.string_id, s2.string_id FROM strings s1, strings s2 | |
275 | WHERE s1.string = s2.string and s1.string_id < s2.string_id; | |
276 | EXEC SQL OPEN csr116; | |
277 | /* The SELECT gives us two columns, both with non-negative integers. | |
278 | * The number in the left column is always the smaller of the two, | |
279 | * and each row includes string IDs for identical strings. We use | |
280 | * them to make a mapping from id-to-delete to id-to-keep for all | |
281 | * superflous IDs. | |
282 | */ | |
283 | q = 0; | |
284 | while (1) | |
285 | { | |
cfc4f91e | 286 | EXEC SQL BEGIN DECLARE SECTION; |
287 | int id1, id2; | |
288 | EXEC SQL END DECLARE SECTION; | |
289 | ||
5eaef520 | 290 | EXEC SQL FETCH csr116 INTO :id1, :id2; |
291 | if (sqlca.sqlcode) | |
292 | break; | |
293 | q++; | |
294 | /* If id2 is already stored, skip this row. */ | |
7ac48069 | 295 | i = (int)hash_lookup(string_dups, id2); |
5eaef520 | 296 | if (i > 0) |
297 | continue; | |
298 | /* Follow the chain of id1 equivalent IDs back to the lowest one. */ | |
299 | id = id1; | |
7ac48069 | 300 | while ((tmp = (int)hash_lookup(string_dups, id)) > 0) |
5eaef520 | 301 | id = tmp; |
7ac48069 | 302 | hash_store(string_dups, id2, (void *)id); |
ab05f33a | 303 | } |
5eaef520 | 304 | EXEC SQL CLOSE csr116; |
305 | dprintf("found %d duplicates\n", q); | |
7ac48069 | 306 | hash_step(string_dups, print_dup_map, NULL); |
5eaef520 | 307 | /* We don't want to delete the duplicates now because if the dbck |
308 | is cancelled, a LOT of state will be lost. So, we'll just let | |
309 | them not get marked as used and then phase3 will clean them up */ | |
310 | ||
311 | dprintf("Loading strings...\n"); | |
312 | sq = sq_create(); | |
313 | strings = create_hash(75000); | |
314 | if (!sq || !strings) | |
315 | out_of_mem("loading strings"); | |
316 | ||
317 | EXEC SQL DECLARE csr101 CURSOR FOR | |
318 | SELECT string_id, string FROM strings ORDER BY string_id; | |
319 | EXEC SQL OPEN csr101; | |
320 | q = 0; | |
321 | while (1) | |
322 | { | |
cfc4f91e | 323 | EXEC SQL BEGIN DECLARE SECTION; |
324 | int id; | |
325 | char buf[STRINGS_STRING_SIZE]; | |
326 | EXEC SQL END DECLARE SECTION; | |
327 | ||
5eaef520 | 328 | EXEC SQL FETCH csr101 INTO :id, :buf; |
329 | if (sqlca.sqlcode) | |
330 | break; | |
331 | q++; | |
332 | s = malloc(sizeof(struct string)); | |
333 | if (!s) | |
334 | out_of_mem("storing strings"); | |
7ac48069 | 335 | s->name = strdup(strtrim(buf)); |
5eaef520 | 336 | s->string_id = id; |
337 | s->refc = 0; | |
338 | retval = hash_store(strings, id, s); | |
339 | if (retval == -1) | |
340 | out_of_mem("storing strings in hash table"); | |
341 | else if (retval == 1) /* duplicate string_id */ | |
342 | { | |
ab05f33a | 343 | sq_save_data(sq, hash_lookup(strings, id)); |
344 | sq_save_data(sq, s); | |
68bbc9c3 | 345 | } |
208a4f4a | 346 | } |
5eaef520 | 347 | EXEC SQL CLOSE csr101; |
348 | /* keep string id 0 (the empty string) even if unreferenced */ | |
349 | string_check(0); | |
350 | ||
351 | printf("Loaded %d strings\n", q); | |
352 | ||
353 | dprintf("Loading users...\n"); | |
354 | sq = sq_create(); | |
cb884d06 | 355 | users = create_hash(65000); |
5eaef520 | 356 | if (!sq || !users) |
357 | out_of_mem("loading users"); | |
358 | ||
359 | EXEC SQL DECLARE csr102 CURSOR FOR | |
360 | SELECT users_id, login, last, first, status, potype, pop_id, box_id, | |
22bbb6f0 | 361 | imap_id, exchange_id, modby, fmodby, pmodby, comments, sigwho, |
362 | sponsor_type, sponsor_id | |
8949c781 | 363 | FROM users ORDER BY users_id; |
5eaef520 | 364 | EXEC SQL OPEN csr102; |
365 | while (1) | |
366 | { | |
cfc4f91e | 367 | EXEC SQL BEGIN DECLARE SECTION; |
368 | char login[USERS_LOGIN_SIZE], nbuf[USERS_FIRST_SIZE + USERS_LAST_SIZE]; | |
369 | char last[USERS_LAST_SIZE], first[USERS_FIRST_SIZE]; | |
8949c781 | 370 | char potype[USERS_POTYPE_SIZE], sponsor_type[USERS_SPONSOR_TYPE_SIZE]; |
22bbb6f0 | 371 | int users_id, status, pop_id, box_id, imap_id, exchange_id, modby; |
372 | int fmodby, pmodby, comments, sigwho, sponsor_id; | |
cfc4f91e | 373 | EXEC SQL END DECLARE SECTION; |
374 | ||
375 | EXEC SQL FETCH csr102 INTO :users_id, :login, :last, :first, | |
22bbb6f0 | 376 | :status, :potype, :pop_id, :box_id, :imap_id, :exchange_id, :modby, |
377 | :fmodby, :pmodby, :comments, :sigwho, :sponsor_type, :sponsor_id; | |
5eaef520 | 378 | if (sqlca.sqlcode) |
379 | break; | |
380 | ||
381 | u = malloc(sizeof(struct user)); | |
382 | if (!u) | |
383 | out_of_mem("storing users"); | |
cfc4f91e | 384 | strcpy(u->login, strtrim(login)); |
385 | u->potype = potype[0]; | |
386 | sprintf(nbuf, "%s, %s", strtrim(last), strtrim(first)); | |
387 | u->fullname = strdup(nbuf); | |
5eaef520 | 388 | u->status = status; |
cfc4f91e | 389 | u->users_id = users_id; |
390 | u->modby = modby; | |
391 | u->fmodby = fmodby; | |
392 | u->pmodby = pmodby; | |
393 | u->comment = comments; | |
394 | u->sigwho = sigwho; | |
8949c781 | 395 | u->sponsor_type = sponsor_type[0]; |
396 | u->sponsor_id = sponsor_id; | |
5eaef520 | 397 | switch (u->potype) |
398 | { | |
68bbc9c3 | 399 | case 'P': |
cfc4f91e | 400 | u->pobox_id = pop_id; |
5eaef520 | 401 | break; |
68bbc9c3 | 402 | case 'S': |
5eaef520 | 403 | /* If potype is SMTP, box_id is a string_id for the strings tbl */ |
cfc4f91e | 404 | u->pobox_id = box_id; |
5eaef520 | 405 | break; |
fc6165db | 406 | case 'I': |
407 | u->pobox_id = imap_id; | |
408 | break; | |
22bbb6f0 | 409 | case 'E': |
410 | u->pobox_id = exchange_id; | |
68bbc9c3 | 411 | default: |
5eaef520 | 412 | u->pobox_id = 0; |
68bbc9c3 | 413 | } |
cfc4f91e | 414 | retval = hash_store(users, users_id, u); |
5eaef520 | 415 | if (retval == -1) |
416 | out_of_mem("storing users in hash table"); | |
417 | else if (retval == 1) | |
418 | { | |
cfc4f91e | 419 | sq_save_data(sq, hash_lookup(users, users_id)); |
5eaef520 | 420 | sq_save_data(sq, u); |
68bbc9c3 | 421 | } |
208a4f4a | 422 | } |
5eaef520 | 423 | EXEC SQL CLOSE csr102; |
424 | ||
425 | generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0); | |
426 | ||
427 | if (!fast) | |
428 | { | |
429 | sq = sq_create(); | |
430 | if (!sq) | |
431 | out_of_mem("finding duplicate logins"); | |
432 | ||
433 | EXEC SQL DECLARE csr103 CURSOR FOR | |
434 | SELECT u1.users_id FROM users u1, users u2 | |
435 | WHERE u1.login = u2.login and u1.rowid != u2.rowid; | |
436 | EXEC SQL OPEN csr103; | |
437 | while (1) | |
438 | { | |
439 | EXEC SQL FETCH csr103 INTO :id; | |
440 | if (sqlca.sqlcode) | |
441 | break; | |
442 | sq_save_data(sq, hash_lookup(users, id)); | |
208a4f4a | 443 | } |
5eaef520 | 444 | EXEC SQL CLOSE csr103; |
445 | handle_duplicate_logins(sq); | |
68bbc9c3 | 446 | } |
447 | ||
5eaef520 | 448 | if (!fast) |
449 | { | |
450 | dprintf("Scanning krbmap...\n"); | |
451 | ||
452 | EXEC SQL DECLARE csr113 CURSOR FOR | |
453 | SELECT k1.users_id FROM krbmap k1, krbmap k2 | |
454 | WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid; | |
455 | EXEC SQL OPEN csr113; | |
456 | while (1) | |
457 | { | |
458 | EXEC SQL FETCH csr113 INTO :id; | |
459 | if (sqlca.sqlcode) | |
460 | break; | |
ab05f33a | 461 | |
5eaef520 | 462 | printf("User %d is in the krbmap more than once!\n", id); |
463 | printf("Not fixing this error\n"); | |
ab05f33a | 464 | } |
5eaef520 | 465 | EXEC SQL CLOSE csr113; |
466 | ||
467 | EXEC SQL DECLARE csr114 CURSOR FOR | |
468 | SELECT k1.string_id FROM krbmap k1, krbmap k2 | |
469 | WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid; | |
470 | EXEC SQL OPEN csr114; | |
471 | while (1) | |
472 | { | |
473 | EXEC SQL FETCH csr114 INTO :id; | |
474 | if (sqlca.sqlcode) | |
475 | break; | |
476 | ||
477 | printf("Principal %d is in the krbmap more than once!\n", id); | |
478 | printf("Not fixing this error\n"); | |
ab05f33a | 479 | } |
5eaef520 | 480 | EXEC SQL CLOSE csr114; |
ab05f33a | 481 | } |
482 | ||
5eaef520 | 483 | dprintf("Loading machines...\n"); |
484 | sq = sq_create(); | |
485 | machines = create_hash(20000); | |
486 | if (!sq || !machines) | |
487 | out_of_mem("loading machines"); | |
488 | ||
489 | EXEC SQL DECLARE csr104 CURSOR FOR | |
490 | SELECT mach_id, name, snet_id, owner_type, owner_id, | |
491 | acomment, ocomment, creator, modby | |
492 | FROM machine ORDER BY mach_id; | |
493 | EXEC SQL OPEN csr104; | |
494 | while (1) | |
495 | { | |
cfc4f91e | 496 | EXEC SQL BEGIN DECLARE SECTION; |
497 | int mach_id, snet_id, owner_id, acomment, ocomment, creator, modby; | |
498 | char name[MACHINE_NAME_SIZE], owner_type[MACHINE_OWNER_TYPE_SIZE]; | |
499 | EXEC SQL END DECLARE SECTION; | |
500 | ||
501 | EXEC SQL FETCH csr104 INTO :mach_id, :name, :snet_id, | |
502 | :owner_type, :owner_id, :acomment, :ocomment, :creator, :modby; | |
5eaef520 | 503 | if (sqlca.sqlcode) |
504 | break; | |
505 | ||
506 | m = malloc(sizeof(struct machine)); | |
507 | if (!m) | |
508 | out_of_mem("storing machines"); | |
509 | strcpy(m->name, strtrim(name)); | |
cfc4f91e | 510 | m->owner_type = owner_type[0]; |
511 | m->owner_id = owner_id; | |
512 | m->snet_id = snet_id; | |
513 | m->mach_id = mach_id; | |
5eaef520 | 514 | m->clucount = 0; |
cfc4f91e | 515 | m->acomment = acomment; |
516 | m->ocomment = ocomment; | |
517 | m->creator = creator; | |
518 | m->modby = modby; | |
519 | retval = hash_store(machines, mach_id, m); | |
5eaef520 | 520 | if (retval == -1) |
521 | out_of_mem("storing machines in hash table"); | |
522 | else if (retval == 1) | |
523 | { | |
cfc4f91e | 524 | sq_save_data(sq, hash_lookup(machines, mach_id)); |
5eaef520 | 525 | sq_save_data(sq, m); |
68bbc9c3 | 526 | } |
208a4f4a | 527 | } |
5eaef520 | 528 | EXEC SQL CLOSE csr104; |
529 | generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0); | |
530 | ||
531 | if (!fast) | |
532 | { | |
cfc4f91e | 533 | EXEC SQL BEGIN DECLARE SECTION; |
534 | char name[HOSTALIAS_NAME_SIZE]; | |
535 | int id1, id2; | |
536 | EXEC SQL END DECLARE SECTION; | |
537 | ||
5eaef520 | 538 | sq = sq_create(); |
539 | if (!sq) | |
540 | out_of_mem("looking for duplicate machine names"); | |
541 | ||
542 | EXEC SQL DECLARE csr105 CURSOR FOR | |
543 | SELECT m1.mach_id FROM machine m1, machine m2 | |
544 | WHERE m1.name = m2.name AND m1.rowid != m2.rowid; | |
545 | EXEC SQL OPEN csr105; | |
546 | while (1) | |
547 | { | |
548 | EXEC SQL FETCH csr105 INTO :id; | |
549 | if (sqlca.sqlcode) | |
550 | break; | |
551 | ||
552 | sq_save_data(sq, hash_lookup(machines, id)); | |
208a4f4a | 553 | } |
5eaef520 | 554 | EXEC SQL CLOSE csr105; |
555 | generic_fix(sq, show_mach_name, "Change name", cant_fix, 0); | |
556 | ||
557 | EXEC SQL DECLARE csr_hal1 CURSOR FOR | |
558 | SELECT h1.name, m1.mach_id, m2.mach_id | |
559 | FROM hostalias h1, machine m1, hostalias h2, machine m2 | |
560 | WHERE h1.name = h2.name AND h1.mach_id != h2.mach_id | |
561 | AND m1.mach_id = h1.mach_id AND m2.mach_id = h2.mach_id; | |
562 | EXEC SQL OPEN csr_hal1; | |
563 | while (1) | |
564 | { | |
ab05f33a | 565 | EXEC SQL FETCH csr_hal1 INTO :name, :id1, :id2; |
5eaef520 | 566 | if (sqlca.sqlcode) |
567 | break; | |
ab05f33a | 568 | printf("Aliases for machines %d and %d have duplicate name %s\n", |
569 | id1, id2, strtrim(name)); | |
a8e78b23 | 570 | cant_fix(0); |
ab05f33a | 571 | } |
5eaef520 | 572 | EXEC SQL CLOSE csr_hal1; |
573 | ||
574 | EXEC SQL DECLARE csr_hal2 CURSOR FOR | |
575 | SELECT h1.name, m1.mach_id, m2.mach_id | |
576 | FROM hostalias h1, machine m1, machine m2 | |
577 | WHERE h1.name = m1.name AND h1.mach_id = m2.mach_id; | |
578 | EXEC SQL OPEN csr_hal2; | |
579 | while (1) | |
580 | { | |
581 | EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2; | |
582 | if (sqlca.sqlcode) | |
583 | break; | |
584 | printf("Machine %d has alias %s that conflicts with machine %d\n", | |
585 | id2, strtrim(name), id1); | |
a8e78b23 | 586 | cant_fix(0); |
5eaef520 | 587 | } |
588 | EXEC SQL CLOSE csr_hal2; | |
772b7afc | 589 | } |
235fd664 | 590 | |
5eaef520 | 591 | dprintf("Loading subnets...\n"); |
592 | subnets = create_hash(254); | |
593 | if (!subnets) | |
594 | out_of_mem("loading subnets"); | |
595 | ||
596 | EXEC SQL DECLARE csr115 CURSOR FOR | |
597 | SELECT snet_id, name, owner_type, owner_id, modby from subnet; | |
598 | EXEC SQL OPEN csr115; | |
599 | while (1) | |
600 | { | |
cfc4f91e | 601 | EXEC SQL BEGIN DECLARE SECTION; |
602 | char name[SUBNET_NAME_SIZE], owner_type[SUBNET_OWNER_TYPE_SIZE]; | |
603 | int snet_id, owner_id, modby; | |
604 | EXEC SQL END DECLARE SECTION; | |
605 | ||
606 | EXEC SQL FETCH csr115 INTO :snet_id, :name, :owner_type, | |
607 | :owner_id, :modby; | |
5eaef520 | 608 | if (sqlca.sqlcode) |
609 | break; | |
610 | ||
611 | sn = malloc(sizeof(struct machine)); | |
612 | if (!sn) | |
613 | out_of_mem("storing subnets"); | |
614 | strcpy(sn->name, strtrim(name)); | |
cfc4f91e | 615 | sn->owner_type = owner_type[0]; |
616 | sn->owner_id = owner_id; | |
617 | sn->snet_id = snet_id; | |
618 | sn->modby = modby; | |
619 | retval = hash_store(subnets, snet_id, sn); | |
5eaef520 | 620 | if (retval == -1) |
621 | out_of_mem("storing subnets in hash table"); | |
622 | else if (retval == 1) | |
623 | { | |
624 | printf("Duplicate subnet ID: %d (%s)\n", id, name); | |
625 | /* should add code to delete */ | |
626 | cant_fix(0); | |
627 | } | |
628 | } | |
629 | EXEC SQL CLOSE csr115; | |
630 | ||
631 | if (!fast) | |
632 | { | |
633 | sq = sq_create(); | |
634 | if (!sq) | |
635 | out_of_mem("looking for duplicate subnet names"); | |
636 | ||
637 | EXEC SQL DECLARE csr117 CURSOR FOR | |
638 | SELECT s1.snet_id FROM subnet s1, subnet s2 | |
639 | WHERE s1.name = s2.name AND s1.rowid != s2.rowid; | |
640 | EXEC SQL OPEN csr117; | |
641 | while (1) | |
642 | { | |
643 | EXEC SQL FETCH csr117 INTO :id; | |
644 | if (sqlca.sqlcode) | |
645 | break; | |
235fd664 | 646 | |
5eaef520 | 647 | sq_save_data(sq, hash_lookup(subnets, id)); |
235fd664 | 648 | } |
5eaef520 | 649 | EXEC SQL CLOSE csr117; |
650 | generic_fix(sq, show_snet_name, "Change name", cant_fix, 0); | |
235fd664 | 651 | } |
5eaef520 | 652 | |
653 | dprintf("Loading clusters...\n"); | |
654 | sq = sq_create(); | |
655 | clusters = create_hash(100); | |
656 | if (!sq || !clusters) | |
657 | out_of_mem("loading clusters"); | |
658 | ||
659 | EXEC SQL DECLARE csr106 CURSOR FOR | |
660 | SELECT clu_id, name, modby FROM clusters; | |
661 | EXEC SQL OPEN csr106; | |
662 | while (1) | |
663 | { | |
cfc4f91e | 664 | EXEC SQL BEGIN DECLARE SECTION; |
665 | int clu_id, modby; | |
666 | char name[CLUSTERS_NAME_SIZE]; | |
667 | EXEC SQL END DECLARE SECTION; | |
668 | ||
669 | EXEC SQL FETCH csr106 INTO :clu_id, :name, :modby; | |
5eaef520 | 670 | if (sqlca.sqlcode) |
671 | break; | |
672 | ||
673 | c = malloc(sizeof(struct cluster)); | |
674 | if (!c) | |
675 | out_of_mem("storing clusters"); | |
676 | strcpy(c->name, strtrim(name)); | |
cfc4f91e | 677 | c->clu_id = clu_id; |
678 | c->modby = modby; | |
679 | retval = hash_store(clusters, clu_id, c); | |
5eaef520 | 680 | if (retval == -1) |
681 | out_of_mem("storing clusters in hash table"); | |
682 | else if (retval == 1) | |
683 | { | |
cfc4f91e | 684 | sq_save_data(sq, hash_lookup(clusters, clu_id)); |
5eaef520 | 685 | sq_save_data(sq, c); |
68bbc9c3 | 686 | } |
208a4f4a | 687 | } |
5eaef520 | 688 | EXEC SQL CLOSE csr106; |
689 | generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0); | |
690 | ||
691 | if (!fast) | |
692 | { | |
693 | sq = sq_create(); | |
694 | if (!sq) | |
695 | out_of_mem("looking for duplicate cluster names"); | |
696 | ||
697 | EXEC SQL DECLARE csr107 CURSOR FOR | |
698 | SELECT c1.clu_id FROM clusters c1, clusters c2 | |
699 | WHERE c1.name = c2.name AND c1.rowid != c2.rowid; | |
700 | EXEC SQL OPEN csr107; | |
701 | while (1) | |
702 | { | |
703 | EXEC SQL FETCH csr107 INTO :id; | |
704 | if (sqlca.sqlcode) | |
705 | break; | |
706 | ||
707 | sq_save_data(sq, hash_lookup(clusters, id)); | |
208a4f4a | 708 | } |
5eaef520 | 709 | EXEC SQL CLOSE csr107; |
710 | generic_fix(sq, show_clu_name, "Change name", cant_fix, 0); | |
68bbc9c3 | 711 | } |
712 | ||
5eaef520 | 713 | dprintf("Loading lists...\n"); |
714 | sq = sq_create(); | |
715 | lists = create_hash(50000); | |
716 | if (!sq || !lists) | |
717 | out_of_mem("loading lists"); | |
718 | ||
719 | EXEC SQL DECLARE csr108 CURSOR FOR | |
ad47bcbe | 720 | SELECT list_id, name, acl_id, acl_type, memacl_id, memacl_type, modby |
721 | FROM list | |
5eaef520 | 722 | ORDER BY list_id; |
723 | EXEC SQL OPEN csr108; | |
724 | while (1) | |
725 | { | |
cfc4f91e | 726 | EXEC SQL BEGIN DECLARE SECTION; |
ad47bcbe | 727 | int list_id, acl_id, memacl_id, modby; |
cfc4f91e | 728 | char name[LIST_NAME_SIZE], acl_type[LIST_ACL_TYPE_SIZE]; |
ad47bcbe | 729 | char memacl_type[LIST_ACL_TYPE_SIZE]; |
cfc4f91e | 730 | EXEC SQL END DECLARE SECTION; |
731 | ||
ad47bcbe | 732 | EXEC SQL FETCH csr108 INTO :list_id, :name, :acl_id, :acl_type, |
733 | :memacl_id, :memacl_type, :modby; | |
5eaef520 | 734 | if (sqlca.sqlcode) |
735 | break; | |
736 | l = malloc(sizeof(struct list)); | |
737 | if (!l) | |
738 | out_of_mem("storing lists"); | |
739 | strcpy(l->name, strtrim(name)); | |
cfc4f91e | 740 | l->acl_type = acl_type[0]; |
741 | l->acl_id = acl_id; | |
ad47bcbe | 742 | l->memacl_type = memacl_type[0]; |
743 | l->memacl_id = memacl_id; | |
cfc4f91e | 744 | l->list_id = list_id; |
745 | l->modby = modby; | |
5eaef520 | 746 | l->members = 0; |
cfc4f91e | 747 | retval = hash_store(lists, list_id, l); |
5eaef520 | 748 | if (retval == -1) |
749 | out_of_mem("storing lists in hash table"); | |
750 | else if (retval == 1) | |
751 | { | |
cfc4f91e | 752 | sq_save_data(sq, hash_lookup(lists, list_id)); |
5eaef520 | 753 | sq_save_data(sq, l); |
68bbc9c3 | 754 | } |
208a4f4a | 755 | } |
5eaef520 | 756 | EXEC SQL CLOSE csr108; |
757 | generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0); | |
758 | ||
759 | if (!fast) | |
760 | { | |
761 | sq = sq_create(); | |
762 | if (!sq) | |
763 | out_of_mem("looking for duplicate list names"); | |
764 | ||
765 | EXEC SQL DECLARE csr109 CURSOR FOR | |
766 | SELECT l1.list_id FROM list l1, list l2 | |
767 | WHERE l1.name = l2.name AND l1.rowid != l2.rowid; | |
768 | EXEC SQL OPEN csr109; | |
769 | while (1) | |
770 | { | |
771 | EXEC SQL FETCH csr109 INTO :id; | |
772 | if (sqlca.sqlcode) | |
773 | break; | |
774 | ||
775 | sq_save_data(sq, hash_lookup(lists, id)); | |
208a4f4a | 776 | } |
5eaef520 | 777 | EXEC SQL CLOSE csr109; |
778 | generic_fix(sq, show_list_name, "Change name", cant_fix, 0); | |
68bbc9c3 | 779 | } |
780 | ||
5eaef520 | 781 | dprintf("Loading filesys...\n"); |
782 | sq = sq_create(); | |
783 | filesys = create_hash(30000); | |
784 | if (!sq || !filesys) | |
785 | out_of_mem("loading filesys"); | |
786 | ||
787 | EXEC SQL DECLARE csr110 CURSOR FOR | |
788 | SELECT filsys_id, label, owner, owners, phys_id, mach_id, | |
789 | type, name, modby FROM filesys ORDER BY filsys_id; | |
790 | EXEC SQL OPEN csr110; | |
791 | while (1) | |
792 | { | |
cfc4f91e | 793 | EXEC SQL BEGIN DECLARE SECTION; |
794 | int filsys_id, owner, owners, phys_id, mach_id, modby; | |
795 | char label[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE]; | |
796 | char name[FILESYS_NAME_SIZE]; | |
797 | EXEC SQL END DECLARE SECTION; | |
798 | ||
799 | EXEC SQL FETCH csr110 INTO :filsys_id, :label, :owner, :owners, | |
800 | :phys_id, :mach_id, :type, :name, :modby; | |
5eaef520 | 801 | if (sqlca.sqlcode) |
802 | break; | |
803 | ||
804 | f = malloc(sizeof(struct filesys)); | |
805 | if (!f) | |
806 | out_of_mem("storing filesystems"); | |
cfc4f91e | 807 | strcpy(f->name, strtrim(label)); |
808 | strcpy(f->dir, strtrim(name)); | |
809 | f->filsys_id = filsys_id; | |
810 | f->owner = owner; | |
811 | f->owners = owners; | |
812 | f->phys_id = phys_id; | |
813 | f->mach_id = mach_id; | |
814 | f->type = type[0]; | |
815 | retval = hash_store(filesys, filsys_id, f); | |
5eaef520 | 816 | if (retval == -1) |
817 | out_of_mem("storing filesys in hash table"); | |
818 | else if (retval == 1) | |
819 | { | |
cfc4f91e | 820 | sq_save_data(sq, hash_lookup(filesys, filsys_id)); |
5eaef520 | 821 | sq_save_data(sq, f); |
68bbc9c3 | 822 | } |
208a4f4a | 823 | } |
5eaef520 | 824 | EXEC SQL CLOSE csr110; |
825 | ||
826 | generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0); | |
827 | ||
828 | if (!fast) | |
829 | { | |
830 | sq = sq_create(); | |
831 | if (!sq) | |
832 | out_of_mem("looking for duplicate filesys names"); | |
833 | ||
834 | EXEC SQL DECLARE csr118 CURSOR FOR | |
835 | SELECT fs1.filsys_id FROM filesys fs1, filesys fs2 | |
836 | WHERE fs1.label = fs2.label AND fs1.rowid != fs2.rowid; | |
837 | EXEC SQL OPEN csr118; | |
838 | while (1) | |
839 | { | |
840 | EXEC SQL FETCH csr118 INTO :id; | |
841 | if (sqlca.sqlcode) | |
842 | break; | |
843 | ||
844 | sq_save_data(sq, hash_lookup(filesys, id)); | |
235fd664 | 845 | } |
5eaef520 | 846 | EXEC SQL CLOSE csr118; |
847 | generic_fix(sq, show_fs_name, "Change name", cant_fix, 0); | |
235fd664 | 848 | } |
849 | ||
5eaef520 | 850 | dprintf("Loading nfsphys...\n"); |
851 | sq = sq_create(); | |
852 | nfsphys = create_hash(500); | |
853 | if (!sq || !nfsphys) | |
854 | out_of_mem("loading nfsphs"); | |
855 | ||
856 | EXEC SQL DECLARE csr111 CURSOR FOR | |
05d03f93 | 857 | SELECT nfsphys_id, dir, mach_id, TO_CHAR(allocated), modby FROM nfsphys; |
5eaef520 | 858 | EXEC SQL OPEN csr111; |
859 | while (1) | |
860 | { | |
cfc4f91e | 861 | EXEC SQL BEGIN DECLARE SECTION; |
05d03f93 | 862 | int nfsphys_id, mach_id, modby; |
cfc4f91e | 863 | char dir[NFSPHYS_DIR_SIZE]; |
05d03f93 | 864 | char allocated[39]; |
cfc4f91e | 865 | EXEC SQL END DECLARE SECTION; |
866 | ||
867 | EXEC SQL FETCH csr111 INTO :nfsphys_id, :dir, :mach_id, | |
868 | :allocated, :modby; | |
5eaef520 | 869 | if (sqlca.sqlcode) |
870 | break; | |
871 | ||
872 | n = malloc(sizeof(struct nfsphys)); | |
873 | if (!n) | |
874 | out_of_mem("storing nfsphys"); | |
cfc4f91e | 875 | strcpy(n->dir, strtrim(dir)); |
876 | n->mach_id = mach_id; | |
877 | n->nfsphys_id = nfsphys_id; | |
05d03f93 | 878 | n->allocated = strtoull(allocated, NULL, 0); |
cfc4f91e | 879 | n->modby = modby; |
5eaef520 | 880 | n->count = 0; |
cfc4f91e | 881 | retval = hash_store(nfsphys, nfsphys_id, n); |
5eaef520 | 882 | if (retval == -1) |
883 | out_of_mem("storing nfsphys in hash table"); | |
884 | else if (retval == 1) | |
885 | { | |
cfc4f91e | 886 | sq_save_data(sq, hash_lookup(nfsphys, nfsphys_id)); |
5eaef520 | 887 | sq_save_data(sq, n); |
68bbc9c3 | 888 | } |
208a4f4a | 889 | } |
5eaef520 | 890 | EXEC SQL CLOSE csr111; |
208a4f4a | 891 | |
5eaef520 | 892 | generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0); |
68bbc9c3 | 893 | |
dabf20aa | 894 | if (!fast) |
5eaef520 | 895 | { |
dabf20aa | 896 | dprintf("Checking printers...\n"); |
cfc4f91e | 897 | |
dabf20aa | 898 | EXEC SQL DECLARE csr119 CURSOR FOR |
899 | SELECT p1.name FROM printers p1, printers p2 | |
900 | WHERE ( p1.name = p2.name AND p1.rowid < p2.rowid ) | |
901 | OR ( p1.name = p2.duplexname ); | |
902 | EXEC SQL OPEN csr119; | |
903 | while (1) | |
904 | { | |
905 | EXEC SQL BEGIN DECLARE SECTION; | |
906 | char name[PRINTERS_NAME_SIZE]; | |
907 | EXEC SQL END DECLARE SECTION; | |
235fd664 | 908 | |
dabf20aa | 909 | EXEC SQL FETCH csr119 INTO :name; |
910 | if (sqlca.sqlcode) | |
911 | break; | |
912 | ||
913 | printf("Printer %s has duplicate name\n", name); | |
914 | cant_fix(0); | |
915 | } | |
916 | EXEC SQL CLOSE csr119; | |
235fd664 | 917 | } |
fe0a844a | 918 | |
919 | dprintf("Loading printservers...\n"); | |
920 | printservers = create_hash(100); | |
921 | if (!printservers) | |
922 | out_of_mem("loading printservers"); | |
923 | ||
924 | EXEC SQL DECLARE csr_ps CURSOR FOR | |
925 | SELECT mach_id, printer_types, owner_type, owner_id, lpc_acl, modby | |
926 | FROM printservers; | |
927 | EXEC SQL OPEN csr_ps; | |
928 | while (1) | |
929 | { | |
930 | EXEC SQL BEGIN DECLARE SECTION; | |
931 | int mach_id, printer_types, owner_id, lpc_acl, modby; | |
932 | char owner_type[PRINTSERVERS_OWNER_TYPE_SIZE]; | |
933 | EXEC SQL END DECLARE SECTION; | |
934 | ||
935 | EXEC SQL FETCH csr_ps INTO :mach_id, :printer_types, :owner_type, | |
936 | :owner_id, :lpc_acl, :modby; | |
937 | if (sqlca.sqlcode) | |
938 | break; | |
939 | ||
940 | ps = malloc(sizeof(struct printserver)); | |
941 | if (!ps) | |
942 | out_of_mem("storing printserver"); | |
943 | ps->mach_id = mach_id; | |
61eec0b8 | 944 | ps->printer_types = printer_types; |
fe0a844a | 945 | ps->owner_type = owner_type[0]; |
946 | ps->owner_id = owner_id; | |
947 | ps->lpc_acl = lpc_acl; | |
948 | ps->modby = modby; | |
949 | retval = hash_store(printservers, mach_id, ps); | |
950 | if (retval == -1) | |
951 | out_of_mem("storing printserver in hash table"); | |
952 | else if (retval == 1) | |
953 | { | |
954 | printf("Duplicate printserver mach_id %d\n", mach_id); | |
955 | cant_fix(0); | |
956 | } | |
957 | } | |
37ed4e84 | 958 | EXEC SQL CLOSE csr_ps; |
959 | ||
960 | if (!fast) | |
961 | { | |
962 | dprintf("Checking zephyr...\n"); | |
963 | ||
964 | EXEC SQL DECLARE csr120 CURSOR FOR | |
965 | SELECT z1.class FROM zephyr z1, zephyr z2 | |
966 | WHERE (z1.class = z2.class AND z1.rowid < z1.rowid); | |
967 | EXEC SQL OPEN csr120; | |
968 | while (1) | |
969 | { | |
970 | EXEC SQL BEGIN DECLARE SECTION; | |
971 | char class[ZEPHYR_CLASS_SIZE]; | |
972 | EXEC SQL END DECLARE SECTION; | |
973 | ||
974 | EXEC SQL FETCH csr120 INTO :class; | |
975 | if (sqlca.sqlcode) | |
976 | break; | |
977 | ||
978 | printf("Zephyr class %s has duplicate name\n", class); | |
979 | cant_fix(0); | |
980 | } | |
981 | EXEC SQL CLOSE csr120; | |
982 | } | |
cb884d06 | 983 | |
984 | dprintf("Loading containers...\n"); | |
985 | containers = create_hash(1000); | |
986 | if (!containers) | |
987 | out_of_mem("loading containers"); | |
988 | ||
989 | EXEC SQL DECLARE csr_cnts CURSOR FOR | |
990 | SELECT name, cnt_id, list_id, acl_type, acl_id, memacl_type, memacl_id, | |
991 | modby FROM containers; | |
992 | EXEC SQL OPEN csr_cnts; | |
993 | while (1) | |
994 | { | |
995 | EXEC SQL BEGIN DECLARE SECTION; | |
996 | int cnt_id, list_id, acl_id, memacl_id, modby; | |
997 | char name[CONTAINERS_NAME_SIZE]; | |
998 | char acl_type[CONTAINERS_ACL_TYPE_SIZE]; | |
999 | char memacl_type[CONTAINERS_MEMACL_TYPE_SIZE]; | |
1000 | EXEC SQL END DECLARE SECTION; | |
1001 | ||
1002 | EXEC SQL FETCH csr_cnts INTO :name, :cnt_id, :list_id, :acl_type, | |
1003 | :acl_id, :memacl_type, :memacl_id, :modby; | |
1004 | if (sqlca.sqlcode) | |
1005 | break; | |
1006 | ||
1007 | cnt = malloc(sizeof(struct container)); | |
1008 | if (!cnt) | |
1009 | out_of_mem("storing container"); | |
1010 | strcpy(cnt->name, strtrim(name)); | |
1011 | cnt->cnt_id = cnt_id; | |
1012 | cnt->list_id = list_id; | |
1013 | cnt->acl_type = acl_type[0]; | |
1014 | cnt->acl_id = acl_id; | |
1015 | cnt->memacl_type = memacl_type[0]; | |
1016 | cnt->memacl_id = memacl_id; | |
1017 | cnt->modby = modby; | |
1018 | retval = hash_store(containers, cnt_id, cnt); | |
1019 | if (retval == -1) | |
1020 | out_of_mem("storing container in hash table"); | |
1021 | else if (retval == 1) | |
1022 | { | |
1023 | printf("Duplicate container cnt_id %d\n", cnt_id); | |
1024 | cant_fix(0); | |
1025 | } | |
1026 | } | |
1027 | EXEC SQL CLOSE csr_cnts; | |
1028 | ||
1029 | if (!fast) | |
1030 | { | |
1031 | sq = sq_create(); | |
1032 | if (!sq) | |
1033 | out_of_mem("looking for duplicate container names"); | |
1034 | ||
1035 | EXEC SQL DECLARE csr121 CURSOR FOR | |
1036 | SELECT cnt1.cnt_id FROM containers cnt1, containers cnt2 | |
1037 | WHERE cnt1.name = cnt2.name AND cnt1.cnt_id != cnt2.cnt_id; | |
1038 | EXEC SQL OPEN csr121; | |
1039 | while (1) | |
1040 | { | |
1041 | EXEC SQL FETCH csr121 INTO :id; | |
1042 | if (sqlca.sqlcode) | |
1043 | break; | |
1044 | ||
1045 | sq_save_data(sq, hash_lookup(containers, id)); | |
1046 | } | |
1047 | EXEC SQL CLOSE csr121; | |
1048 | generic_fix(sq, show_cnt_name, "Change name", cant_fix, 0); | |
1049 | } | |
208a4f4a | 1050 | } |