svcauth.h
上传用户:szlgq88
上传日期:2009-04-28
资源大小:48287k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

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