From cfc4f91e74589a272a447d369ba82205403d34d4 Mon Sep 17 00:00:00 2001 From: danw Date: Mon, 23 Feb 1998 19:23:27 +0000 Subject: [PATCH] Use moira_schema.h (and check a few modby fields that were being missed) --- dbck/dbck.h | 21 +++-- dbck/dbck.pc | 32 ++----- dbck/phase1.pc | 194 ++++++++++++++++++++++++-------------- dbck/phase2.pc | 247 ++++++++++++++++++++++++++++++------------------- dbck/phase4.pc | 111 ---------------------- 5 files changed, 302 insertions(+), 303 deletions(-) diff --git a/dbck/dbck.h b/dbck/dbck.h index 873a45ae..2fcf4893 100644 --- a/dbck/dbck.h +++ b/dbck/dbck.h @@ -9,6 +9,7 @@ #include #include +#include #define MODE_ASK 1 #define MODE_NO 2 @@ -25,7 +26,7 @@ extern struct hash *filesys, *nfsphys, *strings, *subnets, *string_dups; #define dprintf if (debug) printf struct user { - char login[9]; + char login[USERS_LOGIN_SIZE]; char potype; char *fullname; int status; @@ -39,7 +40,7 @@ struct user { }; struct machine { - char name[33]; + char name[MACHINE_NAME_SIZE]; char owner_type; int owner_id; int snet_id; @@ -52,7 +53,7 @@ struct machine { }; struct subnet { - char name[33]; + char name[SUBNET_NAME_SIZE]; char owner_type; int owner_id; int snet_id; @@ -60,16 +61,17 @@ struct subnet { }; struct cluster { - char name[33]; + char name[CLUSTERS_NAME_SIZE]; int clu_id; int modby; }; struct list { - char name[33]; + char name[LIST_NAME_SIZE]; char acl_type; int list_id; - int acl_id; + int acl_id; + int modby; int members; }; @@ -80,8 +82,8 @@ struct string { }; struct filesys { - char name[33]; - char dir[81]; + char name[FILESYS_LABEL_SIZE]; + char dir[FILESYS_NAME_SIZE]; char type; int filsys_id; int mach_id; @@ -91,10 +93,11 @@ struct filesys { }; struct nfsphys { - char dir[33]; + char dir[NFSPHYS_DIR_SIZE]; int mach_id; int nfsphys_id; int allocated; + int modby; int count; }; diff --git a/dbck/dbck.pc b/dbck/dbck.pc index cef40d74..97b76af7 100644 --- a/dbck/dbck.pc +++ b/dbck/dbck.pc @@ -43,7 +43,6 @@ int main(int argc, char **argv) EXEC SQL BEGIN DECLARE SECTION; char *database; EXEC SQL END DECLARE SECTION; - int countonly = 0; struct sigaction sa; database = "moira"; @@ -70,9 +69,6 @@ int main(int argc, char **argv) case 'a': mode = MODE_ASK; break; - case 'c': - countonly++; - break; case 'f': fast++; break; @@ -80,7 +76,7 @@ int main(int argc, char **argv) warn = 0; break; default: - printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n", + printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-f] [-w] [database]\n", argv[0]); exit(1); } @@ -88,9 +84,7 @@ int main(int argc, char **argv) else database = *arg; } - if (countonly) - printf("Only doing counts\n"); - else if (fast) + if (fast) printf("Doing fast version (skipping some checks)\n"); if (mode == MODE_NO) printf("Will NOT modify the database\n"); @@ -123,20 +117,12 @@ int main(int argc, char **argv) /* Begin transaction here. */ - if (!countonly) - { - phase1(); - EXEC SQL COMMIT WORK; - phase2(); - EXEC SQL COMMIT WORK; - phase3(); - EXEC SQL COMMIT WORK; - } - else - { - count_only_setup(); - EXEC SQL COMMIT WORK; - } + phase1(); + EXEC SQL COMMIT WORK; + phase2(); + EXEC SQL COMMIT WORK; + phase3(); + EXEC SQL COMMIT WORK; phase4(); EXEC SQL COMMIT WORK; @@ -148,7 +134,7 @@ int main(int argc, char **argv) void dbmserr(void) { EXEC SQL BEGIN DECLARE SECTION; - char buf[512]; + char buf[256]; EXEC SQL END DECLARE SECTION; int bufsize = 256, msglength = 0; diff --git a/dbck/phase1.pc b/dbck/phase1.pc index 0e99899d..27b0add6 100644 --- a/dbck/phase1.pc +++ b/dbck/phase1.pc @@ -237,9 +237,7 @@ void print_dup_map(int key, void *data, void *hint) void phase1(void) { EXEC SQL BEGIN DECLARE SECTION; - char name[81], name1[81], last[17], first[17], buf[257]; - int id, id1, id2, id3, aid, aid2, status; - int sid, sid2, sid3, sid4, sid5; + int id; EXEC SQL END DECLARE SECTION; int i, q, retval, tmp; struct save_queue *sq; @@ -275,6 +273,10 @@ void phase1(void) q = 0; while (1) { + EXEC SQL BEGIN DECLARE SECTION; + int id1, id2; + EXEC SQL END DECLARE SECTION; + EXEC SQL FETCH csr116 INTO :id1, :id2; if (sqlca.sqlcode) break; @@ -308,6 +310,11 @@ void phase1(void) q = 0; while (1) { + EXEC SQL BEGIN DECLARE SECTION; + int id; + char buf[STRINGS_STRING_SIZE]; + EXEC SQL END DECLARE SECTION; + EXEC SQL FETCH csr101 INTO :id, :buf; if (sqlca.sqlcode) break; @@ -346,43 +353,52 @@ void phase1(void) EXEC SQL OPEN csr102; while (1) { - EXEC SQL FETCH csr102 INTO :id, :name, :last, :first, :status, - :buf, :id2, :id3, :sid, :sid2, :sid3, :sid4, :sid5; + EXEC SQL BEGIN DECLARE SECTION; + char login[USERS_LOGIN_SIZE], nbuf[USERS_FIRST_SIZE + USERS_LAST_SIZE]; + char last[USERS_LAST_SIZE], first[USERS_FIRST_SIZE]; + char potype[USERS_POTYPE_SIZE]; + int users_id, status, pop_id, box_id, modby, fmodby, pmodby; + int comments, sigwho; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr102 INTO :users_id, :login, :last, :first, + :status, :potype, :pop_id, :box_id, :modby, :fmodby, :pmodby, + :comments, :sigwho; if (sqlca.sqlcode) break; u = malloc(sizeof(struct user)); if (!u) out_of_mem("storing users"); - strcpy(u->login, strtrim(name)); - u->potype = buf[0]; - sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); - u->fullname = strdup(buf); + strcpy(u->login, strtrim(login)); + u->potype = potype[0]; + sprintf(nbuf, "%s, %s", strtrim(last), strtrim(first)); + u->fullname = strdup(nbuf); u->status = status; - u->users_id = id; - u->modby = sid; - u->fmodby = sid2; - u->pmodby = sid3; - u->comment = sid4; - u->sigwho = sid5; + u->users_id = users_id; + u->modby = modby; + u->fmodby = fmodby; + u->pmodby = pmodby; + u->comment = comments; + u->sigwho = sigwho; switch (u->potype) { case 'P': - u->pobox_id = id2; + u->pobox_id = pop_id; break; case 'S': /* If potype is SMTP, box_id is a string_id for the strings tbl */ - u->pobox_id = id3; + u->pobox_id = box_id; break; default: u->pobox_id = 0; } - retval = hash_store(users, id, u); + retval = hash_store(users, users_id, u); if (retval == -1) out_of_mem("storing users in hash table"); else if (retval == 1) { - sq_save_data(sq, hash_lookup(users, id)); + sq_save_data(sq, hash_lookup(users, users_id)); sq_save_data(sq, u); } } @@ -459,8 +475,13 @@ void phase1(void) EXEC SQL OPEN csr104; while (1) { - EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2, - :sid3, :sid4, :sid; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, snet_id, owner_id, acomment, ocomment, creator, modby; + char name[MACHINE_NAME_SIZE], owner_type[MACHINE_OWNER_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr104 INTO :mach_id, :name, :snet_id, + :owner_type, :owner_id, :acomment, :ocomment, :creator, :modby; if (sqlca.sqlcode) break; @@ -468,21 +489,21 @@ void phase1(void) if (!m) out_of_mem("storing machines"); strcpy(m->name, strtrim(name)); - m->owner_type = buf[0]; - m->owner_id = id3; - m->snet_id = id2; - m->mach_id = id; + m->owner_type = owner_type[0]; + m->owner_id = owner_id; + m->snet_id = snet_id; + m->mach_id = mach_id; m->clucount = 0; - m->acomment = sid2; - m->ocomment = sid3; - m->creator = sid4; - m->modby = sid; - retval = hash_store(machines, id, m); + m->acomment = acomment; + m->ocomment = ocomment; + m->creator = creator; + m->modby = modby; + retval = hash_store(machines, mach_id, m); if (retval == -1) out_of_mem("storing machines in hash table"); else if (retval == 1) { - sq_save_data(sq, hash_lookup(machines, id)); + sq_save_data(sq, hash_lookup(machines, mach_id)); sq_save_data(sq, m); } } @@ -491,6 +512,11 @@ void phase1(void) if (!fast) { + EXEC SQL BEGIN DECLARE SECTION; + char name[HOSTALIAS_NAME_SIZE]; + int id1, id2; + EXEC SQL END DECLARE SECTION; + sq = sq_create(); if (!sq) out_of_mem("looking for duplicate machine names"); @@ -554,7 +580,13 @@ void phase1(void) EXEC SQL OPEN csr115; while (1) { - EXEC SQL FETCH csr115 INTO :id, :name, :buf, :id2, :sid; + EXEC SQL BEGIN DECLARE SECTION; + char name[SUBNET_NAME_SIZE], owner_type[SUBNET_OWNER_TYPE_SIZE]; + int snet_id, owner_id, modby; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr115 INTO :snet_id, :name, :owner_type, + :owner_id, :modby; if (sqlca.sqlcode) break; @@ -562,11 +594,11 @@ void phase1(void) if (!sn) out_of_mem("storing subnets"); strcpy(sn->name, strtrim(name)); - sn->owner_type = buf[0]; - sn->owner_id = id2; - sn->snet_id = id; - sn->modby = sid; - retval = hash_store(subnets, id, sn); + sn->owner_type = owner_type[0]; + sn->owner_id = owner_id; + sn->snet_id = snet_id; + sn->modby = modby; + retval = hash_store(subnets, snet_id, sn); if (retval == -1) out_of_mem("storing subnets in hash table"); else if (retval == 1) @@ -611,7 +643,12 @@ void phase1(void) EXEC SQL OPEN csr106; while (1) { - EXEC SQL FETCH csr106 INTO :id, :name, :sid; + EXEC SQL BEGIN DECLARE SECTION; + int clu_id, modby; + char name[CLUSTERS_NAME_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr106 INTO :clu_id, :name, :modby; if (sqlca.sqlcode) break; @@ -619,14 +656,14 @@ void phase1(void) if (!c) out_of_mem("storing clusters"); strcpy(c->name, strtrim(name)); - c->clu_id = id; - c->modby = sid; - retval = hash_store(clusters, id, c); + c->clu_id = clu_id; + c->modby = modby; + retval = hash_store(clusters, clu_id, c); if (retval == -1) out_of_mem("storing clusters in hash table"); else if (retval == 1) { - sq_save_data(sq, hash_lookup(clusters, id)); + sq_save_data(sq, hash_lookup(clusters, clu_id)); sq_save_data(sq, c); } } @@ -667,23 +704,29 @@ void phase1(void) EXEC SQL OPEN csr108; while (1) { - EXEC SQL FETCH csr108 INTO :id, :name, :aid, :buf, :sid; + EXEC SQL BEGIN DECLARE SECTION; + int list_id, acl_id, modby; + char name[LIST_NAME_SIZE], acl_type[LIST_ACL_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr108 INTO :list_id, :name, :acl_id, :acl_type, :modby; if (sqlca.sqlcode) break; l = malloc(sizeof(struct list)); if (!l) out_of_mem("storing lists"); strcpy(l->name, strtrim(name)); - l->acl_type = buf[0]; - l->acl_id = aid; - l->list_id = id; + l->acl_type = acl_type[0]; + l->acl_id = acl_id; + l->list_id = list_id; + l->modby = modby; l->members = 0; - retval = hash_store(lists, id, l); + retval = hash_store(lists, list_id, l); if (retval == -1) out_of_mem("storing lists in hash table"); else if (retval == 1) { - sq_save_data(sq, hash_lookup(lists, id)); + sq_save_data(sq, hash_lookup(lists, list_id)); sq_save_data(sq, l); } } @@ -724,28 +767,34 @@ void phase1(void) EXEC SQL OPEN csr110; while (1) { - EXEC SQL FETCH csr110 INTO :id, :name, :aid, :aid2, :id2, :id3, - :buf, :name1, :sid; + EXEC SQL BEGIN DECLARE SECTION; + int filsys_id, owner, owners, phys_id, mach_id, modby; + char label[FILESYS_LABEL_SIZE], type[FILESYS_TYPE_SIZE]; + char name[FILESYS_NAME_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr110 INTO :filsys_id, :label, :owner, :owners, + :phys_id, :mach_id, :type, :name, :modby; if (sqlca.sqlcode) break; f = malloc(sizeof(struct filesys)); if (!f) out_of_mem("storing filesystems"); - strcpy(f->name, strtrim(name)); - strcpy(f->dir, strtrim(name1)); - f->filsys_id = id; - f->owner = aid; - f->owners = aid2; - f->phys_id = id2; - f->mach_id = id3; - f->type = buf[0]; - retval = hash_store(filesys, id, f); + strcpy(f->name, strtrim(label)); + strcpy(f->dir, strtrim(name)); + f->filsys_id = filsys_id; + f->owner = owner; + f->owners = owners; + f->phys_id = phys_id; + f->mach_id = mach_id; + f->type = type[0]; + retval = hash_store(filesys, filsys_id, f); if (retval == -1) out_of_mem("storing filesys in hash table"); else if (retval == 1) { - sq_save_data(sq, hash_lookup(filesys, id)); + sq_save_data(sq, hash_lookup(filesys, filsys_id)); sq_save_data(sq, f); } } @@ -786,24 +835,31 @@ void phase1(void) EXEC SQL OPEN csr111; while (1) { - EXEC SQL FETCH csr111 INTO :id, :name, :id2, :id3, :sid; + EXEC SQL BEGIN DECLARE SECTION; + int nfsphys_id, mach_id, allocated, modby; + char dir[NFSPHYS_DIR_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr111 INTO :nfsphys_id, :dir, :mach_id, + :allocated, :modby; if (sqlca.sqlcode) break; n = malloc(sizeof(struct nfsphys)); if (!n) out_of_mem("storing nfsphys"); - strcpy(n->dir, strtrim(name)); - n->mach_id = id2; - n->nfsphys_id = id; - n->allocated = id3; + strcpy(n->dir, strtrim(dir)); + n->mach_id = mach_id; + n->nfsphys_id = nfsphys_id; + n->allocated = allocated; + n->modby = modby; n->count = 0; - retval = hash_store(nfsphys, id, n); + retval = hash_store(nfsphys, nfsphys_id, n); if (retval == -1) out_of_mem("storing nfsphys in hash table"); else if (retval == 1) { - sq_save_data(sq, hash_lookup(nfsphys, id)); + sq_save_data(sq, hash_lookup(nfsphys, nfsphys_id)); sq_save_data(sq, n); } } @@ -819,6 +875,10 @@ void phase1(void) EXEC SQL OPEN csr119; while (1) { + EXEC SQL BEGIN DECLARE SECTION; + char name[PRINTCAP_NAME_SIZE]; + EXEC SQL END DECLARE SECTION; + EXEC SQL FETCH csr119 INTO :name; if (sqlca.sqlcode) break; diff --git a/dbck/phase2.pc b/dbck/phase2.pc index 8dddbd22..fd034752 100644 --- a/dbck/phase2.pc +++ b/dbck/phase2.pc @@ -80,7 +80,7 @@ int show_mcm_mach(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, found = 1; - char name[33]; + char name[CLUSTERS_NAME_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr201 CURSOR FOR @@ -106,7 +106,7 @@ int show_mcm_clu(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, found = 1; - char name[33]; + char name[MACHINE_NAME_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr202 CURSOR FOR @@ -133,7 +133,7 @@ int show_hostalias(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, found = 1; - char name[33]; + char name[HOSTALIAS_NAME_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr234 CURSOR FOR @@ -159,7 +159,7 @@ int show_pcap_mach(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, found = 1; - char name[33]; + char name[PRINTCAP_NAME_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr235 CURSOR FOR @@ -185,7 +185,7 @@ int show_pcap_quota(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, found = 1; - char name[33]; + char name[PRINTCAP_NAME_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr236 CURSOR FOR @@ -615,7 +615,7 @@ int show_svc(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, found = 1; - char label[17], data[33]; + char label[SVC_SERV_LABEL_SIZE], data[SVC_SERV_CLUSTER_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr203 CURSOR FOR @@ -642,6 +642,9 @@ void list_check(int id, void *list, void *hint) { struct list *l = list; + l->modby = maybe_fixup_modby(l->modby, id, l->name, "list", + "modby", "list_id"); + switch (l->acl_type) { case 'L': @@ -693,7 +696,7 @@ int show_member_list(void *id) { EXEC SQL BEGIN DECLARE SECTION; int mid, iid = (int)id, found = 1; - char mtype[9], *name = ""; + char mtype[IMEMBERS_MEMBER_TYPE_SIZE], *name = ""; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr204 CURSOR FOR @@ -887,7 +890,7 @@ void del_mem_krb(void *id) int show_sh(void *id) { EXEC SQL BEGIN DECLARE SECTION; - char name[33]; + char name[SERVERHOSTS_SERVICE_SIZE]; int iid = (int)id; EXEC SQL END DECLARE SECTION; int found = 1; @@ -1081,6 +1084,9 @@ void check_nfsphys(int id, void *nfsphys, void *hint) { struct nfsphys *n = nfsphys; + n->modby = maybe_fixup_modby(n->modby, id, n->dir, "nfsphys", + "modby", "nfsphys_id"); + if (!hash_lookup(machines, n->mach_id)) { printf("NFSphys %d(%s) on non-existant machine %d\n", @@ -1275,7 +1281,7 @@ int show_quota_nofs(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, id1, found = 1; - char type[9]; + char type[QUOTA_TYPE_SIZE]; EXEC SQL END DECLARE SECTION; EXEC SQL DECLARE csr214 CURSOR FOR @@ -1304,7 +1310,7 @@ int show_quota_wrongpid(void *id) { EXEC SQL BEGIN DECLARE SECTION; int iid = (int)id, id1, found = 1; - char type[9]; + char type[QUOTA_TYPE_SIZE]; EXEC SQL END DECLARE SECTION; struct filesys *f; @@ -1347,7 +1353,7 @@ void fix_quota_physid(void *id) int show_srv_user(void *id) { EXEC SQL BEGIN DECLARE SECTION; - char name[33]; + char name[SERVERS_NAME_SIZE]; int iid = (int)id; EXEC SQL END DECLARE SECTION; int found = 1; @@ -1373,7 +1379,7 @@ int show_srv_user(void *id) int show_srv_list(void *id) { EXEC SQL BEGIN DECLARE SECTION; - char name[33]; + char name[SERVERS_NAME_SIZE]; int iid = (int)id; EXEC SQL END DECLARE SECTION; int found = 1; @@ -1491,7 +1497,7 @@ int show_krb_str(void *id) int show_pdm_mach(void *id) { EXEC SQL BEGIN DECLARE SECTION; - char name[33]; + char name[PALLADIUM_NAME_SIZE]; int iid = (int)id; EXEC SQL END DECLARE SECTION; int found = 1; @@ -1518,10 +1524,6 @@ int show_pdm_mach(void *id) void phase2(void) { - EXEC SQL BEGIN DECLARE SECTION; - int id1, id2, id3, id4, id5; - char type[9], name[33]; - EXEC SQL END DECLARE SECTION; struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5; struct filesys *f; struct list *l; @@ -1550,14 +1552,18 @@ void phase2(void) EXEC SQL OPEN csr221; while (1) { - EXEC SQL FETCH csr221 INTO :id1, :id2; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, clu_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr221 INTO :mach_id, :clu_id; if (sqlca.sqlcode) break; - if (!(m = hash_lookup(machines, id1))) - sq_save_unique_data(sq1, (void *)id1); - else if (!hash_lookup(clusters, id2)) - sq_save_unique_data(sq2, (void *)id2); + if (!(m = hash_lookup(machines, mach_id))) + sq_save_unique_data(sq1, (void *)mach_id); + else if (!hash_lookup(clusters, clu_id)) + sq_save_unique_data(sq2, (void *)clu_id); if (m) m->clucount++; } @@ -1572,12 +1578,16 @@ void phase2(void) EXEC SQL OPEN csr222; while (1) { - EXEC SQL FETCH csr222 INTO :id1; + EXEC SQL BEGIN DECLARE SECTION; + int clu_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr222 INTO :clu_id; if (sqlca.sqlcode) break; - if (!hash_lookup(clusters, id1)) - sq_save_unique_data(sq1, (void *)id1); + if (!hash_lookup(clusters, clu_id)) + sq_save_unique_data(sq1, (void *)clu_id); } EXEC SQL CLOSE csr222; generic_delete(sq1, show_svc, "svc", "clu_id", 1); @@ -1598,20 +1608,26 @@ void phase2(void) EXEC SQL OPEN csr223; while (1) { - EXEC SQL FETCH csr223 INTO :id1, :type, :id2, :id3, :id4; + EXEC SQL BEGIN DECLARE SECTION; + int list_id, id, ref_count, direct; + char type[IMEMBERS_MEMBER_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr223 INTO :list_id, :type, :id, + :ref_count, :direct; if (sqlca.sqlcode) break; - if (!(l = hash_lookup(lists, id1))) - sq_save_unique_data(sq1, (void *)id1); - else if (type[0] == 'U' && !hash_lookup(users, id2)) - sq_save_unique_data(sq2, (void *)id2); - else if (type[0] == 'L' && !hash_lookup(lists, id2)) - sq_save_unique_data(sq3, (void *)id2); - else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id2)) - sq_save_unique_data(sq4, (void *)id2); - else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id2)) - sq_save_unique_data(sq5, (void *)id2); + if (!(l = hash_lookup(lists, list_id))) + sq_save_unique_data(sq1, (void *)list_id); + else if (type[0] == 'U' && !hash_lookup(users, id)) + sq_save_unique_data(sq2, (void *)id); + else if (type[0] == 'L' && !hash_lookup(lists, id)) + sq_save_unique_data(sq3, (void *)id); + else if (type[0] == 'S' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id)) + sq_save_unique_data(sq4, (void *)id); + else if (type[0] == 'K' && !maybe_fixup_unref_string2("imembers", "member_id", "csr223", id)) + sq_save_unique_data(sq5, (void *)id); else l->members++; } @@ -1631,16 +1647,21 @@ void phase2(void) EXEC SQL OPEN csr224; while (1) { - EXEC SQL FETCH csr224 INTO :name, :type, :id1, :id2; + EXEC SQL BEGIN DECLARE SECTION; + int acl_id, modby; + char name[SERVERS_NAME_SIZE], acl_type[SERVERS_ACL_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr224 INTO :name, :acl_type, :acl_id, :modby; if (sqlca.sqlcode) break; - maybe_fixup_modby2("servers", "modby", "csr224", id2); - strtrim(type); - if (!strcmp(type, "USER") && !hash_lookup(users, id1)) - sq_save_data(sq1, (void *)id1); - else if (!strcmp(type, "LIST") && !hash_lookup(lists, id1)) - sq_save_data(sq2, (void *)id1); + maybe_fixup_modby2("servers", "modby", "csr224", modby); + strtrim(acl_type); + if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id)) + sq_save_data(sq1, (void *)acl_id); + else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id)) + sq_save_data(sq2, (void *)acl_id); } EXEC SQL CLOSE csr224; generic_fix(sq1, show_srv_user, "Fix", zero_srv_user, 1); @@ -1654,13 +1675,17 @@ void phase2(void) EXEC SQL OPEN csr225; while (1) { - EXEC SQL FETCH csr225 INTO :id1, :id2; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, modby; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr225 INTO :mach_id, :modby; if (sqlca.sqlcode) break; - maybe_fixup_modby2("serverhosts", "modby", "csr225", id2); - if (!hash_lookup(machines, id1)) - sq_save_data(sq, (void *)id1); + maybe_fixup_modby2("serverhosts", "modby", "csr225", modby); + if (!hash_lookup(machines, mach_id)) + sq_save_data(sq, (void *)mach_id); } EXEC SQL CLOSE csr225; generic_fix(sq, show_sh, "Delete", del_sh_mach, 0); @@ -1680,14 +1705,18 @@ void phase2(void) EXEC SQL OPEN csr226; while (1) { - EXEC SQL FETCH csr226 INTO :id1, :id2; + EXEC SQL BEGIN DECLARE SECTION; + int group_id, filsys_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr226 INTO :group_id, :filsys_id; if (sqlca.sqlcode) break; - if (!(f = hash_lookup(filesys, id1))) - sq_save_data(sq1, (void *)id1); - if (!hash_lookup(filesys, id2)) - sq_save_data(sq3, (void *)id2); + if (!(f = hash_lookup(filesys, group_id))) + sq_save_data(sq1, (void *)group_id); + if (!hash_lookup(filesys, filsys_id)) + sq_save_data(sq3, (void *)filsys_id); } EXEC SQL CLOSE csr226; generic_delete(sq1, show_fsg_missing, "fsgroup", "group_id", 0); @@ -1704,21 +1733,27 @@ void phase2(void) EXEC SQL OPEN csr227; while (1) { - EXEC SQL FETCH csr227 INTO :id1, :type, :id2, :id3, :id4, :id5; + EXEC SQL BEGIN DECLARE SECTION; + int entity_id, filsys_id, phys_id, quota, modby; + char type[QUOTA_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr227 INTO :entity_id, :type, :filsys_id, + :phys_id, :quota, :modby; if (sqlca.sqlcode) break; - maybe_fixup_modby2("quota", "modby", "csr227", id5); - if (type[0] == 'U' && id1 != 0 && !hash_lookup(users, id1)) - sq_save_data(sq1, (void *)id1); - else if (type[0] == 'G' && !hash_lookup(lists, id1)) - sq_save_data(sq4, (void *)id1); - else if (!(f = hash_lookup(filesys, id2))) - sq_save_data(sq2, (void *)id2); - else if (id3 != f->phys_id || !(n = hash_lookup(nfsphys, id3))) - sq_save_data(sq3, (void *)id2); + maybe_fixup_modby2("quota", "modby", "csr227", modby); + if (type[0] == 'U' && entity_id != 0 && !hash_lookup(users, entity_id)) + sq_save_data(sq1, (void *)entity_id); + else if (type[0] == 'G' && !hash_lookup(lists, entity_id)) + sq_save_data(sq4, (void *)entity_id); + else if (!(f = hash_lookup(filesys, filsys_id))) + sq_save_data(sq2, (void *)filsys_id); + else if (phys_id != f->phys_id || !(n = hash_lookup(nfsphys, phys_id))) + sq_save_data(sq3, (void *)phys_id); else - n->count += id4; + n->count += quota; } EXEC SQL CLOSE csr227; generic_fix(sq1, show_quota_nouser, "Delete", fix_quota_nouser, 1); @@ -1735,25 +1770,30 @@ void phase2(void) EXEC SQL OPEN csr228; while (1) { - EXEC SQL FETCH csr228 INTO :id1, :type, :id2, :id3; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, acl_id, modby; + char acl_type[HOSTACCESS_ACL_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr228 INTO :mach_id, :acl_type, :acl_id, :modby; if (sqlca.sqlcode) break; - maybe_fixup_modby2("hostaccess", "modby", "csr228", id3); - strtrim(type); - if (!hash_lookup(machines, id1)) + maybe_fixup_modby2("hostaccess", "modby", "csr228", modby); + strtrim(acl_type); + if (!hash_lookup(machines, mach_id)) { - printf("Hostaccess for non-existant host %d\n", id1); + printf("Hostaccess for non-existant host %d\n", mach_id); printf("Not fixing this error\n"); } - if (!strcmp(type, "USER") && !hash_lookup(users, id2)) + if (!strcmp(acl_type, "USER") && !hash_lookup(users, acl_id)) { - printf("Hostaccess for %d is non-existant user %d\n", id1, id2); + printf("Hostaccess for %d is non-existant user %d\n", mach_id, acl_id); printf("Not fixing this error\n"); } - else if (!strcmp(type, "LIST") && !hash_lookup(lists, id2)) + else if (!strcmp(acl_type, "LIST") && !hash_lookup(lists, acl_id)) { - printf("Hostaccess for %d is non-existant list %d\n", id1, id2); + printf("Hostaccess for %d is non-existant list %d\n", mach_id, acl_id); printf("Not fixing this error\n"); } } @@ -1767,13 +1807,17 @@ void phase2(void) EXEC SQL OPEN csr229; while (1) { - EXEC SQL FETCH csr229 INTO :id1, :id2; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, modby; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr229 INTO :mach_id, :modby; if (sqlca.sqlcode) break; - maybe_fixup_modby2("palladium", "modby", "csr229", id2); - if (!hash_lookup(machines, id1)) - sq_save_unique_data(sq1, (void *)id1); + maybe_fixup_modby2("palladium", "modby", "csr229", modby); + if (!hash_lookup(machines, mach_id)) + sq_save_unique_data(sq1, (void *)mach_id); } EXEC SQL CLOSE csr229; generic_delete(sq1, show_pdm_mach, "palladium", "mach_id", 1); @@ -1787,14 +1831,18 @@ void phase2(void) EXEC SQL OPEN csr230; while (1) { - EXEC SQL FETCH csr230 INTO :id1, :id2; + EXEC SQL BEGIN DECLARE SECTION; + int users_id, string_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr230 INTO :users_id, :string_id; if (sqlca.sqlcode) break; - if (!hash_lookup(users, id1)) - sq_save_unique_data(sq1, (void *)id1); - else if (!maybe_fixup_unref_string2("krbmap", "string_id", "csr230", id2)) - sq_save_unique_data(sq2, (void *)id2); + if (!hash_lookup(users, users_id)) + sq_save_unique_data(sq1, (void *)users_id); + else if (!maybe_fixup_unref_string2("krbmap", "string_id", "csr230", string_id)) + sq_save_unique_data(sq2, (void *)string_id); } EXEC SQL CLOSE csr230; generic_delete(sq1, show_krb_usr, "krbmap", "users_id", 1); @@ -1806,13 +1854,18 @@ void phase2(void) EXEC SQL OPEN csr231; while (1) { - EXEC SQL FETCH csr231 INTO :id1, :name; + EXEC SQL BEGIN DECLARE SECTION; + int list_id; + char tag[CAPACLS_TAG_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr231 INTO :list_id, :tag; if (sqlca.sqlcode) break; - if (!hash_lookup(lists, id1)) + if (!hash_lookup(lists, list_id)) { - printf("Capacl for %s is non-existant list %d\n", name, id1); + printf("Capacl for %s is non-existant list %d\n", tag, list_id); printf("Not fixing this error\n"); } } @@ -1825,12 +1878,16 @@ void phase2(void) EXEC SQL OPEN csr232; while (1) { - EXEC SQL FETCH csr232 INTO :id1; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr232 INTO :mach_id; if (sqlca.sqlcode) break; - if (!hash_lookup(machines, id1)) - sq_save_unique_data(sq1, (void *)id1); + if (!hash_lookup(machines, mach_id)) + sq_save_unique_data(sq1, (void *)mach_id); } EXEC SQL CLOSE csr232; generic_delete(sq1, show_hostalias, "hostalias", "mach_id", 1); @@ -1843,15 +1900,19 @@ void phase2(void) EXEC SQL OPEN csr233; while (1) { - EXEC SQL FETCH csr233 INTO :id1, :id2, :id3; + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, quotaserver, modby; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr233 INTO :mach_id, :quotaserver, :modby; if (sqlca.sqlcode) break; - maybe_fixup_modby2("printcap", "modby", "csr233", id3); - if (!hash_lookup(machines, id1)) - sq_save_unique_data(sq1, (void *)id1); - else if (!hash_lookup(machines, id2)) - sq_save_unique_data(sq2, (void *)id2); + maybe_fixup_modby2("printcap", "modby", "csr233", modby); + if (!hash_lookup(machines, mach_id)) + sq_save_unique_data(sq1, (void *)mach_id); + else if (!hash_lookup(machines, quotaserver)) + sq_save_unique_data(sq2, (void *)quotaserver); } EXEC SQL CLOSE csr233; generic_delete(sq1, show_pcap_mach, "printcap", "mach_id", 1); diff --git a/dbck/phase4.pc b/dbck/phase4.pc index 9aba12e0..052f5c28 100644 --- a/dbck/phase4.pc +++ b/dbck/phase4.pc @@ -133,114 +133,3 @@ void phase4(void) dprintf("Doing NFSphys...\n"); hash_step(nfsphys, check_nfs_counts, 0); } - - -void count_only_setup(void) -{ - EXEC SQL BEGIN DECLARE SECTION; - int id, status, id2, id3; - char name[33], last[17], first[17], buf[257]; - EXEC SQL END DECLARE SECTION; - struct user *u; - struct nfsphys *n; - struct machine *m; - - dprintf("Loading users...\n"); - users = create_hash(30000); - EXEC SQL DECLARE csr402 CURSOR FOR - SELECT users_id, login, last, first, status, - potype, pop_id, box_id FROM users - WHERE potype = 'POP'; - EXEC SQL OPEN csr402; - while (1) - { - EXEC SQL FETCH csr402 INTO :id, :name, :last, :first, :status, - :buf, :id2, :id3; - if (sqlca.sqlcode) - break; - - u = malloc(sizeof(struct user)); - if (!u) - out_of_mem("storing users"); - strcpy(u->login, strtrim(name)); - u->potype = buf[0]; - sprintf(buf, "%s, %s", strtrim(last), strtrim(first)); - u->fullname = strdup(buf); - u->status = status; - u->users_id = id; - switch (u->potype) - { - case 'P': - u->pobox_id = id2; - break; - case 'S': - u->pobox_id = id3; - break; - default: - u->pobox_id = 0; - } - if (hash_store(users, id, u) == -1) - out_of_mem("storing users in hash table"); - } - EXEC SQL CLOSE csr402; - - dprintf("Loading machines...\n"); - machines = create_hash(20000); - EXEC SQL DECLARE csr403 CURSOR FOR - SELECT mach_id, name FROM machine; - EXEC SQL OPEN csr403; - while (1) - { - EXEC SQL FETCH csr403 INTO :id, :name; - if (sqlca.sqlcode) - break; - - m = malloc(sizeof(struct machine)); - if (!m) - out_of_mem("storing machines"); - strcpy(m->name, strtrim(name)); - m->mach_id = id; - if (hash_store(machines, id, m) == -1) - out_of_mem("storing users in hash table"); - } - EXEC SQL CLOSE csr403; - - dprintf("Loading nfsphys...\n"); - nfsphys = create_hash(500); - EXEC SQL DECLARE csr404 CURSOR FOR - SELECT nfsphys_id, dir, mach_id, allocated FROM nfsphys; - EXEC SQL OPEN csr404; - while (1) - { - EXEC SQL FETCH csr404 INTO :id, :name, :id2, :id3; - if (sqlca.sqlcode) - break; - - n = malloc(sizeof(struct nfsphys)); - if (!n) - out_of_mem("storing nfsphys"); - strcpy(n->dir, strtrim(name)); - n->mach_id = id2; - n->nfsphys_id = id; - n->allocated = id3; - n->count = 0; - if (hash_store(nfsphys, id, n) == -1) - out_of_mem("storing nfsphys in hash table"); - } - EXEC SQL CLOSE csr404; - - dprintf("Counting quotas...\n"); - EXEC SQL DECLARE csr405 CURSOR FOR - SELECT phys_id, quota FROM quota; - EXEC SQL OPEN csr405; - while (1) - { - EXEC SQL FETCH csr405 INTO :id, :id2; - if (sqlca.sqlcode) - break; - - if ((n = hash_lookup(nfsphys, id))) - n->count += id2; - } - EXEC SQL CLOSE csr405; -} -- 2.45.2