couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikewall...@apache.org
Subject [2/4] couch commit: updated refs/heads/2452-users-db-security-on-clustered-interface to 4e24b4c
Date Fri, 14 Nov 2014 19:35:05 GMT
Update auth DB docs via the auth module

Documents in the authentication DB were being updated directly
from couch_httpd_auth via couch_db:update_doc/3. This meant that
updates to documents with the authentication DB on the clustered
interface (5984) would fail.

This commit makes the auth module responsible for the document
update via a ?MODULE:update_auth_doc/1 function and add
couch_auth_cache:update_auth_doc/1 which proxies to
couch_db:update_doc/3.

COUCHDB-2452 2/3


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

Branch: refs/heads/2452-users-db-security-on-clustered-interface
Commit: 2ed693836af73c284c1f394a3c908ff3fcc30f59
Parents: cad071c
Author: Mike Wallace <mikewallace@apache.org>
Authored: Tue Nov 11 00:06:19 2014 +0000
Committer: Mike Wallace <mikewallace@apache.org>
Committed: Fri Nov 14 18:21:47 2014 +0000

----------------------------------------------------------------------
 src/couch_auth_cache.erl |  8 ++++++++
 src/couch_httpd_auth.erl | 13 +++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2ed69383/src/couch_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/couch_auth_cache.erl b/src/couch_auth_cache.erl
index 8cf631b..61ff9df 100644
--- a/src/couch_auth_cache.erl
+++ b/src/couch_auth_cache.erl
@@ -25,6 +25,8 @@
 -export([handle_config_change/5]).
 -export([handle_db_event/3]).
 
+-export([update_auth_doc/1]).
+
 -include_lib("couch/include/couch_db.hrl").
 -include("couch_js_functions.hrl").
 
@@ -455,3 +457,9 @@ auth_design_doc(DocId) ->
         {<<"validate_doc_update">>, ?AUTH_DB_DOC_VALIDATE_FUNCTION}
     ],
     {ok, couch_doc:from_json_obj({DocProps})}.
+
+update_auth_doc(Doc) ->
+    DbName = ?l2b(config:get("couch_httpd_auth", "authentication_db", "_users")),
+    couch_util:with_db(DbName, fun(UserDb) ->
+        couch_db:update_doc(UserDb, Doc, [])
+    end).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2ed69383/src/couch_httpd_auth.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_auth.erl b/src/couch_httpd_auth.erl
index 752dd20..a905b6c 100644
--- a/src/couch_httpd_auth.erl
+++ b/src/couch_httpd_auth.erl
@@ -367,14 +367,11 @@ maybe_upgrade_password_hash(UserName, Password, UserProps, AuthModule)
->
     IsAdmin = lists:member(<<"_admin">>, couch_util:get_value(<<"roles">>,
UserProps, [])),
     case {IsAdmin, couch_util:get_value(<<"password_scheme">>, UserProps, <<"simple">>)}
of
     {false, <<"simple">>} ->
-        DbName = ?l2b(config:get("couch_httpd_auth", "authentication_db", "_users")),
-        couch_util:with_db(DbName, fun(UserDb) ->
-            UserProps2 = proplists:delete(<<"password_sha">>, UserProps),
-            UserProps3 = [{<<"password">>, Password} | UserProps2],
-            NewUserDoc = couch_doc:from_json_obj({UserProps3}),
-            {ok, _NewRev} = couch_db:update_doc(UserDb, NewUserDoc, []),
-            AuthModule:get_user_creds(UserName)
-        end);
+        UserProps2 = proplists:delete(<<"password_sha">>, UserProps),
+        UserProps3 = [{<<"password">>, Password} | UserProps2],
+        NewUserDoc = couch_doc:from_json_obj({UserProps3}),
+        {ok, _NewRev} = AuthModule:update_auth_doc(NewUserDoc),
+        AuthModule:get_user_creds(UserName);
     _ ->
         UserProps
     end.


Mime
View raw message