+- add patches.fixes/linux-post-2.6.3-20040220
[linux-flexiantxendom0-3.2.10.git] / include / linux / sunrpc / svcauth.h
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
9 #ifndef _LINUX_SUNRPC_SVCAUTH_H_
10 #define _LINUX_SUNRPC_SVCAUTH_H_
11
12 #ifdef __KERNEL__
13
14 #include <linux/string.h>
15 #include <linux/sunrpc/msg_prot.h>
16 #include <linux/sunrpc/cache.h>
17 #include <linux/hash.h>
18
19 #define SVC_CRED_NGROUPS        32
20 struct svc_cred {
21         uid_t                   cr_uid;
22         gid_t                   cr_gid;
23         gid_t                   cr_groups[SVC_CRED_NGROUPS];
24 };
25
26 struct svc_rqst;                /* forward decl */
27
28 /* Authentication is done in the context of a domain.
29  * For a server, a domain represents a group of clients using
30  * a common mechanism for authentication and having a common mapping
31  * between local identity (uid) and network identity.  All clients
32  * in a domain have similar general access rights.  Each domain can
33  * contain multiple principals which will have different specific right
34  * based on normal Discretionary Access Control.
35  *
36  * For a client, a domain represents a number of servers which all
37  * use a common authentication mechanism and network identity name space.
38  *
39  * A domain is created by an authentication flavour module based on name
40  * only.  Userspace then fills in detail on demand.
41  *
42  * The creation of a domain typically implies creation of one or
43  * more caches for storing domain specific information.
44  */
45 struct auth_domain {
46         struct  cache_head      h;
47         char                    *name;
48         int                     flavour;
49 };
50
51 /*
52  * Each authentication flavour registers an auth_ops
53  * structure.
54  * name is simply the name.
55  * flavour gives the auth flavour. It determines where the flavour is registered
56  * accept() is given a request and should verify it.
57  *   It should inspect the authenticator and verifier, and possibly the data.
58  *    If there is a problem with the authentication *authp should be set.
59  *    The return value of accept() can indicate:
60  *      OK - authorised. client and credential are set in rqstp.
61  *           reqbuf points to arguments
62  *           resbuf points to good place for results.  verfier
63  *             is (probably) already in place.  Certainly space is
64  *             reserved for it.
65  *      DROP - simply drop the request. It may have been deferred
66  *      GARBAGE - rpc garbage_args error
67  *      SYSERR - rpc system_err error
68  *      DENIED - authp holds reason for denial.
69  *
70  *   accept is passed the proc number so that it can accept NULL rpc requests
71  *   even if it cannot authenticate the client (as is sometimes appropriate).
72  *
73  * release() is given a request after the procedure has been run.
74  *  It should sign/encrypt the results if needed
75  * It should return:
76  *    OK - the resbuf is ready to be sent
77  *    DROP - the reply should be quitely dropped
78  *    DENIED - authp holds a reason for MSG_DENIED
79  *    SYSERR - rpc system_err
80  *
81  * domain_release()
82  *   This call releases a domain.
83  */
84 struct auth_ops {
85         char *  name;
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 };
91 extern struct auth_ops  *authtab[RPC_AUTH_MAXFLAVOR];
92
93 #define SVC_GARBAGE     1
94 #define SVC_SYSERR      2
95 #define SVC_VALID       3
96 #define SVC_NEGATIVE    4
97 #define SVC_OK          5
98 #define SVC_DROP        6
99 #define SVC_DENIED      7
100 #define SVC_PENDING     8
101
102
103 extern int      svc_authenticate(struct svc_rqst *rqstp, u32 *authp);
104 extern int      svc_authorise(struct svc_rqst *rqstp);
105 extern int      svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
106 extern void     svc_auth_unregister(rpc_authflavor_t flavor);
107
108 extern struct auth_domain *unix_domain_find(char *name);
109 extern void auth_domain_put(struct auth_domain *item);
110 extern int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom);
111 extern struct auth_domain *auth_domain_lookup(struct auth_domain *item, int set);
112 extern struct auth_domain *auth_domain_find(char *name);
113 extern struct auth_domain *auth_unix_lookup(struct in_addr addr);
114 extern int auth_unix_forget_old(struct auth_domain *dom);
115 extern void svcauth_unix_purge(void);
116
117 static inline unsigned long hash_str(char *name, int bits)
118 {
119         unsigned long hash = 0;
120         unsigned long l = 0;
121         int len = 0;
122         unsigned char c;
123         do {
124                 if (unlikely(!(c = *name++))) {
125                         c = (char)len; len = -1;
126                 }
127                 l = (l << 8) | c;
128                 len++;
129                 if ((len & (BITS_PER_LONG/8-1))==0)
130                         hash = hash_long(hash^l, BITS_PER_LONG);
131         } while (len);
132         return hash >> (BITS_PER_LONG - bits);
133 }
134
135 static inline unsigned long hash_mem(char *buf, int length, int bits)
136 {
137         unsigned long hash = 0;
138         unsigned long l = 0;
139         int len = 0;
140         unsigned char c;
141         do {
142                 if (len == length) {
143                         c = (char)len; len = -1;
144                 } else
145                         c = *buf++;
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
154 extern struct cache_detail auth_domain_cache, ip_map_cache;
155
156 #endif /* __KERNEL__ */
157
158 #endif /* _LINUX_SUNRPC_SVCAUTH_H_ */