kadm5_hook_plugin.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifndef H_KRB5_KADM5_HOOK_PLUGIN
  26. #define H_KRB5_KADM5_HOOK_PLUGIN
  27. /**
  28. * @file krb5/krb5_kadm5_hook_plugin.h
  29. * Provide a plugin interface for kadm5 operations. This interface
  30. * permits a plugin to intercept principal modification, creation and
  31. * change password operations. Operations run at two stages: a
  32. * precommit stage that runs before the operation is committed to the
  33. * database and a postcommit operation that runs after the database
  34. * is updated; see #kadm5_hook_stage for details on semantics.
  35. *
  36. * This interface is based on a proposed extension to Heimdal by Russ
  37. * Allbery; it is likely that Heimdal will adopt an approach based on
  38. * stacked kdb modules rather than this interface. For MIT, writing a
  39. * plugin to this interface is significantly easier than stacking kdb
  40. * modules. Also, the kadm5 interface is significantly more stable
  41. * than the kdb interface, so this approach is more desirable than
  42. * stacked kdb modules.
  43. *
  44. * This interface depends on kadm5/admin.h. As such, the interface
  45. * does not provide strong guarantees of ABI stability.
  46. *
  47. * kadm5_hook plugins should:
  48. * kadm5_hook_<modulename>_initvt, matching the signature:
  49. *
  50. * krb5_error_code
  51. * kadm5_hook_modname_initvt(krb5_context context, int maj_ver, int min_ver,
  52. * krb5_plugin_vtable vtable);
  53. *
  54. * The initvt function should:
  55. *
  56. * - Check that the supplied maj_ver number is supported by the module, or
  57. * return KRB5_PLUGIN_VER_NOTSUPP if it is not.
  58. *
  59. * - Cast the vtable pointer as appropriate for maj_ver:
  60. * maj_ver == 1: Cast to kadm5_hook_vftable_1
  61. *
  62. * - Initialize the methods of the vtable, stopping as appropriate for the
  63. * supplied min_ver. Optional methods may be left uninitialized.
  64. *
  65. * Memory for the vtable is allocated by the caller, not by the module.
  66. */
  67. #include <krb5/krb5.h>
  68. #include <krb5/plugin.h>
  69. #include <kadm5/admin.h>
  70. /**
  71. * Whether the operation is being run before or after the database
  72. * update.
  73. */
  74. enum kadm5_hook_stage {
  75. /** In this stage, any plugin failure prevents following plugins from
  76. * running and aborts the operation.*/
  77. KADM5_HOOK_STAGE_PRECOMMIT,
  78. /** In this stage, plugin failures are logged but otherwise ignored.*/
  79. KADM5_HOOK_STAGE_POSTCOMMIT
  80. };
  81. /** Opaque module data pointer. */
  82. typedef struct kadm5_hook_modinfo_st kadm5_hook_modinfo;
  83. /**
  84. * Interface for the v1 virtual table for the kadm5_hook plugin.
  85. * All entry points are optional. The name field must be provided.
  86. */
  87. typedef struct kadm5_hook_vtable_1_st {
  88. /** A text string identifying the plugin for logging messages. */
  89. const char *name;
  90. /** Initialize a plugin module.
  91. * @param modinfo returns newly allocated module info for future
  92. * calls. Cleaned up by the fini() function.
  93. */
  94. kadm5_ret_t (*init)(krb5_context, kadm5_hook_modinfo **modinfo);
  95. /** Clean up a module and free @a modinfo. */
  96. void (*fini)(krb5_context, kadm5_hook_modinfo *modinfo);
  97. /** Indicates that the password is being changed.
  98. * @param stage is an integer from #kadm5_hook_stage enumeration
  99. * @param keepold is true if existing keys are being kept.
  100. */
  101. kadm5_ret_t (*chpass)(krb5_context,
  102. kadm5_hook_modinfo *modinfo,
  103. int stage,
  104. krb5_principal, krb5_boolean keepold,
  105. int n_ks_tuple,
  106. krb5_key_salt_tuple *ks_tuple,
  107. const char *newpass);
  108. /** Indicate a principal is created. */
  109. kadm5_ret_t (*create)(krb5_context,
  110. kadm5_hook_modinfo *,
  111. int stage,
  112. kadm5_principal_ent_t, long mask,
  113. int n_ks_tuple,
  114. krb5_key_salt_tuple *ks_tuple,
  115. const char *password);
  116. /** Modify a principal. */
  117. kadm5_ret_t (*modify)(krb5_context,
  118. kadm5_hook_modinfo *,
  119. int stage,
  120. kadm5_principal_ent_t, long mask);
  121. /** Indicate a principal is deleted. */
  122. kadm5_ret_t (*remove)(krb5_context,
  123. kadm5_hook_modinfo *modinfo,
  124. int stage, krb5_principal);
  125. /* End of minor version 1. */
  126. } kadm5_hook_vftable_1;
  127. #endif /*H_KRB5_KADM5_HOOK_PLUGIN*/