Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 1 | #ifndef _FS_CEPH_AUTH_H |
| 2 | #define _FS_CEPH_AUTH_H |
| 3 | |
Yehuda Sadeh | 3d14c5d | 2010-04-06 15:14:15 -0700 | [diff] [blame] | 4 | #include <linux/ceph/types.h> |
| 5 | #include <linux/ceph/buffer.h> |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 6 | |
| 7 | /* |
| 8 | * Abstract interface for communicating with the authenticate module. |
| 9 | * There is some handshake that takes place between us and the monitor |
| 10 | * to acquire the necessary keys. These are used to generate an |
| 11 | * 'authorizer' that we use when connecting to a service (mds, osd). |
| 12 | */ |
| 13 | |
| 14 | struct ceph_auth_client; |
| 15 | struct ceph_authorizer; |
| 16 | |
Alex Elder | 6c4a191 | 2012-05-16 15:16:38 -0500 | [diff] [blame] | 17 | struct ceph_auth_handshake { |
| 18 | struct ceph_authorizer *authorizer; |
| 19 | void *authorizer_buf; |
| 20 | size_t authorizer_buf_len; |
| 21 | void *authorizer_reply_buf; |
| 22 | size_t authorizer_reply_buf_len; |
| 23 | }; |
| 24 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 25 | struct ceph_auth_client_ops { |
Sage Weil | 559c1e0 | 2010-05-14 09:55:18 -0700 | [diff] [blame] | 26 | const char *name; |
| 27 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 28 | /* |
| 29 | * true if we are authenticated and can connect to |
| 30 | * services. |
| 31 | */ |
| 32 | int (*is_authenticated)(struct ceph_auth_client *ac); |
| 33 | |
| 34 | /* |
Sage Weil | a41359f | 2010-05-25 15:39:06 -0700 | [diff] [blame] | 35 | * true if we should (re)authenticate, e.g., when our tickets |
| 36 | * are getting old and crusty. |
| 37 | */ |
| 38 | int (*should_authenticate)(struct ceph_auth_client *ac); |
| 39 | |
| 40 | /* |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 41 | * build requests and process replies during monitor |
| 42 | * handshake. if handle_reply returns -EAGAIN, we build |
| 43 | * another request. |
| 44 | */ |
| 45 | int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end); |
| 46 | int (*handle_reply)(struct ceph_auth_client *ac, int result, |
| 47 | void *buf, void *end); |
| 48 | |
| 49 | /* |
| 50 | * Create authorizer for connecting to a service, and verify |
| 51 | * the response to authenticate the service. |
| 52 | */ |
| 53 | int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type, |
Alex Elder | 74f1869 | 2012-05-16 15:16:39 -0500 | [diff] [blame] | 54 | struct ceph_auth_handshake *auth); |
Sage Weil | 0bed9b5 | 2013-03-25 10:26:01 -0700 | [diff] [blame] | 55 | /* ensure that an existing authorizer is up to date */ |
| 56 | int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type, |
| 57 | struct ceph_auth_handshake *auth); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 58 | int (*verify_authorizer_reply)(struct ceph_auth_client *ac, |
| 59 | struct ceph_authorizer *a, size_t len); |
| 60 | void (*destroy_authorizer)(struct ceph_auth_client *ac, |
| 61 | struct ceph_authorizer *a); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 62 | void (*invalidate_authorizer)(struct ceph_auth_client *ac, |
| 63 | int peer_type); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 64 | |
| 65 | /* reset when we (re)connect to a monitor */ |
| 66 | void (*reset)(struct ceph_auth_client *ac); |
| 67 | |
| 68 | void (*destroy)(struct ceph_auth_client *ac); |
| 69 | }; |
| 70 | |
| 71 | struct ceph_auth_client { |
| 72 | u32 protocol; /* CEPH_AUTH_* */ |
| 73 | void *private; /* for use by protocol implementation */ |
| 74 | const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */ |
| 75 | |
| 76 | bool negotiating; /* true if negotiating protocol */ |
| 77 | const char *name; /* entity name */ |
| 78 | u64 global_id; /* our unique id in system */ |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 79 | const struct ceph_crypto_key *key; /* our secret key */ |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 80 | unsigned want_keys; /* which services we want */ |
Sage Weil | e996607 | 2013-03-25 10:26:30 -0700 | [diff] [blame] | 81 | |
| 82 | struct mutex mutex; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | extern struct ceph_auth_client *ceph_auth_init(const char *name, |
Tommi Virtanen | 8323c3a | 2011-03-25 16:32:57 -0700 | [diff] [blame] | 86 | const struct ceph_crypto_key *key); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 87 | extern void ceph_auth_destroy(struct ceph_auth_client *ac); |
| 88 | |
| 89 | extern void ceph_auth_reset(struct ceph_auth_client *ac); |
| 90 | |
| 91 | extern int ceph_auth_build_hello(struct ceph_auth_client *ac, |
| 92 | void *buf, size_t len); |
| 93 | extern int ceph_handle_auth_reply(struct ceph_auth_client *ac, |
| 94 | void *buf, size_t len, |
| 95 | void *reply_buf, size_t reply_len); |
| 96 | extern int ceph_entity_name_encode(const char *name, void **p, void *end); |
| 97 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 98 | extern int ceph_build_auth(struct ceph_auth_client *ac, |
| 99 | void *msg_buf, size_t msg_len); |
| 100 | |
| 101 | extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac); |
Sage Weil | 27859f9 | 2013-03-25 10:26:14 -0700 | [diff] [blame] | 102 | extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac, |
| 103 | int peer_type, |
| 104 | struct ceph_auth_handshake *auth); |
| 105 | extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac, |
| 106 | struct ceph_authorizer *a); |
| 107 | extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac, |
| 108 | int peer_type, |
| 109 | struct ceph_auth_handshake *a); |
| 110 | extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac, |
| 111 | struct ceph_authorizer *a, |
| 112 | size_t len); |
| 113 | extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, |
| 114 | int peer_type); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 115 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 116 | #endif |