1 #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/sunrpc/gss_api.h>
10 #include <linux/seq_file.h>
11 #include <linux/hash.h>
12 #include <linux/string.h>
13 #include <linux/slab.h>
16 #include <linux/kernel.h>
17 #define RPCDBG_FACILITY RPCDBG_AUTH
19 #include <linux/sunrpc/clnt.h>
24 * AUTHUNIX and AUTHNULL credentials are both handled here.
25 * AUTHNULL is treated just like AUTHUNIX except that the uid/gid
26 * are always nobody (-2). i.e. we do the same IP address checks for
27 * AUTHNULL as for AUTHUNIX, and that is done here.
34 /* other stuff later */
37 extern struct auth_ops svcauth_unix
;
39 struct auth_domain
*unix_domain_find(char *name
)
41 struct auth_domain
*rv
;
42 struct unix_domain
*new = NULL
;
44 rv
= auth_domain_lookup(name
, NULL
);
47 if (new && rv
!= &new->h
)
48 auth_domain_put(&new->h
);
50 if (rv
->flavour
!= &svcauth_unix
) {
57 new = kmalloc(sizeof(*new), GFP_KERNEL
);
60 kref_init(&new->h
.ref
);
61 new->h
.name
= kstrdup(name
, GFP_KERNEL
);
62 if (new->h
.name
== NULL
) {
66 new->h
.flavour
= &svcauth_unix
;
67 new->addr_changes
= 0;
68 rv
= auth_domain_lookup(name
, &new->h
);
71 EXPORT_SYMBOL_GPL(unix_domain_find
);
73 static void svcauth_unix_domain_release(struct auth_domain
*dom
)
75 struct unix_domain
*ud
= container_of(dom
, struct unix_domain
, h
);
82 /**************************************************
83 * cache for IP address to unix_domain
84 * as needed by AUTH_UNIX
87 #define IP_HASHMAX (1<<IP_HASHBITS)
88 #define IP_HASHMASK (IP_HASHMAX-1)
92 char m_class
[8]; /* e.g. "nfsd" */
93 struct in6_addr m_addr
;
94 struct unix_domain
*m_client
;
98 static void ip_map_put(struct kref
*kref
)
100 struct cache_head
*item
= container_of(kref
, struct cache_head
, ref
);
101 struct ip_map
*im
= container_of(item
, struct ip_map
,h
);
103 if (test_bit(CACHE_VALID
, &item
->flags
) &&
104 !test_bit(CACHE_NEGATIVE
, &item
->flags
))
105 auth_domain_put(&im
->m_client
->h
);
110 /* hash_long on a 64 bit machine is currently REALLY BAD for
111 * IP addresses in reverse-endian (i.e. on a little-endian machine).
112 * So use a trivial but reliable hash instead
114 static inline int hash_ip(__be32 ip
)
116 int hash
= (__force u32
)ip
^ ((__force u32
)ip
>>16);
117 return (hash
^ (hash
>>8)) & 0xff;
120 static inline int hash_ip6(struct in6_addr ip
)
122 return (hash_ip(ip
.s6_addr32
[0]) ^
123 hash_ip(ip
.s6_addr32
[1]) ^
124 hash_ip(ip
.s6_addr32
[2]) ^
125 hash_ip(ip
.s6_addr32
[3]));
127 static int ip_map_match(struct cache_head
*corig
, struct cache_head
*cnew
)
129 struct ip_map
*orig
= container_of(corig
, struct ip_map
, h
);
130 struct ip_map
*new = container_of(cnew
, struct ip_map
, h
);
131 return strcmp(orig
->m_class
, new->m_class
) == 0 &&
132 ipv6_addr_equal(&orig
->m_addr
, &new->m_addr
);
134 static void ip_map_init(struct cache_head
*cnew
, struct cache_head
*citem
)
136 struct ip_map
*new = container_of(cnew
, struct ip_map
, h
);
137 struct ip_map
*item
= container_of(citem
, struct ip_map
, h
);
139 strcpy(new->m_class
, item
->m_class
);
140 ipv6_addr_copy(&new->m_addr
, &item
->m_addr
);
142 static void update(struct cache_head
*cnew
, struct cache_head
*citem
)
144 struct ip_map
*new = container_of(cnew
, struct ip_map
, h
);
145 struct ip_map
*item
= container_of(citem
, struct ip_map
, h
);
147 kref_get(&item
->m_client
->h
.ref
);
148 new->m_client
= item
->m_client
;
149 new->m_add_change
= item
->m_add_change
;
151 static struct cache_head
*ip_map_alloc(void)
153 struct ip_map
*i
= kmalloc(sizeof(*i
), GFP_KERNEL
);
160 static void ip_map_request(struct cache_detail
*cd
,
161 struct cache_head
*h
,
162 char **bpp
, int *blen
)
165 struct ip_map
*im
= container_of(h
, struct ip_map
, h
);
167 if (ipv6_addr_v4mapped(&(im
->m_addr
))) {
168 snprintf(text_addr
, 20, "%pI4", &im
->m_addr
.s6_addr32
[3]);
170 snprintf(text_addr
, 40, "%pI6", &im
->m_addr
);
172 qword_add(bpp
, blen
, im
->m_class
);
173 qword_add(bpp
, blen
, text_addr
);
177 static int ip_map_upcall(struct cache_detail
*cd
, struct cache_head
*h
)
179 return sunrpc_cache_pipe_upcall(cd
, h
, ip_map_request
);
182 static struct ip_map
*__ip_map_lookup(struct cache_detail
*cd
, char *class, struct in6_addr
*addr
);
183 static int __ip_map_update(struct cache_detail
*cd
, struct ip_map
*ipm
, struct unix_domain
*udom
, time_t expiry
);
185 static int ip_map_parse(struct cache_detail
*cd
,
186 char *mesg
, int mlen
)
188 /* class ipaddress [domainname] */
189 /* should be safe just to use the start of the input buffer
196 struct sockaddr_in s4
;
197 struct sockaddr_in6 s6
;
199 struct sockaddr_in6 sin6
;
203 struct auth_domain
*dom
;
206 if (mesg
[mlen
-1] != '\n')
211 len
= qword_get(&mesg
, class, sizeof(class));
212 if (len
<= 0) return -EINVAL
;
215 len
= qword_get(&mesg
, buf
, mlen
);
216 if (len
<= 0) return -EINVAL
;
218 if (rpc_pton(buf
, len
, &address
.sa
, sizeof(address
)) == 0)
220 switch (address
.sa
.sa_family
) {
222 /* Form a mapped IPv4 address in sin6 */
223 memset(&sin6
, 0, sizeof(sin6
));
224 sin6
.sin6_family
= AF_INET6
;
225 sin6
.sin6_addr
.s6_addr32
[2] = htonl(0xffff);
226 sin6
.sin6_addr
.s6_addr32
[3] = address
.s4
.sin_addr
.s_addr
;
228 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
230 memcpy(&sin6
, &address
.s6
, sizeof(sin6
));
237 expiry
= get_expiry(&mesg
);
241 /* domainname, or empty for NEGATIVE */
242 len
= qword_get(&mesg
, buf
, mlen
);
243 if (len
< 0) return -EINVAL
;
246 dom
= unix_domain_find(buf
);
252 /* IPv6 scope IDs are ignored for now */
253 ipmp
= __ip_map_lookup(cd
, class, &sin6
.sin6_addr
);
255 err
= __ip_map_update(cd
, ipmp
,
256 container_of(dom
, struct unix_domain
, h
),
262 auth_domain_put(dom
);
268 static int ip_map_show(struct seq_file
*m
,
269 struct cache_detail
*cd
,
270 struct cache_head
*h
)
273 struct in6_addr addr
;
274 char *dom
= "-no-domain-";
277 seq_puts(m
, "#class IP domain\n");
280 im
= container_of(h
, struct ip_map
, h
);
281 /* class addr domain */
282 ipv6_addr_copy(&addr
, &im
->m_addr
);
284 if (test_bit(CACHE_VALID
, &h
->flags
) &&
285 !test_bit(CACHE_NEGATIVE
, &h
->flags
))
286 dom
= im
->m_client
->h
.name
;
288 if (ipv6_addr_v4mapped(&addr
)) {
289 seq_printf(m
, "%s %pI4 %s\n",
290 im
->m_class
, &addr
.s6_addr32
[3], dom
);
292 seq_printf(m
, "%s %pI6 %s\n", im
->m_class
, &addr
, dom
);
298 static struct ip_map
*__ip_map_lookup(struct cache_detail
*cd
, char *class,
299 struct in6_addr
*addr
)
302 struct cache_head
*ch
;
304 strcpy(ip
.m_class
, class);
305 ipv6_addr_copy(&ip
.m_addr
, addr
);
306 ch
= sunrpc_cache_lookup(cd
, &ip
.h
,
307 hash_str(class, IP_HASHBITS
) ^
311 return container_of(ch
, struct ip_map
, h
);
316 static inline struct ip_map
*ip_map_lookup(struct net
*net
, char *class,
317 struct in6_addr
*addr
)
319 struct sunrpc_net
*sn
;
321 sn
= net_generic(net
, sunrpc_net_id
);
322 return __ip_map_lookup(sn
->ip_map_cache
, class, addr
);
325 static int __ip_map_update(struct cache_detail
*cd
, struct ip_map
*ipm
,
326 struct unix_domain
*udom
, time_t expiry
)
329 struct cache_head
*ch
;
334 set_bit(CACHE_NEGATIVE
, &ip
.h
.flags
);
336 ip
.m_add_change
= udom
->addr_changes
;
337 /* if this is from the legacy set_client system call,
338 * we need m_add_change to be one higher
343 ip
.h
.expiry_time
= expiry
;
344 ch
= sunrpc_cache_update(cd
, &ip
.h
, &ipm
->h
,
345 hash_str(ipm
->m_class
, IP_HASHBITS
) ^
346 hash_ip6(ipm
->m_addr
));
353 static inline int ip_map_update(struct net
*net
, struct ip_map
*ipm
,
354 struct unix_domain
*udom
, time_t expiry
)
356 struct sunrpc_net
*sn
;
358 sn
= net_generic(net
, sunrpc_net_id
);
359 return __ip_map_update(sn
->ip_map_cache
, ipm
, udom
, expiry
);
362 int auth_unix_add_addr(struct net
*net
, struct in6_addr
*addr
, struct auth_domain
*dom
)
364 struct unix_domain
*udom
;
367 if (dom
->flavour
!= &svcauth_unix
)
369 udom
= container_of(dom
, struct unix_domain
, h
);
370 ipmp
= ip_map_lookup(net
, "nfsd", addr
);
373 return ip_map_update(net
, ipmp
, udom
, NEVER
);
377 EXPORT_SYMBOL_GPL(auth_unix_add_addr
);
379 int auth_unix_forget_old(struct auth_domain
*dom
)
381 struct unix_domain
*udom
;
383 if (dom
->flavour
!= &svcauth_unix
)
385 udom
= container_of(dom
, struct unix_domain
, h
);
386 udom
->addr_changes
++;
389 EXPORT_SYMBOL_GPL(auth_unix_forget_old
);
391 struct auth_domain
*auth_unix_lookup(struct net
*net
, struct in6_addr
*addr
)
394 struct auth_domain
*rv
;
395 struct sunrpc_net
*sn
;
397 sn
= net_generic(net
, sunrpc_net_id
);
398 ipm
= ip_map_lookup(net
, "nfsd", addr
);
402 if (cache_check(sn
->ip_map_cache
, &ipm
->h
, NULL
))
405 if ((ipm
->m_client
->addr_changes
- ipm
->m_add_change
) >0) {
406 if (test_and_set_bit(CACHE_NEGATIVE
, &ipm
->h
.flags
) == 0)
407 auth_domain_put(&ipm
->m_client
->h
);
410 rv
= &ipm
->m_client
->h
;
413 cache_put(&ipm
->h
, sn
->ip_map_cache
);
416 EXPORT_SYMBOL_GPL(auth_unix_lookup
);
418 void svcauth_unix_purge(void)
423 struct sunrpc_net
*sn
;
425 sn
= net_generic(net
, sunrpc_net_id
);
426 cache_purge(sn
->ip_map_cache
);
429 EXPORT_SYMBOL_GPL(svcauth_unix_purge
);
431 static inline struct ip_map
*
432 ip_map_cached_get(struct svc_xprt
*xprt
)
434 struct ip_map
*ipm
= NULL
;
435 struct sunrpc_net
*sn
;
437 if (test_bit(XPT_CACHE_AUTH
, &xprt
->xpt_flags
)) {
438 spin_lock(&xprt
->xpt_lock
);
439 ipm
= xprt
->xpt_auth_cache
;
441 if (!cache_valid(&ipm
->h
)) {
443 * The entry has been invalidated since it was
444 * remembered, e.g. by a second mount from the
447 sn
= net_generic(xprt
->xpt_net
, sunrpc_net_id
);
448 xprt
->xpt_auth_cache
= NULL
;
449 spin_unlock(&xprt
->xpt_lock
);
450 cache_put(&ipm
->h
, sn
->ip_map_cache
);
455 spin_unlock(&xprt
->xpt_lock
);
461 ip_map_cached_put(struct svc_xprt
*xprt
, struct ip_map
*ipm
)
463 if (test_bit(XPT_CACHE_AUTH
, &xprt
->xpt_flags
)) {
464 spin_lock(&xprt
->xpt_lock
);
465 if (xprt
->xpt_auth_cache
== NULL
) {
466 /* newly cached, keep the reference */
467 xprt
->xpt_auth_cache
= ipm
;
470 spin_unlock(&xprt
->xpt_lock
);
473 struct sunrpc_net
*sn
;
475 sn
= net_generic(xprt
->xpt_net
, sunrpc_net_id
);
476 cache_put(&ipm
->h
, sn
->ip_map_cache
);
481 svcauth_unix_info_release(struct svc_xprt
*xpt
)
485 ipm
= xpt
->xpt_auth_cache
;
487 struct sunrpc_net
*sn
;
489 sn
= net_generic(xpt
->xpt_net
, sunrpc_net_id
);
490 cache_put(&ipm
->h
, sn
->ip_map_cache
);
494 /****************************************************************************
495 * auth.unix.gid cache
496 * simple cache to map a UID to a list of GIDs
497 * because AUTH_UNIX aka AUTH_SYS has a max of 16
499 #define GID_HASHBITS 8
500 #define GID_HASHMAX (1<<GID_HASHBITS)
501 #define GID_HASHMASK (GID_HASHMAX - 1)
506 struct group_info
*gi
;
508 static struct cache_head
*gid_table
[GID_HASHMAX
];
510 static void unix_gid_put(struct kref
*kref
)
512 struct cache_head
*item
= container_of(kref
, struct cache_head
, ref
);
513 struct unix_gid
*ug
= container_of(item
, struct unix_gid
, h
);
514 if (test_bit(CACHE_VALID
, &item
->flags
) &&
515 !test_bit(CACHE_NEGATIVE
, &item
->flags
))
516 put_group_info(ug
->gi
);
520 static int unix_gid_match(struct cache_head
*corig
, struct cache_head
*cnew
)
522 struct unix_gid
*orig
= container_of(corig
, struct unix_gid
, h
);
523 struct unix_gid
*new = container_of(cnew
, struct unix_gid
, h
);
524 return orig
->uid
== new->uid
;
526 static void unix_gid_init(struct cache_head
*cnew
, struct cache_head
*citem
)
528 struct unix_gid
*new = container_of(cnew
, struct unix_gid
, h
);
529 struct unix_gid
*item
= container_of(citem
, struct unix_gid
, h
);
530 new->uid
= item
->uid
;
532 static void unix_gid_update(struct cache_head
*cnew
, struct cache_head
*citem
)
534 struct unix_gid
*new = container_of(cnew
, struct unix_gid
, h
);
535 struct unix_gid
*item
= container_of(citem
, struct unix_gid
, h
);
537 get_group_info(item
->gi
);
540 static struct cache_head
*unix_gid_alloc(void)
542 struct unix_gid
*g
= kmalloc(sizeof(*g
), GFP_KERNEL
);
549 static void unix_gid_request(struct cache_detail
*cd
,
550 struct cache_head
*h
,
551 char **bpp
, int *blen
)
554 struct unix_gid
*ug
= container_of(h
, struct unix_gid
, h
);
556 snprintf(tuid
, 20, "%u", ug
->uid
);
557 qword_add(bpp
, blen
, tuid
);
561 static int unix_gid_upcall(struct cache_detail
*cd
, struct cache_head
*h
)
563 return sunrpc_cache_pipe_upcall(cd
, h
, unix_gid_request
);
566 static struct unix_gid
*unix_gid_lookup(uid_t uid
);
567 extern struct cache_detail unix_gid_cache
;
569 static int unix_gid_parse(struct cache_detail
*cd
,
570 char *mesg
, int mlen
)
572 /* uid expiry Ngid gid0 gid1 ... gidN-1 */
579 struct unix_gid ug
, *ugp
;
581 if (mlen
<= 0 || mesg
[mlen
-1] != '\n')
585 rv
= get_int(&mesg
, &uid
);
590 expiry
= get_expiry(&mesg
);
594 rv
= get_int(&mesg
, &gids
);
595 if (rv
|| gids
< 0 || gids
> 8192)
598 ug
.gi
= groups_alloc(gids
);
602 for (i
= 0 ; i
< gids
; i
++) {
604 rv
= get_int(&mesg
, &gid
);
608 GROUP_AT(ug
.gi
, i
) = gid
;
611 ugp
= unix_gid_lookup(uid
);
613 struct cache_head
*ch
;
615 ug
.h
.expiry_time
= expiry
;
616 ch
= sunrpc_cache_update(&unix_gid_cache
,
618 hash_long(uid
, GID_HASHBITS
));
623 cache_put(ch
, &unix_gid_cache
);
629 put_group_info(ug
.gi
);
633 static int unix_gid_show(struct seq_file
*m
,
634 struct cache_detail
*cd
,
635 struct cache_head
*h
)
642 seq_puts(m
, "#uid cnt: gids...\n");
645 ug
= container_of(h
, struct unix_gid
, h
);
646 if (test_bit(CACHE_VALID
, &h
->flags
) &&
647 !test_bit(CACHE_NEGATIVE
, &h
->flags
))
648 glen
= ug
->gi
->ngroups
;
652 seq_printf(m
, "%u %d:", ug
->uid
, glen
);
653 for (i
= 0; i
< glen
; i
++)
654 seq_printf(m
, " %d", GROUP_AT(ug
->gi
, i
));
659 struct cache_detail unix_gid_cache
= {
660 .owner
= THIS_MODULE
,
661 .hash_size
= GID_HASHMAX
,
662 .hash_table
= gid_table
,
663 .name
= "auth.unix.gid",
664 .cache_put
= unix_gid_put
,
665 .cache_upcall
= unix_gid_upcall
,
666 .cache_parse
= unix_gid_parse
,
667 .cache_show
= unix_gid_show
,
668 .match
= unix_gid_match
,
669 .init
= unix_gid_init
,
670 .update
= unix_gid_update
,
671 .alloc
= unix_gid_alloc
,
674 static struct unix_gid
*unix_gid_lookup(uid_t uid
)
677 struct cache_head
*ch
;
680 ch
= sunrpc_cache_lookup(&unix_gid_cache
, &ug
.h
,
681 hash_long(uid
, GID_HASHBITS
));
683 return container_of(ch
, struct unix_gid
, h
);
688 static struct group_info
*unix_gid_find(uid_t uid
, struct svc_rqst
*rqstp
)
691 struct group_info
*gi
;
694 ug
= unix_gid_lookup(uid
);
696 return ERR_PTR(-EAGAIN
);
697 ret
= cache_check(&unix_gid_cache
, &ug
->h
, &rqstp
->rq_chandle
);
700 return ERR_PTR(-ENOENT
);
702 return ERR_PTR(-ESHUTDOWN
);
704 gi
= get_group_info(ug
->gi
);
705 cache_put(&ug
->h
, &unix_gid_cache
);
708 return ERR_PTR(-EAGAIN
);
713 svcauth_unix_set_client(struct svc_rqst
*rqstp
)
715 struct sockaddr_in
*sin
;
716 struct sockaddr_in6
*sin6
, sin6_storage
;
718 struct group_info
*gi
;
719 struct svc_cred
*cred
= &rqstp
->rq_cred
;
720 struct svc_xprt
*xprt
= rqstp
->rq_xprt
;
721 struct net
*net
= xprt
->xpt_net
;
722 struct sunrpc_net
*sn
= net_generic(net
, sunrpc_net_id
);
724 switch (rqstp
->rq_addr
.ss_family
) {
726 sin
= svc_addr_in(rqstp
);
727 sin6
= &sin6_storage
;
728 ipv6_addr_set_v4mapped(sin
->sin_addr
.s_addr
, &sin6
->sin6_addr
);
731 sin6
= svc_addr_in6(rqstp
);
737 rqstp
->rq_client
= NULL
;
738 if (rqstp
->rq_proc
== 0)
741 ipm
= ip_map_cached_get(xprt
);
743 ipm
= __ip_map_lookup(sn
->ip_map_cache
, rqstp
->rq_server
->sv_program
->pg_class
,
749 switch (cache_check(sn
->ip_map_cache
, &ipm
->h
, &rqstp
->rq_chandle
)) {
759 rqstp
->rq_client
= &ipm
->m_client
->h
;
760 kref_get(&rqstp
->rq_client
->ref
);
761 ip_map_cached_put(xprt
, ipm
);
765 gi
= unix_gid_find(cred
->cr_uid
, rqstp
);
766 switch (PTR_ERR(gi
)) {
774 put_group_info(cred
->cr_group_info
);
775 cred
->cr_group_info
= gi
;
780 EXPORT_SYMBOL_GPL(svcauth_unix_set_client
);
783 svcauth_null_accept(struct svc_rqst
*rqstp
, __be32
*authp
)
785 struct kvec
*argv
= &rqstp
->rq_arg
.head
[0];
786 struct kvec
*resv
= &rqstp
->rq_res
.head
[0];
787 struct svc_cred
*cred
= &rqstp
->rq_cred
;
789 cred
->cr_group_info
= NULL
;
790 rqstp
->rq_client
= NULL
;
792 if (argv
->iov_len
< 3*4)
795 if (svc_getu32(argv
) != 0) {
796 dprintk("svc: bad null cred\n");
797 *authp
= rpc_autherr_badcred
;
800 if (svc_getu32(argv
) != htonl(RPC_AUTH_NULL
) || svc_getu32(argv
) != 0) {
801 dprintk("svc: bad null verf\n");
802 *authp
= rpc_autherr_badverf
;
806 /* Signal that mapping to nobody uid/gid is required */
807 cred
->cr_uid
= (uid_t
) -1;
808 cred
->cr_gid
= (gid_t
) -1;
809 cred
->cr_group_info
= groups_alloc(0);
810 if (cred
->cr_group_info
== NULL
)
811 return SVC_CLOSE
; /* kmalloc failure - client must retry */
813 /* Put NULL verifier */
814 svc_putnl(resv
, RPC_AUTH_NULL
);
817 rqstp
->rq_flavor
= RPC_AUTH_NULL
;
822 svcauth_null_release(struct svc_rqst
*rqstp
)
824 if (rqstp
->rq_client
)
825 auth_domain_put(rqstp
->rq_client
);
826 rqstp
->rq_client
= NULL
;
827 if (rqstp
->rq_cred
.cr_group_info
)
828 put_group_info(rqstp
->rq_cred
.cr_group_info
);
829 rqstp
->rq_cred
.cr_group_info
= NULL
;
831 return 0; /* don't drop */
835 struct auth_ops svcauth_null
= {
837 .owner
= THIS_MODULE
,
838 .flavour
= RPC_AUTH_NULL
,
839 .accept
= svcauth_null_accept
,
840 .release
= svcauth_null_release
,
841 .set_client
= svcauth_unix_set_client
,
846 svcauth_unix_accept(struct svc_rqst
*rqstp
, __be32
*authp
)
848 struct kvec
*argv
= &rqstp
->rq_arg
.head
[0];
849 struct kvec
*resv
= &rqstp
->rq_res
.head
[0];
850 struct svc_cred
*cred
= &rqstp
->rq_cred
;
852 int len
= argv
->iov_len
;
854 cred
->cr_group_info
= NULL
;
855 rqstp
->rq_client
= NULL
;
857 if ((len
-= 3*4) < 0)
860 svc_getu32(argv
); /* length */
861 svc_getu32(argv
); /* time stamp */
862 slen
= XDR_QUADLEN(svc_getnl(argv
)); /* machname length */
863 if (slen
> 64 || (len
-= (slen
+ 3)*4) < 0)
865 argv
->iov_base
= (void*)((__be32
*)argv
->iov_base
+ slen
); /* skip machname */
866 argv
->iov_len
-= slen
*4;
868 cred
->cr_uid
= svc_getnl(argv
); /* uid */
869 cred
->cr_gid
= svc_getnl(argv
); /* gid */
870 slen
= svc_getnl(argv
); /* gids length */
871 if (slen
> 16 || (len
-= (slen
+ 2)*4) < 0)
873 cred
->cr_group_info
= groups_alloc(slen
);
874 if (cred
->cr_group_info
== NULL
)
876 for (i
= 0; i
< slen
; i
++)
877 GROUP_AT(cred
->cr_group_info
, i
) = svc_getnl(argv
);
878 if (svc_getu32(argv
) != htonl(RPC_AUTH_NULL
) || svc_getu32(argv
) != 0) {
879 *authp
= rpc_autherr_badverf
;
883 /* Put NULL verifier */
884 svc_putnl(resv
, RPC_AUTH_NULL
);
887 rqstp
->rq_flavor
= RPC_AUTH_UNIX
;
891 *authp
= rpc_autherr_badcred
;
896 svcauth_unix_release(struct svc_rqst
*rqstp
)
898 /* Verifier (such as it is) is already in place.
900 if (rqstp
->rq_client
)
901 auth_domain_put(rqstp
->rq_client
);
902 rqstp
->rq_client
= NULL
;
903 if (rqstp
->rq_cred
.cr_group_info
)
904 put_group_info(rqstp
->rq_cred
.cr_group_info
);
905 rqstp
->rq_cred
.cr_group_info
= NULL
;
911 struct auth_ops svcauth_unix
= {
913 .owner
= THIS_MODULE
,
914 .flavour
= RPC_AUTH_UNIX
,
915 .accept
= svcauth_unix_accept
,
916 .release
= svcauth_unix_release
,
917 .domain_release
= svcauth_unix_domain_release
,
918 .set_client
= svcauth_unix_set_client
,
921 int ip_map_cache_create(struct net
*net
)
924 struct cache_detail
*cd
;
925 struct cache_head
**tbl
;
926 struct sunrpc_net
*sn
= net_generic(net
, sunrpc_net_id
);
928 cd
= kzalloc(sizeof(struct cache_detail
), GFP_KERNEL
);
932 tbl
= kzalloc(IP_HASHMAX
* sizeof(struct cache_head
*), GFP_KERNEL
);
936 cd
->owner
= THIS_MODULE
,
937 cd
->hash_size
= IP_HASHMAX
,
938 cd
->hash_table
= tbl
,
939 cd
->name
= "auth.unix.ip",
940 cd
->cache_put
= ip_map_put
,
941 cd
->cache_upcall
= ip_map_upcall
,
942 cd
->cache_parse
= ip_map_parse
,
943 cd
->cache_show
= ip_map_show
,
944 cd
->match
= ip_map_match
,
945 cd
->init
= ip_map_init
,
947 cd
->alloc
= ip_map_alloc
,
949 err
= cache_register_net(cd
, net
);
953 sn
->ip_map_cache
= cd
;
964 void ip_map_cache_destroy(struct net
*net
)
966 struct sunrpc_net
*sn
;
968 sn
= net_generic(net
, sunrpc_net_id
);
969 cache_purge(sn
->ip_map_cache
);
970 cache_unregister_net(sn
->ip_map_cache
, net
);
971 kfree(sn
->ip_map_cache
->hash_table
);
972 kfree(sn
->ip_map_cache
);