Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/ceph/ceph_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/ceph/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/ceph/decode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/ceph/libceph.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ceph/messenger.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "auth_none.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "auth_x.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * get protocol handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static u32 supported_protocols[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	CEPH_AUTH_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	CEPH_AUTH_CEPHX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int ceph_auth_init_protocol(struct ceph_auth_client *ac, int protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	switch (protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	case CEPH_AUTH_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		return ceph_auth_none_init(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	case CEPH_AUTH_CEPHX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		return ceph_x_init(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * setup, teardown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) struct ceph_auth_client *ceph_auth_init(const char *name, const struct ceph_crypto_key *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct ceph_auth_client *ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dout("auth_init name '%s'\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	ac = kzalloc(sizeof(*ac), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	mutex_init(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	ac->negotiating = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		ac->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		ac->name = CEPH_AUTH_NAME_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	dout("auth_init name %s\n", ac->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	ac->key = key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	return ac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void ceph_auth_destroy(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	dout("auth_destroy %p\n", ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (ac->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		ac->ops->destroy(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	kfree(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Reset occurs when reconnecting to the monitor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) void ceph_auth_reset(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	dout("auth_reset %p\n", ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (ac->ops && !ac->negotiating)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		ac->ops->reset(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ac->negotiating = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * EntityName, not to be confused with entity_name_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) int ceph_auth_entity_name_encode(const char *name, void **p, void *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	int len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (*p + 2*sizeof(u32) + len > end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	ceph_encode_32(p, CEPH_ENTITY_TYPE_CLIENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	ceph_encode_32(p, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	ceph_encode_copy(p, name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Initiate protocol negotiation with monitor.  Include entity name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * and list supported protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct ceph_mon_request_header *monhdr = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	void *p = monhdr + 1, *end = buf + len, *lenp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int i, num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	dout("auth_build_hello\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	monhdr->have_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	monhdr->session_mon = cpu_to_le16(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	monhdr->session_mon_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	ceph_encode_32(&p, CEPH_AUTH_UNKNOWN);  /* no protocol, yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	lenp = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	p += sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	ceph_encode_8(&p, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	num = ARRAY_SIZE(supported_protocols);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	ceph_encode_32(&p, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	ceph_decode_need(&p, end, num * sizeof(u32), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	for (i = 0; i < num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		ceph_encode_32(&p, supported_protocols[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	ret = ceph_auth_entity_name_encode(ac->name, &p, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	ceph_decode_need(&p, end, sizeof(u64), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	ceph_encode_64(&p, ac->global_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ceph_encode_32(&lenp, p - lenp - sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret = p - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int ceph_build_auth_request(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				   void *msg_buf, size_t msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct ceph_mon_request_header *monhdr = msg_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	void *p = monhdr + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	void *end = msg_buf + msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	monhdr->have_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	monhdr->session_mon = cpu_to_le16(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	monhdr->session_mon_tid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	ceph_encode_32(&p, ac->protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	ret = ac->ops->build_request(ac, p + sizeof(u32), end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		pr_err("error %d building auth method %s request\n", ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		       ac->ops->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	dout(" built request %d bytes\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	ceph_encode_32(&p, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	ret = p + ret - msg_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  * Handle auth message from monitor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int ceph_handle_auth_reply(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			   void *buf, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			   void *reply_buf, size_t reply_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	void *p = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	void *end = buf + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	s32 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	u64 global_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	void *payload, *payload_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	char *result_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	int result_msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	dout("handle_auth_reply %p %p\n", p, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	ceph_decode_need(&p, end, sizeof(u32) * 3 + sizeof(u64), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	protocol = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	result = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	global_id = ceph_decode_64(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	payload_len = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	payload = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	p += payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	ceph_decode_need(&p, end, sizeof(u32), bad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	result_msg_len = ceph_decode_32(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	result_msg = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	p += result_msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (p != end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		goto bad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	dout(" result %d '%.*s' gid %llu len %d\n", result, result_msg_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	     result_msg, global_id, payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	payload_end = payload + payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (global_id && ac->global_id != global_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		dout(" set global_id %lld -> %lld\n", ac->global_id, global_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		ac->global_id = global_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (ac->negotiating) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		/* server does not support our protocols? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (!protocol && result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			ret = result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		/* set up (new) protocol handler? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (ac->protocol && ac->protocol != protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			ac->ops->destroy(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			ac->protocol = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			ac->ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		if (ac->protocol != protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			ret = ceph_auth_init_protocol(ac, protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				pr_err("error %d on auth protocol %d init\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 				       ret, protocol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		ac->negotiating = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	ret = ac->ops->handle_reply(ac, result, payload, payload_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (ret == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		ret = ceph_build_auth_request(ac, reply_buf, reply_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	} else if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		pr_err("auth method '%s' error %d\n", ac->ops->name, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) bad:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	pr_err("failed to decode auth msg\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int ceph_build_auth(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		    void *msg_buf, size_t msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (ac->ops->should_authenticate(ac))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		ret = ceph_build_auth_request(ac, msg_buf, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int ceph_auth_is_authenticated(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (ac->ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		ret = ac->ops->is_authenticated(ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) EXPORT_SYMBOL(ceph_auth_is_authenticated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int ceph_auth_create_authorizer(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				int peer_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 				struct ceph_auth_handshake *auth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (ac->ops && ac->ops->create_authorizer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		ret = ac->ops->create_authorizer(ac, peer_type, auth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) EXPORT_SYMBOL(ceph_auth_create_authorizer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) void ceph_auth_destroy_authorizer(struct ceph_authorizer *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	a->destroy(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) EXPORT_SYMBOL(ceph_auth_destroy_authorizer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 				int peer_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 				struct ceph_auth_handshake *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (ac->ops && ac->ops->update_authorizer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		ret = ac->ops->update_authorizer(ac, peer_type, a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) EXPORT_SYMBOL(ceph_auth_update_authorizer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int ceph_auth_add_authorizer_challenge(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 				       struct ceph_authorizer *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				       void *challenge_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				       int challenge_buf_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (ac->ops && ac->ops->add_authorizer_challenge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		ret = ac->ops->add_authorizer_challenge(ac, a, challenge_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 							challenge_buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) EXPORT_SYMBOL(ceph_auth_add_authorizer_challenge);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				      struct ceph_authorizer *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (ac->ops && ac->ops->verify_authorizer_reply)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		ret = ac->ops->verify_authorizer_reply(ac, a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) EXPORT_SYMBOL(ceph_auth_verify_authorizer_reply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, int peer_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	mutex_lock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (ac->ops && ac->ops->invalidate_authorizer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		ac->ops->invalidate_authorizer(ac, peer_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	mutex_unlock(&ac->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) EXPORT_SYMBOL(ceph_auth_invalidate_authorizer);