From 8b420c4627faca27f61f472597c6f67cca2efa2f Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 5 Oct 2017 16:39:30 -0400 Subject: [PATCH] rgw: RGWUser::init no longer overwrites user_id if an admin op specifies a user_id and does not find a user with that id, but does find a user based on a later field (email, access key, etc), RGWUser::user_id will be overwritten with the existing user's id when this happens on 'radosgw-admin user create', RGWUser::execute_add() will modify that existing user, instead of trying to create a new user with the given user_id (and failing due to the conflicting email, access key, etc) by preserving the original user_id (when specified), this uid conflict is detected in RGWUser::check_op() and a "user id mismatch" error is returned Fixes: http://tracker.ceph.com/issues/21685 Signed-off-by: Casey Bodley (cherry picked from commit 4e65c9e9af86e832cb96d57d487771aa28251e7c) --- src/rgw/rgw_user.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index ebe795e7d6f6b..3ad6d762082ae 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -1760,7 +1760,7 @@ int RGWUser::init(RGWUserAdminOpState& op_state) { bool found = false; std::string swift_user; - rgw_user& uid = op_state.get_user_id(); + user_id = op_state.get_user_id(); std::string user_email = op_state.get_user_email(); std::string access_key = op_state.get_access_key(); std::string subuser = op_state.get_subuser(); @@ -1775,16 +1775,16 @@ int RGWUser::init(RGWUserAdminOpState& op_state) clear_populated(); - if (uid.empty() && !subuser.empty()) { + if (user_id.empty() && !subuser.empty()) { size_t pos = subuser.find(':'); if (pos != string::npos) { - uid = subuser.substr(0, pos); - op_state.set_user_id(uid); + user_id = subuser.substr(0, pos); + op_state.set_user_id(user_id); } } - if (!uid.empty() && (uid.compare(RGW_USER_ANON_ID) != 0)) { - found = (rgw_get_user_info_by_uid(store, uid, user_info, &op_state.objv) >= 0); + if (!user_id.empty() && (user_id.compare(RGW_USER_ANON_ID) != 0)) { + found = (rgw_get_user_info_by_uid(store, user_id, user_info, &op_state.objv) >= 0); op_state.found_by_uid = found; } if (!user_email.empty() && !found) { @@ -1809,7 +1809,9 @@ int RGWUser::init(RGWUserAdminOpState& op_state) set_populated(); } - user_id = user_info.user_id; + if (user_id.empty()) { + user_id = user_info.user_id; + } op_state.set_initialized(); // this may have been called by a helper object -- 2.39.5