blob: 00f9649b09015d82c2ce83169478b614c779975d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/net/sunrpc/auth.c
3 *
4 * Generic RPC client authentication API.
5 *
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
8
9#include <linux/types.h>
10#include <linux/sched.h>
11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sunrpc/clnt.h>
15#include <linux/spinlock.h>
16
17#ifdef RPC_DEBUG
18# define RPCDBG_FACILITY RPCDBG_AUTH
19#endif
20
Trond Myklebustfc1b3562007-06-09 16:15:46 -040021static DEFINE_SPINLOCK(rpc_authflavor_lock);
Trond Myklebustf1c0a862007-06-23 20:17:58 -040022static const struct rpc_authops *auth_flavors[RPC_AUTH_MAXFLAVOR] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 &authnull_ops, /* AUTH_NULL */
24 &authunix_ops, /* AUTH_UNIX */
25 NULL, /* others can be loadable modules */
26};
27
Trond Myklebuste092bdc2007-06-23 19:45:36 -040028static LIST_HEAD(cred_unused);
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static u32
31pseudoflavor_to_flavor(u32 flavor) {
32 if (flavor >= RPC_AUTH_MAXFLAVOR)
33 return RPC_AUTH_GSS;
34 return flavor;
35}
36
37int
Trond Myklebustf1c0a862007-06-23 20:17:58 -040038rpcauth_register(const struct rpc_authops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 rpc_authflavor_t flavor;
Trond Myklebustfc1b3562007-06-09 16:15:46 -040041 int ret = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 if ((flavor = ops->au_flavor) >= RPC_AUTH_MAXFLAVOR)
44 return -EINVAL;
Trond Myklebustfc1b3562007-06-09 16:15:46 -040045 spin_lock(&rpc_authflavor_lock);
46 if (auth_flavors[flavor] == NULL) {
47 auth_flavors[flavor] = ops;
48 ret = 0;
49 }
50 spin_unlock(&rpc_authflavor_lock);
51 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
54int
Trond Myklebustf1c0a862007-06-23 20:17:58 -040055rpcauth_unregister(const struct rpc_authops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 rpc_authflavor_t flavor;
Trond Myklebustfc1b3562007-06-09 16:15:46 -040058 int ret = -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 if ((flavor = ops->au_flavor) >= RPC_AUTH_MAXFLAVOR)
61 return -EINVAL;
Trond Myklebustfc1b3562007-06-09 16:15:46 -040062 spin_lock(&rpc_authflavor_lock);
63 if (auth_flavors[flavor] == ops) {
64 auth_flavors[flavor] = NULL;
65 ret = 0;
66 }
67 spin_unlock(&rpc_authflavor_lock);
68 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71struct rpc_auth *
72rpcauth_create(rpc_authflavor_t pseudoflavor, struct rpc_clnt *clnt)
73{
74 struct rpc_auth *auth;
Trond Myklebustf1c0a862007-06-23 20:17:58 -040075 const struct rpc_authops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 u32 flavor = pseudoflavor_to_flavor(pseudoflavor);
77
Olaf Kirchf344f6d2006-03-20 13:44:08 -050078 auth = ERR_PTR(-EINVAL);
79 if (flavor >= RPC_AUTH_MAXFLAVOR)
80 goto out;
81
Olaf Kirchf344f6d2006-03-20 13:44:08 -050082#ifdef CONFIG_KMOD
83 if ((ops = auth_flavors[flavor]) == NULL)
84 request_module("rpc-auth-%u", flavor);
85#endif
Trond Myklebustfc1b3562007-06-09 16:15:46 -040086 spin_lock(&rpc_authflavor_lock);
87 ops = auth_flavors[flavor];
88 if (ops == NULL || !try_module_get(ops->owner)) {
89 spin_unlock(&rpc_authflavor_lock);
Olaf Kirchf344f6d2006-03-20 13:44:08 -050090 goto out;
Trond Myklebustfc1b3562007-06-09 16:15:46 -040091 }
92 spin_unlock(&rpc_authflavor_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 auth = ops->create(clnt, pseudoflavor);
Trond Myklebustfc1b3562007-06-09 16:15:46 -040094 module_put(ops->owner);
J. Bruce Fields6a192752005-06-22 17:16:23 +000095 if (IS_ERR(auth))
96 return auth;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 if (clnt->cl_auth)
Trond Myklebustde7a8ce2007-06-23 10:46:47 -040098 rpcauth_release(clnt->cl_auth);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 clnt->cl_auth = auth;
Olaf Kirchf344f6d2006-03-20 13:44:08 -0500100
101out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return auth;
103}
104
105void
Trond Myklebustde7a8ce2007-06-23 10:46:47 -0400106rpcauth_release(struct rpc_auth *auth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 if (!atomic_dec_and_test(&auth->au_count))
109 return;
110 auth->au_ops->destroy(auth);
111}
112
113static DEFINE_SPINLOCK(rpc_credcache_lock);
114
115/*
116 * Initialize RPC credential cache
117 */
118int
119rpcauth_init_credcache(struct rpc_auth *auth, unsigned long expire)
120{
121 struct rpc_cred_cache *new;
122 int i;
123
Kris Katterjohn8b3a7002006-01-11 15:56:43 -0800124 new = kmalloc(sizeof(*new), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (!new)
126 return -ENOMEM;
127 for (i = 0; i < RPC_CREDCACHE_NR; i++)
128 INIT_HLIST_HEAD(&new->hashtable[i]);
129 new->expire = expire;
130 new->nextgc = jiffies + (expire >> 1);
131 auth->au_credcache = new;
132 return 0;
133}
134
135/*
136 * Destroy a list of credentials
137 */
138static inline
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400139void rpcauth_destroy_credlist(struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 struct rpc_cred *cred;
142
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400143 while (!list_empty(head)) {
144 cred = list_entry(head->next, struct rpc_cred, cr_lru);
145 list_del_init(&cred->cr_lru);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 put_rpccred(cred);
147 }
148}
149
150/*
151 * Clear the RPC credential cache, and delete those credentials
152 * that are not referenced.
153 */
154void
Trond Myklebust3ab9bb72007-06-09 15:41:42 -0400155rpcauth_clear_credcache(struct rpc_cred_cache *cache)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400157 LIST_HEAD(free);
158 struct hlist_head *head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 struct rpc_cred *cred;
160 int i;
161
162 spin_lock(&rpc_credcache_lock);
163 for (i = 0; i < RPC_CREDCACHE_NR; i++) {
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400164 head = &cache->hashtable[i];
165 while (!hlist_empty(head)) {
166 cred = hlist_entry(head->first, struct rpc_cred, cr_hash);
167 get_rpccred(cred);
168 list_move_tail(&cred->cr_lru, &free);
169 smp_wmb();
170 hlist_del_init(&cred->cr_hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172 }
173 spin_unlock(&rpc_credcache_lock);
174 rpcauth_destroy_credlist(&free);
175}
176
Trond Myklebust3ab9bb72007-06-09 15:41:42 -0400177/*
178 * Destroy the RPC credential cache
179 */
180void
181rpcauth_destroy_credcache(struct rpc_auth *auth)
182{
183 struct rpc_cred_cache *cache = auth->au_credcache;
184
185 if (cache) {
186 auth->au_credcache = NULL;
187 rpcauth_clear_credcache(cache);
188 kfree(cache);
189 }
190}
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192/*
193 * Remove stale credentials. Avoid sleeping inside the loop.
194 */
195static void
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400196rpcauth_prune_expired(struct list_head *free)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400198 struct rpc_cred *cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400200 while (!list_empty(&cred_unused)) {
201 cred = list_entry(cred_unused.next, struct rpc_cred, cr_lru);
202 if (time_after(jiffies, cred->cr_expire +
203 cred->cr_auth->au_credcache->expire))
204 break;
205 list_del_init(&cred->cr_lru);
206 if (atomic_read(&cred->cr_count) != 0)
207 continue;
208 get_rpccred(cred);
209 list_add_tail(&cred->cr_lru, free);
210 smp_wmb();
211 hlist_del_init(&cred->cr_hash);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 }
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400213}
214
215/*
216 * Run garbage collector.
217 */
218static void
219rpcauth_gc_credcache(struct rpc_cred_cache *cache, struct list_head *free)
220{
221 if (time_before(jiffies, cache->nextgc))
222 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 cache->nextgc = jiffies + cache->expire;
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400224 rpcauth_prune_expired(free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
227/*
228 * Look up a process' credentials in the authentication cache
229 */
230struct rpc_cred *
231rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
Trond Myklebust8a317762006-02-01 12:18:36 -0500232 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400234 LIST_HEAD(free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 struct rpc_cred_cache *cache = auth->au_credcache;
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400236 struct hlist_node *pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 struct rpc_cred *new = NULL,
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400238 *cred = NULL,
239 *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 int nr = 0;
241
Trond Myklebust8a317762006-02-01 12:18:36 -0500242 if (!(flags & RPCAUTH_LOOKUP_ROOTCREDS))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 nr = acred->uid & RPC_CREDCACHE_MASK;
244retry:
245 spin_lock(&rpc_credcache_lock);
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400246 hlist_for_each_entry(entry, pos, &cache->hashtable[nr], cr_hash) {
247 if (!entry->cr_ops->crmatch(acred, entry, flags))
248 continue;
249 cred = get_rpccred(entry);
250 hlist_del(&entry->cr_hash);
251 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 }
253 if (new) {
254 if (cred)
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400255 list_add_tail(&new->cr_lru, &free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 else
257 cred = new;
258 }
259 if (cred) {
260 hlist_add_head(&cred->cr_hash, &cache->hashtable[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400262 rpcauth_gc_credcache(cache, &free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 spin_unlock(&rpc_credcache_lock);
264
265 rpcauth_destroy_credlist(&free);
266
267 if (!cred) {
Trond Myklebust8a317762006-02-01 12:18:36 -0500268 new = auth->au_ops->crcreate(auth, acred, flags);
Trond Myklebust5fe47552007-06-23 19:55:31 -0400269 if (!IS_ERR(new))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto retry;
Trond Myklebust5fe47552007-06-23 19:55:31 -0400271 cred = new;
Trond Myklebustfc432dd2007-06-25 10:15:15 -0400272 } else if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags)
Trond Myklebustfba3bad2006-02-01 12:19:27 -0500273 && cred->cr_ops->cr_init != NULL
274 && !(flags & RPCAUTH_LOOKUP_NEW)) {
275 int res = cred->cr_ops->cr_init(auth, cred);
276 if (res < 0) {
277 put_rpccred(cred);
278 cred = ERR_PTR(res);
279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
282 return (struct rpc_cred *) cred;
283}
284
285struct rpc_cred *
Trond Myklebust8a317762006-02-01 12:18:36 -0500286rpcauth_lookupcred(struct rpc_auth *auth, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 struct auth_cred acred = {
289 .uid = current->fsuid,
290 .gid = current->fsgid,
291 .group_info = current->group_info,
292 };
293 struct rpc_cred *ret;
294
Chuck Lever46121cf2007-01-31 12:14:08 -0500295 dprintk("RPC: looking up %s cred\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 auth->au_ops->au_name);
297 get_group_info(acred.group_info);
Trond Myklebust8a317762006-02-01 12:18:36 -0500298 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 put_group_info(acred.group_info);
300 return ret;
301}
302
Trond Myklebust5fe47552007-06-23 19:55:31 -0400303void
304rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
305 struct rpc_auth *auth, const struct rpc_credops *ops)
306{
307 INIT_HLIST_NODE(&cred->cr_hash);
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400308 INIT_LIST_HEAD(&cred->cr_lru);
Trond Myklebust5fe47552007-06-23 19:55:31 -0400309 atomic_set(&cred->cr_count, 1);
310 cred->cr_auth = auth;
311 cred->cr_ops = ops;
312 cred->cr_expire = jiffies;
313#ifdef RPC_DEBUG
314 cred->cr_magic = RPCAUTH_CRED_MAGIC;
315#endif
316 cred->cr_uid = acred->uid;
317}
318EXPORT_SYMBOL(rpcauth_init_cred);
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320struct rpc_cred *
321rpcauth_bindcred(struct rpc_task *task)
322{
323 struct rpc_auth *auth = task->tk_auth;
324 struct auth_cred acred = {
325 .uid = current->fsuid,
326 .gid = current->fsgid,
327 .group_info = current->group_info,
328 };
329 struct rpc_cred *ret;
Trond Myklebust8a317762006-02-01 12:18:36 -0500330 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Chuck Lever46121cf2007-01-31 12:14:08 -0500332 dprintk("RPC: %5u looking up %s cred\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 task->tk_pid, task->tk_auth->au_ops->au_name);
334 get_group_info(acred.group_info);
Trond Myklebust8a317762006-02-01 12:18:36 -0500335 if (task->tk_flags & RPC_TASK_ROOTCREDS)
336 flags |= RPCAUTH_LOOKUP_ROOTCREDS;
337 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (!IS_ERR(ret))
339 task->tk_msg.rpc_cred = ret;
340 else
341 task->tk_status = PTR_ERR(ret);
342 put_group_info(acred.group_info);
343 return ret;
344}
345
346void
347rpcauth_holdcred(struct rpc_task *task)
348{
Chuck Lever46121cf2007-01-31 12:14:08 -0500349 dprintk("RPC: %5u holding %s cred %p\n",
350 task->tk_pid, task->tk_auth->au_ops->au_name,
351 task->tk_msg.rpc_cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 if (task->tk_msg.rpc_cred)
353 get_rpccred(task->tk_msg.rpc_cred);
354}
355
356void
357put_rpccred(struct rpc_cred *cred)
358{
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400359 /* Fast path for unhashed credentials */
360 if (!hlist_unhashed(&cred->cr_hash))
361 goto need_lock;
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (!atomic_dec_and_test(&cred->cr_count))
364 return;
Trond Myklebuste092bdc2007-06-23 19:45:36 -0400365 goto out_destroy;
366
367need_lock:
368 if (!atomic_dec_and_lock(&cred->cr_count, &rpc_credcache_lock))
369 return;
370 if (!list_empty(&cred->cr_lru))
371 list_del_init(&cred->cr_lru);
372 if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) == 0)
373 hlist_del(&cred->cr_hash);
374 else if (!hlist_unhashed(&cred->cr_hash)) {
375 cred->cr_expire = jiffies;
376 list_add_tail(&cred->cr_lru, &cred_unused);
377 spin_unlock(&rpc_credcache_lock);
378 return;
379 }
380 spin_unlock(&rpc_credcache_lock);
381out_destroy:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 cred->cr_ops->crdestroy(cred);
383}
384
385void
386rpcauth_unbindcred(struct rpc_task *task)
387{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 struct rpc_cred *cred = task->tk_msg.rpc_cred;
389
Chuck Lever46121cf2007-01-31 12:14:08 -0500390 dprintk("RPC: %5u releasing %s cred %p\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500391 task->tk_pid, task->tk_auth->au_ops->au_name, cred);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 put_rpccred(cred);
394 task->tk_msg.rpc_cred = NULL;
395}
396
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700397__be32 *
398rpcauth_marshcred(struct rpc_task *task, __be32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 struct rpc_cred *cred = task->tk_msg.rpc_cred;
401
Chuck Lever46121cf2007-01-31 12:14:08 -0500402 dprintk("RPC: %5u marshaling %s cred %p\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500403 task->tk_pid, task->tk_auth->au_ops->au_name, cred);
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return cred->cr_ops->crmarshal(task, p);
406}
407
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700408__be32 *
409rpcauth_checkverf(struct rpc_task *task, __be32 *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 struct rpc_cred *cred = task->tk_msg.rpc_cred;
412
Chuck Lever46121cf2007-01-31 12:14:08 -0500413 dprintk("RPC: %5u validating %s cred %p\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500414 task->tk_pid, task->tk_auth->au_ops->au_name, cred);
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 return cred->cr_ops->crvalidate(task, p);
417}
418
419int
420rpcauth_wrap_req(struct rpc_task *task, kxdrproc_t encode, void *rqstp,
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700421 __be32 *data, void *obj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
423 struct rpc_cred *cred = task->tk_msg.rpc_cred;
424
Chuck Lever46121cf2007-01-31 12:14:08 -0500425 dprintk("RPC: %5u using %s cred %p to wrap rpc data\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 task->tk_pid, cred->cr_ops->cr_name, cred);
427 if (cred->cr_ops->crwrap_req)
428 return cred->cr_ops->crwrap_req(task, encode, rqstp, data, obj);
429 /* By default, we encode the arguments normally. */
430 return encode(rqstp, data, obj);
431}
432
433int
434rpcauth_unwrap_resp(struct rpc_task *task, kxdrproc_t decode, void *rqstp,
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700435 __be32 *data, void *obj)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
437 struct rpc_cred *cred = task->tk_msg.rpc_cred;
438
Chuck Lever46121cf2007-01-31 12:14:08 -0500439 dprintk("RPC: %5u using %s cred %p to unwrap rpc data\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 task->tk_pid, cred->cr_ops->cr_name, cred);
441 if (cred->cr_ops->crunwrap_resp)
442 return cred->cr_ops->crunwrap_resp(task, decode, rqstp,
443 data, obj);
444 /* By default, we decode the arguments normally. */
445 return decode(rqstp, data, obj);
446}
447
448int
449rpcauth_refreshcred(struct rpc_task *task)
450{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 struct rpc_cred *cred = task->tk_msg.rpc_cred;
452 int err;
453
Chuck Lever46121cf2007-01-31 12:14:08 -0500454 dprintk("RPC: %5u refreshing %s cred %p\n",
Chuck Lever0bbacc42005-11-01 16:53:32 -0500455 task->tk_pid, task->tk_auth->au_ops->au_name, cred);
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 err = cred->cr_ops->crrefresh(task);
458 if (err < 0)
459 task->tk_status = err;
460 return err;
461}
462
463void
464rpcauth_invalcred(struct rpc_task *task)
465{
Trond Myklebustfc432dd2007-06-25 10:15:15 -0400466 struct rpc_cred *cred = task->tk_msg.rpc_cred;
467
Chuck Lever46121cf2007-01-31 12:14:08 -0500468 dprintk("RPC: %5u invalidating %s cred %p\n",
Trond Myklebustfc432dd2007-06-25 10:15:15 -0400469 task->tk_pid, task->tk_auth->au_ops->au_name, cred);
470 if (cred)
471 clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
474int
475rpcauth_uptodatecred(struct rpc_task *task)
476{
Trond Myklebustfc432dd2007-06-25 10:15:15 -0400477 struct rpc_cred *cred = task->tk_msg.rpc_cred;
478
479 return cred == NULL ||
480 test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}