MasterCFParser
This package provides an objectoriented interface to read/write the postfix superserver configuration file master.cf.
use MasterCFParser;
my $msc = new MasterCFParser();
$msc->readMasterCF();
if( $msc->addService( { 'service' => 'smtps',
'type' => 'inet',
'private' => 'n',
'unpriv' => '-',
'chroot' => 'n',
'wakeup' => '-',
'maxproc' => '-',
'command' => 'smtpd',
'options' => { 'smtpd_tls_wrappermode' => 'yes',
'smtpd_sasl_auth_enable' => 'yes' }
}
) ) {
print "ERROR in addService()\n";
}
my $srvs = $msc->getServiceByAttributes( { 'command' => 'pipe',
'maxproc' => '10' } );
if( ! defined $srvs ) {
print "ERROR in getServiceByAttributes()\n";
}
if( $msc->modifyService( { 'service' => 'cyrus1',
'command' => 'pipe',
'type' => 'unix' } ) ) {
print "ERROR in modifyService()\n";
}
Each commented line of master.cf is internally presented as an hash containing only one key/value pair, that is
comment => "# a commented line"
Every other lines are represented as hash which MUST have the keys
service,type,private,unpriv,chroot,wakeup,maxproc,command
and if present a key 'options'.
'options' can be either a scalar or a hash reference. A scalar for all so called interfaces to non-Postfix software using the 'pipe' command. For all other postfix commands, options must be a hash reference.
new();
Instantiating a MasterCFParser instance. EXAMPLE:
$_CFINST = new MasterCFParser( );
readMasterCF();
Read and parse master.cf into internal format. This method must be invoked before any other method can be invoked.
writeMasterCF();
Write the internal data structure back to master.cf
deleteService($service);
Delete service from internal data structure. $service must contain keys 'service' and 'command', all other keys are ignored.
EXAMPLE:
$msc->deleteService( { 'service' => 'smtps',
'command' => 'smtpd' } );
$hashref = getServiceByAttributes($service);
Get all services matching specified attributes.
EXAMPLE:
my $srvs = $msc->getServiceByAttributes( { 'command' => 'pipe',
'maxproc' => '10' } );
addService($service);
Add a new service to internal data structure. Every key MUST be given with the only exception of 'options', which is optional.
EXAMPLE:
$msc->addService( { 'service' => 'smtps',
'type' => 'inet',
'private' => 'n',
'unpriv' => '-',
'chroot' => 'n',
'wakeup' => '-',
'maxproc' => '-',
'command' => 'smtpd',
'options' => { 'smtpd_tls_wrappermode' => 'yes',
'smtpd_sasl_auth_enable' => 'yes' }
}
);
modifyService($service);
Modify an existing service. Keys 'service' and 'command' MUST be given.
modifyService replaces all keys of the matching internal service with the given keys.
EXAMPLE:
$msc->modifyService( { 'service' => 'cyrus1',
'command' => 'pipe',
'type' => 'unix' } );