2003-01-18 20:42:48 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : acl.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Purpose :
|
|
|
|
%%% Created : 18 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
|
|
|
%%% Id : $Id$
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(acl).
|
|
|
|
-author('alexey@sevcom.net').
|
|
|
|
-vsn('$Revision$ ').
|
|
|
|
|
|
|
|
-export([start/0, add/2, match_rule/2, match_acl/2]).
|
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
|
2003-01-29 18:12:23 +01:00
|
|
|
-record(acl, {aclname, aclspec}).
|
|
|
|
|
2003-01-18 20:42:48 +01:00
|
|
|
start() ->
|
2003-01-29 18:12:23 +01:00
|
|
|
%ets:new(acls, [bag, named_table, public]),
|
|
|
|
mnesia:create_table(acl,
|
|
|
|
[{disc_copies, [node()]},
|
|
|
|
{type, bag},
|
|
|
|
{attributes, record_info(fields, acl)}]),
|
|
|
|
mnesia:add_table_copy(acl, node(), ram_copies),
|
2003-01-21 21:36:55 +01:00
|
|
|
ok.
|
2003-01-18 20:42:48 +01:00
|
|
|
|
|
|
|
|
2003-01-29 18:12:23 +01:00
|
|
|
add(ACLName, ACLSpec) ->
|
|
|
|
F = fun() ->
|
|
|
|
mnesia:write(#acl{aclname = ACLName, aclspec = ACLSpec})
|
|
|
|
end,
|
|
|
|
mnesia:transaction(F).
|
|
|
|
%ets:insert(acls, {ACLName, ACLData}).
|
2003-01-18 20:42:48 +01:00
|
|
|
|
|
|
|
match_rule(Rule, JID) ->
|
2003-01-21 21:36:55 +01:00
|
|
|
case ejabberd_config:get_global_option({access, Rule}) of
|
2003-01-19 21:17:56 +01:00
|
|
|
undefined ->
|
|
|
|
deny;
|
|
|
|
ACLs ->
|
|
|
|
match_acls(ACLs, JID)
|
|
|
|
end.
|
2003-01-18 20:42:48 +01:00
|
|
|
|
|
|
|
match_acls([], _) ->
|
|
|
|
deny;
|
|
|
|
match_acls([{Access, ACL} | ACLs], JID) ->
|
|
|
|
case match_acl(ACL, JID) of
|
|
|
|
true ->
|
|
|
|
Access;
|
|
|
|
_ ->
|
|
|
|
match_acls(ACLs, JID)
|
|
|
|
end.
|
|
|
|
|
|
|
|
match_acl(ACL, JID) ->
|
|
|
|
{User, Server, Resource} = jlib:jid_tolower(JID),
|
2003-01-29 18:12:23 +01:00
|
|
|
lists:any(fun(#acl{aclspec = Spec}) ->
|
2003-01-18 20:42:48 +01:00
|
|
|
case Spec of
|
|
|
|
all ->
|
|
|
|
true;
|
|
|
|
{user, U} ->
|
|
|
|
(U == User) and (?MYNAME == Server);
|
|
|
|
{user, U, S} ->
|
|
|
|
(U == User) and (S == Server);
|
|
|
|
{server, S} ->
|
|
|
|
S == Server
|
|
|
|
end
|
2003-01-29 18:12:23 +01:00
|
|
|
end, ets:lookup(acl, ACL)).
|