2 * linux/net/sunrpc/auth.c
4 * Generic RPC client authentication API.
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
9 #include <linux/types.h>
10 #include <linux/sched.h>
11 #include <linux/cred.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/errno.h>
15 #include <linux/hash.h>
16 #include <linux/sunrpc/clnt.h>
17 #include <linux/sunrpc/gss_api.h>
18 #include <linux/spinlock.h>
20 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
21 # define RPCDBG_FACILITY RPCDBG_AUTH
24 #define RPC_CREDCACHE_DEFAULT_HASHBITS (4)
25 struct rpc_cred_cache
{
26 struct hlist_head
*hashtable
;
27 unsigned int hashbits
;
31 static unsigned int auth_hashbits
= RPC_CREDCACHE_DEFAULT_HASHBITS
;
33 static const struct rpc_authops __rcu
*auth_flavors
[RPC_AUTH_MAXFLAVOR
] = {
34 [RPC_AUTH_NULL
] = (const struct rpc_authops __force __rcu
*)&authnull_ops
,
35 [RPC_AUTH_UNIX
] = (const struct rpc_authops __force __rcu
*)&authunix_ops
,
36 NULL
, /* others can be loadable modules */
39 static LIST_HEAD(cred_unused
);
40 static unsigned long number_cred_unused
;
42 #define MAX_HASHTABLE_BITS (14)
43 static int param_set_hashtbl_sz(const char *val
, const struct kernel_param
*kp
)
51 ret
= kstrtoul(val
, 0, &num
);
55 if (nbits
> MAX_HASHTABLE_BITS
|| nbits
< 2)
57 *(unsigned int *)kp
->arg
= nbits
;
63 static int param_get_hashtbl_sz(char *buffer
, const struct kernel_param
*kp
)
67 nbits
= *(unsigned int *)kp
->arg
;
68 return sprintf(buffer
, "%u", 1U << nbits
);
71 #define param_check_hashtbl_sz(name, p) __param_check(name, p, unsigned int);
73 static const struct kernel_param_ops param_ops_hashtbl_sz
= {
74 .set
= param_set_hashtbl_sz
,
75 .get
= param_get_hashtbl_sz
,
78 module_param_named(auth_hashtable_size
, auth_hashbits
, hashtbl_sz
, 0644);
79 MODULE_PARM_DESC(auth_hashtable_size
, "RPC credential cache hashtable size");
81 static unsigned long auth_max_cred_cachesize
= ULONG_MAX
;
82 module_param(auth_max_cred_cachesize
, ulong
, 0644);
83 MODULE_PARM_DESC(auth_max_cred_cachesize
, "RPC credential maximum total cache size");
86 pseudoflavor_to_flavor(u32 flavor
) {
87 if (flavor
> RPC_AUTH_MAXFLAVOR
)
93 rpcauth_register(const struct rpc_authops
*ops
)
95 const struct rpc_authops
*old
;
96 rpc_authflavor_t flavor
;
98 if ((flavor
= ops
->au_flavor
) >= RPC_AUTH_MAXFLAVOR
)
100 old
= cmpxchg((const struct rpc_authops
** __force
)&auth_flavors
[flavor
], NULL
, ops
);
101 if (old
== NULL
|| old
== ops
)
105 EXPORT_SYMBOL_GPL(rpcauth_register
);
108 rpcauth_unregister(const struct rpc_authops
*ops
)
110 const struct rpc_authops
*old
;
111 rpc_authflavor_t flavor
;
113 if ((flavor
= ops
->au_flavor
) >= RPC_AUTH_MAXFLAVOR
)
116 old
= cmpxchg((const struct rpc_authops
** __force
)&auth_flavors
[flavor
], ops
, NULL
);
117 if (old
== ops
|| old
== NULL
)
121 EXPORT_SYMBOL_GPL(rpcauth_unregister
);
123 static const struct rpc_authops
*
124 rpcauth_get_authops(rpc_authflavor_t flavor
)
126 const struct rpc_authops
*ops
;
128 if (flavor
>= RPC_AUTH_MAXFLAVOR
)
132 ops
= rcu_dereference(auth_flavors
[flavor
]);
135 request_module("rpc-auth-%u", flavor
);
137 ops
= rcu_dereference(auth_flavors
[flavor
]);
141 if (!try_module_get(ops
->owner
))
149 rpcauth_put_authops(const struct rpc_authops
*ops
)
151 module_put(ops
->owner
);
155 * rpcauth_get_pseudoflavor - check if security flavor is supported
156 * @flavor: a security flavor
157 * @info: a GSS mech OID, quality of protection, and service value
159 * Verifies that an appropriate kernel module is available or already loaded.
160 * Returns an equivalent pseudoflavor, or RPC_AUTH_MAXFLAVOR if "flavor" is
161 * not supported locally.
164 rpcauth_get_pseudoflavor(rpc_authflavor_t flavor
, struct rpcsec_gss_info
*info
)
166 const struct rpc_authops
*ops
= rpcauth_get_authops(flavor
);
167 rpc_authflavor_t pseudoflavor
;
170 return RPC_AUTH_MAXFLAVOR
;
171 pseudoflavor
= flavor
;
172 if (ops
->info2flavor
!= NULL
)
173 pseudoflavor
= ops
->info2flavor(info
);
175 rpcauth_put_authops(ops
);
178 EXPORT_SYMBOL_GPL(rpcauth_get_pseudoflavor
);
181 * rpcauth_get_gssinfo - find GSS tuple matching a GSS pseudoflavor
182 * @pseudoflavor: GSS pseudoflavor to match
183 * @info: rpcsec_gss_info structure to fill in
185 * Returns zero and fills in "info" if pseudoflavor matches a
186 * supported mechanism.
189 rpcauth_get_gssinfo(rpc_authflavor_t pseudoflavor
, struct rpcsec_gss_info
*info
)
191 rpc_authflavor_t flavor
= pseudoflavor_to_flavor(pseudoflavor
);
192 const struct rpc_authops
*ops
;
195 ops
= rpcauth_get_authops(flavor
);
200 if (ops
->flavor2info
!= NULL
)
201 result
= ops
->flavor2info(pseudoflavor
, info
);
203 rpcauth_put_authops(ops
);
206 EXPORT_SYMBOL_GPL(rpcauth_get_gssinfo
);
209 * rpcauth_list_flavors - discover registered flavors and pseudoflavors
210 * @array: array to fill in
211 * @size: size of "array"
213 * Returns the number of array items filled in, or a negative errno.
215 * The returned array is not sorted by any policy. Callers should not
216 * rely on the order of the items in the returned array.
219 rpcauth_list_flavors(rpc_authflavor_t
*array
, int size
)
221 const struct rpc_authops
*ops
;
222 rpc_authflavor_t flavor
, pseudos
[4];
223 int i
, len
, result
= 0;
226 for (flavor
= 0; flavor
< RPC_AUTH_MAXFLAVOR
; flavor
++) {
227 ops
= rcu_dereference(auth_flavors
[flavor
]);
228 if (result
>= size
) {
235 if (ops
->list_pseudoflavors
== NULL
) {
236 array
[result
++] = ops
->au_flavor
;
239 len
= ops
->list_pseudoflavors(pseudos
, ARRAY_SIZE(pseudos
));
244 for (i
= 0; i
< len
; i
++) {
245 if (result
>= size
) {
249 array
[result
++] = pseudos
[i
];
254 dprintk("RPC: %s returns %d\n", __func__
, result
);
257 EXPORT_SYMBOL_GPL(rpcauth_list_flavors
);
260 rpcauth_create(const struct rpc_auth_create_args
*args
, struct rpc_clnt
*clnt
)
262 struct rpc_auth
*auth
= ERR_PTR(-EINVAL
);
263 const struct rpc_authops
*ops
;
264 u32 flavor
= pseudoflavor_to_flavor(args
->pseudoflavor
);
266 ops
= rpcauth_get_authops(flavor
);
270 auth
= ops
->create(args
, clnt
);
272 rpcauth_put_authops(ops
);
276 rpcauth_release(clnt
->cl_auth
);
277 clnt
->cl_auth
= auth
;
282 EXPORT_SYMBOL_GPL(rpcauth_create
);
285 rpcauth_release(struct rpc_auth
*auth
)
287 if (!refcount_dec_and_test(&auth
->au_count
))
289 auth
->au_ops
->destroy(auth
);
292 static DEFINE_SPINLOCK(rpc_credcache_lock
);
295 * On success, the caller is responsible for freeing the reference
296 * held by the hashtable
299 rpcauth_unhash_cred_locked(struct rpc_cred
*cred
)
301 if (!test_and_clear_bit(RPCAUTH_CRED_HASHED
, &cred
->cr_flags
))
303 hlist_del_rcu(&cred
->cr_hash
);
308 rpcauth_unhash_cred(struct rpc_cred
*cred
)
310 spinlock_t
*cache_lock
;
313 if (!test_bit(RPCAUTH_CRED_HASHED
, &cred
->cr_flags
))
315 cache_lock
= &cred
->cr_auth
->au_credcache
->lock
;
316 spin_lock(cache_lock
);
317 ret
= rpcauth_unhash_cred_locked(cred
);
318 spin_unlock(cache_lock
);
323 * Initialize RPC credential cache
326 rpcauth_init_credcache(struct rpc_auth
*auth
)
328 struct rpc_cred_cache
*new;
329 unsigned int hashsize
;
331 new = kmalloc(sizeof(*new), GFP_KERNEL
);
334 new->hashbits
= auth_hashbits
;
335 hashsize
= 1U << new->hashbits
;
336 new->hashtable
= kcalloc(hashsize
, sizeof(new->hashtable
[0]), GFP_KERNEL
);
339 spin_lock_init(&new->lock
);
340 auth
->au_credcache
= new;
347 EXPORT_SYMBOL_GPL(rpcauth_init_credcache
);
350 * Setup a credential key lifetime timeout notification
353 rpcauth_key_timeout_notify(struct rpc_auth
*auth
, struct rpc_cred
*cred
)
355 if (!cred
->cr_auth
->au_ops
->key_timeout
)
357 return cred
->cr_auth
->au_ops
->key_timeout(auth
, cred
);
359 EXPORT_SYMBOL_GPL(rpcauth_key_timeout_notify
);
362 rpcauth_cred_key_to_expire(struct rpc_auth
*auth
, struct rpc_cred
*cred
)
364 if (auth
->au_flags
& RPCAUTH_AUTH_NO_CRKEY_TIMEOUT
)
366 if (!cred
->cr_ops
->crkey_to_expire
)
368 return cred
->cr_ops
->crkey_to_expire(cred
);
370 EXPORT_SYMBOL_GPL(rpcauth_cred_key_to_expire
);
373 rpcauth_stringify_acceptor(struct rpc_cred
*cred
)
375 if (!cred
->cr_ops
->crstringify_acceptor
)
377 return cred
->cr_ops
->crstringify_acceptor(cred
);
379 EXPORT_SYMBOL_GPL(rpcauth_stringify_acceptor
);
382 * Destroy a list of credentials
385 void rpcauth_destroy_credlist(struct list_head
*head
)
387 struct rpc_cred
*cred
;
389 while (!list_empty(head
)) {
390 cred
= list_entry(head
->next
, struct rpc_cred
, cr_lru
);
391 list_del_init(&cred
->cr_lru
);
397 rpcauth_lru_add_locked(struct rpc_cred
*cred
)
399 if (!list_empty(&cred
->cr_lru
))
401 number_cred_unused
++;
402 list_add_tail(&cred
->cr_lru
, &cred_unused
);
406 rpcauth_lru_add(struct rpc_cred
*cred
)
408 if (!list_empty(&cred
->cr_lru
))
410 spin_lock(&rpc_credcache_lock
);
411 rpcauth_lru_add_locked(cred
);
412 spin_unlock(&rpc_credcache_lock
);
416 rpcauth_lru_remove_locked(struct rpc_cred
*cred
)
418 if (list_empty(&cred
->cr_lru
))
420 number_cred_unused
--;
421 list_del_init(&cred
->cr_lru
);
425 rpcauth_lru_remove(struct rpc_cred
*cred
)
427 if (list_empty(&cred
->cr_lru
))
429 spin_lock(&rpc_credcache_lock
);
430 rpcauth_lru_remove_locked(cred
);
431 spin_unlock(&rpc_credcache_lock
);
435 * Clear the RPC credential cache, and delete those credentials
436 * that are not referenced.
439 rpcauth_clear_credcache(struct rpc_cred_cache
*cache
)
442 struct hlist_head
*head
;
443 struct rpc_cred
*cred
;
444 unsigned int hashsize
= 1U << cache
->hashbits
;
447 spin_lock(&rpc_credcache_lock
);
448 spin_lock(&cache
->lock
);
449 for (i
= 0; i
< hashsize
; i
++) {
450 head
= &cache
->hashtable
[i
];
451 while (!hlist_empty(head
)) {
452 cred
= hlist_entry(head
->first
, struct rpc_cred
, cr_hash
);
453 rpcauth_unhash_cred_locked(cred
);
454 /* Note: We now hold a reference to cred */
455 rpcauth_lru_remove_locked(cred
);
456 list_add_tail(&cred
->cr_lru
, &free
);
459 spin_unlock(&cache
->lock
);
460 spin_unlock(&rpc_credcache_lock
);
461 rpcauth_destroy_credlist(&free
);
465 * Destroy the RPC credential cache
468 rpcauth_destroy_credcache(struct rpc_auth
*auth
)
470 struct rpc_cred_cache
*cache
= auth
->au_credcache
;
473 auth
->au_credcache
= NULL
;
474 rpcauth_clear_credcache(cache
);
475 kfree(cache
->hashtable
);
479 EXPORT_SYMBOL_GPL(rpcauth_destroy_credcache
);
482 #define RPC_AUTH_EXPIRY_MORATORIUM (60 * HZ)
485 * Remove stale credentials. Avoid sleeping inside the loop.
488 rpcauth_prune_expired(struct list_head
*free
, int nr_to_scan
)
490 struct rpc_cred
*cred
, *next
;
491 unsigned long expired
= jiffies
- RPC_AUTH_EXPIRY_MORATORIUM
;
494 list_for_each_entry_safe(cred
, next
, &cred_unused
, cr_lru
) {
496 if (nr_to_scan
-- == 0)
498 if (refcount_read(&cred
->cr_count
) > 1) {
499 rpcauth_lru_remove_locked(cred
);
503 * Enforce a 60 second garbage collection moratorium
504 * Note that the cred_unused list must be time-ordered.
506 if (!time_in_range(cred
->cr_expire
, expired
, jiffies
))
508 if (!rpcauth_unhash_cred(cred
))
511 rpcauth_lru_remove_locked(cred
);
513 list_add_tail(&cred
->cr_lru
, free
);
515 return freed
? freed
: SHRINK_STOP
;
519 rpcauth_cache_do_shrink(int nr_to_scan
)
524 spin_lock(&rpc_credcache_lock
);
525 freed
= rpcauth_prune_expired(&free
, nr_to_scan
);
526 spin_unlock(&rpc_credcache_lock
);
527 rpcauth_destroy_credlist(&free
);
533 * Run memory cache shrinker.
536 rpcauth_cache_shrink_scan(struct shrinker
*shrink
, struct shrink_control
*sc
)
539 if ((sc
->gfp_mask
& GFP_KERNEL
) != GFP_KERNEL
)
542 /* nothing left, don't come back */
543 if (list_empty(&cred_unused
))
546 return rpcauth_cache_do_shrink(sc
->nr_to_scan
);
550 rpcauth_cache_shrink_count(struct shrinker
*shrink
, struct shrink_control
*sc
)
553 return number_cred_unused
* sysctl_vfs_cache_pressure
/ 100;
557 rpcauth_cache_enforce_limit(void)
560 unsigned int nr_to_scan
;
562 if (number_cred_unused
<= auth_max_cred_cachesize
)
564 diff
= number_cred_unused
- auth_max_cred_cachesize
;
566 if (diff
< nr_to_scan
)
568 rpcauth_cache_do_shrink(nr_to_scan
);
572 * Look up a process' credentials in the authentication cache
575 rpcauth_lookup_credcache(struct rpc_auth
*auth
, struct auth_cred
* acred
,
576 int flags
, gfp_t gfp
)
579 struct rpc_cred_cache
*cache
= auth
->au_credcache
;
580 struct rpc_cred
*cred
= NULL
,
584 nr
= auth
->au_ops
->hash_cred(acred
, cache
->hashbits
);
587 hlist_for_each_entry_rcu(entry
, &cache
->hashtable
[nr
], cr_hash
) {
588 if (!entry
->cr_ops
->crmatch(acred
, entry
, flags
))
590 if (flags
& RPCAUTH_LOOKUP_RCU
) {
591 if (test_bit(RPCAUTH_CRED_NEW
, &entry
->cr_flags
) ||
592 refcount_read(&entry
->cr_count
) == 0)
597 cred
= get_rpccred(entry
);
606 if (flags
& RPCAUTH_LOOKUP_RCU
)
607 return ERR_PTR(-ECHILD
);
609 new = auth
->au_ops
->crcreate(auth
, acred
, flags
, gfp
);
615 spin_lock(&cache
->lock
);
616 hlist_for_each_entry(entry
, &cache
->hashtable
[nr
], cr_hash
) {
617 if (!entry
->cr_ops
->crmatch(acred
, entry
, flags
))
619 cred
= get_rpccred(entry
);
625 set_bit(RPCAUTH_CRED_HASHED
, &cred
->cr_flags
);
626 refcount_inc(&cred
->cr_count
);
627 hlist_add_head_rcu(&cred
->cr_hash
, &cache
->hashtable
[nr
]);
629 list_add_tail(&new->cr_lru
, &free
);
630 spin_unlock(&cache
->lock
);
631 rpcauth_cache_enforce_limit();
633 if (test_bit(RPCAUTH_CRED_NEW
, &cred
->cr_flags
) &&
634 cred
->cr_ops
->cr_init
!= NULL
&&
635 !(flags
& RPCAUTH_LOOKUP_NEW
)) {
636 int res
= cred
->cr_ops
->cr_init(auth
, cred
);
642 rpcauth_destroy_credlist(&free
);
646 EXPORT_SYMBOL_GPL(rpcauth_lookup_credcache
);
649 rpcauth_lookupcred(struct rpc_auth
*auth
, int flags
)
651 struct auth_cred acred
;
652 struct rpc_cred
*ret
;
653 const struct cred
*cred
= current_cred();
655 dprintk("RPC: looking up %s cred\n",
656 auth
->au_ops
->au_name
);
658 memset(&acred
, 0, sizeof(acred
));
659 acred
.uid
= cred
->fsuid
;
660 acred
.gid
= cred
->fsgid
;
661 acred
.group_info
= cred
->group_info
;
662 ret
= auth
->au_ops
->lookup_cred(auth
, &acred
, flags
);
665 EXPORT_SYMBOL_GPL(rpcauth_lookupcred
);
668 rpcauth_init_cred(struct rpc_cred
*cred
, const struct auth_cred
*acred
,
669 struct rpc_auth
*auth
, const struct rpc_credops
*ops
)
671 INIT_HLIST_NODE(&cred
->cr_hash
);
672 INIT_LIST_HEAD(&cred
->cr_lru
);
673 refcount_set(&cred
->cr_count
, 1);
674 cred
->cr_auth
= auth
;
676 cred
->cr_expire
= jiffies
;
677 cred
->cr_uid
= acred
->uid
;
679 EXPORT_SYMBOL_GPL(rpcauth_init_cred
);
682 rpcauth_generic_bind_cred(struct rpc_task
*task
, struct rpc_cred
*cred
, int lookupflags
)
684 dprintk("RPC: %5u holding %s cred %p\n", task
->tk_pid
,
685 cred
->cr_auth
->au_ops
->au_name
, cred
);
686 return get_rpccred(cred
);
688 EXPORT_SYMBOL_GPL(rpcauth_generic_bind_cred
);
690 static struct rpc_cred
*
691 rpcauth_bind_root_cred(struct rpc_task
*task
, int lookupflags
)
693 struct rpc_auth
*auth
= task
->tk_client
->cl_auth
;
694 struct auth_cred acred
= {
695 .uid
= GLOBAL_ROOT_UID
,
696 .gid
= GLOBAL_ROOT_GID
,
699 dprintk("RPC: %5u looking up %s cred\n",
700 task
->tk_pid
, task
->tk_client
->cl_auth
->au_ops
->au_name
);
701 return auth
->au_ops
->lookup_cred(auth
, &acred
, lookupflags
);
704 static struct rpc_cred
*
705 rpcauth_bind_new_cred(struct rpc_task
*task
, int lookupflags
)
707 struct rpc_auth
*auth
= task
->tk_client
->cl_auth
;
709 dprintk("RPC: %5u looking up %s cred\n",
710 task
->tk_pid
, auth
->au_ops
->au_name
);
711 return rpcauth_lookupcred(auth
, lookupflags
);
715 rpcauth_bindcred(struct rpc_task
*task
, struct rpc_cred
*cred
, int flags
)
717 struct rpc_rqst
*req
= task
->tk_rqstp
;
718 struct rpc_cred
*new;
721 if (flags
& RPC_TASK_ASYNC
)
722 lookupflags
|= RPCAUTH_LOOKUP_NEW
;
724 new = cred
->cr_ops
->crbind(task
, cred
, lookupflags
);
725 else if (flags
& RPC_TASK_ROOTCREDS
)
726 new = rpcauth_bind_root_cred(task
, lookupflags
);
728 new = rpcauth_bind_new_cred(task
, lookupflags
);
731 put_rpccred(req
->rq_cred
);
737 put_rpccred(struct rpc_cred
*cred
)
742 if (refcount_dec_and_test(&cred
->cr_count
))
744 if (refcount_read(&cred
->cr_count
) != 1 ||
745 !test_bit(RPCAUTH_CRED_HASHED
, &cred
->cr_flags
))
747 if (test_bit(RPCAUTH_CRED_UPTODATE
, &cred
->cr_flags
) != 0) {
748 cred
->cr_expire
= jiffies
;
749 rpcauth_lru_add(cred
);
751 if (unlikely(!test_bit(RPCAUTH_CRED_HASHED
, &cred
->cr_flags
)))
752 rpcauth_lru_remove(cred
);
753 } else if (rpcauth_unhash_cred(cred
)) {
754 rpcauth_lru_remove(cred
);
755 if (refcount_dec_and_test(&cred
->cr_count
))
763 cred
->cr_ops
->crdestroy(cred
);
765 EXPORT_SYMBOL_GPL(put_rpccred
);
768 rpcauth_marshcred(struct rpc_task
*task
, __be32
*p
)
770 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
772 dprintk("RPC: %5u marshaling %s cred %p\n",
773 task
->tk_pid
, cred
->cr_auth
->au_ops
->au_name
, cred
);
775 return cred
->cr_ops
->crmarshal(task
, p
);
779 rpcauth_checkverf(struct rpc_task
*task
, __be32
*p
)
781 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
783 dprintk("RPC: %5u validating %s cred %p\n",
784 task
->tk_pid
, cred
->cr_auth
->au_ops
->au_name
, cred
);
786 return cred
->cr_ops
->crvalidate(task
, p
);
789 static void rpcauth_wrap_req_encode(kxdreproc_t encode
, struct rpc_rqst
*rqstp
,
790 __be32
*data
, void *obj
)
792 struct xdr_stream xdr
;
794 xdr_init_encode(&xdr
, &rqstp
->rq_snd_buf
, data
);
795 encode(rqstp
, &xdr
, obj
);
799 rpcauth_wrap_req(struct rpc_task
*task
, kxdreproc_t encode
, void *rqstp
,
800 __be32
*data
, void *obj
)
802 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
804 dprintk("RPC: %5u using %s cred %p to wrap rpc data\n",
805 task
->tk_pid
, cred
->cr_ops
->cr_name
, cred
);
806 if (cred
->cr_ops
->crwrap_req
)
807 return cred
->cr_ops
->crwrap_req(task
, encode
, rqstp
, data
, obj
);
808 /* By default, we encode the arguments normally. */
809 rpcauth_wrap_req_encode(encode
, rqstp
, data
, obj
);
814 rpcauth_unwrap_req_decode(kxdrdproc_t decode
, struct rpc_rqst
*rqstp
,
815 __be32
*data
, void *obj
)
817 struct xdr_stream xdr
;
819 xdr_init_decode(&xdr
, &rqstp
->rq_rcv_buf
, data
);
820 return decode(rqstp
, &xdr
, obj
);
824 rpcauth_unwrap_resp(struct rpc_task
*task
, kxdrdproc_t decode
, void *rqstp
,
825 __be32
*data
, void *obj
)
827 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
829 dprintk("RPC: %5u using %s cred %p to unwrap rpc data\n",
830 task
->tk_pid
, cred
->cr_ops
->cr_name
, cred
);
831 if (cred
->cr_ops
->crunwrap_resp
)
832 return cred
->cr_ops
->crunwrap_resp(task
, decode
, rqstp
,
834 /* By default, we decode the arguments normally. */
835 return rpcauth_unwrap_req_decode(decode
, rqstp
, data
, obj
);
839 rpcauth_xmit_need_reencode(struct rpc_task
*task
)
841 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
843 if (!cred
|| !cred
->cr_ops
->crneed_reencode
)
845 return cred
->cr_ops
->crneed_reencode(task
);
849 rpcauth_refreshcred(struct rpc_task
*task
)
851 struct rpc_cred
*cred
;
854 cred
= task
->tk_rqstp
->rq_cred
;
856 err
= rpcauth_bindcred(task
, task
->tk_msg
.rpc_cred
, task
->tk_flags
);
859 cred
= task
->tk_rqstp
->rq_cred
;
861 dprintk("RPC: %5u refreshing %s cred %p\n",
862 task
->tk_pid
, cred
->cr_auth
->au_ops
->au_name
, cred
);
864 err
= cred
->cr_ops
->crrefresh(task
);
867 task
->tk_status
= err
;
872 rpcauth_invalcred(struct rpc_task
*task
)
874 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
876 dprintk("RPC: %5u invalidating %s cred %p\n",
877 task
->tk_pid
, cred
->cr_auth
->au_ops
->au_name
, cred
);
879 clear_bit(RPCAUTH_CRED_UPTODATE
, &cred
->cr_flags
);
883 rpcauth_uptodatecred(struct rpc_task
*task
)
885 struct rpc_cred
*cred
= task
->tk_rqstp
->rq_cred
;
887 return cred
== NULL
||
888 test_bit(RPCAUTH_CRED_UPTODATE
, &cred
->cr_flags
) != 0;
891 static struct shrinker rpc_cred_shrinker
= {
892 .count_objects
= rpcauth_cache_shrink_count
,
893 .scan_objects
= rpcauth_cache_shrink_scan
,
894 .seeks
= DEFAULT_SEEKS
,
897 int __init
rpcauth_init_module(void)
901 err
= rpc_init_authunix();
904 err
= rpc_init_generic_auth();
907 err
= register_shrinker(&rpc_cred_shrinker
);
912 rpc_destroy_generic_auth();
914 rpc_destroy_authunix();
919 void rpcauth_remove_module(void)
921 rpc_destroy_authunix();
922 rpc_destroy_generic_auth();
923 unregister_shrinker(&rpc_cred_shrinker
);