Do not try to fetch module options via eldap_utils
This commit is contained in:
parent
ea7de2097f
commit
a9f7d9481f
|
@ -360,7 +360,7 @@ parse_options(Host) ->
|
||||||
Eldap_ID = jlib:atom_to_binary(gen_mod:get_module_proc(Host, ?MODULE)),
|
Eldap_ID = jlib:atom_to_binary(gen_mod:get_module_proc(Host, ?MODULE)),
|
||||||
Bind_Eldap_ID = jlib:atom_to_binary(
|
Bind_Eldap_ID = jlib:atom_to_binary(
|
||||||
gen_mod:get_module_proc(Host, bind_ejabberd_auth_ldap)),
|
gen_mod:get_module_proc(Host, bind_ejabberd_auth_ldap)),
|
||||||
UIDsTemp = eldap_utils:get_opt(
|
UIDsTemp = gen_mod:get_opt(
|
||||||
{ldap_uids, Host}, [],
|
{ldap_uids, Host}, [],
|
||||||
fun(Us) ->
|
fun(Us) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
|
@ -375,7 +375,7 @@ parse_options(Host) ->
|
||||||
end, [{<<"uid">>, <<"%u">>}]),
|
end, [{<<"uid">>, <<"%u">>}]),
|
||||||
UIDs = eldap_utils:uids_domain_subst(Host, UIDsTemp),
|
UIDs = eldap_utils:uids_domain_subst(Host, UIDsTemp),
|
||||||
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
||||||
UserFilter = case eldap_utils:get_opt(
|
UserFilter = case gen_mod:get_opt(
|
||||||
{ldap_filter, Host}, [],
|
{ldap_filter, Host}, [],
|
||||||
fun check_filter/1, <<"">>) of
|
fun check_filter/1, <<"">>) of
|
||||||
<<"">> ->
|
<<"">> ->
|
||||||
|
@ -386,7 +386,7 @@ parse_options(Host) ->
|
||||||
SearchFilter = eldap_filter:do_sub(UserFilter,
|
SearchFilter = eldap_filter:do_sub(UserFilter,
|
||||||
[{<<"%u">>, <<"*">>}]),
|
[{<<"%u">>, <<"*">>}]),
|
||||||
{DNFilter, DNFilterAttrs} =
|
{DNFilter, DNFilterAttrs} =
|
||||||
eldap_utils:get_opt({ldap_dn_filter, Host}, [],
|
gen_mod:get_opt({ldap_dn_filter, Host}, [],
|
||||||
fun([{DNF, DNFA}]) ->
|
fun([{DNF, DNFA}]) ->
|
||||||
NewDNFA = case DNFA of
|
NewDNFA = case DNFA of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
@ -398,7 +398,7 @@ parse_options(Host) ->
|
||||||
NewDNF = check_filter(DNF),
|
NewDNF = check_filter(DNF),
|
||||||
{NewDNF, NewDNFA}
|
{NewDNF, NewDNFA}
|
||||||
end, {undefined, []}),
|
end, {undefined, []}),
|
||||||
LocalFilter = eldap_utils:get_opt(
|
LocalFilter = gen_mod:get_opt(
|
||||||
{ldap_local_filter, Host}, [], fun(V) -> V end),
|
{ldap_local_filter, Host}, [], fun(V) -> V end),
|
||||||
#state{host = Host, eldap_id = Eldap_ID,
|
#state{host = Host, eldap_id = Eldap_ID,
|
||||||
bind_eldap_id = Bind_Eldap_ID,
|
bind_eldap_id = Bind_Eldap_ID,
|
||||||
|
|
|
@ -33,8 +33,6 @@
|
||||||
make_filter/2,
|
make_filter/2,
|
||||||
get_state/2,
|
get_state/2,
|
||||||
case_insensitive_match/2,
|
case_insensitive_match/2,
|
||||||
get_opt/3,
|
|
||||||
get_opt/4,
|
|
||||||
get_config/2,
|
get_config/2,
|
||||||
decode_octet_string/3,
|
decode_octet_string/3,
|
||||||
uids_domain_subst/2]).
|
uids_domain_subst/2]).
|
||||||
|
@ -171,64 +169,48 @@ uids_domain_subst(Host, UIDs) ->
|
||||||
end,
|
end,
|
||||||
UIDs).
|
UIDs).
|
||||||
|
|
||||||
-spec get_opt({atom(), binary()}, list(), fun()) -> any().
|
|
||||||
|
|
||||||
get_opt({Key, Host}, Opts, F) ->
|
|
||||||
get_opt({Key, Host}, Opts, F, undefined).
|
|
||||||
|
|
||||||
-spec get_opt({atom(), binary()}, list(), fun(), any()) -> any().
|
|
||||||
|
|
||||||
get_opt({Key, Host}, Opts, F, Default) ->
|
|
||||||
case gen_mod:get_opt(Key, Opts, F, undefined) of
|
|
||||||
undefined ->
|
|
||||||
ejabberd_config:get_option(
|
|
||||||
{Key, Host}, F, Default);
|
|
||||||
Val ->
|
|
||||||
Val
|
|
||||||
end.
|
|
||||||
|
|
||||||
-spec get_config(binary(), list()) -> eldap_config().
|
-spec get_config(binary(), list()) -> eldap_config().
|
||||||
|
|
||||||
get_config(Host, Opts) ->
|
get_config(Host, Opts) ->
|
||||||
Servers = get_opt({ldap_servers, Host}, Opts,
|
Servers = gen_mod:get_opt({ldap_servers, Host}, Opts,
|
||||||
fun(L) ->
|
fun(L) ->
|
||||||
[iolist_to_binary(H) || H <- L]
|
[iolist_to_binary(H) || H <- L]
|
||||||
end, [<<"localhost">>]),
|
end, [<<"localhost">>]),
|
||||||
Backups = get_opt({ldap_backups, Host}, Opts,
|
Backups = gen_mod:get_opt({ldap_backups, Host}, Opts,
|
||||||
fun(L) ->
|
fun(L) ->
|
||||||
[iolist_to_binary(H) || H <- L]
|
[iolist_to_binary(H) || H <- L]
|
||||||
end, []),
|
end, []),
|
||||||
Encrypt = get_opt({ldap_encrypt, Host}, Opts,
|
Encrypt = gen_mod:get_opt({ldap_encrypt, Host}, Opts,
|
||||||
fun(tls) -> tls;
|
fun(tls) -> tls;
|
||||||
(starttls) -> starttls;
|
(starttls) -> starttls;
|
||||||
(none) -> none
|
(none) -> none
|
||||||
end, none),
|
end, none),
|
||||||
TLSVerify = get_opt({ldap_tls_verify, Host}, Opts,
|
TLSVerify = gen_mod:get_opt({ldap_tls_verify, Host}, Opts,
|
||||||
fun(hard) -> hard;
|
fun(hard) -> hard;
|
||||||
(soft) -> soft;
|
(soft) -> soft;
|
||||||
(false) -> false
|
(false) -> false
|
||||||
end, false),
|
end, false),
|
||||||
TLSCAFile = get_opt({ldap_tls_cacertfile, Host}, Opts,
|
TLSCAFile = gen_mod:get_opt({ldap_tls_cacertfile, Host}, Opts,
|
||||||
fun iolist_to_binary/1),
|
fun iolist_to_binary/1),
|
||||||
TLSDepth = get_opt({ldap_tls_depth, Host}, Opts,
|
TLSDepth = gen_mod:get_opt({ldap_tls_depth, Host}, Opts,
|
||||||
fun(I) when is_integer(I), I>=0 -> I end),
|
fun(I) when is_integer(I), I>=0 -> I end),
|
||||||
Port = get_opt({ldap_port, Host}, Opts,
|
Port = gen_mod:get_opt({ldap_port, Host}, Opts,
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
fun(I) when is_integer(I), I>0 -> I end,
|
||||||
case Encrypt of
|
case Encrypt of
|
||||||
tls -> ?LDAPS_PORT;
|
tls -> ?LDAPS_PORT;
|
||||||
starttls -> ?LDAP_PORT;
|
starttls -> ?LDAP_PORT;
|
||||||
_ -> ?LDAP_PORT
|
_ -> ?LDAP_PORT
|
||||||
end),
|
end),
|
||||||
RootDN = get_opt({ldap_rootdn, Host}, Opts,
|
RootDN = gen_mod:get_opt({ldap_rootdn, Host}, Opts,
|
||||||
fun iolist_to_binary/1,
|
fun iolist_to_binary/1,
|
||||||
<<"">>),
|
<<"">>),
|
||||||
Password = get_opt({ldap_password, Host}, Opts,
|
Password = gen_mod:get_opt({ldap_password, Host}, Opts,
|
||||||
fun iolist_to_binary/1,
|
fun iolist_to_binary/1,
|
||||||
<<"">>),
|
<<"">>),
|
||||||
Base = get_opt({ldap_base, Host}, Opts,
|
Base = gen_mod:get_opt({ldap_base, Host}, Opts,
|
||||||
fun iolist_to_binary/1,
|
fun iolist_to_binary/1,
|
||||||
<<"">>),
|
<<"">>),
|
||||||
OldDerefAliases = get_opt({deref_aliases, Host}, Opts,
|
OldDerefAliases = gen_mod:get_opt({deref_aliases, Host}, Opts,
|
||||||
fun(never) -> never;
|
fun(never) -> never;
|
||||||
(searching) -> searching;
|
(searching) -> searching;
|
||||||
(finding) -> finding;
|
(finding) -> finding;
|
||||||
|
@ -236,7 +218,7 @@ get_config(Host, Opts) ->
|
||||||
end, unspecified),
|
end, unspecified),
|
||||||
DerefAliases =
|
DerefAliases =
|
||||||
if OldDerefAliases == unspecified ->
|
if OldDerefAliases == unspecified ->
|
||||||
get_opt({ldap_deref_aliases, Host}, Opts,
|
gen_mod:get_opt({ldap_deref_aliases, Host}, Opts,
|
||||||
fun(never) -> never;
|
fun(never) -> never;
|
||||||
(searching) -> searching;
|
(searching) -> searching;
|
||||||
(finding) -> finding;
|
(finding) -> finding;
|
||||||
|
|
|
@ -155,13 +155,20 @@ wait_for_stop1(MonitorReference) ->
|
||||||
|
|
||||||
-type check_fun() :: fun((any()) -> any()) | {module(), atom()}.
|
-type check_fun() :: fun((any()) -> any()) | {module(), atom()}.
|
||||||
|
|
||||||
-spec get_opt(atom(), opts(), check_fun()) -> any().
|
-spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun()) -> any().
|
||||||
|
|
||||||
get_opt(Opt, Opts, F) ->
|
get_opt(Opt, Opts, F) ->
|
||||||
get_opt(Opt, Opts, F, undefined).
|
get_opt(Opt, Opts, F, undefined).
|
||||||
|
|
||||||
-spec get_opt(atom(), opts(), check_fun(), any()) -> any().
|
-spec get_opt(atom() | {atom(), binary()|global}, opts(), check_fun(), any()) -> any().
|
||||||
|
|
||||||
|
get_opt({Opt, Host}, Opts, F, Default) ->
|
||||||
|
case lists:keysearch(Opt, 1, Opts) of
|
||||||
|
false ->
|
||||||
|
ejabberd_config:get_option({Opt, Host}, F, Default);
|
||||||
|
{value, {_, Val}} ->
|
||||||
|
ejabberd_config:prepare_opt_val(Opt, Val, F, Default)
|
||||||
|
end;
|
||||||
get_opt(Opt, Opts, F, Default) ->
|
get_opt(Opt, Opts, F, Default) ->
|
||||||
case lists:keysearch(Opt, 1, Opts) of
|
case lists:keysearch(Opt, 1, Opts) of
|
||||||
false ->
|
false ->
|
||||||
|
|
|
@ -521,29 +521,29 @@ parse_options(Host, Opts) ->
|
||||||
(false) -> false;
|
(false) -> false;
|
||||||
(true) -> true
|
(true) -> true
|
||||||
end, true),
|
end, true),
|
||||||
UserCacheValidity = eldap_utils:get_opt(
|
UserCacheValidity = gen_mod:get_opt(
|
||||||
{ldap_user_cache_validity, Host}, Opts,
|
{ldap_user_cache_validity, Host}, Opts,
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
fun(I) when is_integer(I), I>0 -> I end,
|
||||||
?USER_CACHE_VALIDITY),
|
?USER_CACHE_VALIDITY),
|
||||||
GroupCacheValidity = eldap_utils:get_opt(
|
GroupCacheValidity = gen_mod:get_opt(
|
||||||
{ldap_group_cache_validity, Host}, Opts,
|
{ldap_group_cache_validity, Host}, Opts,
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
fun(I) when is_integer(I), I>0 -> I end,
|
||||||
?GROUP_CACHE_VALIDITY),
|
?GROUP_CACHE_VALIDITY),
|
||||||
UserCacheSize = eldap_utils:get_opt(
|
UserCacheSize = gen_mod:get_opt(
|
||||||
{ldap_user_cache_size, Host}, Opts,
|
{ldap_user_cache_size, Host}, Opts,
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
fun(I) when is_integer(I), I>0 -> I end,
|
||||||
?CACHE_SIZE),
|
?CACHE_SIZE),
|
||||||
GroupCacheSize = eldap_utils:get_opt(
|
GroupCacheSize = gen_mod:get_opt(
|
||||||
{ldap_group_cache_size, Host}, Opts,
|
{ldap_group_cache_size, Host}, Opts,
|
||||||
fun(I) when is_integer(I), I>0 -> I end,
|
fun(I) when is_integer(I), I>0 -> I end,
|
||||||
?CACHE_SIZE),
|
?CACHE_SIZE),
|
||||||
ConfigFilter = eldap_utils:get_opt({ldap_filter, Host}, Opts,
|
ConfigFilter = gen_mod:get_opt({ldap_filter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun check_filter/1, <<"">>),
|
||||||
ConfigUserFilter = eldap_utils:get_opt({ldap_ufilter, Host}, Opts,
|
ConfigUserFilter = gen_mod:get_opt({ldap_ufilter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun check_filter/1, <<"">>),
|
||||||
ConfigGroupFilter = eldap_utils:get_opt({ldap_gfilter, Host}, Opts,
|
ConfigGroupFilter = gen_mod:get_opt({ldap_gfilter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun check_filter/1, <<"">>),
|
||||||
RosterFilter = eldap_utils:get_opt({ldap_rfilter, Host}, Opts,
|
RosterFilter = gen_mod:get_opt({ldap_rfilter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>),
|
fun check_filter/1, <<"">>),
|
||||||
SubFilter = <<"(&(", UIDAttr/binary, "=",
|
SubFilter = <<"(&(", UIDAttr/binary, "=",
|
||||||
UIDAttrFormat/binary, ")(", GroupAttr/binary, "=%g))">>,
|
UIDAttrFormat/binary, ")(", GroupAttr/binary, "=%g))">>,
|
||||||
|
|
|
@ -739,7 +739,7 @@ parse_options(Host, Opts) ->
|
||||||
end, 30),
|
end, 30),
|
||||||
Eldap_ID = jlib:atom_to_binary(gen_mod:get_module_proc(Host, ?PROCNAME)),
|
Eldap_ID = jlib:atom_to_binary(gen_mod:get_module_proc(Host, ?PROCNAME)),
|
||||||
Cfg = eldap_utils:get_config(Host, Opts),
|
Cfg = eldap_utils:get_config(Host, Opts),
|
||||||
UIDsTemp = eldap_utils:get_opt(
|
UIDsTemp = gen_mod:get_opt(
|
||||||
{ldap_uids, Host}, Opts,
|
{ldap_uids, Host}, Opts,
|
||||||
fun(Us) ->
|
fun(Us) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
|
@ -752,7 +752,7 @@ parse_options(Host, Opts) ->
|
||||||
end, [{<<"uid">>, <<"%u">>}]),
|
end, [{<<"uid">>, <<"%u">>}]),
|
||||||
UIDs = eldap_utils:uids_domain_subst(Host, UIDsTemp),
|
UIDs = eldap_utils:uids_domain_subst(Host, UIDsTemp),
|
||||||
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
SubFilter = eldap_utils:generate_subfilter(UIDs),
|
||||||
UserFilter = case eldap_utils:get_opt(
|
UserFilter = case gen_mod:get_opt(
|
||||||
{ldap_filter, Host}, Opts,
|
{ldap_filter, Host}, Opts,
|
||||||
fun check_filter/1, <<"">>) of
|
fun check_filter/1, <<"">>) of
|
||||||
<<"">> ->
|
<<"">> ->
|
||||||
|
|
Loading…
Reference in New Issue