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 sin6
.sin6_family
= AF_INET6
;
224 ipv6_addr_set_v4mapped(address
.s4
.sin_addr
.s_addr
,
227 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
229 memcpy(&sin6
, &address
.s6
, sizeof(sin6
));
236 expiry
= get_expiry(&mesg
);
240 /* domainname, or empty for NEGATIVE */
241 len
= qword_get(&mesg
, buf
, mlen
);
242 if (len
< 0) return -EINVAL
;
245 dom
= unix_domain_find(buf
);
251 /* IPv6 scope IDs are ignored for now */
252 ipmp
= __ip_map_lookup(cd
, class, &sin6
.sin6_addr
);
254 err
= __ip_map_update(cd
, ipmp
,
255 container_of(dom
, struct unix_domain
, h
),
261 auth_domain_put(dom
);
267 static int ip_map_show(struct seq_file
*m
,
268 struct cache_detail
*cd
,
269 struct cache_head
*h
)
272 struct in6_addr addr
;
273 char *dom
= "-no-domain-";
276 seq_puts(m
, "#class IP domain\n");
279 im
= container_of(h
, struct ip_map
, h
);
280 /* class addr domain */
281 ipv6_addr_copy(&addr
, &im
->m_addr
);
283 if (test_bit(CACHE_VALID
, &h
->flags
) &&
284 !test_bit(CACHE_NEGATIVE
, &h
->flags
))
285 dom
= im
->m_client
->h
.name
;
287 if (ipv6_addr_v4mapped(&addr
)) {
288 seq_printf(m
, "%s %pI4 %s\n",
289 im
->m_class
, &addr
.s6_addr32
[3], dom
);
291 seq_printf(m
, "%s %pI6 %s\n", im
->m_class
, &addr
, dom
);
297 static struct ip_map
*__ip_map_lookup(struct cache_detail
*cd
, char *class,
298 struct in6_addr
*addr
)
301 struct cache_head
*ch
;
303 strcpy(ip
.m_class
, class);
304 ipv6_addr_copy(&ip
.m_addr
, addr
);
305 ch
= sunrpc_cache_lookup(cd
, &ip
.h
,
306 hash_str(class, IP_HASHBITS
) ^
310 return container_of(ch
, struct ip_map
, h
);
315 static inline struct ip_map
*ip_map_lookup(struct net
*net
, char *class,
316 struct in6_addr
*addr
)
318 struct sunrpc_net
*sn
;
320 sn
= net_generic(net
, sunrpc_net_id
);
321 return __ip_map_lookup(sn
->ip_map_cache
, class, addr
);
324 static int __ip_map_update(struct cache_detail
*cd
, struct ip_map
*ipm
,
325 struct unix_domain
*udom
, time_t expiry
)
328 struct cache_head
*ch
;
333 set_bit(CACHE_NEGATIVE
, &ip
.h
.flags
);
335 ip
.m_add_change
= udom
->addr_changes
;
336 /* if this is from the legacy set_client system call,
337 * we need m_add_change to be one higher
342 ip
.h
.expiry_time
= expiry
;
343 ch
= sunrpc_cache_update(cd
, &ip
.h
, &ipm
->h
,
344 hash_str(ipm
->m_class
, IP_HASHBITS
) ^
345 hash_ip6(ipm
->m_addr
));
352 static inline int ip_map_update(struct net
*net
, struct ip_map
*ipm
,
353 struct unix_domain
*udom
, time_t expiry
)
355 struct sunrpc_net
*sn
;
357 sn
= net_generic(net
, sunrpc_net_id
);
358 return __ip_map_update(sn
->ip_map_cache
, ipm
, udom
, expiry
);
361 int auth_unix_add_addr(struct net
*net
, struct in6_addr
*addr
, struct auth_domain
*dom
)
363 struct unix_domain
*udom
;
366 if (dom
->flavour
!= &svcauth_unix
)
368 udom
= container_of(dom
, struct unix_domain
, h
);
369 ipmp
= ip_map_lookup(net
, "nfsd", addr
);
372 return ip_map_update(net
, ipmp
, udom
, NEVER
);
376 EXPORT_SYMBOL_GPL(auth_unix_add_addr
);
378 int auth_unix_forget_old(struct auth_domain
*dom
)
380 struct unix_domain
*udom
;
382 if (dom
->flavour
!= &svcauth_unix
)
384 udom
= container_of(dom
, struct unix_domain
, h
);
385 udom
->addr_changes
++;
388 EXPORT_SYMBOL_GPL(auth_unix_forget_old
);
390 struct auth_domain
*auth_unix_lookup(struct net
*net
, struct in6_addr
*addr
)
393 struct auth_domain
*rv
;
394 struct sunrpc_net
*sn
;
396 sn
= net_generic(net
, sunrpc_net_id
);
397 ipm
= ip_map_lookup(net
, "nfsd", addr
);
401 if (cache_check(sn
->ip_map_cache
, &ipm
->h
, NULL
))
404 if ((ipm
->m_client
->addr_changes
- ipm
->m_add_change
) >0) {
405 if (test_and_set_bit(CACHE_NEGATIVE
, &ipm
->h
.flags
) == 0)
406 auth_domain_put(&ipm
->m_client
->h
);
409 rv
= &ipm
->m_client
->h
;
412 cache_put(&ipm
->h
, sn
->ip_map_cache
);
415 EXPORT_SYMBOL_GPL(auth_unix_lookup
);
417 void svcauth_unix_purge(void)
422 struct sunrpc_net
*sn
;
424 sn
= net_generic(net
, sunrpc_net_id
);
425 cache_purge(sn
->ip_map_cache
);
428 EXPORT_SYMBOL_GPL(svcauth_unix_purge
);
430 static inline struct ip_map
*
431 ip_map_cached_get(struct svc_xprt
*xprt
)
433 struct ip_map
*ipm
= NULL
;
434 struct sunrpc_net
*sn
;
436 if (test_bit(XPT_CACHE_AUTH
, &xprt
->xpt_flags
)) {
437 spin_lock(&xprt
->xpt_lock
);
438 ipm
= xprt
->xpt_auth_cache
;
440 if (!cache_valid(&ipm
->h
)) {
442 * The entry has been invalidated since it was
443 * remembered, e.g. by a second mount from the
446 sn
= net_generic(xprt
->xpt_net
, sunrpc_net_id
);
447 xprt
->xpt_auth_cache
= NULL
;
448 spin_unlock(&xprt
->xpt_lock
);
449 cache_put(&ipm
->h
, sn
->ip_map_cache
);
454 spin_unlock(&xprt
->xpt_lock
);
460 ip_map_cached_put(struct svc_xprt
*xprt
, struct ip_map
*ipm
)
462 if (test_bit(XPT_CACHE_AUTH
, &xprt
->xpt_flags
)) {
463 spin_lock(&xprt
->xpt_lock
);
464 if (xprt
->xpt_auth_cache
== NULL
) {
465 /* newly cached, keep the reference */
466 xprt
->xpt_auth_cache
= ipm
;
469 spin_unlock(&xprt
->xpt_lock
);
472 struct sunrpc_net
*sn
;
474 sn
= net_generic(xprt
->xpt_net
, sunrpc_net_id
);
475 cache_put(&ipm
->h
, sn
->ip_map_cache
);
480 svcauth_unix_info_release(struct svc_xprt
*xpt
)
484 ipm
= xpt
->xpt_auth_cache
;
486 struct sunrpc_net
*sn
;
488 sn
= net_generic(xpt
->xpt_net
, sunrpc_net_id
);
489 cache_put(&ipm
->h
, sn
->ip_map_cache
);
493 /****************************************************************************
494 * auth.unix.gid cache
495 * simple cache to map a UID to a list of GIDs
496 * because AUTH_UNIX aka AUTH_SYS has a max of 16
498 #define GID_HASHBITS 8
499 #define GID_HASHMAX (1<<GID_HASHBITS)
500 #define GID_HASHMASK (GID_HASHMAX - 1)
505 struct group_info
*gi
;
507 static struct cache_head
*gid_table
[GID_HASHMAX
];
509 static void unix_gid_put(struct kref
*kref
)
511 struct cache_head
*item
= container_of(kref
, struct cache_head
, ref
);
512 struct unix_gid
*ug
= container_of(item
, struct unix_gid
, h
);
513 if (test_bit(CACHE_VALID
, &item
->flags
) &&
514 !test_bit(CACHE_NEGATIVE
, &item
->flags
))
515 put_group_info(ug
->gi
);
519 static int unix_gid_match(struct cache_head
*corig
, struct cache_head
*cnew
)
521 struct unix_gid
*orig
= container_of(corig
, struct unix_gid
, h
);
522 struct unix_gid
*new = container_of(cnew
, struct unix_gid
, h
);
523 return orig
->uid
== new->uid
;
525 static void unix_gid_init(struct cache_head
*cnew
, struct cache_head
*citem
)
527 struct unix_gid
*new = container_of(cnew
, struct unix_gid
, h
);
528 struct unix_gid
*item
= container_of(citem
, struct unix_gid
, h
);
529 new->uid
= item
->uid
;
531 static void unix_gid_update(struct cache_head
*cnew
, struct cache_head
*citem
)
533 struct unix_gid
*new = container_of(cnew
, struct unix_gid
, h
);
534 struct unix_gid
*item
= container_of(citem
, struct unix_gid
, h
);
536 get_group_info(item
->gi
);
539 static struct cache_head
*unix_gid_alloc(void)
541 struct unix_gid
*g
= kmalloc(sizeof(*g
), GFP_KERNEL
);
548 static void unix_gid_request(struct cache_detail
*cd
,
549 struct cache_head
*h
,
550 char **bpp
, int *blen
)
553 struct unix_gid
*ug
= container_of(h
, struct unix_gid
, h
);
555 snprintf(tuid
, 20, "%u", ug
->uid
);
556 qword_add(bpp
, blen
, tuid
);
560 static int unix_gid_upcall(struct cache_detail
*cd
, struct cache_head
*h
)
562 return sunrpc_cache_pipe_upcall(cd
, h
, unix_gid_request
);
565 static struct unix_gid
*unix_gid_lookup(uid_t uid
);
566 extern struct cache_detail unix_gid_cache
;
568 static int unix_gid_parse(struct cache_detail
*cd
,
569 char *mesg
, int mlen
)
571 /* uid expiry Ngid gid0 gid1 ... gidN-1 */
578 struct unix_gid ug
, *ugp
;
580 if (mlen
<= 0 || mesg
[mlen
-1] != '\n')
584 rv
= get_int(&mesg
, &uid
);
589 expiry
= get_expiry(&mesg
);
593 rv
= get_int(&mesg
, &gids
);
594 if (rv
|| gids
< 0 || gids
> 8192)
597 ug
.gi
= groups_alloc(gids
);
601 for (i
= 0 ; i
< gids
; i
++) {
603 rv
= get_int(&mesg
, &gid
);
607 GROUP_AT(ug
.gi
, i
) = gid
;
610 ugp
= unix_gid_lookup(uid
);
612 struct cache_head
*ch
;
614 ug
.h
.expiry_time
= expiry
;
615 ch
= sunrpc_cache_update(&unix_gid_cache
,
617 hash_long(uid
, GID_HASHBITS
));
622 cache_put(ch
, &unix_gid_cache
);
628 put_group_info(ug
.gi
);
632 static int unix_gid_show(struct seq_file
*m
,
633 struct cache_detail
*cd
,
634 struct cache_head
*h
)
641 seq_puts(m
, "#uid cnt: gids...\n");
644 ug
= container_of(h
, struct unix_gid
, h
);
645 if (test_bit(CACHE_VALID
, &h
->flags
) &&
646 !test_bit(CACHE_NEGATIVE
, &h
->flags
))
647 glen
= ug
->gi
->ngroups
;
651 seq_printf(m
, "%u %d:", ug
->uid
, glen
);
652 for (i
= 0; i
< glen
; i
++)
653 seq_printf(m
, " %d", GROUP_AT(ug
->gi
, i
));
658 struct cache_detail unix_gid_cache
= {
659 .owner
= THIS_MODULE
,
660 .hash_size
= GID_HASHMAX
,
661 .hash_table
= gid_table
,
662 .name
= "auth.unix.gid",
663 .cache_put
= unix_gid_put
,
664 .cache_upcall
= unix_gid_upcall
,
665 .cache_parse
= unix_gid_parse
,
666 .cache_show
= unix_gid_show
,
667 .match
= unix_gid_match
,
668 .init
= unix_gid_init
,
669 .update
= unix_gid_update
,
670 .alloc
= unix_gid_alloc
,
673 static struct unix_gid
*unix_gid_lookup(uid_t uid
)
676 struct cache_head
*ch
;
679 ch
= sunrpc_cache_lookup(&unix_gid_cache
, &ug
.h
,
680 hash_long(uid
, GID_HASHBITS
));
682 return container_of(ch
, struct unix_gid
, h
);
687 static struct group_info
*unix_gid_find(uid_t uid
, struct svc_rqst
*rqstp
)
690 struct group_info
*gi
;
693 ug
= unix_gid_lookup(uid
);
695 return ERR_PTR(-EAGAIN
);
696 ret
= cache_check(&unix_gid_cache
, &ug
->h
, &rqstp
->rq_chandle
);
699 return ERR_PTR(-ENOENT
);
701 return ERR_PTR(-ESHUTDOWN
);
703 gi
= get_group_info(ug
->gi
);
704 cache_put(&ug
->h
, &unix_gid_cache
);
707 return ERR_PTR(-EAGAIN
);
712 svcauth_unix_set_client(struct svc_rqst
*rqstp
)
714 struct sockaddr_in
*sin
;
715 struct sockaddr_in6
*sin6
, sin6_storage
;
717 struct group_info
*gi
;
718 struct svc_cred
*cred
= &rqstp
->rq_cred
;
719 struct svc_xprt
*xprt
= rqstp
->rq_xprt
;
720 struct net
*net
= xprt
->xpt_net
;
721 struct sunrpc_net
*sn
= net_generic(net
, sunrpc_net_id
);
723 switch (rqstp
->rq_addr
.ss_family
) {
725 sin
= svc_addr_in(rqstp
);
726 sin6
= &sin6_storage
;
727 ipv6_addr_set_v4mapped(sin
->sin_addr
.s_addr
, &sin6
->sin6_addr
);
730 sin6
= svc_addr_in6(rqstp
);
736 rqstp
->rq_client
= NULL
;
737 if (rqstp
->rq_proc
== 0)
740 ipm
= ip_map_cached_get(xprt
);
742 ipm
= __ip_map_lookup(sn
->ip_map_cache
, rqstp
->rq_server
->sv_program
->pg_class
,
748 switch (cache_check(sn
->ip_map_cache
, &ipm
->h
, &rqstp
->rq_chandle
)) {
758 rqstp
->rq_client
= &ipm
->m_client
->h
;
759 kref_get(&rqstp
->rq_client
->ref
);
760 ip_map_cached_put(xprt
, ipm
);
764 gi
= unix_gid_find(cred
->cr_uid
, rqstp
);
765 switch (PTR_ERR(gi
)) {
773 put_group_info(cred
->cr_group_info
);
774 cred
->cr_group_info
= gi
;
779 EXPORT_SYMBOL_GPL(svcauth_unix_set_client
);
782 svcauth_null_accept(struct svc_rqst
*rqstp
, __be32
*authp
)
784 struct kvec
*argv
= &rqstp
->rq_arg
.head
[0];
785 struct kvec
*resv
= &rqstp
->rq_res
.head
[0];
786 struct svc_cred
*cred
= &rqstp
->rq_cred
;
788 cred
->cr_group_info
= NULL
;
789 rqstp
->rq_client
= NULL
;
791 if (argv
->iov_len
< 3*4)
794 if (svc_getu32(argv
) != 0) {
795 dprintk("svc: bad null cred\n");
796 *authp
= rpc_autherr_badcred
;
799 if (svc_getu32(argv
) != htonl(RPC_AUTH_NULL
) || svc_getu32(argv
) != 0) {
800 dprintk("svc: bad null verf\n");
801 *authp
= rpc_autherr_badverf
;
805 /* Signal that mapping to nobody uid/gid is required */
806 cred
->cr_uid
= (uid_t
) -1;
807 cred
->cr_gid
= (gid_t
) -1;
808 cred
->cr_group_info
= groups_alloc(0);
809 if (cred
->cr_group_info
== NULL
)
810 return SVC_CLOSE
; /* kmalloc failure - client must retry */
812 /* Put NULL verifier */
813 svc_putnl(resv
, RPC_AUTH_NULL
);
816 rqstp
->rq_flavor
= RPC_AUTH_NULL
;
821 svcauth_null_release(struct svc_rqst
*rqstp
)
823 if (rqstp
->rq_client
)
824 auth_domain_put(rqstp
->rq_client
);
825 rqstp
->rq_client
= NULL
;
826 if (rqstp
->rq_cred
.cr_group_info
)
827 put_group_info(rqstp
->rq_cred
.cr_group_info
);
828 rqstp
->rq_cred
.cr_group_info
= NULL
;
830 return 0; /* don't drop */
834 struct auth_ops svcauth_null
= {
836 .owner
= THIS_MODULE
,
837 .flavour
= RPC_AUTH_NULL
,
838 .accept
= svcauth_null_accept
,
839 .release
= svcauth_null_release
,
840 .set_client
= svcauth_unix_set_client
,
845 svcauth_unix_accept(struct svc_rqst
*rqstp
, __be32
*authp
)
847 struct kvec
*argv
= &rqstp
->rq_arg
.head
[0];
848 struct kvec
*resv
= &rqstp
->rq_res
.head
[0];
849 struct svc_cred
*cred
= &rqstp
->rq_cred
;
851 int len
= argv
->iov_len
;
853 cred
->cr_group_info
= NULL
;
854 rqstp
->rq_client
= NULL
;
856 if ((len
-= 3*4) < 0)
859 svc_getu32(argv
); /* length */
860 svc_getu32(argv
); /* time stamp */
861 slen
= XDR_QUADLEN(svc_getnl(argv
)); /* machname length */
862 if (slen
> 64 || (len
-= (slen
+ 3)*4) < 0)
864 argv
->iov_base
= (void*)((__be32
*)argv
->iov_base
+ slen
); /* skip machname */
865 argv
->iov_len
-= slen
*4;
867 cred
->cr_uid
= svc_getnl(argv
); /* uid */
868 cred
->cr_gid
= svc_getnl(argv
); /* gid */
869 slen
= svc_getnl(argv
); /* gids length */
870 if (slen
> 16 || (len
-= (slen
+ 2)*4) < 0)
872 cred
->cr_group_info
= groups_alloc(slen
);
873 if (cred
->cr_group_info
== NULL
)
875 for (i
= 0; i
< slen
; i
++)
876 GROUP_AT(cred
->cr_group_info
, i
) = svc_getnl(argv
);
877 if (svc_getu32(argv
) != htonl(RPC_AUTH_NULL
) || svc_getu32(argv
) != 0) {
878 *authp
= rpc_autherr_badverf
;
882 /* Put NULL verifier */
883 svc_putnl(resv
, RPC_AUTH_NULL
);
886 rqstp
->rq_flavor
= RPC_AUTH_UNIX
;
890 *authp
= rpc_autherr_badcred
;
895 svcauth_unix_release(struct svc_rqst
*rqstp
)
897 /* Verifier (such as it is) is already in place.
899 if (rqstp
->rq_client
)
900 auth_domain_put(rqstp
->rq_client
);
901 rqstp
->rq_client
= NULL
;
902 if (rqstp
->rq_cred
.cr_group_info
)
903 put_group_info(rqstp
->rq_cred
.cr_group_info
);
904 rqstp
->rq_cred
.cr_group_info
= NULL
;
910 struct auth_ops svcauth_unix
= {
912 .owner
= THIS_MODULE
,
913 .flavour
= RPC_AUTH_UNIX
,
914 .accept
= svcauth_unix_accept
,
915 .release
= svcauth_unix_release
,
916 .domain_release
= svcauth_unix_domain_release
,
917 .set_client
= svcauth_unix_set_client
,
920 int ip_map_cache_create(struct net
*net
)
923 struct cache_detail
*cd
;
924 struct cache_head
**tbl
;
925 struct sunrpc_net
*sn
= net_generic(net
, sunrpc_net_id
);
927 cd
= kzalloc(sizeof(struct cache_detail
), GFP_KERNEL
);
931 tbl
= kzalloc(IP_HASHMAX
* sizeof(struct cache_head
*), GFP_KERNEL
);
935 cd
->owner
= THIS_MODULE
,
936 cd
->hash_size
= IP_HASHMAX
,
937 cd
->hash_table
= tbl
,
938 cd
->name
= "auth.unix.ip",
939 cd
->cache_put
= ip_map_put
,
940 cd
->cache_upcall
= ip_map_upcall
,
941 cd
->cache_parse
= ip_map_parse
,
942 cd
->cache_show
= ip_map_show
,
943 cd
->match
= ip_map_match
,
944 cd
->init
= ip_map_init
,
946 cd
->alloc
= ip_map_alloc
,
948 err
= cache_register_net(cd
, net
);
952 sn
->ip_map_cache
= cd
;
963 void ip_map_cache_destroy(struct net
*net
)
965 struct sunrpc_net
*sn
;
967 sn
= net_generic(net
, sunrpc_net_id
);
968 cache_purge(sn
->ip_map_cache
);
969 cache_unregister_net(sn
->ip_map_cache
, net
);
970 kfree(sn
->ip_map_cache
->hash_table
);
971 kfree(sn
->ip_map_cache
);