aboutsummaryrefslogtreecommitdiff
path: root/src/eldap_utils.erl
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-04-30 19:01:47 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-04-30 19:01:47 +0300
commitfddd6110e00df12c99a20a2cc9d074f5f4f1f965 (patch)
tree366575b855f1b2013db7eeb02ecb213f81c98c1f /src/eldap_utils.erl
parentMerge branch 'new-option-validation' (diff)
Don't validate an option in gen_mod:get*opt() functions
The changes are very similar to those from previous commit: * Now there is no need to pass validating function in gen_mod:get_opt() and gen_mod:get_module_opt() functions, because the modules' configuration keeps already validated values. * New functions gen_mod:get_opt/2 and gen_mod:get_module_opt/3 are introduced. * Functions gen_mod:get_opt/4 and get_module_opt/5 are deprecated. If the functions are still called, the "function" argument is simply ignored. * Validating callback Mod:listen_opt_type/1 is introduced to validate listening options at startup.
Diffstat (limited to 'src/eldap_utils.erl')
-rw-r--r--src/eldap_utils.erl68
1 files changed, 18 insertions, 50 deletions
diff --git a/src/eldap_utils.erl b/src/eldap_utils.erl
index 4306def0c..d15e5bc9c 100644
--- a/src/eldap_utils.erl
+++ b/src/eldap_utils.erl
@@ -173,58 +173,25 @@ uids_domain_subst(Host, UIDs) ->
-spec get_config(binary(), list()) -> eldap_config().
get_config(Host, Opts) ->
- Servers = gen_mod:get_opt({ldap_servers, Host}, Opts,
- fun(L) ->
- [iolist_to_binary(H) || H <- L]
- end, [<<"localhost">>]),
- Backups = gen_mod:get_opt({ldap_backups, Host}, Opts,
- fun(L) ->
- [iolist_to_binary(H) || H <- L]
- end, []),
- Encrypt = gen_mod:get_opt({ldap_encrypt, Host}, Opts,
- fun(tls) -> tls;
- (starttls) -> starttls;
- (none) -> none
- end, none),
- TLSVerify = gen_mod:get_opt({ldap_tls_verify, Host}, Opts,
- fun(hard) -> hard;
- (soft) -> soft;
- (false) -> false
- end, false),
- TLSCAFile = gen_mod:get_opt({ldap_tls_cacertfile, Host}, Opts,
- fun iolist_to_binary/1),
- TLSDepth = gen_mod:get_opt({ldap_tls_depth, Host}, Opts,
- fun(I) when is_integer(I), I>=0 -> I end),
+ Servers = gen_mod:get_opt({ldap_servers, Host}, Opts, [<<"localhost">>]),
+ Backups = gen_mod:get_opt({ldap_backups, Host}, Opts, []),
+ Encrypt = gen_mod:get_opt({ldap_encrypt, Host}, Opts, none),
+ TLSVerify = gen_mod:get_opt({ldap_tls_verify, Host}, Opts, false),
+ TLSCAFile = gen_mod:get_opt({ldap_tls_cacertfile, Host}, Opts),
+ TLSDepth = gen_mod:get_opt({ldap_tls_depth, Host}, Opts),
Port = gen_mod:get_opt({ldap_port, Host}, Opts,
- fun(I) when is_integer(I), I>0 -> I end,
- case Encrypt of
- tls -> ?LDAPS_PORT;
- starttls -> ?LDAP_PORT;
- _ -> ?LDAP_PORT
- end),
- RootDN = gen_mod:get_opt({ldap_rootdn, Host}, Opts,
- fun iolist_to_binary/1,
- <<"">>),
- Password = gen_mod:get_opt({ldap_password, Host}, Opts,
- fun iolist_to_binary/1,
- <<"">>),
- Base = gen_mod:get_opt({ldap_base, Host}, Opts,
- fun iolist_to_binary/1,
- <<"">>),
- OldDerefAliases = gen_mod:get_opt({deref_aliases, Host}, Opts,
- fun(never) -> never;
- (searching) -> searching;
- (finding) -> finding;
- (always) -> always
- end, unspecified),
+ case Encrypt of
+ tls -> ?LDAPS_PORT;
+ starttls -> ?LDAP_PORT;
+ _ -> ?LDAP_PORT
+ end),
+ RootDN = gen_mod:get_opt({ldap_rootdn, Host}, Opts, <<"">>),
+ Password = gen_mod:get_opt({ldap_password, Host}, Opts, <<"">>),
+ Base = gen_mod:get_opt({ldap_base, Host}, Opts, <<"">>),
+ OldDerefAliases = gen_mod:get_opt({deref_aliases, Host}, Opts, unspecified),
DerefAliases =
if OldDerefAliases == unspecified ->
- gen_mod:get_opt({ldap_deref_aliases, Host}, Opts,
- fun(never) -> never;
- (searching) -> searching;
- (finding) -> finding;
- (always) -> always
- end, never);
+ gen_mod:get_opt({ldap_deref_aliases, Host}, Opts, never);
true ->
?WARNING_MSG("Option 'deref_aliases' is deprecated. "
"The option is still supported "
@@ -377,7 +344,8 @@ opt_type(ldap_port) ->
opt_type(ldap_rootdn) -> fun iolist_to_binary/1;
opt_type(ldap_servers) ->
fun (L) -> [iolist_to_binary(H) || H <- L] end;
-opt_type(ldap_tls_cacertfile) -> fun iolist_to_binary/1;
+opt_type(ldap_tls_cacertfile) ->
+ fun(S) -> binary_to_list(iolist_to_binary(S)) end;
opt_type(ldap_tls_depth) ->
fun (I) when is_integer(I), I >= 0 -> I end;
opt_type(ldap_tls_verify) ->