summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Parent <math.parent@gmail.com>2009-12-13 15:19:23 (GMT)
committerMathieu Parent <math.parent@gmail.com>2009-12-13 15:19:23 (GMT)
commit82b88f3b213aa5cb26760aa538a2b1df2010ac34 (patch)
tree4f0298ad44bec446c29ea00936cd74cdda8ff837
parente4ccdc80f078f713070d0c7f6326fba9a82cfd91 (diff)
downloadperl-Kolab-82b88f3b213aa5cb26760aa538a2b1df2010ac34.tar.gz
perl-kolab:
new @@@print@@@ macro available for: getLDAPReplicas(), getLDAPAccess(), getCyrusGroups(), getPostfixMap(map). This removed the use of %special_templates, %haschanged, Kolab::Conf::reload(). kolabd: kolab/issue1740 (fully generate slapd.access, slapd.replicas, transport, virtual and imapd.groups by templates) using the new @@@print@@@ macro (perl-kolab) and RUNONCHANGE.
-rw-r--r--ChangeLog7
-rw-r--r--lib/Kolab/Conf.pm202
2 files changed, 46 insertions, 163 deletions
diff --git a/ChangeLog b/ChangeLog
index 3edffd2..2e7e757 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-13 Mathieu Parent <math.parent@gmail.com>
+
+ * lib/Kolab/Conf.pm, sbin/kolabconf.in: new @@@print@@@ macro
+ available for: getLDAPReplicas(), getLDAPAccess(),
+ getCyrusGroups(), getPostfixMap(map). This removed the use of
+ %special_templates, %haschanged, Kolab::Conf::reload()
+
2009-11-24 Gunnar Wrobel <wrobel@pardus.de>
* Makefile.PL: kolab/issue3952 (Version in kolabconf is not
diff --git a/lib/Kolab/Conf.pm b/lib/Kolab/Conf.pm
index ce2e479..c6a226b 100644
--- a/lib/Kolab/Conf.pm
+++ b/lib/Kolab/Conf.pm
@@ -42,10 +42,8 @@ our @ISA = qw(Exporter);
our %EXPORT_TAGS = (
'all' => [ qw(
- &buildCyrusGroups
- &buildLDAPReplicas
&rebuildTemplates
- &checkPermissions
+ &checkPermissions
) ]
);
@@ -59,7 +57,6 @@ my %templates = ();
my %ownership = ();
my %permissions = ();
my %templatehaschanged = ();
-my %haschanged = ();
my %commentchar = ();
sub fixup {
@@ -92,7 +89,6 @@ sub printWarning {
$cc = "#" if (!defined $cc);
# Different warnings during bootstrapping and regular configuration
-# $Kolab::config{"bootstrap_config"} = "true";
if ((defined $Kolab::config{"bootstrap_config"}) &&
($Kolab::config{"bootstrap_config"} eq "true")) {
@@ -127,14 +123,6 @@ sub build {
my $oldcfg = $cfg . '.old';
my $templatedir = $Kolab::config{"templatedir"};
- my %special_templates = (
- "$templatedir/transport.template" => 1,
- "$templatedir/virtual.template" => 1,
- "$templatedir/imapd.group.template" => 1,
- "$templatedir/slapd.access.template" => 1,
- "$templatedir/slapd.replicas.template" => 1
- );
-
my $oldmask = umask 077;
#creating the config file is changing it
if (! -f $cfg) {
@@ -145,7 +133,6 @@ sub build {
# To avoid warnings, the backup files must be owned by root
chown(0, 0, $oldcfg);
umask $oldmask;
- #chmod(0600, $oldcfg) if ($oldcfg =~ /openldap/);
Kolab::log('T', "Creating new configuration file `$cfg' from template `$tmpl'", KOLAB_DEBUG );
@@ -202,6 +189,7 @@ sub build {
}
s/\@{3}if (\S+?)\@{3}\n?//;
} elsif (/\@{3}else\@{3}/) {
+ # @@@else@@@
if( $keep == 0 ) {
# Now keep
$keep = 1;
@@ -214,15 +202,28 @@ sub build {
s/\@{3}else\@{3}\n?//;
} elsif (/\@{3}endif\@{3}/) {
+ # @@@endif@@@
($skip > 0) && $skip--;
s/\@{3}endif\@{3}\n?//;
} elsif (/\@{3}warning\@{3}/) {
-
+ # @@@warning@@@
printWarning($config, $tmpl, $cchr);
+ } elsif (/\@{3}print\s+([^\s()]+?)\s*\(([^,]+)?\)\@{3}/) {
+ # @@@print func([arg])@@@
+ my $val;
+ if ($1 eq 'getLDAPReplicas') {$val = getLDAPReplicas();}
+ elsif ($1 eq 'getLDAPAccess') {$val = getLDAPAccess();}
+ elsif ($1 eq 'getCyrusGroups') {$val = getCyrusGroups();}
+ elsif ($1 eq 'getPostfixMap') {$val = getPostfixMap($2);}
+ else {Kolab::log('T', "Unknown printable value `$1'", KOLAB_WARN);}
+ s/\@{3}print\s+(\S+?)\@{3}//;
+ ($skip == 0) && print $config $val;
} else {
while (/\@{3}([^\s\@]+?)(\|(.+?)\((.*)\))?\@{3}/) {
+ # @@@attr@@@
+ # @@@attr|function(args)@@@
my $attr = $1;
my $fct = $3;
my $args = $4;
@@ -278,13 +279,10 @@ sub build {
move($config->filename, $cfg) || Kolab::log('T', "Error moving configfile to $cfg, error: $!", KOLAB_ERROR );
fixup( $cfg, $owner, $perm );
- if (-f $oldcfg && !defined $special_templates{$tmpl} ) {
+ if (-f $oldcfg) {
my $rc = `diff -q $cfg $oldcfg`;
chomp($rc);
if ($rc) {
- if ($cfg =~ /openldap/) {
- $haschanged{'slapd'} = 1;
- }
$templatehaschanged{$tmpl} = 1;
Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG );
@@ -294,23 +292,12 @@ sub build {
Kolab::log('T', "Finished creating configuration file `$cfg'", KOLAB_DEBUG );
}
-sub buildPostfixMap
+sub getPostfixMap
{
my $map = shift;
+ my $ret = '';
Kolab::log('T', "Building Postfix $map map", KOLAB_DEBUG);
- my $templatedir = $Kolab::config{"templatedir"};
-
- my $keytemplate = "$templatedir/$map.template";
- my $cfg = $templates{$keytemplate};
- my $oldcfg = $cfg . '.old';
-
- my $cfgfile;
- if (!($cfgfile = IO::File->new($cfg, 'a'))) {
- Kolab::log('T', "Unable to create Postfix $map map: $!", KOLAB_ERROR);
- exit(1);
- }
-
my $ldap = Kolab::LDAP::create(
$Kolab::config{'ldap_ip'},
$Kolab::config{'ldap_port'},
@@ -335,7 +322,7 @@ sub buildPostfixMap
foreach (@$routes) {
$_ = trim($_);
Kolab::log('T', "Adding entry `$_' to $map");
- print $cfgfile $_ . "\n";
+ $ret .= $_ . "\n";
}
}
} else {
@@ -343,45 +330,15 @@ sub buildPostfixMap
}
Kolab::LDAP::destroy($ldap);
- $cfgfile->close;
-
- if (-f $oldcfg) {
- my $rc = `diff -q $cfg $oldcfg`;
- chomp($rc);
- if ($rc) {
- Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG);
- $templatehaschanged{$keytemplate} = 1;
- }
- } else {
- Kolab::log('T', "`$cfg' creation detected", KOLAB_DEBUG);
- $templatehaschanged{$keytemplate} = 1;
- }
-
Kolab::log('T', "Finished building Postfix $map map", KOLAB_DEBUG);
+ return $ret;
}
-sub buildCyrusGroups
+sub getCyrusGroups
{
+ my $ret ='';
Kolab::log('T', 'Building Cyrus groups', KOLAB_DEBUG);
- my $templatedir = $Kolab::config{"templatedir"};
-
- my $keytemplate = "$templatedir/imapd.group.template";
- my $cfg = $templates{$keytemplate};
- my $oldcfg = $cfg . '.old';
- #delete $templates{$keytemplate};
-
- #my $oldmask = umask 077;
- #copy($cfg, $oldcfg);
- #chown($Kolab::config{'kolab_uid'}, $Kolab::config{'kolab_gid'}, $oldcfg);
- #umask $oldmask;
-
- my $groupconf;
- if (!($groupconf = IO::File->new($cfg, 'a'))) {
- Kolab::log('T', "Unable to open configuration file `$cfg': $!", KOLAB_ERROR);
- exit(1);
- }
-
my $ldap = Kolab::LDAP::create(
$Kolab::config{'ldap_ip'},
$Kolab::config{'ldap_port'},
@@ -419,7 +376,7 @@ sub buildCyrusGroups
}
}
$group =~ s/,$//;
- print $groupconf $group . "\n";
+ $ret .= $group . "\n";
Kolab::log('T', "Adding cyrus group `$group'");
$count++;
}
@@ -427,33 +384,17 @@ sub buildCyrusGroups
Kolab::log('T', 'No Cyrus groups found');
}
- $groupconf->close;
Kolab::LDAP::destroy($ldap);
- fixup( $cfg, $ownership{$cfg}, $permissions{$cfg});
-
Kolab::log('T', 'Finished building Cyrus groups', KOLAB_DEBUG );
+ return $ret;
}
-sub buildLDAPAccess
+sub getLDAPAccess
{
+ my $ret = '';
Kolab::log('T', 'Building LDAP access file', KOLAB_DEBUG);
- my $templatedir = $Kolab::config{"templatedir"};
-
- my $keytemplate = "$templatedir/slapd.access.template";
- if( ! -f $keytemplate ) {
- Kolab::log('T', "No LDAP access file `$keytemplate', skipping", KOLAB_DEBUG);
- return;
- }
- my $cfg = $templates{$keytemplate};
- my $oldcfg = $cfg . '.old';
-
- my $access;
- if (!($access = IO::File->new($cfg, 'a'))) {
- Kolab::log('T', "Unable to open configuration file `$cfg': $!", KOLAB_ERROR);
- exit(1);
- }
my $global_acl = <<'EOS';
# Domain specific access
@@ -497,68 +438,37 @@ EOS
}
($str = $dom_acl1) =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
- print $access $str;
+ $ret .= $str;
foreach $domain (@domains) {
($str = $dom_acl2) =~ s/\@{3}domain\@{3}/$domain/g;
$str =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
- print $access $str;
+ $ret .= $str;
}
($str = $dom_acl3) =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
- print $access $str;
+ $ret .= $str;
foreach $domain (@domains) {
($str = $global_acl) =~ s/\@{3}domain\@{3}/$domain/g;
$str =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
- print $access $str;
+ $ret .= $str;
Kolab::log('T', "Adding acl for domain '$str'");
}
-
- $access->close;
-
- if (-f $oldcfg) {
- my $rc = `diff -q $cfg $oldcfg`;
- chomp($rc);
- if ($rc) {
- Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG);
- $haschanged{'slapd'} = 1;
- }
- } else {
- $haschanged{'slapd'} = 1;
- }
-
- fixup( $cfg, $ownership{$cfg}, $permissions{$cfg});
-
- Kolab::log('T', 'Finished building LDAP access file', KOLAB_DEBUG );
+ return $ret;
}
-sub buildLDAPReplicas
+sub getLDAPReplicas
{
+ my $ret = '';
Kolab::log('T', 'Building LDAP replicas', KOLAB_DEBUG);
- my $templatedir = $Kolab::config{"templatedir"};
-
- my $keytemplate = "$templatedir/slapd.replicas.template";
- if( ! -f $keytemplate ) {
- Kolab::log('T', "No LDAP replicas `$keytemplate', skipping", KOLAB_DEBUG);
- return;
- }
- my $cfg = $templates{$keytemplate};
- my $oldcfg = $cfg . '.old';
-
- my $repl;
- if (!($repl = IO::File->new($cfg, 'a'))) {
- Kolab::log('T', "Unable to open configuration file `$cfg': $!", KOLAB_ERROR);
- exit(1);
- }
-
# directory_mode syncrepl is supported from openldap-2.3.x and beyond
if ($Kolab::config{'directory_mode'} eq "syncrepl") {
if ( $Kolab::config{'is_master'} eq "false" ) {
# Output a syncrepl statement for database synchronisation
- print $repl "syncrepl rid=0 \n"
+ $ret .= "syncrepl rid=0 \n"
." provider=".$Kolab::config{"ldap_master_uri"}."\n"
." type=refreshAndPersist\n"
." retry=\"60 10 300 +\"\n"
@@ -582,34 +492,20 @@ sub buildLDAPReplicas
}
for my $h ( @kh ) {
next if lc($h) eq lc($Kolab::config{'fqdnhostname'});
- print $repl "replica uri=ldaps://$h\n"
+ $ret .= "replica uri=ldaps://$h\n"
." binddn=\"".$Kolab::config{'bind_dn'}."\"\n"
." bindmethod=simple credentials=".$Kolab::config{'bind_pw'}."\n\n";
}
} else {
# Slave setup
# Output an update dn statement instead
- print $repl "updatedn ".$Kolab::config{'bind_dn'}."\n";
- print $repl "updateref ".$Kolab::config{'ldap_master_uri'}."\n";
+ $ret .= "updatedn ".$Kolab::config{'bind_dn'}."\n";
+ $ret .= "updateref ".$Kolab::config{'ldap_master_uri'}."\n";
}
}
- $repl->close;
-
- fixup( $cfg, $ownership{$cfg}, $permissions{$cfg});
-
- if (-f $oldcfg) {
- my $rc = `diff -q $cfg $oldcfg`;
- chomp($rc);
- if ($rc) {
- Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG);
- $haschanged{'slapd'} = 1;
- }
- } else {
- $haschanged{'slapd'} = 1;
- }
-
Kolab::log('T', 'Finished building LDAP replicas', KOLAB_DEBUG);
+ return $ret;
}
sub replaceMetaVar
@@ -715,16 +611,9 @@ sub rebuildTemplates
my $tpl;
foreach $tpl (keys %templates) {
$cfg = $templates{$tpl};
- #print STDOUT "Rebuilding $tpl => $cfg\n";
build($tpl, $cfg, $ownership{$cfg}, $permissions{$cfg}, $commentchar{$cfg});
}
- buildPostfixMap('transport');
- buildPostfixMap('virtual');
- buildLDAPAccess;
- buildLDAPReplicas;
- buildCyrusGroups;
-
Kolab::log('T', 'Finished regenerating configuration files', KOLAB_DEBUG );
my %cmds = ();
@@ -770,7 +659,6 @@ sub bootstrapConfig
my $out;
foreach my $tpl (@templ) {
$cfg = $templates{$tpl};
- # print STDOUT "Rebuilding $tpl => $cfg\n";
build($tpl, $cfg, $ownership{$cfg}, $permissions{$cfg}, $commentchar{$cfg});
}
}
@@ -811,18 +699,6 @@ sub checkPermissions {
return $ok;
}
-sub reload
-{
- if ($haschanged{'slapd'}) {
- &Kolab::log('K', 'Restarting OpenLDAP...');
- system("$Kolab::config{'KOLABRC'} rc openldap restart &");
- }
-
- %Kolab::Conf::haschanged = ();
-
- &Kolab::log('K', 'Reload finished');
-}
-
1;
__END__
=head1 NAME