1.\" $NetBSD: krb5-plugin.7,v 1.3 2023/06/19 21:41:44 christos Exp $ 2.\" 3.\" Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan 4.\" (Royal Institute of Technology, Stockholm, Sweden). 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" 3. Neither the name of the Institute nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.\" Id 35.\" 36.Dd December 21, 2011 37.Dt KRB5-PLUGIN 7 38.Os HEIMDAL 39.Sh NAME 40.Nm krb5-plugin 41.Nd plugin interface for Heimdal 42.Sh SYNOPSIS 43.In krb5.h 44.In krb5/an2ln_plugin.h 45.In krb5/ccache_plugin.h 46.In krb5/db_plugin.h 47.In krb5/kuserok_plugin.h 48.In krb5/locate_plugin.h 49.In krb5/send_to_kdc_plugin.h 50.Sh DESCRIPTION 51Heimdal has a plugin interface. Plugins may be statically linked into 52Heimdal and registered via the 53.Xr krb5_plugin_register 3 54function, or they may be dynamically loaded from shared objects present 55in the Heimdal plugins directories. 56.Pp 57Plugins consist of a C struct whose struct name is given in the 58associated header file, such as, for example, 59.Va krb5plugin_kuserok_ftable 60and a pointer to which is either registered via 61.Xr krb5_plugin_register 3 62or found in a shared object via a symbol lookup for the symbol name 63defined in the associated header file (e.g., "kuserok" for the 64plugin for 65.Xr krb5_kuserok 3 66). 67.Pp 68The plugin structs for all plugin types always begin with the same three 69common fields: 70.Bl -enum -compact 71.It 72.Va minor_version 73, an int. Plugin minor versions are defined in each plugin type's 74associated header file. 75.It 76.Va init 77, a pointer to a function with two arguments, a krb5_context and a 78void **, returning a krb5_error_code. This function will be called to 79initialize a plugin-specific context in the form of a void * that will 80be output through the init function's second argument. 81.It 82.Va fini 83, a pointer to a function of one argument, a void *, consisting of the 84plugin's context to be destroyed, and returning void. 85.El 86.Pp 87Each plugin type must add zero or more fields to this struct following 88the above three. Plugins are typically invoked in no particular order 89until one succeeds or fails, or all return a special return value such 90as KRB5_PLUGIN_NO_HANDLE to indicate that the plugin was not applicable. 91Most plugin types obtain deterministic plugin behavior in spite of the 92non-deterministic invocation order by, for example, invoking all plugins 93for each "rule" and passing the rule to each plugin with the expectation 94that just one plugin will match any given rule. 95.Pp 96There is a database plugin system intended for many of the uses of 97databases in Heimdal. The plugin is expected to call 98.Xr heim_db_register 3 99from its 100.Va init 101entry point to register a DB type. The DB plugin's 102.Va fini 103function must do nothing, and the plugin must not provide any other 104entry points. 105.Pp 106The krb5_kuserok plugin adds a single field to its struct: a pointer to 107a function that implements kuserok functionality with the following 108form: 109.Bd -literal -offset indent 110static krb5_error_code 111kuserok(void *plug_ctx, krb5_context context, const char *rule, 112 unsigned int flags, const char *k5login_dir, 113 const char *luser, krb5_const_principal principal, 114 krb5_boolean *result) 115.Ed 116.Pp 117The 118.Va luser 119, 120.Va principal 121and 122.Va result 123arguments are self-explanatory (see 124.Xr krb5_kuserok 3 125). The 126.Va plug_ctx 127argument is the context output by the plugin's init function. The 128.Va rule 129argument is a kuserok rule from the krb5.conf file; each plugin is invoked once 130for each rule until all plugins fail or one succeeds. The 131.Va k5login_dir 132argument provides an alternative k5login file location, if not NULL. 133The 134.Va flags 135argument indicates whether the plugin may call 136.Xr krb5_aname_to_localname 3 137(KUSEROK_ANAME_TO_LNAME_OK), and whether k5login databases are expected to be 138authoritative (KUSEROK_K5LOGIN_IS_AUTHORITATIVE). 139.Pp 140The plugin for 141.Xr krb5_aname_to_localname 3 142is named "an2ln" and has a single extra field for the plugin struct: 143.Bd -literal -offset indent 144typedef krb5_error_code (*set_result_f)(void *, const char *); 145 146static krb5_error_code 147an2ln(void *plug_ctx, krb5_context context, const char *rule, 148 krb5_const_principal aname, set_result_f set_res_f, void *set_res_ctx) 149.Ed 150.Pp 151The arguments for the 152.Va an2ln 153plugin are similar to those of the kuserok plugin, but the result, being 154a string, is set by calling the 155.Va set_res_f 156function argument with the 157.Va set_res_ctx 158and result string as arguments. The 159.Va set_res_f 160function will make a copy of the string. 161.Sh FILES 162.Bl -tag -compact 163.It Pa libdir/plugin/krb5/* 164Shared objects containing plugins for Heimdal. 165.El 166.Sh EXAMPLES 167.Pp 168An example an2ln plugin that maps principals to a constant "nouser" 169follows: 170.Pp 171.Bd -literal -offset indent 172#include <krb5/an2ln_plugin.h> 173 174static krb5_error_code KRB5_CALLCONV 175nouser_plug_init(krb5_context context, void **ctx) 176{ 177 *ctx = NULL; 178 return 0; 179} 180 181static void KRB5_CALLCONV nouser_plug_fini(void *ctx) { } 182 183static krb5_error_code KRB5_CALLCONV 184nouser_plug_an2ln(void *plug_ctx, krb5_context context, 185 const char *rule, 186 krb5_const_principal aname, 187 set_result_f set_res_f, void *set_res_ctx) 188{ 189 krb5_error_code ret; 190 191 if (strcmp(rule, "NOUSER") != 0) 192 return KRB5_PLUGIN_NO_HANDLE; 193 194 ret = set_res_f(set_res_ctx, "nouser"); 195 196 return ret; 197} 198 199krb5plugin_an2ln_ftable an2ln = { 200 KRB5_PLUGIN_AN2LN_VERSION_0, 201 nouser_plug_init, 202 nouser_plug_fini, 203 nouser_plug_an2ln, 204}; 205.Ed 206.Pp 207An example kuserok plugin that rejects all requests follows. (Note that 208there exists a built-in plugin with this functionality; see 209.Xr krb5_kuserok 3 210). 211.Pp 212.Bd -literal -offset indent 213#include <krb5/kuserok_plugin.h> 214 215static krb5_error_code KRB5_CALLCONV 216reject_plug_init(krb5_context context, void **ctx) 217{ 218 *ctx = NULL; 219 return 0; 220} 221 222static void KRB5_CALLCONV reject_plug_fini(void *ctx) { } 223 224static krb5_error_code KRB5_CALLCONV 225reject_plug_kuserok(void *plug_ctx, krb5_context context, const char *rule, 226 unsigned int flags, const char *k5login_dir, 227 const char *luser, krb5_const_principal principal, 228 krb5_boolean *result) 229{ 230 if (strcmp(rule, "REJECT") != 0) 231 return KRB5_PLUGIN_NO_HANDLE; 232 233 *result = FALSE; 234 return 0; 235} 236 237krb5plugin_kuserok_ftable kuserok = { 238 KRB5_PLUGIN_KUSEROK_VERSION_0, 239 reject_plug_init, 240 reject_plug_fini, 241 reject_plug_kuserok, 242}; 243.Ed 244.Sh SEE ALSO 245.Xr krb5_plugin_register 3 246.Xr krb5_kuserok 3 247.Xr krb5_aname_to_localname 3 248