]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: remove error handling for get_random_bytes 17972/head
authorCasey Bodley <cbodley@redhat.com>
Tue, 26 Sep 2017 14:45:07 +0000 (10:45 -0400)
committerCasey Bodley <cbodley@redhat.com>
Mon, 9 Oct 2017 14:42:25 +0000 (10:42 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_crypt.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_user.cc
src/rgw/rgw_user.h

index 13472446314ab16b9128d4377dd5090dab1e07fd..19298c559eaebad2b948bd2d47d8284462267c85 100644 (file)
@@ -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; i<size - 1; i++) {
@@ -802,19 +794,13 @@ int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size) /* size
     dest[i] = alphanum_upper_table[pos % (sizeof(alphanum_upper_table) - 1)];
   }
   dest[i] = '\0';
-
-  return 0;
 }
 
 static const char alphanum_lower_table[]="0123456789abcdefghijklmnopqrstuvwxyz";
 
-int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_lower(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; i<size - 1; i++) {
@@ -822,31 +808,21 @@ int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size) /* size
     dest[i] = alphanum_lower_table[pos % (sizeof(alphanum_lower_table) - 1)];
   }
   dest[i] = '\0';
-
-  return 0;
 }
 
-int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length)
+void gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length)
 {
   char buf[length + 1];
-  int ret = gen_rand_alphanumeric_lower(cct, buf, sizeof(buf));
-  if (ret < 0) {
-    return ret;
-  }
+  gen_rand_alphanumeric_lower(cct, buf, sizeof(buf));
   *str = buf;
-  return 0;
 }
 
 // this is basically a modified base64 charset, url friendly
 static const char alphanum_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
 
-int gen_rand_alphanumeric(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric(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; i<size - 1; i++) {
@@ -854,19 +830,13 @@ int gen_rand_alphanumeric(CephContext *cct, char *dest, int size) /* size should
     dest[i] = alphanum_table[pos & 63];
   }
   dest[i] = '\0';
-
-  return 0;
 }
 
 static const char alphanum_no_underscore_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.";
 
-int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_no_underscore(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; i<size - 1; i++) {
@@ -874,19 +844,13 @@ int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size)
     dest[i] = alphanum_no_underscore_table[pos & 63];
   }
   dest[i] = '\0';
-
-  return 0;
 }
 
 static const char alphanum_plain_table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
 
-int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size) /* size should be the required string size + 1 */
+void gen_rand_alphanumeric_plain(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; i<size - 1; i++) {
@@ -894,8 +858,6 @@ int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size) /* size
     dest[i] = alphanum_plain_table[pos % (sizeof(alphanum_plain_table) - 1)];
   }
   dest[i] = '\0';
-
-  return 0;
 }
 
 int NameVal::parse()
index 0acc379e68f660ab8b3324d0780edfe8b1735bd3..d7d5386d4eadbccb3a0e06b5187b472aad75bb2d 100644 (file)
@@ -262,14 +262,13 @@ enum {
 
 
  /* size should be the required string size + 1 */
-extern int gen_rand_base64(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size);
-extern int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size);
-
-extern int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length);
+int gen_rand_base64(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size);
+void gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length);
 
 enum RGWIntentEvent {
   DEL_OBJ = 0,
index 1af9782bd38a462bd429e5a62fb58933ac082be3..4dcf88247585695e1b1729aecde500d1da1c0e64 100644 (file)
@@ -823,10 +823,7 @@ int RGWPutObj_BlockEncrypt::throttle_data(void *handle,
 
 std::string create_random_key_selector(CephContext * const cct) {
   char random[AES_256_KEYSIZE];
-  if (get_random_bytes(&random[0], sizeof(random)) != 0) {
-    ldout(cct, 0) << "ERROR: cannot get_random_bytes. " << dendl;
-    for (char& v:random) v=rand();
-  }
+  cct->random()->get_bytes(&random[0], sizeof(random));
   return std::string(random, sizeof(random));
 }
 
index 1ca671d861d04c019d8d971f69591bc4e0daac3b..9cd7c84c0fb744f70e2ffde06da0505506bcdc15 100644 (file)
@@ -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;
   }
index a14e19c37db01a8e87244e6a4452672ad62ed2e8..1d549ac2b2c87de91f9d6c0447c6c72ab552226e 100644 (file)
@@ -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;
   }
 
index 516617a295574c985bcee22c3bbbca60de174569..091f30d282578bf7bb21b3d59811d40e8299f88d 100644 (file)
@@ -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())