diff options
Diffstat (limited to 'fs/ceph/auth_none.c')
-rw-r--r-- | fs/ceph/auth_none.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/fs/ceph/auth_none.c b/fs/ceph/auth_none.c new file mode 100644 index 000000000000..b4ef6f0a6c85 --- /dev/null +++ b/fs/ceph/auth_none.c | |||
@@ -0,0 +1,121 @@ | |||
1 | |||
2 | #include "ceph_debug.h" | ||
3 | |||
4 | #include <linux/err.h> | ||
5 | #include <linux/module.h> | ||
6 | #include <linux/random.h> | ||
7 | |||
8 | #include "auth_none.h" | ||
9 | #include "auth.h" | ||
10 | #include "decode.h" | ||
11 | |||
12 | static void reset(struct ceph_auth_client *ac) | ||
13 | { | ||
14 | struct ceph_auth_none_info *xi = ac->private; | ||
15 | |||
16 | xi->starting = true; | ||
17 | xi->built_authorizer = false; | ||
18 | } | ||
19 | |||
20 | static void destroy(struct ceph_auth_client *ac) | ||
21 | { | ||
22 | kfree(ac->private); | ||
23 | ac->private = NULL; | ||
24 | } | ||
25 | |||
26 | static int is_authenticated(struct ceph_auth_client *ac) | ||
27 | { | ||
28 | struct ceph_auth_none_info *xi = ac->private; | ||
29 | |||
30 | return !xi->starting; | ||
31 | } | ||
32 | |||
33 | /* | ||
34 | * the generic auth code decode the global_id, and we carry no actual | ||
35 | * authenticate state, so nothing happens here. | ||
36 | */ | ||
37 | static int handle_reply(struct ceph_auth_client *ac, int result, | ||
38 | void *buf, void *end) | ||
39 | { | ||
40 | struct ceph_auth_none_info *xi = ac->private; | ||
41 | |||
42 | xi->starting = false; | ||
43 | return result; | ||
44 | } | ||
45 | |||
46 | /* | ||
47 | * build an 'authorizer' with our entity_name and global_id. we can | ||
48 | * reuse a single static copy since it is identical for all services | ||
49 | * we connect to. | ||
50 | */ | ||
51 | static int ceph_auth_none_create_authorizer( | ||
52 | struct ceph_auth_client *ac, int peer_type, | ||
53 | struct ceph_authorizer **a, | ||
54 | void **buf, size_t *len, | ||
55 | void **reply_buf, size_t *reply_len) | ||
56 | { | ||
57 | struct ceph_auth_none_info *ai = ac->private; | ||
58 | struct ceph_none_authorizer *au = &ai->au; | ||
59 | void *p, *end; | ||
60 | int ret; | ||
61 | |||
62 | if (!ai->built_authorizer) { | ||
63 | p = au->buf; | ||
64 | end = p + sizeof(au->buf); | ||
65 | ceph_encode_8(&p, 1); | ||
66 | ret = ceph_entity_name_encode(ac->name, &p, end - 8); | ||
67 | if (ret < 0) | ||
68 | goto bad; | ||
69 | ceph_decode_need(&p, end, sizeof(u64), bad2); | ||
70 | ceph_encode_64(&p, ac->global_id); | ||
71 | au->buf_len = p - (void *)au->buf; | ||
72 | ai->built_authorizer = true; | ||
73 | dout("built authorizer len %d\n", au->buf_len); | ||
74 | } | ||
75 | |||
76 | *a = (struct ceph_authorizer *)au; | ||
77 | *buf = au->buf; | ||
78 | *len = au->buf_len; | ||
79 | *reply_buf = au->reply_buf; | ||
80 | *reply_len = sizeof(au->reply_buf); | ||
81 | return 0; | ||
82 | |||
83 | bad2: | ||
84 | ret = -ERANGE; | ||
85 | bad: | ||
86 | return ret; | ||
87 | } | ||
88 | |||
89 | static void ceph_auth_none_destroy_authorizer(struct ceph_auth_client *ac, | ||
90 | struct ceph_authorizer *a) | ||
91 | { | ||
92 | /* nothing to do */ | ||
93 | } | ||
94 | |||
95 | static const struct ceph_auth_client_ops ceph_auth_none_ops = { | ||
96 | .reset = reset, | ||
97 | .destroy = destroy, | ||
98 | .is_authenticated = is_authenticated, | ||
99 | .handle_reply = handle_reply, | ||
100 | .create_authorizer = ceph_auth_none_create_authorizer, | ||
101 | .destroy_authorizer = ceph_auth_none_destroy_authorizer, | ||
102 | }; | ||
103 | |||
104 | int ceph_auth_none_init(struct ceph_auth_client *ac) | ||
105 | { | ||
106 | struct ceph_auth_none_info *xi; | ||
107 | |||
108 | dout("ceph_auth_none_init %p\n", ac); | ||
109 | xi = kzalloc(sizeof(*xi), GFP_NOFS); | ||
110 | if (!xi) | ||
111 | return -ENOMEM; | ||
112 | |||
113 | xi->starting = true; | ||
114 | xi->built_authorizer = false; | ||
115 | |||
116 | ac->protocol = CEPH_AUTH_NONE; | ||
117 | ac->private = xi; | ||
118 | ac->ops = &ceph_auth_none_ops; | ||
119 | return 0; | ||
120 | } | ||
121 | |||