aboutsummaryrefslogtreecommitdiff
path: root/src/mod_shared_roster_ldap.erl
diff options
context:
space:
mode:
authorEvgeny Khramtsov <ekhramtsov@process-one.net>2019-06-14 12:33:26 +0300
committerEvgeny Khramtsov <ekhramtsov@process-one.net>2019-06-14 12:33:26 +0300
commita02cff0e780bb735531594c4ece81e8628f79782 (patch)
tree6fe7d8219d14f58183be1741fcea262c216db447 /src/mod_shared_roster_ldap.erl
parentReturn jid_malformed error when sending presence without nick to conference (diff)
Use new configuration validator
Diffstat (limited to 'src/mod_shared_roster_ldap.erl')
-rw-r--r--src/mod_shared_roster_ldap.erl197
1 files changed, 101 insertions, 96 deletions
diff --git a/src/mod_shared_roster_ldap.erl b/src/mod_shared_roster_ldap.erl
index 327ec0a9d..524f65113 100644
--- a/src/mod_shared_roster_ldap.erl
+++ b/src/mod_shared_roster_ldap.erl
@@ -26,8 +26,6 @@
%%%-------------------------------------------------------------------
-module(mod_shared_roster_ldap).
--behaviour(ejabberd_config).
-
-behaviour(gen_server).
-behaviour(gen_mod).
@@ -42,7 +40,7 @@
-export([get_user_roster/2,
get_jid_info/4, process_item/2, in_subscription/2,
out_subscription/1, mod_opt_type/1, mod_options/1,
- opt_type/1, depends/2, transform_module_options/1]).
+ depends/2]).
-include("logger.hrl").
-include("xmpp.hrl").
@@ -72,7 +70,7 @@
user_desc = <<"">> :: binary(),
user_uid = <<"">> :: binary(),
uid_format = <<"">> :: binary(),
- uid_format_re = <<"">> :: binary(),
+ uid_format_re :: undefined | re:mp(),
filter = <<"">> :: binary(),
ufilter = <<"">> :: binary(),
rfilter = <<"">> :: binary(),
@@ -351,7 +349,7 @@ get_user_name(User, Host) ->
search_group_info(State, Group) ->
Extractor = case State#state.uid_format_re of
- <<"">> ->
+ undefined ->
fun (UID) ->
catch eldap_utils:get_user_part(UID,
State#state.uid_format)
@@ -440,22 +438,22 @@ get_user_part_re(String, Pattern) ->
parse_options(Host, Opts) ->
Eldap_ID = misc:atom_to_binary(gen_mod:get_module_proc(Host, ?MODULE)),
- Cfg = eldap_utils:get_config(Host, Opts),
- GroupAttr = gen_mod:get_opt(ldap_groupattr, Opts),
- GroupDesc = case gen_mod:get_opt(ldap_groupdesc, Opts) of
+ Cfg = ?eldap_config(mod_shared_roster_ldap_opt, Opts),
+ GroupAttr = mod_shared_roster_ldap_opt:ldap_groupattr(Opts),
+ GroupDesc = case mod_shared_roster_ldap_opt:ldap_groupdesc(Opts) of
undefined -> GroupAttr;
GD -> GD
end,
- UserDesc = gen_mod:get_opt(ldap_userdesc, Opts),
- UserUID = gen_mod:get_opt(ldap_useruid, Opts),
- UIDAttr = gen_mod:get_opt(ldap_memberattr, Opts),
- UIDAttrFormat = gen_mod:get_opt(ldap_memberattr_format, Opts),
- UIDAttrFormatRe = gen_mod:get_opt(ldap_memberattr_format_re, Opts),
- AuthCheck = gen_mod:get_opt(ldap_auth_check, Opts),
- ConfigFilter = gen_mod:get_opt(ldap_filter, Opts),
- ConfigUserFilter = gen_mod:get_opt(ldap_ufilter, Opts),
- ConfigGroupFilter = gen_mod:get_opt(ldap_gfilter, Opts),
- RosterFilter = gen_mod:get_opt(ldap_rfilter, Opts),
+ UserDesc = mod_shared_roster_ldap_opt:ldap_userdesc(Opts),
+ UserUID = mod_shared_roster_ldap_opt:ldap_useruid(Opts),
+ UIDAttr = mod_shared_roster_ldap_opt:ldap_memberattr(Opts),
+ UIDAttrFormat = mod_shared_roster_ldap_opt:ldap_memberattr_format(Opts),
+ UIDAttrFormatRe = mod_shared_roster_ldap_opt:ldap_memberattr_format_re(Opts),
+ AuthCheck = mod_shared_roster_ldap_opt:ldap_auth_check(Opts),
+ ConfigFilter = mod_shared_roster_ldap_opt:ldap_filter(Opts),
+ ConfigUserFilter = mod_shared_roster_ldap_opt:ldap_ufilter(Opts),
+ ConfigGroupFilter = mod_shared_roster_ldap_opt:ldap_gfilter(Opts),
+ RosterFilter = mod_shared_roster_ldap_opt:ldap_rfilter(Opts),
SubFilter = <<"(&(", UIDAttr/binary, "=",
UIDAttrFormat/binary, ")(", GroupAttr/binary, "=%g))">>,
UserSubFilter = case ConfigUserFilter of
@@ -516,103 +514,110 @@ init_cache(Host, Opts) ->
UseCache.
use_cache(_Host, Opts) ->
- gen_mod:get_opt(use_cache, Opts).
+ mod_shared_roster_ldap_opt:use_cache(Opts).
cache_opts(_Host, Opts) ->
- MaxSize = gen_mod:get_opt(cache_size, Opts),
- CacheMissed = gen_mod:get_opt(cache_missed, Opts),
- LifeTime = case gen_mod:get_opt(cache_life_time, Opts) of
+ MaxSize = mod_shared_roster_ldap_opt:cache_size(Opts),
+ CacheMissed = mod_shared_roster_ldap_opt:cache_missed(Opts),
+ LifeTime = case mod_shared_roster_ldap_opt:cache_life_time(Opts) of
infinity -> infinity;
I -> timer:seconds(I)
end,
[{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}].
-transform_module_options(Opts) ->
- lists:map(
- fun({ldap_group_cache_size, I}) ->
- ?WARNING_MSG("Option 'ldap_group_cache_size' is deprecated, "
- "use 'cache_size' instead", []),
- {cache_size, I};
- ({ldap_user_cache_size, I}) ->
- ?WARNING_MSG("Option 'ldap_user_cache_size' is deprecated, "
- "use 'cache_size' instead", []),
- {cache_size, I};
- ({ldap_group_cache_validity, Secs}) ->
- ?WARNING_MSG("Option 'ldap_group_cache_validity' is deprecated, "
- "use 'cache_life_time' instead", []),
- {cache_life_time, Secs};
- ({ldap_user_cache_validity, Secs}) ->
- ?WARNING_MSG("Option 'ldap_user_cache_validity' is deprecated, "
- "use 'cache_life_time' instead", []),
- {cache_life_time, Secs};
- (Opt) ->
- Opt
- end, Opts).
-
mod_opt_type(ldap_auth_check) ->
- fun (on) -> true;
- (off) -> false;
- (false) -> false;
- (true) -> true
- end;
+ econf:bool();
mod_opt_type(ldap_gfilter) ->
- opt_type(ldap_gfilter);
-mod_opt_type(O) when O == cache_size;
- O == cache_life_time ->
- fun (I) when is_integer(I), I > 0 -> I;
- (infinity) -> infinity
- end;
-mod_opt_type(O) when O == use_cache; O == cache_missed ->
- fun (B) when is_boolean(B) -> B end;
-mod_opt_type(ldap_groupattr) -> fun iolist_to_binary/1;
+ econf:ldap_filter();
+mod_opt_type(ldap_groupattr) ->
+ econf:binary();
mod_opt_type(ldap_groupdesc) ->
- fun(undefined) -> undefined;
- (G) -> iolist_to_binary(G)
- end;
-mod_opt_type(ldap_memberattr) -> fun iolist_to_binary/1;
+ econf:binary();
+mod_opt_type(ldap_memberattr) ->
+ econf:binary();
mod_opt_type(ldap_memberattr_format) ->
- fun iolist_to_binary/1;
+ econf:binary();
mod_opt_type(ldap_memberattr_format_re) ->
- fun (S) ->
- Re = iolist_to_binary(S),
- case Re of
- <<>> -> <<>>;
- _ -> {ok, MP} = re:compile(Re), MP
- end
- end;
+ econf:re();
mod_opt_type(ldap_rfilter) ->
- opt_type(ldap_rfilter);
+ econf:ldap_filter();
mod_opt_type(ldap_ufilter) ->
- opt_type(ldap_ufilter);
-mod_opt_type(ldap_userdesc) -> fun iolist_to_binary/1;
-mod_opt_type(ldap_useruid) -> fun iolist_to_binary/1;
-mod_opt_type(Opt) ->
- eldap_utils:opt_type(Opt).
-
+ econf:ldap_filter();
+mod_opt_type(ldap_userdesc) ->
+ econf:binary();
+mod_opt_type(ldap_useruid) ->
+ econf:binary();
+mod_opt_type(ldap_backups) ->
+ econf:list(econf:domain(), [unique]);
+mod_opt_type(ldap_base) ->
+ econf:binary();
+mod_opt_type(ldap_deref_aliases) ->
+ econf:enum([never, searching, finding, always]);
+mod_opt_type(ldap_encrypt) ->
+ econf:enum([tls, starttls, none]);
+mod_opt_type(ldap_filter) ->
+ econf:ldap_filter();
+mod_opt_type(ldap_password) ->
+ econf:binary();
+mod_opt_type(ldap_port) ->
+ econf:port();
+mod_opt_type(ldap_rootdn) ->
+ econf:binary();
+mod_opt_type(ldap_servers) ->
+ econf:list(econf:domain(), [unique]);
+mod_opt_type(ldap_tls_cacertfile) ->
+ econf:pem();
+mod_opt_type(ldap_tls_certfile) ->
+ econf:pem();
+mod_opt_type(ldap_tls_depth) ->
+ econf:non_neg_int();
+mod_opt_type(ldap_tls_verify) ->
+ econf:enum([hard, soft, false]);
+mod_opt_type(ldap_uids) ->
+ econf:either(
+ econf:list(
+ econf:and_then(
+ econf:binary(),
+ fun(U) -> {U, <<"%u">>} end)),
+ econf:map(econf:binary(), econf:binary(), [unique]));
+mod_opt_type(use_cache) ->
+ econf:well_known(use_cache, ?MODULE);
+mod_opt_type(cache_size) ->
+ econf:well_known(cache_size, ?MODULE);
+mod_opt_type(cache_missed) ->
+ econf:well_known(cache_missed, ?MODULE);
+mod_opt_type(cache_life_time) ->
+ econf:well_known(cache_life_time, ?MODULE).
+
+-spec mod_options(binary()) -> [{ldap_uids, [{binary(), binary()}]} |
+ {atom(), any()}].
mod_options(Host) ->
[{ldap_auth_check, true},
- {ldap_gfilter, ejabberd_config:get_option({ldap_gfilter, Host}, <<"">>)},
+ {ldap_gfilter, <<"">>},
{ldap_groupattr, <<"cn">>},
{ldap_groupdesc, undefined},
{ldap_memberattr, <<"memberUid">>},
{ldap_memberattr_format, <<"%u">>},
- {ldap_memberattr_format_re, <<"">>},
- {ldap_rfilter, ejabberd_config:get_option({ldap_rfilter, Host}, <<"">>)},
- {ldap_ufilter, ejabberd_config:get_option({ldap_ufilter, Host}, <<"">>)},
+ {ldap_memberattr_format_re, undefined},
+ {ldap_rfilter, <<"">>},
+ {ldap_ufilter, <<"">>},
{ldap_userdesc, <<"cn">>},
{ldap_useruid, <<"cn">>},
- {use_cache, ejabberd_config:use_cache(Host)},
- {cache_size, ejabberd_config:cache_size(Host)},
- {cache_missed, ejabberd_config:cache_missed(Host)},
- {cache_life_time, ejabberd_config:cache_life_time(Host)}
- | lists:map(
- fun({Opt, Default}) ->
- {Opt, ejabberd_config:get_option({Opt, Host}, Default)}
- end, eldap_utils:options(Host))].
-
-opt_type(O) when O == ldap_rfilter; O == ldap_gfilter; O == ldap_ufilter ->
- fun(<<>>) -> <<>>;
- (F) -> eldap_utils:check_filter(F)
- end;
-opt_type(_) ->
- [ldap_gfilter, ldap_rfilter, ldap_ufilter].
+ {ldap_backups, ejabberd_option:ldap_backups(Host)},
+ {ldap_base, ejabberd_option:ldap_base(Host)},
+ {ldap_uids, ejabberd_option:ldap_uids(Host)},
+ {ldap_deref_aliases, ejabberd_option:ldap_deref_aliases(Host)},
+ {ldap_encrypt, ejabberd_option:ldap_encrypt(Host)},
+ {ldap_password, ejabberd_option:ldap_password(Host)},
+ {ldap_port, ejabberd_option:ldap_port(Host)},
+ {ldap_rootdn, ejabberd_option:ldap_rootdn(Host)},
+ {ldap_servers, ejabberd_option:ldap_servers(Host)},
+ {ldap_filter, ejabberd_option:ldap_filter(Host)},
+ {ldap_tls_certfile, ejabberd_option:ldap_tls_certfile(Host)},
+ {ldap_tls_cacertfile, ejabberd_option:ldap_tls_cacertfile(Host)},
+ {ldap_tls_depth, ejabberd_option:ldap_tls_depth(Host)},
+ {ldap_tls_verify, ejabberd_option:ldap_tls_verify(Host)},
+ {use_cache, ejabberd_option:use_cache(Host)},
+ {cache_size, ejabberd_option:cache_size(Host)},
+ {cache_missed, ejabberd_option:cache_missed(Host)},
+ {cache_life_time, ejabberd_option:cache_life_time(Host)}].