auth.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/include/linux/sunrpc/auth.h
  4. *
  5. * Declarations for the RPC client authentication machinery.
  6. *
  7. * Copyright (C) 1996, Olaf Kirch <[email protected]>
  8. */
  9. #ifndef _LINUX_SUNRPC_AUTH_H
  10. #define _LINUX_SUNRPC_AUTH_H
  11. #include <linux/sunrpc/sched.h>
  12. #include <linux/sunrpc/msg_prot.h>
  13. #include <linux/sunrpc/xdr.h>
  14. #include <linux/atomic.h>
  15. #include <linux/rcupdate.h>
  16. #include <linux/uidgid.h>
  17. #include <linux/utsname.h>
  18. /*
  19. * Maximum size of AUTH_NONE authentication information, in XDR words.
  20. */
  21. #define NUL_CALLSLACK (4)
  22. #define NUL_REPLYSLACK (2)
  23. /*
  24. * Size of the nodename buffer. RFC1831 specifies a hard limit of 255 bytes,
  25. * but Linux hostnames are actually limited to __NEW_UTS_LEN bytes.
  26. */
  27. #define UNX_MAXNODENAME __NEW_UTS_LEN
  28. #define UNX_CALLSLACK (21 + XDR_QUADLEN(UNX_MAXNODENAME))
  29. #define UNX_NGROUPS 16
  30. struct rpcsec_gss_info;
  31. struct auth_cred {
  32. const struct cred *cred;
  33. const char *principal; /* If present, this is a machine credential */
  34. };
  35. /*
  36. * Client user credentials
  37. */
  38. struct rpc_auth;
  39. struct rpc_credops;
  40. struct rpc_cred {
  41. struct hlist_node cr_hash; /* hash chain */
  42. struct list_head cr_lru; /* lru garbage collection */
  43. struct rcu_head cr_rcu;
  44. struct rpc_auth * cr_auth;
  45. const struct rpc_credops *cr_ops;
  46. unsigned long cr_expire; /* when to gc */
  47. unsigned long cr_flags; /* various flags */
  48. refcount_t cr_count; /* ref count */
  49. const struct cred *cr_cred;
  50. /* per-flavor data */
  51. };
  52. #define RPCAUTH_CRED_NEW 0
  53. #define RPCAUTH_CRED_UPTODATE 1
  54. #define RPCAUTH_CRED_HASHED 2
  55. #define RPCAUTH_CRED_NEGATIVE 3
  56. const struct cred *rpc_machine_cred(void);
  57. /*
  58. * Client authentication handle
  59. */
  60. struct rpc_cred_cache;
  61. struct rpc_authops;
  62. struct rpc_auth {
  63. unsigned int au_cslack; /* call cred size estimate */
  64. unsigned int au_rslack; /* reply cred size estimate */
  65. unsigned int au_verfsize; /* size of reply verifier */
  66. unsigned int au_ralign; /* words before UL header */
  67. unsigned long au_flags;
  68. const struct rpc_authops *au_ops;
  69. rpc_authflavor_t au_flavor; /* pseudoflavor (note may
  70. * differ from the flavor in
  71. * au_ops->au_flavor in gss
  72. * case) */
  73. refcount_t au_count; /* Reference counter */
  74. struct rpc_cred_cache * au_credcache;
  75. /* per-flavor data */
  76. };
  77. /* rpc_auth au_flags */
  78. #define RPCAUTH_AUTH_DATATOUCH (1)
  79. #define RPCAUTH_AUTH_UPDATE_SLACK (2)
  80. struct rpc_auth_create_args {
  81. rpc_authflavor_t pseudoflavor;
  82. const char *target_name;
  83. };
  84. /* Flags for rpcauth_lookupcred() */
  85. #define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */
  86. #define RPCAUTH_LOOKUP_ASYNC 0x02 /* Don't block waiting for memory */
  87. /*
  88. * Client authentication ops
  89. */
  90. struct rpc_authops {
  91. struct module *owner;
  92. rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */
  93. char * au_name;
  94. struct rpc_auth * (*create)(const struct rpc_auth_create_args *,
  95. struct rpc_clnt *);
  96. void (*destroy)(struct rpc_auth *);
  97. int (*hash_cred)(struct auth_cred *, unsigned int);
  98. struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
  99. struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int, gfp_t);
  100. rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *);
  101. int (*flavor2info)(rpc_authflavor_t,
  102. struct rpcsec_gss_info *);
  103. int (*key_timeout)(struct rpc_auth *,
  104. struct rpc_cred *);
  105. };
  106. struct rpc_credops {
  107. const char * cr_name; /* Name of the auth flavour */
  108. int (*cr_init)(struct rpc_auth *, struct rpc_cred *);
  109. void (*crdestroy)(struct rpc_cred *);
  110. int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
  111. int (*crmarshal)(struct rpc_task *task,
  112. struct xdr_stream *xdr);
  113. int (*crrefresh)(struct rpc_task *);
  114. int (*crvalidate)(struct rpc_task *task,
  115. struct xdr_stream *xdr);
  116. int (*crwrap_req)(struct rpc_task *task,
  117. struct xdr_stream *xdr);
  118. int (*crunwrap_resp)(struct rpc_task *task,
  119. struct xdr_stream *xdr);
  120. int (*crkey_timeout)(struct rpc_cred *);
  121. char * (*crstringify_acceptor)(struct rpc_cred *);
  122. bool (*crneed_reencode)(struct rpc_task *);
  123. };
  124. extern const struct rpc_authops authunix_ops;
  125. extern const struct rpc_authops authnull_ops;
  126. int __init rpc_init_authunix(void);
  127. int __init rpcauth_init_module(void);
  128. void rpcauth_remove_module(void);
  129. void rpc_destroy_authunix(void);
  130. int rpcauth_register(const struct rpc_authops *);
  131. int rpcauth_unregister(const struct rpc_authops *);
  132. struct rpc_auth * rpcauth_create(const struct rpc_auth_create_args *,
  133. struct rpc_clnt *);
  134. void rpcauth_release(struct rpc_auth *);
  135. rpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t,
  136. struct rpcsec_gss_info *);
  137. int rpcauth_get_gssinfo(rpc_authflavor_t,
  138. struct rpcsec_gss_info *);
  139. struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int, gfp_t);
  140. void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
  141. struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
  142. void put_rpccred(struct rpc_cred *);
  143. int rpcauth_marshcred(struct rpc_task *task,
  144. struct xdr_stream *xdr);
  145. int rpcauth_checkverf(struct rpc_task *task,
  146. struct xdr_stream *xdr);
  147. int rpcauth_wrap_req_encode(struct rpc_task *task,
  148. struct xdr_stream *xdr);
  149. int rpcauth_wrap_req(struct rpc_task *task,
  150. struct xdr_stream *xdr);
  151. int rpcauth_unwrap_resp_decode(struct rpc_task *task,
  152. struct xdr_stream *xdr);
  153. int rpcauth_unwrap_resp(struct rpc_task *task,
  154. struct xdr_stream *xdr);
  155. bool rpcauth_xmit_need_reencode(struct rpc_task *task);
  156. int rpcauth_refreshcred(struct rpc_task *);
  157. void rpcauth_invalcred(struct rpc_task *);
  158. int rpcauth_uptodatecred(struct rpc_task *);
  159. int rpcauth_init_credcache(struct rpc_auth *);
  160. void rpcauth_destroy_credcache(struct rpc_auth *);
  161. void rpcauth_clear_credcache(struct rpc_cred_cache *);
  162. char * rpcauth_stringify_acceptor(struct rpc_cred *);
  163. static inline
  164. struct rpc_cred *get_rpccred(struct rpc_cred *cred)
  165. {
  166. if (cred != NULL && refcount_inc_not_zero(&cred->cr_count))
  167. return cred;
  168. return NULL;
  169. }
  170. #endif /* _LINUX_SUNRPC_AUTH_H */