From c88a4650ba08028d6d8d545de8888dcdd4f11d37 Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 25 Apr 2008 09:25:31 +0000 Subject: [PATCH] * src/ejabberd_c2s.erl: Added forbidden_session_hook * src/acl.erl: New access types: resource, resource_regexp and resource_glob * doc/guide.tex: Likewise SVN Revision: 1301 --- ChangeLog | 8 ++++++++ doc/guide.tex | 11 +++++++++++ src/acl.erl | 8 +++++++- src/ejabberd_c2s.erl | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index cbd370e02..d712b3a7f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-04-25 Badlop + + * src/ejabberd_c2s.erl: Added forbidden_session_hook + + * src/acl.erl: New access types: resource, resource_regexp and + resource_glob + * doc/guide.tex: Likewise + 2008-04-23 Alexey Shchepin * src/treap.erl: Bugfix diff --git a/doc/guide.tex b/doc/guide.tex index 293a1107f..b8b9fd1db 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -1142,6 +1142,11 @@ declarations of ACLs in the configuration file have the following syntax: \begin{verbatim} {acl, exampleorg, {server, "example.org"}}. \end{verbatim} +\titem{\{resource, \}} Matches any JID with a resource + \term{}. Example: +\begin{verbatim} +{acl, mucklres, {resource, "muckl"}}. +\end{verbatim} \titem{\{user\_regexp, \}} Matches any local user with a name that matches \term{} on local virtual hosts. Example: \begin{verbatim} @@ -1158,6 +1163,11 @@ declarations of ACLs in the configuration file have the following syntax: \begin{verbatim} {acl, icq, {server_regexp, "^icq\\."}}. \end{verbatim} +\titem{\{resource\_regexp, \}} Matches any JID with a resource that + matches \term{}. Example: +\begin{verbatim} +{acl, icq, {resource_regexp, "^laptop\\."}}. +\end{verbatim} \titem{\{node\_regexp, , \}} Matches any user with a name that matches \term{} at any server that matches \term{}. Example: @@ -1167,6 +1177,7 @@ declarations of ACLs in the configuration file have the following syntax: \titem{\{user\_glob, \}} \titem{\{user\_glob, , \}} \titem{\{server\_glob, \}} +\titem{\{resource\_glob, \}} \titem{\{node\_glob, , \}} This is the same as above. However, it uses shell glob patterns instead of regexp. These patterns can have the following special characters: diff --git a/src/acl.erl b/src/acl.erl index c3fcebba4..eed295cb8 100644 --- a/src/acl.erl +++ b/src/acl.erl @@ -158,7 +158,7 @@ match_acl(ACL, JID, Host) -> all -> true; none -> false; _ -> - {User, Server, _Resource} = jlib:jid_tolower(JID), + {User, Server, Resource} = jlib:jid_tolower(JID), lists:any(fun(#acl{aclspec = Spec}) -> case Spec of all -> @@ -173,6 +173,8 @@ match_acl(ACL, JID, Host) -> (U == User) andalso (S == Server); {server, S} -> S == Server; + {resource, R} -> + R == Resource; {user_regexp, UR} -> ((Host == Server) orelse ((Host == global) andalso @@ -183,6 +185,8 @@ match_acl(ACL, JID, Host) -> is_regexp_match(User, UR); {server_regexp, SR} -> is_regexp_match(Server, SR); + {resource_regexp, RR} -> + is_regexp_match(Resource, RR); {node_regexp, UR, SR} -> is_regexp_match(Server, SR) andalso is_regexp_match(User, UR); @@ -197,6 +201,8 @@ match_acl(ACL, JID, Host) -> is_glob_match(User, UR); {server_glob, SR} -> is_glob_match(Server, SR); + {resource_glob, RR} -> + is_glob_match(Resource, RR); {node_glob, UR, SR} -> is_glob_match(Server, SR) andalso is_glob_match(User, UR); diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 567cd6b6e..225bce8eb 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -823,6 +823,8 @@ wait_for_session({xmlstreamelement, El}, StateData) -> pres_t = ?SETS:from_list(Ts1), privacy_list = PrivList}); _ -> + ejabberd_hooks:run(forbidden_session_hook, + StateData#state.server, [JID]), ?INFO_MSG("(~w) Forbidden session for ~s", [StateData#state.socket, jlib:jid_to_string(JID)]),