From cd5cca0cac5e81d9ccaa35dcdf92594e9e92b68c Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 10 Sep 2013 22:04:40 -0400 Subject: [PATCH] pcache: rename and fix callback() rename callback() to cc_plugin_register_to_context() and document its purpose. The parameter that is the cc_ops structure is 'plugctx' not 'plug'. This is critical because 'plug' is the common_plugin_model structure and casting the wrong object leads to random behavior including crashes. The test to exit without action was reversed. With these changes ccache plugins can be registered on each krb5_init_context() operation. Change-Id: I295ea91759f69b36ac13b1bfff87306d40df4a26 --- lib/krb5/pcache.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/krb5/pcache.c b/lib/krb5/pcache.c index 345188062..f5023346e 100644 --- a/lib/krb5/pcache.c +++ b/lib/krb5/pcache.c @@ -36,30 +36,35 @@ #endif #include +/* + * cc_plugin_register_to_context is executed once per krb5_init_context(). + * Its job is to register the plugin's krb5_cc_ops structure with the + * krb5_context. + */ + static krb5_error_code KRB5_LIB_CALL -callback(krb5_context context, const void *plug, void *plugctx, void *userctx) +cc_plugin_register_to_context(krb5_context context, const void *plug, void *plugctx, void *userctx) { - krb5_cc_ops *ccops = (krb5_cc_ops *)plug; + krb5_cc_ops *ccops = (krb5_cc_ops *)plugctx; krb5_error_code ret; - if (ccops != NULL && ccops->version >= KRB5_CC_OPS_VERSION) - return KRB5_PLUGIN_NO_HANDLE; + if (ccops == NULL && ccops->version < KRB5_CC_OPS_VERSION) + return KRB5_PLUGIN_NO_HANDLE; ret = krb5_cc_register(context, ccops, TRUE); if (ret != 0) - *((krb5_error_code *)userctx) = ret; + *((krb5_error_code *)userctx) = ret; return KRB5_PLUGIN_NO_HANDLE; } - KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL _krb5_load_ccache_plugins(krb5_context context) { krb5_error_code userctx = 0; (void)_krb5_plugin_run_f(context, "krb5", KRB5_PLUGIN_CCACHE, - 0, 0, &userctx, callback); + 0, 0, &userctx, cc_plugin_register_to_context); return userctx; }