auth.h 3.1 KB

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