auth.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * auth.h, Authentication interface.
  3. *
  4. * Copyright (c) 2010, Oracle America, Inc.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following
  14. * disclaimer in the documentation and/or other materials
  15. * provided with the distribution.
  16. * * Neither the name of the "Oracle America, Inc." nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  27. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. * The data structures are completely opaque to the client. The client
  34. * is required to pass a AUTH * to routines that create rpc
  35. * "sessions".
  36. */
  37. #ifndef _RPC_AUTH_H
  38. #define _RPC_AUTH_H 1
  39. #include <features.h>
  40. #include <rpc/xdr.h>
  41. __BEGIN_DECLS
  42. #define MAX_AUTH_BYTES 400
  43. #define MAXNETNAMELEN 255 /* maximum length of network user's name */
  44. /*
  45. * Status returned from authentication check
  46. */
  47. enum auth_stat {
  48. AUTH_OK=0,
  49. /*
  50. * failed at remote end
  51. */
  52. AUTH_BADCRED=1, /* bogus credentials (seal broken) */
  53. AUTH_REJECTEDCRED=2, /* client should begin new session */
  54. AUTH_BADVERF=3, /* bogus verifier (seal broken) */
  55. AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
  56. AUTH_TOOWEAK=5, /* rejected due to security reasons */
  57. /*
  58. * failed locally
  59. */
  60. AUTH_INVALIDRESP=6, /* bogus response verifier */
  61. AUTH_FAILED=7 /* some unknown reason */
  62. };
  63. union des_block {
  64. struct {
  65. uint32_t high;
  66. uint32_t low;
  67. } key;
  68. char c[8];
  69. };
  70. typedef union des_block des_block;
  71. extern bool_t xdr_des_block (XDR *__xdrs, des_block *__blkp) __THROW;
  72. /*
  73. * Authentication info. Opaque to client.
  74. */
  75. struct opaque_auth {
  76. enum_t oa_flavor; /* flavor of auth */
  77. caddr_t oa_base; /* address of more auth stuff */
  78. u_int oa_length; /* not to exceed MAX_AUTH_BYTES */
  79. };
  80. /*
  81. * Auth handle, interface to client side authenticators.
  82. */
  83. typedef struct AUTH AUTH;
  84. struct AUTH {
  85. struct opaque_auth ah_cred;
  86. struct opaque_auth ah_verf;
  87. union des_block ah_key;
  88. struct auth_ops {
  89. void (*ah_nextverf) (AUTH *);
  90. int (*ah_marshal) (AUTH *, XDR *); /* nextverf & serialize */
  91. int (*ah_validate) (AUTH *, struct opaque_auth *);
  92. /* validate verifier */
  93. int (*ah_refresh) (AUTH *); /* refresh credentials */
  94. void (*ah_destroy) (AUTH *); /* destroy this structure */
  95. } *ah_ops;
  96. caddr_t ah_private;
  97. };
  98. /*
  99. * Authentication ops.
  100. * The ops and the auth handle provide the interface to the authenticators.
  101. *
  102. * AUTH *auth;
  103. * XDR *xdrs;
  104. * struct opaque_auth verf;
  105. */
  106. #define AUTH_NEXTVERF(auth) \
  107. ((*((auth)->ah_ops->ah_nextverf))(auth))
  108. #define auth_nextverf(auth) \
  109. ((*((auth)->ah_ops->ah_nextverf))(auth))
  110. #define AUTH_MARSHALL(auth, xdrs) \
  111. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  112. #define auth_marshall(auth, xdrs) \
  113. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  114. #define AUTH_VALIDATE(auth, verfp) \
  115. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  116. #define auth_validate(auth, verfp) \
  117. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  118. #define AUTH_REFRESH(auth) \
  119. ((*((auth)->ah_ops->ah_refresh))(auth))
  120. #define auth_refresh(auth) \
  121. ((*((auth)->ah_ops->ah_refresh))(auth))
  122. #define AUTH_DESTROY(auth) \
  123. ((*((auth)->ah_ops->ah_destroy))(auth))
  124. #define auth_destroy(auth) \
  125. ((*((auth)->ah_ops->ah_destroy))(auth))
  126. extern struct opaque_auth _null_auth;
  127. /*
  128. * These are the various implementations of client side authenticators.
  129. */
  130. /*
  131. * Unix style authentication
  132. * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
  133. * char *machname;
  134. * int uid;
  135. * int gid;
  136. * int len;
  137. * int *aup_gids;
  138. */
  139. extern AUTH *authunix_create (char *__machname, __uid_t __uid, __gid_t __gid,
  140. int __len, __gid_t *__aup_gids);
  141. extern AUTH *authunix_create_default (void);
  142. extern AUTH *authnone_create (void) __THROW;
  143. extern AUTH *authdes_create (const char *__servername, u_int __window,
  144. struct sockaddr *__syncaddr, des_block *__ckey)
  145. __THROW;
  146. extern AUTH *authdes_pk_create (const char *, netobj *, u_int,
  147. struct sockaddr *, des_block *) __THROW;
  148. #define AUTH_NONE 0 /* no authentication */
  149. #define AUTH_NULL 0 /* backward compatibility */
  150. #define AUTH_SYS 1 /* unix style (uid, gids) */
  151. #define AUTH_UNIX AUTH_SYS
  152. #define AUTH_SHORT 2 /* short hand unix style */
  153. #define AUTH_DES 3 /* des style (encrypted timestamps) */
  154. #define AUTH_DH AUTH_DES /* Diffie-Hellman (this is DES) */
  155. #define AUTH_KERB 4 /* kerberos style */
  156. /*
  157. * Netname manipulating functions
  158. *
  159. */
  160. extern int getnetname (char *) __THROW;
  161. extern int host2netname (char *, const char *, const char *) __THROW;
  162. extern int user2netname (char *, const uid_t, const char *) __THROW;
  163. extern int netname2user (const char *, uid_t *, gid_t *, int *, gid_t *)
  164. __THROW;
  165. extern int netname2host (const char *, char *, const int) __THROW;
  166. /*
  167. *
  168. * These routines interface to the keyserv daemon
  169. *
  170. */
  171. extern int key_decryptsession (char *, des_block *);
  172. extern int key_decryptsession_pk (char *, netobj *, des_block *);
  173. extern int key_encryptsession (char *, des_block *);
  174. extern int key_encryptsession_pk (char *, netobj *, des_block *);
  175. extern int key_gendes (des_block *);
  176. extern int key_setsecret (char *);
  177. extern int key_secretkey_is_set (void);
  178. extern int key_get_conv (char *, des_block *);
  179. /*
  180. * XDR an opaque authentication struct.
  181. */
  182. extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *) __THROW;
  183. __END_DECLS
  184. #endif /* rpc/auth.h */