]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/rados: generalize RGWUID for accounts
authorCasey Bodley <cbodley@redhat.com>
Thu, 30 Nov 2023 21:55:11 +0000 (16:55 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 12 Apr 2024 19:34:26 +0000 (15:34 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
(cherry picked from commit c72a51e08c5fb570a270efc3e1a7aff1e0383d16)

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

index ef847df5c1d04254af22d8de5d18a4179da1c431..c4585413a3b3a37608d93e7e90c5a0a5b03b6b37 100644 (file)
@@ -31,31 +31,28 @@ class RGWBucketCtl;
 class RGWUserBuckets;
 
 /**
- * A string wrapper that includes encode/decode functions
- * for easily accessing a UID in all forms
+ * A string wrapper that includes encode/decode functions for easily accessing
+ * a UID in all forms. In some objects, this may refer to an account id instead
+ * of a user.
  */
 struct RGWUID
 {
-  rgw_user user_id;
+  std::string id;
   void encode(bufferlist& bl) const {
-    std::string s;
-    user_id.to_str(s);
     using ceph::encode;
-    encode(s, bl);
+    encode(id, bl);
   }
   void decode(bufferlist::const_iterator& bl) {
-    std::string s;
     using ceph::decode;
-    decode(s, bl);
-    user_id.from_str(s);
+    decode(id, bl);
   }
   void dump(Formatter *f) const {
-    f->dump_string("user_id", user_id.to_str());
+    f->dump_string("user_id", id);
   }
   static void generate_test_instances(std::list<RGWUID*>& o) {
     o.push_back(new RGWUID);
     o.push_back(new RGWUID);
-    o.back()->user_id.from_str("test:tester");
+    o.back()->id = "test:tester";
   }
 };
 WRITE_CLASS_ENCODER(RGWUID)
index 0d01c96d481ff919250bf5285a0c5edcb0f9c225..9d06d5f13af9960a31ee192fa08975bd666bd4f4 100644 (file)
@@ -13,6 +13,7 @@
 #include "svc_sync_modules.h"
 
 #include "rgw_user.h"
+#include "rgw_account.h"
 #include "rgw_bucket.h"
 #include "rgw_tools.h"
 #include "rgw_zone.h"
@@ -136,8 +137,8 @@ int RGWSI_User_RADOS::read_user_info(RGWSI_MetaBackend::Context *ctx,
   auto iter = bl.cbegin();
   try {
     decode(user_id, iter);
-    if (user_id.user_id != user) {
-      ldpp_dout(dpp, -1)  << "ERROR: rgw_get_user_info_by_uid(): user id mismatch: " << user_id.user_id << " != " << user << dendl;
+    if (rgw_user{user_id.id} != user) {
+      ldpp_dout(dpp, -1)  << "ERROR: rgw_get_user_info_by_uid(): user id mismatch: " << user_id.id << " != " << user << dendl;
       return -EIO;
     }
     if (!iter.end()) {
@@ -202,7 +203,7 @@ public:
       objv_tracker(objv_tracker), mtime(mtime),
       exclusive(exclusive), pattrs(pattrs), y(y) {
     ctx = static_cast<RGWSI_MetaBackend_SObj::Context_SObj *>(_ctx);
-    ui.user_id = info.user_id;
+    ui.id = info.user_id.to_str();
   }
 
   int prepare(const DoutPrefixProvider *dpp) {
@@ -545,21 +546,25 @@ int RGWSI_User_RADOS::get_user_info_from_index(RGWSI_MetaBackend::Context* ctx,
 
   rgw_cache_entry_info cache_info;
 
-  auto iter = bl.cbegin();
   try {
+    auto iter = bl.cbegin();
     decode(uid, iter);
-
-    int ret = read_user_info(ctx, uid.user_id,
-                             &e.info, &e.objv_tracker, nullptr, &cache_info, nullptr,
-                             y, dpp);
-    if (ret < 0) {
-      return ret;
-    }
-  } catch (buffer::error& err) {
+  } catch (const buffer::error&) {
     ldpp_dout(dpp, 0) << "ERROR: failed to decode user info, caught buffer::error" << dendl;
     return -EIO;
   }
 
+  if (rgw::account::validate_id(uid.id)) {
+    // this index is used for an account, not a user
+    return -ENOENT;
+  }
+
+  ret = read_user_info(ctx, rgw_user{uid.id}, &e.info, &e.objv_tracker,
+                       nullptr, &cache_info, nullptr, y, dpp);
+  if (ret < 0) {
+    return ret;
+  }
+
   uinfo_cache->put(dpp, svc.cache, cache_key, &e, { &cache_info });
 
   *info = e.info;