auth_null.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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/utsname.h>
  11. #include <linux/sunrpc/clnt.h>
  12. #ifdef RPC_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(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
  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. return get_rpccred(&null_cred);
  34. }
  35. /*
  36. * Destroy cred handle.
  37. */
  38. static void
  39. nul_destroy_cred(struct rpc_cred *cred)
  40. {
  41. }
  42. /*
  43. * Match cred handle against current process
  44. */
  45. static int
  46. nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags)
  47. {
  48. return 1;
  49. }
  50. /*
  51. * Marshal credential.
  52. */
  53. static __be32 *
  54. nul_marshal(struct rpc_task *task, __be32 *p)
  55. {
  56. *p++ = htonl(RPC_AUTH_NULL);
  57. *p++ = 0;
  58. *p++ = htonl(RPC_AUTH_NULL);
  59. *p++ = 0;
  60. return p;
  61. }
  62. /*
  63. * Refresh credential. This is a no-op for AUTH_NULL
  64. */
  65. static int
  66. nul_refresh(struct rpc_task *task)
  67. {
  68. task->tk_msg.rpc_cred->cr_flags |= RPCAUTH_CRED_UPTODATE;
  69. return 0;
  70. }
  71. static __be32 *
  72. nul_validate(struct rpc_task *task, __be32 *p)
  73. {
  74. rpc_authflavor_t flavor;
  75. u32 size;
  76. flavor = ntohl(*p++);
  77. if (flavor != RPC_AUTH_NULL) {
  78. printk("RPC: bad verf flavor: %u\n", flavor);
  79. return NULL;
  80. }
  81. size = ntohl(*p++);
  82. if (size != 0) {
  83. printk("RPC: bad verf size: %u\n", size);
  84. return NULL;
  85. }
  86. return p;
  87. }
  88. struct rpc_authops authnull_ops = {
  89. .owner = THIS_MODULE,
  90. .au_flavor = RPC_AUTH_NULL,
  91. #ifdef RPC_DEBUG
  92. .au_name = "NULL",
  93. #endif
  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 = 4,
  101. .au_rslack = 2,
  102. .au_ops = &authnull_ops,
  103. .au_flavor = RPC_AUTH_NULL,
  104. .au_count = ATOMIC_INIT(0),
  105. };
  106. static
  107. struct rpc_credops null_credops = {
  108. .cr_name = "AUTH_NULL",
  109. .crdestroy = nul_destroy_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_ops = &null_credops,
  118. .cr_count = ATOMIC_INIT(1),
  119. .cr_flags = RPCAUTH_CRED_UPTODATE,
  120. #ifdef RPC_DEBUG
  121. .cr_magic = RPCAUTH_CRED_MAGIC,
  122. #endif
  123. };