Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: binary MIME-Version: 1.0 X-Mailer: MIME-tools 5.411 (Entity 5.404) X-RT-Original-Encoding: iso-8859-1 Content-Length: 7240 From jik@kamens.brookline.ma.us Wed Feb 12 12:16:35 1997 Received: from MIT.EDU (PACIFIC-CARRIER-ANNEX.MIT.EDU [18.69.0.28]) by rt-11.MIT.EDU (8.7.5/8.7.3) with SMTP id MAA10162 for ; Wed, 12 Feb 1997 12:16:35 -0500 Received: from jik.saturn.net by MIT.EDU with SMTP id AA22887; Wed, 12 Feb 97 12:16:32 EST Received: (from jik@localhost) by jik.saturn.net (8.8.4/8.8.4) id MAA22859; Wed, 12 Feb 1997 12:20:21 -0500 Message-Id: <199702121720.MAA22859@jik.saturn.net> Date: Wed, 12 Feb 1997 12:20:21 -0500 From: "Jonathan I. Kamens" Reply-To: jik@kamens.brookline.ma.us To: krb5-bugs@MIT.EDU Subject: keytab library should cache most-recently-used keytab entry X-Send-Pr-Version: 3.99 >Number: 371 >Category: krb5-libs >Synopsis: keytab library should cache most-recently-used keytab entry >Confidential: no >Severity: non-critical >Priority: low >Responsible: krb5-unassigned >State: open >Class: sw-bug >Submitter-Id: unknown >Arrival-Date: Wed Feb 12 12:17:01 EST 1997 >Last-Modified: Mon Aug 11 16:04:00 EDT 1997 >Originator: Jonathan I. Kamens >Organization: OpenVision Technologies, Inc. >Release: 1.0 >Environment: N/A >Description: The speed of krb5_kt_get_entry() for persistent applications can be greatly improved by making it cache the keytab entry most recently returned to a caller, so that if a subsequent request is for the same keytab entry, it can be returned without needing to open and scan the keytab file again. This doesn't provide a significant performance improvement on systems which cache files in memory and whose disks aren't very busy, but it will improve performance on systems which don't cache files and/or which are busy enough that the keytab file isn't kept in the cache all the time. >How-To-Repeat: >Fix: --- krb5-1.0/src/lib/krb5/keytab/file/ktf_close.c Thu Apr 13 20:53:11 1995 +++ krb5-1.0/src/lib/krb5/keytab/file/ktf_close.c Wed Feb 12 09:30:54 1997 @@ -41,6 +41,8 @@ */ { krb5_xfree(KTFILENAME(id)); + if (KTCACHE(id).magic) + krb5_kt_free_entry(context, &KTCACHE(id)); krb5_xfree(id->data); id->ops = 0; krb5_xfree(id); --- krb5-1.0/src/lib/krb5/keytab/file/ktf_g_ent.c Tue Nov 19 17:07:30 1996 +++ krb5-1.0/src/lib/krb5/keytab/file/ktf_g_ent.c Wed Feb 12 09:17:08 1997 @@ -41,6 +41,42 @@ krb5_keytab_entry cur_entry, new_entry; krb5_error_code kerror = 0; int found_wrong_kvno = 0; + krb5_enctype entry_type; + + switch (enctype) { + case ENCTYPE_DES_CBC_CRC: + case ENCTYPE_DES_CBC_MD5: + case ENCTYPE_DES_CBC_MD4: + case ENCTYPE_DES_CBC_RAW: + enctype = ENCTYPE_DES_CBC_CRC; + break; + } + + if (KTCACHE(id).magic) { + new_entry = KTCACHE(id); + + entry_type = new_entry.key.enctype; + switch(entry_type) { + case ENCTYPE_DES_CBC_CRC: + case ENCTYPE_DES_CBC_MD5: + case ENCTYPE_DES_CBC_MD4: + case ENCTYPE_DES_CBC_RAW: + entry_type = ENCTYPE_DES_CBC_CRC; + break; + } + + if (((enctype == IGNORE_ENCTYPE) || (enctype == entry_type)) && + krb5_principal_compare(context, principal, new_entry.principal) && + ((kvno == IGNORE_VNO) || (kvno == new_entry.vno))) { + if ((kerror = krb5_ktfileint_copy_entry(context, &new_entry, entry))) + return(kerror); + return 0; + } + else { + krb5_kt_free_entry(context, &new_entry); + KTCACHE(id).magic = 0; + } + } /* Open the keyfile for reading */ if ((kerror = krb5_ktfileint_openr(context, id))) @@ -54,20 +90,9 @@ cur_entry.vno = 0; cur_entry.key.contents = 0; while (TRUE) { - krb5_enctype entry_type; - if ((kerror = krb5_ktfileint_read_entry(context, id, &new_entry))) break; - switch (enctype) { - case ENCTYPE_DES_CBC_CRC: - case ENCTYPE_DES_CBC_MD5: - case ENCTYPE_DES_CBC_MD4: - case ENCTYPE_DES_CBC_RAW: - enctype = ENCTYPE_DES_CBC_CRC; - break; - } - entry_type = new_entry.key.enctype; switch(entry_type) { case ENCTYPE_DES_CBC_CRC: @@ -118,5 +143,6 @@ return kerror; } *entry = cur_entry; + (void) krb5_ktfileint_copy_entry(context, &cur_entry, &KTCACHE(id)); return 0; } --- krb5-1.0/src/lib/krb5/keytab/file/ktf_resolv.c Tue Aug 29 14:34:32 1995 +++ krb5-1.0/src/lib/krb5/keytab/file/ktf_resolv.c Wed Feb 12 09:17:33 1997 @@ -53,6 +53,7 @@ (void) strcpy(data->name, name); data->openf = 0; + memset(&data->cache, 0, sizeof(data->cache)); (*id)->data = (krb5_pointer)data; (*id)->magic = KV5M_KEYTAB; --- krb5-1.0/src/lib/krb5/keytab/file/ktf_util.c Mon Sep 11 21:25:09 1995 +++ krb5-1.0/src/lib/krb5/keytab/file/ktf_util.c Wed Feb 12 09:24:54 1997 @@ -771,3 +771,31 @@ return 0; } +/* + * Copy a keytab entry's data from an old structure into a new + * (already allocated) structure. + */ + +krb5_error_code +krb5_ktfileint_copy_entry(context, old_entry, new_entry) + krb5_context context; + krb5_keytab_entry *old_entry, *new_entry; +{ + krb5_error_code code; + krb5_keytab_entry tmp_entry; + + tmp_entry = *old_entry; + + if ((code = krb5_copy_principal(context, old_entry->principal, + &tmp_entry.principal))) + return code; + + if ((code = krb5_copy_keyblock_contents(context, &old_entry->key, + &tmp_entry.key))) { + (void) krb5_free_principal(context, tmp_entry.principal); + return code; + } + + *new_entry = tmp_entry; + return 0; +} --- krb5-1.0/src/lib/krb5/keytab/file/ktf_wreslv.c Tue Aug 29 14:34:35 1995 +++ krb5-1.0/src/lib/krb5/keytab/file/ktf_wreslv.c Wed Feb 12 09:18:15 1997 @@ -53,6 +53,7 @@ (void) strcpy(data->name, name); data->openf = 0; + memset(&data->cache, 0, sizeof(data->cache)); (*id)->data = (krb5_pointer)data; (*id)->magic = KV5M_KEYTAB; --- krb5-1.0/src/lib/krb5/keytab/file/ktfile.h Fri Jan 26 00:20:17 1996 +++ krb5-1.0/src/lib/krb5/keytab/file/ktfile.h Wed Feb 12 09:16:18 1997 @@ -49,6 +49,7 @@ char *name; /* Name of the file */ FILE *openf; /* open file, if any. */ int version; /* Version number of keytab */ + krb5_keytab_entry cache; /* Cached last keytab entry returned by get_entry */ } krb5_ktfile_data; /* @@ -58,6 +59,7 @@ #define KTFILENAME(id) (((krb5_ktfile_data *)(id)->data)->name) #define KTFILEP(id) (((krb5_ktfile_data *)(id)->data)->openf) #define KTVERSION(id) (((krb5_ktfile_data *)(id)->data)->version) +#define KTCACHE(id) (((krb5_ktfile_data *)(id)->data)->cache) extern struct _krb5_kt_ops krb5_ktf_ops; extern struct _krb5_kt_ops krb5_ktf_writable_ops; @@ -160,6 +162,11 @@ krb5_keytab, krb5_int32 *, krb5_int32 *)); + +krb5_error_code krb5_ktfileint_copy_entry + PROTOTYPE((krb5_context, + krb5_keytab_entry *, + krb5_keytab_entry *)); #endif /* KRB5_KTFILE__ */ >Audit-Trail: From: "Jonathan I. Kamens" To: krb5-bugs@MIT.EDU Cc: Subject: Re: krb5-libs/371: keytab code should cache the most-recently-used keytab entry Date: Mon, 11 Aug 1997 16:03:29 -0400 Has this patch been merged back into the main branch of the MIT tree? Will it be included in the next MIT release? jik >Unformatted: