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 * The kadm5_hook interface currently has only one supported major version, 50 * which is 1. Major version 1 has a current minor version number of 2. 51 * 52 * kadm5_hook plugins should: 53 * kadm5_hook_<modulename>_initvt, matching the signature: 54 * 55 * krb5_error_code 56 * kadm5_hook_modname_initvt(krb5_context context, int maj_ver, int min_ver, 57 * krb5_plugin_vtable vtable); 58 * 59 * The initvt function should: 60 * 61 * - Check that the supplied maj_ver number is supported by the module, or 62 * return KRB5_PLUGIN_VER_NOTSUPP if it is not. 63 * 64 * - Cast the vtable pointer as appropriate for maj_ver: 65 * maj_ver == 1: Cast to kadm5_hook_vftable_1 66 * 67 * - Initialize the methods of the vtable, stopping as appropriate for the 68 * supplied min_ver. Optional methods may be left uninitialized. 69 * 70 * Memory for the vtable is allocated by the caller, not by the module. 71 */ 72 73 #include <krb5/krb5.h> 74 #include <krb5/plugin.h> 75 #include <kadm5/admin.h> 76 77 /** 78 * Whether the operation is being run before or after the database 79 * update. 80 */ 81 enum kadm5_hook_stage { 82 /** In this stage, any plugin failure prevents following plugins from 83 * running and aborts the operation.*/ 84 KADM5_HOOK_STAGE_PRECOMMIT, 85 /** In this stage, plugin failures are logged but otherwise ignored.*/ 86 KADM5_HOOK_STAGE_POSTCOMMIT 87 }; 88 89 /** Opaque module data pointer. */ 90 typedef struct kadm5_hook_modinfo_st kadm5_hook_modinfo; 91 92 /** 93 * Interface for the v1 virtual table for the kadm5_hook plugin. 94 * All entry points are optional. The name field must be provided. 95 */ 96 typedef struct kadm5_hook_vtable_1_st { 97 98 /** A text string identifying the plugin for logging messages. */ 99 const char *name; 100 101 /** Initialize a plugin module. 102 * @param modinfo returns newly allocated module info for future 103 * calls. Cleaned up by the fini() function. 104 */ 105 kadm5_ret_t (*init)(krb5_context, kadm5_hook_modinfo **modinfo); 106 107 /** Clean up a module and free @a modinfo. */ 108 void (*fini)(krb5_context, kadm5_hook_modinfo *modinfo); 109 110 /** Indicates that the password is being changed. 111 * @param stage is an integer from #kadm5_hook_stage enumeration 112 * @param keepold is true if existing keys are being kept. 113 * @param newpass is NULL if the key sare being randomized. 114 */ 115 kadm5_ret_t (*chpass)(krb5_context, 116 kadm5_hook_modinfo *modinfo, 117 int stage, 118 krb5_principal, krb5_boolean keepold, 119 int n_ks_tuple, 120 krb5_key_salt_tuple *ks_tuple, 121 const char *newpass); 122 123 /** Indicate a principal is created. */ 124 kadm5_ret_t (*create)(krb5_context, 125 kadm5_hook_modinfo *, 126 int stage, 127 kadm5_principal_ent_t, long mask, 128 int n_ks_tuple, 129 krb5_key_salt_tuple *ks_tuple, 130 const char *password); 131 132 /** Modify a principal. */ 133 kadm5_ret_t (*modify)(krb5_context, 134 kadm5_hook_modinfo *, 135 int stage, 136 kadm5_principal_ent_t, long mask); 137 138 /** Indicate a principal is deleted. */ 139 kadm5_ret_t (*remove)(krb5_context, 140 kadm5_hook_modinfo *modinfo, 141 int stage, krb5_principal); 142 143 /* End of minor version 1. */ 144 145 /** Indicate a principal is renamed. */ 146 kadm5_ret_t (*rename)(krb5_context, 147 kadm5_hook_modinfo *modinfo, 148 int stage, krb5_principal, krb5_principal); 149 150 /* End of minor version 2. */ 151 152 } kadm5_hook_vftable_1; 153 154 #endif /*H_KRB5_KADM5_HOOK_PLUGIN*/ 155