}
const rgw_user& uid = op_state.get_user_id();
- if (uid.compare(RGW_USER_ANON_ID) == 0) {
+ if (uid == rgw_user(RGW_USER_ANON_ID)) {
keys_allowed = false;
return -EINVAL;
}
}
const rgw_user& uid = op_state.get_user_id();
- if (uid.compare(RGW_USER_ANON_ID) == 0) {
+ if (uid == rgw_user(RGW_USER_ANON_ID)) {
subusers_allowed = false;
return -EACCES;
}
}
const rgw_user& uid = op_state.get_user_id();
- if (uid.compare(RGW_USER_ANON_ID) == 0) {
+ if (uid == rgw_user(RGW_USER_ANON_ID)) {
caps_allowed = false;
return -EACCES;
}
}
}
- if (!user_id.empty() && (user_id.compare(RGW_USER_ANON_ID) != 0)) {
+ if (!user_id.empty() && user_id != rgw_user(RGW_USER_ANON_ID)) {
user = driver->get_user(user_id);
found = (user->load_user(dpp, y) >= 0);
op_state.found_by_uid = found;
int ret = 0;
const rgw_user& uid = op_state.get_user_id();
- if (uid.compare(RGW_USER_ANON_ID) == 0) {
+ if (uid == rgw_user(RGW_USER_ANON_ID)) {
set_err_msg(err_msg, "unable to perform operations on the anonymous user");
return -EINVAL;
}
- if (is_populated() && user_id.compare(uid) != 0) {
+ if (is_populated() && user_id != uid) {
set_err_msg(err_msg, "user id mismatch, operation id: " + uid.to_str()
+ " does not match: " + user_id.to_str());
}
// ensure that we can modify the user's attributes
- if (user_id.compare(RGW_USER_ANON_ID) == 0) {
+ if (user_id == rgw_user(RGW_USER_ANON_ID)) {
set_err_msg(err_msg, "unable to modify anonymous user's info");
return -EACCES;
}
// make sure we are not adding a duplicate email
if (old_email != op_email) {
ret = driver->get_user_by_email(dpp, op_email, y, &duplicate_check);
- if (ret >= 0 && duplicate_check->get_id().compare(user_id) != 0) {
+ if (ret >= 0 && duplicate_check->get_id() != user_id) {
set_err_msg(err_msg, "cannot add duplicate email");
return -ERR_EMAIL_EXIST;
}
add_grant(&group_grant);
} else if (canned_acl.compare("bucket-owner-read") == 0) {
bucket_owner_grant.set_canon(bid, bname, RGW_PERM_READ);
- if (bid.compare(owner.get_id()) != 0)
+ if (bid != owner.get_id())
add_grant(&bucket_owner_grant);
} else if (canned_acl.compare("bucket-owner-full-control") == 0) {
bucket_owner_grant.set_canon(bid, bname, RGW_PERM_FULL_CONTROL);
- if (bid.compare(owner.get_id()) != 0)
+ if (bid != owner.get_id())
add_grant(&bucket_owner_grant);
} else {
return -EINVAL;
ACLOwner *requested_owner = static_cast<ACLOwner_S3 *>(find_first("Owner"));
if (requested_owner) {
rgw_user& requested_id = requested_owner->get_id();
- if (!requested_id.empty() && requested_id.compare(owner->get_id()) != 0)
+ if (!requested_id.empty() && requested_id != owner->get_id())
return -EPERM;
}
return ret;
}
const rgw_user& bucket_owner = bucket_policy.get_owner().get_id();
- if (bucket_owner.compare(s->user->get_id()) != 0 &&
+ if (bucket_owner != s->user->get_id() &&
! s->auth.identity->is_admin_of(bucket_owner)) {
auto r = eval_identity_or_session_policies(dpp, s->iam_user_policies, s->env,
rgw::IAM::s3ListBucket, ARN(bucket->get_key()));
#include "common/Formatter.h"
struct rgw_user {
+ // note: order of member variables matches the sort order of operator<=>
std::string tenant;
- std::string id;
std::string ns;
+ std::string id;
rgw_user() {}
explicit rgw_user(const std::string& s) {
}
rgw_user(const std::string& tenant, const std::string& id, const std::string& ns="")
: tenant(tenant),
- id(id),
- ns(ns) {
+ ns(ns),
+ id(id) {
}
rgw_user(std::string&& tenant, std::string&& id, std::string&& ns="")
: tenant(std::move(tenant)),
- id(std::move(id)),
- ns(std::move(ns)) {
+ ns(std::move(ns)),
+ id(std::move(id)) {
}
void encode(ceph::buffer::list& bl) const {
return *this;
}
- int compare(const rgw_user& u) const {
- int r = tenant.compare(u.tenant);
- if (r != 0)
- return r;
- r = ns.compare(u.ns);
- if (r != 0) {
- return r;
- }
- return id.compare(u.id);
- }
- int compare(const std::string& str) const {
- rgw_user u(str);
- return compare(u);
- }
+ friend auto operator<=>(const rgw_user&, const rgw_user&) = default;
- bool operator!=(const rgw_user& rhs) const {
- return (compare(rhs) != 0);
- }
- bool operator==(const rgw_user& rhs) const {
- return (compare(rhs) == 0);
- }
- bool operator<(const rgw_user& rhs) const {
- if (tenant < rhs.tenant) {
- return true;
- } else if (tenant > rhs.tenant) {
- return false;
- }
- if (ns < rhs.ns) {
- return true;
- } else if (ns > rhs.ns) {
- return false;
- }
- return (id < rhs.id);
- }
void dump(ceph::Formatter *f) const;
static void generate_test_instances(std::list<rgw_user*>& o);
};
int compare_user_info(RGWUserInfo& i1, RGWUserInfo& i2) {
int rv;
- if ((rv = i1.user_id.compare(i2.user_id)) != 0)
+ if ((rv = i1.user_id.id.compare(i2.user_id.id)) != 0)
return rv;
if ((rv = i1.display_name.compare(i2.display_name)) != 0)
return rv;