auth_none.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /*
  31. * the generic auth code decode the global_id, and we carry no actual
  32. * authenticate state, so nothing happens here.
  33. */
  34. static int handle_reply(struct ceph_auth_client *ac, int result,
  35. void *buf, void *end)
  36. {
  37. struct ceph_auth_none_info *xi = ac->private;
  38. xi->starting = false;
  39. return result;
  40. }
  41. /*
  42. * build an 'authorizer' with our entity_name and global_id. we can
  43. * reuse a single static copy since it is identical for all services
  44. * we connect to.
  45. */
  46. static int ceph_auth_none_create_authorizer(
  47. struct ceph_auth_client *ac, int peer_type,
  48. struct ceph_authorizer **a,
  49. void **buf, size_t *len,
  50. void **reply_buf, size_t *reply_len)
  51. {
  52. struct ceph_auth_none_info *ai = ac->private;
  53. struct ceph_none_authorizer *au = &ai->au;
  54. void *p, *end;
  55. int ret;
  56. if (!ai->built_authorizer) {
  57. p = au->buf;
  58. end = p + sizeof(au->buf);
  59. ceph_encode_8(&p, 1);
  60. ret = ceph_entity_name_encode(ac->name, &p, end - 8);
  61. if (ret < 0)
  62. goto bad;
  63. ceph_decode_need(&p, end, sizeof(u64), bad2);
  64. ceph_encode_64(&p, ac->global_id);
  65. au->buf_len = p - (void *)au->buf;
  66. ai->built_authorizer = true;
  67. dout("built authorizer len %d\n", au->buf_len);
  68. }
  69. *a = (struct ceph_authorizer *)au;
  70. *buf = au->buf;
  71. *len = au->buf_len;
  72. *reply_buf = au->reply_buf;
  73. *reply_len = sizeof(au->reply_buf);
  74. return 0;
  75. bad2:
  76. ret = -ERANGE;
  77. bad:
  78. return ret;
  79. }
  80. static void ceph_auth_none_destroy_authorizer(struct ceph_auth_client *ac,
  81. struct ceph_authorizer *a)
  82. {
  83. /* nothing to do */
  84. }
  85. static const struct ceph_auth_client_ops ceph_auth_none_ops = {
  86. .name = "none",
  87. .reset = reset,
  88. .destroy = destroy,
  89. .is_authenticated = is_authenticated,
  90. .should_authenticate = should_authenticate,
  91. .handle_reply = handle_reply,
  92. .create_authorizer = ceph_auth_none_create_authorizer,
  93. .destroy_authorizer = ceph_auth_none_destroy_authorizer,
  94. };
  95. int ceph_auth_none_init(struct ceph_auth_client *ac)
  96. {
  97. struct ceph_auth_none_info *xi;
  98. dout("ceph_auth_none_init %p\n", ac);
  99. xi = kzalloc(sizeof(*xi), GFP_NOFS);
  100. if (!xi)
  101. return -ENOMEM;
  102. xi->starting = true;
  103. xi->built_authorizer = false;
  104. ac->protocol = CEPH_AUTH_NONE;
  105. ac->private = xi;
  106. ac->ops = &ceph_auth_none_ops;
  107. return 0;
  108. }