5 The RegexPolicyDaemon (rxpd) can be used to efficiently check data against
6 different lists of regular expressions. This can be used to build whitelists/
7 blacklists to protect many kinds of Internet services. It uses a simple textual
8 protocol that is easily implementable in scripting languages. Example usages
9 are access and content control (spam filtering) for CGI scripts, wikis, email,
10 revision control systems, IRC servers and clients, and so on.
12 Rxpd encourages users to distribute their lists in a friend2friend network. It
13 has features to fetch, updaten, filter and merge lists. The idea is that users/
14 administrators maintain manageable lists which cover single topics and then
17 Building and Installing
21 Release tarballs are attached to the wiki at:
23 * http://www.pipapo.org/pipawiki/RegexPolicyDaemon?action=AttachFile
25 I am using gpg signed tarballs for distribution. As first step one has to check
28 $ gpg rxpd-X.Y.tar.gz.gpg
30 This will produce a rxpd-X.Y.tar.gz and report if the signature could be
33 Since the package is built with gnu autotools, the usual build and install
36 $ tar xzvf rxpd-X.Y.tar.gz
38 $ mkdir build # using a build directory is optional
44 Development Version via git
46 The development version is available via git from 'git://git.pipapo.org/rxpd'
47 or mirrored at repo.or.cz 'git://repo.or.cz/rxpd.git'.
49 After you cloned the repository you need to bootstrap the autotools first
53 Then the usual configure / make will work.
55 There is a special makefile target make meta to bring several files (README,
56 AUTHORS, NEWS, TODO) in sync with the Rxpd Documentation wiki and update the
61 Rxpd requires gnu-pth and its development headers.
65 A single executable called 'rxpd' will be installed in $prefix/bin.
69 Rxpd targets to be simple and efficently validating data against Regular
70 expressions. It has (yet) no configuration file for the daemon itself and is
71 controlled by commandline options. Most management of regular expression lists
72 can be done remotely over a simple protocol. By itself it has has no
73 authentication but there is a 'policy' check which validates incoming requests
74 against an special regex list which then defines if the client is allowed to do
75 a certain task. Any further management like distributing the lists,
76 authenticate sessions more strongly and so on should be done by other means and
77 are not planned to be included in rxpd.
79 The goal it to create a common place which applications can use to validate any
80 kind of data. This works efficently because short lived programs like CGI
81 scripts take the advantage of regular expressions which are precompiled in core
82 and generally such lists might be shared between different applications.
84 Commandline Options and Starting
88 Increase verbosity level. Verbosity levels correspondend to syslog
89 -v levels, where LOG_WARNING is the default. Thus -v can be given up to
90 three times to get LOG_DEBUG.
91 -V Just shows version information and then exit.
92 -d Detach from terminal and run in background.
93 -D Run in debug mode, that is, increasing verbosity to at lest LOG_INFO and
94 don't detach. An additional -v can be used for LOG_DEBUG.
95 -b dir Give the basedir for rules. Rules have to be in a single directory, rxpd
96 will never access any data outside of this directory.
97 -q Turn rxpd quiet, only LOG_ALERT or worse will be logged.
98 -t Give a port number for a tcp port to listen on. This option can be
99 port appear multiple times. Only root can listen on ports less than 1024.
100 -u Path for a unix local socket to listen on. This option can appear
102 -p Define which rules-list will be be used to limit access to the rxpd
103 policy itself. If not given, no access restrictions apply (everything
104 allowed!). Policy matching will be descriped in detail later.
105 -i Turn all regular expressions case insensitive.
106 -4 Use only IPv4, default is IPv4 and IPv6 when compiled in.
108 -h Give a short usage notice and then exit.
109 -U When started as root, switch to 'user', if not given, 'nobody' is used.
114 There are only 2 things allowed in a list file:
117 + Begining with a '#' at the first column followed by arbitary text.
118 Comments are preserved and have semantic meaning as they can be used to
119 organize the data. Comments in the form '#UPPERCASE: ' are special/
120 reserved, the engine uses them to disable rules when they expire or
121 flag errorneous rules, '#lowercase: ' can be used for custom enabling/
122 disableing of rules, see the FILTER command.
124 + Starting with an optional accesstime entry, then a name, followed by a
125 regex. This three parts are delimited by colons.
126 + 'atime' will be maintained by the daemon to reflect the last time the
127 rule matched some data. This is time in seconds since epoch in UTC.
128 + 'name' is an arbitary string which has not special meaning for the rxpd
129 but will send back to the calling applications and be used there to
131 + the regex is a POSIX extended regular expression, regex are currently
132 case-insensitive this will become configureable later.
134 Lines in can be at most 4095 bytes long.
138 # Free things are good!
144 Matches will later report the line matched, without the atime and first colon
145 part. "Macrosoft" matches "M.*soft" thus "reject:M.*soft" will be returned.
147 Note that the first 'accept' rule has no atime, to initiate atimes they can be
148 initalized with '0' the daemon will update them on access and rewrite the List
149 files with the 'SAVE' command or when it recieves a SIGTERM.
151 When there is an error in a regular expression, it will be replaced with #
152 ERROR:, followed by the cause of the error, followed by the rules string in
157 Rxpd uses a simple line based text protocol. The first line is always the
158 command and list which will be used on the following data, it is not possible
159 to change the command throughout a session. Each session will generate at least
160 one line of response. When no other output is available '#OK:' is send, in case
161 of an error a line starting with '#ERROR:' is send.
163 Lines end with any combination of the 'newline' and/or 'carriage return'
166 The protocol is line based where lines which are longer than 4095 characters
167 are broken (may be word-wraped on the last whitespace character in the line in
172 * 'CHECK:list\n..data..'
173 + check all following data against the list. Returns the first matching
174 rule (excluding the 'atime' field), if any. When a empty line is send,
175 the daemon answers with "#OK:". This can be used to syncronize the
176 queries before sending new data.
177 * 'APPEND:list\n..rules..'
178 + append the following lines to list.
179 * 'PREPEND:list\n..rules..'
180 + prepend the following lines to list.
181 * 'REMOVE:list\n..rules..'
182 + remove all matching lines from list.
183 * 'REPLACE:list\nrule\n..replacements..'
184 + find the position matching the first line, which can be a rule or a
185 comment and replaces it with the following rules. Updates are atomic
186 and done when either an empty line is send or when the connection gets
189 + reload list from disk, this resets the 'atime' to the values stored on
192 + save list to disk, saves new atime records.
193 * 'EXPIRE:list\nseconds'
194 + marks all rules from list which are subject of atime updates and where
195 not touched for some (much) seconds with a '#EXPIRED:' comment,
196 effectively disabling them.
197 * 'FILTER:list\nfilters...'
198 + runs 'filters..' (also rules lists) over list and takes action for
199 matches. There are 2 Actions defined:
200 o 'DELETE' removes the matching rule completely from the list
201 o 'ACTIVATE' tries to reactivate a previously commented out rule (#
203 o any other name will just comment out the matching rule using the
205 * 'FETCH:list\nremote'
206 + fetches a list from remote storing it in local 'list'. 'remote' has the
207 form address/listname where address is either 'ip:port' or a path to a
210 Idea: do we want 'FETCH:list\
211 nremote:policylist' which gives a local list filtering remote first?
212 * 'UPDATE:list\nsource...'
213 + updates atimes in 'list' from sources, uses an efficent forward looking
214 algorithm, rule reordering in sources is not supported (adding/removing
215 rules works). sources have to be other local lists.
216 * 'MERGE:list\nsources..'
217 + Adds new lines from other 'sources..' to 'list', order will be
218 preserved. Does NOT delete removed lines.
220 + dump the content of list.
222 + list all loaded lists.
224 + exits the daemon gracefully, pending connections will still be served
225 but no new connections are accepted.
227 + prints package and version information.
229 + gives a short list of available commands.
233 Rxpd acts on following signals:
236 + Reload all files from disk
238 + Save all files and exit
240 + Exit immediately without saving
242 + Save all files while continue running
250 Rxpd is intended to be used as distributed system, this makes clear that data
251 put into it has to follow some rules to avoid clashing with foreign data. While
252 rxpd doesn't enforce any naming rules I write some suggestions/proposals here.
254 Rule lists in rxpd are files, with 0.3 they are organized as directory hierachy
255 under the rules-basedir.
257 Most importantly we need to distinguish the authority for a rules list, this
258 can be either a specifc user or some server. For users we use the users email
259 as unique identifier, for servers their hostname will suffice. Further we need
260 to address the purpose or protocol for which a list is primary used and finally
261 the list shall have a descriptive name.
263 This triple forms a uniqe identifier for any list.
267 One list of rules can be used to define access policies for the rxpd itself (-p
268 option). Each command will be extended with access protocol (one of tcp4, tcp6
269 or unix) and the peer address and then checked against this policy list. When
270 this check yields in an 'ACCEPT:..' rule, the command is allowed, for
271 everything else will result in an error and drop the connection.
273 For example if '-p policy' is used:
276 # [atime]:rulename:command:list:proto:address
278 # Allow dumping of the 'policy' list itself
280 # Clients from local network are allowed to do anything
281 :ACCEPT:.*:tcp.:10\..*$
282 # Forbid all others to do anything else with the policy
284 # Finally allow anything else
289 We want to protect a wiki or such against vandalism: blacklists are in
290 $blacklists.d/ lets say /etc/blacklists.d/
292 The wiki engine builds a tuple hostname;ip which is checked against a blacklist
293 which classify the 'hosts'
295 this is /etc/blacklist.d/hosts
297 # local access are always trusted, thats localhost any my local network
298 :allow:localhost;127.0.0.1
299 :allow:mydomain.org;10.10.
300 # some really bad guys are put on a blacklist which never ever shall get access
302 # everyone else shall just get the content checked
305 so printf("CHECK:hosts\n%s;%s\n", hostname, ipaddr) send to the blacklist
306 daemon will result in either 'allow', 'deny' or 'check' send back. The first
307 both (allow/deny) results are handled obliviously. With the 'check' result the
308 edited content will be filtered against another list '/etc/blacklists.d/
311 #example .. see BadContent on this wiki
317 <!> WIP <!> Not always running
319 Note: there is an almost unrestricted rxpd running here as demo:
321 $ echo -e 'LIST:' | nc www.pipapo.org 2345
325 $ echo -e 'DUMP:policy' | nc www.pipapo.org 2345
327 # rule:command:list:proto:address
329 # Allow dumping of the 'policy' list itself
331 # Clients from local network are allowed to do anything
332 :ACCEPT:.*:tcp.:10\..*$
333 # Forbid all others to do anything else with the policy
335 # Hey and no one shall remotely shutdown this daemon!
337 # Finally allow anything else
340 Also checkout the 'HELP:' and 'VERSION:' command. See this documentation for
343 This Documentation is maintained at:
345 * http://www.pipapo.org/pipawiki/RegexPolicyDaemon/Documentation
347 RegexPolicyDaemon/Documentation (last edited 2007-11-02 02:28:10 by ct)