Copyright © 2003 Miklos Tirpak
Copyright © 2006-2008 Juha Heinanen
Copyright © 2009 Irina-Maria Stanescu
Revision History | |
---|---|
Revision $Revision: 8740 $ | $Date$ |
Table of Contents
default_allow_file
(string)default_deny_file
(string)check_all_branches
(integer)allow_suffix
(string)deny_suffix
(string)db_url
(string)address_table
(string)grp_col
(string)ip_col
(string)mask_col
(string)port_col
(string)proto_col
(string)pattern_col
(string)info_col
(string)allow_routing()
allow_routing(basename)
allow_routing(allow_file,deny_file)
allow_register(basename)
allow_register(allow_file, deny_file)
allow_uri(basename, pvar)
check_address(group_id, ip,
port, proto [, context_info [, pattern]])
check_source_address(group_id [, context_info [, pattern]])
get_source_group(pvar)
List of Examples
default_allow_file
parameterdefault_deny_file
parametercheck_all_branches
parameterallow_suffix
parameterdeny_suffix
parameterdb_url
parameteraddress_table
parametergrp_col
parameterip_col
parametermask_col
parameterport_col
parameterproto_col
parameterpattern_col
parameterinfo_col
parameterallow_routing
usageallow_routing(basename)
usageallow_routing(allow_file, deny_file)
usageallow_register(basename)
usageallow_register(allow_file, deny_file)
usageallow_uri(basename, pvar)
usagecheck_address()
usagecheck_source_address()
usageget_source_group()
usage
The module can be used to determine if a call has appropriate
permission to be established.
Permission rules are stored in plaintext configuration files similar to
hosts.allow
and hosts.deny
files used by tcpd.
When allow_routing
function is
called it tries to find a rule that matches selected fields of the
message.
OpenSIPS is a forking proxy and therefore a single message can be sent to different destinations simultaneously. When checking permissions all the destinations must be checked and if one of them fails, the forwarding will fail.
The matching algorithm is as follows, first match wins:
Create a set of pairs of form (From, R-URI of branch 1), (From, R-URI of branch 2), etc.
Routing will be allowed when all pairs match an entry in the allow file.
Otherwise routing will be denied when one of pairs matches an entry in the deny file.
Otherwise, routing will be allowed.
A non-existing permission control file is treated as if it were an empty file. Thus, permission control can be turned off by providing no permission control files.
From header field and Request-URIs are always compared with regular
expressions! For the syntax see the sample file:
config/permissions.allow
.
In addition to call routing it is also possible to check REGISTER messages and decide--based on the configuration files--whether the message should be allowed and the registration accepted or not.
Main purpose of the function is to prevent registration of "prohibited"
IP addresses. One example, when a malicious user registers a contact
containing IP address of a PSTN gateway, he might be able to bypass
authorization checks performed by the SIP proxy. That is undesirable
and therefore attempts to register IP address of a PSTN gateway should
be rejected. Files config/register.allow
and config/register.deny
contain an example
configuration.
Function for registration checking is called allow_register
and the algorithm is very
similar to the algorithm described in
Section 1.1.1, “Call Routing”. The only difference is in the way
how pairs are created.
Instead of From header field the function uses To header field because To header field in REGISTER messages contains the URI of the person being registered. Instead of the Request-URI of branches the function uses Contact header field.
Thus, pairs used in matching will look like this: (To, Contact 1), (To, Contact 2), (To, Contact 3), and so on..
The algorithm of matching is same as described in Section 1.1.1, “Call Routing”.
The module can be used to determine if request is
allowed to the destination specified by an URI stored in
a pvar. Permission rules are stored in
plaintext configuration files similar to
hosts.allow
and
hosts.deny
used by tcpd.
When allow_uri
function is called, it tries to find a rule that matches
selected fields of the message.
The matching algorithm is as follows, first match wins:
Create a pair <From URI, URI stored in pvar>.
Request will be allowed when the pair matches an entry in the allow file.
Otherwise request will be denied when the pair matches an entry in the deny file.
Otherwise, request will be allowed.
A non-existing permission control file is treated as if it were an empty file. Thus, permission control can be turned off by providing no permission control files.
From URI and URI stored in pvar are always compared with regular
expressions! For the syntax see the sample file:
config/permissions.allow
.
The module can be used to determine if an address (IP
address and port) matches any of the IP subnets
stored in cached OpenSIPS database table.
Port 0 in cached database table matches any port. Group ID, IP
address, port and transport protocol values to be matched can be either taken from
the request (check_source_address
) or given as pvar
arguments or directly as strings(check_address
).
Addresses stored in cached database table can be grouped
together into one or more groups specified by a group
identifier (unsigned integer). Group identifier is given as
argument to check_address
and
check_source_address
.
Otherwise the request is rejected.
The address database table is specified by module parameters.
The following modules must be loaded before this module:
No dependencies on other OpenSIPS modules.
Default allow file used by functions without parameters. If you don't specify full pathname then the directory in which is the main config file is located will be used.
Default value is “permissions.allow”.
Example 1.1. Set default_allow_file
parameter
... modparam("permissions", "default_allow_file", "/etc/permissions.allow") ...
Default file containing deny rules. The file is used by functions without parameters. If you don't specify full pathname then the directory in which the main config file is located will be used.
Default value is “permissions.deny”.
Example 1.2. Set default_deny_file
parameter
... modparam("permissions", "default_deny_file", "/etc/permissions.deny") ...
If set then allow_routing functions will check Request-URI of all branches (default). If disabled then only Request-URI of the first branch will be checked.
Do not disable this parameter unless you really know what you are doing.
Default value is 1.
Example 1.3. Set check_all_branches
parameter
... modparam("permissions", "check_all_branches", 0) ...
Suffix to be appended to basename to create filename of the allow
file when version with one parameter of either
allow_routing
or
allow_register
is used.
Including leading dot.
Default value is “.allow”.
Suffix to be appended to basename to create filename of the deny file
when version with one parameter of either
allow_routing
or
allow_register
is used.
Including leading dot.
Default value is “.deny”.
This is URL of the database to be used.
Default value is “NULL”.
Example 1.6. Set db_url
parameter
... modparam("permissions", "db_url", "dbdriver://username:password@dbhost/dbname") ...
Name of database table containing matching rules used by
allow_register
function.
Default value is “address”.
Name of address table column containing group identifier of the address.
Default value is “grp”.
Name of address table column containing IP address part of the address.
Default value is “ip”.
Name of address table column containing network mask of the address. Possible values are 0-32.
Default value is “mask”.
Name of address table column containing port part of the address.
Default value is “port”.
Name of address table column containing transport protocol that is matched against transport protocol of received request. Possible values that can be stored in proto_col are “any”, “udp”, “tcp”, “tls”, “sctp”, and “none”. Value “any” matches always and value “none” never.
Default value is “proto”.
Name of address table column containing regular
expression that is matched against the arguments received by
check_address
or check_source_address
.
Default value is “pattern”.
Name of address table column containing a string
that is added as value to a pvar given as argument
to check_address
or check_source_address
in
case the function succedes.
Default value is “context_info”.
Returns true if all pairs constructed as described in Section 1.1.1, “Call Routing” have appropriate permissions according to
the configuration files. This function uses default configuration
files specified in default_allow_file
and
default_deny_file
.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Returns true if all pairs constructed as described in Section 1.1.1, “Call Routing” have appropriate permissions according to the configuration files given as parameters.
Meaning of the parameters is as follows:
basename - Basename from which allow
and deny filenames will be created by appending contents of
allow_suffix
and deny_suffix
parameters.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Returns true if all pairs constructed as described in Section 1.1.1, “Call Routing” have appropriate permissions according to the configuration files given as parameters.
Meaning of the parameters is as follows:
allow_file - File containing allow rules.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
deny_file - File containing deny rules.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.17. allow_routing(allow_file, deny_file)
usage
... if (allow_routing("rules.allow", "rules.deny")) { t_relay(); }; ...
The function returns true if all pairs constructed as described in Section 1.1.2, “Registration Permissions” have appropriate permissions according to the configuration files given as parameters.
Meaning of the parameters is as follows:
basename - Basename from which allow
and deny filenames will be created by appending contents of
allow_suffix
and deny_suffix
parameters.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.18. allow_register(basename)
usage
... if (method=="REGISTER") { if (allow_register("register")) { save("location"); exit; } else { sl_send_reply("403", "Forbidden"); }; }; ...
The function returns true if all pairs constructed as described in Section 1.1.2, “Registration Permissions” have appropriate permissions according to the configuration files given as parameters.
Meaning of the parameters is as follows:
allow_file - File containing allow rules.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
deny_file - File containing deny rules.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.19. allow_register(allow_file, deny_file)
usage
... if (method=="REGISTER") { if (allow_register("register.allow", "register.deny")) { save("location"); exit; } else { sl_send_reply("403", "Forbidden"); }; }; ...
Returns true if the pair constructed as described in Section 1.1.3, “URI Permissions” have appropriate permissions according to the configuration files specified by the parameter.
Meaning of the parameter is as follows:
basename - Basename from which allow
and deny filenames will be created by appending contents of
allow_suffix
and deny_suffix
parameters.
If the parameter doesn't contain full pathname then the function expects the file to be located in the same directory as the main configuration file of the server.
pvar - Any pseudo-variable defined in OpenSIPS.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.20. allow_uri(basename, pvar)
usage
... if (allow_uri("basename", "$rt")) { // Check Refer-To URI t_relay(); }; if (allow_uri("basename", "$avp(uri)") { // Check URI stored in $avp(uri) t_relay(); }; ...
Returns 1 if group id, IP address, port and protocol given as arguments match an IP subnet found in cached address table, as described in Section 1.1.4, “Address Permissions” . The function takes 4 mandatory arguments and 2 optional ones.
This function can be useful to check if a request can be allowed without authentication.
Meaning of the parameter is as follows:
This argument represents the group id to be matched. It can be an integer string or a string pvar. If the group_id argument is "0", the query can match any group in the cached address table.
This argument represents the ip address to be matched. It can be an given directly as string or as a string pvar. This argument cannot be null/empty.
This argument represents the port to be matched. It can be an given as an integer string or as a string pvar. Cached address table entry containing port value 0 matches any port. Also, a "0" value for the argument can match any port in the address table.
This argument represents the protocol used for transport; it can be an given as string or as string pvar. Transport protocol is either "ANY" or any valid transport protocol value: "UDP, "TCP", "TLS", and "SCTP".
This argument represents the pvar in wich the context_info field from the cached address table will be stored in case of match. This argument is optional.
This argument is a string to be matched with the regular expression pattern field from the cached address table. This argument is optional.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.21. check_address()
usage
... // Checks if the tuple IP address/port (given as strings) and source protocol // (given as pvar), belongs to group 4, verifies if pattern string "texttest" // matches the regular expression field in the database table and stores the // context information in $avp(ctx) if (check_address("4","192.168.2.135","5700","$proto","$avp(ctx)", "texttest")) { t_relay(); xlog("$avp(ctx)\n"); } ... // Checks if the tuple IP address/port/protocol of the source message is in group 4 if (check_address("4","$si","$sp","$proto")) { t_relay(); } ... // Checks if the tuple IP address/port/protocol stored in AVPs s:ip/s:port/s:proto // is in group 4 and stores context information in $avp(ctx) $avp(ip) = "192.168.2.135"; $avp(port) = 5061; $avp(proto) = "any"; if (check_address("4","$avp(ip)","$avp(port)","$avp(proto)","$avp(ctx))) { t_relay(); xlog("$avp(ctx)\n"); } ... // Checks if the tuple IP address/port (given as strings) and source protocol // (given as pvar) is in group 4, verifies if pattern string "texttest" matches // the regular expression field in the database table, without storing any // context information if (check_address("4","$si","5700","$proto","", "texttest")) { t_relay(); } ...
Equivalent to check_address(group_id, "$si", "$sp", "$proto", context_info, pattern).
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.22. check_source_address()
usage
... // Check if source address/port/proto is in group 4 and stores // context information in $avp(ctx) if (check_source_address("4","$avp(ctx)")) { xlog("$avp(ctx)\n"); }else { sl_send_reply("403", "Forbidden"); } ...
Checks if an entry with the source ip/port/protocol is found in cached address or subnet table in any group. If yes, returns that group in the pvar parameter. If not returns -1. Port value 0 in cached address and subnet table matches any port.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
Example 1.23. get_source_group()
usage
... if ( get_source_group("$var(group)") ) { # do something with $var(group) xlog("group is $var(group)\n"); }; ...
Causes permissions module to re-read the contents of the address database table into cache memory. In cache memory the entries are for performance reasons stored in two different tables: address table and subnet table depending on the value of the mask field (32 or smaller).
Parameters: none
Causes permissions module to dump contents of the address table from cache memory.
Parameters: none
Causes permissions module to dump contents of cache memory subnet table.
Parameters: none
Tests if (URI, Contact) pair is allowed according to allow/deny files. The files must already have been loaded by OpenSIPS.
Parameters:
basename - Basename from which allow and deny filenames will be created by appending contents of allow_suffix and deny_suffix parameters.
URI - URI to be tested
Contact - Contact to be tested