]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: version id should not contain underscore
authorYehuda Sadeh <yehuda@redhat.com>
Sat, 24 Jan 2015 01:28:14 +0000 (17:28 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 29 Jan 2015 17:31:32 +0000 (09:31 -0800)
The problem is that we use underscore for the raw object name encoding.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_rados.cc

index fd0a35cac81c48020d98e026f633ca297059115c..17e9fc95a58a3fc2e124f5f72e27326941d37a64 100644 (file)
@@ -505,6 +505,26 @@ int gen_rand_alphanumeric(CephContext *cct, char *dest, int size) /* size should
   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 */
+{
+  int ret = get_random_bytes(dest, size);
+  if (ret < 0) {
+    lderr(cct) << "cannot get random bytes: " << cpp_strerror(-ret) << dendl;
+    return ret;
+  }
+
+  int i;
+  for (i=0; i<size - 1; i++) {
+    int pos = (unsigned)dest[i];
+    dest[i] = alphanum_no_underscore_table[pos & 63];
+  }
+  dest[i] = '\0';
+
+  return 0;
+}
+
 int NameVal::parse()
 {
   int delim_pos = str.find('=');
index d77ad5004f8616c63cd6c847e19d99ad8d4035ea..394c11ed774b46d771e0b5e001a65848fb2c3cb4 100644 (file)
@@ -193,6 +193,7 @@ 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_lower(CephContext *cct, string *str, int length);
 
index cdeb259f625e5481ed2fc38b4e4283f1cef28065..7c5df6295c9a784aed7bef47e301a70a661d60e6 100644 (file)
@@ -6232,7 +6232,8 @@ void RGWRados::gen_rand_obj_instance_name(rgw_obj *target_obj)
 #define OBJ_INSTANCE_LEN 32
   char buf[OBJ_INSTANCE_LEN + 1];
 
-  gen_rand_alphanumeric(cct, buf, OBJ_INSTANCE_LEN); /* don't want it to get url escaped */
+  gen_rand_alphanumeric_no_underscore(cct, buf, OBJ_INSTANCE_LEN); /* don't want it to get url escaped,
+                                                                      no underscore for instance name due to the way we encode the raw keys */
 
   target_obj->set_instance(buf);
 }