Reg_name = list_to_atom("eldap_" ++ Name),
gen_fsm:start_link({local, Reg_name}, ?MODULE, [], []).
-start_link(Name, Hosts, Port, Rootdn, Passwd, Encrypt) ->
+start_link(Name, Hosts, Port, Rootdn, Passwd, Opts) ->
Reg_name = list_to_atom("eldap_" ++ Name),
- gen_fsm:start_link({local, Reg_name}, ?MODULE, {Hosts, Port, Rootdn, Passwd, Encrypt}, []).
+ gen_fsm:start_link({local, Reg_name}, ?MODULE,
+ {Hosts, Port, Rootdn, Passwd, Opts}, []).
%%% --------------------------------------------------------------------
%%% Get status of connection.
%%----------------------------------------------------------------------
init([]) ->
case get_config() of
- {ok, Hosts, Rootdn, Passwd, Encrypt} ->
- init({Hosts, Rootdn, Passwd, Encrypt});
+ {ok, Hosts, Rootdn, Passwd, Opts} ->
+ init({Hosts, Rootdn, Passwd, Opts});
{error, Reason} ->
{stop, Reason}
end;
-init({Hosts, Port, Rootdn, Passwd, Encrypt}) ->
+init({Hosts, Port, Rootdn, Passwd, Opts}) ->
catch ssl:start(),
{X1,X2,X3} = erlang:now(),
ssl:seed(integer_to_list(X1) ++ integer_to_list(X2) ++ integer_to_list(X3)),
+ Encrypt = case proplists:get_value(encrypt, Opts) of
+ tls -> tls;
+ _ -> none
+ end,
PortTemp = case Port of
undefined ->
case Encrypt of
end;
PT -> PT
end,
- TLSOpts = [verify_none],
+ TLSOpts = case proplists:get_value(tls_verify, Opts) of
+ soft ->
+ [{verify, 1}];
+ hard ->
+ [{verify, 2}];
+ _ ->
+ [{verify, 0}]
+ end,
{ok, connecting, #eldap{hosts = Hosts,
port = PortTemp,
rootdn = Rootdn,
tls ->
SockMod = ssl,
SslOpts = [{packet, asn1}, {active, true}, {keepalive, true},
- binary],
+ binary | S#eldap.tls_options],
ssl:connect(Host, S#eldap.port, SslOpts);
%% starttls -> %% TODO: Implement STARTTLS;
_ ->
case file:consult(File) of
{ok, Entries} ->
case catch parse(Entries) of
- {ok, Hosts, Port, Rootdn, Passwd, Encrypt} ->
- {ok, Hosts, Port, Rootdn, Passwd, Encrypt};
+ {ok, Hosts, Port, Rootdn, Passwd, Opts} ->
+ {ok, Hosts, Port, Rootdn, Passwd, Opts};
{error, Reason} ->
{error, Reason};
{'EXIT', Reason} ->
get_integer(port, Entries),
get_list(rootdn, Entries),
get_list(passwd, Entries),
- get_atom(encrypt, Entries)}.
+ get_list(options, Entries)}.
get_integer(Key, List) ->
case lists:keysearch(Key, 1, List) of
throw({error, "No Entry in Config for " ++ atom_to_list(Key)})
end.
-get_atom(Key, List) ->
- case lists:keysearch(Key, 1, List) of
- {value, {Key, Value}} when is_atom(Value) ->
- Value;
- {value, {Key, _Value}} ->
- throw({error, "Bad Value in Config for " ++ atom_to_list(Key)});
- false ->
- throw({error, "No Entry in Config for " ++ atom_to_list(Key)})
- end.
+%% get_atom(Key, List) ->
+%% case lists:keysearch(Key, 1, List) of
+%% {value, {Key, Value}} when is_atom(Value) ->
+%% Value;
+%% {value, {Key, _Value}} ->
+%% throw({error, "Bad Value in Config for " ++ atom_to_list(Key)});
+%% false ->
+%% throw({error, "No Entry in Config for " ++ atom_to_list(Key)})
+%% end.
get_hosts(Key, List) ->
lists:map(fun({Key1, {A,B,C,D}}) when is_integer(A),
modify_passwd(PoolName, DN, Passwd) ->
do_request(PoolName, {modify_passwd, [DN, Passwd]}).
-start_link(Name, Hosts, Backups, Port, Rootdn, Passwd, Encrypt) ->
+start_link(Name, Hosts, Backups, Port, Rootdn, Passwd, Opts) ->
PoolName = make_id(Name),
pg2:create(PoolName),
- lists:foreach(fun(Host) ->
- ID = erlang:ref_to_list(make_ref()),
- case catch eldap:start_link(ID, [Host|Backups], Port, Rootdn, Passwd, Encrypt) of
- {ok, Pid} ->
- pg2:join(PoolName, Pid);
- _ ->
- error
- end
- end, Hosts).
+ lists:foreach(
+ fun(Host) ->
+ ID = erlang:ref_to_list(make_ref()),
+ case catch eldap:start_link(ID, [Host|Backups], Port,
+ Rootdn, Passwd, Opts) of
+ {ok, Pid} ->
+ pg2:join(PoolName, Pid);
+ _ ->
+ error
+ end
+ end, Hosts).
%%====================================================================
%% Internal functions