auth.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* @(#)auth.h 2.3 88/08/07 4.0 RPCSRC; from 1.17 88/02/08 SMI */
  2. /*
  3. * Copyright (c) 2010, Oracle America, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions 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. * * Neither the name of the "Oracle America, Inc." nor the names of
  19. * its contributors may be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  24. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  25. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  28. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * auth.h, Authentication interface.
  36. *
  37. * The data structures are completely opaque to the client. The client
  38. * is required to pass a AUTH * to routines that create rpc
  39. * "sessions".
  40. */
  41. #ifndef GSSRPC_AUTH_H
  42. #define GSSRPC_AUTH_H
  43. #include <gssrpc/xdr.h>
  44. GSSRPC__BEGIN_DECLS
  45. #define MAX_AUTH_BYTES 400
  46. #define MAXNETNAMELEN 255 /* maximum length of network user's name */
  47. /*
  48. * Status returned from authentication check
  49. */
  50. enum auth_stat {
  51. AUTH_OK=0,
  52. /*
  53. * failed at remote end
  54. */
  55. AUTH_BADCRED=1, /* bogus credentials (seal broken) */
  56. AUTH_REJECTEDCRED=2, /* client should begin new session */
  57. AUTH_BADVERF=3, /* bogus verifier (seal broken) */
  58. AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
  59. AUTH_TOOWEAK=5, /* rejected due to security reasons */
  60. /*
  61. * failed locally
  62. */
  63. AUTH_INVALIDRESP=6, /* bogus response verifier */
  64. AUTH_FAILED=7, /* some unknown reason */
  65. /*
  66. * RPCSEC_GSS errors
  67. */
  68. RPCSEC_GSS_CREDPROBLEM = 13,
  69. RPCSEC_GSS_CTXPROBLEM = 14
  70. };
  71. union des_block {
  72. #if 0 /* XXX nothing uses this, anyway */
  73. struct {
  74. uint32_t high;
  75. uint32_t low;
  76. } key;
  77. #endif
  78. char c[8];
  79. };
  80. typedef union des_block des_block;
  81. extern bool_t xdr_des_block(XDR *, des_block *);
  82. /*
  83. * Authentication info. Opaque to client.
  84. */
  85. struct opaque_auth {
  86. enum_t oa_flavor; /* flavor of auth */
  87. caddr_t oa_base; /* address of more auth stuff */
  88. u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
  89. };
  90. /*
  91. * Auth handle, interface to client side authenticators.
  92. */
  93. struct rpc_msg;
  94. typedef struct AUTH {
  95. struct opaque_auth ah_cred;
  96. struct opaque_auth ah_verf;
  97. union des_block ah_key;
  98. struct auth_ops {
  99. void (*ah_nextverf)(struct AUTH *);
  100. /* nextverf & serialize */
  101. int (*ah_marshal)(struct AUTH *, XDR *);
  102. /* validate varifier */
  103. int (*ah_validate)(struct AUTH *,
  104. struct opaque_auth *);
  105. /* refresh credentials */
  106. int (*ah_refresh)(struct AUTH *, struct rpc_msg *);
  107. /* destroy this structure */
  108. void (*ah_destroy)(struct AUTH *);
  109. /* encode data for wire */
  110. int (*ah_wrap)(struct AUTH *, XDR *,
  111. xdrproc_t, caddr_t);
  112. /* decode data from wire */
  113. int (*ah_unwrap)(struct AUTH *, XDR *,
  114. xdrproc_t, caddr_t);
  115. } *ah_ops;
  116. void *ah_private;
  117. } AUTH;
  118. /*
  119. * Authentication ops.
  120. * The ops and the auth handle provide the interface to the authenticators.
  121. *
  122. * AUTH *auth;
  123. * XDR *xdrs;
  124. * struct opaque_auth verf;
  125. */
  126. #define AUTH_NEXTVERF(auth) \
  127. ((*((auth)->ah_ops->ah_nextverf))(auth))
  128. #define auth_nextverf(auth) \
  129. ((*((auth)->ah_ops->ah_nextverf))(auth))
  130. #define AUTH_MARSHALL(auth, xdrs) \
  131. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  132. #define auth_marshall(auth, xdrs) \
  133. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  134. #define AUTH_VALIDATE(auth, verfp) \
  135. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  136. #define auth_validate(auth, verfp) \
  137. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  138. #define AUTH_REFRESH(auth, msg) \
  139. ((*((auth)->ah_ops->ah_refresh))(auth, msg))
  140. #define auth_refresh(auth, msg) \
  141. ((*((auth)->ah_ops->ah_refresh))(auth, msg))
  142. #define AUTH_WRAP(auth, xdrs, xfunc, xwhere) \
  143. ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
  144. xfunc, xwhere))
  145. #define auth_wrap(auth, xdrs, xfunc, xwhere) \
  146. ((*((auth)->ah_ops->ah_wrap))(auth, xdrs, \
  147. xfunc, xwhere))
  148. #define AUTH_UNWRAP(auth, xdrs, xfunc, xwhere) \
  149. ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
  150. xfunc, xwhere))
  151. #define auth_unwrap(auth, xdrs, xfunc, xwhere) \
  152. ((*((auth)->ah_ops->ah_unwrap))(auth, xdrs, \
  153. xfunc, xwhere))
  154. #define AUTH_DESTROY(auth) \
  155. ((*((auth)->ah_ops->ah_destroy))(auth))
  156. #define auth_destroy(auth) \
  157. ((*((auth)->ah_ops->ah_destroy))(auth))
  158. #ifdef GSSRPC__IMPL
  159. /* RENAMED: should be _null_auth if we can use reserved namespace. */
  160. extern struct opaque_auth gssrpc__null_auth;
  161. #endif
  162. /*
  163. * These are the various implementations of client side authenticators.
  164. */
  165. /*
  166. * Unix style authentication
  167. * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
  168. * char *machname;
  169. * int uid;
  170. * int gid;
  171. * int len;
  172. * int *aup_gids;
  173. */
  174. extern AUTH *authunix_create(char *machname, int uid, int gid, int len,
  175. int *aup_gids);
  176. extern AUTH *authunix_create_default(void); /* takes no parameters */
  177. extern AUTH *authnone_create(void); /* takes no parameters */
  178. extern AUTH *authdes_create();
  179. extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
  180. #define AUTH_NONE 0 /* no authentication */
  181. #define AUTH_NULL 0 /* backward compatibility */
  182. #define AUTH_UNIX 1 /* unix style (uid, gids) */
  183. #define AUTH_SHORT 2 /* short hand unix style */
  184. #define AUTH_DES 3 /* des style (encrypted timestamps) */
  185. #define AUTH_GSSAPI 300001 /* GSS-API style */
  186. #define RPCSEC_GSS 6 /* RPCSEC_GSS */
  187. #if 0
  188. /*
  189. * BACKWARDS COMPATIBILIY! OpenV*Secure 1.0 had AUTH_GSSAPI == 4. We
  190. * need to accept this value until 1.0 is dead.
  191. */
  192. /* This conflicts with AUTH_KERB (Solaris). */
  193. #define AUTH_GSSAPI_COMPAT 4
  194. #endif
  195. GSSRPC__END_DECLS
  196. #endif /* !defined(GSSRPC_AUTH_H) */