3 * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
15 EXEC SQL INCLUDE sqlca;
19 EXEC SQL WHENEVER SQLERROR DO dbmserr();
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);
42 int show_cnt_name(void *cnt);
44 int show_user_id(void *user)
46 struct user *u = user;
47 printf("User %s (%s, status %d) has duplicate ID\n",
48 u->login, u->fullname, u->status);
52 void handle_duplicate_logins(struct save_queue *sq)
54 struct user *u, *uu, *tmp;
57 if (sq_get_data(sq, &uu))
59 while (sq_get_data(sq, &u))
61 if (!strcmp(u->login, uu->login))
63 if (uu->status == 1 || u->status == 0)
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) &&
74 single_fix("Delete the second one", 0))
75 single_delete("users", "users_id", uu->users_id);
76 else if (single_fix("Unregister the second one", 0))
78 EXEC SQL BEGIN DECLARE SECTION;
79 int id = uu->users_id, rowcount;
80 EXEC SQL END DECLARE SECTION;
83 SET login = '#' || CHAR(users.unix_uid), status = 0
85 rowcount = sqlca.sqlerrd[2];
88 printf("%d entr%s fixed\n", rowcount,
89 rowcount == 1 ? "y" : "ies");
92 printf("Not fixed\n");
102 void fix_user_id(void *user)
104 struct user *u = user;
105 u->users_id = generic_fix_id("users", "users_id", "login",
106 u->users_id, u->login);
110 void cant_fix(void *id)
112 printf("Sorry, don't know how to fix that\n");
115 int show_mach_id(void *machine)
117 struct machine *m = machine;
118 printf("Machine %s has duplicate ID %d\n", m->name, m->mach_id);
122 int show_mach_name(void *machine)
124 struct machine *m = machine;
125 printf("Machine %s (%d) has duplicate name\n", m->name, m->mach_id);
129 void fix_mach_id(void *machine)
131 struct machine *m = machine;
132 m->mach_id = generic_fix_id("machine", "mach_id", "name",
133 m->mach_id, m->name);
136 int show_snet_name(void *subnet)
138 struct subnet *s = subnet;
139 printf("Subnet %s (%d) has duplicate name\n", s->name, s->snet_id);
143 int show_clu_id(void *cluster)
145 struct cluster *c = cluster;
146 printf("Cluster %s has duplicate ID %d\n", c->name, c->clu_id);
150 int show_clu_name(void *cluster)
152 struct cluster *c = cluster;
153 printf("Cluster %s (%d) has duplicate name\n", c->name, c->clu_id);
157 void fix_clu_id(void *cluster)
159 struct cluster *c = cluster;
160 c->clu_id = generic_fix_id("cluster", "clu_id", "name", c->clu_id, c->name);
163 int show_list_id(void *list)
165 struct list *l = list;
166 printf("List %s has duplicate ID %d\n", l->name, l->list_id);
170 int show_list_name(void *list)
172 struct list *l = list;
173 printf("List %s (%d) has duplicate name\n", l->name, l->list_id);
177 void fix_list_id(void *list)
179 struct list *l = list;
180 l->list_id = generic_fix_id("list", "list_id", "name", l->list_id, l->name);
183 int show_fs_id(void *filesys)
185 struct filesys *f = filesys;
186 printf("Filesys %s has duplicate ID %d\n", f->name, f->filsys_id);
190 void fix_fs_id(void *filesys)
192 struct filesys *f = filesys;
193 f->filsys_id = generic_fix_id("filesys", "filsys_id", "label",
194 f->filsys_id, f->name);
197 int show_fs_name(void *filesys)
199 struct filesys *fs = filesys;
200 printf("Filesys %s (%d) has duplicate name\n", fs->name, fs->filsys_id);
204 int show_np_id(void *nfsphys)
206 struct nfsphys *n = nfsphys;
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);
213 void fix_np_id(void *nfsphys)
215 struct nfsphys *n = nfsphys;
216 n->nfsphys_id = generic_fix_id("nfsphys", "nfsphys_id", "dir",
217 n->nfsphys_id, n->dir);
220 int show_str_id(void *string)
222 struct string *s = string;
223 printf("String %s has duplicate ID %d\n", s->name, s->string_id);
227 int print_str_id(void *id)
229 printf("String %d is a duplicate\n", (int)id);
233 void print_dup_map(int key, void *data, void *hint)
235 printf("String %d is a duplicate of string %d\n", key, (int)data);
238 int show_cnt_name(void *container)
240 struct container *cnt = container;
241 printf("Container %s (%d) has duplicate name\n", cnt->name, cnt->cnt_id);
247 EXEC SQL BEGIN DECLARE SECTION;
249 EXEC SQL END DECLARE SECTION;
250 int i, q, retval, tmp;
251 struct save_queue *sq;
260 struct printserver *ps;
261 struct container *cnt;
263 printf("Phase 1 - Looking for duplicates\n");
265 /* self-join strings table on "string" to get duplicate strings, then
266 build a duplicates table to merge them. */
268 dprintf("Looking for duplicate strings...\n");
269 string_dups = create_hash(100);
271 out_of_mem("storing duplicate strings");
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
286 EXEC SQL BEGIN DECLARE SECTION;
288 EXEC SQL END DECLARE SECTION;
290 EXEC SQL FETCH csr116 INTO :id1, :id2;
294 /* If id2 is already stored, skip this row. */
295 i = (int)hash_lookup(string_dups, id2);
298 /* Follow the chain of id1 equivalent IDs back to the lowest one. */
300 while ((tmp = (int)hash_lookup(string_dups, id)) > 0)
302 hash_store(string_dups, id2, (void *)id);
304 EXEC SQL CLOSE csr116;
305 dprintf("found %d duplicates\n", q);
306 hash_step(string_dups, print_dup_map, NULL);
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 */
311 dprintf("Loading strings...\n");
313 strings = create_hash(75000);
315 out_of_mem("loading strings");
317 EXEC SQL DECLARE csr101 CURSOR FOR
318 SELECT string_id, string FROM strings ORDER BY string_id;
319 EXEC SQL OPEN csr101;
323 EXEC SQL BEGIN DECLARE SECTION;
325 char buf[STRINGS_STRING_SIZE];
326 EXEC SQL END DECLARE SECTION;
328 EXEC SQL FETCH csr101 INTO :id, :buf;
332 s = malloc(sizeof(struct string));
334 out_of_mem("storing strings");
335 s->name = strdup(strtrim(buf));
338 retval = hash_store(strings, id, s);
340 out_of_mem("storing strings in hash table");
341 else if (retval == 1) /* duplicate string_id */
343 sq_save_data(sq, hash_lookup(strings, id));
347 EXEC SQL CLOSE csr101;
348 /* keep string id 0 (the empty string) even if unreferenced */
351 printf("Loaded %d strings\n", q);
353 dprintf("Loading users...\n");
355 users = create_hash(65000);
357 out_of_mem("loading users");
359 EXEC SQL DECLARE csr102 CURSOR FOR
360 SELECT users_id, login, last, first, status, potype, pop_id, box_id,
361 imap_id, modby, fmodby, pmodby, comments, sigwho FROM users
363 EXEC SQL OPEN csr102;
366 EXEC SQL BEGIN DECLARE SECTION;
367 char login[USERS_LOGIN_SIZE], nbuf[USERS_FIRST_SIZE + USERS_LAST_SIZE];
368 char last[USERS_LAST_SIZE], first[USERS_FIRST_SIZE];
369 char potype[USERS_POTYPE_SIZE];
370 int users_id, status, pop_id, box_id, imap_id, modby, fmodby, pmodby;
371 int comments, sigwho;
372 EXEC SQL END DECLARE SECTION;
374 EXEC SQL FETCH csr102 INTO :users_id, :login, :last, :first,
375 :status, :potype, :pop_id, :box_id, :imap_id, :modby, :fmodby,
376 :pmodby, :comments, :sigwho;
380 u = malloc(sizeof(struct user));
382 out_of_mem("storing users");
383 strcpy(u->login, strtrim(login));
384 u->potype = potype[0];
385 sprintf(nbuf, "%s, %s", strtrim(last), strtrim(first));
386 u->fullname = strdup(nbuf);
388 u->users_id = users_id;
392 u->comment = comments;
397 u->pobox_id = pop_id;
400 /* If potype is SMTP, box_id is a string_id for the strings tbl */
401 u->pobox_id = box_id;
404 u->pobox_id = imap_id;
409 retval = hash_store(users, users_id, u);
411 out_of_mem("storing users in hash table");
412 else if (retval == 1)
414 sq_save_data(sq, hash_lookup(users, users_id));
418 EXEC SQL CLOSE csr102;
420 generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
426 out_of_mem("finding duplicate logins");
428 EXEC SQL DECLARE csr103 CURSOR FOR
429 SELECT u1.users_id FROM users u1, users u2
430 WHERE u1.login = u2.login and u1.rowid != u2.rowid;
431 EXEC SQL OPEN csr103;
434 EXEC SQL FETCH csr103 INTO :id;
437 sq_save_data(sq, hash_lookup(users, id));
439 EXEC SQL CLOSE csr103;
440 handle_duplicate_logins(sq);
445 dprintf("Scanning krbmap...\n");
447 EXEC SQL DECLARE csr113 CURSOR FOR
448 SELECT k1.users_id FROM krbmap k1, krbmap k2
449 WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid;
450 EXEC SQL OPEN csr113;
453 EXEC SQL FETCH csr113 INTO :id;
457 printf("User %d is in the krbmap more than once!\n", id);
458 printf("Not fixing this error\n");
460 EXEC SQL CLOSE csr113;
462 EXEC SQL DECLARE csr114 CURSOR FOR
463 SELECT k1.string_id FROM krbmap k1, krbmap k2
464 WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid;
465 EXEC SQL OPEN csr114;
468 EXEC SQL FETCH csr114 INTO :id;
472 printf("Principal %d is in the krbmap more than once!\n", id);
473 printf("Not fixing this error\n");
475 EXEC SQL CLOSE csr114;
478 dprintf("Loading machines...\n");
480 machines = create_hash(20000);
481 if (!sq || !machines)
482 out_of_mem("loading machines");
484 EXEC SQL DECLARE csr104 CURSOR FOR
485 SELECT mach_id, name, snet_id, owner_type, owner_id,
486 acomment, ocomment, creator, modby
487 FROM machine ORDER BY mach_id;
488 EXEC SQL OPEN csr104;
491 EXEC SQL BEGIN DECLARE SECTION;
492 int mach_id, snet_id, owner_id, acomment, ocomment, creator, modby;
493 char name[MACHINE_NAME_SIZE], owner_type[MACHINE_OWNER_TYPE_SIZE];
494 EXEC SQL END DECLARE SECTION;
496 EXEC SQL FETCH csr104 INTO :mach_id, :name, :snet_id,
497 :owner_type, :owner_id, :acomment, :ocomment, :creator, :modby;
501 m = malloc(sizeof(struct machine));
503 out_of_mem("storing machines");
504 strcpy(m->name, strtrim(name));
505 m->owner_type = owner_type[0];
506 m->owner_id = owner_id;
507 m->snet_id = snet_id;
508 m->mach_id = mach_id;
510 m->acomment = acomment;
511 m->ocomment = ocomment;
512 m->creator = creator;
514 retval = hash_store(machines, mach_id, m);
516 out_of_mem("storing machines in hash table");
517 else if (retval == 1)
519 sq_save_data(sq, hash_lookup(machines, mach_id));
523 EXEC SQL CLOSE csr104;
524 generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
528 EXEC SQL BEGIN DECLARE SECTION;
529 char name[HOSTALIAS_NAME_SIZE];
531 EXEC SQL END DECLARE SECTION;
535 out_of_mem("looking for duplicate machine names");
537 EXEC SQL DECLARE csr105 CURSOR FOR
538 SELECT m1.mach_id FROM machine m1, machine m2
539 WHERE m1.name = m2.name AND m1.rowid != m2.rowid;
540 EXEC SQL OPEN csr105;
543 EXEC SQL FETCH csr105 INTO :id;
547 sq_save_data(sq, hash_lookup(machines, id));
549 EXEC SQL CLOSE csr105;
550 generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
552 EXEC SQL DECLARE csr_hal1 CURSOR FOR
553 SELECT h1.name, m1.mach_id, m2.mach_id
554 FROM hostalias h1, machine m1, hostalias h2, machine m2
555 WHERE h1.name = h2.name AND h1.mach_id != h2.mach_id
556 AND m1.mach_id = h1.mach_id AND m2.mach_id = h2.mach_id;
557 EXEC SQL OPEN csr_hal1;
560 EXEC SQL FETCH csr_hal1 INTO :name, :id1, :id2;
563 printf("Aliases for machines %d and %d have duplicate name %s\n",
564 id1, id2, strtrim(name));
567 EXEC SQL CLOSE csr_hal1;
569 EXEC SQL DECLARE csr_hal2 CURSOR FOR
570 SELECT h1.name, m1.mach_id, m2.mach_id
571 FROM hostalias h1, machine m1, machine m2
572 WHERE h1.name = m1.name AND h1.mach_id = m2.mach_id;
573 EXEC SQL OPEN csr_hal2;
576 EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2;
579 printf("Machine %d has alias %s that conflicts with machine %d\n",
580 id2, strtrim(name), id1);
583 EXEC SQL CLOSE csr_hal2;
586 dprintf("Loading subnets...\n");
587 subnets = create_hash(254);
589 out_of_mem("loading subnets");
591 EXEC SQL DECLARE csr115 CURSOR FOR
592 SELECT snet_id, name, owner_type, owner_id, modby from subnet;
593 EXEC SQL OPEN csr115;
596 EXEC SQL BEGIN DECLARE SECTION;
597 char name[SUBNET_NAME_SIZE], owner_type[SUBNET_OWNER_TYPE_SIZE];
598 int snet_id, owner_id, modby;
599 EXEC SQL END DECLARE SECTION;
601 EXEC SQL FETCH csr115 INTO :snet_id, :name, :owner_type,
606 sn = malloc(sizeof(struct machine));
608 out_of_mem("storing subnets");
609 strcpy(sn->name, strtrim(name));
610 sn->owner_type = owner_type[0];
611 sn->owner_id = owner_id;
612 sn->snet_id = snet_id;
614 retval = hash_store(subnets, snet_id, sn);
616 out_of_mem("storing subnets in hash table");
617 else if (retval == 1)
619 printf("Duplicate subnet ID: %d (%s)\n", id, name);
620 /* should add code to delete */
624 EXEC SQL CLOSE csr115;
630 out_of_mem("looking for duplicate subnet names");
632 EXEC SQL DECLARE csr117 CURSOR FOR
633 SELECT s1.snet_id FROM subnet s1, subnet s2
634 WHERE s1.name = s2.name AND s1.rowid != s2.rowid;
635 EXEC SQL OPEN csr117;
638 EXEC SQL FETCH csr117 INTO :id;
642 sq_save_data(sq, hash_lookup(subnets, id));
644 EXEC SQL CLOSE csr117;
645 generic_fix(sq, show_snet_name, "Change name", cant_fix, 0);
648 dprintf("Loading clusters...\n");
650 clusters = create_hash(100);
651 if (!sq || !clusters)
652 out_of_mem("loading clusters");
654 EXEC SQL DECLARE csr106 CURSOR FOR
655 SELECT clu_id, name, modby FROM clusters;
656 EXEC SQL OPEN csr106;
659 EXEC SQL BEGIN DECLARE SECTION;
661 char name[CLUSTERS_NAME_SIZE];
662 EXEC SQL END DECLARE SECTION;
664 EXEC SQL FETCH csr106 INTO :clu_id, :name, :modby;
668 c = malloc(sizeof(struct cluster));
670 out_of_mem("storing clusters");
671 strcpy(c->name, strtrim(name));
674 retval = hash_store(clusters, clu_id, c);
676 out_of_mem("storing clusters in hash table");
677 else if (retval == 1)
679 sq_save_data(sq, hash_lookup(clusters, clu_id));
683 EXEC SQL CLOSE csr106;
684 generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
690 out_of_mem("looking for duplicate cluster names");
692 EXEC SQL DECLARE csr107 CURSOR FOR
693 SELECT c1.clu_id FROM clusters c1, clusters c2
694 WHERE c1.name = c2.name AND c1.rowid != c2.rowid;
695 EXEC SQL OPEN csr107;
698 EXEC SQL FETCH csr107 INTO :id;
702 sq_save_data(sq, hash_lookup(clusters, id));
704 EXEC SQL CLOSE csr107;
705 generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
708 dprintf("Loading lists...\n");
710 lists = create_hash(50000);
712 out_of_mem("loading lists");
714 EXEC SQL DECLARE csr108 CURSOR FOR
715 SELECT list_id, name, acl_id, acl_type, memacl_id, memacl_type, modby
718 EXEC SQL OPEN csr108;
721 EXEC SQL BEGIN DECLARE SECTION;
722 int list_id, acl_id, memacl_id, modby;
723 char name[LIST_NAME_SIZE], acl_type[LIST_ACL_TYPE_SIZE];
724 char memacl_type[LIST_ACL_TYPE_SIZE];
725 EXEC SQL END DECLARE SECTION;
727 EXEC SQL FETCH csr108 INTO :list_id, :name, :acl_id, :acl_type,
728 :memacl_id, :memacl_type, :modby;
731 l = malloc(sizeof(struct list));
733 out_of_mem("storing lists");
734 strcpy(l->name, strtrim(name));
735 l->acl_type = acl_type[0];
737 l->memacl_type = memacl_type[0];
738 l->memacl_id = memacl_id;
739 l->list_id = list_id;
742 retval = hash_store(lists, list_id, l);
744 out_of_mem("storing lists in hash table");
745 else if (retval == 1)
747 sq_save_data(sq, hash_lookup(lists, list_id));
751 EXEC SQL CLOSE csr108;
752 generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
758 out_of_mem("looking for duplicate list names");
760 EXEC SQL DECLARE csr109 CURSOR FOR
761 SELECT l1.list_id FROM list l1, list l2
762 WHERE l1.name = l2.name AND l1.rowid != l2.rowid;
763 EXEC SQL OPEN csr109;
766 EXEC SQL FETCH csr109 INTO :id;
770 sq_save_data(sq, hash_lookup(lists, id));
772 EXEC SQL CLOSE csr109;
773 generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
776 dprintf("Loading filesys...\n");
778 filesys = create_hash(30000);
780 out_of_mem("loading filesys");
782 EXEC SQL DECLARE csr110 CURSOR FOR
783 SELECT filsys_id, label, owner, owners, phys_id, mach_id,
784 type, name, modby FROM filesys ORDER BY filsys_id;
785 EXEC SQL OPEN csr110;
788 EXEC SQL BEGIN DECLARE SECTION;
789 int filsys_id, owner, owners, phys_id, mach_id, modby;
790 char label[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
791 char name[FILESYS_NAME_SIZE];
792 EXEC SQL END DECLARE SECTION;
794 EXEC SQL FETCH csr110 INTO :filsys_id, :label, :owner, :owners,
795 :phys_id, :mach_id, :type, :name, :modby;
799 f = malloc(sizeof(struct filesys));
801 out_of_mem("storing filesystems");
802 strcpy(f->name, strtrim(label));
803 strcpy(f->dir, strtrim(name));
804 f->filsys_id = filsys_id;
807 f->phys_id = phys_id;
808 f->mach_id = mach_id;
810 retval = hash_store(filesys, filsys_id, f);
812 out_of_mem("storing filesys in hash table");
813 else if (retval == 1)
815 sq_save_data(sq, hash_lookup(filesys, filsys_id));
819 EXEC SQL CLOSE csr110;
821 generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
827 out_of_mem("looking for duplicate filesys names");
829 EXEC SQL DECLARE csr118 CURSOR FOR
830 SELECT fs1.filsys_id FROM filesys fs1, filesys fs2
831 WHERE fs1.label = fs2.label AND fs1.rowid != fs2.rowid;
832 EXEC SQL OPEN csr118;
835 EXEC SQL FETCH csr118 INTO :id;
839 sq_save_data(sq, hash_lookup(filesys, id));
841 EXEC SQL CLOSE csr118;
842 generic_fix(sq, show_fs_name, "Change name", cant_fix, 0);
845 dprintf("Loading nfsphys...\n");
847 nfsphys = create_hash(500);
849 out_of_mem("loading nfsphs");
851 EXEC SQL DECLARE csr111 CURSOR FOR
852 SELECT nfsphys_id, dir, mach_id, TO_CHAR(allocated), modby FROM nfsphys;
853 EXEC SQL OPEN csr111;
856 EXEC SQL BEGIN DECLARE SECTION;
857 int nfsphys_id, mach_id, modby;
858 char dir[NFSPHYS_DIR_SIZE];
860 EXEC SQL END DECLARE SECTION;
862 EXEC SQL FETCH csr111 INTO :nfsphys_id, :dir, :mach_id,
867 n = malloc(sizeof(struct nfsphys));
869 out_of_mem("storing nfsphys");
870 strcpy(n->dir, strtrim(dir));
871 n->mach_id = mach_id;
872 n->nfsphys_id = nfsphys_id;
873 n->allocated = strtoull(allocated, NULL, 0);
876 retval = hash_store(nfsphys, nfsphys_id, n);
878 out_of_mem("storing nfsphys in hash table");
879 else if (retval == 1)
881 sq_save_data(sq, hash_lookup(nfsphys, nfsphys_id));
885 EXEC SQL CLOSE csr111;
887 generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
891 dprintf("Checking printers...\n");
893 EXEC SQL DECLARE csr119 CURSOR FOR
894 SELECT p1.name FROM printers p1, printers p2
895 WHERE ( p1.name = p2.name AND p1.rowid < p2.rowid )
896 OR ( p1.name = p2.duplexname );
897 EXEC SQL OPEN csr119;
900 EXEC SQL BEGIN DECLARE SECTION;
901 char name[PRINTERS_NAME_SIZE];
902 EXEC SQL END DECLARE SECTION;
904 EXEC SQL FETCH csr119 INTO :name;
908 printf("Printer %s has duplicate name\n", name);
911 EXEC SQL CLOSE csr119;
914 dprintf("Loading printservers...\n");
915 printservers = create_hash(100);
917 out_of_mem("loading printservers");
919 EXEC SQL DECLARE csr_ps CURSOR FOR
920 SELECT mach_id, printer_types, owner_type, owner_id, lpc_acl, modby
922 EXEC SQL OPEN csr_ps;
925 EXEC SQL BEGIN DECLARE SECTION;
926 int mach_id, printer_types, owner_id, lpc_acl, modby;
927 char owner_type[PRINTSERVERS_OWNER_TYPE_SIZE];
928 EXEC SQL END DECLARE SECTION;
930 EXEC SQL FETCH csr_ps INTO :mach_id, :printer_types, :owner_type,
931 :owner_id, :lpc_acl, :modby;
935 ps = malloc(sizeof(struct printserver));
937 out_of_mem("storing printserver");
938 ps->mach_id = mach_id;
939 ps->printer_types = printer_types;
940 ps->owner_type = owner_type[0];
941 ps->owner_id = owner_id;
942 ps->lpc_acl = lpc_acl;
944 retval = hash_store(printservers, mach_id, ps);
946 out_of_mem("storing printserver in hash table");
947 else if (retval == 1)
949 printf("Duplicate printserver mach_id %d\n", mach_id);
953 EXEC SQL CLOSE csr_ps;
957 dprintf("Checking zephyr...\n");
959 EXEC SQL DECLARE csr120 CURSOR FOR
960 SELECT z1.class FROM zephyr z1, zephyr z2
961 WHERE (z1.class = z2.class AND z1.rowid < z1.rowid);
962 EXEC SQL OPEN csr120;
965 EXEC SQL BEGIN DECLARE SECTION;
966 char class[ZEPHYR_CLASS_SIZE];
967 EXEC SQL END DECLARE SECTION;
969 EXEC SQL FETCH csr120 INTO :class;
973 printf("Zephyr class %s has duplicate name\n", class);
976 EXEC SQL CLOSE csr120;
979 dprintf("Loading containers...\n");
980 containers = create_hash(1000);
982 out_of_mem("loading containers");
984 EXEC SQL DECLARE csr_cnts CURSOR FOR
985 SELECT name, cnt_id, list_id, acl_type, acl_id, memacl_type, memacl_id,
986 modby FROM containers;
987 EXEC SQL OPEN csr_cnts;
990 EXEC SQL BEGIN DECLARE SECTION;
991 int cnt_id, list_id, acl_id, memacl_id, modby;
992 char name[CONTAINERS_NAME_SIZE];
993 char acl_type[CONTAINERS_ACL_TYPE_SIZE];
994 char memacl_type[CONTAINERS_MEMACL_TYPE_SIZE];
995 EXEC SQL END DECLARE SECTION;
997 EXEC SQL FETCH csr_cnts INTO :name, :cnt_id, :list_id, :acl_type,
998 :acl_id, :memacl_type, :memacl_id, :modby;
1002 cnt = malloc(sizeof(struct container));
1004 out_of_mem("storing container");
1005 strcpy(cnt->name, strtrim(name));
1006 cnt->cnt_id = cnt_id;
1007 cnt->list_id = list_id;
1008 cnt->acl_type = acl_type[0];
1009 cnt->acl_id = acl_id;
1010 cnt->memacl_type = memacl_type[0];
1011 cnt->memacl_id = memacl_id;
1013 retval = hash_store(containers, cnt_id, cnt);
1015 out_of_mem("storing container in hash table");
1016 else if (retval == 1)
1018 printf("Duplicate container cnt_id %d\n", cnt_id);
1022 EXEC SQL CLOSE csr_cnts;
1028 out_of_mem("looking for duplicate container names");
1030 EXEC SQL DECLARE csr121 CURSOR FOR
1031 SELECT cnt1.cnt_id FROM containers cnt1, containers cnt2
1032 WHERE cnt1.name = cnt2.name AND cnt1.cnt_id != cnt2.cnt_id;
1033 EXEC SQL OPEN csr121;
1036 EXEC SQL FETCH csr121 INTO :id;
1040 sq_save_data(sq, hash_lookup(containers, id));
1042 EXEC SQL CLOSE csr121;
1043 generic_fix(sq, show_cnt_name, "Change name", cant_fix, 0);