auth.h 2.9 KB

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