end,
UIDs = case ejabberd_config:get_local_option({ldap_uids, Host}) of
undefined -> [{"uid", "%u"}];
- UI -> UI
+ UI -> eldap_utils:uids_domain_subst(Host, UI)
end,
+ SubFilter = lists:flatten(eldap_utils:generate_subfilter(UIDs)),
UserFilter = case ejabberd_config:get_local_option({ldap_filter, Host}) of
undefined -> "";
- F -> F
+ "" -> "";
+ F ->
+ eldap_utils:check_filter(F),
+ "(&" ++ SubFilter ++ F ++ ")"
end,
LDAPBase = ejabberd_config:get_local_option({ldap_base, Host}),
{DNFilter, DNFilterAttrs} =
{DNF, DNFA} ->
{DNF, DNFA}
end,
- LocalFilter = ejabberd_config:get_local_option({ldap_local_filter, Host}),
+ eldap_utils:check_filter(DNFilter),
+ LocalFilter = ejabberd_config:get_local_option({ldap_local_filter, Host}),
#state{host = Host,
eldap_id = Eldap_ID,
bind_eldap_id = Bind_Eldap_ID,
%%%-------------------------------------------------------------------
parse(L, SList) when is_list(L), is_list(SList) ->
case catch eldap_filter_yecc:parse(scan(L, SList)) of
+ {'EXIT', _} = Err ->
+ {error, Err};
{error, {_, _, Msg}} ->
{error, Msg};
{ok, Result} ->
make_filter/2,
get_state/2,
case_insensitive_match/2,
+ check_filter/1,
uids_domain_subst/2]).
+-include("ejabberd.hrl").
+
%% Generate an 'or' LDAP query on one or several attributes
%% If there is only one attribute
generate_subfilter([UID]) ->
(A) -> A
end,
UIDs).
+
+check_filter(undefined) ->
+ ok;
+check_filter(Filter) ->
+ case eldap_filter:parse(Filter) of
+ {ok, _} ->
+ ok;
+ Err ->
+ ?ERROR_MSG("failed to parse LDAP filter:~n"
+ "** Filter: ~p~n"
+ "** Reason: ~p",
+ [Filter, Err])
+ end.
RF ->
RF
end,
-
+ lists:foreach(fun eldap_utils:check_filter/1,
+ [ConfigFilter, ConfigUserFilter,
+ ConfigGroupFilter, RosterFilter]),
SubFilter = "(&("++UIDAttr++"="++UIDAttrFormat++")("++GroupAttr++"=%g))",
UserSubFilter = case ConfigUserFilter of
undefined -> eldap_filter:do_sub(SubFilter, [{"%g", "*"}]);
case ejabberd_config:get_local_option({ldap_filter, Host}) of
undefined -> SubFilter;
"" -> SubFilter;
- F -> "(&" ++ SubFilter ++ F ++ ")"
+ F ->
+ eldap_utils:check_filter(F),
+ "(&" ++ SubFilter ++ F ++ ")"
end;
"" -> SubFilter;
- F -> "(&" ++ SubFilter ++ F ++ ")"
+ F ->
+ eldap_utils:check_filter(F),
+ "(&" ++ SubFilter ++ F ++ ")"
end,
{ok, SearchFilter} = eldap_filter:parse(
eldap_filter:do_sub(UserFilter, [{"%u","*"}])),