auth.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. const char *name;
  15. /*
  16. * true if we are authenticated and can connect to
  17. * services.
  18. */
  19. int (*is_authenticated)(struct ceph_auth_client *ac);
  20. /*
  21. * build requests and process replies during monitor
  22. * handshake. if handle_reply returns -EAGAIN, we build
  23. * another request.
  24. */
  25. int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
  26. int (*handle_reply)(struct ceph_auth_client *ac, int result,
  27. void *buf, void *end);
  28. /*
  29. * Create authorizer for connecting to a service, and verify
  30. * the response to authenticate the service.
  31. */
  32. int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
  33. struct ceph_authorizer **a,
  34. void **buf, size_t *len,
  35. void **reply_buf, size_t *reply_len);
  36. int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
  37. struct ceph_authorizer *a, size_t len);
  38. void (*destroy_authorizer)(struct ceph_auth_client *ac,
  39. struct ceph_authorizer *a);
  40. void (*invalidate_authorizer)(struct ceph_auth_client *ac,
  41. int peer_type);
  42. /* reset when we (re)connect to a monitor */
  43. void (*reset)(struct ceph_auth_client *ac);
  44. void (*destroy)(struct ceph_auth_client *ac);
  45. };
  46. struct ceph_auth_client {
  47. u32 protocol; /* CEPH_AUTH_* */
  48. void *private; /* for use by protocol implementation */
  49. const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
  50. bool negotiating; /* true if negotiating protocol */
  51. const char *name; /* entity name */
  52. u64 global_id; /* our unique id in system */
  53. const char *secret; /* our secret key */
  54. unsigned want_keys; /* which services we want */
  55. };
  56. extern struct ceph_auth_client *ceph_auth_init(const char *name,
  57. const char *secret);
  58. extern void ceph_auth_destroy(struct ceph_auth_client *ac);
  59. extern void ceph_auth_reset(struct ceph_auth_client *ac);
  60. extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
  61. void *buf, size_t len);
  62. extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
  63. void *buf, size_t len,
  64. void *reply_buf, size_t reply_len);
  65. extern int ceph_entity_name_encode(const char *name, void **p, void *end);
  66. extern int ceph_build_auth(struct ceph_auth_client *ac,
  67. void *msg_buf, size_t msg_len);
  68. extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
  69. #endif