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