Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
5.2 KiB

  1. /* $OpenBSD: auth.h,v 1.5 2004/01/22 21:48:02 espie Exp $ */
  2. /* $NetBSD: auth.h,v 1.7 1995/04/29 05:27:55 cgd Exp $ */
  3. /*
  4. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  5. * unrestricted use provided that this legend is included on all tape
  6. * media and as a part of the software program in whole or part. Users
  7. * may copy or modify Sun RPC without charge, but are not authorized
  8. * to license or distribute it to anyone else except as part of a product or
  9. * program developed by the user.
  10. *
  11. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  12. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  13. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  14. *
  15. * Sun RPC is provided with no support and without any obligation on the
  16. * part of Sun Microsystems, Inc. to assist in its use, correction,
  17. * modification or enhancement.
  18. *
  19. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  20. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  21. * OR ANY PART THEREOF.
  22. *
  23. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  24. * or profits or other special, indirect and consequential damages, even if
  25. * Sun has been advised of the possibility of such damages.
  26. *
  27. * Sun Microsystems, Inc.
  28. * 2550 Garcia Avenue
  29. * Mountain View, California 94043
  30. *
  31. * from: @(#)auth.h 1.17 88/02/08 SMI
  32. * @(#)auth.h 2.3 88/08/07 4.0 RPCSRC
  33. */
  34. /*
  35. * auth.h, Authentication interface.
  36. *
  37. * Copyright (C) 1984, Sun Microsystems, Inc.
  38. *
  39. * The data structures are completely opaque to the client. The client
  40. * is required to pass a AUTH * to routines that create rpc
  41. * "sessions".
  42. */
  43. #ifndef _RPC_AUTH_H
  44. #define _RPC_AUTH_H
  45. #include <sys/cdefs.h>
  46. #define MAX_AUTH_BYTES 400
  47. #define MAXNETNAMELEN 255 /* maximum length of network user's name */
  48. /*
  49. * Status returned from authentication check
  50. */
  51. enum auth_stat {
  52. AUTH_OK=0,
  53. /*
  54. * failed at remote end
  55. */
  56. AUTH_BADCRED=1, /* bogus credentials (seal broken) */
  57. AUTH_REJECTEDCRED=2, /* client should begin new session */
  58. AUTH_BADVERF=3, /* bogus verifier (seal broken) */
  59. AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
  60. AUTH_TOOWEAK=5, /* rejected due to security reasons */
  61. /*
  62. * failed locally
  63. */
  64. AUTH_INVALIDRESP=6, /* bogus response verifier */
  65. AUTH_FAILED=7 /* some unknown reason */
  66. };
  67. typedef u_int32_t u_int32; /* 32-bit unsigned integers */
  68. union des_block {
  69. struct {
  70. u_int32 high;
  71. u_int32 low;
  72. } key;
  73. char c[8];
  74. };
  75. typedef union des_block des_block;
  76. __BEGIN_DECLS
  77. extern bool_t xdr_des_block(XDR *, des_block *);
  78. __END_DECLS
  79. /*
  80. * Authentication info. Opaque to client.
  81. */
  82. struct opaque_auth {
  83. enum_t oa_flavor; /* flavor of auth */
  84. caddr_t oa_base; /* address of more auth stuff */
  85. unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */
  86. };
  87. /*
  88. * Auth handle, interface to client side authenticators.
  89. */
  90. typedef struct __rpc_auth {
  91. struct opaque_auth ah_cred;
  92. struct opaque_auth ah_verf;
  93. union des_block ah_key;
  94. struct auth_ops {
  95. void (*ah_nextverf)(struct __rpc_auth *);
  96. /* nextverf & serialize */
  97. int (*ah_marshal)(struct __rpc_auth *, XDR *);
  98. /* validate varifier */
  99. int (*ah_validate)(struct __rpc_auth *,
  100. struct opaque_auth *);
  101. /* refresh credentials */
  102. int (*ah_refresh)(struct __rpc_auth *);
  103. /* destroy this structure */
  104. void (*ah_destroy)(struct __rpc_auth *);
  105. } *ah_ops;
  106. caddr_t ah_private;
  107. } AUTH;
  108. /*
  109. * Authentication ops.
  110. * The ops and the auth handle provide the interface to the authenticators.
  111. *
  112. * AUTH *auth;
  113. * XDR *xdrs;
  114. * struct opaque_auth verf;
  115. */
  116. #define AUTH_NEXTVERF(auth) \
  117. ((*((auth)->ah_ops->ah_nextverf))(auth))
  118. #define auth_nextverf(auth) \
  119. ((*((auth)->ah_ops->ah_nextverf))(auth))
  120. #define AUTH_MARSHALL(auth, xdrs) \
  121. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  122. #define auth_marshall(auth, xdrs) \
  123. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  124. #define AUTH_VALIDATE(auth, verfp) \
  125. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  126. #define auth_validate(auth, verfp) \
  127. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  128. #define AUTH_REFRESH(auth) \
  129. ((*((auth)->ah_ops->ah_refresh))(auth))
  130. #define auth_refresh(auth) \
  131. ((*((auth)->ah_ops->ah_refresh))(auth))
  132. #define AUTH_DESTROY(auth) \
  133. ((*((auth)->ah_ops->ah_destroy))(auth))
  134. #define auth_destroy(auth) \
  135. ((*((auth)->ah_ops->ah_destroy))(auth))
  136. extern struct opaque_auth _null_auth;
  137. /*
  138. * These are the various implementations of client side authenticators.
  139. */
  140. /*
  141. * Unix style authentication
  142. * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
  143. * char *machname;
  144. * int uid;
  145. * int gid;
  146. * int len;
  147. * int *aup_gids;
  148. */
  149. __BEGIN_DECLS
  150. struct sockaddr_in;
  151. extern AUTH *authunix_create(char *, int, int, int, int *);
  152. extern AUTH *authunix_create_default(void);
  153. extern AUTH *authnone_create(void);
  154. extern AUTH *authdes_create(char *, unsigned int, struct sockaddr_in *,
  155. des_block *);
  156. __END_DECLS
  157. #define AUTH_NONE 0 /* no authentication */
  158. #define AUTH_NULL 0 /* backward compatibility */
  159. #define AUTH_UNIX 1 /* unix style (uid, gids) */
  160. #define AUTH_SHORT 2 /* short hand unix style */
  161. #define AUTH_DES 3 /* des style (encrypted timestamps) */
  162. #endif /* !_RPC_AUTH_H */