mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
parent
fd8e5ffce7
commit
368858a744
@ -73,7 +73,7 @@
|
|||||||
-callback plain_password_required(binary()) -> boolean().
|
-callback plain_password_required(binary()) -> boolean().
|
||||||
-callback store_type(binary()) -> plain | external | scram.
|
-callback store_type(binary()) -> plain | external | scram.
|
||||||
-callback set_password(binary(), binary(), password()) ->
|
-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 remove_user(binary(), binary()) -> ok | {error, db_failure | not_allowed}.
|
||||||
-callback user_exists(binary(), binary()) -> {ets_cache:tag(), boolean() | {error, db_failure}}.
|
-callback user_exists(binary(), binary()) -> {ets_cache:tag(), boolean() | {error, db_failure}}.
|
||||||
-callback check_password(binary(), binary(), binary(), binary()) -> {ets_cache:tag(), boolean()}.
|
-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
|
false
|
||||||
end.
|
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) ->
|
set_password(User, Server, Password) ->
|
||||||
case validate_credentials(User, Server, Password) of
|
case validate_credentials(User, Server, Password) of
|
||||||
{ok, LUser, LServer} ->
|
{ok, LUser, LServer} ->
|
||||||
@ -266,7 +268,9 @@ set_password(User, Server, Password) ->
|
|||||||
Err
|
Err
|
||||||
end.
|
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) ->
|
try_register(User, Server, Password) ->
|
||||||
case validate_credentials(User, Server, Password) of
|
case validate_credentials(User, Server, Password) of
|
||||||
{ok, LUser, LServer} ->
|
{ok, LUser, LServer} ->
|
||||||
@ -537,6 +541,7 @@ password_format(LServer) ->
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% Backend calls
|
%%% Backend calls
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
-spec db_try_register(binary(), binary(), password(), module()) -> ok | {error, exists | db_failure | not_allowed}.
|
||||||
db_try_register(User, Server, Password, Mod) ->
|
db_try_register(User, Server, Password, Mod) ->
|
||||||
case erlang:function_exported(Mod, try_register, 3) of
|
case erlang:function_exported(Mod, try_register, 3) of
|
||||||
true ->
|
true ->
|
||||||
@ -544,22 +549,24 @@ db_try_register(User, Server, Password, Mod) ->
|
|||||||
scram -> password_to_scram(Password);
|
scram -> password_to_scram(Password);
|
||||||
_ -> Password
|
_ -> Password
|
||||||
end,
|
end,
|
||||||
case use_cache(Mod, Server) of
|
Ret = case use_cache(Mod, Server) of
|
||||||
true ->
|
true ->
|
||||||
case ets_cache:update(
|
ets_cache:update(
|
||||||
cache_tab(Mod), {User, Server}, {ok, Password},
|
cache_tab(Mod), {User, Server}, {ok, Password},
|
||||||
fun() -> Mod:try_register(User, Server, Password1) end,
|
fun() -> Mod:try_register(User, Server, Password1) end,
|
||||||
cache_nodes(Mod, Server)) of
|
cache_nodes(Mod, Server));
|
||||||
{ok, _} -> ok;
|
false ->
|
||||||
{error, _} = Err -> Err
|
ets_cache:untag(Mod:try_register(User, Server, Password1))
|
||||||
end;
|
end,
|
||||||
false ->
|
case Ret of
|
||||||
ets_cache:untag(Mod:try_register(User, Server, Password1))
|
{ok, _} -> ok;
|
||||||
|
{error, _} = Err -> Err
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
||||||
{error, not_allowed}
|
{error, not_allowed}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec db_set_password(binary(), binary(), password(), module()) -> ok | {error, db_failure | not_allowed}.
|
||||||
db_set_password(User, Server, Password, Mod) ->
|
db_set_password(User, Server, Password, Mod) ->
|
||||||
case erlang:function_exported(Mod, set_password, 3) of
|
case erlang:function_exported(Mod, set_password, 3) of
|
||||||
true ->
|
true ->
|
||||||
@ -567,17 +574,18 @@ db_set_password(User, Server, Password, Mod) ->
|
|||||||
scram -> password_to_scram(Password);
|
scram -> password_to_scram(Password);
|
||||||
_ -> Password
|
_ -> Password
|
||||||
end,
|
end,
|
||||||
case use_cache(Mod, Server) of
|
Ret = case use_cache(Mod, Server) of
|
||||||
true ->
|
true ->
|
||||||
case ets_cache:update(
|
ets_cache:update(
|
||||||
cache_tab(Mod), {User, Server}, {ok, Password},
|
cache_tab(Mod), {User, Server}, {ok, Password},
|
||||||
fun() -> Mod:set_password(User, Server, Password1) end,
|
fun() -> Mod:set_password(User, Server, Password1) end,
|
||||||
cache_nodes(Mod, Server)) of
|
cache_nodes(Mod, Server));
|
||||||
{ok, _} -> ok;
|
false ->
|
||||||
{error, _} = Err -> Err
|
ets_cache:untag(Mod:set_password(User, Server, Password1))
|
||||||
end;
|
end,
|
||||||
false ->
|
case Ret of
|
||||||
ets_cache:untag(Mod:set_password(User, Server, Password1))
|
{ok, _} -> ok;
|
||||||
|
{error, _} = Err -> Err
|
||||||
end;
|
end;
|
||||||
false ->
|
false ->
|
||||||
{error, not_allowed}
|
{error, not_allowed}
|
||||||
|
@ -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));
|
xmpp:make_error(IQ, xmpp:err_not_allowed(format_error(Why), Lang));
|
||||||
{error, weak_password = Why} ->
|
{error, weak_password = Why} ->
|
||||||
xmpp:make_error(IQ, xmpp:err_not_acceptable(format_error(Why), Lang));
|
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} ->
|
{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))
|
xmpp:make_error(IQ, xmpp:err_internal_server_error(format_error(Why), Lang))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -367,10 +361,6 @@ try_register(User, Server, Password, SourceRaw, Lang) ->
|
|||||||
{error, exists = Why} ->
|
{error, exists = Why} ->
|
||||||
{error, xmpp:err_conflict(format_error(Why), Lang)};
|
{error, xmpp:err_conflict(format_error(Why), Lang)};
|
||||||
{error, db_failure = Why} ->
|
{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)}
|
{error, xmpp:err_internal_server_error(format_error(Why), Lang)}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -384,8 +374,6 @@ format_error(weak_password) ->
|
|||||||
?T("The password is too weak");
|
?T("The password is too weak");
|
||||||
format_error(invalid_password) ->
|
format_error(invalid_password) ->
|
||||||
?T("The password contains unacceptable characters");
|
?T("The password contains unacceptable characters");
|
||||||
format_error(empty_password) ->
|
|
||||||
?T("Empty password");
|
|
||||||
format_error(not_allowed) ->
|
format_error(not_allowed) ->
|
||||||
?T("Not allowed");
|
?T("Not allowed");
|
||||||
format_error(exists) ->
|
format_error(exists) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user