From: Casey Bodley Date: Sun, 25 Feb 2024 15:04:44 +0000 (-0500) Subject: rgw: make user email matching case-insensitive X-Git-Tag: testing/wip-yuriw-testing-20240416.150233~10^2~45 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=7f4391ee0549eb552c498c68d0cf2a955382989b;p=ceph-ci.git rgw: make user email matching case-insensitive handle user emails the same way we do account account emails. store RGWUserInfo::user_email exactly as the user specified it, but convert the object name to lower-case for case-insensitive matching Signed-off-by: Casey Bodley (cherry picked from commit 947390a342208a8348b030a179bc723d866c0104) --- diff --git a/src/rgw/driver/rados/rgw_user.h b/src/rgw/driver/rados/rgw_user.h index ec177bfdcbd..d3303f96257 100644 --- a/src/rgw/driver/rados/rgw_user.h +++ b/src/rgw/driver/rados/rgw_user.h @@ -242,9 +242,7 @@ struct RGWUserAdminOpState { } void set_user_email(const std::string& email) { - /* always lowercase email address */ user_email = email; - boost::algorithm::to_lower(user_email); user_email_specified = true; } diff --git a/src/rgw/services/svc_user_rados.cc b/src/rgw/services/svc_user_rados.cc index 3ca8c36361b..5f158569fa2 100644 --- a/src/rgw/services/svc_user_rados.cc +++ b/src/rgw/services/svc_user_rados.cc @@ -313,9 +313,12 @@ public: encode(ui, link_bl); if (!info.user_email.empty()) { - if (!old_info || - old_info->user_email.compare(info.user_email) != 0) { /* only if new index changed */ - ret = rgw_put_system_obj(dpp, svc.sysobj, svc.zone->get_zone_params().user_email_pool, info.user_email, + // only if new index changed + if (!old_info || !boost::iequals(info.user_email, old_info->user_email)) { + // store as lower case for case-insensitive matching + std::string oid = info.user_email; + boost::to_lower(oid); + ret = rgw_put_system_obj(dpp, svc.sysobj, svc.zone->get_zone_params().user_email_pool, oid, link_bl, exclusive, NULL, real_time(), y); if (ret < 0) return ret; @@ -410,7 +413,7 @@ public: } if (!old_info.user_email.empty() && - old_info.user_email != new_info.user_email) { + !boost::iequals(old_info.user_email, new_info.user_email)) { ret = svc.user->remove_email_index(dpp, old_info.user_email, y); if (ret < 0 && ret != -ENOENT) { set_err_msg("ERROR: could not remove index for email " + old_info.user_email); @@ -523,7 +526,9 @@ int RGWSI_User_RADOS::remove_email_index(const DoutPrefixProvider *dpp, if (email.empty()) { return 0; } - rgw_raw_obj obj(svc.zone->get_zone_params().user_email_pool, email); + std::string oid = email; + boost::to_lower(oid); + rgw_raw_obj obj(svc.zone->get_zone_params().user_email_pool, oid); auto sysobj = svc.sysobj->get_obj(obj); return sysobj.wop().remove(dpp, y); } @@ -722,7 +727,9 @@ int RGWSI_User_RADOS::get_user_info_by_email(RGWSI_MetaBackend::Context *ctx, real_time *pmtime, optional_yield y, const DoutPrefixProvider *dpp) { - return get_user_info_from_index(ctx, email, svc.zone->get_zone_params().user_email_pool, + std::string oid = email; + boost::to_lower(oid); + return get_user_info_from_index(ctx, oid, svc.zone->get_zone_params().user_email_pool, info, objv_tracker, pmtime, y, dpp); } @@ -766,5 +773,7 @@ int RGWSI_User_RADOS::read_email_index(const DoutPrefixProvider* dpp, RGWUID& uid) { const rgw_pool& pool = svc.zone->get_zone_params().user_email_pool; - return read_index(dpp, y, svc.sysobj, pool, std::string{email}, nullptr, uid); + std::string oid{email}; + boost::to_lower(oid); + return read_index(dpp, y, svc.sysobj, pool, oid, nullptr, uid); }