auth.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /* ensure that an existing authorizer is up to date */
  47. int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
  48. struct ceph_auth_handshake *auth);
  49. int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
  50. struct ceph_authorizer *a, size_t len);
  51. void (*destroy_authorizer)(struct ceph_auth_client *ac,
  52. struct ceph_authorizer *a);
  53. void (*invalidate_authorizer)(struct ceph_auth_client *ac,
  54. int peer_type);
  55. /* reset when we (re)connect to a monitor */
  56. void (*reset)(struct ceph_auth_client *ac);
  57. void (*destroy)(struct ceph_auth_client *ac);
  58. };
  59. struct ceph_auth_client {
  60. u32 protocol; /* CEPH_AUTH_* */
  61. void *private; /* for use by protocol implementation */
  62. const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
  63. bool negotiating; /* true if negotiating protocol */
  64. const char *name; /* entity name */
  65. u64 global_id; /* our unique id in system */
  66. const struct ceph_crypto_key *key; /* our secret key */
  67. unsigned want_keys; /* which services we want */
  68. struct mutex mutex;
  69. };
  70. extern struct ceph_auth_client *ceph_auth_init(const char *name,
  71. const struct ceph_crypto_key *key);
  72. extern void ceph_auth_destroy(struct ceph_auth_client *ac);
  73. extern void ceph_auth_reset(struct ceph_auth_client *ac);
  74. extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
  75. void *buf, size_t len);
  76. extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
  77. void *buf, size_t len,
  78. void *reply_buf, size_t reply_len);
  79. extern int ceph_entity_name_encode(const char *name, void **p, void *end);
  80. extern int ceph_build_auth(struct ceph_auth_client *ac,
  81. void *msg_buf, size_t msg_len);
  82. extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
  83. extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
  84. int peer_type,
  85. struct ceph_auth_handshake *auth);
  86. extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac,
  87. struct ceph_authorizer *a);
  88. extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
  89. int peer_type,
  90. struct ceph_auth_handshake *a);
  91. extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
  92. struct ceph_authorizer *a,
  93. size_t len);
  94. extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,
  95. int peer_type);
  96. #endif