svcauth.h 5.9 KB

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