auth_none.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. }
  14. static void destroy(struct ceph_auth_client *ac)
  15. {
  16. kfree(ac->private);
  17. ac->private = NULL;
  18. }
  19. static int is_authenticated(struct ceph_auth_client *ac)
  20. {
  21. struct ceph_auth_none_info *xi = ac->private;
  22. return !xi->starting;
  23. }
  24. static int should_authenticate(struct ceph_auth_client *ac)
  25. {
  26. struct ceph_auth_none_info *xi = ac->private;
  27. return xi->starting;
  28. }
  29. static int ceph_auth_none_build_authorizer(struct ceph_auth_client *ac,
  30. struct ceph_none_authorizer *au)
  31. {
  32. void *p = au->buf;
  33. void *const end = p + sizeof(au->buf);
  34. int ret;
  35. ceph_encode_8_safe(&p, end, 1, e_range);
  36. ret = ceph_auth_entity_name_encode(ac->name, &p, end);
  37. if (ret < 0)
  38. return ret;
  39. ceph_encode_64_safe(&p, end, ac->global_id, e_range);
  40. au->buf_len = p - (void *)au->buf;
  41. dout("%s built authorizer len %d\n", __func__, au->buf_len);
  42. return 0;
  43. e_range:
  44. return -ERANGE;
  45. }
  46. static int build_request(struct ceph_auth_client *ac, void *buf, void *end)
  47. {
  48. return 0;
  49. }
  50. /*
  51. * the generic auth code decode the global_id, and we carry no actual
  52. * authenticate state, so nothing happens here.
  53. */
  54. static int handle_reply(struct ceph_auth_client *ac, int result,
  55. void *buf, void *end)
  56. {
  57. struct ceph_auth_none_info *xi = ac->private;
  58. xi->starting = false;
  59. return result;
  60. }
  61. static void ceph_auth_none_destroy_authorizer(struct ceph_authorizer *a)
  62. {
  63. kfree(a);
  64. }
  65. /*
  66. * build an 'authorizer' with our entity_name and global_id. it is
  67. * identical for all services we connect to.
  68. */
  69. static int ceph_auth_none_create_authorizer(
  70. struct ceph_auth_client *ac, int peer_type,
  71. struct ceph_auth_handshake *auth)
  72. {
  73. struct ceph_none_authorizer *au;
  74. int ret;
  75. au = kmalloc(sizeof(*au), GFP_NOFS);
  76. if (!au)
  77. return -ENOMEM;
  78. au->base.destroy = ceph_auth_none_destroy_authorizer;
  79. ret = ceph_auth_none_build_authorizer(ac, au);
  80. if (ret) {
  81. kfree(au);
  82. return ret;
  83. }
  84. auth->authorizer = (struct ceph_authorizer *) au;
  85. auth->authorizer_buf = au->buf;
  86. auth->authorizer_buf_len = au->buf_len;
  87. auth->authorizer_reply_buf = au->reply_buf;
  88. auth->authorizer_reply_buf_len = sizeof (au->reply_buf);
  89. return 0;
  90. }
  91. static const struct ceph_auth_client_ops ceph_auth_none_ops = {
  92. .name = "none",
  93. .reset = reset,
  94. .destroy = destroy,
  95. .is_authenticated = is_authenticated,
  96. .should_authenticate = should_authenticate,
  97. .build_request = build_request,
  98. .handle_reply = handle_reply,
  99. .create_authorizer = ceph_auth_none_create_authorizer,
  100. };
  101. int ceph_auth_none_init(struct ceph_auth_client *ac)
  102. {
  103. struct ceph_auth_none_info *xi;
  104. dout("ceph_auth_none_init %p\n", ac);
  105. xi = kzalloc(sizeof(*xi), GFP_NOFS);
  106. if (!xi)
  107. return -ENOMEM;
  108. xi->starting = true;
  109. ac->protocol = CEPH_AUTH_NONE;
  110. ac->private = xi;
  111. ac->ops = &ceph_auth_none_ops;
  112. return 0;
  113. }