0001
0002
0003 #include <linux/ceph/ceph_debug.h>
0004
0005 #include <linux/err.h>
0006 #include <linux/module.h>
0007 #include <linux/random.h>
0008 #include <linux/slab.h>
0009
0010 #include <linux/ceph/decode.h>
0011 #include <linux/ceph/auth.h>
0012
0013 #include "auth_none.h"
0014
0015 static void reset(struct ceph_auth_client *ac)
0016 {
0017 struct ceph_auth_none_info *xi = ac->private;
0018
0019 xi->starting = true;
0020 }
0021
0022 static void destroy(struct ceph_auth_client *ac)
0023 {
0024 kfree(ac->private);
0025 ac->private = NULL;
0026 }
0027
0028 static int is_authenticated(struct ceph_auth_client *ac)
0029 {
0030 struct ceph_auth_none_info *xi = ac->private;
0031
0032 return !xi->starting;
0033 }
0034
0035 static int should_authenticate(struct ceph_auth_client *ac)
0036 {
0037 struct ceph_auth_none_info *xi = ac->private;
0038
0039 return xi->starting;
0040 }
0041
0042 static int ceph_auth_none_build_authorizer(struct ceph_auth_client *ac,
0043 struct ceph_none_authorizer *au)
0044 {
0045 void *p = au->buf;
0046 void *const end = p + sizeof(au->buf);
0047 int ret;
0048
0049 ceph_encode_8_safe(&p, end, 1, e_range);
0050 ret = ceph_auth_entity_name_encode(ac->name, &p, end);
0051 if (ret < 0)
0052 return ret;
0053
0054 ceph_encode_64_safe(&p, end, ac->global_id, e_range);
0055 au->buf_len = p - (void *)au->buf;
0056 dout("%s built authorizer len %d\n", __func__, au->buf_len);
0057 return 0;
0058
0059 e_range:
0060 return -ERANGE;
0061 }
0062
0063 static int build_request(struct ceph_auth_client *ac, void *buf, void *end)
0064 {
0065 return 0;
0066 }
0067
0068
0069
0070
0071
0072 static int handle_reply(struct ceph_auth_client *ac, u64 global_id,
0073 void *buf, void *end, u8 *session_key,
0074 int *session_key_len, u8 *con_secret,
0075 int *con_secret_len)
0076 {
0077 struct ceph_auth_none_info *xi = ac->private;
0078
0079 xi->starting = false;
0080 ceph_auth_set_global_id(ac, global_id);
0081 return 0;
0082 }
0083
0084 static void ceph_auth_none_destroy_authorizer(struct ceph_authorizer *a)
0085 {
0086 kfree(a);
0087 }
0088
0089
0090
0091
0092
0093 static int ceph_auth_none_create_authorizer(
0094 struct ceph_auth_client *ac, int peer_type,
0095 struct ceph_auth_handshake *auth)
0096 {
0097 struct ceph_none_authorizer *au;
0098 int ret;
0099
0100 au = kmalloc(sizeof(*au), GFP_NOFS);
0101 if (!au)
0102 return -ENOMEM;
0103
0104 au->base.destroy = ceph_auth_none_destroy_authorizer;
0105
0106 ret = ceph_auth_none_build_authorizer(ac, au);
0107 if (ret) {
0108 kfree(au);
0109 return ret;
0110 }
0111
0112 auth->authorizer = (struct ceph_authorizer *) au;
0113 auth->authorizer_buf = au->buf;
0114 auth->authorizer_buf_len = au->buf_len;
0115 auth->authorizer_reply_buf = NULL;
0116 auth->authorizer_reply_buf_len = 0;
0117
0118 return 0;
0119 }
0120
0121 static const struct ceph_auth_client_ops ceph_auth_none_ops = {
0122 .reset = reset,
0123 .destroy = destroy,
0124 .is_authenticated = is_authenticated,
0125 .should_authenticate = should_authenticate,
0126 .build_request = build_request,
0127 .handle_reply = handle_reply,
0128 .create_authorizer = ceph_auth_none_create_authorizer,
0129 };
0130
0131 int ceph_auth_none_init(struct ceph_auth_client *ac)
0132 {
0133 struct ceph_auth_none_info *xi;
0134
0135 dout("ceph_auth_none_init %p\n", ac);
0136 xi = kzalloc(sizeof(*xi), GFP_NOFS);
0137 if (!xi)
0138 return -ENOMEM;
0139
0140 xi->starting = true;
0141
0142 ac->protocol = CEPH_AUTH_NONE;
0143 ac->private = xi;
0144 ac->ops = &ceph_auth_none_ops;
0145 return 0;
0146 }