From: caleb miles Date: Tue, 28 Aug 2012 17:41:42 +0000 (-0700) Subject: rgw_admin.cc: Prevent clobbering the index when linking a bucket. X-Git-Tag: v0.53~251 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e3834f023be6d897995a2a7f6829f442be0795ff;p=ceph.git rgw_admin.cc: Prevent clobbering the index when linking a bucket. Prevent the 'bucket link' command from overwriting the index of an existing bucket. Corrects bug 2935: http://tracker.newdream.net/issues/2935 Signed-off-by: caleb miles --- diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 36eddaf49ac..561d4a4aef7 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1178,15 +1178,35 @@ int main(int argc, char **argv) //cout << "bucket is linked to user '" << owner.get_id() << "'.. unlinking" << std::endl; r = rgw_remove_user_bucket_info(owner.get_id(), bucket); if (r < 0) { - cerr << "could not unlink policy from user '" << owner.get_id() << "'" << std::endl; - return r; + cerr << "could not unlink policy from user '" << owner.get_id() << "'" << std::endl; + return r; } - } - r = create_bucket(bucket_name.c_str(), uid_str, info.display_name, info.auid); - if (r < 0) + // now update the user for the bucket... + if (info.display_name.empty()) { + cerr << "WARNING: user " << info.user_id << " has no display name set" << std::endl; + } else { + policy.create_default(info.user_id, info.display_name); + + // ...and encode the acl + aclbl.clear(); + policy.encode(aclbl); + + r = rgwstore->set_attr(NULL, obj, RGW_ATTR_ACL, aclbl); + if (r < 0) + return r; + + r = rgw_add_bucket(info.user_id, bucket); + if (r < 0) + return r; + } + } else { + // the bucket seems not to exist, so we should probably create it... + r = create_bucket(bucket_name.c_str(), uid_str, info.display_name, info.auid); + if (r < 0) cerr << "error linking bucket to user: r=" << r << std::endl; - return -r; + return -r; + } } if (opt_cmd == OPT_BUCKET_UNLINK) {