Table of Contents

Policy Database

j-chkmail policy database is a central concept in j-chkmail. This is the place where most static information defining j-chkmail behaviour is stored.

This page contains information specific to policy database : how to add entries to it, how data is queried, …

If you're looking for information on the meaning of data stored here, they're better described elsewhere, where the feature using these data are explained.

Syntax

The syntax of this file is very simple but flexible and strong. Its idea is very similar to that one found at sendmail access database.

Entries syntax is :

Prefix:Key          Value

where,

An example of already implemented kind of entries follows :

j-policy.txt

CtrlChan:DEFAULT           REJECT
CtrlChan:127.0.0.1         OK
CtrlChan:194.21.16.16      OK
#
ConnRate:DEFAULT           15
ConnRate:127.0.0.1         1000
ConnRate:LOCAL             500
#
NetClass:199.199.123       DOMAIN
NetClass:192.168           LOCAL
#
BadMX:saveinternet.net     ERROR:421:4.5.1:Too busy now... Try later !

How database is looked up

Basically, query follows the rule : ”if the given key exists, its associated value is returned”.

We tried to implement into j-chkmail almost the same logic used by sendmail to query access database. But, still, there may be some differences.

If the key is an IP address, a domain, a hostname or an email, the database will be queried multiple times, with keys derived from the initial key. If the search isn't satisfied, a last query is usually done using the default value, in order to get the default value for the searched information.

  • There is no CIDR based database queries. Network addresses are looked up based on byte frontiers, even if the concept of network classes is considered deprecated.
  • When the key isn't found,

Some policy decisions are made upon multiple database queries - based on triplets : SMTP client information (IP address or network address or host name or network class), sender e-mail address and recipient e-mail address. E.g., greylisting, content check, …

The easiest way to explain all this is with an example.

GreyCheck

GreyCheckConnect:default           YES
GreyCheckConnect:10.3              NO-QUICK
GreyCheckConnect:193.22.33         NO
GreyCheckConnect:yahoo.com         NO-QUICK
GreyCheckConnect:dnsbl             YES-QUICK
GreyCheckFrom:joe@domain.com       NO
GreyCheckFrom:j-chkmail.org        NO-QUICK
GreyCheckTo:postmaster@            NO
GreyCheckTo:joe@domain.com         NO
GreyCheckTo:charles@domain.com     YES

When duplicate keys are found at j-policy.txt file, usually only the first one will be taken into account. j-policy.db is created from j-policy.txt, using j-makemap (see /var/jchkmail/cdb/Makefile). The way j-makemap handles duplicate records depends on the -m option : -m s to preserve first found keys (skip new ones) and -m u to update with new values.

Current data defined at policy database

Defining networks classes

NetClass:key      value

Key maybe one of :

Value represents the class to which you'll class the key. There are three static predefined known classes : LOCAL, DOMAIN and FRIEND, but you can define other classes if these three classes aren't enough.

Examples :

j-policy.txt

# predefined classes
NetClass:10               LOCAL 
NetClass:199.201          DOMAIN 
NetClass:1.2.3.4          FRIEND
NetClass:domain.com       DOMAIN
# locally defined classes
NetClass:10.1             DEPMATH
NetClass:10.2             DEPPHYS
NetClass:10.3             DEPCHEM

Authenticated SMTP connections fall into an special network class : AUTH. AUTH class is considered a dynamic network class to which are assigned the same rigths than LOCAL network class.

Defining Limits per SMTP client

These prefixes can be used to define limits to be applied to SMTP clients :

When the limits are evaluated on a sliding time window, the size of this window is ten minutes.

j-policy.txt

ConnRate:DEFAULT              15
ConnRate:LOCAL                300
ConnRate:DOMAIN               200
ConnRate:FRIEND               30
ConnRate:10.3                 400
ConnRate:domain.com           2
ConnRate:DEPMATH              400

ConnRate:1.2.3.4              20
ConnOpen:1.2.3.4              4
RcptRate:1.2.3.4              40
MaxRcpt:1.2.3.4               4
MsgRate:1.2.3.4               30
MaxMsgs:1.2.3.4               3

Greylisting

j-policy.txt - Default policy : ENABLED

