/* * Reset occurs when reconnecting to the monitor.
*/ void ceph_auth_reset(struct ceph_auth_client *ac)
{
mutex_lock(&ac->mutex);
dout("auth_reset %p\n", ac); if (ac->ops && !ac->negotiating)
ac->ops->reset(ac);
ac->negotiating = true;
mutex_unlock(&ac->mutex);
}
/* * EntityName, not to be confused with entity_name_t
*/ int ceph_auth_entity_name_encode(constchar *name, void **p, void *end)
{ int len = strlen(name);
if (*p + 2*sizeof(u32) + len > end) return -ERANGE;
ceph_encode_32(p, CEPH_ENTITY_TYPE_CLIENT);
ceph_encode_32(p, len);
ceph_encode_copy(p, name, len); return 0;
}
/* * Initiate protocol negotiation with monitor. Include entity name * and list supported protocols.
*/ int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len)
{ struct ceph_mon_request_header *monhdr = buf; void *p = monhdr + 1, *end = buf + len, *lenp; int i, num; int ret;
dout(" result %d '%.*s' gid %llu len %d\n", result, result_msg_len,
result_msg, global_id, payload_len);
payload_end = payload + payload_len;
if (ac->negotiating) { /* server does not support our protocols? */ if (!protocol && result < 0) {
ret = result; goto out;
} /* set up (new) protocol handler? */ if (ac->protocol && ac->protocol != protocol) {
ac->ops->destroy(ac);
ac->protocol = 0;
ac->ops = NULL;
} if (ac->protocol != protocol) {
ret = init_protocol(ac, protocol); if (ret) {
pr_err("auth protocol '%s' init failed: %d\n",
ceph_auth_proto_name(protocol), ret); goto out;
}
}
ac->negotiating = false;
}
if (result) {
pr_err("auth protocol '%s' mauth authentication failed: %d\n",
ceph_auth_proto_name(ac->protocol), result);
ret = result; goto out;
}
ret = ac->ops->handle_reply(ac, global_id, payload, payload_end,
NULL, NULL, NULL, NULL); if (ret == -EAGAIN) {
ret = build_request(ac, true, reply_buf, reply_len); goto out;
} elseif (ret) { goto out;
}
out:
mutex_unlock(&ac->mutex); return ret;
bad:
pr_err("failed to decode auth msg\n");
ret = -EINVAL; goto out;
}
int ceph_build_auth(struct ceph_auth_client *ac, void *msg_buf, size_t msg_len)
{ int ret = 0;
mutex_lock(&ac->mutex); if (ac->ops->should_authenticate(ac))
ret = build_request(ac, true, msg_buf, msg_len);
mutex_unlock(&ac->mutex); return ret;
}
int ceph_auth_is_authenticated(struct ceph_auth_client *ac)
{ int ret = 0;
mutex_lock(&ac->mutex); if (ac->ops)
ret = ac->ops->is_authenticated(ac);
mutex_unlock(&ac->mutex); return ret;
}
EXPORT_SYMBOL(ceph_auth_is_authenticated);
int __ceph_auth_get_authorizer(struct ceph_auth_client *ac, struct ceph_auth_handshake *auth, int peer_type, bool force_new, int *proto, int *pref_mode, int *fallb_mode)
{ int ret;
mutex_lock(&ac->mutex); if (force_new && auth->authorizer) {
ceph_auth_destroy_authorizer(auth->authorizer);
auth->authorizer = NULL;
} if (!auth->authorizer)
ret = ac->ops->create_authorizer(ac, peer_type, auth); elseif (ac->ops->update_authorizer)
ret = ac->ops->update_authorizer(ac, peer_type, auth); else
ret = 0; if (ret) goto out;
int ceph_auth_add_authorizer_challenge(struct ceph_auth_client *ac, struct ceph_authorizer *a, void *challenge_buf, int challenge_buf_len)
{ int ret = 0;
mutex_lock(&ac->mutex); if (ac->ops && ac->ops->add_authorizer_challenge)
ret = ac->ops->add_authorizer_challenge(ac, a, challenge_buf,
challenge_buf_len);
mutex_unlock(&ac->mutex); return ret;
}
EXPORT_SYMBOL(ceph_auth_add_authorizer_challenge);
int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac, struct ceph_authorizer *a, void *reply, int reply_len,
u8 *session_key, int *session_key_len,
u8 *con_secret, int *con_secret_len)
{ int ret = 0;
mutex_lock(&ac->mutex); if (ac->ops && ac->ops->verify_authorizer_reply)
ret = ac->ops->verify_authorizer_reply(ac, a,
reply, reply_len, session_key, session_key_len,
con_secret, con_secret_len);
mutex_unlock(&ac->mutex); return ret;
}
EXPORT_SYMBOL(ceph_auth_verify_authorizer_reply);
void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac, int peer_type)
{
mutex_lock(&ac->mutex); if (ac->ops && ac->ops->invalidate_authorizer)
ac->ops->invalidate_authorizer(ac, peer_type);
mutex_unlock(&ac->mutex);
}
EXPORT_SYMBOL(ceph_auth_invalidate_authorizer);
/* * msgr2 authentication
*/
staticbool contains(constint *arr, int cnt, int val)
{ int i;
for (i = 0; i < cnt; i++) { if (arr[i] == val) returntrue;
}
/* * Similar to ceph_auth_build_hello().
*/ int ceph_auth_get_request(struct ceph_auth_client *ac, void *buf, int buf_len)
{ int proto = ac->key ? CEPH_AUTH_CEPHX : CEPH_AUTH_NONE; void *end = buf + buf_len; void *lenp; void *p; int ret;
int ceph_auth_handle_reply_done(struct ceph_auth_client *ac,
u64 global_id, void *reply, int reply_len,
u8 *session_key, int *session_key_len,
u8 *con_secret, int *con_secret_len)
{ int ret;
int ceph_auth_get_authorizer(struct ceph_auth_client *ac, struct ceph_auth_handshake *auth, int peer_type, void *buf, int *buf_len)
{ void *end = buf + *buf_len; int pref_mode, fallb_mode; int proto; void *p; int ret;
ret = __ceph_auth_get_authorizer(ac, auth, peer_type, true, &proto,
&pref_mode, &fallb_mode); if (ret) return ret;
p = buf;
ceph_encode_32_safe(&p, end, proto, e_range);
ret = encode_con_modes(&p, end, pref_mode, fallb_mode); if (ret) return ret;
int ceph_auth_handle_svc_reply_done(struct ceph_auth_client *ac, struct ceph_auth_handshake *auth, void *reply, int reply_len,
u8 *session_key, int *session_key_len,
u8 *con_secret, int *con_secret_len)
{ return ceph_auth_verify_authorizer_reply(ac, auth->authorizer,
reply, reply_len, session_key, session_key_len,
con_secret, con_secret_len);
}
EXPORT_SYMBOL(ceph_auth_handle_svc_reply_done);
bool ceph_auth_handle_bad_authorizer(struct ceph_auth_client *ac, int peer_type, int used_proto, int result, constint *allowed_protos, int proto_cnt, constint *allowed_modes, int mode_cnt)
{
mutex_lock(&ac->mutex);
WARN_ON(used_proto != ac->protocol);
if (result == -EOPNOTSUPP) { if (!contains(allowed_protos, proto_cnt, ac->protocol)) {
pr_err("auth protocol '%s' not allowed by %s\n",
ceph_auth_proto_name(ac->protocol),
ceph_entity_type_name(peer_type)); goto not_allowed;
} if (!contains(allowed_modes, mode_cnt, ac->preferred_mode) &&
(ac->fallback_mode == CEPH_CON_MODE_UNKNOWN ||
!contains(allowed_modes, mode_cnt, ac->fallback_mode))) {
pr_err("preferred mode '%s' not allowed by %s\n",
ceph_con_mode_name(ac->preferred_mode),
ceph_entity_type_name(peer_type)); if (ac->fallback_mode == CEPH_CON_MODE_UNKNOWN)
pr_err("no fallback mode\n"); else
pr_err("fallback mode '%s' not allowed by %s\n",
ceph_con_mode_name(ac->fallback_mode),
ceph_entity_type_name(peer_type)); goto not_allowed;
}
}
WARN_ON(result == -EOPNOTSUPP || result >= 0);
pr_err("auth protocol '%s' authorization to %s failed: %d\n",
ceph_auth_proto_name(ac->protocol),
ceph_entity_type_name(peer_type), result);
if (ac->ops->invalidate_authorizer)
ac->ops->invalidate_authorizer(ac, peer_type);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.