auth.c 15 KB

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