From: mar Date: Tue, 26 Oct 1993 16:42:47 +0000 (+0000) Subject: check new hosttable info X-Git-Tag: release77~88 X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/772b7afc00b0b2254cd317d78c41527442be565c check new hosttable info --- diff --git a/dbck/FIXES b/dbck/FIXES index fb1cca78..a1648de5 100644 --- a/dbck/FIXES +++ b/dbck/FIXES @@ -11,6 +11,8 @@ PHASE 1: looking for duplicates Each mach_id must be unique Alloc new ID * Each machine name must be unique (if -f flag not specified) + Each snet_id must be unique + Alloc new ID Each clu_id must be unique Alloc new ID * Each cluster must have a unique name (if -f flag not specified) @@ -52,6 +54,10 @@ P Every STRING member must be a real string Delete the member P Every KERBEROS member must be a real string Delete the member +P Every machine owner must exist + Set dummy owner +P Every machine must be on a subnet + Set to placeholder subnet P Every service USER owner must be a real user Make user 0 own service P Every service LIST owner must be a real list diff --git a/dbck/dbck.dc b/dbck/dbck.dc index f2405717..525d567a 100644 --- a/dbck/dbck.dc +++ b/dbck/dbck.dc @@ -23,7 +23,7 @@ int fast = 0; int warn = 1; int abort_p = 0; struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys; -struct hash *strings, *members; +struct hash *strings, *members, *subnets; EXEC SQL BEGIN DECLARE SECTION; int dcmenable; EXEC SQL END DECLARE SECTION; diff --git a/dbck/dbck.h b/dbck/dbck.h index f876ebbd..1cad37ce 100644 --- a/dbck/dbck.h +++ b/dbck/dbck.h @@ -19,7 +19,7 @@ extern int debug, mode, fast, dcmenable, warn; extern struct hash *users, *machines, *clusters, *lists; -extern struct hash *filesys, *nfsphys, *strings; +extern struct hash *filesys, *nfsphys, *strings, *subnets; #define MAX_ID_VALUE 32765 #define MIN_ID_VALUE 100 @@ -37,8 +37,12 @@ struct user { struct machine { char name[33]; + char owner_type; + int owner_id; + int snet_id; int mach_id; int clucount; + }; struct cluster { diff --git a/dbck/phase1.dc b/dbck/phase1.dc index 60256c0b..a937cebe 100644 --- a/dbck/phase1.dc +++ b/dbck/phase1.dc @@ -306,11 +306,14 @@ phase1() sq = sq_create(); EXEC SQL DECLARE csr104 CURSOR FOR - SELECT mach_id, name, modby FROM machine ORDER BY mach_id; + SELECT mach_id, name, snet_id, owner_type, owner_id, + acomment, ocomment, creator, modby + FROM machine ORDER BY mach_id; if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); EXEC SQL OPEN csr104; while(1) { - EXEC SQL FETCH csr104 INTO :id, :name, :sid; + EXEC SQL FETCH csr104 INTO :id, :name, :id2, :buf, :id3, :sid2, + :sid3, :sid4, :sid; if (sqlca.sqlcode != 0) { ingerr(&sqlca.sqlcode); break; @@ -320,14 +323,19 @@ phase1() if (m == NULL) 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->clucount = 0; if (hash_store(machines, id, m)) { sq_save_data(sq, hash_lookup(machines, id)); sq_save_data(sq, m); } - if (sid < 0) - string_check(-sid); + if (sid2) string_check(sid2); + if (sid3) string_check(sid3); + if (sid4 < 0) string_check(-sid4); + if (sid < 0) string_check(-sid); } EXEC SQL CLOSE csr104; generic_fix(sq, show_mach_id, "Change ID", fix_mach_id, 0); @@ -353,6 +361,25 @@ phase1() generic_fix(sq, show_mach_name, "Change name", cant_fix, 0); } + dprintf("Loading subnets...\n"); + subnets = create_hash(254); + + EXEC SQL DECLARE csr115 CURSOR FOR + SELECT snet_id, name from subnet; + if (sqlca.sqlcode != 0) ingerr(&sqlca.sqlcode); + EXEC SQL OPEN csr115; + while(1) { + EXEC SQL FETCH csr115 INTO :id, :name; + if (sqlca.sqlcode != 0) { + ingerr(&sqlca.sqlcode); + break; + } + if (hash_store(subnets, id, name)) { + printf("Duplicate subnet ID: %d (%s)\n", id, name); + } + } + EXEC SQL CLOSE csr115; + dprintf("Loading clusters...\n"); sq = sq_create(); clusters = create_hash(100); diff --git a/dbck/phase2.dc b/dbck/phase2.dc index c5b977bc..a9aea9d6 100644 --- a/dbck/phase2.dc +++ b/dbck/phase2.dc @@ -118,6 +118,71 @@ int id; modified("users"); } + +mach_check(id, m, hint) +int id; +struct machine *m; +int hint; +{ + if (!hash_lookup(subnets, m->snet_id)) { + printf("Machine %s is on a non-existant subnet %d\n", + m->name, m->snet_id); + if (single_fix("Move to null-subnet", 1)) { + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, iid = id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE machine SET snet_id=0 WHERE mach_id = :iid; + EXEC SQL INQUIRE_SQL(:rowcount = rowcount); + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); + else + printf("Not fixed\n"); + modified("machine"); + } + } + + switch (m->owner_type) { + case 'U': + if (!hash_lookup(users, m->owner_id)) { + printf("Machine %s has non-existant USER owner %d\n", + m->name, m->owner_id); + if (single_fix("Set to no owner", 1)) { + clear_mach_owner(m); + } + } + break; + case 'L': + if (!hash_lookup(lists, m->owner_id)) { + printf("Machine %s has non-existant LIST owner %d\n", + m->name, m->owner_id); + if (single_fix("Set to no owner", 1)) { + clear_mach_owner(m); + } + } + break; + } +} + + +clear_mach_owner(m) +struct machine *m; +{ + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id = m->mach_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE machine SET owner_type='NONE', owner_id=0 + WHERE mach_id = :id; + EXEC SQL INQUIRE_SQL(:rowcount = rowcount); + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount==1?"y":"ies"); + else + printf("Not fixed\n"); + modified("machine"); +} + + show_svc(id) int id; { @@ -1124,6 +1189,9 @@ phase2() dprintf("Checking users...\n"); hash_step(users, pobox_check, NULL); + dprintf("Checking machines...\n"); + hash_step(machines, mach_check, NULL); + dprintf("Checking mcmap...\n"); sq1 = sq_create(); sq2 = sq_create();