blob: 5b774d141e0969d56560b175c39c689ccc0b0a80 [file] [log] [blame]
Sage Weil4e7a5dc2009-11-18 16:19:57 -08001#ifndef _FS_CEPH_AUTH_H
2#define _FS_CEPH_AUTH_H
3
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07004#include <linux/ceph/types.h>
5#include <linux/ceph/buffer.h>
Sage Weil4e7a5dc2009-11-18 16:19:57 -08006
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
14struct ceph_auth_client;
15struct ceph_authorizer;
16
Alex Elder6c4a1912012-05-16 15:16:38 -050017struct 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 Weil4e7a5dc2009-11-18 16:19:57 -080025struct ceph_auth_client_ops {
Sage Weil559c1e02010-05-14 09:55:18 -070026 const char *name;
27
Sage Weil4e7a5dc2009-11-18 16:19:57 -080028 /*
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 Weila41359f2010-05-25 15:39:06 -070035 * 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 Weil4e7a5dc2009-11-18 16:19:57 -080041 * 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,
54 struct ceph_authorizer **a,
55 void **buf, size_t *len,
56 void **reply_buf, size_t *reply_len);
57 int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
58 struct ceph_authorizer *a, size_t len);
59 void (*destroy_authorizer)(struct ceph_auth_client *ac,
60 struct ceph_authorizer *a);
Sage Weil9bd2e6f2010-02-02 16:21:06 -080061 void (*invalidate_authorizer)(struct ceph_auth_client *ac,
62 int peer_type);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080063
64 /* reset when we (re)connect to a monitor */
65 void (*reset)(struct ceph_auth_client *ac);
66
67 void (*destroy)(struct ceph_auth_client *ac);
68};
69
70struct ceph_auth_client {
71 u32 protocol; /* CEPH_AUTH_* */
72 void *private; /* for use by protocol implementation */
73 const struct ceph_auth_client_ops *ops; /* null iff protocol==0 */
74
75 bool negotiating; /* true if negotiating protocol */
76 const char *name; /* entity name */
77 u64 global_id; /* our unique id in system */
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070078 const struct ceph_crypto_key *key; /* our secret key */
Sage Weil4e7a5dc2009-11-18 16:19:57 -080079 unsigned want_keys; /* which services we want */
80};
81
82extern struct ceph_auth_client *ceph_auth_init(const char *name,
Tommi Virtanen8323c3a2011-03-25 16:32:57 -070083 const struct ceph_crypto_key *key);
Sage Weil4e7a5dc2009-11-18 16:19:57 -080084extern void ceph_auth_destroy(struct ceph_auth_client *ac);
85
86extern void ceph_auth_reset(struct ceph_auth_client *ac);
87
88extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
89 void *buf, size_t len);
90extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
91 void *buf, size_t len,
92 void *reply_buf, size_t reply_len);
93extern int ceph_entity_name_encode(const char *name, void **p, void *end);
94
Sage Weil9bd2e6f2010-02-02 16:21:06 -080095extern int ceph_build_auth(struct ceph_auth_client *ac,
96 void *msg_buf, size_t msg_len);
97
98extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
99
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800100#endif