Skip to content

Commit

Permalink
Minor cleanup thanks to Joel Clark.
Browse files Browse the repository at this point in the history
Closes COUCHDB-669



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@915476 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
davisp committed Feb 23, 2010
1 parent 209ad16 commit c18afdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions THANKS
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ suggesting improvements or submitting changes. Some of these people are:
* Jan Kassens <jan@kassens.net> * Jan Kassens <jan@kassens.net>
* James Marca <jmarca@translab.its.uci.edu> * James Marca <jmarca@translab.its.uci.edu>
* Matt Goodall <matt.goodall@gmail.com> * Matt Goodall <matt.goodall@gmail.com>
* Joel Clark <unsigned_char@yahoo.com>


For a list of authors see the `AUTHORS` file. For a list of authors see the `AUTHORS` file.
13 changes: 7 additions & 6 deletions src/couchdb/couch_httpd_auth.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ cookie_authentication_handler(#httpd{mochi_req=MochiReq}=Req) ->
throw({bad_request, Reason}) throw({bad_request, Reason})
end, end,
% Verify expiry and hash % Verify expiry and hash
{NowMS, NowS, _} = erlang:now(), CurrentTime = make_cookie_time(),
CurrentTime = NowMS * 1000000 + NowS,
case couch_config:get("couch_httpd_auth", "secret", nil) of case couch_config:get("couch_httpd_auth", "secret", nil) of
nil -> nil ->
?LOG_ERROR("cookie auth secret is not set",[]), ?LOG_ERROR("cookie auth secret is not set",[]),
Expand Down Expand Up @@ -362,8 +361,7 @@ cookie_auth_header(#httpd{user_ctx=#user_ctx{name=User}, auth={Secret, true}}, H
Cookies = mochiweb_cookies:parse_cookie(CookieHeader), Cookies = mochiweb_cookies:parse_cookie(CookieHeader),
AuthSession = proplists:get_value("AuthSession", Cookies), AuthSession = proplists:get_value("AuthSession", Cookies),
if AuthSession == undefined -> if AuthSession == undefined ->
{NowMS, NowS, _} = erlang:now(), TimeStamp = make_cookie_time(),
TimeStamp = NowMS * 1000000 + NowS,
[cookie_auth_cookie(?b2l(User), Secret, TimeStamp)]; [cookie_auth_cookie(?b2l(User), Secret, TimeStamp)];
true -> true ->
[] []
Expand Down Expand Up @@ -414,8 +412,7 @@ handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) ->
true -> true ->
% setup the session cookie % setup the session cookie
Secret = ?l2b(ensure_cookie_auth_secret()), Secret = ?l2b(ensure_cookie_auth_secret()),
{NowMS, NowS, _} = erlang:now(), CurrentTime = make_cookie_time(),
CurrentTime = NowMS * 1000000 + NowS,
Cookie = cookie_auth_cookie(?b2l(UserName), <<Secret/binary, UserSalt/binary>>, CurrentTime), Cookie = cookie_auth_cookie(?b2l(UserName), <<Secret/binary, UserSalt/binary>>, CurrentTime),
% TODO document the "next" feature in Futon % TODO document the "next" feature in Futon
{Code, Headers} = case couch_httpd:qs_value(Req, "next", nil) of {Code, Headers} = case couch_httpd:qs_value(Req, "next", nil) of
Expand Down Expand Up @@ -487,3 +484,7 @@ to_int(Value) when is_list(Value) ->
list_to_integer(Value); list_to_integer(Value);
to_int(Value) when is_integer(Value) -> to_int(Value) when is_integer(Value) ->
Value. Value.

make_cookie_time() ->
{NowMS, NowS, _} = erlang:now(),
NowMS * 1000000 + NowS.

0 comments on commit c18afdf

Please sign in to comment.