From: Casey Bodley Date: Tue, 26 Sep 2017 14:45:07 +0000 (-0400) Subject: rgw: remove error handling for get_random_bytes X-Git-Tag: v13.0.1~587^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F17972%2Fhead;p=ceph.git rgw: remove error handling for get_random_bytes Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 13472446314a..19298c559eae 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -767,11 +767,7 @@ int gen_rand_base64(CephContext *cct, char *dest, int size) /* size should be th char tmp_dest[size + 4]; /* so that there's space for the extra '=' characters, and some */ int ret; - ret = get_random_bytes(buf, sizeof(buf)); - if (ret < 0) { - lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl; - return ret; - } + cct->random()->get_bytes(buf, sizeof(buf)); ret = ceph_armor(tmp_dest, &tmp_dest[sizeof(tmp_dest)], (const char *)buf, ((const char *)buf) + ((size - 1) * 3 + 4 - 1) / 4); @@ -788,13 +784,9 @@ int gen_rand_base64(CephContext *cct, char *dest, int size) /* size should be th static const char alphanum_upper_table[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */ +void gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */ { - int ret = get_random_bytes(dest, size); - if (ret < 0) { - lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl; - return ret; - } + cct->random()->get_bytes(dest, size); int i; for (i=0; irandom()->get_bytes(dest, size); int i; for (i=0; irandom()->get_bytes(dest, size); int i; for (i=0; irandom()->get_bytes(dest, size); int i; for (i=0; irandom()->get_bytes(dest, size); int i; for (i=0; irandom()->get_bytes(&random[0], sizeof(random)); return std::string(random, sizeof(random)); } diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 1ca671d861d0..9cd7c84c0fb7 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -10773,11 +10773,8 @@ int RGWRados::olh_init_modification_impl(const RGWBucketInfo& bucket_info, RGWOb if (!has_tag) { /* obj tag */ string obj_tag; - int ret = gen_rand_alphanumeric_lower(cct, &obj_tag, 32); - if (ret < 0) { - ldout(cct, 0) << "ERROR: gen_rand_alphanumeric_lower() returned ret=" << ret << dendl; - return ret; - } + gen_rand_alphanumeric_lower(cct, &obj_tag, 32); + bufferlist bl; bl.append(obj_tag.c_str(), obj_tag.size()); op.setxattr(RGW_ATTR_ID_TAG, bl); @@ -10787,11 +10784,8 @@ int RGWRados::olh_init_modification_impl(const RGWBucketInfo& bucket_info, RGWOb /* olh tag */ string olh_tag; - ret = gen_rand_alphanumeric_lower(cct, &olh_tag, 32); - if (ret < 0) { - ldout(cct, 0) << "ERROR: gen_rand_alphanumeric_lower() returned ret=" << ret << dendl; - return ret; - } + gen_rand_alphanumeric_lower(cct, &olh_tag, 32); + bufferlist olh_bl; olh_bl.append(olh_tag.c_str(), olh_tag.size()); op.setxattr(RGW_ATTR_OLH_ID_TAG, olh_bl); @@ -10817,11 +10811,8 @@ int RGWRados::olh_init_modification_impl(const RGWBucketInfo& bucket_info, RGWOb *op_tag = buf; string s; - int ret = gen_rand_alphanumeric_lower(cct, &s, OLH_PENDING_TAG_LEN - op_tag->size()); - if (ret < 0) { - ldout(cct, 0) << "ERROR: gen_rand_alphanumeric_lower() returned ret=" << ret << dendl; - return ret; - } + gen_rand_alphanumeric_lower(cct, &s, OLH_PENDING_TAG_LEN - op_tag->size()); + op_tag->append(s); string attr_name = RGW_ATTR_OLH_PENDING_PREFIX; @@ -10829,7 +10820,7 @@ int RGWRados::olh_init_modification_impl(const RGWBucketInfo& bucket_info, RGWOb op.setxattr(attr_name.c_str(), bl); - ret = obj_operate(bucket_info, olh_obj, &op); + int ret = obj_operate(bucket_info, olh_obj, &op); if (ret < 0) { return ret; } diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index a14e19c37db0..1d549ac2b2c8 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -903,7 +903,6 @@ int RGWAccessKeyPool::generate_key(RGWUserAdminOpState& op_state, std::string *e RGWAccessKey new_key; RGWUserInfo duplicate_check; - int ret = 0; int key_type = op_state.get_key_type(); bool gen_access = op_state.will_gen_access(); bool gen_secret = op_state.will_gen_secret(); @@ -956,13 +955,7 @@ int RGWAccessKeyPool::generate_key(RGWUserAdminOpState& op_state, std::string *e key = op_state.get_secret_key(); } else { char secret_key_buf[SECRET_KEY_LEN + 1]; - - ret = gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, sizeof(secret_key_buf)); - if (ret < 0) { - set_err_msg(err_msg, "unable to generate secret key"); - return ret; - } - + gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, sizeof(secret_key_buf)); key = secret_key_buf; } @@ -972,14 +965,7 @@ int RGWAccessKeyPool::generate_key(RGWUserAdminOpState& op_state, std::string *e do { int id_buf_size = sizeof(public_id_buf); - ret = gen_rand_alphanumeric_upper(g_ceph_context, - public_id_buf, id_buf_size); - - if (ret < 0) { - set_err_msg(err_msg, "unable to generate access key"); - return ret; - } - + gen_rand_alphanumeric_upper(g_ceph_context, public_id_buf, id_buf_size); id = public_id_buf; if (!validate_access_key(id)) continue; @@ -1068,15 +1054,8 @@ int RGWAccessKeyPool::modify_key(RGWUserAdminOpState& op_state, std::string *err if (op_state.will_gen_secret()) { char secret_key_buf[SECRET_KEY_LEN + 1]; - - int ret; int key_buf_size = sizeof(secret_key_buf); - ret = gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, key_buf_size); - if (ret < 0) { - set_err_msg(err_msg, "unable to generate secret key"); - return ret; - } - + gen_rand_alphanumeric_plain(g_ceph_context, secret_key_buf, key_buf_size); key = secret_key_buf; } diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 516617a29557..091f30d28257 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -464,8 +464,7 @@ struct RGWUserAdminOpState { int sub_buf_size = RAND_SUBUSER_LEN + 1; char sub_buf[RAND_SUBUSER_LEN + 1]; - if (gen_rand_alphanumeric_upper(g_ceph_context, sub_buf, sub_buf_size) < 0) - return ""; + gen_rand_alphanumeric_upper(g_ceph_context, sub_buf, sub_buf_size); rand_suffix = sub_buf; if (rand_suffix.empty())