]> granicus.if.org Git - ejabberd/commitdiff
Fix return type in try_set_password()
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Sun, 7 Jul 2019 09:16:04 +0000 (12:16 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Sun, 7 Jul 2019 09:16:04 +0000 (12:16 +0300)
Fixes #2932

src/ejabberd_auth.erl
src/mod_register.erl

index 1c5eddfd82a3ca939d18149c2ab94214b6654b7a..c5fda7d34d7964e5f4d8e1b80c8639356179f8a1 100644 (file)
@@ -73,7 +73,7 @@
 -callback plain_password_required(binary()) -> boolean().
 -callback store_type(binary()) -> plain | external | scram.
 -callback set_password(binary(), binary(), password()) ->
-    {ets_cache:tag(), {ok, password()} | {error, db_failure}}.
+    {ets_cache:tag(), {ok, password()} | {error, db_failure | not_allowed}}.
 -callback remove_user(binary(), binary()) -> ok | {error, db_failure | not_allowed}.
 -callback user_exists(binary(), binary()) -> {ets_cache:tag(), boolean() | {error, db_failure}}.
 -callback check_password(binary(), binary(), binary(), binary()) -> {ets_cache:tag(), boolean()}.
@@ -252,7 +252,9 @@ check_password_with_authmodule(User, AuthzId, Server, Password, Digest, DigestGe
            false
     end.
 
--spec set_password(binary(), binary(), password()) -> ok | {error, atom()}.
+-spec set_password(binary(), binary(), password()) -> ok | {error,
+                                                           db_failure | not_allowed |
+                                                           invalid_jid | invalid_password}.
 set_password(User, Server, Password) ->
     case validate_credentials(User, Server, Password) of
        {ok, LUser, LServer} ->
@@ -266,7 +268,9 @@ set_password(User, Server, Password) ->
            Err
     end.
 
--spec try_register(binary(), binary(), password()) -> ok | {error, atom()}.
+-spec try_register(binary(), binary(), password()) -> ok | {error,
+                                                           db_failure | not_allowed | exists |
+                                                           invalid_jid | invalid_password}.
 try_register(User, Server, Password) ->
     case validate_credentials(User, Server, Password) of
        {ok, LUser, LServer} ->
@@ -537,6 +541,7 @@ password_format(LServer) ->
 %%%----------------------------------------------------------------------
 %%% Backend calls
 %%%----------------------------------------------------------------------
+-spec db_try_register(binary(), binary(), password(), module()) -> ok | {error, exists | db_failure | not_allowed}.
 db_try_register(User, Server, Password, Mod) ->
     case erlang:function_exported(Mod, try_register, 3) of
        true ->
@@ -544,22 +549,24 @@ db_try_register(User, Server, Password, Mod) ->
                            scram -> password_to_scram(Password);
                            _ -> Password
                        end,
-           case use_cache(Mod, Server) of
-               true ->
-                   case ets_cache:update(
-                          cache_tab(Mod), {User, Server}, {ok, Password},
-                          fun() -> Mod:try_register(User, Server, Password1) end,
-                          cache_nodes(Mod, Server)) of
-                       {ok, _} -> ok;
-                       {error, _} = Err -> Err
-                   end;
-               false ->
-                   ets_cache:untag(Mod:try_register(User, Server, Password1))
+           Ret = case use_cache(Mod, Server) of
+                     true ->
+                         ets_cache:update(
+                           cache_tab(Mod), {User, Server}, {ok, Password},
+                           fun() -> Mod:try_register(User, Server, Password1) end,
+                           cache_nodes(Mod, Server));
+                     false ->
+                         ets_cache:untag(Mod:try_register(User, Server, Password1))
+                 end,
+           case Ret of
+               {ok, _} -> ok;
+               {error, _} = Err -> Err
            end;
        false ->
            {error, not_allowed}
     end.
 
+-spec db_set_password(binary(), binary(), password(), module()) -> ok | {error, db_failure | not_allowed}.
 db_set_password(User, Server, Password, Mod) ->
     case erlang:function_exported(Mod, set_password, 3) of
        true ->
@@ -567,17 +574,18 @@ db_set_password(User, Server, Password, Mod) ->
                            scram -> password_to_scram(Password);
                            _ -> Password
                        end,
-           case use_cache(Mod, Server) of
-               true ->
-                   case ets_cache:update(
-                          cache_tab(Mod), {User, Server}, {ok, Password},
-                          fun() -> Mod:set_password(User, Server, Password1) end,
-                          cache_nodes(Mod, Server)) of
-                       {ok, _} -> ok;
-                       {error, _} = Err -> Err
-                   end;
-               false ->
-                   ets_cache:untag(Mod:set_password(User, Server, Password1))
+           Ret = case use_cache(Mod, Server) of
+                     true ->
+                         ets_cache:update(
+                           cache_tab(Mod), {User, Server}, {ok, Password},
+                           fun() -> Mod:set_password(User, Server, Password1) end,
+                           cache_nodes(Mod, Server));
+                     false ->
+                         ets_cache:untag(Mod:set_password(User, Server, Password1))
+                 end,
+           case Ret of
+               {ok, _} -> ok;
+               {error, _} = Err -> Err
            end;
        false ->
            {error, not_allowed}
index ee5b76db325b412365df52f67a1f8137e29abaee..9ac3f6c06fb4fed890f1a1dd7d27f599d2ccbd5c 100644 (file)
@@ -297,13 +297,7 @@ try_set_password(User, Server, Password, #iq{lang = Lang, meta = M} = IQ) ->
            xmpp:make_error(IQ, xmpp:err_not_allowed(format_error(Why), Lang));
        {error, weak_password = Why} ->
            xmpp:make_error(IQ, xmpp:err_not_acceptable(format_error(Why), Lang));
-       {error, empty_password = Why} ->
-           xmpp:make_error(IQ, xmpp:err_bad_request(format_error(Why), Lang));
        {error, db_failure = Why} ->
-           xmpp:make_error(IQ, xmpp:err_internal_server_error(format_error(Why), Lang));
-       {error, Why} ->
-           ?ERROR_MSG("Failed to change password for user ~s@~s: ~s",
-                      [User, Server, format_error(Why)]),
            xmpp:make_error(IQ, xmpp:err_internal_server_error(format_error(Why), Lang))
     end.
 
@@ -367,10 +361,6 @@ try_register(User, Server, Password, SourceRaw, Lang) ->
        {error, exists = Why} ->
            {error, xmpp:err_conflict(format_error(Why), Lang)};
        {error, db_failure = Why} ->
-           {error, xmpp:err_internal_server_error(format_error(Why), Lang)};
-       {error, Why} ->
-           ?ERROR_MSG("Failed to register user ~s@~s: ~s",
-                      [User, Server, format_error(Why)]),
            {error, xmpp:err_internal_server_error(format_error(Why), Lang)}
     end.
 
@@ -384,8 +374,6 @@ format_error(weak_password) ->
     ?T("The password is too weak");
 format_error(invalid_password) ->
     ?T("The password contains unacceptable characters");
-format_error(empty_password) ->
-    ?T("Empty password");
 format_error(not_allowed) ->
     ?T("Not allowed");
 format_error(exists) ->