From: danw Date: Thu, 13 Jan 2000 01:39:45 +0000 (+0000) Subject: check printservers X-Git-Url: http://andersk.mit.edu/gitweb/moira.git/commitdiff_plain/fe0a844a056f5f9d887251364966d6a4dee16800 check printservers --- diff --git a/dbck/FIXES b/dbck/FIXES index 351000f0..311fb59f 100644 --- a/dbck/FIXES +++ b/dbck/FIXES @@ -37,6 +37,7 @@ F* Each filesys name must be unique Each string_id must be unique Delete all copies F* Each printer name must be unique + * Each printserver entry must be for a unique mach_id PHASE 2: checking references @@ -109,10 +110,20 @@ P Every quota's phys_id must match the filesys' phys_id * Every hostaccess LIST must exist Every printer must have real printer, spool, and quota machines Delete the printer + Every print must be on a printserver + Delete the printer * Every printer must have a real log machine Reset to WSLOGGER.MIT.EDU Every print ac/lpc_acl must exist Make it list 0 + Every printserver must correspond to an existing machine + Delete printserver + Every printserver printer_types must be a real string + Set to empty string + Every printserver owner must be a real user/list/kerberos + Set to NONE + Every printserver lpc_acl must be a real list + Set to list 0 P Every user in the krbmap must exist Delete map entry P Every string in the krbmap must exist diff --git a/dbck/dbck.h b/dbck/dbck.h index 2fcf4893..07c4414b 100644 --- a/dbck/dbck.h +++ b/dbck/dbck.h @@ -17,7 +17,7 @@ #define MODE_YES 4 extern int debug, mode, fast, dcmenable, warn; -extern struct hash *users, *machines, *clusters, *lists; +extern struct hash *users, *machines, *clusters, *lists, *printservers; extern struct hash *filesys, *nfsphys, *strings, *subnets, *string_dups; #define MAX_ID_VALUE 32765 @@ -101,6 +101,15 @@ struct nfsphys { int count; }; +struct printserver { + int mach_id; + int printer_types; + char owner_type; + int owner_id; + int lpc_acl; + int modby; +}; + void dbmserr(void); void out_of_mem(char *msg); void cleanup(void); diff --git a/dbck/dbck.pc b/dbck/dbck.pc index 3ebc691a..3f68472e 100644 --- a/dbck/dbck.pc +++ b/dbck/dbck.pc @@ -26,7 +26,7 @@ int fast = 0; int warn = 1; int abort_p = 0; struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys; -struct hash *strings, *members, *subnets, *string_dups; +struct hash *strings, *members, *subnets, *string_dups, *printservers; EXEC SQL BEGIN DECLARE SECTION; int dcmenable; EXEC SQL END DECLARE SECTION; @@ -50,7 +50,7 @@ int main(int argc, char **argv) while (++arg - argv < argc) { - if (**arg == '-') + if (**arg == '-') { switch ((*arg)[1]) { diff --git a/dbck/phase1.pc b/dbck/phase1.pc index 38a16a5f..5a1c15de 100644 --- a/dbck/phase1.pc +++ b/dbck/phase1.pc @@ -249,6 +249,7 @@ void phase1(void) struct string *s; struct filesys *f; struct nfsphys *n; + struct printserver *ps; printf("Phase 1 - Looking for duplicates\n"); @@ -894,4 +895,44 @@ void phase1(void) } EXEC SQL CLOSE csr119; } + + dprintf("Loading printservers...\n"); + printservers = create_hash(100); + if (!printservers) + out_of_mem("loading printservers"); + + EXEC SQL DECLARE csr_ps CURSOR FOR + SELECT mach_id, printer_types, owner_type, owner_id, lpc_acl, modby + FROM printservers; + EXEC SQL OPEN csr_ps; + while (1) + { + EXEC SQL BEGIN DECLARE SECTION; + int mach_id, printer_types, owner_id, lpc_acl, modby; + char owner_type[PRINTSERVERS_OWNER_TYPE_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL FETCH csr_ps INTO :mach_id, :printer_types, :owner_type, + :owner_id, :lpc_acl, :modby; + if (sqlca.sqlcode) + break; + + ps = malloc(sizeof(struct printserver)); + if (!ps) + out_of_mem("storing printserver"); + ps->mach_id = mach_id; + ps->owner_type = owner_type[0]; + ps->owner_id = owner_id; + ps->lpc_acl = lpc_acl; + ps->modby = modby; + retval = hash_store(printservers, mach_id, ps); + if (retval == -1) + out_of_mem("storing printserver in hash table"); + else if (retval == 1) + { + printf("Duplicate printserver mach_id %d\n", mach_id); + cant_fix(0); + } + } + EXEC SQL CLOSE csr111; } diff --git a/dbck/phase2.pc b/dbck/phase2.pc index 89982100..9bc0d6c3 100644 --- a/dbck/phase2.pc +++ b/dbck/phase2.pc @@ -23,6 +23,7 @@ int show_mcm_mach(void *id); int show_mcm_clu(void *id); int show_hostalias(void *id); int show_printer_mach(void *id); +int show_printer_server(void *id); int show_printer_loghost(void *id); int show_printer_spool(void *id); int show_printer_quota(void *id); @@ -62,6 +63,7 @@ void del_sh_mach(void *id); void fsmatch(int id, void *nfsphys, void *filesys); void check_fs(int id, void *filesys, void *hint); void check_nfsphys(int id, void *nfsphys, void *hint); +void check_ps(int id, void *printserver, void *hint); int show_fsg_missing(void *id); int show_fsg_type(void *filesys); void fix_fsg_type(void *filesys); @@ -187,6 +189,32 @@ int show_printer_mach(void *id) return found; } +int show_printer_server(void *id) +{ + EXEC SQL BEGIN DECLARE SECTION; + int iid = (int)id, found = 1; + char name[PRINTERS_NAME_SIZE]; + EXEC SQL END DECLARE SECTION; + + EXEC SQL DECLARE csr_sps CURSOR FOR + SELECT name FROM printers WHERE mach_id = :iid; + EXEC SQL OPEN csr_sps; + while (1) + { + EXEC SQL FETCH csr_sps INTO :name; + if (sqlca.sqlcode) + break; + + strtrim(name); + + found = 0; + printf("Printer %s, non-existant printserver %d in printers table\n", + name, iid); + } + EXEC SQL CLOSE csr_sps; + return found; +} + int show_printer_loghost(void *id) { EXEC SQL BEGIN DECLARE SECTION; @@ -1295,6 +1323,103 @@ void check_nfsphys(int id, void *nfsphys, void *hint) } } +static void clear_ps_owner(struct printserver *ps) +{ + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id = ps->mach_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE printserver SET owner_type = 'NONE', owner_id = 0 + WHERE mach_id = :id; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("printservers"); +} + +static void clear_ps_lpc(struct printserver *ps) +{ + EXEC SQL BEGIN DECLARE SECTION; + int rowcount, id = ps->mach_id; + EXEC SQL END DECLARE SECTION; + + EXEC SQL UPDATE printserver SET lpc_acl = 0 + WHERE mach_id = :id; + rowcount = sqlca.sqlerrd[2]; + if (rowcount > 0) + printf("%d entr%s fixed\n", rowcount, rowcount == 1 ? "y" : "ies"); + else + printf("Not fixed\n"); + modified("printservers"); +} + +void check_ps(int id, void *printserver, void *hint) +{ + struct printserver *ps = printserver; + struct machine *m; + char *name; + + m = hash_lookup(machines, id); + if (!m) + { + printf("Printserver on non-existant machine %d\n", id); + if (single_fix("Delete", 0)) + { + single_delete("printserver", "mach_id", id); + return; + } + else + name = "[UNKNOWN]"; + } + else + name = m->name; + + ps->modby = maybe_fixup_modby(ps->modby, id, name, "printserver", + "modby", "mach_id"); + ps->printer_types = maybe_fixup_unref_string(ps->printer_types, id, name, + "printservers", "printer_types", + "mach_id"); + + switch (ps->owner_type) + { + case 'U': + if (!hash_lookup(users, ps->owner_id)) + { + printf("Printserver %s has non-existant USER owner %d\n", + name, ps->owner_id); + if (single_fix("Set to no owner", 1)) + clear_ps_owner(ps); + } + break; + case 'L': + if (!hash_lookup(lists, ps->owner_id)) + { + printf("Printserver %s has non-existant LIST owner %d\n", + name, ps->owner_id); + if (single_fix("Set to no owner", 1)) + clear_ps_owner(ps); + } + break; + case 'K': + if (ps->owner_id) + ps->owner_id = maybe_fixup_unref_string(ps->owner_id, id, name, + "printserver", "owner_id", + "mach_id"); + if (ps->owner_id == 0) + clear_ps_owner(ps); + } + + if (!hash_lookup(lists, ps->lpc_acl)) + { + printf("Printserver %s has non-existent lpc_acl %d\n", + name, ps->lpc_acl); + if (single_fix("Set to no lpc_acl", 1)) + clear_ps_lpc(ps); + } +} + int show_fsg_missing(void *id) { EXEC SQL BEGIN DECLARE SECTION; @@ -1693,7 +1818,7 @@ int show_krb_str(void *id) void phase2(void) { - struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5; + struct save_queue *sq, *sq1, *sq2, *sq3, *sq4, *sq5, *sq6; struct filesys *f; struct list *l; struct nfsphys *n; @@ -2045,6 +2170,7 @@ void phase2(void) sq3 = sq_create(); sq4 = sq_create(); sq5 = sq_create(); + sq6 = sq_create(); EXEC SQL DECLARE csr233 CURSOR FOR SELECT mach_id, loghost, rm, rq, ac, lpc_acl, modby, rowid FROM printers; EXEC SQL OPEN csr233; @@ -2064,6 +2190,8 @@ void phase2(void) sq_save_unique_data(sq1, (void *)mach_id); else if (!hash_lookup(machines, rm)) sq_save_unique_data(sq2, (void *)rm); + else if (!hash_lookup(printservers, rm)) + sq_save_unique_data(sq6, (void *)mach_id); else if (!hash_lookup(machines, rq)) sq_save_unique_data(sq3, (void *)rq); else { @@ -2080,9 +2208,13 @@ void phase2(void) } EXEC SQL CLOSE csr233; generic_delete(sq1, show_printer_mach, "printers", "mach_id", 1); + generic_delete(sq6, show_printer_server, "printers", "mach_id", 1); generic_delete(sq2, show_printer_spool, "printers", "rm", 1); generic_delete(sq3, show_printer_quota, "printers", "rq", 1); generic_fix(sq4, show_printer_ac, "Clear", fix_printer_ac, 1); generic_fix(sq5, show_printer_lpc_acl, "Clear", fix_printer_lpc_acl, 1); + + dprintf("Checking printservers\n"); + hash_step(printservers, check_ps, NULL); }