localauth_plugin.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * Declarations for localauth plugin module implementors.
  33. *
  34. * The localauth pluggable interface currently has only one supported major
  35. * version, which is 1. Major version 1 has a current minor version number of
  36. * 1.
  37. *
  38. * Localauth plugin modules should define a function named
  39. * localauth_<modulename>_initvt, matching the signature:
  40. *
  41. * krb5_error_code
  42. * localauth_modname_initvt(krb5_context context, int maj_ver, int min_ver,
  43. * krb5_plugin_vtable vtable);
  44. *
  45. * The initvt function should:
  46. *
  47. * - Check that the supplied maj_ver number is supported by the module, or
  48. * return KRB5_PLUGIN_VER_NOTSUPP if it is not.
  49. *
  50. * - Cast the vtable pointer as appropriate for maj_ver:
  51. * maj_ver == 1: Cast to krb5_localauth_vtable
  52. *
  53. * - Initialize the methods of the vtable, stopping as appropriate for the
  54. * supplied min_ver. Optional methods may be left uninitialized.
  55. *
  56. * Memory for the vtable is allocated by the caller, not by the module.
  57. */
  58. #ifndef KRB5_LOCALAUTH_PLUGIN_H
  59. #define KRB5_LOCALAUTH_PLUGIN_H
  60. #include <krb5/krb5.h>
  61. #include <krb5/plugin.h>
  62. /* An abstract type for localauth module data. */
  63. typedef struct krb5_localauth_moddata_st *krb5_localauth_moddata;
  64. /*** Method type declarations ***/
  65. /* Optional: Initialize module data. */
  66. typedef krb5_error_code
  67. (*krb5_localauth_init_fn)(krb5_context context,
  68. krb5_localauth_moddata *data);
  69. /* Optional: Release resources used by module data. */
  70. typedef void
  71. (*krb5_localauth_fini_fn)(krb5_context context, krb5_localauth_moddata data);
  72. /*
  73. * Optional: Determine whether aname is authorized to log in as the local
  74. * account lname. Return 0 if aname is authorized, EPERM if aname is
  75. * authoritatively not authorized, KRB5_PLUGIN_NO_HANDLE if the module cannot
  76. * determine whether aname is authorized, and any other error code for a
  77. * serious failure to process the request. aname will be considered authorized
  78. * if at least one module returns 0 and all other modules return
  79. * KRB5_PLUGIN_NO_HANDLE.
  80. */
  81. typedef krb5_error_code
  82. (*krb5_localauth_userok_fn)(krb5_context context, krb5_localauth_moddata data,
  83. krb5_const_principal aname, const char *lname);
  84. /*
  85. * Optional (mandatory if an2ln_types is set): Determine the local account name
  86. * corresponding to aname. Return 0 and set *lname_out if a mapping can be
  87. * determined; the contents of *lname_out will later be released with a call to
  88. * the module's free_string method. Return KRB5_LNAME_NOTRANS if no mapping
  89. * can be determined. Return any other error code for a serious failure to
  90. * process the request; this will halt the krb5_aname_to_localname operation.
  91. *
  92. * If the module's an2ln_types field is set, this method will only be invoked
  93. * when a profile "auth_to_local" value references one of the module's types.
  94. * type and residual will be set to the type and residual of the auth_to_local
  95. * value.
  96. *
  97. * If the module's an2ln_types field is not set but the an2ln method is
  98. * implemented, this method will be invoked independently of the profile's
  99. * auth_to_local settings, with type and residual set to NULL. If multiple
  100. * modules are registered with an2ln methods but no an2ln_types field, the
  101. * order of invocation is not defined, but all such modules will be consulted
  102. * before the built-in mechanisms are tried.
  103. */
  104. typedef krb5_error_code
  105. (*krb5_localauth_an2ln_fn)(krb5_context context, krb5_localauth_moddata data,
  106. const char *type, const char *residual,
  107. krb5_const_principal aname, char **lname_out);
  108. /*
  109. * Optional (mandatory if an2ln is implemented): Release the memory returned by
  110. * an invocation of an2ln.
  111. */
  112. typedef void
  113. (*krb5_localauth_free_string_fn)(krb5_context context,
  114. krb5_localauth_moddata data, char *str);
  115. /* localauth vtable for major version 1. */
  116. typedef struct krb5_localauth_vtable_st {
  117. const char *name; /* Mandatory: name of module. */
  118. const char **an2ln_types; /* Optional: uppercase auth_to_local types */
  119. krb5_localauth_init_fn init;
  120. krb5_localauth_fini_fn fini;
  121. krb5_localauth_userok_fn userok;
  122. krb5_localauth_an2ln_fn an2ln;
  123. krb5_localauth_free_string_fn free_string;
  124. /* Minor version 1 ends here. */
  125. } *krb5_localauth_vtable;
  126. #endif /* KRB5_LOCALAUTH_PLUGIN_H */