windc.c revision 178825
1178825Sdfr/*
2178825Sdfr * Copyright (c) 2007 Kungliga Tekniska H�gskolan
3178825Sdfr * (Royal Institute of Technology, Stockholm, Sweden).
4178825Sdfr * All rights reserved.
5178825Sdfr *
6178825Sdfr * Redistribution and use in source and binary forms, with or without
7178825Sdfr * modification, are permitted provided that the following conditions
8178825Sdfr * are met:
9178825Sdfr *
10178825Sdfr * 1. Redistributions of source code must retain the above copyright
11178825Sdfr *    notice, this list of conditions and the following disclaimer.
12178825Sdfr *
13178825Sdfr * 2. Redistributions in binary form must reproduce the above copyright
14178825Sdfr *    notice, this list of conditions and the following disclaimer in the
15178825Sdfr *    documentation and/or other materials provided with the distribution.
16178825Sdfr *
17178825Sdfr * 3. Neither the name of the Institute nor the names of its contributors
18178825Sdfr *    may be used to endorse or promote products derived from this software
19178825Sdfr *    without specific prior written permission.
20178825Sdfr *
21178825Sdfr * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22178825Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23178825Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24178825Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25178825Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26178825Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27178825Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28178825Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29178825Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30178825Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31178825Sdfr * SUCH DAMAGE.
32178825Sdfr */
33178825Sdfr
34178825Sdfr#include "kdc_locl.h"
35178825Sdfr
36178825SdfrRCSID("$Id: windc.c 20559 2007-04-24 16:00:07Z lha $");
37178825Sdfr
38178825Sdfrstatic krb5plugin_windc_ftable *windcft;
39178825Sdfrstatic void *windcctx;
40178825Sdfr
41178825Sdfr/*
42178825Sdfr * Pick the first WINDC module that we find.
43178825Sdfr */
44178825Sdfr
45178825Sdfrkrb5_error_code
46178825Sdfrkrb5_kdc_windc_init(krb5_context context)
47178825Sdfr{
48178825Sdfr    struct krb5_plugin *list = NULL, *e;
49178825Sdfr    krb5_error_code ret;
50178825Sdfr
51178825Sdfr    ret = _krb5_plugin_find(context, PLUGIN_TYPE_DATA, "windc", &list);
52178825Sdfr    if(ret != 0 || list == NULL)
53178825Sdfr	return 0;
54178825Sdfr
55178825Sdfr    for (e = list; e != NULL; e = _krb5_plugin_get_next(e)) {
56178825Sdfr
57178825Sdfr	windcft = _krb5_plugin_get_symbol(e);
58178825Sdfr	if (windcft->minor_version < KRB5_WINDC_PLUGING_MINOR)
59178825Sdfr	    continue;
60178825Sdfr
61178825Sdfr	(*windcft->init)(context, &windcctx);
62178825Sdfr	break;
63178825Sdfr    }
64178825Sdfr    if (e == NULL) {
65178825Sdfr	_krb5_plugin_free(list);
66178825Sdfr	krb5_set_error_string(context, "Did not find any WINDC plugin");
67178825Sdfr	windcft = NULL;
68178825Sdfr	return ENOENT;
69178825Sdfr    }
70178825Sdfr
71178825Sdfr    return 0;
72178825Sdfr}
73178825Sdfr
74178825Sdfr
75178825Sdfrkrb5_error_code
76178825Sdfr_kdc_pac_generate(krb5_context context,
77178825Sdfr		  hdb_entry_ex *client,
78178825Sdfr		  krb5_pac *pac)
79178825Sdfr{
80178825Sdfr    *pac = NULL;
81178825Sdfr    if (windcft == NULL)
82178825Sdfr	return 0;
83178825Sdfr    return (windcft->pac_generate)(windcctx, context, client, pac);
84178825Sdfr}
85178825Sdfr
86178825Sdfrkrb5_error_code
87178825Sdfr_kdc_pac_verify(krb5_context context,
88178825Sdfr		const krb5_principal client_principal,
89178825Sdfr		hdb_entry_ex *client,
90178825Sdfr		hdb_entry_ex *server,
91178825Sdfr		krb5_pac *pac)
92178825Sdfr{
93178825Sdfr    if (windcft == NULL) {
94178825Sdfr	krb5_set_error_string(context, "Can't verify PAC, no function");
95178825Sdfr	return EINVAL;
96178825Sdfr    }
97178825Sdfr    return (windcft->pac_verify)(windcctx, context,
98178825Sdfr				 client_principal, client, server, pac);
99178825Sdfr}
100178825Sdfr
101178825Sdfrkrb5_error_code
102178825Sdfr_kdc_windc_client_access(krb5_context context,
103178825Sdfr			 struct hdb_entry_ex *client,
104178825Sdfr			 KDC_REQ *req)
105178825Sdfr{
106178825Sdfr    if (windcft == NULL)
107178825Sdfr	return 0;
108178825Sdfr    return (windcft->client_access)(windcctx, context, client, req);
109178825Sdfr}
110