From c1f42770f45205c8a3eae774d09e747408130c50 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 6 Jan 2014 12:53:58 -0800 Subject: [PATCH] radosgw-admin: fix object policy read op Fixes: #7083 This was broken when we fixed #6940. We use the same function to both read the bucket policy and the object policy. However, each needed to be treated differently. Restore old behavior for objects. Signed-off-by: Yehuda Sadeh (cherry picked from commit b1976dd00f5b29c01791272f63a18250319f2edb) --- src/rgw/rgw_bucket.cc | 40 +++++++++++++++++++++++++++------------- src/rgw/rgw_bucket.h | 1 + 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index fee04dbba950f..3e57b934fef77 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -727,11 +727,37 @@ int RGWBucket::check_index(RGWBucketAdminOpState& op_state, return 0; } + +int RGWBucket::policy_bl_to_stream(bufferlist& bl, ostream& o) +{ + RGWAccessControlPolicy_S3 policy(g_ceph_context); + bufferlist::iterator iter = bl.begin(); + try { + policy.decode(iter); + } catch (buffer::error& err) { + dout(0) << "ERROR: caught buffer::error, could not decode policy" << dendl; + return -EIO; + } + policy.to_xml(o); + return 0; +} + int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, ostream& o) { std::string object_name = op_state.get_object_name(); rgw_bucket bucket = op_state.get_bucket(); + if (!object_name.empty()) { + bufferlist bl; + rgw_obj obj(bucket, object_name); + int ret = store->get_attr(NULL, obj, RGW_ATTR_ACL, bl); + if (ret < 0) + return ret; + + return policy_bl_to_stream(bl, o); + } + + RGWBucketInfo bucket_info; map attrs; int ret = store->get_bucket_info(NULL, bucket.name, bucket_info, NULL, &attrs); @@ -744,19 +770,7 @@ int RGWBucket::get_policy(RGWBucketAdminOpState& op_state, ostream& o) return -ENOENT; } - bufferlist& bl = aiter->second; - - RGWAccessControlPolicy_S3 policy(g_ceph_context); - bufferlist::iterator iter = bl.begin(); - try { - policy.decode(iter); - } catch (buffer::error& err) { - dout(0) << "ERROR: caught buffer::error, could not decode policy" << dendl; - return -EIO; - } - policy.to_xml(o); - - return 0; + return policy_bl_to_stream(aiter->second, o); } diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h index d84a8a13fe2ea..f3fb4f22480f6 100644 --- a/src/rgw/rgw_bucket.h +++ b/src/rgw/rgw_bucket.h @@ -205,6 +205,7 @@ public: int unlink(RGWBucketAdminOpState& op_state, std::string *err_msg = NULL); int remove_object(RGWBucketAdminOpState& op_state, std::string *err_msg = NULL); + int policy_bl_to_stream(bufferlist& bl, ostream& o); int get_policy(RGWBucketAdminOpState& op_state, ostream& o); void clear_failure() { failure = false; }; -- 2.39.5