Skip to content

Commit

Permalink
Apply fixes and remove tests for missing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mremond committed Apr 1, 2016
1 parent 47266de commit e24da57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 363 deletions.
48 changes: 31 additions & 17 deletions src/mod_admin_extra.erl
Expand Up @@ -590,36 +590,35 @@ remove_node(Node) ->
%%%

set_password(User, Host, Password) ->
case ejabberd_auth:set_password(User, Host, Password) of
ok ->
ok;
_ ->
error
end.
Fun = fun () -> ejabberd_auth:set_password(User, Host, Password) end,
user_action(User, Host, Fun, ok).

%% Copied some code from ejabberd_commands.erl
check_password_hash(User, Host, PasswordHash, HashMethod) ->
AccountPass = ejabberd_auth:get_password_s(User, Host),
AccountPassHash = case {AccountPass, HashMethod} of
{A, _} when is_tuple(A) -> scrammed;
{_, "md5"} -> get_md5(AccountPass);
{_, "sha"} -> get_sha(AccountPass);
_ -> undefined
{_, <<"md5">>} -> get_md5(AccountPass);
{_, <<"sha">>} -> get_sha(AccountPass);
{_, _Method} ->
?ERROR_MSG("check_password_hash called "
"with hash method", [_Method]),
undefined
end,
case AccountPassHash of
scrammed ->
?ERROR_MSG("Passwords are scrammed, and check_password_hash can not work.", []),
?ERROR_MSG("Passwords are scrammed, and check_password_hash cannot work.", []),
throw(passwords_scrammed_command_cannot_work);
undefined -> error;
undefined -> throw(unkown_hash_method);
PasswordHash -> ok;
_ -> error
_ -> false
end.
get_md5(AccountPass) ->
lists:flatten([io_lib:format("~.16B", [X])
|| X <- binary_to_list(erlang:md5(AccountPass))]).
iolist_to_binary([io_lib:format("~2.16.0B", [X])
|| X <- binary_to_list(erlang:md5(AccountPass))]).
get_sha(AccountPass) ->
lists:flatten([io_lib:format("~.16B", [X])
|| X <- binary_to_list(p1_sha:sha1(AccountPass))]).
iolist_to_binary([io_lib:format("~2.16.0B", [X])
|| X <- binary_to_list(p1_sha:sha1(AccountPass))]).

num_active_users(Host, Days) ->
list_last_activity(Host, true, Days).
Expand Down Expand Up @@ -782,7 +781,8 @@ resource_num(User, Host, Num) ->
true ->
lists:nth(Num, Resources);
false ->
lists:flatten(io_lib:format("Error: Wrong resource number: ~p", [Num]))
throw({bad_argument,
lists:flatten(io_lib:format("Wrong resource number: ~p", [Num]))})
end.

kick_session(User, Server, Resource, ReasonText) ->
Expand Down Expand Up @@ -1569,6 +1569,20 @@ decide_rip_jid({UName, UServer}, Match_list) ->
end,
Match_list).

user_action(User, Server, Fun, OK) ->
case ejabberd_auth:is_user_exists(User, Server) of
true ->
case catch Fun() of
OK -> ok;
{error, Error} -> throw(Error);
Error ->
?ERROR_MSG("Command returned: ~p", [Error]),
1
end;
false ->
throw({not_found, "unknown_user"})
end.

%% Copied from ejabberd-2.0.0/src/acl.erl
is_regexp_match(String, RegExp) ->
case ejabberd_regexp:run(String, RegExp) of
Expand Down

0 comments on commit e24da57

Please sign in to comment.