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 WINDC module that we find.
42 static const char *windc_plugin_deps
[] = {
49 static struct heim_plugin_data windc_plugin_data
= {
52 KRB5_WINDC_PLUGIN_MINOR
,
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
;
65 krb5_kdc_windc_init(krb5_context context
)
67 (void)_krb5_plugin_run_f(context
, &windc_plugin_data
, 0, NULL
, load
);
77 static krb5_error_code KRB5_LIB_CALL
78 generate(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
80 krb5plugin_windc_ftable
*ft
= (krb5plugin_windc_ftable
*)plug
;
81 struct generate_uc
*uc
= (struct generate_uc
*)userctx
;
83 if (ft
->pac_generate
== NULL
)
84 return KRB5_PLUGIN_NO_HANDLE
;
85 return ft
->pac_generate((void *)plug
, context
, uc
->client
, uc
->pac
);
90 _kdc_pac_generate(krb5_context context
,
94 struct generate_uc uc
;
102 (void)_krb5_plugin_run_f(context
, &windc_plugin_data
,
108 krb5_principal client_principal
;
109 krb5_principal delegated_proxy_principal
;
110 hdb_entry_ex
*client
;
111 hdb_entry_ex
*server
;
112 hdb_entry_ex
*krbtgt
;
117 static krb5_error_code KRB5_LIB_CALL
118 verify(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
120 krb5plugin_windc_ftable
*ft
= (krb5plugin_windc_ftable
*)plug
;
121 struct verify_uc
*uc
= (struct verify_uc
*)userctx
;
124 if (ft
->pac_verify
== NULL
)
125 return KRB5_PLUGIN_NO_HANDLE
;
126 ret
= ft
->pac_verify((void *)plug
, context
,
127 uc
->client_principal
,
128 uc
->delegated_proxy_principal
,
129 uc
->client
, uc
->server
, uc
->krbtgt
, uc
->pac
);
137 _kdc_pac_verify(krb5_context context
,
138 const krb5_principal client_principal
,
139 const krb5_principal delegated_proxy_principal
,
140 hdb_entry_ex
*client
,
141 hdb_entry_ex
*server
,
142 hdb_entry_ex
*krbtgt
,
151 uc
.client_principal
= client_principal
;
152 uc
.delegated_proxy_principal
= delegated_proxy_principal
;
157 uc
.verified
= verified
;
159 (void)_krb5_plugin_run_f(context
, &windc_plugin_data
,
165 krb5_kdc_configuration
*config
;
166 hdb_entry_ex
*client_ex
;
167 const char *client_name
;
168 hdb_entry_ex
*server_ex
;
169 const char *server_name
;
171 METHOD_DATA
*method_data
;
174 static krb5_error_code KRB5_LIB_CALL
175 check(krb5_context context
, const void *plug
, void *plugctx
, void *userctx
)
177 krb5plugin_windc_ftable
*ft
= (krb5plugin_windc_ftable
*)plug
;
178 struct check_uc
*uc
= (struct check_uc
*)userctx
;
180 if (ft
->client_access
== NULL
)
181 return KRB5_PLUGIN_NO_HANDLE
;
182 return ft
->client_access((void *)plug
, context
, uc
->config
,
183 uc
->client_ex
, uc
->client_name
,
184 uc
->server_ex
, uc
->server_name
,
185 uc
->req
, uc
->method_data
);
190 _kdc_check_access(astgs_request_t r
, KDC_REQ
*req
, METHOD_DATA
*method_data
)
192 krb5_context context
= r
->context
;
193 krb5_kdc_configuration
*config
= r
->config
;
194 hdb_entry_ex
*client_ex
= r
->client
;
195 const char *client_name
= r
->cname
;
196 hdb_entry_ex
*server_ex
= r
->server
;
197 const char *server_name
= r
->sname
;
198 krb5_error_code ret
= KRB5_PLUGIN_NO_HANDLE
;
203 uc
.client_ex
= client_ex
;
204 uc
.client_name
= client_name
;
205 uc
.server_ex
= server_ex
;
206 uc
.server_name
= server_name
;
208 uc
.method_data
= method_data
;
210 ret
= _krb5_plugin_run_f(context
, &windc_plugin_data
,
214 if (ret
== KRB5_PLUGIN_NO_HANDLE
)
215 return kdc_check_flags(r
, req
->msg_type
== krb_as_req
);
219 uintptr_t KRB5_CALLCONV
220 kdc_get_instance(const char *libname
)
222 static const char *instance
= "libkdc";
224 if (strcmp(libname
, "kdc") == 0)
225 return (uintptr_t)instance
;
226 else if (strcmp(libname
, "hdb") == 0)
227 return hdb_get_instance(libname
);
228 else if (strcmp(libname
, "krb5") == 0)
229 return krb5_get_instance(libname
);