mod_wrap2
The mod_wrap2 package allows the proftpd daemon to provide tcpwrapper-like access control rules while running in standalone mode. It also allows for those access rules to be stored in various formats, such as files (e.g. /etc/hosts.allow and /etc/hosts.deny) or in SQL tables. Note that the mod_wrap2 module does not require or use the standard tcpwrappers libwrap library, and instead implements the same functionality internally (in order to support SQL-based access rules). Please read the usage documentation for more details.
proftpd
tcpwrapper
/etc/hosts.allow
/etc/hosts.deny
libwrap
This module is contained in mod_wrap2.c, mod_wrap2.h, and in the submodules source files, for ProFTPD 1.3.x. These modules are not enabled by default. Installation notes follow the directive documentation.
mod_wrap2.c
mod_wrap2.h
The most current version of mod_wrap2's submodules supports storage of access table information in various formats:
mod_wrap2_file
mod_wrap2_redis
mod_wrap2_sql
The most current version of mod_wrap2 is distributed with the ProFTPD source code.
Please contact TJ Saunders <tj at castaglia.org> with any questions, concerns, or suggestions regarding this module.
Many, many thanks to Wietse Venema for writing the tcpwrappers package and its libwrap library, from which this module drew much of its code.
tcpwrappers
2002-12-12: Thanks to Steve Grubb for pointing out a few cases where interrupted functions were not being properly handled, and for reviewing the module code.
<VirtualHost
<Global>
<Anonymous>
The WrapAllowMsg directive configures a message that will be added to proftpd's response to the connecting client when that client is allowed by mod_wrap2's access check. In the mesg parameter, the magic cookie '%u' is replaced with the username specified by the client during login.
WrapAllowMsg
Example:
WrapAllowMsg "User '%u' allowed by access rules"
The WrapDenyMsg directive configures a message that will be sent to the connecting client when that client is denied by mod_wrap2's access check, and disconnected. In the mesg parameter, the magic cookie '%u' is replaced with the username specified by the client during login.
WrapDenyMsg
WrapDenyMsg "User '%u' denied by access rules"
<VirtualHost>
The WrapEngine directive enables or disables the module's runtime access control engine. If it is set to off this module does no runtime processing at all. Use this directive to disable the module instead of commenting out all mod_wrap2 directives.
WrapEngine
The WrapGroupTables directive configures the information necessary for mod_wrap2 to locate and use the tables containing the access rules for specific groups.
WrapGroupTables
The group-AND-expression parameter is a logical AND expression, which means that the connecting user must be a member of all the groups listed for this directive to apply. Group names may be negated with a ! prefix.
!
The next two parameters specify two tables, an allow and a deny table, each of which contain the IP addresses, networks or host/network masks to be allowed or denied.
Please consult the relevant submodule documentation for details on that module's syntax for specifying tables. The service name for which mod_wrap2 will look in the indicated access tables is "proftpd" by default; this can be configured via the WrapServiceName directive.
WrapServiceName
See also: WrapServiceName, WrapTables, WrapUserTables
The WrapLog directive is used to specify a log file for mod_wrap2 reporting, and can be done a per-server basis. The file parameter must be the full path to the file to use for logging. Note that this path must not be to a world-writeable directory and, unless AllowLogSymlinks is explicitly set to on (generally a bad idea), the path must not be a symbolic link.
WrapLog
AllowLogSymlinks
If file is "none", no logging will be done at all; this setting can be used to override a WrapLog setting inherited from a <Global> context.
The WrapOptions directive is used to configure various optional behavior of mod_wrap2. Note: all of the configured WrapOptions parameters must appear on the same line in the configuration; only the first WrapOptions directive that appears in the configuration is used.
WrapOptions
WrapOptions CheckOnConnect
The currently implemented options are:
CheckAllNames
This causes mod_wrap2 to check all of the known DNS names for the client IP address against the DNS names/patterns in the access rules, rather than just checking the first DNS name returned for the client IP address.
CheckOnConnect
This causes mod_wrap2 to check the allow/deny tables when the client first connects, rather than waiting until the client has authenticated before checking the access rules. This means that per-user/group allow/deny tables, and the use of the tilde (~) notation in table paths, is not supported when this option is used.
In addition, if mod_wrap2_sql is used, the order in which that module is loaded is very important. The mod_sql module must appear after the mod_wrap2 module in the --with-modules configure option, e.g.:
mod_sql
--with-modules
--with-modules=mod_wrap2:mod_wrap2_sql:mod_sql:mod_sql_mysql
LoadModule
... LoadModule mod_wrap2.c LoadModule mod_wrap2_sql.c ... LoadModule mod_sql.c LoadModule mod_sql_mysql.c ...
You will also need to ensure that mod_sql creates a database connection at connect time, using the PERCONNECTION connection policy; see SQLConnectInfo for more details:
PERCONNECTION
SQLConnectInfo
SQLConnectInfo database user password PERCONNECTION
Without this, the database connection will not be created at connect time, and the mod_wrap2 module will be unable to check any allow/deny rules stored in SQL tables when the client connects.
WrapServiceName proftpd
WrapServiceName is used to configure the name of the service under which mod_wrap2 will check the allow/deny tables. By default, this is the name of the program started, i.e. "proftpd". However, some administrators may want to use a different, more generic service name, such as "ftpd"; use this directive for such needs. The lookup using the configured name is case-sensitive.
The WrapTables directive configures the information necessary for mod_wrap2 to locate and use the tables containing the access rules for all clients.
WrapTables
The two parameters specify two tables, an allow and a deny table, each of which contain the IP addresses, networks or host/network masks to be allowed or denied.
See also: WrapGroupTables, WrapServiceName, WrapUserTables
The WrapUserTables directive configures the information necessary for mod_wrap2 to locate and use the tables containing the access rules for specific users.
WrapUserTables
The user-OR-expression parameter is a logical OR expression, which means that the connecting user can be any the users listed for this directive to apply. User names may be negated with a ! prefix.
See also: WrapGroupTables, WrapServiceName, WrapTables
--enable-wrapper-options
There is a built-in precedence to the WrapUserTables, WrapGroupTables, and WrapTables directives, if all are used. mod_wrap2 will look for applicable WrapUserTables for the connecting user first. If no applicable WrapUserTables are found, mod_wrap2 will search for WrapGroupTables which pertain to the connecting user. If not found, mod_wrap2 will then look for the server-wide WrapTables directive. This allows for access control to be set on a per-server basis, and allow for per-user or per-group access control to be handled without interfering with the overall server access rules.
When checking the tables, mod_wrap2 always checks the allow table first. If the client has been explicitly allowed by the rules in that table, processing stops and mod_wrap2 allows the client to continue the session. If not explicitly allowed, mod_wrap2 will then check the deny table's access rules. If the client has been explicitly denied by rules in that table, mod_wrap2 will disconnect the client. By default, if neither explicitly allowed or explicitly denied, mod_wrap2 will allow the client to continue.
In addition to the various formats supported by the submodules, there is a special source type: "builtin". This is used in the situations where the administrator wishes to configure "mostly closed" access rules, the most common situation. For example, if all clients are to be denied by mod_wrap2 by default, unless that client is granted access via an allow table entry, then the administrator can use:
builtin:all
Patterns The access control language implements the following patterns:
.castaglia.org
golem.devlan.castaglia.org
131.155.
131.155.x.x
net/mask
net
mask
131.155.72.0/255.255.254.0
131.155.72.0
131.155.73.255
[3ffe:505:2:1::]/64
3ffe:505:2:1::
3ffe:505:2:1:ffff:ffff:ffff:ffff:
Wildcards The access control language supports explicit wildcards:
Operators
list1 EXCEPT list2
a EXCEPT b EXCEPT c
(a EXCEPT (b EXCEPT c))
Server Endpoint Patterns In order to distinguish clients by the network address that they connect to, use patterns of the form:
process-name@host-pattern : client-list ...
The host-pattern obeys the same syntax rules as host names and addresses in client lists.
Client Username Lookup When the client host supports the RFC 931 protocol, the proftpd daemon can retrieve additional information about the owner of a connection. Client username information, when available (i.e. when IdentLookups are not disabled), is logged together with the client host name, and can be used to match patterns like:
IdentLookups
daemon-list : ... user-pattern@host-pattern ...
A user-pattern has the same syntax as a daemon pattern, so the same wildcards apply (netgroup membership is not supported). One should not get carried away with username lookups, though:
opt1 : opt2 ...
An option is of the form "keyword" or "keyword value". Options are processed in the specified order. For the sake of backwards compatibility with earlier versions, a `=' is permitted between keyword and value.
"keyword"
"keyword value"
The allow and deny keywords make it possible to keep all access control rules within a single file, for example in the hosts.allow file. To permit access from specific hosts only:
hosts.allow
ALL: .friendly.domain: ALLOW ALL: ALL: DENY
ALL: .bad.domain: DENY ALL: ALL: ALLOW
name=value
Diagnostics When a syntax error is found in an options list, the error is reported in the WrapLog and the access option will be ignored.
$ ./configure --with-modules=wrap-modules $ make $ make install
For file-based access tables, include the mod_wrap2_file submodule, e.g.:
mod_wrap2:mod_wrap2_file
mod_wrap2:mod_wrap2_sql
mod_wrap2:mod_wrap2_file:mod_wrap2_sql