
permissions Module

Miklos Tirpak

Edited by

Miklos Tirpak

   Copyright © 2003 Miklos Tirpak
     _________________________________________________________

   Table of Contents
   1. User's Guide

        1.1. Overview

              1.1.1. Call Routing
              1.1.2. Registration Permissions

        1.2. Dependencies

              1.2.1. SER Modules
              1.2.2. External Libraries or Applications

        1.3. Exported Parameters

              1.3.1. default_allow_file (string)
              1.3.2. default_deny_file (string)
              1.3.3. check_all_branches (integer)
              1.3.4. allow_suffix (string)
              1.3.5. deny_suffix (string)
              1.3.6. db_url (string)
              1.3.7. db_mode (integer)
              1.3.8. trusted_table (string)
              1.3.9. source_col (string)
              1.3.10. proto_col (string)
              1.3.11. from_col (string)

        1.4. Exported Functions

              1.4.1. allow_routing()
              1.4.2. allow_routing(basename)
              1.4.3. allow_routing(allow_file, deny_file)
              1.4.4. allow_register(basename)
              1.4.5. allow_register(allow_file, deny_file)
              1.4.6. allow_trusted()

   2. Developer's Guide
   3. Frequently Asked Questions

   List of Examples
   1-1. Set default_allow_file parameter
   1-2. Set default_deny_file parameter
   1-3. Set check_all_branches parameter
   1-4. Set allow_suffix parameter
   1-5. Set deny_suffix parameter
   1-6. allow_routing usage
   1-7. allow_routing(basename) usage
   1-8. allow_routing(allow_file, deny_file) usage
   1-9. allow_register(basename) usage
   1-10. allow_register(allow_file, deny_file) usage
     _________________________________________________________

Chapter 1. User's Guide

1.1. Overview

1.1.1. Call Routing

   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.

   SER 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.
     _________________________________________________________

1.1.2. Registration Permissions

   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. 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.
     _________________________________________________________

1.2. Dependencies

1.2.1. SER Modules

   The following modules must be loaded before this module:

     * No dependencies on other SER modules.
     _________________________________________________________

1.2.2. External Libraries or Applications

   The following libraries or applications must be installed
   before running SER with this module loaded:

     * None.
     _________________________________________________________

1.3. Exported Parameters

1.3.1. default_allow_file (string)

   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")
...
     _________________________________________________________

1.3.2. default_deny_file (string)

   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")
...
     _________________________________________________________

1.3.3. check_all_branches (integer)

   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.

   Warning

   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)
...
     _________________________________________________________

1.3.4. allow_suffix (string)

   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.

   Note

   Including leading dot.

   Default value is ".allow". 

   Example 1-4. Set allow_suffix parameter
...
modparam("permissions", "allow_suffix", ".allow")
...
     _________________________________________________________

1.3.5. deny_suffix (string)

   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.

   Note

   Including leading dot.

   Default value is ".deny". 

   Example 1-5. Set deny_suffix parameter
...
modparam("permissions", "deny_suffix", ".deny")
...
     _________________________________________________________

1.3.6. db_url (string)

   The URL of database to be used to obtain the list of trusted
   hosts.

   Default value is "mysql://ser:heslo@localhost/ser". 
     _________________________________________________________

1.3.7. db_mode (integer)

   This parameter controls the cache that speeds up lookups of
   trusted hosts. The value 1 enables cache, 0 disables it (each
   query would result in a database lookup).

   Default value is 0 (disable cache). 
     _________________________________________________________

1.3.8. trusted_table (string)

   The name of the table in database containing the list of
   trusted hosts.

   Default value is "trusted". 
     _________________________________________________________

1.3.9. source_col (string)

   The name of the column in trusted table which contains source
   IP address.

   Default value is "src_ip". 
     _________________________________________________________

1.3.10. proto_col (string)

   The name of the column in trusted table which contains the
   protocol identifier (UDP, TCP, TLS).

   Default value is "proto". 
     _________________________________________________________

1.3.11. from_col (string)

   The name of the column in trusted table which contains regular
   expressions that will be matched agains From header field.

   Default value is "from_pattern". 
     _________________________________________________________

1.4. Exported Functions

1.4.1. allow_routing()

   Returns true if all pairs constructed as described in Section
   1.1.1 have appropriate permissions according to the
   configuration files. This function uses default configuration
   files specified in default_allow_file and default_deny_file.

   Example 1-6. allow_routing usage
...
if (allow_routing()) {
    t_relay();
};
...
     _________________________________________________________

1.4.2. allow_routing(basename)

   Returns true if all pairs constructed as described in Section
   1.1.1 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.

   Example 1-7. allow_routing(basename) usage
...
if (allow_routing("basename")) {
    t_relay();
};
...
     _________________________________________________________

1.4.3. allow_routing(allow_file, deny_file)

   Returns true if all pairs constructed as described in Section
   1.1.1 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.

   Example 1-8. allow_routing(allow_file, deny_file) usage
...
if (allow_routing("rules.allow", "rules.deny")) {
    t_relay();
};
...
     _________________________________________________________

1.4.4. allow_register(basename)

   The function returns true if all pairs constructed as
   described in Section 1.1.2 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.

   Example 1-9. allow_register(basename) usage
...
if (method=="REGISTER") {
    if (allow_register("register")) {
        save("location");
        break;
    } else {
        sl_send_reply("403", "Forbidden");
    };
};
...
     _________________________________________________________

1.4.5. allow_register(allow_file, deny_file)

   The function returns true if all pairs constructed as
   described in Section 1.1.2 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.

   Example 1-10. allow_register(allow_file, deny_file) usage
...
if (method=="REGISTER") {
    if (allow_register("register.allow", "register.deny")) {
        save("location");
        break;
    } else {
        sl_send_reply("403", "Forbidden");
    };
};
...
     _________________________________________________________

1.4.6. allow_trusted()

   The function check the source IP, protocol, and the contents
   of From header field against entries in trusted table and
   returns true if there is a match. This means that the
   end-device is trusted.
     _________________________________________________________

Chapter 2. Developer's Guide

   The module does not provide any sort of API to use in other
   SER modules.
     _________________________________________________________

Chapter 3. Frequently Asked Questions

   3.1. Where can I find more about SER?
   3.2. Where can I post a question about this module?
   3.3. How can I report a bug?

   3.1. Where can I find more about SER?

   Take a look at http://iptel.org/ser.

   3.2. Where can I post a question about this module?

   First at all check if your question was already answered on
   one of our mailing lists:

     * http://mail.iptel.org/mailman/listinfo/serusers
     * http://mail.iptel.org/mailman/listinfo/serdev

   E-mails regarding any stable version should be sent to
   <serusers@iptel.org> and e-mail regarding development versions
   or CVS snapshots should be send to <serdev@iptel.org>.

   If you want to keep the mail private, send it to
   <serhelp@iptel.org>.

   3.3. How can I report a bug?

   Please follow the guidelines provided at:
   http://iptel.org/ser/bugs
