summaryrefslogtreecommitdiff
path: root/src/mongo/db/auth/auth_index_d.cpp
diff options
context:
space:
mode:
authorAndreas Nilsson <andreas.nilsson@10gen.com>2014-11-13 11:52:34 -0500
committerAndreas Nilsson <andreas.nilsson@10gen.com>2014-11-13 11:55:50 -0500
commit2882b7b7e6606f8d45941fd83d9707bb8a4b3f7d (patch)
tree07306824f233e1742f1fe0d113b2b60281da9489 /src/mongo/db/auth/auth_index_d.cpp
parentd1cba25b72f41a2374eae4f74e12299196149580 (diff)
downloadmongo-2882b7b7e6606f8d45941fd83d9707bb8a4b3f7d.tar.gz
SERVER-15947 Prevent starting a 2.8 server with 2.4 auth indexes
Diffstat (limited to 'src/mongo/db/auth/auth_index_d.cpp')
-rw-r--r--src/mongo/db/auth/auth_index_d.cpp49
1 files changed, 22 insertions, 27 deletions
diff --git a/src/mongo/db/auth/auth_index_d.cpp b/src/mongo/db/auth/auth_index_d.cpp
index ddcb6986de7..410a6e24de6 100644
--- a/src/mongo/db/auth/auth_index_d.cpp
+++ b/src/mongo/db/auth/auth_index_d.cpp
@@ -74,38 +74,33 @@ namespace {
} // namespace
- void configureSystemIndexes(OperationContext* txn) {
- int authzVersion;
- Status status = getGlobalAuthorizationManager()->getAuthorizationVersion(
- txn, &authzVersion);
- if (!status.isOK()) {
- return;
- }
-
- if (authzVersion >= AuthorizationManager::schemaVersion26Final) {
- const NamespaceString systemUsers("admin", "system.users");
+ Status verifySystemIndexes(OperationContext* txn) {
+ const NamespaceString systemUsers = AuthorizationManager::usersCollectionNamespace;
- // Make sure the old unique index from v2.4 on system.users doesn't exist.
- AutoGetDb autoDb(txn, systemUsers.db(), MODE_X);
- if (!autoDb.getDb()) {
- return;
- }
+ // Make sure the old unique index from v2.4 on system.users doesn't exist.
+ AutoGetDb autoDb(txn, systemUsers.db(), MODE_X);
+ if (!autoDb.getDb()) {
+ return Status::OK();
+ }
- Collection* collection = autoDb.getDb()->getCollection(txn,
- NamespaceString(systemUsers));
- if (!collection) {
- return;
- }
+ Collection* collection = autoDb.getDb()->getCollection(txn,
+ NamespaceString(systemUsers));
+ if (!collection) {
+ return Status::OK();
+ }
- IndexCatalog* indexCatalog = collection->getIndexCatalog();
- IndexDescriptor* oldIndex = NULL;
+ IndexCatalog* indexCatalog = collection->getIndexCatalog();
+ IndexDescriptor* oldIndex = NULL;
- WriteUnitOfWork wunit(txn);
- while ((oldIndex = indexCatalog->findIndexByKeyPattern(txn, v1SystemUsersKeyPattern))) {
- indexCatalog->dropIndex(txn, oldIndex);
- }
- wunit.commit();
+ if (indexCatalog &&
+ (oldIndex = indexCatalog->findIndexByKeyPattern(txn, v1SystemUsersKeyPattern))) {
+ return Status(ErrorCodes::AuthSchemaIncompatible,
+ "Old 2.4 style user index identified. "
+ "The authentication schema needs to be updated by "
+ "running authSchemaUpgrade on a 2.6 server.");
}
+
+ return Status::OK();
}
void createSystemIndexes(OperationContext* txn, Collection* collection) {