couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikewall...@apache.org
Subject chttpd commit: updated refs/heads/2452-users-db-security-on-clustered-interface to f2fcc28
Date Thu, 04 Dec 2014 10:52:23 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/2452-users-db-security-on-clustered-interface 25ec565c1 -> f2fcc285a


Restart changes listener on config changes

Previously if chttpd_auth/authentication_db was changed in the
config then a changes listener would not be started for the new
authentication DB until the current changes request timed out.
During that time any changes to the users DB (e.g. password
changes) would not take effect. This is primarily a problem when
running share/www/script/test/users_db_security.js however it could
conceivably become a problem under normal running conditions.

This commit adds a config listener which causes the current changes
listener to be killed when the chttpd_auth/authentication_db config
value is changed. It will then be restarted via the existing
handle_info/2 clause.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/f2fcc285
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/f2fcc285
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/f2fcc285

Branch: refs/heads/2452-users-db-security-on-clustered-interface
Commit: f2fcc285a4dfee352a8348ec6ad0f251543c5f3b
Parents: 25ec565
Author: Mike Wallace <mikewallace@apache.org>
Authored: Wed Nov 26 23:05:38 2014 +0000
Committer: Mike Wallace <mikewallace@apache.org>
Committed: Wed Nov 26 23:05:38 2014 +0000

----------------------------------------------------------------------
 src/chttpd_auth_cache.erl | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/f2fcc285/src/chttpd_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_auth_cache.erl b/src/chttpd_auth_cache.erl
index afe522a..550858a 100644
--- a/src/chttpd_auth_cache.erl
+++ b/src/chttpd_auth_cache.erl
@@ -12,12 +12,14 @@
 
 -module(chttpd_auth_cache).
 -behaviour(gen_server).
+-behaviour(config_listener).
 
 -export([start_link/0, get_user_creds/1]).
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
 	 code_change/3]).
 -export([listen_for_changes/1, changes_callback/2]).
 -export([update_auth_doc/1]).
+-export([handle_config_change/5]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -76,8 +78,12 @@ get_from_cache(UserName) ->
 %% gen_server callbacks
 
 init([]) ->
+    ok = config:listen_for_changes(?MODULE, nil),
     {ok, #state{changes_pid = spawn_changes(0)}}.
 
+handle_call(restart_listener, _From, #state{changes_pid=Pid} = State) ->
+    exit(Pid, kill),
+    {reply, ok, State};
 handle_call(_Call, _From, State) ->
     {noreply, State}.
 
@@ -96,6 +102,12 @@ handle_info({'DOWN', _, _, Pid, Reason}, #state{changes_pid=Pid} = State)
->
     {noreply, State#state{last_seq=Seq}};
 handle_info({start_listener, Seq}, State) ->
     {noreply, State#state{changes_pid = spawn_changes(Seq)}};
+handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
+    erlang:send_after(5000, self(), restart_config_listener),
+    {noreply, State};
+handle_info(restart_config_listener, State) ->
+    ok = config:listen_for_changes(?MODULE, nil),
+    {noreply, State};
 handle_info(_Msg, State) ->
     {noreply, State}.
 
@@ -105,6 +117,11 @@ terminate(_Reason, #state{changes_pid = Pid}) ->
 code_change(_OldVsn, #state{}=State, _Extra) ->
     {ok, State}.
 
+handle_config_change("chttpd_auth", "authentication_db", _, _, _) ->
+    {ok, gen_server:call(?MODULE, restart_listener, infinity)};
+handle_config_change(_, _, _, _, _) ->
+    {ok, nil}.
+
 %% private functions
 
 spawn_changes(Since) ->


Mime
View raw message