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