auth_none.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include <linux/ceph/ceph_debug.h>
  2. #include <linux/err.h>
  3. #include <linux/module.h>
  4. #include <linux/random.h>
  5. #include <linux/slab.h>
  6. #include <linux/ceph/decode.h>
  7. #include <linux/ceph/auth.h>
  8. #include "auth_none.h"
  9. static void reset(struct ceph_auth_client *ac)
  10. {
  11. struct ceph_auth_none_info *xi = ac->private;
  12. xi->starting = true;
  13. xi->built_authorizer = false;
  14. }
  15. static void destroy(struct ceph_auth_client *ac)
  16. {
  17. kfree(ac->private);
  18. ac->private = NULL;
  19. }
  20. static int is_authenticated(struct ceph_auth_client *ac)
  21. {
  22. struct ceph_auth_none_info *xi = ac->private;
  23. return !xi->starting;
  24. }
  25. static int should_authenticate(struct ceph_auth_client *ac)
  26. {
  27. struct ceph_auth_none_info *xi = ac->private;
  28. return xi->starting;
  29. }
  30. static int build_request(struct ceph_auth_client *ac, void *buf, void *end)
  31. {
  32. return 0;
  33. }
  34. /*
  35. * the generic auth code decode the global_id, and we carry no actual
  36. * authenticate state, so nothing happens here.
  37. */
  38. static int handle_reply(struct ceph_auth_client *ac, int result,
  39. void *buf, void *end)
  40. {
  41. struct ceph_auth_none_info *xi = ac->private;
  42. xi->starting = false;
  43. return result;
  44. }
  45. /*
  46. * build an 'authorizer' with our entity_name and global_id. we can
  47. * reuse a single static copy since it is identical for all services
  48. * we connect to.
  49. */
  50. static int ceph_auth_none_create_authorizer(
  51. struct ceph_auth_client *ac, int peer_type,
  52. struct ceph_auth_handshake *auth)
  53. {
  54. struct ceph_auth_none_info *ai = ac->private;
  55. struct ceph_none_authorizer *au = &ai->au;
  56. void *p, *end;
  57. int ret;
  58. if (!ai->built_authorizer) {
  59. p = au->buf;
  60. end = p + sizeof(au->buf);
  61. ceph_encode_8(&p, 1);
  62. ret = ceph_entity_name_encode(ac->name, &p, end - 8);
  63. if (ret < 0)
  64. goto bad;
  65. ceph_decode_need(&p, end, sizeof(u64), bad2);
  66. ceph_encode_64(&p, ac->global_id);
  67. au->buf_len = p - (void *)au->buf;
  68. ai->built_authorizer = true;
  69. dout("built authorizer len %d\n", au->buf_len);
  70. }
  71. auth->authorizer = (struct ceph_authorizer *) au;
  72. auth->authorizer_buf = au->buf;
  73. auth->authorizer_buf_len = au->buf_len;
  74. auth->authorizer_reply_buf = au->reply_buf;
  75. auth->authorizer_reply_buf_len = sizeof (au->reply_buf);
  76. return 0;
  77. bad2:
  78. ret = -ERANGE;
  79. bad:
  80. return ret;
  81. }
  82. static void ceph_auth_none_destroy_authorizer(struct ceph_auth_client *ac,
  83. struct ceph_authorizer *a)
  84. {
  85. /* nothing to do */
  86. }
  87. static const struct ceph_auth_client_ops ceph_auth_none_ops = {
  88. .name = "none",
  89. .reset = reset,
  90. .destroy = destroy,
  91. .is_authenticated = is_authenticated,
  92. .should_authenticate = should_authenticate,
  93. .build_request = build_request,
  94. .handle_reply = handle_reply,
  95. .create_authorizer = ceph_auth_none_create_authorizer,
  96. .destroy_authorizer = ceph_auth_none_destroy_authorizer,
  97. };
  98. int ceph_auth_none_init(struct ceph_auth_client *ac)
  99. {
  100. struct ceph_auth_none_info *xi;
  101. dout("ceph_auth_none_init %p\n", ac);
  102. xi = kzalloc(sizeof(*xi), GFP_NOFS);
  103. if (!xi)
  104. return -ENOMEM;
  105. xi->starting = true;
  106. xi->built_authorizer = false;
  107. ac->protocol = CEPH_AUTH_NONE;
  108. ac->private = xi;
  109. ac->ops = &ceph_auth_none_ops;
  110. return 0;
  111. }