2004-07-30 23:09:55 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_vcard_ldap.erl
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2006-09-14 04:54:21 +02:00
|
|
|
%%% Purpose : Support for VCards from LDAP storage.
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% Created : 2 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2010-01-12 17:11:32 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
2007-12-24 13:58:05 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2004-07-30 23:09:55 +02:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_vcard_ldap).
|
2007-12-24 13:58:05 +01:00
|
|
|
-author('alexey@process-one.net').
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
-behaviour(gen_server).
|
2004-07-30 23:09:55 +02:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
%% gen_server callbacks.
|
|
|
|
-export([init/1,
|
|
|
|
handle_info/2,
|
|
|
|
handle_call/3,
|
|
|
|
handle_cast/2,
|
|
|
|
terminate/2,
|
|
|
|
code_change/3
|
|
|
|
]).
|
|
|
|
|
|
|
|
-export([start/2,
|
|
|
|
start_link/2,
|
|
|
|
stop/1,
|
|
|
|
get_sm_features/5,
|
2004-07-30 23:09:55 +02:00
|
|
|
process_local_iq/3,
|
|
|
|
process_sm_iq/3,
|
2007-01-27 17:40:37 +01:00
|
|
|
remove_user/1,
|
|
|
|
route/4
|
2006-09-14 04:54:21 +02:00
|
|
|
]).
|
2004-07-30 23:09:55 +02:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2008-07-16 18:58:42 +02:00
|
|
|
-include("eldap/eldap.hrl").
|
2004-07-30 23:09:55 +02:00
|
|
|
-include("jlib.hrl").
|
|
|
|
|
2005-08-25 22:48:45 +02:00
|
|
|
-define(PROCNAME, ejabberd_mod_vcard_ldap).
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
-record(state, {serverhost,
|
|
|
|
myhost,
|
|
|
|
eldap_id,
|
|
|
|
search,
|
|
|
|
servers,
|
2007-01-27 17:40:37 +01:00
|
|
|
backups,
|
2006-09-14 04:54:21 +02:00
|
|
|
port,
|
2009-05-25 19:15:48 +02:00
|
|
|
encrypt,
|
2006-09-14 04:54:21 +02:00
|
|
|
dn,
|
|
|
|
base,
|
|
|
|
password,
|
2006-10-17 14:35:47 +02:00
|
|
|
uids,
|
2006-09-14 04:54:21 +02:00
|
|
|
vcard_map,
|
|
|
|
vcard_map_attrs,
|
|
|
|
user_filter,
|
|
|
|
search_filter,
|
|
|
|
search_fields,
|
|
|
|
search_reported,
|
2007-01-27 17:40:37 +01:00
|
|
|
search_reported_attrs,
|
|
|
|
matches
|
2006-09-14 04:54:21 +02:00
|
|
|
}).
|
|
|
|
|
|
|
|
-define(VCARD_MAP,
|
|
|
|
[{"NICKNAME", "%u", []},
|
|
|
|
{"FN", "%s", ["displayName"]},
|
|
|
|
{"FAMILY", "%s", ["sn"]},
|
2007-12-27 17:40:03 +01:00
|
|
|
{"GIVEN", "%s", ["givenName"]},
|
2006-09-14 04:54:21 +02:00
|
|
|
{"MIDDLE", "%s", ["initials"]},
|
|
|
|
{"ORGNAME", "%s", ["o"]},
|
|
|
|
{"ORGUNIT", "%s", ["ou"]},
|
|
|
|
{"CTRY", "%s", ["c"]},
|
|
|
|
{"LOCALITY", "%s", ["l"]},
|
|
|
|
{"STREET", "%s", ["street"]},
|
|
|
|
{"REGION", "%s", ["st"]},
|
|
|
|
{"PCODE", "%s", ["postalCode"]},
|
|
|
|
{"TITLE", "%s", ["title"]},
|
|
|
|
{"URL", "%s", ["labeleduri"]},
|
|
|
|
{"DESC", "%s", ["description"]},
|
|
|
|
{"TEL", "%s", ["telephoneNumber"]},
|
|
|
|
{"EMAIL", "%s", ["mail"]},
|
|
|
|
{"BDAY", "%s", ["birthDay"]},
|
|
|
|
{"ROLE", "%s", ["employeeType"]},
|
|
|
|
{"PHOTO", "%s", ["jpegPhoto"]}
|
|
|
|
]).
|
|
|
|
|
|
|
|
-define(SEARCH_FIELDS,
|
|
|
|
[{"User", "%u"},
|
|
|
|
{"Full Name", "displayName"},
|
|
|
|
{"Given Name", "givenName"},
|
|
|
|
{"Middle Name", "initials"},
|
|
|
|
{"Family Name", "sn"},
|
|
|
|
{"Nickname", "%u"},
|
|
|
|
{"Birthday", "birthDay"},
|
|
|
|
{"Country", "c"},
|
|
|
|
{"City", "l"},
|
|
|
|
{"Email", "mail"},
|
|
|
|
{"Organization Name", "o"},
|
|
|
|
{"Organization Unit", "ou"}
|
|
|
|
]).
|
|
|
|
|
|
|
|
-define(SEARCH_REPORTED,
|
|
|
|
[{"Full Name", "FN"},
|
2007-11-27 15:06:44 +01:00
|
|
|
{"Given Name", "FIRST"},
|
2006-09-14 04:54:21 +02:00
|
|
|
{"Middle Name", "MIDDLE"},
|
2007-11-27 15:06:44 +01:00
|
|
|
{"Family Name", "LAST"},
|
|
|
|
{"Nickname", "NICK"},
|
2006-09-14 04:54:21 +02:00
|
|
|
{"Birthday", "BDAY"},
|
|
|
|
{"Country", "CTRY"},
|
|
|
|
{"City", "LOCALITY"},
|
|
|
|
{"Email", "EMAIL"},
|
|
|
|
{"Organization Name", "ORGNAME"},
|
|
|
|
{"Organization Unit", "ORGUNIT"}
|
|
|
|
]).
|
|
|
|
|
|
|
|
%% Unused callbacks.
|
|
|
|
handle_cast(_Request, State) ->
|
|
|
|
{noreply, State}.
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
|
|
|
%% -----
|
|
|
|
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, Opts) ->
|
2006-09-14 04:54:21 +02:00
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
|
|
ChildSpec = {
|
|
|
|
Proc, {?MODULE, start_link, [Host, Opts]},
|
2007-01-27 17:40:37 +01:00
|
|
|
transient, 1000, worker, [?MODULE]
|
2006-09-14 04:54:21 +02:00
|
|
|
},
|
|
|
|
supervisor:start_child(ejabberd_sup, ChildSpec).
|
|
|
|
|
|
|
|
stop(Host) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
|
|
gen_server:call(Proc, stop),
|
|
|
|
supervisor:terminate_child(ejabberd_sup, Proc),
|
|
|
|
supervisor:delete_child(ejabberd_sup, Proc).
|
|
|
|
|
|
|
|
terminate(_Reason, State) ->
|
|
|
|
Host = State#state.serverhost,
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_VCARD),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_VCARD),
|
|
|
|
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
|
|
|
case State#state.search of
|
|
|
|
true ->
|
|
|
|
ejabberd_router:unregister_route(State#state.myhost);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
start_link(Host, Opts) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
|
|
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
|
|
|
|
|
|
|
|
init([Host, Opts]) ->
|
|
|
|
State = parse_options(Host, Opts),
|
2007-01-27 17:40:37 +01:00
|
|
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, parallel),
|
2005-06-20 05:18:13 +02:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_VCARD,
|
2004-07-30 23:09:55 +02:00
|
|
|
?MODULE, process_local_iq, IQDisc),
|
2005-06-20 05:18:13 +02:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_VCARD,
|
2004-07-30 23:09:55 +02:00
|
|
|
?MODULE, process_sm_iq, IQDisc),
|
2005-09-04 03:58:47 +02:00
|
|
|
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE, get_sm_features, 50),
|
2007-01-27 17:40:37 +01:00
|
|
|
eldap_pool:start_link(State#state.eldap_id,
|
2006-09-14 04:54:21 +02:00
|
|
|
State#state.servers,
|
2007-01-27 17:40:37 +01:00
|
|
|
State#state.backups,
|
2006-09-14 04:54:21 +02:00
|
|
|
State#state.port,
|
|
|
|
State#state.dn,
|
2009-05-25 19:15:48 +02:00
|
|
|
State#state.password,
|
|
|
|
State#state.encrypt),
|
2006-09-14 04:54:21 +02:00
|
|
|
case State#state.search of
|
|
|
|
true ->
|
|
|
|
ejabberd_router:register_route(State#state.myhost);
|
2004-07-30 23:09:55 +02:00
|
|
|
_ ->
|
2006-09-14 04:54:21 +02:00
|
|
|
ok
|
|
|
|
end,
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
handle_info({route, From, To, Packet}, State) ->
|
|
|
|
case catch do_route(State, From, To, Packet) of
|
2007-01-27 17:40:37 +01:00
|
|
|
Pid when is_pid(Pid) ->
|
|
|
|
ok;
|
2004-07-30 23:09:55 +02:00
|
|
|
_ ->
|
2007-01-27 17:40:37 +01:00
|
|
|
Err = jlib:make_error_reply(Packet, ?ERR_INTERNAL_SERVER_ERROR),
|
|
|
|
ejabberd_router:route(To, From, Err)
|
|
|
|
end,
|
|
|
|
{noreply, State};
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
handle_info(_Info, State) ->
|
|
|
|
{noreply, State}.
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2005-09-04 03:58:47 +02:00
|
|
|
get_sm_features({error, _Error} = Acc, _From, _To, _Node, _Lang) ->
|
|
|
|
Acc;
|
|
|
|
get_sm_features(Acc, _From, _To, Node, _Lang) ->
|
|
|
|
case Node of
|
2006-09-14 04:54:21 +02:00
|
|
|
[] ->
|
|
|
|
case Acc of
|
|
|
|
{result, Features} ->
|
|
|
|
{result, [?NS_VCARD | Features]};
|
|
|
|
empty ->
|
|
|
|
{result, [?NS_VCARD]}
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
Acc
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2004-07-30 23:09:55 +02:00
|
|
|
process_local_iq(_From, _To, #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
|
|
|
case Type of
|
|
|
|
set ->
|
|
|
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
get ->
|
|
|
|
IQ#iq{type = result,
|
|
|
|
sub_el = [{xmlelement, "vCard",
|
|
|
|
[{"xmlns", ?NS_VCARD}],
|
|
|
|
[{xmlelement, "FN", [],
|
|
|
|
[{xmlcdata, "ejabberd"}]},
|
|
|
|
{xmlelement, "URL", [],
|
2007-11-28 00:35:26 +01:00
|
|
|
[{xmlcdata, ?EJABBERD_URI}]},
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement, "DESC", [],
|
|
|
|
[{xmlcdata,
|
|
|
|
translate:translate(
|
|
|
|
Lang,
|
2007-12-15 13:02:00 +01:00
|
|
|
"Erlang Jabber Server") ++
|
2010-01-12 17:11:32 +01:00
|
|
|
"\nCopyright (c) 2002-2010 ProcessOne"}]},
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement, "BDAY", [],
|
|
|
|
[{xmlcdata, "2002-11-16"}]}
|
|
|
|
]}]}
|
|
|
|
end.
|
|
|
|
|
2007-01-27 17:40:37 +01:00
|
|
|
process_sm_iq(_From, #jid{lserver=LServer} = To, #iq{sub_el = SubEl} = IQ) ->
|
|
|
|
case catch process_vcard_ldap(To, IQ, LServer) of
|
|
|
|
{'EXIT', _} ->
|
|
|
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
|
2006-09-14 04:54:21 +02:00
|
|
|
Other ->
|
|
|
|
Other
|
2004-07-30 23:09:55 +02:00
|
|
|
end.
|
|
|
|
|
2007-01-27 17:40:37 +01:00
|
|
|
process_vcard_ldap(To, IQ, Server) ->
|
|
|
|
{ok, State} = eldap_utils:get_state(Server, ?PROCNAME),
|
2006-09-14 04:54:21 +02:00
|
|
|
#iq{type = Type, sub_el = SubEl} = IQ,
|
2007-01-27 17:40:37 +01:00
|
|
|
case Type of
|
|
|
|
set ->
|
|
|
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
get ->
|
|
|
|
#jid{luser = LUser} = To,
|
|
|
|
LServer = State#state.serverhost,
|
|
|
|
case ejabberd_auth:is_user_exists(LUser, LServer) of
|
|
|
|
true ->
|
|
|
|
VCardMap = State#state.vcard_map,
|
|
|
|
case find_ldap_user(LUser, State) of
|
|
|
|
#eldap_entry{attributes = Attributes} ->
|
|
|
|
Vcard = ldap_attributes_to_vcard(Attributes, VCardMap, {LUser, LServer}),
|
|
|
|
IQ#iq{type = result, sub_el = Vcard};
|
2006-09-14 04:54:21 +02:00
|
|
|
_ ->
|
|
|
|
IQ#iq{type = result, sub_el = []}
|
2007-01-27 17:40:37 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
IQ#iq{type = result, sub_el = []}
|
|
|
|
end
|
|
|
|
end.
|
2006-09-14 04:54:21 +02:00
|
|
|
|
2007-01-27 17:40:37 +01:00
|
|
|
handle_call(get_state, _From, State) ->
|
|
|
|
{reply, {ok, State}, State};
|
2006-09-14 04:54:21 +02:00
|
|
|
handle_call(stop, _From, State) ->
|
|
|
|
{stop, normal, ok, State};
|
|
|
|
handle_call(_Request, _From, State) ->
|
|
|
|
{reply, bad_request, State}.
|
|
|
|
|
|
|
|
find_ldap_user(User, State) ->
|
|
|
|
Base = State#state.base,
|
|
|
|
RFC2254_Filter = State#state.user_filter,
|
|
|
|
Eldap_ID = State#state.eldap_id,
|
|
|
|
VCardAttrs = State#state.vcard_map_attrs,
|
|
|
|
case eldap_filter:parse(RFC2254_Filter, [{"%u", User}]) of
|
|
|
|
{ok, EldapFilter} ->
|
2007-01-27 17:40:37 +01:00
|
|
|
case eldap_pool:search(Eldap_ID, [{base, Base},
|
2006-09-14 04:54:21 +02:00
|
|
|
{filter, EldapFilter},
|
|
|
|
{attributes, VCardAttrs}]) of
|
|
|
|
#eldap_search_result{entries = [E | _]} ->
|
|
|
|
E;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end;
|
2004-07-30 23:09:55 +02:00
|
|
|
_ ->
|
2006-09-14 04:54:21 +02:00
|
|
|
false
|
2004-07-30 23:09:55 +02:00
|
|
|
end.
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attributes_to_vcard(Attributes, VCardMap, UD) ->
|
|
|
|
Attrs = lists:map(
|
|
|
|
fun({VCardName, _, _}) ->
|
|
|
|
{stringprep:tolower(VCardName),
|
|
|
|
map_vcard_attr(VCardName, Attributes, VCardMap, UD)}
|
|
|
|
end, VCardMap),
|
|
|
|
Elts = [ldap_attribute_to_vcard(vCard, Attr) || Attr <- Attrs],
|
|
|
|
NElts = [ldap_attribute_to_vcard(vCardN, Attr) || Attr <- Attrs],
|
|
|
|
OElts = [ldap_attribute_to_vcard(vCardO, Attr) || Attr <- Attrs],
|
|
|
|
AElts = [ldap_attribute_to_vcard(vCardA, Attr) || Attr <- Attrs],
|
|
|
|
[{xmlelement, "vCard", [{"xmlns", ?NS_VCARD}],
|
|
|
|
lists:append([X || X <- Elts, X /= none],
|
|
|
|
[{xmlelement,"N",[], [X || X <- NElts, X /= none]},
|
|
|
|
{xmlelement,"ORG",[], [X || X <- OElts, X /= none]},
|
|
|
|
{xmlelement,"ADR",[], [X || X <- AElts, X /= none]}])
|
|
|
|
}].
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCard, {"fn", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"FN",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"nickname", Value}) ->
|
2007-12-27 17:40:03 +01:00
|
|
|
{xmlelement,"NICKNAME",[],[{xmlcdata,Value}]};
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"title", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"TITLE",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"bday", Value}) ->
|
|
|
|
{xmlelement,"BDAY",[],[{xmlcdata,Value}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCard, {"url", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"URL",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"desc", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"DESC",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"role", Value}) ->
|
|
|
|
{xmlelement,"ROLE",[],[{xmlcdata,Value}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCard, {"tel", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"TEL",[],[{xmlelement,"VOICE",[],[]},
|
|
|
|
{xmlelement,"WORK",[],[]},
|
|
|
|
{xmlelement,"NUMBER",[],[{xmlcdata,Value}]}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"email", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"EMAIL",[],[{xmlelement,"INTERNET",[],[]},
|
|
|
|
{xmlelement,"PREF",[],[]},
|
|
|
|
{xmlelement,"USERID",[],[{xmlcdata,Value}]}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCard, {"photo", Value}) ->
|
|
|
|
{xmlelement,"PHOTO",[],[
|
|
|
|
{xmlelement,"BINVAL",[],[{xmlcdata, jlib:encode_base64(Value)}]}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCardN, {"family", Value}) ->
|
2007-12-27 17:40:03 +01:00
|
|
|
{xmlelement,"FAMILY",[],[{xmlcdata,Value}]};
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCardN, {"given", Value}) ->
|
2007-12-27 17:40:03 +01:00
|
|
|
{xmlelement,"GIVEN",[],[{xmlcdata,Value}]};
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCardN, {"middle", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"MIDDLE",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCardO, {"orgname", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"ORGNAME",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCardO, {"orgunit", Value}) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement,"ORGUNIT",[],[{xmlcdata,Value}]};
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCardA, {"locality", Value}) ->
|
|
|
|
{xmlelement,"LOCALITY",[],[{xmlcdata,Value}]};
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
ldap_attribute_to_vcard(vCardA, {"street", Value}) ->
|
|
|
|
{xmlelement,"STREET",[],[{xmlcdata,Value}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCardA, {"ctry", Value}) ->
|
|
|
|
{xmlelement,"CTRY",[],[{xmlcdata,Value}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCardA, {"region", Value}) ->
|
|
|
|
{xmlelement,"REGION",[],[{xmlcdata,Value}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(vCardA, {"pcode", Value}) ->
|
|
|
|
{xmlelement,"PCODE",[],[{xmlcdata,Value}]};
|
|
|
|
|
|
|
|
ldap_attribute_to_vcard(_, _) ->
|
|
|
|
none.
|
2004-07-30 23:09:55 +02:00
|
|
|
|
|
|
|
-define(TLFIELD(Type, Label, Var),
|
|
|
|
{xmlelement, "field", [{"type", Type},
|
|
|
|
{"label", translate:translate(Lang, Label)},
|
|
|
|
{"var", Var}], []}).
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
-define(FORM(JID, SearchFields),
|
2004-07-30 23:09:55 +02:00
|
|
|
[{xmlelement, "instructions", [],
|
|
|
|
[{xmlcdata, translate:translate(Lang, "You need an x:data capable client to search")}]},
|
|
|
|
{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
|
|
|
|
[{xmlelement, "title", [],
|
|
|
|
[{xmlcdata, translate:translate(Lang, "Search users in ") ++
|
|
|
|
jlib:jid_to_string(JID)}]},
|
|
|
|
{xmlelement, "instructions", [],
|
|
|
|
[{xmlcdata, translate:translate(Lang, "Fill in fields to search "
|
2006-09-14 04:54:21 +02:00
|
|
|
"for any matching Jabber User")}]}
|
|
|
|
] ++ lists:map(fun({X,Y}) -> ?TLFIELD("text-single", X, Y) end, SearchFields)}]).
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
do_route(State, From, To, Packet) ->
|
2007-01-27 17:40:37 +01:00
|
|
|
spawn(?MODULE, route, [State, From, To, Packet]).
|
|
|
|
|
|
|
|
route(State, From, To, Packet) ->
|
2004-07-30 23:09:55 +02:00
|
|
|
#jid{user = User, resource = Resource} = To,
|
2009-07-17 22:45:44 +02:00
|
|
|
ServerHost = State#state.serverhost,
|
2004-07-30 23:09:55 +02:00
|
|
|
if
|
|
|
|
(User /= "") or (Resource /= "") ->
|
|
|
|
Err = jlib:make_error_reply(Packet, ?ERR_SERVICE_UNAVAILABLE),
|
2006-09-14 04:54:21 +02:00
|
|
|
ejabberd_router:route(To, From, Err);
|
2004-07-30 23:09:55 +02:00
|
|
|
true ->
|
|
|
|
IQ = jlib:iq_query_info(Packet),
|
|
|
|
case IQ of
|
|
|
|
#iq{type = Type, xmlns = ?NS_SEARCH, lang = Lang, sub_el = SubEl} ->
|
|
|
|
case Type of
|
|
|
|
set ->
|
|
|
|
XDataEl = find_xdata_el(SubEl),
|
|
|
|
case XDataEl of
|
|
|
|
false ->
|
|
|
|
Err = jlib:make_error_reply(
|
|
|
|
Packet, ?ERR_BAD_REQUEST),
|
|
|
|
ejabberd_router:route(To, From, Err);
|
|
|
|
_ ->
|
|
|
|
XData = jlib:parse_xdata_submit(XDataEl),
|
|
|
|
case XData of
|
|
|
|
invalid ->
|
|
|
|
Err = jlib:make_error_reply(
|
|
|
|
Packet,
|
|
|
|
?ERR_BAD_REQUEST),
|
|
|
|
ejabberd_router:route(To, From,
|
|
|
|
Err);
|
|
|
|
_ ->
|
|
|
|
ResIQ =
|
|
|
|
IQ#iq{
|
|
|
|
type = result,
|
|
|
|
sub_el =
|
|
|
|
[{xmlelement,
|
|
|
|
"query",
|
|
|
|
[{"xmlns", ?NS_SEARCH}],
|
|
|
|
[{xmlelement, "x",
|
|
|
|
[{"xmlns", ?NS_XDATA},
|
|
|
|
{"type", "result"}],
|
2006-09-14 04:54:21 +02:00
|
|
|
search_result(Lang, To, State, XData)
|
2004-07-30 23:09:55 +02:00
|
|
|
}]}]},
|
|
|
|
ejabberd_router:route(
|
|
|
|
To, From, jlib:iq_to_xml(ResIQ))
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
get ->
|
2006-09-14 04:54:21 +02:00
|
|
|
SearchFields = State#state.search_fields,
|
2004-07-30 23:09:55 +02:00
|
|
|
ResIQ = IQ#iq{type = result,
|
|
|
|
sub_el = [{xmlelement,
|
|
|
|
"query",
|
|
|
|
[{"xmlns", ?NS_SEARCH}],
|
2006-09-14 04:54:21 +02:00
|
|
|
?FORM(To, SearchFields)
|
2004-07-30 23:09:55 +02:00
|
|
|
}]},
|
|
|
|
ejabberd_router:route(To,
|
|
|
|
From,
|
|
|
|
jlib:iq_to_xml(ResIQ))
|
|
|
|
end;
|
2007-05-29 16:53:09 +02:00
|
|
|
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
|
2004-07-30 23:09:55 +02:00
|
|
|
case Type of
|
|
|
|
set ->
|
|
|
|
Err = jlib:make_error_reply(
|
|
|
|
Packet, ?ERR_NOT_ALLOWED),
|
|
|
|
ejabberd_router:route(To, From, Err);
|
|
|
|
get ->
|
2009-07-17 22:45:44 +02:00
|
|
|
Info = ejabberd_hooks:run_fold(
|
|
|
|
disco_info, ServerHost, [],
|
|
|
|
[ServerHost, ?MODULE, "", ""]),
|
2004-07-30 23:09:55 +02:00
|
|
|
ResIQ =
|
|
|
|
IQ#iq{type = result,
|
|
|
|
sub_el = [{xmlelement,
|
|
|
|
"query",
|
|
|
|
[{"xmlns", ?NS_DISCO_INFO}],
|
|
|
|
[{xmlelement, "identity",
|
|
|
|
[{"category", "directory"},
|
|
|
|
{"type", "user"},
|
|
|
|
{"name",
|
2007-05-29 16:53:09 +02:00
|
|
|
translate:translate(Lang, "vCard User Search")}],
|
2004-07-30 23:09:55 +02:00
|
|
|
[]},
|
|
|
|
{xmlelement, "feature",
|
|
|
|
[{"var", ?NS_SEARCH}], []},
|
|
|
|
{xmlelement, "feature",
|
|
|
|
[{"var", ?NS_VCARD}], []}
|
2009-07-17 22:45:44 +02:00
|
|
|
] ++ Info
|
2004-07-30 23:09:55 +02:00
|
|
|
}]},
|
|
|
|
ejabberd_router:route(To,
|
|
|
|
From,
|
|
|
|
jlib:iq_to_xml(ResIQ))
|
|
|
|
end;
|
2006-09-14 04:54:21 +02:00
|
|
|
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} ->
|
2004-07-30 23:09:55 +02:00
|
|
|
case Type of
|
|
|
|
set ->
|
|
|
|
Err = jlib:make_error_reply(
|
|
|
|
Packet, ?ERR_NOT_ALLOWED),
|
|
|
|
ejabberd_router:route(To, From, Err);
|
|
|
|
get ->
|
|
|
|
ResIQ =
|
|
|
|
IQ#iq{type = result,
|
|
|
|
sub_el = [{xmlelement,
|
|
|
|
"query",
|
2005-11-19 02:20:05 +01:00
|
|
|
[{"xmlns", ?NS_DISCO_ITEMS}],
|
2004-07-30 23:09:55 +02:00
|
|
|
[]}]},
|
|
|
|
ejabberd_router:route(To,
|
|
|
|
From,
|
|
|
|
jlib:iq_to_xml(ResIQ))
|
|
|
|
end;
|
|
|
|
#iq{type = get, xmlns = ?NS_VCARD, lang = Lang} ->
|
|
|
|
ResIQ =
|
|
|
|
IQ#iq{type = result,
|
|
|
|
sub_el = [{xmlelement,
|
|
|
|
"vCard",
|
|
|
|
[{"xmlns", ?NS_VCARD}],
|
|
|
|
iq_get_vcard(Lang)}]},
|
|
|
|
ejabberd_router:route(To,
|
|
|
|
From,
|
|
|
|
jlib:iq_to_xml(ResIQ));
|
|
|
|
_ ->
|
|
|
|
Err = jlib:make_error_reply(Packet,
|
|
|
|
?ERR_SERVICE_UNAVAILABLE),
|
|
|
|
ejabberd_router:route(To, From, Err)
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
iq_get_vcard(Lang) ->
|
|
|
|
[{xmlelement, "FN", [],
|
|
|
|
[{xmlcdata, "ejabberd/mod_vcard"}]},
|
|
|
|
{xmlelement, "URL", [],
|
2007-11-28 00:35:26 +01:00
|
|
|
[{xmlcdata, ?EJABBERD_URI}]},
|
2004-07-30 23:09:55 +02:00
|
|
|
{xmlelement, "DESC", [],
|
|
|
|
[{xmlcdata, translate:translate(
|
|
|
|
Lang,
|
2007-12-15 13:02:00 +01:00
|
|
|
"ejabberd vCard module") ++
|
2010-01-12 17:11:32 +01:00
|
|
|
"\nCopyright (c) 2003-2010 ProcessOne"}]}].
|
2004-07-30 23:09:55 +02:00
|
|
|
|
|
|
|
-define(LFIELD(Label, Var),
|
|
|
|
{xmlelement, "field", [{"label", translate:translate(Lang, Label)},
|
|
|
|
{"var", Var}], []}).
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
search_result(Lang, JID, State, Data) ->
|
|
|
|
SearchReported = State#state.search_reported,
|
|
|
|
Header = [{xmlelement, "title", [],
|
|
|
|
[{xmlcdata, translate:translate(Lang, "Search Results for ") ++
|
|
|
|
jlib:jid_to_string(JID)}]},
|
|
|
|
{xmlelement, "reported", [],
|
2007-11-29 19:24:31 +01:00
|
|
|
[?TLFIELD("text-single", "Jabber ID", "jid")] ++
|
2006-09-14 04:54:21 +02:00
|
|
|
lists:map(
|
2007-11-29 19:24:31 +01:00
|
|
|
fun({Name, Value}) -> ?TLFIELD("text-single", Name, Value) end,
|
2006-09-14 04:54:21 +02:00
|
|
|
SearchReported)
|
|
|
|
}],
|
|
|
|
case search(State, Data) of
|
|
|
|
error ->
|
|
|
|
Header;
|
|
|
|
Result ->
|
|
|
|
Header ++ Result
|
|
|
|
end.
|
2004-07-30 23:09:55 +02:00
|
|
|
|
|
|
|
-define(FIELD(Var, Val),
|
|
|
|
{xmlelement, "field", [{"var", Var}],
|
|
|
|
[{xmlelement, "value", [],
|
|
|
|
[{xmlcdata, Val}]}]}).
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
search(State, Data) ->
|
|
|
|
Base = State#state.base,
|
|
|
|
SearchFilter = State#state.search_filter,
|
|
|
|
Eldap_ID = State#state.eldap_id,
|
2006-10-17 14:35:47 +02:00
|
|
|
UIDs = State#state.uids,
|
2007-01-27 17:40:37 +01:00
|
|
|
Limit = State#state.matches,
|
2006-09-14 04:54:21 +02:00
|
|
|
ReportedAttrs = State#state.search_reported_attrs,
|
2006-10-17 14:35:47 +02:00
|
|
|
Filter = eldap:'and'([SearchFilter, eldap_utils:make_filter(Data, UIDs)]),
|
2007-01-27 17:40:37 +01:00
|
|
|
case eldap_pool:search(Eldap_ID, [{base, Base},
|
2006-09-14 04:54:21 +02:00
|
|
|
{filter, Filter},
|
2007-01-27 17:40:37 +01:00
|
|
|
{limit, Limit},
|
2006-09-14 04:54:21 +02:00
|
|
|
{attributes, ReportedAttrs}]) of
|
2004-07-30 23:09:55 +02:00
|
|
|
#eldap_search_result{entries = E} ->
|
2006-09-14 04:54:21 +02:00
|
|
|
search_items(E, State);
|
|
|
|
_ ->
|
|
|
|
error
|
2004-07-30 23:09:55 +02:00
|
|
|
end.
|
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
search_items(Entries, State) ->
|
|
|
|
LServer = State#state.serverhost,
|
|
|
|
SearchReported = State#state.search_reported,
|
|
|
|
VCardMap = State#state.vcard_map,
|
2006-10-17 14:35:47 +02:00
|
|
|
UIDs = State#state.uids,
|
2006-09-14 04:54:21 +02:00
|
|
|
Attributes = lists:map(
|
|
|
|
fun(E) ->
|
|
|
|
#eldap_entry{attributes = Attrs} = E,
|
|
|
|
Attrs
|
|
|
|
end, Entries),
|
|
|
|
lists:flatmap(
|
|
|
|
fun(Attrs) ->
|
2006-10-17 14:35:47 +02:00
|
|
|
case eldap_utils:find_ldap_attrs(UIDs, Attrs) of
|
|
|
|
{U, UIDAttrFormat} ->
|
|
|
|
case eldap_utils:get_user_part(U, UIDAttrFormat) of
|
|
|
|
{ok, Username} ->
|
|
|
|
case ejabberd_auth:is_user_exists(Username, LServer) of
|
|
|
|
true ->
|
|
|
|
RFields = lists:map(
|
2006-09-14 04:54:21 +02:00
|
|
|
fun({_, VCardName}) ->
|
|
|
|
{VCardName,
|
|
|
|
map_vcard_attr(
|
|
|
|
VCardName,
|
|
|
|
Attrs,
|
|
|
|
VCardMap,
|
|
|
|
{Username, ?MYNAME})}
|
|
|
|
end, SearchReported),
|
2006-10-17 14:35:47 +02:00
|
|
|
Result = [?FIELD("jid", Username ++ "@" ++ LServer)] ++
|
|
|
|
[?FIELD(Name, Value) || {Name, Value} <- RFields],
|
|
|
|
[{xmlelement, "item", [], Result}];
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
"" ->
|
2006-09-14 04:54:21 +02:00
|
|
|
[]
|
2006-10-17 14:35:47 +02:00
|
|
|
end
|
2006-09-14 04:54:21 +02:00
|
|
|
end, Attributes).
|
|
|
|
|
|
|
|
remove_user(_User) ->
|
|
|
|
true.
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
%%%-----------------------
|
|
|
|
%%% Auxiliary functions.
|
|
|
|
%%%-----------------------
|
|
|
|
|
|
|
|
map_vcard_attr(VCardName, Attributes, Pattern, UD) ->
|
|
|
|
Res = lists:filter(
|
|
|
|
fun({Name, _, _}) ->
|
2006-10-17 14:35:47 +02:00
|
|
|
eldap_utils:case_insensitive_match(Name, VCardName)
|
2006-09-14 04:54:21 +02:00
|
|
|
end, Pattern),
|
|
|
|
case Res of
|
|
|
|
[{_, Str, Attrs}] ->
|
|
|
|
process_pattern(Str, UD,
|
2006-10-17 14:35:47 +02:00
|
|
|
[eldap_utils:get_ldap_attr(X, Attributes) || X<-Attrs]);
|
2006-09-14 04:54:21 +02:00
|
|
|
_ -> ""
|
|
|
|
end.
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-23 06:28:03 +02:00
|
|
|
process_pattern(Str, {User, Domain}, AttrValues) ->
|
2009-07-31 08:32:24 +02:00
|
|
|
eldap_filter:do_sub(
|
|
|
|
Str,
|
|
|
|
[{"%u", User},{"%d", Domain}] ++
|
|
|
|
[{"%s", V, 1} || V <- AttrValues]).
|
2006-09-14 04:54:21 +02:00
|
|
|
|
|
|
|
find_xdata_el({xmlelement, _Name, _Attrs, SubEls}) ->
|
|
|
|
find_xdata_el1(SubEls).
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
find_xdata_el1([]) ->
|
|
|
|
false;
|
|
|
|
find_xdata_el1([{xmlelement, Name, Attrs, SubEls} | Els]) ->
|
|
|
|
case xml:get_attr_s("xmlns", Attrs) of
|
|
|
|
?NS_XDATA ->
|
|
|
|
{xmlelement, Name, Attrs, SubEls};
|
|
|
|
_ ->
|
|
|
|
find_xdata_el1(Els)
|
|
|
|
end;
|
|
|
|
find_xdata_el1([_ | Els]) ->
|
|
|
|
find_xdata_el1(Els).
|
2004-07-30 23:09:55 +02:00
|
|
|
|
2006-09-14 04:54:21 +02:00
|
|
|
parse_options(Host, Opts) ->
|
2007-08-25 19:24:00 +02:00
|
|
|
MyHost = gen_mod:get_opt_host(Host, Opts, "vjud.@HOST@"),
|
2006-09-14 04:54:21 +02:00
|
|
|
Search = gen_mod:get_opt(search, Opts, true),
|
2007-01-27 17:40:37 +01:00
|
|
|
Matches = case gen_mod:get_opt(matches, Opts, 30) of
|
|
|
|
infinity -> 0;
|
|
|
|
N -> N
|
|
|
|
end,
|
2006-09-14 04:54:21 +02:00
|
|
|
Eldap_ID = atom_to_list(gen_mod:get_module_proc(Host, ?PROCNAME)),
|
|
|
|
LDAPServers = case gen_mod:get_opt(ldap_servers, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
ejabberd_config:get_local_option({ldap_servers, Host});
|
|
|
|
S -> S
|
|
|
|
end,
|
2007-01-27 17:40:37 +01:00
|
|
|
LDAPBackups = case gen_mod:get_opt(ldap_backups, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
ejabberd_config:get_local_option({ldap_servers, Host});
|
|
|
|
Backups -> Backups
|
|
|
|
end,
|
2009-05-25 19:15:48 +02:00
|
|
|
LDAPEncrypt = case gen_mod:get_opt(ldap_encrypt, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
ejabberd_config:get_local_option({ldap_encrypt, Host});
|
|
|
|
E -> E
|
|
|
|
end,
|
|
|
|
LDAPPortTemp = case gen_mod:get_opt(ldap_port, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
ejabberd_config:get_local_option({ldap_port, Host});
|
|
|
|
PT -> PT
|
|
|
|
end,
|
|
|
|
LDAPPort = case LDAPPortTemp of
|
2006-09-14 04:54:21 +02:00
|
|
|
undefined ->
|
2009-05-25 19:15:48 +02:00
|
|
|
case LDAPEncrypt of
|
|
|
|
tls -> ?LDAPS_PORT;
|
|
|
|
starttls -> ?LDAP_PORT;
|
|
|
|
_ -> ?LDAP_PORT
|
2006-09-14 04:54:21 +02:00
|
|
|
end;
|
|
|
|
P -> P
|
|
|
|
end,
|
|
|
|
LDAPBase = case gen_mod:get_opt(ldap_base, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
ejabberd_config:get_local_option({ldap_base, Host});
|
|
|
|
B -> B
|
|
|
|
end,
|
2006-10-17 14:35:47 +02:00
|
|
|
UIDs = case gen_mod:get_opt(ldap_uids, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
case ejabberd_config:get_local_option({ldap_uids, Host}) of
|
|
|
|
undefined -> [{"uid", "%u"}];
|
2007-01-27 17:40:37 +01:00
|
|
|
UI -> eldap_utils:uids_domain_subst(Host, UI)
|
2006-10-17 14:35:47 +02:00
|
|
|
end;
|
2007-01-27 17:40:37 +01:00
|
|
|
UI -> eldap_utils:uids_domain_subst(Host, UI)
|
2006-10-17 14:35:47 +02:00
|
|
|
end,
|
2006-09-14 04:54:21 +02:00
|
|
|
RootDN = case gen_mod:get_opt(ldap_rootdn, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
case ejabberd_config:get_local_option({ldap_rootdn, Host}) of
|
|
|
|
undefined -> "";
|
|
|
|
RDN -> RDN
|
|
|
|
end;
|
|
|
|
RDN -> RDN
|
|
|
|
end,
|
|
|
|
Password = case gen_mod:get_opt(ldap_password, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
case ejabberd_config:get_local_option({ldap_password, Host}) of
|
|
|
|
undefined -> "";
|
|
|
|
Pass -> Pass
|
|
|
|
end;
|
|
|
|
Pass -> Pass
|
|
|
|
end,
|
2006-10-17 14:35:47 +02:00
|
|
|
SubFilter = lists:flatten(eldap_utils:generate_subfilter(UIDs)),
|
2006-09-14 04:54:21 +02:00
|
|
|
UserFilter = case gen_mod:get_opt(ldap_filter, Opts, undefined) of
|
|
|
|
undefined ->
|
|
|
|
case ejabberd_config:get_local_option({ldap_filter, Host}) of
|
|
|
|
undefined -> SubFilter;
|
|
|
|
"" -> SubFilter;
|
|
|
|
F -> "(&" ++ SubFilter ++ F ++ ")"
|
|
|
|
end;
|
|
|
|
"" -> SubFilter;
|
|
|
|
F -> "(&" ++ SubFilter ++ F ++ ")"
|
|
|
|
end,
|
|
|
|
{ok, SearchFilter} = eldap_filter:parse(
|
|
|
|
eldap_filter:do_sub(UserFilter, [{"%u","*"}])),
|
|
|
|
VCardMap = gen_mod:get_opt(ldap_vcard_map, Opts, ?VCARD_MAP),
|
|
|
|
SearchFields = gen_mod:get_opt(ldap_search_fields, Opts, ?SEARCH_FIELDS),
|
|
|
|
SearchReported = gen_mod:get_opt(ldap_search_reported, Opts, ?SEARCH_REPORTED),
|
|
|
|
%% In search requests we need to fetch only attributes defined
|
|
|
|
%% in vcard-map and search-reported. In some cases,
|
|
|
|
%% this will essentially reduce network traffic from an LDAP server.
|
2006-10-17 14:35:47 +02:00
|
|
|
UIDAttrs = [UAttr || {UAttr, _} <- UIDs],
|
2006-09-14 04:54:21 +02:00
|
|
|
VCardMapAttrs = lists:usort(
|
2006-10-17 14:35:47 +02:00
|
|
|
lists:append([A || {_, _, A} <- VCardMap]) ++ UIDAttrs),
|
2006-09-14 04:54:21 +02:00
|
|
|
SearchReportedAttrs =
|
|
|
|
lists:usort(lists:flatmap(
|
|
|
|
fun({_, N}) ->
|
|
|
|
case lists:keysearch(N, 1, VCardMap) of
|
|
|
|
{value, {_, _, L}} -> L;
|
|
|
|
_ -> []
|
|
|
|
end
|
2006-10-17 14:35:47 +02:00
|
|
|
end, SearchReported) ++ UIDAttrs),
|
2006-09-14 04:54:21 +02:00
|
|
|
#state{serverhost = Host,
|
|
|
|
myhost = MyHost,
|
|
|
|
eldap_id = Eldap_ID,
|
|
|
|
search = Search,
|
|
|
|
servers = LDAPServers,
|
2007-01-27 17:40:37 +01:00
|
|
|
backups = LDAPBackups,
|
2006-09-14 04:54:21 +02:00
|
|
|
port = LDAPPort,
|
2009-05-25 19:15:48 +02:00
|
|
|
encrypt = LDAPEncrypt,
|
2006-09-14 04:54:21 +02:00
|
|
|
dn = RootDN,
|
|
|
|
base = LDAPBase,
|
|
|
|
password = Password,
|
2006-10-17 14:35:47 +02:00
|
|
|
uids = UIDs,
|
2006-09-14 04:54:21 +02:00
|
|
|
vcard_map = VCardMap,
|
|
|
|
vcard_map_attrs = VCardMapAttrs,
|
|
|
|
user_filter = UserFilter,
|
|
|
|
search_filter = SearchFilter,
|
|
|
|
search_fields = SearchFields,
|
|
|
|
search_reported = SearchReported,
|
2007-01-27 17:40:37 +01:00
|
|
|
search_reported_attrs = SearchReportedAttrs,
|
|
|
|
matches = Matches
|
2006-09-14 04:54:21 +02:00
|
|
|
}.
|