return DAOS_NOT_IMPLEMENTED_LOG(dpp);
}
-int DaosBucket::chown(const DoutPrefixProvider* dpp, const rgw_owner& new_user,
+int DaosBucket::chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_user,
+ const std::string& new_owner_name,
optional_yield y) {
return DAOS_NOT_IMPLEMENTED_LOG(dpp);
}
virtual int sync_owner_stats(const DoutPrefixProvider* dpp,
optional_yield y) override;
virtual int check_bucket_shards(const DoutPrefixProvider* dpp) override;
- virtual int chown(const DoutPrefixProvider* dpp, const rgw_owner& new_user,
+ virtual int chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_user,
+ const std::string& new_owner_name,
optional_yield y) override;
virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive,
ceph::real_time mtime) override;
return 0;
}
-int POSIXBucket::chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner, optional_yield y)
-{
+int POSIXBucket::chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) {
/* TODO map user to UID/GID, and change it */
return 0;
}
RGWBucketEnt* ent) override;
virtual int check_bucket_shards(const DoutPrefixProvider* dpp,
uint64_t num_objs, optional_yield y) override;
- virtual int chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner, optional_yield y) override;
+ virtual int chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) override;
virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive,
- ceph::real_time mtime, optional_yield y) override;
+ ceph::real_time mtime, optional_yield y) override;
virtual int check_empty(const DoutPrefixProvider* dpp, optional_yield y) override;
virtual int check_quota(const DoutPrefixProvider *dpp, RGWQuota& quota, uint64_t obj_size, optional_yield y, bool check_size_only = false) override;
virtual int try_refresh_info(const DoutPrefixProvider* dpp, ceph::real_time* pmtime, optional_yield y) override;
void check_bad_owner_bucket_mapping(rgw::sal::Driver* driver,
const rgw_owner& owner,
+ const std::string& owner_name,
const std::string& tenant,
bool fix, optional_yield y,
const DoutPrefixProvider *dpp)
<< " got " << bucket << std::endl;
if (fix) {
cout << "fixing" << std::endl;
- r = bucket->chown(dpp, owner, y);
+ r = bucket->chown(dpp, owner, owner_name, y);
if (r < 0) {
cerr << "failed to fix bucket: " << cpp_strerror(-r) << std::endl;
}
void check_bad_owner_bucket_mapping(rgw::sal::Driver* driver,
const rgw_owner& owner,
+ const std::string& owner_name,
const std::string& tenant,
bool fix, optional_yield y,
const DoutPrefixProvider *dpp);
y, dpp, update_entrypoint);
}
-int RadosBucket::chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner, optional_yield y)
-{
+int RadosBucket::chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) {
// unlink from the owner, but don't update the entrypoint until link()
int r = this->unlink(dpp, info.owner, y, false);
if (r < 0) {
try {
auto p = i->second.cbegin();
- RGWAccessControlPolicy acl;
- decode(acl, p);
+ RGWAccessControlPolicy policy;
+ decode(policy, p);
+ //Get the ACL from the policy
+ RGWAccessControlList& acl = policy.get_acl();
+ ACLOwner& owner = policy.get_owner();
+
+ //Remove grant that is set to old owner
+ acl.remove_canon_user_grant(owner.id);
+
+ //Create a grant and add grant
+ ACLGrant grant;
+ grant.set_canon(new_owner, new_owner_name, RGW_PERM_FULL_CONTROL);
+ acl.add_grant(grant);
- acl.get_owner().id = new_owner;
+ //Update the ACL owner to the new user
+ owner.id = new_owner;
+ owner.display_name = new_owner_name;
bufferlist bl;
- encode(acl, bl);
+ encode(policy, bl);
i->second = std::move(bl);
} catch (const buffer::error&) {
RGWBucketEnt* ent) override;
int check_bucket_shards(const DoutPrefixProvider* dpp, uint64_t num_objs,
optional_yield y) override;
- virtual int chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner, optional_yield y) override;
+ virtual int chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) override;
virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive, ceph::real_time mtime, optional_yield y) override;
virtual int check_empty(const DoutPrefixProvider* dpp, optional_yield y) override;
virtual int check_quota(const DoutPrefixProvider *dpp, RGWQuota& quota, uint64_t obj_size, optional_yield y, bool check_size_only = false) override;
optional_yield y,
rgw::sal::Driver* driver,
const rgw_bucket& bucketid,
- const rgw_owner& new_owner)
-{
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name) {
// retry in case of racing writes to the bucket instance metadata
static constexpr auto max_retries = 10;
int tries = 0;
return r;
}
- r = bucket->chown(dpp, new_owner, y);
+ r = bucket->chown(dpp, new_owner, new_owner_name, y);
if (r < 0) {
ldpp_dout(dpp, 1) << "failed to chown bucket " << bucketid
<< ": " << cpp_strerror(r) << dendl;
static int adopt_user_buckets(const DoutPrefixProvider* dpp, optional_yield y,
rgw::sal::Driver* driver, const rgw_user& user,
- const rgw_account_id& account_id)
-{
+ const rgw_account_id& account_id,
+ const std::string& account_name) {
const size_t max_chunk = dpp->get_cct()->_conf->rgw_list_buckets_max_chunk;
constexpr bool need_stats = false;
}
for (const auto& ent : listing.buckets) {
- r = adopt_user_bucket(dpp, y, driver, ent.bucket, account_id);
+ r = adopt_user_bucket(dpp, y, driver, ent.bucket, account_id,
+ account_name);
if (r < 0 && r != -ENOENT) {
return r;
}
set_err_msg(err_msg, err);
return ret;
}
+ RGWAccountInfo account_info;
+ rgw::sal::Attrs attrs;
+ RGWObjVersionTracker objv;
+ int r = driver->load_account_by_id(dpp, y, op_state.account_id,
+ account_info,
+ attrs, objv);
+ if (r < 0) {
+ err = "Failed to load account by id";
+ return r;
+ }
// change account on user's buckets
ret = adopt_user_buckets(dpp, y, driver, user_info.user_id,
- user_info.account_id);
+ user_info.account_id, account_info.name);
if (ret < 0) {
set_err_msg(err_msg, "failed to change ownership of user's buckets");
return ret;
}
if (opt_cmd == OPT::USER_CHECK) {
- check_bad_owner_bucket_mapping(driver, user->get_id(), user->get_tenant(),
+ check_bad_owner_bucket_mapping(driver, user->get_id(),
+ user->get_display_name(), user->get_tenant(),
fix, null_yield, dpp());
}
const DoutPrefixProvider *dpp, optional_yield y)
{
/* Chown on the bucket */
- int ret = bucket->chown(dpp, new_user->get_id(), y);
+ int ret = bucket->chown(dpp, new_user->get_id(), new_user->get_display_name(),
+ y);
if (ret < 0) {
set_err_msg(err_msg, "Failed to change object ownership: " + cpp_strerror(-ret));
}
uint64_t num_objs, optional_yield y) = 0;
/** Change the owner of this bucket in the backing store. Current owner must be set. Does not
* change ownership of the objects in the bucket. */
- virtual int chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner, optional_yield y) = 0;
+ virtual int chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) = 0;
/** Store the cached bucket info into the backing store */
virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive, ceph::real_time mtime, optional_yield y) = 0;
/** Get the owner of this bucket */
return 0;
}
- int DBBucket::chown(const DoutPrefixProvider *dpp, const rgw_owner& new_owner, optional_yield y)
- {
+ int DBBucket::chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) {
int ret;
ret = store->getDB()->update_bucket(dpp, "owner", info, false, &new_owner, nullptr, nullptr, nullptr);
RGWBucketEnt* ent) override;
int check_bucket_shards(const DoutPrefixProvider *dpp,
uint64_t num_objs, optional_yield y) override;
- virtual int chown(const DoutPrefixProvider *dpp, const rgw_owner& new_owner, optional_yield y) override;
+ virtual int chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) override;
virtual int put_info(const DoutPrefixProvider *dpp, bool exclusive, ceph::real_time mtime, optional_yield y) override;
virtual int check_empty(const DoutPrefixProvider *dpp, optional_yield y) override;
virtual int check_quota(const DoutPrefixProvider *dpp, RGWQuota& quota, uint64_t obj_size, optional_yield y, bool check_size_only = false) override;
return next->check_bucket_shards(dpp, num_objs, y);
}
-int FilterBucket::chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner, optional_yield y)
-{
- return next->chown(dpp, new_owner, y);
+int FilterBucket::chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) {
+ return next->chown(dpp, new_owner, new_owner_name, y);
}
int FilterBucket::put_info(const DoutPrefixProvider* dpp, bool exclusive,
RGWBucketEnt* ent) override;
int check_bucket_shards(const DoutPrefixProvider* dpp,
uint64_t num_objs, optional_yield y) override;
- virtual int chown(const DoutPrefixProvider* dpp, const rgw_owner& new_owner,
- optional_yield y) override;
+ virtual int chown(const DoutPrefixProvider* dpp,
+ const rgw_owner& new_owner,
+ const std::string& new_owner_name,
+ optional_yield y) override;
virtual int put_info(const DoutPrefixProvider* dpp, bool exclusive,
ceph::real_time mtime, optional_yield y) override;
virtual const rgw_owner& get_owner() const override;