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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/ceph/ceph_debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/ceph/decode.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ceph/auth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "auth_none.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static void reset(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct ceph_auth_none_info *xi = ac->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	xi->starting = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void destroy(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	kfree(ac->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	ac->private = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int is_authenticated(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct ceph_auth_none_info *xi = ac->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	return !xi->starting;
^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) static int should_authenticate(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct ceph_auth_none_info *xi = ac->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	return xi->starting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static int ceph_auth_none_build_authorizer(struct ceph_auth_client *ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 					   struct ceph_none_authorizer *au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	void *p = au->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	void *const end = p + sizeof(au->buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	ceph_encode_8_safe(&p, end, 1, e_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	ret = ceph_auth_entity_name_encode(ac->name, &p, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	ceph_encode_64_safe(&p, end, ac->global_id, e_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	au->buf_len = p - (void *)au->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	dout("%s built authorizer len %d\n", __func__, au->buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) e_range:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int build_request(struct ceph_auth_client *ac, void *buf, void *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * the generic auth code decode the global_id, and we carry no actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * authenticate state, so nothing happens here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int handle_reply(struct ceph_auth_client *ac, int result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			void *buf, void *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct ceph_auth_none_info *xi = ac->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	xi->starting = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static void ceph_auth_none_destroy_authorizer(struct ceph_authorizer *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	kfree(a);
^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)  * build an 'authorizer' with our entity_name and global_id.  it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * identical for all services we connect to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int ceph_auth_none_create_authorizer(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct ceph_auth_client *ac, int peer_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct ceph_auth_handshake *auth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct ceph_none_authorizer *au;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	au = kmalloc(sizeof(*au), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (!au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	au->base.destroy = ceph_auth_none_destroy_authorizer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ret = ceph_auth_none_build_authorizer(ac, au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		kfree(au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	auth->authorizer = (struct ceph_authorizer *) au;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	auth->authorizer_buf = au->buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	auth->authorizer_buf_len = au->buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	auth->authorizer_reply_buf = au->reply_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	auth->authorizer_reply_buf_len = sizeof (au->reply_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct ceph_auth_client_ops ceph_auth_none_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.name = "none",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	.reset = reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	.destroy = destroy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	.is_authenticated = is_authenticated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	.should_authenticate = should_authenticate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.build_request = build_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.handle_reply = handle_reply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.create_authorizer = ceph_auth_none_create_authorizer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int ceph_auth_none_init(struct ceph_auth_client *ac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct ceph_auth_none_info *xi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	dout("ceph_auth_none_init %p\n", ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	xi = kzalloc(sizeof(*xi), GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (!xi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	xi->starting = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ac->protocol = CEPH_AUTH_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ac->private = xi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	ac->ops = &ceph_auth_none_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }