auth_none.c 2.6 KB

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