Skip to content

Commit

Permalink
COUCHDB-1060 - Prevent _admin appearing twice
Browse files Browse the repository at this point in the history
  • Loading branch information
rnewson authored and benoitc committed May 5, 2012
1 parent c21a740 commit aef088b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/couch_httpd/src/couch_auth_cache.erl
Expand Up @@ -49,15 +49,15 @@ get_user_creds(UserName) ->
[HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","),
case get_from_cache(UserName) of
nil ->
make_admin_doc(HashedPwd, Salt, [<<"_admin">>]);
make_admin_doc(HashedPwd, Salt, []);
UserProps when is_list(UserProps) ->
make_admin_doc(HashedPwd, Salt, couch_util:get_value(<<"roles">>, UserProps))
end;
"-pbkdf2-" ++ HashedPwdSaltAndIterations ->
[HashedPwd, Salt, Iterations] = string:tokens(HashedPwdSaltAndIterations, ","),
case get_from_cache(UserName) of
nil ->
make_admin_doc(HashedPwd, Salt, Iterations, [<<"_admin">>]);
make_admin_doc(HashedPwd, Salt, Iterations, []);
UserProps when is_list(UserProps) ->
make_admin_doc(HashedPwd, Salt, Iterations, couch_util:get_value(<<"roles">>, UserProps))
end;
Expand All @@ -66,14 +66,14 @@ get_user_creds(UserName) ->
end,
validate_user_creds(UserCreds).

make_admin_doc(HashedPwd, Salt, Roles) ->
[{<<"roles">>, Roles},
make_admin_doc(HashedPwd, Salt, ExtraRoles) ->
[{<<"roles">>, [<<"_admin">>|ExtraRoles]},
{<<"salt">>, ?l2b(Salt)},
{<<"password_scheme">>, <<"simple">>},
{<<"password_sha">>, ?l2b(HashedPwd)}].

make_admin_doc(DerivedKey, Salt, Iterations, Roles) ->
[{<<"roles">>, [<<"_admin">>|Roles]},
make_admin_doc(DerivedKey, Salt, Iterations, ExtraRoles) ->
[{<<"roles">>, [<<"_admin">>|ExtraRoles]},
{<<"salt">>, ?l2b(Salt)},
{<<"iterations">>, list_to_integer(Iterations)},
{<<"password_scheme">>, <<"pbkdf2">>},
Expand Down

0 comments on commit aef088b

Please sign in to comment.