auth_null.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/net/sunrpc/auth_null.c
  4. *
  5. * AUTH_NULL authentication. Really :-)
  6. *
  7. * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
  8. */
  9. #include <linux/types.h>
  10. #include <linux/module.h>
  11. #include <linux/sunrpc/clnt.h>
  12. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  13. # define RPCDBG_FACILITY RPCDBG_AUTH
  14. #endif
  15. static struct rpc_auth null_auth;
  16. static struct rpc_cred null_cred;
  17. static struct rpc_auth *
  18. nul_create(const struct rpc_auth_create_args *args, struct rpc_clnt *clnt)
  19. {
  20. atomic_inc(&null_auth.au_count);
  21. return &null_auth;
  22. }
  23. static void
  24. nul_destroy(struct rpc_auth *auth)
  25. {
  26. }
  27. /*
  28. * Lookup NULL creds for current process
  29. */
  30. static struct rpc_cred *
  31. nul_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
  32. {
  33. if (flags & RPCAUTH_LOOKUP_RCU)
  34. return &null_cred;
  35. return get_rpccred(&null_cred);
  36. }
  37. /*
  38. * Destroy cred handle.
  39. */
  40. static void
  41. nul_destroy_cred(struct rpc_cred *cred)
  42. {
  43. }
  44. /*
  45. * Match cred handle against current process
  46. */
  47. static int
  48. nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags)
  49. {
  50. return 1;
  51. }
  52. /*
  53. * Marshal credential.
  54. */
  55. static __be32 *
  56. nul_marshal(struct rpc_task *task, __be32 *p)
  57. {
  58. *p++ = htonl(RPC_AUTH_NULL);
  59. *p++ = 0;
  60. *p++ = htonl(RPC_AUTH_NULL);
  61. *p++ = 0;
  62. return p;
  63. }
  64. /*
  65. * Refresh credential. This is a no-op for AUTH_NULL
  66. */
  67. static int
  68. nul_refresh(struct rpc_task *task)
  69. {
  70. set_bit(RPCAUTH_CRED_UPTODATE, &task->tk_rqstp->rq_cred->cr_flags);
  71. return 0;
  72. }
  73. static __be32 *
  74. nul_validate(struct rpc_task *task, __be32 *p)
  75. {
  76. rpc_authflavor_t flavor;
  77. u32 size;
  78. flavor = ntohl(*p++);
  79. if (flavor != RPC_AUTH_NULL) {
  80. printk("RPC: bad verf flavor: %u\n", flavor);
  81. return ERR_PTR(-EIO);
  82. }
  83. size = ntohl(*p++);
  84. if (size != 0) {
  85. printk("RPC: bad verf size: %u\n", size);
  86. return ERR_PTR(-EIO);
  87. }
  88. return p;
  89. }
  90. const struct rpc_authops authnull_ops = {
  91. .owner = THIS_MODULE,
  92. .au_flavor = RPC_AUTH_NULL,
  93. .au_name = "NULL",
  94. .create = nul_create,
  95. .destroy = nul_destroy,
  96. .lookup_cred = nul_lookup_cred,
  97. };
  98. static
  99. struct rpc_auth null_auth = {
  100. .au_cslack = NUL_CALLSLACK,
  101. .au_rslack = NUL_REPLYSLACK,
  102. .au_flags = RPCAUTH_AUTH_NO_CRKEY_TIMEOUT,
  103. .au_ops = &authnull_ops,
  104. .au_flavor = RPC_AUTH_NULL,
  105. .au_count = ATOMIC_INIT(0),
  106. };
  107. static
  108. const struct rpc_credops null_credops = {
  109. .cr_name = "AUTH_NULL",
  110. .crdestroy = nul_destroy_cred,
  111. .crbind = rpcauth_generic_bind_cred,
  112. .crmatch = nul_match,
  113. .crmarshal = nul_marshal,
  114. .crrefresh = nul_refresh,
  115. .crvalidate = nul_validate,
  116. };
  117. static
  118. struct rpc_cred null_cred = {
  119. .cr_lru = LIST_HEAD_INIT(null_cred.cr_lru),
  120. .cr_auth = &null_auth,
  121. .cr_ops = &null_credops,
  122. .cr_count = ATOMIC_INIT(1),
  123. .cr_flags = 1UL << RPCAUTH_CRED_UPTODATE,
  124. };