1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 23d14c5d2SYehuda Sadeh 33d14c5d2SYehuda Sadeh #include <linux/ceph/ceph_debug.h> 43d14c5d2SYehuda Sadeh 53d14c5d2SYehuda Sadeh #include <linux/err.h> 63d14c5d2SYehuda Sadeh #include <linux/module.h> 73d14c5d2SYehuda Sadeh #include <linux/random.h> 83d14c5d2SYehuda Sadeh #include <linux/slab.h> 93d14c5d2SYehuda Sadeh 103d14c5d2SYehuda Sadeh #include <linux/ceph/decode.h> 113d14c5d2SYehuda Sadeh #include <linux/ceph/auth.h> 123d14c5d2SYehuda Sadeh 133d14c5d2SYehuda Sadeh #include "auth_none.h" 143d14c5d2SYehuda Sadeh 153d14c5d2SYehuda Sadeh static void reset(struct ceph_auth_client *ac) 163d14c5d2SYehuda Sadeh { 173d14c5d2SYehuda Sadeh struct ceph_auth_none_info *xi = ac->private; 183d14c5d2SYehuda Sadeh 193d14c5d2SYehuda Sadeh xi->starting = true; 203d14c5d2SYehuda Sadeh } 213d14c5d2SYehuda Sadeh 223d14c5d2SYehuda Sadeh static void destroy(struct ceph_auth_client *ac) 233d14c5d2SYehuda Sadeh { 243d14c5d2SYehuda Sadeh kfree(ac->private); 253d14c5d2SYehuda Sadeh ac->private = NULL; 263d14c5d2SYehuda Sadeh } 273d14c5d2SYehuda Sadeh 283d14c5d2SYehuda Sadeh static int is_authenticated(struct ceph_auth_client *ac) 293d14c5d2SYehuda Sadeh { 303d14c5d2SYehuda Sadeh struct ceph_auth_none_info *xi = ac->private; 313d14c5d2SYehuda Sadeh 323d14c5d2SYehuda Sadeh return !xi->starting; 333d14c5d2SYehuda Sadeh } 343d14c5d2SYehuda Sadeh 353d14c5d2SYehuda Sadeh static int should_authenticate(struct ceph_auth_client *ac) 363d14c5d2SYehuda Sadeh { 373d14c5d2SYehuda Sadeh struct ceph_auth_none_info *xi = ac->private; 383d14c5d2SYehuda Sadeh 393d14c5d2SYehuda Sadeh return xi->starting; 403d14c5d2SYehuda Sadeh } 413d14c5d2SYehuda Sadeh 426c1ea260SIlya Dryomov static int ceph_auth_none_build_authorizer(struct ceph_auth_client *ac, 436c1ea260SIlya Dryomov struct ceph_none_authorizer *au) 446c1ea260SIlya Dryomov { 456c1ea260SIlya Dryomov void *p = au->buf; 466c1ea260SIlya Dryomov void *const end = p + sizeof(au->buf); 476c1ea260SIlya Dryomov int ret; 486c1ea260SIlya Dryomov 496c1ea260SIlya Dryomov ceph_encode_8_safe(&p, end, 1, e_range); 50f01d5cb2SIlya Dryomov ret = ceph_auth_entity_name_encode(ac->name, &p, end); 516c1ea260SIlya Dryomov if (ret < 0) 526c1ea260SIlya Dryomov return ret; 536c1ea260SIlya Dryomov 546c1ea260SIlya Dryomov ceph_encode_64_safe(&p, end, ac->global_id, e_range); 556c1ea260SIlya Dryomov au->buf_len = p - (void *)au->buf; 566c1ea260SIlya Dryomov dout("%s built authorizer len %d\n", __func__, au->buf_len); 576c1ea260SIlya Dryomov return 0; 586c1ea260SIlya Dryomov 596c1ea260SIlya Dryomov e_range: 606c1ea260SIlya Dryomov return -ERANGE; 616c1ea260SIlya Dryomov } 626c1ea260SIlya Dryomov 632cb33cacSTyler Hicks static int build_request(struct ceph_auth_client *ac, void *buf, void *end) 642cb33cacSTyler Hicks { 652cb33cacSTyler Hicks return 0; 662cb33cacSTyler Hicks } 672cb33cacSTyler Hicks 683d14c5d2SYehuda Sadeh /* 693d14c5d2SYehuda Sadeh * the generic auth code decode the global_id, and we carry no actual 703d14c5d2SYehuda Sadeh * authenticate state, so nothing happens here. 713d14c5d2SYehuda Sadeh */ 723d14c5d2SYehuda Sadeh static int handle_reply(struct ceph_auth_client *ac, int result, 73*285ea34fSIlya Dryomov void *buf, void *end, u8 *session_key, 74*285ea34fSIlya Dryomov int *session_key_len, u8 *con_secret, 75*285ea34fSIlya Dryomov int *con_secret_len) 763d14c5d2SYehuda Sadeh { 773d14c5d2SYehuda Sadeh struct ceph_auth_none_info *xi = ac->private; 783d14c5d2SYehuda Sadeh 793d14c5d2SYehuda Sadeh xi->starting = false; 803d14c5d2SYehuda Sadeh return result; 813d14c5d2SYehuda Sadeh } 823d14c5d2SYehuda Sadeh 836c1ea260SIlya Dryomov static void ceph_auth_none_destroy_authorizer(struct ceph_authorizer *a) 846c1ea260SIlya Dryomov { 856c1ea260SIlya Dryomov kfree(a); 866c1ea260SIlya Dryomov } 876c1ea260SIlya Dryomov 883d14c5d2SYehuda Sadeh /* 896c1ea260SIlya Dryomov * build an 'authorizer' with our entity_name and global_id. it is 906c1ea260SIlya Dryomov * identical for all services we connect to. 913d14c5d2SYehuda Sadeh */ 923d14c5d2SYehuda Sadeh static int ceph_auth_none_create_authorizer( 933d14c5d2SYehuda Sadeh struct ceph_auth_client *ac, int peer_type, 9474f1869fSAlex Elder struct ceph_auth_handshake *auth) 953d14c5d2SYehuda Sadeh { 966c1ea260SIlya Dryomov struct ceph_none_authorizer *au; 973d14c5d2SYehuda Sadeh int ret; 983d14c5d2SYehuda Sadeh 996c1ea260SIlya Dryomov au = kmalloc(sizeof(*au), GFP_NOFS); 1006c1ea260SIlya Dryomov if (!au) 1016c1ea260SIlya Dryomov return -ENOMEM; 1026c1ea260SIlya Dryomov 1036c1ea260SIlya Dryomov au->base.destroy = ceph_auth_none_destroy_authorizer; 1046c1ea260SIlya Dryomov 1056c1ea260SIlya Dryomov ret = ceph_auth_none_build_authorizer(ac, au); 1066c1ea260SIlya Dryomov if (ret) { 1076c1ea260SIlya Dryomov kfree(au); 1086c1ea260SIlya Dryomov return ret; 1093d14c5d2SYehuda Sadeh } 1103d14c5d2SYehuda Sadeh 11174f1869fSAlex Elder auth->authorizer = (struct ceph_authorizer *) au; 11274f1869fSAlex Elder auth->authorizer_buf = au->buf; 11374f1869fSAlex Elder auth->authorizer_buf_len = au->buf_len; 11474f1869fSAlex Elder auth->authorizer_reply_buf = au->reply_buf; 11574f1869fSAlex Elder auth->authorizer_reply_buf_len = sizeof (au->reply_buf); 11674f1869fSAlex Elder 1173d14c5d2SYehuda Sadeh return 0; 1183d14c5d2SYehuda Sadeh } 1193d14c5d2SYehuda Sadeh 1203d14c5d2SYehuda Sadeh static const struct ceph_auth_client_ops ceph_auth_none_ops = { 1213d14c5d2SYehuda Sadeh .name = "none", 1223d14c5d2SYehuda Sadeh .reset = reset, 1233d14c5d2SYehuda Sadeh .destroy = destroy, 1243d14c5d2SYehuda Sadeh .is_authenticated = is_authenticated, 1253d14c5d2SYehuda Sadeh .should_authenticate = should_authenticate, 1262cb33cacSTyler Hicks .build_request = build_request, 1273d14c5d2SYehuda Sadeh .handle_reply = handle_reply, 1283d14c5d2SYehuda Sadeh .create_authorizer = ceph_auth_none_create_authorizer, 1293d14c5d2SYehuda Sadeh }; 1303d14c5d2SYehuda Sadeh 1313d14c5d2SYehuda Sadeh int ceph_auth_none_init(struct ceph_auth_client *ac) 1323d14c5d2SYehuda Sadeh { 1333d14c5d2SYehuda Sadeh struct ceph_auth_none_info *xi; 1343d14c5d2SYehuda Sadeh 1353d14c5d2SYehuda Sadeh dout("ceph_auth_none_init %p\n", ac); 1363d14c5d2SYehuda Sadeh xi = kzalloc(sizeof(*xi), GFP_NOFS); 1373d14c5d2SYehuda Sadeh if (!xi) 1383d14c5d2SYehuda Sadeh return -ENOMEM; 1393d14c5d2SYehuda Sadeh 1403d14c5d2SYehuda Sadeh xi->starting = true; 1413d14c5d2SYehuda Sadeh 1423d14c5d2SYehuda Sadeh ac->protocol = CEPH_AUTH_NONE; 1433d14c5d2SYehuda Sadeh ac->private = xi; 1443d14c5d2SYehuda Sadeh ac->ops = &ceph_auth_none_ops; 1453d14c5d2SYehuda Sadeh return 0; 1463d14c5d2SYehuda Sadeh } 147