]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: handle swift PUT with incorrect etag
authorYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 27 Oct 2011 00:20:51 +0000 (17:20 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Thu, 27 Oct 2011 00:20:51 +0000 (17:20 -0700)
src/rgw/rgw_common.h
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_rest.cc
src/rgw/rgw_rest.h
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index 72c4ed8b93333de8c882344861096214ded29880..c395dc6e61b7c233274528da4978eec43e71b53f 100644 (file)
@@ -96,31 +96,32 @@ using ceph::crypto::MD5;
   state->bytes_received += olen; \
 } while (0)
 
-#define STATUS_CREATED          1900
-#define STATUS_ACCEPTED         1901
-#define STATUS_NO_CONTENT       1902
-#define STATUS_PARTIAL_CONTENT  1903
-
-#define ERR_INVALID_BUCKET_NAME 2000
-#define ERR_INVALID_OBJECT_NAME 2001
-#define ERR_NO_SUCH_BUCKET      2002
-#define ERR_METHOD_NOT_ALLOWED  2003
-#define ERR_INVALID_DIGEST      2004
-#define ERR_BAD_DIGEST          2005
-#define ERR_UNRESOLVABLE_EMAIL  2006
-#define ERR_INVALID_PART        2007
-#define ERR_INVALID_PART_ORDER  2008
-#define ERR_NO_SUCH_UPLOAD      2009
-#define ERR_REQUEST_TIMEOUT     2010
-#define ERR_LENGTH_REQUIRED     2011
-#define ERR_REQUEST_TIME_SKEWED 2012
-#define ERR_BUCKET_EXISTS       2013
-#define ERR_BAD_URL             2014
-#define ERR_PRECONDITION_FAILED 2015
-#define ERR_NOT_MODIFIED        2016
-#define ERR_INVALID_UTF8        2017
-#define ERR_USER_SUSPENDED      2100
-#define ERR_INTERNAL_ERROR      2200
+#define STATUS_CREATED           1900
+#define STATUS_ACCEPTED          1901
+#define STATUS_NO_CONTENT        1902
+#define STATUS_PARTIAL_CONTENT   1903
+
+#define ERR_INVALID_BUCKET_NAME  2000
+#define ERR_INVALID_OBJECT_NAME  2001
+#define ERR_NO_SUCH_BUCKET       2002
+#define ERR_METHOD_NOT_ALLOWED   2003
+#define ERR_INVALID_DIGEST       2004
+#define ERR_BAD_DIGEST           2005
+#define ERR_UNRESOLVABLE_EMAIL   2006
+#define ERR_INVALID_PART         2007
+#define ERR_INVALID_PART_ORDER   2008
+#define ERR_NO_SUCH_UPLOAD       2009
+#define ERR_REQUEST_TIMEOUT      2010
+#define ERR_LENGTH_REQUIRED      2011
+#define ERR_REQUEST_TIME_SKEWED  2012
+#define ERR_BUCKET_EXISTS        2013
+#define ERR_BAD_URL              2014
+#define ERR_PRECONDITION_FAILED  2015
+#define ERR_NOT_MODIFIED         2016
+#define ERR_INVALID_UTF8         2017
+#define ERR_UNPROCESSABLE_ENTITY 2018
+#define ERR_USER_SUSPENDED       2100
+#define ERR_INTERNAL_ERROR       2200
 
 typedef void *RGWAccessHandle;
 
index 7e4507ddbe841db09d5104d4eaf7276b17d226a5..8c7ab3a065453ac7877298ce47810c3200496810 100644 (file)
@@ -655,6 +655,10 @@ void RGWPutObj::execute()
       dout(15) << "supplied_md5=" << supplied_md5 << dendl;
     }
 
+    if (supplied_etag) {
+      strncpy(supplied_md5, supplied_etag, sizeof(supplied_md5));
+    }
+
     MD5 hash;
     string oid;
     multipart = s->args.exists("uploadId");
@@ -748,6 +752,11 @@ void RGWPutObj::execute()
     policy.encode(aclbl);
 
     etag = calc_md5;
+
+    if (supplied_etag && etag.compare(supplied_etag) != 0) {
+      ret = -ERR_UNPROCESSABLE_ENTITY;
+      goto done_err;
+    }
     map<string, bufferlist> attrs;
     bufferlist bl;
     bl.append(etag.c_str(), etag.size() + 1);
index 2e6fe39039cb706939ce8325e94c694cd6f3226f..e736103bb3616ef1e0c2c774ab0c6966fe053b51 100644 (file)
@@ -238,6 +238,7 @@ protected:
   off_t ofs;
   char *data;
   const char *supplied_md5_b64;
+  const char *supplied_etag;
   string etag;
 
 public:
@@ -249,6 +250,7 @@ public:
     ofs = 0;
     data = NULL;
     supplied_md5_b64 = NULL;
+    supplied_etag = NULL;
     etag = "";
   }
   int verify_permission();
index 2ad08070673f48ffa8d761d4db7671727c910666..1912d6066b660f1836f2a5111b8fa3ca65f02ddf 100644 (file)
@@ -65,6 +65,7 @@ const static struct rgw_html_errors RGW_HTML_SWIFT_ERRORS[] = {
     { ERR_USER_SUSPENDED, 401, "UserSuspended" },
     { ERR_INVALID_UTF8, 412, "Invalid UTF8" },
     { ERR_BAD_URL, 412, "Bad URL" },
+    { ERR_UNPROCESSABLE_ENTITY, 422, "UnprocessableEntity" },
 };
 
 #define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0]))
index 7aeb0d5c195778a8cf1c23bc12cd59795b8111f6..d26bc03ae9971455c6da7bedd3f8a565b8b84f97 100644 (file)
@@ -62,7 +62,7 @@ public:
   RGWPutObj_REST() {}
   ~RGWPutObj_REST() {}
 
-  int get_params();
+  virtual int get_params();
   int get_data();
 };
 
index 5706ea2edeb17ea67d3f0c4340b06737f971f7d8..e5bdefd9f70e5e03cc3a407d6fbc88686fedbb47 100644 (file)
@@ -236,6 +236,12 @@ void RGWDeleteBucket_REST_SWIFT::send_response()
   flush_formatter_to_req_state(s, s->formatter);
 }
 
+int RGWPutObj_REST_SWIFT::get_params()
+{
+  supplied_etag = s->env->get("HTTP_ETAG");
+  return 0;
+}
+
 void RGWPutObj_REST_SWIFT::send_response()
 {
   if (!ret)
index fde210100c196bd1bb7370c53ae4cfebe333c9f9..63bbcb769ab03d8b4b608bf9a21ef0c7178ee349 100644 (file)
@@ -77,6 +77,7 @@ public:
   RGWPutObj_REST_SWIFT() {}
   ~RGWPutObj_REST_SWIFT() {}
 
+  int get_params();
   void send_response();
 };