summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/user_management_commands.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2018-01-16 13:00:48 -0500
committerMathias Stearn <mathias@10gen.com>2018-01-17 17:10:47 -0500
commitdaf6c4714b45aeb8ba1a09380135b3267c4cc280 (patch)
treec436a157d25ccb13f91746ba4e099a6396462115 /src/mongo/db/commands/user_management_commands.cpp
parent4dc36c7ccb6b5b8f7d865993b5d648fe6dc4b7c7 (diff)
downloadmongo-daf6c4714b45aeb8ba1a09380135b3267c4cc280.tar.gz
SERVER-32617 Fix code that reconstructs status with just code and string
Diffstat (limited to 'src/mongo/db/commands/user_management_commands.cpp')
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp67
1 files changed, 28 insertions, 39 deletions
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index 0ad3dff7fc2..97255194138 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -87,6 +87,12 @@ namespace {
// Used to obtain mutex that guards modifications to persistent authorization data
const auto getAuthzDataMutex = ServiceContext::declareDecoration<stdx::mutex>();
+Status useDefaultCode(const Status& status, ErrorCodes::Error defaultCode) {
+ if (status.code() != ErrorCodes::UnknownError)
+ return status;
+ return Status(defaultCode, status.reason());
+}
+
BSONArray roleSetToBSONArray(const unordered_set<RoleName>& roles) {
BSONArrayBuilder rolesArrayBuilder;
for (unordered_set<RoleName>::const_iterator it = roles.begin(); it != roles.end(); ++it) {
@@ -1986,15 +1992,11 @@ public:
// Must invalidate even on bad status - what if the write succeeded but the GLE failed?
authzManager->invalidateUserCache();
if (!status.isOK()) {
- ErrorCodes::Error code = status.code() == ErrorCodes::UnknownError
- ? ErrorCodes::UserModificationFailed
- : status.code();
return CommandHelpers::appendCommandStatus(
result,
- Status(code,
- str::stream() << "Failed to remove role " << roleName.getFullName()
- << " from all users: "
- << status.reason()));
+ useDefaultCode(status, ErrorCodes::UserModificationFailed)
+ .withContext(str::stream() << "Failed to remove role " << roleName.getFullName()
+ << " from all users"));
}
// Remove this role from all other roles
@@ -2015,15 +2017,12 @@ public:
// Must invalidate even on bad status - what if the write succeeded but the GLE failed?
authzManager->invalidateUserCache();
if (!status.isOK()) {
- ErrorCodes::Error code = status.code() == ErrorCodes::UnknownError
- ? ErrorCodes::RoleModificationFailed
- : status.code();
return CommandHelpers::appendCommandStatus(
result,
- Status(code,
- str::stream() << "Removed role " << roleName.getFullName()
- << " from all users but failed to remove from all roles: "
- << status.reason()));
+ useDefaultCode(status, ErrorCodes::RoleModificationFailed)
+ .withContext(
+ str::stream() << "Removed role " << roleName.getFullName()
+ << " from all users but failed to remove from all roles"));
}
audit::logDropRole(Client::getCurrent(), roleName);
@@ -2039,11 +2038,10 @@ public:
if (!status.isOK()) {
return CommandHelpers::appendCommandStatus(
result,
- Status(status.code(),
- str::stream() << "Removed role " << roleName.getFullName()
- << " from all users and roles but failed to actually delete"
- " the role itself: "
- << status.reason()));
+ status.withContext(
+ str::stream() << "Removed role " << roleName.getFullName()
+ << " from all users and roles but failed to actually delete"
+ " the role itself"));
}
dassert(nMatched == 0 || nMatched == 1);
@@ -2118,15 +2116,11 @@ public:
// Must invalidate even on bad status - what if the write succeeded but the GLE failed?
authzManager->invalidateUserCache();
if (!status.isOK()) {
- ErrorCodes::Error code = status.code() == ErrorCodes::UnknownError
- ? ErrorCodes::UserModificationFailed
- : status.code();
return CommandHelpers::appendCommandStatus(
result,
- Status(code,
- str::stream() << "Failed to remove roles from \"" << dbname
- << "\" db from all users: "
- << status.reason()));
+ useDefaultCode(status, ErrorCodes::UserModificationFailed)
+ .withContext(str::stream() << "Failed to remove roles from \"" << dbname
+ << "\" db from all users"));
}
// Remove these roles from all other roles
@@ -2144,15 +2138,11 @@ public:
// Must invalidate even on bad status - what if the write succeeded but the GLE failed?
authzManager->invalidateUserCache();
if (!status.isOK()) {
- ErrorCodes::Error code = status.code() == ErrorCodes::UnknownError
- ? ErrorCodes::RoleModificationFailed
- : status.code();
return CommandHelpers::appendCommandStatus(
result,
- Status(code,
- str::stream() << "Failed to remove roles from \"" << dbname
- << "\" db from all roles: "
- << status.reason()));
+ useDefaultCode(status, ErrorCodes::RoleModificationFailed)
+ .withContext(str::stream() << "Failed to remove roles from \"" << dbname
+ << "\" db from all roles"));
}
audit::logDropAllRolesFromDatabase(Client::getCurrent(), dbname);
@@ -2164,12 +2154,11 @@ public:
if (!status.isOK()) {
return CommandHelpers::appendCommandStatus(
result,
- Status(status.code(),
- str::stream() << "Removed roles from \"" << dbname
- << "\" db "
- " from all users and roles but failed to actually delete"
- " those roles themselves: "
- << status.reason()));
+ status.withContext(
+ str::stream() << "Removed roles from \"" << dbname
+ << "\" db "
+ " from all users and roles but failed to actually delete"
+ " those roles themselves"));
}
result.append("n", nMatched);