1 .\" Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
2 .\" (Royal Institute of Technology, Stockholm, Sweden).
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of the Institute nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 .Nd plugin interface for Heimdal
42 .In krb5/an2ln_plugin.h
43 .In krb5/ccache_plugin.h
45 .In krb5/kuserok_plugin.h
46 .In krb5/locate_plugin.h
47 .In krb5/send_to_kdc_plugin.h
49 Heimdal has a plugin interface. Plugins may be statically linked into
50 Heimdal and registered via the
51 .Xr krb5_plugin_register 3
52 function, or they may be dynamically loaded from shared objects present
53 in the Heimdal plugins directories.
55 Plugins consist of a C struct whose struct name is given in the
56 associated header file, such as, for example,
57 .Va krb5plugin_kuserok_ftable
58 and a pointer to which is either registered via
59 .Xr krb5_plugin_register 3
60 or found in a shared object via a symbol lookup for the symbol name
61 defined in the associated header file (e.g., "kuserok" for the
66 The plugin structs for all plugin types always begin with the same three
71 , an int. Plugin minor versions are defined in each plugin type's
72 associated header file.
75 , a pointer to a function with two arguments, a krb5_context and a
76 void **, returning a krb5_error_code. This function will be called to
77 initialize a plugin-specific context in the form of a void * that will
78 be output through the init function's second argument.
81 , a pointer to a function of one argument, a void *, consisting of the
82 plugin's context to be destroyed, and returning void.
85 Each plugin type must add zero or more fields to this struct following
86 the above three. Plugins are typically invoked in no particular order
87 until one succeeds or fails, or all return a special return value such
88 as KRB5_PLUGIN_NO_HANDLE to indicate that the plugin was not applicable.
89 Most plugin types obtain deterministic plugin behavior in spite of the
90 non-deterministic invocation order by, for example, invoking all plugins
91 for each "rule" and passing the rule to each plugin with the expectation
92 that just one plugin will match any given rule.
94 There is a database plugin system intended for many of the uses of
95 databases in Heimdal. The plugin is expected to call
96 .Xr heim_db_register 3
99 entry point to register a DB type. The DB plugin's
101 function must do nothing, and the plugin must not provide any other
104 The krb5_kuserok plugin adds a single field to its struct: a pointer to
105 a function that implements kuserok functionality with the following
107 .Bd -literal -offset indent
108 static krb5_error_code
109 kuserok(void *plug_ctx, krb5_context context, const char *rule,
110 unsigned int flags, const char *k5login_dir,
111 const char *luser, krb5_const_principal principal,
112 krb5_boolean *result)
121 arguments are self-explanatory (see
125 argument is the context output by the plugin's init function. The
127 argument is a kuserok rule from the krb5.conf file; each plugin is invoked once
128 for each rule until all plugins fail or one succeeds. The
130 argument provides an alternative k5login file location, if not NULL.
133 argument indicates whether the plugin may call
134 .Xr krb5_aname_to_localname 3
135 (KUSEROK_ANAME_TO_LNAME_OK), and whether k5login databases are expected to be
136 authoritative (KUSEROK_K5LOGIN_IS_AUTHORITATIVE).
139 .Xr krb5_aname_to_localname 3
140 is named "an2ln" and has a single extra field for the plugin struct:
141 .Bd -literal -offset indent
142 typedef krb5_error_code (*set_result_f)(void *, const char *);
144 static krb5_error_code
145 an2ln(void *plug_ctx, krb5_context context, const char *rule,
146 krb5_const_principal aname, set_result_f set_res_f, void *set_res_ctx)
149 The arguments for the
151 plugin are similar to those of the kuserok plugin, but the result, being
152 a string, is set by calling the
154 function argument with the
156 and result string as arguments. The
158 function will make a copy of the string.
161 .It Pa libdir/plugin/krb5/*
162 Shared objects containing plugins for Heimdal.
166 An example an2ln plugin that maps principals to a constant "nouser"
169 .Bd -literal -offset indent
170 #include <krb5/an2ln_plugin.h>
172 static krb5_error_code
173 nouser_plug_init(krb5_context context, void **ctx)
179 static void nouser_plug_fini(void *ctx) { }
181 static krb5_error_code
182 nouser_plug_an2ln(void *plug_ctx, krb5_context context,
184 krb5_const_principal aname,
185 set_result_f set_res_f, void *set_res_ctx)
189 if (strcmp(rule, "NOUSER") != 0)
190 return KRB5_PLUGIN_NO_HANDLE;
192 ret = set_res_f(set_res_ctx, "nouser");
197 krb5plugin_an2ln_ftable an2ln = {
198 KRB5_PLUGIN_AN2LN_VERSION_0,
205 An example kuserok plugin that rejects all requests follows. (Note that
206 there exists a built-in plugin with this functionality; see
210 .Bd -literal -offset indent
211 #include <krb5/kuserok_plugin.h>
213 static krb5_error_code
214 reject_plug_init(krb5_context context, void **ctx)
220 static void reject_plug_fini(void *ctx) { }
222 static krb5_error_code
223 reject_plug_kuserok(void *plug_ctx, krb5_context context, const char *rule,
224 unsigned int flags, const char *k5login_dir,
225 const char *luser, krb5_const_principal principal,
226 krb5_boolean *result)
228 if (strcmp(rule, "REJECT") != 0)
229 return KRB5_PLUGIN_NO_HANDLE;
235 krb5plugin_kuserok_ftable kuserok = {
236 KRB5_PLUGIN_KUSEROK_VERSION_0,
243 .Xr krb5_plugin_register 3
245 .Xr krb5_aname_to_localname 3