qpsmtpd/plugins/user_config
Jared Johnson 50cc469881 Add docs and flexible path to user_config plugin
I needed to make the path modifyable for testing anyway, might as well make it
actually usable.  Not yet tested.
2014-09-15 17:01:39 -05:00

51 lines
1.1 KiB
Perl

#!perl
use strict;
use warnings;
=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';
}
sub hook_user_config {
my ($self,$txn,$user,$conf) = @_;
my $path = $self->{pattern} or return DECLINED;
$path =~ s/%u/$user->user/g;
$path =~ s/%h/$user->host/g;
$path =~ s/%a/$user->address/g;
my $filename = "$path/$conf";
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;
}