Document kadm5_hook chpass randomize-key behavior
[krb5.git] / src / include / krb5 / kadm5_hook_plugin.h
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright (C) 2010 by the Massachusetts Institute of Technology.
4  * All rights reserved.
5  *
6  * Export of this software from the United States of America may
7  *   require a specific license from the United States Government.
8  *   It is the responsibility of any person or organization contemplating
9  *   export to obtain such a license before exporting.
10  *
11  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12  * distribute this software and its documentation for any purpose and
13  * without fee is hereby granted, provided that the above copyright
14  * notice appear in all copies and that both that copyright notice and
15  * this permission notice appear in supporting documentation, and that
16  * the name of M.I.T. not be used in advertising or publicity pertaining
17  * to distribution of the software without specific, written prior
18  * permission.  Furthermore if you modify this software you must label
19  * your software as modified software and not distribute it in such a
20  * fashion that it might be confused with the original M.I.T. software.
21  * M.I.T. makes no representations about the suitability of
22  * this software for any purpose.  It is provided "as is" without express
23  * or implied warranty.
24  */
25
26 #ifndef H_KRB5_KADM5_HOOK_PLUGIN
27 #define H_KRB5_KADM5_HOOK_PLUGIN
28
29 /**
30  * @file krb5/krb5_kadm5_hook_plugin.h
31  * Provide a plugin interface for kadm5 operations. This interface
32  * permits a plugin to intercept principal modification, creation and
33  * change password operations. Operations run at two stages: a
34  * precommit stage that runs before the operation is committed to the
35  * database and a postcommit operation that runs after the database
36  * is updated; see #kadm5_hook_stage for details on semantics.
37  *
38  * This interface is based on a proposed extension to Heimdal by Russ
39  * Allbery; it is likely that Heimdal will adopt an approach based on
40  * stacked kdb modules rather than this interface. For MIT, writing a
41  * plugin to this interface is significantly easier than stacking kdb
42  * modules. Also, the kadm5 interface is significantly more stable
43  * than the kdb interface, so this approach is more desirable than
44  * stacked kdb modules.
45  *
46  * This interface depends on kadm5/admin.h. As such, the interface
47  * does not provide strong guarantees of ABI stability.
48  *
49  * kadm5_hook plugins should:
50  * kadm5_hook_<modulename>_initvt, matching the signature:
51  *
52  *   krb5_error_code
53  *   kadm5_hook_modname_initvt(krb5_context context, int maj_ver, int min_ver,
54  *                         krb5_plugin_vtable vtable);
55  *
56  * The initvt function should:
57  *
58  * - Check that the supplied maj_ver number is supported by the module, or
59  *   return KRB5_PLUGIN_VER_NOTSUPP if it is not.
60  *
61  * - Cast the vtable pointer as appropriate for maj_ver:
62  *     maj_ver == 1: Cast to kadm5_hook_vftable_1
63  *
64  * - Initialize the methods of the vtable, stopping as appropriate for the
65  *   supplied min_ver.  Optional methods may be left uninitialized.
66  *
67  * Memory for the vtable is allocated by the caller, not by the module.
68  */
69
70 #include <krb5/krb5.h>
71 #include <krb5/plugin.h>
72 #include <kadm5/admin.h>
73
74 /**
75  * Whether the operation is being run before or after the database
76  * update.
77  */
78 enum kadm5_hook_stage {
79     /** In this stage, any plugin failure prevents following plugins from
80      *         running and aborts the operation.*/
81     KADM5_HOOK_STAGE_PRECOMMIT,
82     /** In this stage, plugin failures are logged but otherwise ignored.*/
83     KADM5_HOOK_STAGE_POSTCOMMIT
84 };
85
86 /** Opaque module data pointer. */
87 typedef struct kadm5_hook_modinfo_st kadm5_hook_modinfo;
88
89 /**
90  * Interface for the v1 virtual table for the kadm5_hook plugin.
91  * All entry points are optional. The name field must be provided.
92  */
93 typedef struct kadm5_hook_vtable_1_st {
94
95     /** A text string identifying the plugin for logging messages. */
96     const char *name;
97
98     /** Initialize a plugin module.
99      * @param modinfo returns newly allocated module info for future
100      * calls.  Cleaned up by the fini() function.
101      */
102     kadm5_ret_t (*init)(krb5_context, kadm5_hook_modinfo **modinfo);
103
104     /** Clean up a module and free @a modinfo. */
105     void (*fini)(krb5_context, kadm5_hook_modinfo *modinfo);
106
107     /** Indicates that the password is being changed.
108      * @param stage is an integer from #kadm5_hook_stage enumeration
109      * @param keepold is true if existing keys are being kept.
110      * @param newpass is NULL if the key sare being randomized.
111      */
112     kadm5_ret_t (*chpass)(krb5_context,
113                           kadm5_hook_modinfo *modinfo,
114                           int stage,
115                           krb5_principal, krb5_boolean keepold,
116                           int n_ks_tuple,
117                           krb5_key_salt_tuple *ks_tuple,
118                           const char *newpass);
119
120     /** Indicate a principal is created. */
121     kadm5_ret_t (*create)(krb5_context,
122                           kadm5_hook_modinfo *,
123                           int stage,
124                           kadm5_principal_ent_t, long mask,
125                           int n_ks_tuple,
126                           krb5_key_salt_tuple *ks_tuple,
127                           const char *password);
128
129     /** Modify a principal. */
130     kadm5_ret_t (*modify)(krb5_context,
131                           kadm5_hook_modinfo *,
132                           int stage,
133                           kadm5_principal_ent_t, long mask);
134
135     /** Indicate a principal is deleted. */
136     kadm5_ret_t (*remove)(krb5_context,
137                           kadm5_hook_modinfo *modinfo,
138                           int stage, krb5_principal);
139
140     /* End of minor version 1. */
141 } kadm5_hook_vftable_1;
142
143 #endif /*H_KRB5_KADM5_HOOK_PLUGIN*/