auth_none.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_auth_handshake *auth)
  49. {
  50. struct ceph_auth_none_info *ai = ac->private;
  51. struct ceph_none_authorizer *au = &ai->au;
  52. void *p, *end;
  53. int ret;
  54. if (!ai->built_authorizer) {
  55. p = au->buf;
  56. end = p + sizeof(au->buf);
  57. ceph_encode_8(&p, 1);
  58. ret = ceph_entity_name_encode(ac->name, &p, end - 8);
  59. if (ret < 0)
  60. goto bad;
  61. ceph_decode_need(&p, end, sizeof(u64), bad2);
  62. ceph_encode_64(&p, ac->global_id);
  63. au->buf_len = p - (void *)au->buf;
  64. ai->built_authorizer = true;
  65. dout("built authorizer len %d\n", au->buf_len);
  66. }
  67. auth->authorizer = (struct ceph_authorizer *) au;
  68. auth->authorizer_buf = au->buf;
  69. auth->authorizer_buf_len = au->buf_len;
  70. auth->authorizer_reply_buf = au->reply_buf;
  71. auth->authorizer_reply_buf_len = sizeof (au->reply_buf);
  72. return 0;
  73. bad2:
  74. ret = -ERANGE;
  75. bad:
  76. return ret;
  77. }
  78. static void ceph_auth_none_destroy_authorizer(struct ceph_auth_client *ac,
  79. struct ceph_authorizer *a)
  80. {
  81. /* nothing to do */
  82. }
  83. static const struct ceph_auth_client_ops ceph_auth_none_ops = {
  84. .name = "none",
  85. .reset = reset,
  86. .destroy = destroy,
  87. .is_authenticated = is_authenticated,
  88. .should_authenticate = should_authenticate,
  89. .handle_reply = handle_reply,
  90. .create_authorizer = ceph_auth_none_create_authorizer,
  91. .destroy_authorizer = ceph_auth_none_destroy_authorizer,
  92. };
  93. int ceph_auth_none_init(struct ceph_auth_client *ac)
  94. {
  95. struct ceph_auth_none_info *xi;
  96. dout("ceph_auth_none_init %p\n", ac);
  97. xi = kzalloc(sizeof(*xi), GFP_NOFS);
  98. if (!xi)
  99. return -ENOMEM;
  100. xi->starting = true;
  101. xi->built_authorizer = false;
  102. ac->protocol = CEPH_AUTH_NONE;
  103. ac->private = xi;
  104. ac->ops = &ceph_auth_none_ops;
  105. return 0;
  106. }