auth_none.c 2.6 KB

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