2 * Copyright (c) 2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static int have_plugin
= 0;
39 * Pick the first KDC plugin module that we find.
42 static const char *kdc_plugin_deps
[] = {
49 static struct heim_plugin_data kdc_plugin_data
= {
52 KRB5_PLUGIN_KDC_VERSION_10
,
57 static krb5_error_code KRB5_LIB_CALL
58 load(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
61 return KRB5_PLUGIN_NO_HANDLE
;
64 KDC_LIB_FUNCTION krb5_error_code KDC_LIB_CALL
65 krb5_kdc_plugin_init(krb5_context context
)
67 (void)_krb5_plugin_run_f(context
, &kdc_plugin_data
, 0, NULL
, load
);
73 krb5_kdc_configuration
*config
;
76 const krb5_keyblock
*reply_key
;
77 uint64_t pac_attributes
;
81 static krb5_error_code KRB5_LIB_CALL
82 generate(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
84 const krb5plugin_kdc_ftable
*ft
= (const krb5plugin_kdc_ftable
*)plug
;
85 struct generate_uc
*uc
= (struct generate_uc
*)userctx
;
87 if (ft
->pac_generate
== NULL
)
88 return KRB5_PLUGIN_NO_HANDLE
;
90 return ft
->pac_generate((void *)plug
,
102 _kdc_pac_generate(krb5_context context
,
103 krb5_kdc_configuration
*config
,
106 const krb5_keyblock
*reply_key
,
107 uint64_t pac_attributes
,
110 krb5_error_code ret
= 0;
111 struct generate_uc uc
;
115 if (krb5_config_get_bool_default(context
, NULL
, FALSE
, "realms",
116 client
->principal
->realm
,
117 "disable_pac", NULL
))
124 uc
.reply_key
= reply_key
;
126 uc
.pac_attributes
= pac_attributes
;
128 ret
= _krb5_plugin_run_f(context
, &kdc_plugin_data
,
130 if (ret
!= KRB5_PLUGIN_NO_HANDLE
)
136 ret
= krb5_pac_init(context
, pac
);
142 krb5_kdc_configuration
*config
;
143 krb5_principal client_principal
;
144 krb5_principal delegated_proxy_principal
;
151 static krb5_error_code KRB5_LIB_CALL
152 verify(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
154 const krb5plugin_kdc_ftable
*ft
= (const krb5plugin_kdc_ftable
*)plug
;
155 struct verify_uc
*uc
= (struct verify_uc
*)userctx
;
158 if (ft
->pac_verify
== NULL
)
159 return KRB5_PLUGIN_NO_HANDLE
;
161 ret
= ft
->pac_verify((void *)plug
,
164 uc
->client_principal
,
165 uc
->delegated_proxy_principal
,
166 uc
->client
, uc
->server
, uc
->krbtgt
, uc
->pac
);
171 _kdc_pac_verify(krb5_context context
,
172 krb5_kdc_configuration
*config
,
173 const krb5_principal client_principal
,
174 const krb5_principal delegated_proxy_principal
,
183 return KRB5_PLUGIN_NO_HANDLE
;
186 uc
.client_principal
= client_principal
;
187 uc
.delegated_proxy_principal
= delegated_proxy_principal
;
193 return _krb5_plugin_run_f(context
, &kdc_plugin_data
,
197 static krb5_error_code KRB5_LIB_CALL
198 check(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
200 const krb5plugin_kdc_ftable
*ft
= (const krb5plugin_kdc_ftable
*)plug
;
202 if (ft
->client_access
== NULL
)
203 return KRB5_PLUGIN_NO_HANDLE
;
204 return ft
->client_access((void *)plug
, userctx
);
208 _kdc_check_access(astgs_request_t r
)
210 krb5_error_code ret
= KRB5_PLUGIN_NO_HANDLE
;
213 ret
= _krb5_plugin_run_f(r
->context
, &kdc_plugin_data
,
217 if (ret
== KRB5_PLUGIN_NO_HANDLE
)
218 return kdc_check_flags(r
, r
->req
.msg_type
== krb_as_req
,
219 r
->client
, r
->server
);
223 static krb5_error_code KRB5_LIB_CALL
224 referral_policy(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
226 const krb5plugin_kdc_ftable
*ft
= (const krb5plugin_kdc_ftable
*)plug
;
228 if (ft
->referral_policy
== NULL
)
229 return KRB5_PLUGIN_NO_HANDLE
;
230 return ft
->referral_policy((void *)plug
, userctx
);
234 _kdc_referral_policy(astgs_request_t r
)
236 krb5_error_code ret
= KRB5_PLUGIN_NO_HANDLE
;
239 ret
= _krb5_plugin_run_f(r
->context
, &kdc_plugin_data
, 0, r
, referral_policy
);
244 static krb5_error_code KRB5_LIB_CALL
245 finalize_reply(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
247 const krb5plugin_kdc_ftable
*ft
= (const krb5plugin_kdc_ftable
*)plug
;
249 if (ft
->finalize_reply
== NULL
)
250 return KRB5_PLUGIN_NO_HANDLE
;
251 return ft
->finalize_reply((void *)plug
, userctx
);
255 _kdc_finalize_reply(astgs_request_t r
)
257 krb5_error_code ret
= KRB5_PLUGIN_NO_HANDLE
;
260 ret
= _krb5_plugin_run_f(r
->context
, &kdc_plugin_data
, 0, r
, finalize_reply
);
262 if (ret
== KRB5_PLUGIN_NO_HANDLE
)
268 static krb5_error_code KRB5_LIB_CALL
269 audit(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
271 const krb5plugin_kdc_ftable
*ft
= (const krb5plugin_kdc_ftable
*)plug
;
273 if (ft
->audit
== NULL
)
274 return KRB5_PLUGIN_NO_HANDLE
;
275 return ft
->audit((void *)plug
, userctx
);
279 _kdc_plugin_audit(astgs_request_t r
)
281 krb5_error_code ret
= KRB5_PLUGIN_NO_HANDLE
;
284 ret
= _krb5_plugin_run_f(r
->context
, &kdc_plugin_data
, 0, r
, audit
);
286 if (ret
== KRB5_PLUGIN_NO_HANDLE
)
292 KDC_LIB_FUNCTION
uintptr_t KDC_LIB_CALL
293 kdc_get_instance(const char *libname
)
295 static const char *instance
= "libkdc";
297 if (strcmp(libname
, "kdc") == 0)
298 return (uintptr_t)instance
;
299 else if (strcmp(libname
, "hdb") == 0)
300 return hdb_get_instance(libname
);
301 else if (strcmp(libname
, "krb5") == 0)
302 return krb5_get_instance(libname
);
303 else if (strcmp(libname
, "gssapi") == 0)
304 return gss_get_instance(libname
);