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/>
|
|
|
|
|
|
|
|
=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 {
|
|
|
|
my ( $self, $qp, $pattern ) = @_;
|
|
|
|
$self->{pattern} = $pattern || '/home/%u/.qpsmtpd';
|
|
|
|
}
|
|
|
|
|
2014-09-10 01:09:31 +02:00
|
|
|
sub hook_user_config {
|
2014-09-15 17:40:46 +02:00
|
|
|
my ($self,$txn,$addr,$conf) = @_;
|
2014-09-12 10:16:45 +02:00
|
|
|
my $path = $self->{pattern} or return DECLINED;
|
2014-09-15 17:40:46 +02:00
|
|
|
my ( $user, $host, $address ) = ( $addr->user, $addr->host, $addr->address );
|
|
|
|
$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;
|
|
|
|
unless (open $fh,$filename) {
|
|
|
|
$self->log(LOGNOTICE,"Couldn't open $filename:$!");
|
|
|
|
return DECLINED;
|
|
|
|
}
|
|
|
|
map {chomp} (my @return = (<$fh>));
|
|
|
|
return OK,@return;
|
|
|
|
}
|