auth_null.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifdef RPC_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_clnt *clnt, rpc_authflavor_t flavor)
  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. return get_rpccred(&null_cred);
  33. }
  34. /*
  35. * Destroy cred handle.
  36. */
  37. static void
  38. nul_destroy_cred(struct rpc_cred *cred)
  39. {
  40. }
  41. /*
  42. * Match cred handle against current process
  43. */
  44. static int
  45. nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags)
  46. {
  47. return 1;
  48. }
  49. /*
  50. * Marshal credential.
  51. */
  52. static __be32 *
  53. nul_marshal(struct rpc_task *task, __be32 *p)
  54. {
  55. *p++ = htonl(RPC_AUTH_NULL);
  56. *p++ = 0;
  57. *p++ = htonl(RPC_AUTH_NULL);
  58. *p++ = 0;
  59. return p;
  60. }
  61. /*
  62. * Refresh credential. This is a no-op for AUTH_NULL
  63. */
  64. static int
  65. nul_refresh(struct rpc_task *task)
  66. {
  67. set_bit(RPCAUTH_CRED_UPTODATE, &task->tk_rqstp->rq_cred->cr_flags);
  68. return 0;
  69. }
  70. static __be32 *
  71. nul_validate(struct rpc_task *task, __be32 *p)
  72. {
  73. rpc_authflavor_t flavor;
  74. u32 size;
  75. flavor = ntohl(*p++);
  76. if (flavor != RPC_AUTH_NULL) {
  77. printk("RPC: bad verf flavor: %u\n", flavor);
  78. return NULL;
  79. }
  80. size = ntohl(*p++);
  81. if (size != 0) {
  82. printk("RPC: bad verf size: %u\n", size);
  83. return NULL;
  84. }
  85. return p;
  86. }
  87. const struct rpc_authops authnull_ops = {
  88. .owner = THIS_MODULE,
  89. .au_flavor = RPC_AUTH_NULL,
  90. .au_name = "NULL",
  91. .create = nul_create,
  92. .destroy = nul_destroy,
  93. .lookup_cred = nul_lookup_cred,
  94. };
  95. static
  96. struct rpc_auth null_auth = {
  97. .au_cslack = 4,
  98. .au_rslack = 2,
  99. .au_ops = &authnull_ops,
  100. .au_flavor = RPC_AUTH_NULL,
  101. .au_count = ATOMIC_INIT(0),
  102. };
  103. static
  104. const struct rpc_credops null_credops = {
  105. .cr_name = "AUTH_NULL",
  106. .crdestroy = nul_destroy_cred,
  107. .crbind = rpcauth_generic_bind_cred,
  108. .crmatch = nul_match,
  109. .crmarshal = nul_marshal,
  110. .crrefresh = nul_refresh,
  111. .crvalidate = nul_validate,
  112. };
  113. static
  114. struct rpc_cred null_cred = {
  115. .cr_lru = LIST_HEAD_INIT(null_cred.cr_lru),
  116. .cr_auth = &null_auth,
  117. .cr_ops = &null_credops,
  118. .cr_count = ATOMIC_INIT(1),
  119. .cr_flags = 1UL << RPCAUTH_CRED_UPTODATE,
  120. #ifdef RPC_DEBUG
  121. .cr_magic = RPCAUTH_CRED_MAGIC,
  122. #endif
  123. };