auth.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef _FS_CEPH_AUTH_H
  2. #define _FS_CEPH_AUTH_H
  3. #include "types.h"
  4. #include "buffer.h"
  5. /*
  6. * Abstract interface for communicating with the authenticate module.
  7. * There is some handshake that takes place between us and the monitor
  8. * to acquire the necessary keys. These are used to generate an
  9. * 'authorizer' that we use when connecting to a service (mds, osd).
  10. */
  11. struct ceph_auth_client;
  12. struct ceph_authorizer;
  13. struct ceph_auth_client_ops {
  14. /*
  15. * true if we are authenticated and can connect to
  16. * services.
  17. */
  18. int (*is_authenticated)(struct ceph_auth_client *ac);
  19. /*
  20. * build requests and process replies during monitor
  21. * handshake. if handle_reply returns -EAGAIN, we build
  22. * another request.
  23. */
  24. int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
  25. int (*handle_reply)(struct ceph_auth_client *ac, int result,
  26. void *buf, void *end);
  27. /*
  28. * Create authorizer for connecting to a service, and verify
  29. * the response to authenticate the service.
  30. */
  31. int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
  32. struct ceph_authorizer **a,
  33. void **buf, size_t *len,
  34. void **reply_buf, size_t *reply_len);
  35. int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
  36. struct ceph_authorizer *a, size_t len);
  37. void (*destroy_authorizer)(struct ceph_auth_client *ac,
  38. struct ceph_authorizer *a);
  39. void (*invalidate_authorizer)(struct ceph_auth_client *ac,
  40. int peer_type);
  41. /* reset when we (re)connect to a monitor */
  42. void (*reset)(struct ceph_auth_client *ac);
  43. void (*destroy)(struct ceph_auth_client *ac);
  44. };
  45. struct ceph_auth_client {
  46. u32 protocol; /* CEPH_AUTH_* */
  47. void *private; /* for use by protocol implementation */
  48. const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
  49. bool negotiating; /* true if negotiating protocol */
  50. const char *name; /* entity name */
  51. u64 global_id; /* our unique id in system */
  52. const char *secret; /* our secret key */
  53. unsigned want_keys; /* which services we want */
  54. };
  55. extern struct ceph_auth_client *ceph_auth_init(const char *name,
  56. const char *secret);
  57. extern void ceph_auth_destroy(struct ceph_auth_client *ac);
  58. extern void ceph_auth_reset(struct ceph_auth_client *ac);
  59. extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
  60. void *buf, size_t len);
  61. extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
  62. void *buf, size_t len,
  63. void *reply_buf, size_t reply_len);
  64. extern int ceph_entity_name_encode(const char *name, void **p, void *end);
  65. extern int ceph_build_auth(struct ceph_auth_client *ac,
  66. void *msg_buf, size_t msg_len);
  67. extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
  68. #endif