GreyCheckConnect:default               YES
GreyCheckConnect:MATH                  NO-QUICK
GreyCheckConnect:1.2.3.4               NO-QUICK
GreyCheckFrom:john@friend.com          NO-QUICK
GreyCheckFrom:spammer.com              YES-QUICK
GreyCheckTo:postmaster@mydomain.com    NO

j-policy.txt - Default policy : DISABLED

GreyCheckConnect:default               NO
GreyCheckFrom:spammer.com              YES-QUICK
GreyCheckTo:postmaster@mydomain.com    NO
GreyCheckTo:Alice@mydomain.com         YES
GreyCheckTo:Bob@mydomain.com           YES
GreyCheckTo:Charles@mydomain.com       YES

Greylisting is never applied to predefined known networks

j-policy.txt

GreyEquivDomain:domain.com       domain-one.com, domain-two.com

As shown above, you can define more than one value for this particular kind of key. You should just separate them by spaces or commas.

Defining rules for message content checking

Rules to define which messages will have its content checked

j-policy.txt

# sympa mailing list server
ContentCheckConnect:X.X.X.115         NO-QUICK
XFilesCheckConnect:X.X.X.115          NO-QUICK
VirusCheckConnect:X.X.X.115           NO-QUICK
BayesCheckFrom:domain.com             NO-QUICK
RejectShortMsgsTo:joe@example.com     NO

Message Archiving

Rules to define which messages shall be archived

j-policy.txt

ArchiveConnect:DEFAULT          NO
ArchiveConnect:10.3             YES-QUICK
ArchiveFrom:joe@spammer.com     YES-QUICK
ArchiveTo:archive@domain.com    YES

Centralized greylisting server access

This prefix is used to control which computers have access to the centralized greylisting server

j-policy.txt

GreydAccess:DEFAULT                  REJECT
GreydAccess:127.0.0.1                OK
GreydAccess:10.3.4.5                 OK

j-chkmail control channel access

This prefix controls which IP addresses can connect to the filter control channel.

j-policy.txt

CtrlChan:DEFAULT             REJECT
CtrlChan:127.0.0.1           OK
CtrlChan:10.3.3              OK

BadMX

Use this entries to define unwanted domains or IP addresses, based on their MX.

j-policy.txt

BadMX:10                ERROR:421:4.5.1:Sender MX in an unallocated or reserved network 
BadMX:saveinternet.net  ERROR:421:4.5.1:Unwanted or unreacheable MX... Try later !

Maintaining policy database

Policy database is usually at /var/jchkmail/cdb. As it's installed, it's the concatenation of some text files :

[martins@localhost cdb]$ pwd
/var/jchkmail/cdb
[joe@localhost cdb]$ ls -l j-policy.*.txt
-rw-r--r-- 1 root root     0 Dec 11 21:17 j-policy.base.txt
-rw-r--r-- 1 root root    66 Feb  9 11:47 j-policy.local.txt
-rw-r--r-- 1 root root 16172 Feb  7 15:08 j-policy.z-badmx.txt
-rw-r--r-- 1 root root  3745 Feb  7 15:08 j-policy.z-defaults.txt
-rw-r--r-- 1 root root 11146 Feb  7 15:08 j-policy.z-grey.txt
-rw-r--r-- 1 root root  5727 Feb  7 15:08 j-policy.z-iana.txt
[joe@localhost cdb]$ 

  • In order to ease management of the policy database source files, you can have as many as you want. They will be concatenated to generate the text file j-policy.txt, which will be read to create the hash database which will be read by the filter.
  • j-policy.z-*.txt files contains default values. These files installed and updated with the filter. As long as their suffix begins with “z-“, they will be the last files to be read. Only entries which weren't yet defined will be taken into account.

You'll probably need to adapt the Makefile installed inside /var/jchkmail/cdb to match the make program in you system.

[martins@localhost cdb]$ more /var/jchkmail/cdb/Makefile
...
# POLICY_SRC variable defines which files to include in your
#      policy database
#
# Depending on your Operating System, you can use one of this options :
# - GNU make
POLICYSRC = $(wildcard j-policy.*.txt)
# - SunOS make
#POLICYSRC:sh =ls j-policy.*.txt
# - List text files by hand
#POLICYSRC = j-policy.grey.txt j-policy.badmx.txt j-policy.base.txt