blob: 177f81608cfbaa1fd983b2b22497a74c58f96b67 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/types.h>
2#include <linux/sched.h>
3#include <linux/module.h>
4#include <linux/sunrpc/types.h>
5#include <linux/sunrpc/xdr.h>
6#include <linux/sunrpc/svcsock.h>
7#include <linux/sunrpc/svcauth.h>
8#include <linux/err.h>
9#include <linux/seq_file.h>
10#include <linux/hash.h>
Paulo Marques543537b2005-06-23 00:09:02 -070011#include <linux/string.h>
Greg Banks7b2b1fe2006-10-04 02:15:50 -070012#include <net/sock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#define RPCDBG_FACILITY RPCDBG_AUTH
15
16
17/*
18 * AUTHUNIX and AUTHNULL credentials are both handled here.
19 * AUTHNULL is treated just like AUTHUNIX except that the uid/gid
20 * are always nobody (-2). i.e. we do the same IP address checks for
21 * AUTHNULL as for AUTHUNIX, and that is done here.
22 */
23
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025struct unix_domain {
26 struct auth_domain h;
27 int addr_changes;
28 /* other stuff later */
29};
30
NeilBrownefc36aa2006-03-27 01:14:59 -080031extern struct auth_ops svcauth_unix;
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033struct auth_domain *unix_domain_find(char *name)
34{
NeilBrownefc36aa2006-03-27 01:14:59 -080035 struct auth_domain *rv;
36 struct unix_domain *new = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
NeilBrownefc36aa2006-03-27 01:14:59 -080038 rv = auth_domain_lookup(name, NULL);
39 while(1) {
NeilBrownad1b5222006-03-27 01:15:11 -080040 if (rv) {
41 if (new && rv != &new->h)
42 auth_domain_put(&new->h);
43
44 if (rv->flavour != &svcauth_unix) {
45 auth_domain_put(rv);
46 return NULL;
47 }
NeilBrownefc36aa2006-03-27 01:14:59 -080048 return rv;
49 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
NeilBrownefc36aa2006-03-27 01:14:59 -080051 new = kmalloc(sizeof(*new), GFP_KERNEL);
52 if (new == NULL)
53 return NULL;
54 kref_init(&new->h.ref);
55 new->h.name = kstrdup(name, GFP_KERNEL);
56 new->h.flavour = &svcauth_unix;
57 new->addr_changes = 0;
58 rv = auth_domain_lookup(name, &new->h);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
62static void svcauth_unix_domain_release(struct auth_domain *dom)
63{
64 struct unix_domain *ud = container_of(dom, struct unix_domain, h);
65
66 kfree(dom->name);
67 kfree(ud);
68}
69
70
71/**************************************************
72 * cache for IP address to unix_domain
73 * as needed by AUTH_UNIX
74 */
75#define IP_HASHBITS 8
76#define IP_HASHMAX (1<<IP_HASHBITS)
77#define IP_HASHMASK (IP_HASHMAX-1)
78
79struct ip_map {
80 struct cache_head h;
81 char m_class[8]; /* e.g. "nfsd" */
82 struct in_addr m_addr;
83 struct unix_domain *m_client;
84 int m_add_change;
85};
86static struct cache_head *ip_table[IP_HASHMAX];
87
NeilBrownbaab9352006-03-27 01:15:09 -080088static void ip_map_put(struct kref *kref)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
NeilBrownbaab9352006-03-27 01:15:09 -080090 struct cache_head *item = container_of(kref, struct cache_head, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 struct ip_map *im = container_of(item, struct ip_map,h);
NeilBrownbaab9352006-03-27 01:15:09 -080092
93 if (test_bit(CACHE_VALID, &item->flags) &&
94 !test_bit(CACHE_NEGATIVE, &item->flags))
95 auth_domain_put(&im->m_client->h);
96 kfree(im);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
NeilBrown1f1e0302006-01-06 00:09:49 -080099#if IP_HASHBITS == 8
100/* hash_long on a 64 bit machine is currently REALLY BAD for
101 * IP addresses in reverse-endian (i.e. on a little-endian machine).
102 * So use a trivial but reliable hash instead
103 */
Al Viro48061262006-11-08 00:22:34 -0800104static inline int hash_ip(__be32 ip)
NeilBrown1f1e0302006-01-06 00:09:49 -0800105{
Al Viro48061262006-11-08 00:22:34 -0800106 int hash = (__force u32)ip ^ ((__force u32)ip>>16);
NeilBrown1f1e0302006-01-06 00:09:49 -0800107 return (hash ^ (hash>>8)) & 0xff;
108}
109#endif
NeilBrown1a9917c2006-03-27 01:15:02 -0800110static int ip_map_match(struct cache_head *corig, struct cache_head *cnew)
111{
112 struct ip_map *orig = container_of(corig, struct ip_map, h);
113 struct ip_map *new = container_of(cnew, struct ip_map, h);
114 return strcmp(orig->m_class, new->m_class) == 0
115 && orig->m_addr.s_addr == new->m_addr.s_addr;
116}
117static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
118{
119 struct ip_map *new = container_of(cnew, struct ip_map, h);
120 struct ip_map *item = container_of(citem, struct ip_map, h);
NeilBrown1f1e0302006-01-06 00:09:49 -0800121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 strcpy(new->m_class, item->m_class);
123 new->m_addr.s_addr = item->m_addr.s_addr;
124}
NeilBrown1a9917c2006-03-27 01:15:02 -0800125static void update(struct cache_head *cnew, struct cache_head *citem)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
NeilBrown1a9917c2006-03-27 01:15:02 -0800127 struct ip_map *new = container_of(cnew, struct ip_map, h);
128 struct ip_map *item = container_of(citem, struct ip_map, h);
129
NeilBrownefc36aa2006-03-27 01:14:59 -0800130 kref_get(&item->m_client->h.ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 new->m_client = item->m_client;
132 new->m_add_change = item->m_add_change;
133}
NeilBrown1a9917c2006-03-27 01:15:02 -0800134static struct cache_head *ip_map_alloc(void)
135{
136 struct ip_map *i = kmalloc(sizeof(*i), GFP_KERNEL);
137 if (i)
138 return &i->h;
139 else
140 return NULL;
141}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143static void ip_map_request(struct cache_detail *cd,
144 struct cache_head *h,
145 char **bpp, int *blen)
146{
147 char text_addr[20];
148 struct ip_map *im = container_of(h, struct ip_map, h);
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700149 __be32 addr = im->m_addr.s_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 snprintf(text_addr, 20, "%u.%u.%u.%u",
152 ntohl(addr) >> 24 & 0xff,
153 ntohl(addr) >> 16 & 0xff,
154 ntohl(addr) >> 8 & 0xff,
155 ntohl(addr) >> 0 & 0xff);
156
157 qword_add(bpp, blen, im->m_class);
158 qword_add(bpp, blen, text_addr);
159 (*bpp)[-1] = '\n';
160}
161
NeilBrown1a9917c2006-03-27 01:15:02 -0800162static struct ip_map *ip_map_lookup(char *class, struct in_addr addr);
163static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165static int ip_map_parse(struct cache_detail *cd,
166 char *mesg, int mlen)
167{
168 /* class ipaddress [domainname] */
169 /* should be safe just to use the start of the input buffer
170 * for scratch: */
171 char *buf = mesg;
172 int len;
173 int b1,b2,b3,b4;
174 char c;
NeilBrown1a9917c2006-03-27 01:15:02 -0800175 char class[8];
176 struct in_addr addr;
177 int err;
178
179 struct ip_map *ipmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 struct auth_domain *dom;
181 time_t expiry;
182
183 if (mesg[mlen-1] != '\n')
184 return -EINVAL;
185 mesg[mlen-1] = 0;
186
187 /* class */
NeilBrown1a9917c2006-03-27 01:15:02 -0800188 len = qword_get(&mesg, class, sizeof(class));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (len <= 0) return -EINVAL;
190
191 /* ip address */
192 len = qword_get(&mesg, buf, mlen);
193 if (len <= 0) return -EINVAL;
194
195 if (sscanf(buf, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) != 4)
196 return -EINVAL;
197
198 expiry = get_expiry(&mesg);
199 if (expiry ==0)
200 return -EINVAL;
201
202 /* domainname, or empty for NEGATIVE */
203 len = qword_get(&mesg, buf, mlen);
204 if (len < 0) return -EINVAL;
205
206 if (len) {
207 dom = unix_domain_find(buf);
208 if (dom == NULL)
209 return -ENOENT;
210 } else
211 dom = NULL;
212
NeilBrown1a9917c2006-03-27 01:15:02 -0800213 addr.s_addr =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
NeilBrown1a9917c2006-03-27 01:15:02 -0800216 ipmp = ip_map_lookup(class,addr);
217 if (ipmp) {
218 err = ip_map_update(ipmp,
219 container_of(dom, struct unix_domain, h),
220 expiry);
221 } else
222 err = -ENOMEM;
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 if (dom)
225 auth_domain_put(dom);
NeilBrown1a9917c2006-03-27 01:15:02 -0800226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 cache_flush();
NeilBrown1a9917c2006-03-27 01:15:02 -0800228 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
231static int ip_map_show(struct seq_file *m,
232 struct cache_detail *cd,
233 struct cache_head *h)
234{
235 struct ip_map *im;
236 struct in_addr addr;
237 char *dom = "-no-domain-";
238
239 if (h == NULL) {
240 seq_puts(m, "#class IP domain\n");
241 return 0;
242 }
243 im = container_of(h, struct ip_map, h);
244 /* class addr domain */
245 addr = im->m_addr;
246
247 if (test_bit(CACHE_VALID, &h->flags) &&
248 !test_bit(CACHE_NEGATIVE, &h->flags))
249 dom = im->m_client->h.name;
250
251 seq_printf(m, "%s %d.%d.%d.%d %s\n",
252 im->m_class,
Al Viro753ed902006-09-26 22:30:23 -0700253 ntohl(addr.s_addr) >> 24 & 0xff,
254 ntohl(addr.s_addr) >> 16 & 0xff,
255 ntohl(addr.s_addr) >> 8 & 0xff,
256 ntohl(addr.s_addr) >> 0 & 0xff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 dom
258 );
259 return 0;
260}
261
262
263struct cache_detail ip_map_cache = {
Bruce Allanf35279d2005-09-06 15:17:08 -0700264 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 .hash_size = IP_HASHMAX,
266 .hash_table = ip_table,
267 .name = "auth.unix.ip",
268 .cache_put = ip_map_put,
269 .cache_request = ip_map_request,
270 .cache_parse = ip_map_parse,
271 .cache_show = ip_map_show,
NeilBrown1a9917c2006-03-27 01:15:02 -0800272 .match = ip_map_match,
273 .init = ip_map_init,
274 .update = update,
275 .alloc = ip_map_alloc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276};
277
NeilBrown1a9917c2006-03-27 01:15:02 -0800278static struct ip_map *ip_map_lookup(char *class, struct in_addr addr)
279{
280 struct ip_map ip;
281 struct cache_head *ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
NeilBrown1a9917c2006-03-27 01:15:02 -0800283 strcpy(ip.m_class, class);
284 ip.m_addr = addr;
285 ch = sunrpc_cache_lookup(&ip_map_cache, &ip.h,
286 hash_str(class, IP_HASHBITS) ^
Al Viro48061262006-11-08 00:22:34 -0800287 hash_ip(addr.s_addr));
NeilBrown1a9917c2006-03-27 01:15:02 -0800288
289 if (ch)
290 return container_of(ch, struct ip_map, h);
291 else
292 return NULL;
293}
294
295static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry)
296{
297 struct ip_map ip;
298 struct cache_head *ch;
299
300 ip.m_client = udom;
301 ip.h.flags = 0;
302 if (!udom)
303 set_bit(CACHE_NEGATIVE, &ip.h.flags);
304 else {
305 ip.m_add_change = udom->addr_changes;
306 /* if this is from the legacy set_client system call,
307 * we need m_add_change to be one higher
308 */
309 if (expiry == NEVER)
310 ip.m_add_change++;
311 }
312 ip.h.expiry_time = expiry;
313 ch = sunrpc_cache_update(&ip_map_cache,
314 &ip.h, &ipm->h,
315 hash_str(ipm->m_class, IP_HASHBITS) ^
Al Viro48061262006-11-08 00:22:34 -0800316 hash_ip(ipm->m_addr.s_addr));
NeilBrown1a9917c2006-03-27 01:15:02 -0800317 if (!ch)
318 return -ENOMEM;
NeilBrownbaab9352006-03-27 01:15:09 -0800319 cache_put(ch, &ip_map_cache);
NeilBrown1a9917c2006-03-27 01:15:02 -0800320 return 0;
321}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom)
324{
325 struct unix_domain *udom;
NeilBrown1a9917c2006-03-27 01:15:02 -0800326 struct ip_map *ipmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
NeilBrownefc36aa2006-03-27 01:14:59 -0800328 if (dom->flavour != &svcauth_unix)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return -EINVAL;
330 udom = container_of(dom, struct unix_domain, h);
NeilBrown1a9917c2006-03-27 01:15:02 -0800331 ipmp = ip_map_lookup("nfsd", addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
NeilBrown1a9917c2006-03-27 01:15:02 -0800333 if (ipmp)
334 return ip_map_update(ipmp, udom, NEVER);
335 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 return -ENOMEM;
337}
338
339int auth_unix_forget_old(struct auth_domain *dom)
340{
341 struct unix_domain *udom;
342
NeilBrownefc36aa2006-03-27 01:14:59 -0800343 if (dom->flavour != &svcauth_unix)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 return -EINVAL;
345 udom = container_of(dom, struct unix_domain, h);
346 udom->addr_changes++;
347 return 0;
348}
349
350struct auth_domain *auth_unix_lookup(struct in_addr addr)
351{
Greg Banks40f10522006-10-02 02:17:43 -0700352 struct ip_map *ipm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 struct auth_domain *rv;
354
NeilBrown1a9917c2006-03-27 01:15:02 -0800355 ipm = ip_map_lookup("nfsd", addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 if (!ipm)
358 return NULL;
359 if (cache_check(&ip_map_cache, &ipm->h, NULL))
360 return NULL;
361
362 if ((ipm->m_client->addr_changes - ipm->m_add_change) >0) {
363 if (test_and_set_bit(CACHE_NEGATIVE, &ipm->h.flags) == 0)
364 auth_domain_put(&ipm->m_client->h);
365 rv = NULL;
366 } else {
367 rv = &ipm->m_client->h;
NeilBrownefc36aa2006-03-27 01:14:59 -0800368 kref_get(&rv->ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
NeilBrownbaab9352006-03-27 01:15:09 -0800370 cache_put(&ipm->h, &ip_map_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return rv;
372}
373
374void svcauth_unix_purge(void)
375{
376 cache_purge(&ip_map_cache);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
Greg Banks7b2b1fe2006-10-04 02:15:50 -0700379static inline struct ip_map *
380ip_map_cached_get(struct svc_rqst *rqstp)
381{
382 struct ip_map *ipm = rqstp->rq_sock->sk_info_authunix;
383 if (ipm != NULL) {
384 if (!cache_valid(&ipm->h)) {
385 /*
386 * The entry has been invalidated since it was
387 * remembered, e.g. by a second mount from the
388 * same IP address.
389 */
390 rqstp->rq_sock->sk_info_authunix = NULL;
391 cache_put(&ipm->h, &ip_map_cache);
392 return NULL;
393 }
394 cache_get(&ipm->h);
395 }
396 return ipm;
397}
398
399static inline void
400ip_map_cached_put(struct svc_rqst *rqstp, struct ip_map *ipm)
401{
402 struct svc_sock *svsk = rqstp->rq_sock;
403
404 if (svsk->sk_sock->type == SOCK_STREAM && svsk->sk_info_authunix == NULL)
405 svsk->sk_info_authunix = ipm; /* newly cached, keep the reference */
406 else
407 cache_put(&ipm->h, &ip_map_cache);
408}
409
410void
411svcauth_unix_info_release(void *info)
412{
413 struct ip_map *ipm = info;
414 cache_put(&ipm->h, &ip_map_cache);
415}
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417static int
418svcauth_unix_set_client(struct svc_rqst *rqstp)
419{
NeilBrown1a9917c2006-03-27 01:15:02 -0800420 struct ip_map *ipm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 rqstp->rq_client = NULL;
423 if (rqstp->rq_proc == 0)
424 return SVC_OK;
425
Greg Banks7b2b1fe2006-10-04 02:15:50 -0700426 ipm = ip_map_cached_get(rqstp);
427 if (ipm == NULL)
428 ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class,
429 rqstp->rq_addr.sin_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 if (ipm == NULL)
432 return SVC_DENIED;
433
434 switch (cache_check(&ip_map_cache, &ipm->h, &rqstp->rq_chandle)) {
435 default:
436 BUG();
437 case -EAGAIN:
J.Bruce Fieldse0bb89e2006-12-13 00:35:25 -0800438 case -ETIMEDOUT:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 return SVC_DROP;
440 case -ENOENT:
441 return SVC_DENIED;
442 case 0:
443 rqstp->rq_client = &ipm->m_client->h;
NeilBrownefc36aa2006-03-27 01:14:59 -0800444 kref_get(&rqstp->rq_client->ref);
Greg Banks7b2b1fe2006-10-04 02:15:50 -0700445 ip_map_cached_put(rqstp, ipm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 break;
447 }
448 return SVC_OK;
449}
450
451static int
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700452svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
454 struct kvec *argv = &rqstp->rq_arg.head[0];
455 struct kvec *resv = &rqstp->rq_res.head[0];
456 struct svc_cred *cred = &rqstp->rq_cred;
457
458 cred->cr_group_info = NULL;
459 rqstp->rq_client = NULL;
460
461 if (argv->iov_len < 3*4)
462 return SVC_GARBAGE;
463
464 if (svc_getu32(argv) != 0) {
465 dprintk("svc: bad null cred\n");
466 *authp = rpc_autherr_badcred;
467 return SVC_DENIED;
468 }
Alexey Dobriyan76994312006-09-26 22:28:46 -0700469 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 dprintk("svc: bad null verf\n");
471 *authp = rpc_autherr_badverf;
472 return SVC_DENIED;
473 }
474
475 /* Signal that mapping to nobody uid/gid is required */
476 cred->cr_uid = (uid_t) -1;
477 cred->cr_gid = (gid_t) -1;
478 cred->cr_group_info = groups_alloc(0);
479 if (cred->cr_group_info == NULL)
480 return SVC_DROP; /* kmalloc failure - client must retry */
481
482 /* Put NULL verifier */
Alexey Dobriyan76994312006-09-26 22:28:46 -0700483 svc_putnl(resv, RPC_AUTH_NULL);
484 svc_putnl(resv, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 return SVC_OK;
487}
488
489static int
490svcauth_null_release(struct svc_rqst *rqstp)
491{
492 if (rqstp->rq_client)
493 auth_domain_put(rqstp->rq_client);
494 rqstp->rq_client = NULL;
495 if (rqstp->rq_cred.cr_group_info)
496 put_group_info(rqstp->rq_cred.cr_group_info);
497 rqstp->rq_cred.cr_group_info = NULL;
498
499 return 0; /* don't drop */
500}
501
502
503struct auth_ops svcauth_null = {
504 .name = "null",
505 .owner = THIS_MODULE,
506 .flavour = RPC_AUTH_NULL,
507 .accept = svcauth_null_accept,
508 .release = svcauth_null_release,
509 .set_client = svcauth_unix_set_client,
510};
511
512
513static int
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700514svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 struct kvec *argv = &rqstp->rq_arg.head[0];
517 struct kvec *resv = &rqstp->rq_res.head[0];
518 struct svc_cred *cred = &rqstp->rq_cred;
519 u32 slen, i;
520 int len = argv->iov_len;
521
522 cred->cr_group_info = NULL;
523 rqstp->rq_client = NULL;
524
525 if ((len -= 3*4) < 0)
526 return SVC_GARBAGE;
527
528 svc_getu32(argv); /* length */
529 svc_getu32(argv); /* time stamp */
Alexey Dobriyan76994312006-09-26 22:28:46 -0700530 slen = XDR_QUADLEN(svc_getnl(argv)); /* machname length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 if (slen > 64 || (len -= (slen + 3)*4) < 0)
532 goto badcred;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700533 argv->iov_base = (void*)((__be32*)argv->iov_base + slen); /* skip machname */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 argv->iov_len -= slen*4;
535
Alexey Dobriyan76994312006-09-26 22:28:46 -0700536 cred->cr_uid = svc_getnl(argv); /* uid */
537 cred->cr_gid = svc_getnl(argv); /* gid */
538 slen = svc_getnl(argv); /* gids length */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (slen > 16 || (len -= (slen + 2)*4) < 0)
540 goto badcred;
541 cred->cr_group_info = groups_alloc(slen);
542 if (cred->cr_group_info == NULL)
543 return SVC_DROP;
544 for (i = 0; i < slen; i++)
Alexey Dobriyan76994312006-09-26 22:28:46 -0700545 GROUP_AT(cred->cr_group_info, i) = svc_getnl(argv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Alexey Dobriyan76994312006-09-26 22:28:46 -0700547 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 *authp = rpc_autherr_badverf;
549 return SVC_DENIED;
550 }
551
552 /* Put NULL verifier */
Alexey Dobriyan76994312006-09-26 22:28:46 -0700553 svc_putnl(resv, RPC_AUTH_NULL);
554 svc_putnl(resv, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556 return SVC_OK;
557
558badcred:
559 *authp = rpc_autherr_badcred;
560 return SVC_DENIED;
561}
562
563static int
564svcauth_unix_release(struct svc_rqst *rqstp)
565{
566 /* Verifier (such as it is) is already in place.
567 */
568 if (rqstp->rq_client)
569 auth_domain_put(rqstp->rq_client);
570 rqstp->rq_client = NULL;
571 if (rqstp->rq_cred.cr_group_info)
572 put_group_info(rqstp->rq_cred.cr_group_info);
573 rqstp->rq_cred.cr_group_info = NULL;
574
575 return 0;
576}
577
578
579struct auth_ops svcauth_unix = {
580 .name = "unix",
581 .owner = THIS_MODULE,
582 .flavour = RPC_AUTH_UNIX,
583 .accept = svcauth_unix_accept,
584 .release = svcauth_unix_release,
585 .domain_release = svcauth_unix_domain_release,
586 .set_client = svcauth_unix_set_client,
587};
588