]> andersk Git - moira.git/blob - dbck/phase1.pc
don't make "install" depend on "all"
[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   struct printserver *ps;
253
254   printf("Phase 1 - Looking for duplicates\n");
255
256   /* self-join strings table on "string" to get duplicate strings, then
257      build a duplicates table to merge them. */
258
259   dprintf("Looking for duplicate strings...\n");
260   string_dups = create_hash(100);
261   if (!string_dups)
262     out_of_mem("storing duplicate strings");
263
264   EXEC SQL DECLARE csr116 CURSOR FOR
265     SELECT s1.string_id, s2.string_id FROM strings s1, strings s2
266     WHERE s1.string = s2.string and s1.string_id < s2.string_id;
267   EXEC SQL OPEN csr116;
268   /*  The SELECT gives us two columns, both with non-negative integers.
269    *  The number in the left column is always the smaller of the two,
270    *  and each row includes string IDs for identical strings.  We use
271    *  them to make a mapping from id-to-delete to id-to-keep for all
272    *  superflous IDs.
273    */
274   q = 0;
275   while (1)
276     {
277       EXEC SQL BEGIN DECLARE SECTION;
278       int id1, id2;
279       EXEC SQL END DECLARE SECTION;
280
281       EXEC SQL FETCH csr116 INTO :id1, :id2;
282       if (sqlca.sqlcode)
283         break;
284       q++;
285       /*  If id2 is already stored, skip this row. */
286       i = (int)hash_lookup(string_dups, id2);
287       if (i > 0)
288         continue;
289       /*  Follow the chain of id1 equivalent IDs back to the lowest one. */
290       id = id1;
291       while ((tmp = (int)hash_lookup(string_dups, id)) > 0)
292         id = tmp;
293       hash_store(string_dups, id2, (void *)id);
294     }
295   EXEC SQL CLOSE csr116;
296   dprintf("found %d duplicates\n", q);
297   hash_step(string_dups, print_dup_map, NULL);
298   /* We don't want to delete the duplicates now because if the dbck
299      is cancelled, a LOT of state will be lost. So, we'll just let
300      them not get marked as used and then phase3 will clean them up */
301
302   dprintf("Loading strings...\n");
303   sq = sq_create();
304   strings = create_hash(75000);
305   if (!sq || !strings)
306     out_of_mem("loading strings");
307
308   EXEC SQL DECLARE csr101 CURSOR FOR
309     SELECT string_id, string FROM strings ORDER BY string_id;
310   EXEC SQL OPEN csr101;
311   q = 0;
312   while (1)
313     {
314       EXEC SQL BEGIN DECLARE SECTION;
315       int id;
316       char buf[STRINGS_STRING_SIZE];
317       EXEC SQL END DECLARE SECTION;
318
319       EXEC SQL FETCH csr101 INTO :id, :buf;
320       if (sqlca.sqlcode)
321         break;
322       q++;
323       s = malloc(sizeof(struct string));
324       if (!s)
325         out_of_mem("storing strings");
326       s->name = strdup(strtrim(buf));
327       s->string_id = id;
328       s->refc = 0;
329       retval = hash_store(strings, id, s);
330       if (retval == -1)
331         out_of_mem("storing strings in hash table");
332       else if (retval == 1) /* duplicate string_id */
333         {
334           sq_save_data(sq, hash_lookup(strings, id));
335           sq_save_data(sq, s);
336         }
337     }
338   EXEC SQL CLOSE csr101;
339   /* keep string id 0 (the empty string) even if unreferenced */
340   string_check(0);
341
342   printf("Loaded %d strings\n", q);
343
344   dprintf("Loading users...\n");
345   sq = sq_create();
346   users = create_hash(30000);
347   if (!sq || !users)
348     out_of_mem("loading users");
349
350   EXEC SQL DECLARE csr102 CURSOR FOR
351     SELECT users_id, login, last, first, status, potype, pop_id, box_id,
352     imap_id, modby, fmodby, pmodby, comments, sigwho FROM users
353     ORDER BY users_id;
354   EXEC SQL OPEN csr102;
355   while (1)
356     {
357       EXEC SQL BEGIN DECLARE SECTION;
358       char login[USERS_LOGIN_SIZE], nbuf[USERS_FIRST_SIZE + USERS_LAST_SIZE];
359       char last[USERS_LAST_SIZE], first[USERS_FIRST_SIZE];
360       char potype[USERS_POTYPE_SIZE];
361       int users_id, status, pop_id, box_id, imap_id, modby, fmodby, pmodby;
362       int comments, sigwho;
363       EXEC SQL END DECLARE SECTION;
364
365       EXEC SQL FETCH csr102 INTO :users_id, :login, :last, :first,
366         :status, :potype, :pop_id, :box_id, :imap_id, :modby, :fmodby,
367         :pmodby, :comments, :sigwho;
368       if (sqlca.sqlcode)
369         break;
370
371       u = malloc(sizeof(struct user));
372       if (!u)
373         out_of_mem("storing users");
374       strcpy(u->login, strtrim(login));
375       u->potype = potype[0];
376       sprintf(nbuf, "%s, %s", strtrim(last), strtrim(first));
377       u->fullname = strdup(nbuf);
378       u->status = status;
379       u->users_id = users_id;
380       u->modby = modby;
381       u->fmodby = fmodby;
382       u->pmodby = pmodby;
383       u->comment = comments;
384       u->sigwho = sigwho;
385       switch (u->potype)
386         {
387         case 'P':
388           u->pobox_id = pop_id;
389           break;
390         case 'S':
391           /*  If potype is SMTP, box_id is a string_id for the strings tbl */
392           u->pobox_id = box_id;
393           break;
394         case 'I':
395           u->pobox_id = imap_id;
396           break;
397         default:
398           u->pobox_id = 0;
399         }
400       retval = hash_store(users, users_id, u);
401       if (retval == -1)
402         out_of_mem("storing users in hash table");
403       else if (retval == 1)
404         {
405           sq_save_data(sq, hash_lookup(users, users_id));
406           sq_save_data(sq, u);
407         }
408     }
409   EXEC SQL CLOSE csr102;
410
411   generic_fix(sq, show_user_id, "Change ID", fix_user_id, 0);
412
413   if (!fast)
414     {
415       sq = sq_create();
416       if (!sq)
417         out_of_mem("finding duplicate logins");
418
419       EXEC SQL DECLARE csr103 CURSOR FOR
420         SELECT u1.users_id FROM users u1, users u2
421         WHERE u1.login = u2.login and u1.rowid != u2.rowid;
422       EXEC SQL OPEN csr103;
423       while (1)
424         {
425           EXEC SQL FETCH csr103 INTO :id;
426           if (sqlca.sqlcode)
427             break;
428           sq_save_data(sq, hash_lookup(users, id));
429         }
430       EXEC SQL CLOSE csr103;
431       handle_duplicate_logins(sq);
432     }
433
434   if (!fast)
435     {
436       dprintf("Scanning krbmap...\n");
437
438       EXEC SQL DECLARE csr113 CURSOR FOR
439         SELECT k1.users_id FROM krbmap k1, krbmap k2
440         WHERE k1.users_id = k2.users_id AND k1.rowid != k2.rowid;
441       EXEC SQL OPEN csr113;
442       while (1)
443         {
444           EXEC SQL FETCH csr113 INTO :id;
445           if (sqlca.sqlcode)
446             break;
447
448           printf("User %d is in the krbmap more than once!\n", id);
449           printf("Not fixing this error\n");
450         }
451       EXEC SQL CLOSE csr113;
452
453       EXEC SQL DECLARE csr114 CURSOR FOR
454         SELECT k1.string_id FROM krbmap k1, krbmap k2
455         WHERE k1.string_id = k2.string_id AND k1.rowid != k2.rowid;
456       EXEC SQL OPEN csr114;
457       while (1)
458         {
459           EXEC SQL FETCH csr114 INTO :id;
460           if (sqlca.sqlcode)
461             break;
462
463           printf("Principal %d is in the krbmap more than once!\n", id);
464           printf("Not fixing this error\n");
465         }
466       EXEC SQL CLOSE csr114;
467     }
468
469   dprintf("Loading machines...\n");
470   sq = sq_create();
471   machines = create_hash(20000);
472   if (!sq || !machines)
473     out_of_mem("loading machines");
474
475   EXEC SQL DECLARE csr104 CURSOR FOR
476     SELECT mach_id, name, snet_id, owner_type, owner_id,
477     acomment, ocomment, creator, modby
478     FROM machine ORDER BY mach_id;
479   EXEC SQL OPEN csr104;
480   while (1)
481     {
482       EXEC SQL BEGIN DECLARE SECTION;
483       int mach_id, snet_id, owner_id, acomment, ocomment, creator, modby;
484       char name[MACHINE_NAME_SIZE], owner_type[MACHINE_OWNER_TYPE_SIZE];
485       EXEC SQL END DECLARE SECTION;
486
487       EXEC SQL FETCH csr104 INTO :mach_id, :name, :snet_id,
488         :owner_type, :owner_id, :acomment, :ocomment, :creator, :modby;
489       if (sqlca.sqlcode)
490         break;
491
492       m = malloc(sizeof(struct machine));
493       if (!m)
494         out_of_mem("storing machines");
495       strcpy(m->name, strtrim(name));
496       m->owner_type = owner_type[0];
497       m->owner_id = owner_id;
498       m->snet_id = snet_id;
499       m->mach_id = mach_id;
500       m->clucount = 0;
501       m->acomment = acomment;
502       m->ocomment = ocomment;
503       m->creator = creator;
504       m->modby = modby;
505       retval = hash_store(machines, mach_id, m);
506       if (retval == -1)
507         out_of_mem("storing machines in hash table");
508       else if (retval == 1)
509         {
510           sq_save_data(sq, hash_lookup(machines, mach_id));
511           sq_save_data(sq, m);
512         }
513     }
514   EXEC SQL CLOSE csr104;
515   generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0);
516
517   if (!fast)
518     {
519       EXEC SQL BEGIN DECLARE SECTION;
520       char name[HOSTALIAS_NAME_SIZE];
521       int id1, id2;
522       EXEC SQL END DECLARE SECTION;
523
524       sq = sq_create();
525       if (!sq)
526         out_of_mem("looking for duplicate machine names");
527
528       EXEC SQL DECLARE csr105 CURSOR FOR
529         SELECT m1.mach_id FROM machine m1, machine m2
530         WHERE m1.name = m2.name AND m1.rowid != m2.rowid;
531       EXEC SQL OPEN csr105;
532       while (1)
533         {
534           EXEC SQL FETCH csr105 INTO :id;
535           if (sqlca.sqlcode)
536             break;
537
538           sq_save_data(sq, hash_lookup(machines, id));
539         }
540       EXEC SQL CLOSE csr105;
541       generic_fix(sq, show_mach_name, "Change name", cant_fix, 0);
542
543       EXEC SQL DECLARE csr_hal1 CURSOR FOR
544         SELECT h1.name, m1.mach_id, m2.mach_id
545         FROM hostalias h1, machine m1, hostalias h2, machine m2
546         WHERE h1.name = h2.name AND h1.mach_id != h2.mach_id
547         AND m1.mach_id = h1.mach_id AND m2.mach_id = h2.mach_id;
548       EXEC SQL OPEN csr_hal1;
549       while (1)
550         {
551           EXEC SQL FETCH csr_hal1 INTO :name, :id1, :id2;
552           if (sqlca.sqlcode)
553             break;
554           printf("Aliases for machines %d and %d have duplicate name %s\n",
555                  id1, id2, strtrim(name));
556           cant_fix(0);
557         }
558       EXEC SQL CLOSE csr_hal1;
559
560       EXEC SQL DECLARE csr_hal2 CURSOR FOR
561         SELECT h1.name, m1.mach_id, m2.mach_id
562         FROM hostalias h1, machine m1, machine m2
563         WHERE h1.name = m1.name AND h1.mach_id = m2.mach_id;
564       EXEC SQL OPEN csr_hal2;
565         while (1)
566           {
567             EXEC SQL FETCH csr_hal2 INTO :name, :id1, :id2;
568             if (sqlca.sqlcode)
569               break;
570             printf("Machine %d has alias %s that conflicts with machine %d\n",
571                    id2, strtrim(name), id1);
572             cant_fix(0);
573           }
574         EXEC SQL CLOSE csr_hal2;
575     }
576
577   dprintf("Loading subnets...\n");
578   subnets = create_hash(254);
579   if (!subnets)
580     out_of_mem("loading subnets");
581
582   EXEC SQL DECLARE csr115 CURSOR FOR
583     SELECT snet_id, name, owner_type, owner_id, modby from subnet;
584   EXEC SQL OPEN csr115;
585   while (1)
586     {
587       EXEC SQL BEGIN DECLARE SECTION;
588       char name[SUBNET_NAME_SIZE], owner_type[SUBNET_OWNER_TYPE_SIZE];
589       int snet_id, owner_id, modby;
590       EXEC SQL END DECLARE SECTION;
591
592       EXEC SQL FETCH csr115 INTO :snet_id, :name, :owner_type,
593         :owner_id, :modby;
594       if (sqlca.sqlcode)
595         break;
596
597       sn = malloc(sizeof(struct machine));
598       if (!sn)
599         out_of_mem("storing subnets");
600       strcpy(sn->name, strtrim(name));
601       sn->owner_type = owner_type[0];
602       sn->owner_id = owner_id;
603       sn->snet_id = snet_id;
604       sn->modby = modby;
605       retval = hash_store(subnets, snet_id, sn);
606       if (retval == -1)
607         out_of_mem("storing subnets in hash table");
608       else if (retval == 1)
609         {
610           printf("Duplicate subnet ID: %d (%s)\n", id, name);
611           /* should add code to delete */
612           cant_fix(0);
613         }
614     }
615   EXEC SQL CLOSE csr115;
616
617   if (!fast)
618     {
619       sq = sq_create();
620       if (!sq)
621         out_of_mem("looking for duplicate subnet names");
622
623       EXEC SQL DECLARE csr117 CURSOR FOR
624         SELECT s1.snet_id FROM subnet s1, subnet s2
625         WHERE s1.name = s2.name AND s1.rowid != s2.rowid;
626       EXEC SQL OPEN csr117;
627       while (1)
628         {
629           EXEC SQL FETCH csr117 INTO :id;
630           if (sqlca.sqlcode)
631             break;
632
633           sq_save_data(sq, hash_lookup(subnets, id));
634         }
635       EXEC SQL CLOSE csr117;
636       generic_fix(sq, show_snet_name, "Change name", cant_fix, 0);
637     }
638
639   dprintf("Loading clusters...\n");
640   sq = sq_create();
641   clusters = create_hash(100);
642   if (!sq || !clusters)
643     out_of_mem("loading clusters");
644
645   EXEC SQL DECLARE csr106 CURSOR FOR
646     SELECT clu_id, name, modby FROM clusters;
647   EXEC SQL OPEN csr106;
648   while (1)
649     {
650       EXEC SQL BEGIN DECLARE SECTION;
651       int clu_id, modby;
652       char name[CLUSTERS_NAME_SIZE];
653       EXEC SQL END DECLARE SECTION;
654
655       EXEC SQL FETCH csr106 INTO :clu_id, :name, :modby;
656       if (sqlca.sqlcode)
657         break;
658
659       c = malloc(sizeof(struct cluster));
660       if (!c)
661         out_of_mem("storing clusters");
662       strcpy(c->name, strtrim(name));
663       c->clu_id = clu_id;
664       c->modby = modby;
665       retval = hash_store(clusters, clu_id, c);
666       if (retval == -1)
667         out_of_mem("storing clusters in hash table");
668       else if (retval == 1)
669         {
670           sq_save_data(sq, hash_lookup(clusters, clu_id));
671           sq_save_data(sq, c);
672         }
673     }
674   EXEC SQL CLOSE csr106;
675   generic_fix(sq, show_clu_id, "Change ID", fix_clu_id, 0);
676
677   if (!fast)
678     {
679       sq = sq_create();
680       if (!sq)
681         out_of_mem("looking for duplicate cluster names");
682
683       EXEC SQL DECLARE csr107 CURSOR FOR
684         SELECT c1.clu_id FROM clusters c1, clusters c2
685         WHERE c1.name = c2.name AND c1.rowid != c2.rowid;
686       EXEC SQL OPEN csr107;
687       while (1)
688         {
689           EXEC SQL FETCH csr107 INTO :id;
690           if (sqlca.sqlcode)
691             break;
692
693           sq_save_data(sq, hash_lookup(clusters, id));
694         }
695       EXEC SQL CLOSE csr107;
696       generic_fix(sq, show_clu_name, "Change name", cant_fix, 0);
697     }
698
699   dprintf("Loading lists...\n");
700   sq = sq_create();
701   lists = create_hash(50000);
702   if (!sq || !lists)
703     out_of_mem("loading lists");
704
705   EXEC SQL DECLARE csr108 CURSOR FOR
706     SELECT list_id, name, acl_id, acl_type, modby  FROM list
707     ORDER BY list_id;
708   EXEC SQL OPEN csr108;
709   while (1)
710     {
711       EXEC SQL BEGIN DECLARE SECTION;
712       int list_id, acl_id, modby;
713       char name[LIST_NAME_SIZE], acl_type[LIST_ACL_TYPE_SIZE];
714       EXEC SQL END DECLARE SECTION;
715
716       EXEC SQL FETCH csr108 INTO :list_id, :name, :acl_id, :acl_type, :modby;
717       if (sqlca.sqlcode)
718         break;
719       l = malloc(sizeof(struct list));
720       if (!l)
721         out_of_mem("storing lists");
722       strcpy(l->name, strtrim(name));
723       l->acl_type = acl_type[0];
724       l->acl_id = acl_id;
725       l->list_id = list_id;
726       l->modby = modby;
727       l->members = 0;
728       retval = hash_store(lists, list_id, l);
729       if (retval == -1)
730         out_of_mem("storing lists in hash table");
731       else if (retval == 1)
732         {
733           sq_save_data(sq, hash_lookup(lists, list_id));
734           sq_save_data(sq, l);
735         }
736     }
737   EXEC SQL CLOSE csr108;
738   generic_fix(sq, show_list_id, "Change ID", fix_list_id, 0);
739
740   if (!fast)
741     {
742       sq = sq_create();
743       if (!sq)
744         out_of_mem("looking for duplicate list names");
745
746       EXEC SQL DECLARE csr109 CURSOR FOR
747         SELECT l1.list_id FROM list l1, list l2
748         WHERE l1.name = l2.name AND l1.rowid != l2.rowid;
749       EXEC SQL OPEN csr109;
750       while (1)
751         {
752           EXEC SQL FETCH csr109 INTO :id;
753           if (sqlca.sqlcode)
754             break;
755
756           sq_save_data(sq, hash_lookup(lists, id));
757         }
758       EXEC SQL CLOSE csr109;
759       generic_fix(sq, show_list_name, "Change name", cant_fix, 0);
760     }
761
762   dprintf("Loading filesys...\n");
763   sq = sq_create();
764   filesys = create_hash(30000);
765   if (!sq || !filesys)
766     out_of_mem("loading filesys");
767
768   EXEC SQL DECLARE csr110 CURSOR FOR
769     SELECT filsys_id, label, owner, owners, phys_id, mach_id,
770     type, name, modby FROM filesys ORDER BY filsys_id;
771   EXEC SQL OPEN csr110;
772   while (1)
773     {
774       EXEC SQL BEGIN DECLARE SECTION;
775       int filsys_id, owner, owners, phys_id, mach_id, modby;
776       char label[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE];
777       char name[FILESYS_NAME_SIZE];
778       EXEC SQL END DECLARE SECTION;
779
780       EXEC SQL FETCH csr110 INTO :filsys_id, :label, :owner, :owners,
781         :phys_id, :mach_id, :type, :name, :modby;
782       if (sqlca.sqlcode)
783         break;
784
785       f = malloc(sizeof(struct filesys));
786       if (!f)
787         out_of_mem("storing filesystems");
788       strcpy(f->name, strtrim(label));
789       strcpy(f->dir, strtrim(name));
790       f->filsys_id = filsys_id;
791       f->owner = owner;
792       f->owners = owners;
793       f->phys_id = phys_id;
794       f->mach_id = mach_id;
795       f->type = type[0];
796       retval = hash_store(filesys, filsys_id, f);
797       if (retval == -1)
798         out_of_mem("storing filesys in hash table");
799       else if (retval == 1)
800         {
801           sq_save_data(sq, hash_lookup(filesys, filsys_id));
802           sq_save_data(sq, f);
803         }
804     }
805   EXEC SQL CLOSE csr110;
806
807   generic_fix(sq, show_fs_id, "Change ID", fix_fs_id, 0);
808
809   if (!fast)
810     {
811       sq = sq_create();
812       if (!sq)
813         out_of_mem("looking for duplicate filesys names");
814
815       EXEC SQL DECLARE csr118 CURSOR FOR
816         SELECT fs1.filsys_id FROM filesys fs1, filesys fs2
817         WHERE fs1.label = fs2.label AND fs1.rowid != fs2.rowid;
818       EXEC SQL OPEN csr118;
819       while (1)
820         {
821           EXEC SQL FETCH csr118 INTO :id;
822           if (sqlca.sqlcode)
823             break;
824
825           sq_save_data(sq, hash_lookup(filesys, id));
826         }
827       EXEC SQL CLOSE csr118;
828       generic_fix(sq, show_fs_name, "Change name", cant_fix, 0);
829     }
830
831   dprintf("Loading nfsphys...\n");
832   sq = sq_create();
833   nfsphys = create_hash(500);
834   if (!sq || !nfsphys)
835     out_of_mem("loading nfsphs");
836
837   EXEC SQL DECLARE csr111 CURSOR FOR
838     SELECT nfsphys_id, dir, mach_id, allocated, modby FROM nfsphys;
839   EXEC SQL OPEN csr111;
840   while (1)
841     {
842       EXEC SQL BEGIN DECLARE SECTION;
843       int nfsphys_id, mach_id, allocated, modby;
844       char dir[NFSPHYS_DIR_SIZE];
845       EXEC SQL END DECLARE SECTION;
846
847       EXEC SQL FETCH csr111 INTO :nfsphys_id, :dir, :mach_id,
848         :allocated, :modby;
849       if (sqlca.sqlcode)
850         break;
851
852       n = malloc(sizeof(struct nfsphys));
853       if (!n)
854         out_of_mem("storing nfsphys");
855       strcpy(n->dir, strtrim(dir));
856       n->mach_id = mach_id;
857       n->nfsphys_id = nfsphys_id;
858       n->allocated = allocated;
859       n->modby = modby;
860       n->count = 0;
861       retval = hash_store(nfsphys, nfsphys_id, n);
862       if (retval == -1)
863         out_of_mem("storing nfsphys in hash table");
864       else if (retval == 1)
865         {
866           sq_save_data(sq, hash_lookup(nfsphys, nfsphys_id));
867           sq_save_data(sq, n);
868         }
869     }
870   EXEC SQL CLOSE csr111;
871
872   generic_fix(sq, show_np_id, "Change ID", fix_np_id, 0);
873
874   if (!fast)
875     {
876       dprintf("Checking printers...\n");
877
878       EXEC SQL DECLARE csr119 CURSOR FOR
879         SELECT p1.name FROM printers p1, printers p2
880         WHERE ( p1.name = p2.name AND p1.rowid < p2.rowid )
881         OR ( p1.name = p2.duplexname );
882       EXEC SQL OPEN csr119;
883       while (1)
884         {
885           EXEC SQL BEGIN DECLARE SECTION;
886           char name[PRINTERS_NAME_SIZE];
887           EXEC SQL END DECLARE SECTION;
888
889           EXEC SQL FETCH csr119 INTO :name;
890           if (sqlca.sqlcode)
891             break;
892
893           printf("Printer %s has duplicate name\n", name);
894           cant_fix(0);
895         }
896       EXEC SQL CLOSE csr119;
897     }
898
899   dprintf("Loading printservers...\n");
900   printservers = create_hash(100);
901   if (!printservers)
902     out_of_mem("loading printservers");
903
904   EXEC SQL DECLARE csr_ps CURSOR FOR
905     SELECT mach_id, printer_types, owner_type, owner_id, lpc_acl, modby
906     FROM printservers;
907   EXEC SQL OPEN csr_ps;
908   while (1)
909     {
910       EXEC SQL BEGIN DECLARE SECTION;
911       int mach_id, printer_types, owner_id, lpc_acl, modby;
912       char owner_type[PRINTSERVERS_OWNER_TYPE_SIZE];
913       EXEC SQL END DECLARE SECTION;
914
915       EXEC SQL FETCH csr_ps INTO :mach_id, :printer_types, :owner_type,
916         :owner_id, :lpc_acl, :modby;
917       if (sqlca.sqlcode)
918         break;
919
920       ps = malloc(sizeof(struct printserver));
921       if (!ps)
922         out_of_mem("storing printserver");
923       ps->mach_id = mach_id;
924       ps->owner_type = owner_type[0];
925       ps->owner_id = owner_id;
926       ps->lpc_acl = lpc_acl;
927       ps->modby = modby;
928       retval = hash_store(printservers, mach_id, ps);
929       if (retval == -1)
930         out_of_mem("storing printserver in hash table");
931       else if (retval == 1)
932         {
933           printf("Duplicate printserver mach_id %d\n", mach_id);
934           cant_fix(0);
935         }
936     }
937   EXEC SQL CLOSE csr111;
938 }
This page took 0.147403 seconds and 5 git commands to generate.