summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2018-09-03 11:59:48 +0200
committerGarren Smith <garren.smith@gmail.com>2018-09-03 12:18:28 +0200
commit5e6d94d36abada6d1b1fa6d90bb4bf340745a7f0 (patch)
treec0c437e56b44aada312bea248f39848c68d4bf26
parent3aad6b66108e568c8b58b2328b55c707a0524611 (diff)
downloadcouchdb-no-system-db-partition.tar.gz
disallow creation of partitioned system dbno-system-db-partition
-rw-r--r--src/chttpd/src/chttpd_db.erl14
-rw-r--r--src/couch/src/couch_db.erl2
2 files changed, 10 insertions, 6 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 37289ebd6..c8012524b 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -338,7 +338,7 @@ create_db_req(#httpd{}=Req, DbName) ->
Q = chttpd:qs_value(Req, "q", config:get("cluster", "q", "8")),
P = chttpd:qs_value(Req, "placement", config:get("cluster", "placement")),
EngineOpt = parse_engine_opt(Req),
- Partitioned = parse_partitioned_opt(Req),
+ Partitioned = parse_partitioned_opt(Req, DbName),
Options = [
{n, N},
{q, Q},
@@ -1469,13 +1469,15 @@ parse_engine_opt(Req) ->
end.
-parse_partitioned_opt(Req) ->
- case chttpd:qs_value(Req, "partitioned") of
- undefined ->
+parse_partitioned_opt(Req, DbName) ->
+ case {chttpd:qs_value(Req, "partitioned"), couch_db:is_system_db(DbName)} of
+ {undefined, _ } ->
false;
- "true" ->
+ {"true", false} ->
true;
- _ ->
+ {"true", true} ->
+ throw({bad_request, <<"Cannot partition a system database">>});
+ {_, _} ->
throw({bad_request, <<"`partitioned` parameter can only be set to true.">>})
end.
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index a5c71d75d..cc11d776c 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -183,6 +183,8 @@ is_db(#db{}) ->
is_db(_) ->
false.
+is_system_db(DbName) when is_list(DbName); is_binary(DbName) ->
+ is_systemdb(DbName);
is_system_db(#db{options = Options}) ->
lists:member(sys_db, Options).