1 /* $NetBSD: pcache.c,v 1.2 2017/01/28 21:31:49 christos Exp $ */
2
3 /***********************************************************************
4 * Copyright (c) 2010, Secure Endpoints Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 **********************************************************************/
33
34 #include "krb5_locl.h"
35 #include "ccache_plugin.h"
36 #ifdef HAVE_DLFCN_H
37 #include <dlfcn.h>
38 #endif
39 #include <assert.h>
40
41 /*
42 * cc_plugin_register_to_context is executed once per krb5_init_context().
43 * Its job is to register the plugin's krb5_cc_ops structure with the
44 * krb5_context.
45 */
46
47 static krb5_error_code KRB5_LIB_CALL
cc_plugin_register_to_context(krb5_context context,const void * plug,void * plugctx,void * userctx)48 cc_plugin_register_to_context(krb5_context context, const void *plug, void *plugctx, void *userctx)
49 {
50 krb5_cc_ops *ccops = (krb5_cc_ops *)plugctx;
51 krb5_error_code ret;
52
53 if (ccops == NULL || ccops->version < KRB5_CC_OPS_VERSION)
54 return KRB5_PLUGIN_NO_HANDLE;
55
56 ret = krb5_cc_register(context, ccops, TRUE);
57 if (ret != 0)
58 *((krb5_error_code *)userctx) = ret;
59
60 return KRB5_PLUGIN_NO_HANDLE;
61 }
62
63 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
_krb5_load_ccache_plugins(krb5_context context)64 _krb5_load_ccache_plugins(krb5_context context)
65 {
66 krb5_error_code userctx = 0;
67
68 (void)_krb5_plugin_run_f(context, "krb5", KRB5_PLUGIN_CCACHE,
69 0, 0, &userctx, cc_plugin_register_to_context);
70
71 return userctx;
72 }
73