spamdyke: rDNS Directory Structure

# spamdyke

## A drop-in connection-time spam filter for qmail

## rDNS directories

Some of the options described below search directory structures for rDNS names. A directory structure is used because repeatedly searching a file full of domain names incurs a serious performance penalty. Querying the filesystem for the existance of a single file is very fast. Rule of thumb: if there are more than 100-200 entries in a file, consider switching to a directory structure instead.

To construct the directory path it uses, spamdyke takes the remote server's rDNS name, breaks it apart at the dots and reverses it using the following patterns:

  `e-five.d-four.c-three.b-two.a-one` becomes `a-one/b/b-two/c-three/e-five.d-four.c-three.b-two.a-one`
  `d-four.c-three.b-two.a-one` becomes `a-one/b/b-two/c-three/d-four.c-three.b-two.a-one`
  `c-three.b-two.a-one` becomes `a-one/b/b-two/c-three.b-two.a-one`
  `b-two.a-one` becomes `a-one/b/b-two/b-two.a-one`
  `a-one` becomes `a-one/a/a-one`

In essence, the last three sections of the name are reversed and become directory names. If there are more than three sections, no further directories are created. Also, the first letter of the next-to-last section is used as a directory name. This is done to keep the numbers of directories per folder lower, since the "com" folder has the potential to become unmanagable. The full rDNS name is always used as the filename.

The final filename is treated as a wildcard and matches any host that ends with the given name. For example, if the following file existed in the directory structure:

  `com/e/example/example.com`

spamdyke would match the following rDNS names:

  `example.com`
  `mail.example.com`
  `internal.mail.example.com`
  `2ndfloor.internal.mail.example.com`

These directory and filenames can be constructed with the domain2path tool, included with spamdyke. domain2path takes one rDNS name as an argument and returns the correct path to that name. domain2path also accepts a flag, `-d`, which makes it only return the directories in the path. This is useful in scripts:

  `mkdir -p /PATH/TO/DIR/`domain2path -d FQDN``
  `touch /PATH/TO/DIR/`domain2path FQDN``

NOTE: The names of all the directories and files used in the directory structure must be lowercase or spamdyke will not match them. Unfortunately, searching a case sensitive filesystem in a case insensitive manner is not practical.