2014-09-11 17:13:32 +02:00
|
|
|
#!perl
|
2014-09-10 01:09:31 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2014-09-12 10:16:45 +02:00
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
user_config - basic plugin for storing per-user configuration directives
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
# in config/plugins
|
|
|
|
|
|
|
|
user_config [B<filename pattern>]
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item B<config file search pattern>
|
|
|
|
|
|
|
|
Pattern to use when searching for user config directory
|
|
|
|
Substitute %u for username, %h for host, or %a for full addressn.
|
|
|
|
Default: I</home/%u/.qpsmtpd/>
|
|
|
|
|
2014-09-17 08:27:19 +02:00
|
|
|
=back
|
|
|
|
|
2014-09-12 10:16:45 +02:00
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This plugin implements very basic support for storing user configuration
|
|
|
|
in separate directories similar to the global qpsmtpd config directory.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
sub init {
|
2014-09-16 00:57:12 +02:00
|
|
|
my ($self, $qp, $pattern) = @_;
|
2014-09-12 10:16:45 +02:00
|
|
|
$self->{pattern} = $pattern || '/home/%u/.qpsmtpd';
|
|
|
|
}
|
|
|
|
|
2014-09-10 01:09:31 +02:00
|
|
|
sub hook_user_config {
|
2014-09-16 00:57:12 +02:00
|
|
|
my ($self, $txn, $addr, $conf) = @_;
|
2014-09-12 10:16:45 +02:00
|
|
|
my $path = $self->{pattern} or return DECLINED;
|
2014-09-16 00:57:12 +02:00
|
|
|
my ($user, $host, $address) = ($addr->user, $addr->host, $addr->address);
|
2014-09-15 17:40:46 +02:00
|
|
|
$path =~ s/%u/$user/g;
|
|
|
|
$path =~ s/%h/$host/g;
|
|
|
|
$path =~ s/%a/$address/g;
|
2014-09-12 10:16:45 +02:00
|
|
|
my $filename = "$path/$conf";
|
2014-09-10 01:09:31 +02:00
|
|
|
return DECLINED unless -f $filename;
|
|
|
|
my $fh;
|
2014-09-16 00:57:12 +02:00
|
|
|
|
|
|
|
unless (open $fh, $filename) {
|
|
|
|
$self->log(LOGNOTICE, "Couldn't open $filename:$!");
|
2014-09-10 01:09:31 +02:00
|
|
|
return DECLINED;
|
|
|
|
}
|
2014-09-16 00:57:12 +02:00
|
|
|
my @return = <$fh>;
|
|
|
|
chomp @return;
|
|
|
|
return OK, @return;
|
2014-09-10 01:09:31 +02:00
|
|
|
}
|