]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
validate_bucket_name: loosen up
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 24 Mar 2011 17:27:18 +0000 (10:27 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 24 Mar 2011 17:27:45 +0000 (10:27 -0700)
Allow users to create bucket names that don't meet the S3
recommendations, but which do meet the spec.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/rgw/rgw_rest.cc

index e2dd0e1c4b683eb260a29a4c2c98779a7903622a..9eebce4267268aa857e85195f425e4f27383fce0 100644 (file)
@@ -517,40 +517,41 @@ static void init_auth_info(struct req_state *s)
   }
 }
 
-// This function enforces some fairly strict limits on bucket names.  These
-// correspond to Amazon's "recommendations", and are stricter than its actual
-// hard-and-fast rules about bucket names.  This way, all our buckets will be
-// accessible via the virtual host calling format, rather than only some of
-// them.
+// This function enforces Amazon's spec for bucket names.
+// (The requirements, not the recommendations.)
 static int validate_bucket_name(const char *bucket)
 {
   int len = strlen(bucket);
   if (len < 3) {
-    if (len == 0)
-      return 0;
     // Name too short
     return INVALID_BUCKET_NAME;
   }
-  else if (len > 63) {
+  else if (len > 255) {
     // Name too long
     return INVALID_BUCKET_NAME;
   }
+
+  if (!(islower(bucket[0]) || isdigit(bucket[0]))) {
+    // bucket names must start with a number or letter
+    return INVALID_BUCKET_NAME;
+  }
+
+  bool looks_like_ip_address = isdigit(bucket[0]);
+
   for (const char *s = bucket; *s; ++s) {
     char c = *s;
-    if (islower(c))
+    if (isdigit(c) || (c == '.'))
       continue;
-    if (isdigit(c))
+    looks_like_ip_address = false;
+    if (islower(c))
       continue;
-    if (c == '-')
+    if ((c == '-') || (c == '_'))
       continue;
     // Invalid character
-    // Yes, we are even excluding capital letters.
+    // Yes, we even exclude capital letters.
     return INVALID_BUCKET_NAME;
   }
-  // can't have dashes at the beginning or the end.
-  if (bucket[0] == '-')
-    return INVALID_BUCKET_NAME;
-  if (bucket[len-1] == '-')
+  if (looks_like_ip_address)
     return INVALID_BUCKET_NAME;
   return 0;
 }