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