xref: /freebsd/crypto/krb5/src/include/krb5/hostrealm_plugin.h (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright (C) 2013 by the Massachusetts Institute of Technology.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  *   notice, this list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in
15  *   the documentation and/or other materials provided with the
16  *   distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Declarations for hostrealm plugin module implementors.
34  *
35  * The hostrealm pluggable interface currently has only one supported major
36  * version, which is 1.  Major version 1 has a current minor version number of
37  * 1.
38  *
39  * Hostrealm plugin modules should define a function named
40  * hostrealm_<modulename>_initvt, matching the signature:
41  *
42  *   krb5_error_code
43  *   hostrealm_modname_initvt(krb5_context context, int maj_ver, int min_ver,
44  *                            krb5_plugin_vtable vtable);
45  *
46  * The initvt function should:
47  *
48  * - Check that the supplied maj_ver number is supported by the module, or
49  *   return KRB5_PLUGIN_VER_NOTSUPP if it is not.
50  *
51  * - Cast the vtable pointer as appropriate for maj_ver:
52  *     maj_ver == 1: Cast to krb5_hostrealm_vtable
53  *
54  * - Initialize the methods of the vtable, stopping as appropriate for the
55  *   supplied min_ver.  Optional methods may be left uninitialized.
56  *
57  * Memory for the vtable is allocated by the caller, not by the module.
58  */
59 
60 #ifndef KRB5_HOSTREALM_PLUGIN_H
61 #define KRB5_HOSTREALM_PLUGIN_H
62 
63 #include <krb5/krb5.h>
64 #include <krb5/plugin.h>
65 
66 /* An abstract type for hostrealm module data. */
67 typedef struct krb5_hostrealm_moddata_st *krb5_hostrealm_moddata;
68 
69 /*** Method type declarations ***/
70 
71 /* Optional: Initialize module data. */
72 typedef krb5_error_code
73 (*krb5_hostrealm_init_fn)(krb5_context context,
74                           krb5_hostrealm_moddata *data);
75 
76 /*
77  * Optional: Determine the possible realms of a hostname, using only secure,
78  * authoritative mechanisms (ones which should be used prior to trying
79  * referrals when getting a service ticket).  Return success with a
80  * null-terminated list of realms in *realms_out, KRB5_PLUGIN_NO_HANDLE to
81  * defer to later modules, or another error to terminate processing.
82  */
83 typedef krb5_error_code
84 (*krb5_hostrealm_host_realm_fn)(krb5_context context,
85                                 krb5_hostrealm_moddata data,
86                                 const char *host, char ***realms_out);
87 
88 /*
89  * Optional: Determine the possible realms of a hostname, using heuristic or
90  * less secure mechanisms (ones which should be used after trying referrals
91  * when getting a service ticket).  Return success with a null-terminated list
92  * of realms in *realms_out, KRB5_PLUGIN_NO_HANDLE to defer to later modules,
93  * or another error to terminate processing.
94  */
95 typedef krb5_error_code
96 (*krb5_hostrealm_fallback_realm_fn)(krb5_context context,
97                                     krb5_hostrealm_moddata data,
98                                     const char *host, char ***realms_out);
99 
100 /*
101  * Optional: Determine the possible default realms of the local host.  Return
102  * success with a null-terminated list of realms in *realms_out,
103  * KRB5_PLUGIN_NO_HANDLE to defer to later modules, or another error to
104  * terminate processing.
105  */
106 typedef krb5_error_code
107 (*krb5_hostrealm_default_realm_fn)(krb5_context context,
108                                    krb5_hostrealm_moddata data,
109                                    char ***realms_out);
110 
111 /*
112  * Mandatory (if any of the query methods are implemented): Release the memory
113  * returned by one of the interface methods.
114  */
115 typedef void
116 (*krb5_hostrealm_free_list_fn)(krb5_context context,
117                                krb5_hostrealm_moddata data, char **list);
118 
119 /* Optional: Release resources used by module data. */
120 typedef void
121 (*krb5_hostrealm_fini_fn)(krb5_context context, krb5_hostrealm_moddata data);
122 
123 /* hostrealm vtable for major version 1. */
124 typedef struct krb5_hostrealm_vtable_st {
125     const char *name;           /* Mandatory: name of module. */
126     krb5_hostrealm_init_fn init;
127     krb5_hostrealm_fini_fn fini;
128     krb5_hostrealm_host_realm_fn host_realm;
129     krb5_hostrealm_fallback_realm_fn fallback_realm;
130     krb5_hostrealm_default_realm_fn default_realm;
131     krb5_hostrealm_free_list_fn free_list;
132     /* Minor version 1 ends here. */
133 } *krb5_hostrealm_vtable;
134 
135 #endif /* KRB5_HOSTREALM_PLUGIN_H */
136