svcauth.h 5.6 KB

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