svcauth.h 6.2 KB

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