~cmiller/ubuntu/karmic/couchdb/fix-init-overeager-su

« back to all changes in this revision

Viewing changes to src/couchdb/couch_httpd_auth.erl

  • Committer: Bazaar Package Importer
  • Author(s): Elliot Murphy
  • Date: 2009-08-31 09:06:26 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090831090626-2jnyuxjzrhzyg2f6
Tags: 0.10.0~svn809550-0ubuntu1
* New snapshot of couchdb 0.10.x stable prerelease branch (LP: #421971)
  - fixes a process leak in local changes feed consumer
  - disables internal gen_server timeouts
  - minimize the number of full commits
  - follow 302 redirects during replication
  - more precise and accurate calculation of replication progress
  - added crypto export notice to README
  - Fix for problem where HEAD requests that would have a chunked responses
    would send the chunked response anyway.
  - send deleted docs to changes filters and protect against missing
    filters.
  - merge cascading auth patch by Jason Davies, closes COUCHDB-478
* Drop debian/patches/oauth_ini_users.patch as it has been merged upstream.
* debian/postrm
  - don't try to delete couchdb system user/group (LP: #387945)

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    end.
46
46
 
47
47
basic_username_pw(Req) ->
48
 
    case header_value(Req, "Authorization") of
 
48
    AuthorizationHeader = header_value(Req, "Authorization"),
 
49
    case AuthorizationHeader of
49
50
    "Basic " ++ Base64Value ->
 
51
        io:format("~n~nBase64Value: '~p'~n~n", [Base64Value]),
50
52
        case string:tokens(?b2l(couch_util:decodeBase64(Base64Value)),":") of
51
53
        [User, Pass] ->
52
54
            {User, Pass};
109
111
 
110
112
% maybe we can use hovercraft to simplify running this view query
111
113
get_user(Db, UserName) ->
112
 
    DesignId = <<"_design/_auth">>,
113
 
    ViewName = <<"users">>,
114
 
    % if the design doc or the view doesn't exist, then make it
115
 
    ensure_users_view_exists(Db, DesignId, ViewName),
116
 
    
117
 
    case (catch couch_view:get_map_view(Db, DesignId, ViewName, nil)) of
118
 
    {ok, View, _Group} ->
119
 
        FoldlFun = fun
120
 
        ({{Key, _DocId}, Value}, _, nil) when Key == UserName -> {ok, Value};
121
 
        (_, _, Acc) -> {stop, Acc}
122
 
        end,
123
 
        case couch_view:fold(View, {UserName, nil}, fwd, FoldlFun, nil) of
124
 
        {ok, {Result}} -> Result;
125
 
        _Else -> nil
126
 
        end;
127
 
    {not_found, _Reason} ->
128
 
        nil
129
 
        % case (catch couch_view:get_reduce_view(Db, DesignId, ViewName, nil)) of
130
 
        % {ok, _ReduceView, _Group} ->
131
 
        %     not_implemented;
132
 
        % {not_found, _Reason} ->
133
 
        %     nil
134
 
        % end
 
114
    % In the future this will be pluggable. For now we check the .ini first,
 
115
    % then fall back to querying the db.
 
116
    io:format("~n~nget-user: '~p'~n", [get_user]),
 
117
    case couch_config:get("admins", ?b2l(UserName)) of
 
118
    "-hashed-" ++ HashedPwdAndSalt ->
 
119
        io:format("hashed: '~p'~n", [hashed]),
 
120
        [HashedPwd, Salt] = string:tokens(HashedPwdAndSalt, ","),
 
121
        [{<<"roles">>, [<<"_admin">>]},
 
122
          {<<"salt">>, ?l2b(Salt)},
 
123
          {<<"password_sha">>, ?l2b(HashedPwd)}];
 
124
    _ ->
 
125
        DesignId = <<"_design/_auth">>,
 
126
        ViewName = <<"users">>,
 
127
        % if the design doc or the view doesn't exist, then make it
 
128
        ensure_users_view_exists(Db, DesignId, ViewName),
 
129
 
 
130
        case (catch couch_view:get_map_view(Db, DesignId, ViewName, nil)) of
 
131
        {ok, View, _Group} ->
 
132
            FoldlFun = fun
 
133
            ({{Key, _DocId}, Value}, _, nil) when Key == UserName -> {ok, Value};
 
134
            (_, _, Acc) -> {stop, Acc}
 
135
            end,
 
136
            case couch_view:fold(View, {UserName, nil}, fwd, FoldlFun, nil) of
 
137
            {ok, {Result}} -> Result;
 
138
            _Else -> nil
 
139
            end;
 
140
        {not_found, _Reason} ->
 
141
            nil
 
142
            % case (catch couch_view:get_reduce_view(Db, DesignId, ViewName, nil)) of
 
143
            % {ok, _ReduceView, _Group} ->
 
144
            %     not_implemented;
 
145
            % {not_found, _Reason} ->
 
146
            %     nil
 
147
            % end
 
148
        end
135
149
    end.
136
150
    
137
151
ensure_users_db_exists(DbName) ->