1178825Sdfr/*
2233294Sstas * Copyright (c) 2007 Kungliga Tekniska H��gskolan
3233294Sstas * (Royal Institute of Technology, Stockholm, Sweden).
4233294Sstas * All rights reserved.
5178825Sdfr *
6233294Sstas * Redistribution and use in source and binary forms, with or without
7233294Sstas * modification, are permitted provided that the following conditions
8233294Sstas * are met:
9178825Sdfr *
10233294Sstas * 1. Redistributions of source code must retain the above copyright
11233294Sstas *    notice, this list of conditions and the following disclaimer.
12178825Sdfr *
13233294Sstas * 2. Redistributions in binary form must reproduce the above copyright
14233294Sstas *    notice, this list of conditions and the following disclaimer in the
15233294Sstas *    documentation and/or other materials provided with the distribution.
16178825Sdfr *
17233294Sstas * 3. Neither the name of the Institute nor the names of its contributors
18233294Sstas *    may be used to endorse or promote products derived from this software
19233294Sstas *    without specific prior written permission.
20178825Sdfr *
21233294Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22233294Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24233294Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31233294Sstas * SUCH DAMAGE.
32178825Sdfr */
33178825Sdfr
34178825Sdfr#include "kdc_locl.h"
35178825Sdfr
36178825Sdfrstatic krb5plugin_windc_ftable *windcft;
37178825Sdfrstatic void *windcctx;
38178825Sdfr
39178825Sdfr/*
40178825Sdfr * Pick the first WINDC module that we find.
41178825Sdfr */
42178825Sdfr
43178825Sdfrkrb5_error_code
44178825Sdfrkrb5_kdc_windc_init(krb5_context context)
45178825Sdfr{
46178825Sdfr    struct krb5_plugin *list = NULL, *e;
47178825Sdfr    krb5_error_code ret;
48178825Sdfr
49178825Sdfr    ret = _krb5_plugin_find(context, PLUGIN_TYPE_DATA, "windc", &list);
50178825Sdfr    if(ret != 0 || list == NULL)
51178825Sdfr	return 0;
52178825Sdfr
53178825Sdfr    for (e = list; e != NULL; e = _krb5_plugin_get_next(e)) {
54178825Sdfr
55178825Sdfr	windcft = _krb5_plugin_get_symbol(e);
56233294Sstas	if (windcft->minor_version < KRB5_WINDC_PLUGIN_MINOR)
57178825Sdfr	    continue;
58233294Sstas
59178825Sdfr	(*windcft->init)(context, &windcctx);
60178825Sdfr	break;
61178825Sdfr    }
62233294Sstas    _krb5_plugin_free(list);
63178825Sdfr    if (e == NULL) {
64233294Sstas	krb5_set_error_message(context, ENOENT, "Did not find any WINDC plugin");
65178825Sdfr	windcft = NULL;
66178825Sdfr	return ENOENT;
67178825Sdfr    }
68178825Sdfr
69178825Sdfr    return 0;
70178825Sdfr}
71178825Sdfr
72178825Sdfr
73233294Sstaskrb5_error_code
74178825Sdfr_kdc_pac_generate(krb5_context context,
75233294Sstas		  hdb_entry_ex *client,
76178825Sdfr		  krb5_pac *pac)
77178825Sdfr{
78178825Sdfr    *pac = NULL;
79178825Sdfr    if (windcft == NULL)
80178825Sdfr	return 0;
81178825Sdfr    return (windcft->pac_generate)(windcctx, context, client, pac);
82178825Sdfr}
83178825Sdfr
84233294Sstaskrb5_error_code
85233294Sstas_kdc_pac_verify(krb5_context context,
86178825Sdfr		const krb5_principal client_principal,
87233294Sstas		const krb5_principal delegated_proxy_principal,
88178825Sdfr		hdb_entry_ex *client,
89178825Sdfr		hdb_entry_ex *server,
90233294Sstas		hdb_entry_ex *krbtgt,
91233294Sstas		krb5_pac *pac,
92233294Sstas		int *verified)
93178825Sdfr{
94233294Sstas    krb5_error_code ret;
95233294Sstas
96233294Sstas    if (windcft == NULL)
97233294Sstas	return 0;
98233294Sstas
99233294Sstas    ret = windcft->pac_verify(windcctx, context,
100233294Sstas			      client_principal,
101233294Sstas			      delegated_proxy_principal,
102233294Sstas			      client, server, krbtgt, pac);
103233294Sstas    if (ret == 0)
104233294Sstas	*verified = 1;
105233294Sstas    return ret;
106178825Sdfr}
107178825Sdfr
108178825Sdfrkrb5_error_code
109233294Sstas_kdc_check_access(krb5_context context,
110233294Sstas		  krb5_kdc_configuration *config,
111233294Sstas		  hdb_entry_ex *client_ex, const char *client_name,
112233294Sstas		  hdb_entry_ex *server_ex, const char *server_name,
113233294Sstas		  KDC_REQ *req,
114233294Sstas		  krb5_data *e_data)
115178825Sdfr{
116178825Sdfr    if (windcft == NULL)
117233294Sstas	    return kdc_check_flags(context, config,
118233294Sstas				   client_ex, client_name,
119233294Sstas				   server_ex, server_name,
120233294Sstas				   req->msg_type == krb_as_req);
121233294Sstas
122233294Sstas    return (windcft->client_access)(windcctx,
123233294Sstas				    context, config,
124233294Sstas				    client_ex, client_name,
125233294Sstas				    server_ex, server_name,
126233294Sstas				    req, e_data);
127178825Sdfr}
128