From addc744692f60885a747c4531cd12bf19b3a7f2a Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 2 Apr 2012 13:11:01 -0700 Subject: [PATCH] rgw: check for subuser existence This fixes #1856: looking up subuser that doesn't exist returns user as long as subuser prefix defined existing user. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_admin.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 0be7f9ddc84..c67d211d671 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -732,20 +732,30 @@ int main(int argc, char **argv) } } + bool subuser_found = false; + + if (!subuser.empty()) { + map::iterator iter = info.subusers.find(subuser); + subuser_found = (iter != info.subusers.end()); + + if (!subuser_found && opt_cmd != OPT_SUBUSER_CREATE) { + cerr << "subuser specified but was not found, aborting" << std::endl; + return 1; + } + } + if (opt_cmd == OPT_SUBUSER_CREATE || opt_cmd == OPT_SUBUSER_MODIFY || opt_cmd == OPT_SUBUSER_RM) { if (subuser.empty()) { cerr << "subuser creation was requires specifying subuser name" << std::endl; return 1; } - map::iterator iter = info.subusers.find(subuser); - bool found = (iter != info.subusers.end()); if (opt_cmd == OPT_SUBUSER_CREATE) { - if (found) { + if (subuser_found) { cerr << "error: subuser already exists" << std::endl; return 1; } - } else if (!found) { + } else if (!subuser_found) { cerr << "error: subuser doesn't exist" << std::endl; return 1; }