Linux-libre 3.16.85-gnu
[librecmc/linux-libre.git] / include / linux / ceph / auth.h
1 #ifndef _FS_CEPH_AUTH_H
2 #define _FS_CEPH_AUTH_H
3
4 #include <linux/ceph/types.h>
5 #include <linux/ceph/buffer.h>
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
16 struct ceph_authorizer {
17         void (*destroy)(struct ceph_authorizer *);
18 };
19
20 struct ceph_auth_handshake {
21         struct ceph_authorizer *authorizer;
22         void *authorizer_buf;
23         size_t authorizer_buf_len;
24         void *authorizer_reply_buf;
25         size_t authorizer_reply_buf_len;
26 };
27
28 struct ceph_auth_client_ops {
29         const char *name;
30
31         /*
32          * true if we are authenticated and can connect to
33          * services.
34          */
35         int (*is_authenticated)(struct ceph_auth_client *ac);
36
37         /*
38          * true if we should (re)authenticate, e.g., when our tickets
39          * are getting old and crusty.
40          */
41         int (*should_authenticate)(struct ceph_auth_client *ac);
42
43         /*
44          * build requests and process replies during monitor
45          * handshake.  if handle_reply returns -EAGAIN, we build
46          * another request.
47          */
48         int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
49         int (*handle_reply)(struct ceph_auth_client *ac, int result,
50                             void *buf, void *end);
51
52         /*
53          * Create authorizer for connecting to a service, and verify
54          * the response to authenticate the service.
55          */
56         int (*create_authorizer)(struct ceph_auth_client *ac, int peer_type,
57                                  struct ceph_auth_handshake *auth);
58         /* ensure that an existing authorizer is up to date */
59         int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
60                                  struct ceph_auth_handshake *auth);
61         int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
62                                        struct ceph_authorizer *a, size_t len);
63         void (*invalidate_authorizer)(struct ceph_auth_client *ac,
64                                       int peer_type);
65
66         /* reset when we (re)connect to a monitor */
67         void (*reset)(struct ceph_auth_client *ac);
68
69         void (*destroy)(struct ceph_auth_client *ac);
70 };
71
72 struct ceph_auth_client {
73         u32 protocol;           /* CEPH_AUTH_* */
74         void *private;          /* for use by protocol implementation */
75         const struct ceph_auth_client_ops *ops;  /* null iff protocol==0 */
76
77         bool negotiating;       /* true if negotiating protocol */
78         const char *name;       /* entity name */
79         u64 global_id;          /* our unique id in system */
80         const struct ceph_crypto_key *key;     /* our secret key */
81         unsigned want_keys;     /* which services we want */
82
83         struct mutex mutex;
84 };
85
86 extern struct ceph_auth_client *ceph_auth_init(const char *name,
87                                                const struct ceph_crypto_key *key);
88 extern void ceph_auth_destroy(struct ceph_auth_client *ac);
89
90 extern void ceph_auth_reset(struct ceph_auth_client *ac);
91
92 extern int ceph_auth_build_hello(struct ceph_auth_client *ac,
93                                  void *buf, size_t len);
94 extern int ceph_handle_auth_reply(struct ceph_auth_client *ac,
95                                   void *buf, size_t len,
96                                   void *reply_buf, size_t reply_len);
97 extern int ceph_entity_name_encode(const char *name, void **p, void *end);
98
99 extern int ceph_build_auth(struct ceph_auth_client *ac,
100                     void *msg_buf, size_t msg_len);
101
102 extern int ceph_auth_is_authenticated(struct ceph_auth_client *ac);
103 extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
104                                        int peer_type,
105                                        struct ceph_auth_handshake *auth);
106 void ceph_auth_destroy_authorizer(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);
115
116 #endif