auth_null.c 2.6 KB

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