]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add support for form expiration in Swift's FormPost.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 20 Sep 2016 13:31:03 +0000 (15:31 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 24 Apr 2017 15:32:14 +0000 (17:32 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest_swift.cc
src/rgw/rgw_rest_swift.h

index f0069700463bc57d7674b97e6a3e047b6044e07c..fe10ac292fd9ab5c25135e3b0a62a25bc4c53ee5 100644 (file)
@@ -1724,6 +1724,25 @@ void RGWFormPost::init(RGWRados* const store,
   return RGWPostObj_ObjStore::init(store, s, dialect_handler);
 }
 
+bool RGWFormPost::is_expired(const std::string& expires)
+{
+  string err;
+  const utime_t now = ceph_clock_now(g_ceph_context);
+  const uint64_t expiration = (uint64_t)strict_strtoll(expires.c_str(),
+                                                       10, &err);
+  if (!err.empty()) {
+    dout(5) << "failed to parse temp_url_expires: " << err << dendl;
+    return true;
+  }
+
+  if (expiration <= (uint64_t)now.sec()) {
+    dout(5) << "temp url expired: " << expiration << " <= " << now.sec() << dendl;
+    return true;
+  }
+
+  return false;
+}
+
 int RGWFormPost::get_params()
 {
   /* The parentt class extracts boundary info from the Content-Type. */
@@ -1792,6 +1811,12 @@ int RGWFormPost::get_params()
     }
   } while (! stream_done);
 
+  std::string expires;
+  if (part_str("expires", &expires) && is_expired(expires)) {
+    err_msg = "FormPost: Form Expired";
+    return -EACCES;
+  }
+
   return ! current_data_part ? -EINVAL : 0;
 }
 
@@ -1860,6 +1885,7 @@ int RGWFormPost::get_data(ceph::bufferlist& bl)
 void RGWFormPost::send_response()
 {
   set_req_state_err(s, op_ret);
+  s->err.s3_code = err_msg;
   dump_errno(s);
   end_header(s, this);
 }
index 6572034a87c77872c0317ee50f004d66bcb30362..333860dd4c7894c92387fbf67601453cbe893f5c 100644 (file)
@@ -241,6 +241,7 @@ public:
 class RGWFormPost : public RGWPostObj_ObjStore {
   std::string get_current_filename() const override;
   bool is_next_file_to_upload() override;
+  static bool is_expired(const std::string& expires);
 
   boost::optional<post_form_part> current_data_part;
   std::string prefix;