Changes

Jump to navigation Jump to search
Created page with "<span id="_top">Qpsmtpd#Plugins</span> = NAME = per_user_config = DESCRIPTION = A simple approach for loading per-user or per-domain config data..."
<span id="_top">[[Qpsmtpd#Plugins]]</span>
= [[#___top|NAME]] =

per_user_config

= [[#___top|DESCRIPTION]] =

A simple approach for loading per-user or per-domain config data from subdirectories of the qpsmtpd/config directory. Three directory layouts are supported: 'domain/user' (default), 'domain', and 'user', specified as the single parameter to the per_user_config plugin.

per_user_config returns DECLINED for excluded config files, if no user can be identified, or if no per-user config file can be found.

To use per-user configs, simply load the per_user_config plugin early in the config/plugins file, and then in a subsequent sender or rcpt plugin pass a 'sender' or 'rcpt' argument in a second hashref argument to config() e.g.

<pre> C&lt;@config = $self-&gt;qp-&gt;config('myconfigfile', { rcpt =&gt; $rcpt });&gt;</pre>
'''NB:''' per_user_config currently requires a patched version of Qpsmtpd.pm to support this second hashref argument - the patch should be available with this plugin. ]

By default per-user or -domain configs ''replace'' more global ones. Sometimes merging earlier (more global) configs with later (more specific) ones makes sense - to enable this functionality pass an additional 'merge' argument to config() e.g.

<pre> C&lt;@config = $self-&gt;qp-&gt;config('myconfigfile',
{ rcpt =&gt; $rcpt, merge =&gt; 1 });&gt;</pre>
This simply concatenates config files together (more global first) - no checking for uniqueness or anything like that is done.

= [[#___top|CONFIG]] =

Per-user or per-domain config data is defined in standard qpsmtpd config files in subdirectories of qpsmtpd/config. Three directory layouts are supported, specified by the single parameter passed to the per_user_config plugin. Valid values are:

<pre> domain/user | domain | user</pre>
'domain/user' configs (the default) allow individual recipient config files to be defined in a two-tier directory layout, having individual username subdirectories within domain subdirectories of qpsmtpd/config e.g.

<pre> config/
spamassassin [0]
openfusion.com.au/
spamassassin [1]
gavin/
spamassassin [2]</pre>
This allows the spamassassin config file [2] to be used for mail to gavin@openfusion.com.au, while all other openfusion.com.au users use the spamassassin config file [1]. If no other domain directories exists, all other domains will use the global spamassassin config file [0].

'domain' configs do away with the user level and define configs within domain subdirectories of qpsmtpd/config e.g.

<pre> config/
dnsbl_zones
spamassassin
openfusion.com.au/
dnsbl_zones
spamassassin
someotherdomain.com/
dnsbl_zones
spamassassin
whitelisthosts</pre>
'user' configs do away with the domain level and define configs directly within user subdirectories of qpsmtpd/config e.g.

<pre> config/
spamassassin
gavin/
spamassassin
john/
spamassassin</pre>
This is probably only of use in single-domain contexts, of course.

For all layouts symlinks can be used for both directories and files to allow aliasing.

= [[#___top|NOTES]] =

per_user_config requires a 'sender' or 'rcpt' argument. Per-recipient configs are much more common (since qpsmtpd is usually used in 'inbound' settings), but sender configs also make sense, particularly in 'outbound' contexts.

Per-recipient configs obviously work well in rcpt-hook plugins. If you want to use per-recipient configs with post_data plugins, you have to handle the possibility that the multiple recipients may not have identical configs. See the denysoft_multi_rcpt plugin for one approach to this.

Plugins that want to support per-user configs typically have to be specially adapted (e.g. to defer most processing to rcpt hook time) and ideally should take a 'per_sender' or 'per_recipient' plugin argument to turn this functionality on.

per_user_config records a couple of items for use by later plugins: a 'per_user_config_layout' connection note records the layout parameter passed in, and a 'per_rcpt_configdir' (or 'per_sender_configdir') transaction note records the most-specific config directory found for the most recent user.

Note that username suffixes (the '-qpsmtpd' part in gavin-qpsmtpd@openfusion.com.au) are always removed from usernames before looking for user directories. This might sometimes surprise you (e.g. mailer-daemon -&gt; mailer).

No caching of results is done by default, since the number of config files involved might be huge.

= [[#___top|AUTHOR]] =

Written by Gavin Carr &lt;gavin@openfusion.com.au&gt;.

<!-- Generated Sat Apr 13 15:41:17 EDT 2019 using
perldoc -T -ohtml $plugins/$1 \|pandoc -f html -t mediawiki \|sed '1 i\\n\n\n<span id="_top">[[Qpsmtpd#Plugins]]</span>' \|sed -e 's#</d.>##'
-->
----
[[Category:Qpsmtpd|per_user_config]]

Navigation menu