diff options
author | Robert Guo <robert.guo@10gen.com> | 2016-03-22 17:10:50 -0400 |
---|---|---|
committer | Robert Guo <robert.guo@10gen.com> | 2016-03-29 13:08:43 -0400 |
commit | e242b49373f0a9ee39f2b02f1a766a84c2c869b6 (patch) | |
tree | 3eaf08b0a85cbfde4b041f944001232d5e55e6e6 /src/mongo/db/namespace_string.h | |
parent | ea07e34466f14b127ac97f58ec6a40e9e52ebbd5 (diff) | |
download | mongo-e242b49373f0a9ee39f2b02f1a766a84c2c869b6.tar.gz |
SERVER-22577 disallow creation of databases containing $ on mmapv1
Diffstat (limited to 'src/mongo/db/namespace_string.h')
-rw-r--r-- | src/mongo/db/namespace_string.h | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index 5a891df19c0..65d23736dee 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -96,6 +96,16 @@ public: MaxNsCollectionLen = MaxNsLen - 7 /*strlen(".$extra")*/, }; + /** + * DollarInDbNameBehavior::allow is deprecated. + * Please use DollarInDbNameBehavior::disallow and check explicitly for any DB names that must + * contain a $. + */ + enum class DollarInDbNameBehavior { + Disallow, + Allow, // Deprecated + }; + StringData db() const; StringData coll() const; @@ -165,7 +175,7 @@ public: * valid. */ bool isValid() const { - return validDBName(db()) && !coll().empty(); + return validDBName(db(), DollarInDbNameBehavior::Allow) && !coll().empty(); } bool operator==(const std::string& nsIn) const { @@ -220,12 +230,12 @@ public: /** * Returns true for DBs with special meaning to mongodb. */ - static bool internalDb(StringData ns) { - if (ns == "admin") + static bool internalDb(StringData db) { + if (db == "admin") return true; - if (ns == "local") + if (db == "local") return true; - if (ns == "config") + if (db == "config") return true; return false; } @@ -242,9 +252,12 @@ public: * foo"bar * * @param db - a possible database name + * @param DollarInDbNameBehavior - please do not change the default value. DB names that must + * contain a $ should be checked explicitly. * @return if db is an allowed database name */ - static bool validDBName(StringData dbin); + static bool validDBName(StringData db, + DollarInDbNameBehavior behavior = DollarInDbNameBehavior::Disallow); /** * Takes a fully qualified namespace (ie dbname.collectionName), and returns true if |