auth.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef __AUTH_H__
  2. #define __AUTH_H__
  3. #include <rpc/xdr.h>
  4. /*
  5. * Status returned from authentication check
  6. */
  7. enum auth_stat {
  8. AUTH_OK=0,
  9. /*
  10. * failed at remote end
  11. */
  12. AUTH_BADCRED=1, /* bogus credentials (seal broken) */
  13. AUTH_REJECTEDCRED=2, /* client should begin new session */
  14. AUTH_BADVERF=3, /* bogus verifier (seal broken) */
  15. AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
  16. AUTH_TOOWEAK=5, /* rejected due to security reasons */
  17. /*
  18. * failed locally
  19. */
  20. AUTH_INVALIDRESP=6, /* bogus response verifier */
  21. AUTH_FAILED=7 /* some unknown reason */
  22. };
  23. union des_block {
  24. struct {
  25. uint32_t high;
  26. uint32_t low;
  27. } key;
  28. char c[8];
  29. };
  30. typedef union des_block des_block;
  31. /*
  32. * Authentication info. Opaque to client.
  33. */
  34. struct opaque_auth {
  35. enum_t oa_flavor; /* flavor of auth */
  36. char* oa_base; /* address of more auth stuff */
  37. unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */
  38. };
  39. /*
  40. * Auth handle, interface to client side authenticators.
  41. */
  42. typedef struct AUTH AUTH;
  43. struct AUTH {
  44. struct opaque_auth ah_cred;
  45. struct opaque_auth ah_verf;
  46. union des_block ah_key;
  47. struct auth_ops {
  48. void (*ah_nextverf) (AUTH *);
  49. int (*ah_marshal) (AUTH *, XDR *); /* nextverf & serialize */
  50. int (*ah_validate) (AUTH *, struct opaque_auth *);
  51. /* validate verifier */
  52. int (*ah_refresh) (AUTH *); /* refresh credentials */
  53. void (*ah_destroy) (AUTH *); /* destroy this structure */
  54. } *ah_ops;
  55. char* ah_private;
  56. };
  57. extern struct opaque_auth _null_auth;
  58. /*
  59. * Authentication ops.
  60. * The ops and the auth handle provide the interface to the authenticators.
  61. *
  62. * AUTH *auth;
  63. * XDR *xdrs;
  64. * struct opaque_auth verf;
  65. */
  66. #define AUTH_NEXTVERF(auth) \
  67. ((*((auth)->ah_ops->ah_nextverf))(auth))
  68. #define auth_nextverf(auth) \
  69. ((*((auth)->ah_ops->ah_nextverf))(auth))
  70. #define AUTH_MARSHALL(auth, xdrs) \
  71. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  72. #define auth_marshall(auth, xdrs) \
  73. ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
  74. #define AUTH_VALIDATE(auth, verfp) \
  75. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  76. #define auth_validate(auth, verfp) \
  77. ((*((auth)->ah_ops->ah_validate))((auth), verfp))
  78. #define AUTH_REFRESH(auth) \
  79. ((*((auth)->ah_ops->ah_refresh))(auth))
  80. #define auth_refresh(auth) \
  81. ((*((auth)->ah_ops->ah_refresh))(auth))
  82. #define AUTH_DESTROY(auth) \
  83. ((*((auth)->ah_ops->ah_destroy))(auth))
  84. #define auth_destroy(auth) \
  85. ((*((auth)->ah_ops->ah_destroy))(auth))
  86. #define MAX_AUTH_BYTES 400
  87. #define MAXNETNAMELEN 255 /* maximum length of network user's name */
  88. AUTH *authnone_create(void);
  89. #endif