]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: make user email matching case-insensitive
authorCasey Bodley <cbodley@redhat.com>
Sun, 25 Feb 2024 15:04:44 +0000 (10:04 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 12 Apr 2024 19:34:29 +0000 (15:34 -0400)
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 <cbodley@redhat.com>
(cherry picked from commit 947390a342208a8348b030a179bc723d866c0104)

src/rgw/driver/rados/rgw_user.h
src/rgw/services/svc_user_rados.cc

index ec177bfdcbdcaf812a73906619a046af7fa4e86c..d3303f96257df35f8f9faf93fe5f62fc1e3ac458 100644 (file)
@@ -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;
   }
 
index 3ca8c36361baf52827f8003092aa4e92776a1924..5f158569fa29314f8a2bbb6d7e01368a4e92b4d1 100644 (file)
@@ -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);
 }