auth.h 3.0 KB

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