From c824e18e66cd3847f8a56d97bc515d8e7c6e5bcd Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 21 Sep 2016 13:39:25 +0200 Subject: [PATCH] rgw: refactor the expiration checking in FormPost of Swift API. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_rest_swift.cc | 31 +++++++++++++++++-------------- src/rgw/rgw_rest_swift.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 069962319da..86ab012632b 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -1724,23 +1724,27 @@ void RGWFormPost::init(RGWRados* const store, return RGWPostObj_ObjStore::init(store, s, dialect_handler); } -bool RGWFormPost::is_expired(const std::string& expires) +bool RGWFormPost::is_non_expired() { - 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; + std::string expires = get_part_str(ctrl_parts, "expires", "0"); + + std::string err; + const uint64_t expires_timestamp = + static_cast(strict_strtoll(expires.c_str(), 10, &err)); + + if (! err.empty()) { + dout(5) << "failed to parse FormPost's expires: " << err << dendl; + return false; } - if (expiration <= (uint64_t)now.sec()) { - dout(5) << "temp url expired: " << expiration << " <= " << now.sec() << dendl; - return true; + const utime_t now = ceph_clock_now(); + if (expires_timestamp <= static_cast(now.sec())) { + dout(5) << "FormPost form expired: " + << expires_timestamp << " <= " << now.sec() << dendl; + return false; } - return false; + return true; } bool RGWFormPost::is_integral() @@ -1846,8 +1850,7 @@ int RGWFormPost::get_params() } } while (! stream_done); - std::string expires; - if (part_str(ctrl_parts, "expires", &expires) && is_expired(expires)) { + if (! is_non_expired()) { err_msg = "FormPost: Form Expired"; return -EACCES; } diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h index e6762029621..c6029350146 100644 --- a/src/rgw/rgw_rest_swift.h +++ b/src/rgw/rgw_rest_swift.h @@ -244,7 +244,7 @@ class RGWFormPost : public RGWPostObj_ObjStore { std::string get_current_filename() const override; bool is_next_file_to_upload() override; bool is_integral(); - static bool is_expired(const std::string& expires); + bool is_non_expired(); parts_collection_t ctrl_parts; boost::optional current_data_part; -- 2.47.3