diff options
-rw-r--r-- | src/couchdb/couch_config.erl | 10 | ||||
-rw-r--r-- | src/couchdb/couch_server.erl | 12 | ||||
-rwxr-xr-x | test/etap/082-config-register.t | 7 |
3 files changed, 21 insertions, 8 deletions
diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl index 69d0ac93..5d911455 100644 --- a/src/couchdb/couch_config.erl +++ b/src/couchdb/couch_config.erl @@ -128,7 +128,7 @@ handle_call({set, Sec, Key, Val, Persist}, _From, Config) -> _ -> ok end, - [catch F(Sec, Key, Val) || {_Pid, F} <- Config#config.notify_funs], + [catch F(Sec, Key, Val, Persist) || {_Pid, F} <- Config#config.notify_funs], {reply, ok, Config}; handle_call({delete, Sec, Key, Persist}, _From, Config) -> true = ets:delete(?MODULE, {Sec,Key}), @@ -140,7 +140,7 @@ handle_call({delete, Sec, Key, Persist}, _From, Config) -> _ -> ok end, - [catch F(Sec, Key, deleted) || {_Pid, F} <- Config#config.notify_funs], + [catch F(Sec, Key, deleted, Persist) || {_Pid, F} <- Config#config.notify_funs], {reply, ok, Config}; handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) -> erlang:monitor(process, Pid), @@ -148,10 +148,12 @@ handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) -> Fun2 = case Fun of _ when is_function(Fun, 1) -> - fun(Section, _Key, _Value) -> Fun(Section) end; + fun(Section, _Key, _Value, _Persist) -> Fun(Section) end; _ when is_function(Fun, 2) -> - fun(Section, Key, _Value) -> Fun(Section, Key) end; + fun(Section, Key, _Value, _Persist) -> Fun(Section, Key) end; _ when is_function(Fun, 3) -> + fun(Section, Key, Value, _Persist) -> Fun(Section, Key, Value) end; + _ when is_function(Fun, 4) -> Fun end, {reply, ok, Config#config{notify_funs=[{Pid, Fun2} | PidFuns]}}. diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl index 8fab42f1..afdf9365 100644 --- a/src/couchdb/couch_server.erl +++ b/src/couchdb/couch_server.erl @@ -95,13 +95,17 @@ get_full_filename(Server, DbName) -> filename:join([Server#server.root_dir, "./" ++ DbName ++ ".couch"]). hash_admin_passwords() -> + hash_admin_passwords(true). + +hash_admin_passwords(Persist) -> lists:foreach( fun({_User, "-hashed-" ++ _}) -> ok; % already hashed ({User, ClearPassword}) -> Salt = ?b2l(couch_uuids:random()), Hashed = couch_util:to_hex(crypto:sha(ClearPassword ++ Salt)), - couch_config:set("admins", User, "-hashed-" ++ Hashed ++ "," ++ Salt) + couch_config:set("admins", + User, "-hashed-" ++ Hashed ++ "," ++ Salt, Persist) end, couch_config:get("admins")). init([]) -> @@ -125,10 +129,10 @@ init([]) -> end), hash_admin_passwords(), ok = couch_config:register( - fun("admins") -> + fun("admins", _Key, _Value, Persist) -> % spawn here so couch_config doesn't try to call itself - spawn(fun() -> hash_admin_passwords() end) - end), + spawn(fun() -> hash_admin_passwords(Persist) end) + end, false), {ok, RegExp} = re:compile("^[a-z][a-z0-9\\_\\$()\\+\\-\\/]*$"), ets:new(couch_dbs_by_name, [set, private, named_table]), ets:new(couch_dbs_by_pid, [set, private, named_table]), diff --git a/test/etap/082-config-register.t b/test/etap/082-config-register.t index a35d96aa..416c45ee 100755 --- a/test/etap/082-config-register.t +++ b/test/etap/082-config-register.t @@ -84,4 +84,11 @@ test() -> "Implicitly test that the function got de-registered" ), + % test passing of Persist flag + couch_config:register( + fun("httpd", _, _, Persist) -> + etap:is(Persist, false) + end), + ok = couch_config:set("httpd", "port", "80", false), + ok. |