auth.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  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. #include <linux/types.h>
  9. #include <linux/sched.h>
  10. #include <linux/module.h>
  11. #include <linux/slab.h>
  12. #include <linux/errno.h>
  13. #include <linux/hash.h>
  14. #include <linux/sunrpc/clnt.h>
  15. #include <linux/spinlock.h>
  16. #ifdef RPC_DEBUG
  17. # define RPCDBG_FACILITY RPCDBG_AUTH
  18. #endif
  19. #define RPC_CREDCACHE_DEFAULT_HASHBITS (4)
  20. struct rpc_cred_cache {
  21. struct hlist_head *hashtable;
  22. unsigned int hashbits;
  23. spinlock_t lock;
  24. };
  25. static unsigned int auth_hashbits = RPC_CREDCACHE_DEFAULT_HASHBITS;
  26. static DEFINE_SPINLOCK(rpc_authflavor_lock);
  27. static const struct rpc_authops *auth_flavors[RPC_AUTH_MAXFLAVOR] = {
  28. &authnull_ops, /* AUTH_NULL */
  29. &authunix_ops, /* AUTH_UNIX */
  30. NULL, /* others can be loadable modules */
  31. };
  32. static LIST_HEAD(cred_unused);
  33. static unsigned long number_cred_unused;
  34. #define MAX_HASHTABLE_BITS (14)
  35. static int param_set_hashtbl_sz(const char *val, const struct kernel_param *kp)
  36. {
  37. unsigned long num;
  38. unsigned int nbits;
  39. int ret;
  40. if (!val)
  41. goto out_inval;
  42. ret = strict_strtoul(val, 0, &num);
  43. if (ret == -EINVAL)
  44. goto out_inval;
  45. nbits = fls(num);
  46. if (num > (1U << nbits))
  47. nbits++;
  48. if (nbits > MAX_HASHTABLE_BITS || nbits < 2)
  49. goto out_inval;
  50. *(unsigned int *)kp->arg = nbits;
  51. return 0;
  52. out_inval:
  53. return -EINVAL;
  54. }
  55. static int param_get_hashtbl_sz(char *buffer, const struct kernel_param *kp)
  56. {
  57. unsigned int nbits;
  58. nbits = *(unsigned int *)kp->arg;
  59. return sprintf(buffer, "%u", 1U << nbits);
  60. }
  61. #define param_check_hashtbl_sz(name, p) __param_check(name, p, unsigned int);
  62. static struct kernel_param_ops param_ops_hashtbl_sz = {
  63. .set = param_set_hashtbl_sz,
  64. .get = param_get_hashtbl_sz,
  65. };
  66. module_param_named(auth_hashtable_size, auth_hashbits, hashtbl_sz, 0644);
  67. MODULE_PARM_DESC(auth_hashtable_size, "RPC credential cache hashtable size");
  68. static u32
  69. pseudoflavor_to_flavor(u32 flavor) {
  70. if (flavor >= RPC_AUTH_MAXFLAVOR)
  71. return RPC_AUTH_GSS;
  72. return flavor;
  73. }
  74. int
  75. rpcauth_register(const struct rpc_authops *ops)
  76. {
  77. rpc_authflavor_t flavor;
  78. int ret = -EPERM;
  79. if ((flavor = ops->au_flavor) >= RPC_AUTH_MAXFLAVOR)
  80. return -EINVAL;
  81. spin_lock(&rpc_authflavor_lock);
  82. if (auth_flavors[flavor] == NULL) {
  83. auth_flavors[flavor] = ops;
  84. ret = 0;
  85. }
  86. spin_unlock(&rpc_authflavor_lock);
  87. return ret;
  88. }
  89. EXPORT_SYMBOL_GPL(rpcauth_register);
  90. int
  91. rpcauth_unregister(const struct rpc_authops *ops)
  92. {
  93. rpc_authflavor_t flavor;
  94. int ret = -EPERM;
  95. if ((flavor = ops->au_flavor) >= RPC_AUTH_MAXFLAVOR)
  96. return -EINVAL;
  97. spin_lock(&rpc_authflavor_lock);
  98. if (auth_flavors[flavor] == ops) {
  99. auth_flavors[flavor] = NULL;
  100. ret = 0;
  101. }
  102. spin_unlock(&rpc_authflavor_lock);
  103. return ret;
  104. }
  105. EXPORT_SYMBOL_GPL(rpcauth_unregister);
  106. struct rpc_auth *
  107. rpcauth_create(rpc_authflavor_t pseudoflavor, struct rpc_clnt *clnt)
  108. {
  109. struct rpc_auth *auth;
  110. const struct rpc_authops *ops;
  111. u32 flavor = pseudoflavor_to_flavor(pseudoflavor);
  112. auth = ERR_PTR(-EINVAL);
  113. if (flavor >= RPC_AUTH_MAXFLAVOR)
  114. goto out;
  115. if ((ops = auth_flavors[flavor]) == NULL)
  116. request_module("rpc-auth-%u", flavor);
  117. spin_lock(&rpc_authflavor_lock);
  118. ops = auth_flavors[flavor];
  119. if (ops == NULL || !try_module_get(ops->owner)) {
  120. spin_unlock(&rpc_authflavor_lock);
  121. goto out;
  122. }
  123. spin_unlock(&rpc_authflavor_lock);
  124. auth = ops->create(clnt, pseudoflavor);
  125. module_put(ops->owner);
  126. if (IS_ERR(auth))
  127. return auth;
  128. if (clnt->cl_auth)
  129. rpcauth_release(clnt->cl_auth);
  130. clnt->cl_auth = auth;
  131. out:
  132. return auth;
  133. }
  134. EXPORT_SYMBOL_GPL(rpcauth_create);
  135. void
  136. rpcauth_release(struct rpc_auth *auth)
  137. {
  138. if (!atomic_dec_and_test(&auth->au_count))
  139. return;
  140. auth->au_ops->destroy(auth);
  141. }
  142. static DEFINE_SPINLOCK(rpc_credcache_lock);
  143. static void
  144. rpcauth_unhash_cred_locked(struct rpc_cred *cred)
  145. {
  146. hlist_del_rcu(&cred->cr_hash);
  147. smp_mb__before_clear_bit();
  148. clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags);
  149. }
  150. static int
  151. rpcauth_unhash_cred(struct rpc_cred *cred)
  152. {
  153. spinlock_t *cache_lock;
  154. int ret;
  155. cache_lock = &cred->cr_auth->au_credcache->lock;
  156. spin_lock(cache_lock);
  157. ret = atomic_read(&cred->cr_count) == 0;
  158. if (ret)
  159. rpcauth_unhash_cred_locked(cred);
  160. spin_unlock(cache_lock);
  161. return ret;
  162. }
  163. /*
  164. * Initialize RPC credential cache
  165. */
  166. int
  167. rpcauth_init_credcache(struct rpc_auth *auth)
  168. {
  169. struct rpc_cred_cache *new;
  170. unsigned int hashsize;
  171. new = kmalloc(sizeof(*new), GFP_KERNEL);
  172. if (!new)
  173. goto out_nocache;
  174. new->hashbits = auth_hashbits;
  175. hashsize = 1U << new->hashbits;
  176. new->hashtable = kcalloc(hashsize, sizeof(new->hashtable[0]), GFP_KERNEL);
  177. if (!new->hashtable)
  178. goto out_nohashtbl;
  179. spin_lock_init(&new->lock);
  180. auth->au_credcache = new;
  181. return 0;
  182. out_nohashtbl:
  183. kfree(new);
  184. out_nocache:
  185. return -ENOMEM;
  186. }
  187. EXPORT_SYMBOL_GPL(rpcauth_init_credcache);
  188. /*
  189. * Destroy a list of credentials
  190. */
  191. static inline
  192. void rpcauth_destroy_credlist(struct list_head *head)
  193. {
  194. struct rpc_cred *cred;
  195. while (!list_empty(head)) {
  196. cred = list_entry(head->next, struct rpc_cred, cr_lru);
  197. list_del_init(&cred->cr_lru);
  198. put_rpccred(cred);
  199. }
  200. }
  201. /*
  202. * Clear the RPC credential cache, and delete those credentials
  203. * that are not referenced.
  204. */
  205. void
  206. rpcauth_clear_credcache(struct rpc_cred_cache *cache)
  207. {
  208. LIST_HEAD(free);
  209. struct hlist_head *head;
  210. struct rpc_cred *cred;
  211. unsigned int hashsize = 1U << cache->hashbits;
  212. int i;
  213. spin_lock(&rpc_credcache_lock);
  214. spin_lock(&cache->lock);
  215. for (i = 0; i < hashsize; i++) {
  216. head = &cache->hashtable[i];
  217. while (!hlist_empty(head)) {
  218. cred = hlist_entry(head->first, struct rpc_cred, cr_hash);
  219. get_rpccred(cred);
  220. if (!list_empty(&cred->cr_lru)) {
  221. list_del(&cred->cr_lru);
  222. number_cred_unused--;
  223. }
  224. list_add_tail(&cred->cr_lru, &free);
  225. rpcauth_unhash_cred_locked(cred);
  226. }
  227. }
  228. spin_unlock(&cache->lock);
  229. spin_unlock(&rpc_credcache_lock);
  230. rpcauth_destroy_credlist(&free);
  231. }
  232. /*
  233. * Destroy the RPC credential cache
  234. */
  235. void
  236. rpcauth_destroy_credcache(struct rpc_auth *auth)
  237. {
  238. struct rpc_cred_cache *cache = auth->au_credcache;
  239. if (cache) {
  240. auth->au_credcache = NULL;
  241. rpcauth_clear_credcache(cache);
  242. kfree(cache->hashtable);
  243. kfree(cache);
  244. }
  245. }
  246. EXPORT_SYMBOL_GPL(rpcauth_destroy_credcache);
  247. #define RPC_AUTH_EXPIRY_MORATORIUM (60 * HZ)
  248. /*
  249. * Remove stale credentials. Avoid sleeping inside the loop.
  250. */
  251. static int
  252. rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
  253. {
  254. spinlock_t *cache_lock;
  255. struct rpc_cred *cred, *next;
  256. unsigned long expired = jiffies - RPC_AUTH_EXPIRY_MORATORIUM;
  257. list_for_each_entry_safe(cred, next, &cred_unused, cr_lru) {
  258. if (nr_to_scan-- == 0)
  259. break;
  260. /*
  261. * Enforce a 60 second garbage collection moratorium
  262. * Note that the cred_unused list must be time-ordered.
  263. */
  264. if (time_in_range(cred->cr_expire, expired, jiffies) &&
  265. test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0)
  266. return 0;
  267. list_del_init(&cred->cr_lru);
  268. number_cred_unused--;
  269. if (atomic_read(&cred->cr_count) != 0)
  270. continue;
  271. cache_lock = &cred->cr_auth->au_credcache->lock;
  272. spin_lock(cache_lock);
  273. if (atomic_read(&cred->cr_count) == 0) {
  274. get_rpccred(cred);
  275. list_add_tail(&cred->cr_lru, free);
  276. rpcauth_unhash_cred_locked(cred);
  277. }
  278. spin_unlock(cache_lock);
  279. }
  280. return (number_cred_unused / 100) * sysctl_vfs_cache_pressure;
  281. }
  282. /*
  283. * Run memory cache shrinker.
  284. */
  285. static int
  286. rpcauth_cache_shrinker(struct shrinker *shrink, int nr_to_scan, gfp_t gfp_mask)
  287. {
  288. LIST_HEAD(free);
  289. int res;
  290. if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
  291. return (nr_to_scan == 0) ? 0 : -1;
  292. if (list_empty(&cred_unused))
  293. return 0;
  294. spin_lock(&rpc_credcache_lock);
  295. res = rpcauth_prune_expired(&free, nr_to_scan);
  296. spin_unlock(&rpc_credcache_lock);
  297. rpcauth_destroy_credlist(&free);
  298. return res;
  299. }
  300. /*
  301. * Look up a process' credentials in the authentication cache
  302. */
  303. struct rpc_cred *
  304. rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
  305. int flags)
  306. {
  307. LIST_HEAD(free);
  308. struct rpc_cred_cache *cache = auth->au_credcache;
  309. struct hlist_node *pos;
  310. struct rpc_cred *cred = NULL,
  311. *entry, *new;
  312. unsigned int nr;
  313. nr = hash_long(acred->uid, cache->hashbits);
  314. rcu_read_lock();
  315. hlist_for_each_entry_rcu(entry, pos, &cache->hashtable[nr], cr_hash) {
  316. if (!entry->cr_ops->crmatch(acred, entry, flags))
  317. continue;
  318. spin_lock(&cache->lock);
  319. if (test_bit(RPCAUTH_CRED_HASHED, &entry->cr_flags) == 0) {
  320. spin_unlock(&cache->lock);
  321. continue;
  322. }
  323. cred = get_rpccred(entry);
  324. spin_unlock(&cache->lock);
  325. break;
  326. }
  327. rcu_read_unlock();
  328. if (cred != NULL)
  329. goto found;
  330. new = auth->au_ops->crcreate(auth, acred, flags);
  331. if (IS_ERR(new)) {
  332. cred = new;
  333. goto out;
  334. }
  335. spin_lock(&cache->lock);
  336. hlist_for_each_entry(entry, pos, &cache->hashtable[nr], cr_hash) {
  337. if (!entry->cr_ops->crmatch(acred, entry, flags))
  338. continue;
  339. cred = get_rpccred(entry);
  340. break;
  341. }
  342. if (cred == NULL) {
  343. cred = new;
  344. set_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags);
  345. hlist_add_head_rcu(&cred->cr_hash, &cache->hashtable[nr]);
  346. } else
  347. list_add_tail(&new->cr_lru, &free);
  348. spin_unlock(&cache->lock);
  349. found:
  350. if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) &&
  351. cred->cr_ops->cr_init != NULL &&
  352. !(flags & RPCAUTH_LOOKUP_NEW)) {
  353. int res = cred->cr_ops->cr_init(auth, cred);
  354. if (res < 0) {
  355. put_rpccred(cred);
  356. cred = ERR_PTR(res);
  357. }
  358. }
  359. rpcauth_destroy_credlist(&free);
  360. out:
  361. return cred;
  362. }
  363. EXPORT_SYMBOL_GPL(rpcauth_lookup_credcache);
  364. struct rpc_cred *
  365. rpcauth_lookupcred(struct rpc_auth *auth, int flags)
  366. {
  367. struct auth_cred acred;
  368. struct rpc_cred *ret;
  369. const struct cred *cred = current_cred();
  370. dprintk("RPC: looking up %s cred\n",
  371. auth->au_ops->au_name);
  372. memset(&acred, 0, sizeof(acred));
  373. acred.uid = cred->fsuid;
  374. acred.gid = cred->fsgid;
  375. acred.group_info = get_group_info(((struct cred *)cred)->group_info);
  376. ret = auth->au_ops->lookup_cred(auth, &acred, flags);
  377. put_group_info(acred.group_info);
  378. return ret;
  379. }
  380. void
  381. rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
  382. struct rpc_auth *auth, const struct rpc_credops *ops)
  383. {
  384. INIT_HLIST_NODE(&cred->cr_hash);
  385. INIT_LIST_HEAD(&cred->cr_lru);
  386. atomic_set(&cred->cr_count, 1);
  387. cred->cr_auth = auth;
  388. cred->cr_ops = ops;
  389. cred->cr_expire = jiffies;
  390. #ifdef RPC_DEBUG
  391. cred->cr_magic = RPCAUTH_CRED_MAGIC;
  392. #endif
  393. cred->cr_uid = acred->uid;
  394. }
  395. EXPORT_SYMBOL_GPL(rpcauth_init_cred);
  396. struct rpc_cred *
  397. rpcauth_generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred, int lookupflags)
  398. {
  399. dprintk("RPC: %5u holding %s cred %p\n", task->tk_pid,
  400. cred->cr_auth->au_ops->au_name, cred);
  401. return get_rpccred(cred);
  402. }
  403. EXPORT_SYMBOL_GPL(rpcauth_generic_bind_cred);
  404. static struct rpc_cred *
  405. rpcauth_bind_root_cred(struct rpc_task *task, int lookupflags)
  406. {
  407. struct rpc_auth *auth = task->tk_client->cl_auth;
  408. struct auth_cred acred = {
  409. .uid = 0,
  410. .gid = 0,
  411. };
  412. dprintk("RPC: %5u looking up %s cred\n",
  413. task->tk_pid, task->tk_client->cl_auth->au_ops->au_name);
  414. return auth->au_ops->lookup_cred(auth, &acred, lookupflags);
  415. }
  416. static struct rpc_cred *
  417. rpcauth_bind_new_cred(struct rpc_task *task, int lookupflags)
  418. {
  419. struct rpc_auth *auth = task->tk_client->cl_auth;
  420. dprintk("RPC: %5u looking up %s cred\n",
  421. task->tk_pid, auth->au_ops->au_name);
  422. return rpcauth_lookupcred(auth, lookupflags);
  423. }
  424. static int
  425. rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
  426. {
  427. struct rpc_rqst *req = task->tk_rqstp;
  428. struct rpc_cred *new;
  429. int lookupflags = 0;
  430. if (flags & RPC_TASK_ASYNC)
  431. lookupflags |= RPCAUTH_LOOKUP_NEW;
  432. if (cred != NULL)
  433. new = cred->cr_ops->crbind(task, cred, lookupflags);
  434. else if (flags & RPC_TASK_ROOTCREDS)
  435. new = rpcauth_bind_root_cred(task, lookupflags);
  436. else
  437. new = rpcauth_bind_new_cred(task, lookupflags);
  438. if (IS_ERR(new))
  439. return PTR_ERR(new);
  440. if (req->rq_cred != NULL)
  441. put_rpccred(req->rq_cred);
  442. req->rq_cred = new;
  443. return 0;
  444. }
  445. void
  446. put_rpccred(struct rpc_cred *cred)
  447. {
  448. /* Fast path for unhashed credentials */
  449. if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) == 0) {
  450. if (atomic_dec_and_test(&cred->cr_count))
  451. cred->cr_ops->crdestroy(cred);
  452. return;
  453. }
  454. if (!atomic_dec_and_lock(&cred->cr_count, &rpc_credcache_lock))
  455. return;
  456. if (!list_empty(&cred->cr_lru)) {
  457. number_cred_unused--;
  458. list_del_init(&cred->cr_lru);
  459. }
  460. if (test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0) {
  461. if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0) {
  462. cred->cr_expire = jiffies;
  463. list_add_tail(&cred->cr_lru, &cred_unused);
  464. number_cred_unused++;
  465. goto out_nodestroy;
  466. }
  467. if (!rpcauth_unhash_cred(cred)) {
  468. /* We were hashed and someone looked us up... */
  469. goto out_nodestroy;
  470. }
  471. }
  472. spin_unlock(&rpc_credcache_lock);
  473. cred->cr_ops->crdestroy(cred);
  474. return;
  475. out_nodestroy:
  476. spin_unlock(&rpc_credcache_lock);
  477. }
  478. EXPORT_SYMBOL_GPL(put_rpccred);
  479. __be32 *
  480. rpcauth_marshcred(struct rpc_task *task, __be32 *p)
  481. {
  482. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  483. dprintk("RPC: %5u marshaling %s cred %p\n",
  484. task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
  485. return cred->cr_ops->crmarshal(task, p);
  486. }
  487. __be32 *
  488. rpcauth_checkverf(struct rpc_task *task, __be32 *p)
  489. {
  490. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  491. dprintk("RPC: %5u validating %s cred %p\n",
  492. task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
  493. return cred->cr_ops->crvalidate(task, p);
  494. }
  495. int
  496. rpcauth_wrap_req(struct rpc_task *task, kxdrproc_t encode, void *rqstp,
  497. __be32 *data, void *obj)
  498. {
  499. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  500. dprintk("RPC: %5u using %s cred %p to wrap rpc data\n",
  501. task->tk_pid, cred->cr_ops->cr_name, cred);
  502. if (cred->cr_ops->crwrap_req)
  503. return cred->cr_ops->crwrap_req(task, encode, rqstp, data, obj);
  504. /* By default, we encode the arguments normally. */
  505. return encode(rqstp, data, obj);
  506. }
  507. int
  508. rpcauth_unwrap_resp(struct rpc_task *task, kxdrproc_t decode, void *rqstp,
  509. __be32 *data, void *obj)
  510. {
  511. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  512. dprintk("RPC: %5u using %s cred %p to unwrap rpc data\n",
  513. task->tk_pid, cred->cr_ops->cr_name, cred);
  514. if (cred->cr_ops->crunwrap_resp)
  515. return cred->cr_ops->crunwrap_resp(task, decode, rqstp,
  516. data, obj);
  517. /* By default, we decode the arguments normally. */
  518. return decode(rqstp, data, obj);
  519. }
  520. int
  521. rpcauth_refreshcred(struct rpc_task *task)
  522. {
  523. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  524. int err;
  525. cred = task->tk_rqstp->rq_cred;
  526. if (cred == NULL) {
  527. err = rpcauth_bindcred(task, task->tk_msg.rpc_cred, task->tk_flags);
  528. if (err < 0)
  529. goto out;
  530. cred = task->tk_rqstp->rq_cred;
  531. };
  532. dprintk("RPC: %5u refreshing %s cred %p\n",
  533. task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
  534. err = cred->cr_ops->crrefresh(task);
  535. out:
  536. if (err < 0)
  537. task->tk_status = err;
  538. return err;
  539. }
  540. void
  541. rpcauth_invalcred(struct rpc_task *task)
  542. {
  543. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  544. dprintk("RPC: %5u invalidating %s cred %p\n",
  545. task->tk_pid, cred->cr_auth->au_ops->au_name, cred);
  546. if (cred)
  547. clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
  548. }
  549. int
  550. rpcauth_uptodatecred(struct rpc_task *task)
  551. {
  552. struct rpc_cred *cred = task->tk_rqstp->rq_cred;
  553. return cred == NULL ||
  554. test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0;
  555. }
  556. static struct shrinker rpc_cred_shrinker = {
  557. .shrink = rpcauth_cache_shrinker,
  558. .seeks = DEFAULT_SEEKS,
  559. };
  560. int __init rpcauth_init_module(void)
  561. {
  562. int err;
  563. err = rpc_init_authunix();
  564. if (err < 0)
  565. goto out1;
  566. err = rpc_init_generic_auth();
  567. if (err < 0)
  568. goto out2;
  569. register_shrinker(&rpc_cred_shrinker);
  570. return 0;
  571. out2:
  572. rpc_destroy_authunix();
  573. out1:
  574. return err;
  575. }
  576. void __exit rpcauth_remove_module(void)
  577. {
  578. rpc_destroy_authunix();
  579. rpc_destroy_generic_auth();
  580. unregister_shrinker(&rpc_cred_shrinker);
  581. }