svcauth.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/include/linux/sunrpc/svcauth.h
  4. *
  5. * RPC server-side authentication stuff.
  6. *
  7. * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  8. */
  9. #ifndef _LINUX_SUNRPC_SVCAUTH_H_
  10. #define _LINUX_SUNRPC_SVCAUTH_H_
  11. #ifdef __KERNEL__
  12. #include <linux/string.h>
  13. #include <linux/sunrpc/msg_prot.h>
  14. #include <linux/sunrpc/cache.h>
  15. #include <linux/sunrpc/gss_api.h>
  16. #include <linux/hash.h>
  17. #include <linux/stringhash.h>
  18. #include <linux/cred.h>
  19. struct svc_cred {
  20. kuid_t cr_uid;
  21. kgid_t cr_gid;
  22. struct group_info *cr_group_info;
  23. u32 cr_flavor; /* pseudoflavor */
  24. /* name of form servicetype/hostname@REALM, passed down by
  25. * gss-proxy: */
  26. char *cr_raw_principal;
  27. /* name of form servicetype@hostname, passed down by
  28. * rpc.svcgssd, or computed from the above: */
  29. char *cr_principal;
  30. char *cr_targ_princ;
  31. struct gss_api_mech *cr_gss_mech;
  32. };
  33. static inline void init_svc_cred(struct svc_cred *cred)
  34. {
  35. cred->cr_group_info = NULL;
  36. cred->cr_raw_principal = NULL;
  37. cred->cr_principal = NULL;
  38. cred->cr_targ_princ = NULL;
  39. cred->cr_gss_mech = NULL;
  40. }
  41. static inline void free_svc_cred(struct svc_cred *cred)
  42. {
  43. if (cred->cr_group_info)
  44. put_group_info(cred->cr_group_info);
  45. kfree(cred->cr_raw_principal);
  46. kfree(cred->cr_principal);
  47. kfree(cred->cr_targ_princ);
  48. gss_mech_put(cred->cr_gss_mech);
  49. init_svc_cred(cred);
  50. }
  51. struct svc_rqst; /* forward decl */
  52. struct in6_addr;
  53. /* Authentication is done in the context of a domain.
  54. *
  55. * Currently, the nfs server uses the auth_domain to stand
  56. * for the "client" listed in /etc/exports.
  57. *
  58. * More generally, a domain might represent a group of clients using
  59. * a common mechanism for authentication and having a common mapping
  60. * between local identity (uid) and network identity. All clients
  61. * in a domain have similar general access rights. Each domain can
  62. * contain multiple principals which will have different specific right
  63. * based on normal Discretionary Access Control.
  64. *
  65. * A domain is created by an authentication flavour module based on name
  66. * only. Userspace then fills in detail on demand.
  67. *
  68. * In the case of auth_unix and auth_null, the auth_domain is also
  69. * associated with entries in another cache representing the mapping
  70. * of ip addresses to the given client.
  71. */
  72. struct auth_domain {
  73. struct kref ref;
  74. struct hlist_node hash;
  75. char *name;
  76. struct auth_ops *flavour;
  77. };
  78. /*
  79. * Each authentication flavour registers an auth_ops
  80. * structure.
  81. * name is simply the name.
  82. * flavour gives the auth flavour. It determines where the flavour is registered
  83. * accept() is given a request and should verify it.
  84. * It should inspect the authenticator and verifier, and possibly the data.
  85. * If there is a problem with the authentication *authp should be set.
  86. * The return value of accept() can indicate:
  87. * OK - authorised. client and credential are set in rqstp.
  88. * reqbuf points to arguments
  89. * resbuf points to good place for results. verfier
  90. * is (probably) already in place. Certainly space is
  91. * reserved for it.
  92. * DROP - simply drop the request. It may have been deferred
  93. * GARBAGE - rpc garbage_args error
  94. * SYSERR - rpc system_err error
  95. * DENIED - authp holds reason for denial.
  96. * COMPLETE - the reply is encoded already and ready to be sent; no
  97. * further processing is necessary. (This is used for processing
  98. * null procedure calls which are used to set up encryption
  99. * contexts.)
  100. *
  101. * accept is passed the proc number so that it can accept NULL rpc requests
  102. * even if it cannot authenticate the client (as is sometimes appropriate).
  103. *
  104. * release() is given a request after the procedure has been run.
  105. * It should sign/encrypt the results if needed
  106. * It should return:
  107. * OK - the resbuf is ready to be sent
  108. * DROP - the reply should be quitely dropped
  109. * DENIED - authp holds a reason for MSG_DENIED
  110. * SYSERR - rpc system_err
  111. *
  112. * domain_release()
  113. * This call releases a domain.
  114. * set_client()
  115. * Givens a pending request (struct svc_rqst), finds and assigns
  116. * an appropriate 'auth_domain' as the client.
  117. */
  118. struct auth_ops {
  119. char * name;
  120. struct module *owner;
  121. int flavour;
  122. int (*accept)(struct svc_rqst *rq, __be32 *authp);
  123. int (*release)(struct svc_rqst *rq);
  124. void (*domain_release)(struct auth_domain *);
  125. int (*set_client)(struct svc_rqst *rq);
  126. };
  127. #define SVC_GARBAGE 1
  128. #define SVC_SYSERR 2
  129. #define SVC_VALID 3
  130. #define SVC_NEGATIVE 4
  131. #define SVC_OK 5
  132. #define SVC_DROP 6
  133. #define SVC_CLOSE 7 /* Like SVC_DROP, but request is definitely
  134. * lost so if there is a tcp connection, it
  135. * should be closed
  136. */
  137. #define SVC_DENIED 8
  138. #define SVC_PENDING 9
  139. #define SVC_COMPLETE 10
  140. struct svc_xprt;
  141. extern int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp);
  142. extern int svc_authorise(struct svc_rqst *rqstp);
  143. extern int svc_set_client(struct svc_rqst *rqstp);
  144. extern int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
  145. extern void svc_auth_unregister(rpc_authflavor_t flavor);
  146. extern struct auth_domain *unix_domain_find(char *name);
  147. extern void auth_domain_put(struct auth_domain *item);
  148. extern int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom);
  149. extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
  150. extern struct auth_domain *auth_domain_find(char *name);
  151. extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr);
  152. extern int auth_unix_forget_old(struct auth_domain *dom);
  153. extern void svcauth_unix_purge(struct net *net);
  154. extern void svcauth_unix_info_release(struct svc_xprt *xpt);
  155. extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
  156. extern int unix_gid_cache_create(struct net *net);
  157. extern void unix_gid_cache_destroy(struct net *net);
  158. /*
  159. * The <stringhash.h> functions are good enough that we don't need to
  160. * use hash_32() on them; just extracting the high bits is enough.
  161. */
  162. static inline unsigned long hash_str(char const *name, int bits)
  163. {
  164. return hashlen_hash(hashlen_string(NULL, name)) >> (32 - bits);
  165. }
  166. static inline unsigned long hash_mem(char const *buf, int length, int bits)
  167. {
  168. return full_name_hash(NULL, buf, length) >> (32 - bits);
  169. }
  170. #endif /* __KERNEL__ */
  171. #endif /* _LINUX_SUNRPC_SVCAUTH_H_ */