summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMathieu Parent <math.parent@gmail.com>2009-12-13 18:27:08 (GMT)
committerMathieu Parent <math.parent@gmail.com>2009-12-13 18:27:08 (GMT)
commitc2a016601ca62d9ed13e7aa96ae93aa378b17d95 (patch)
tree38e977efd452ea9e56fe69beb27043baf751b00c /lib
parent59825e388ee4799b86c4519b71e092fb8a1a43b3 (diff)
downloadperl-Kolab-c2a016601ca62d9ed13e7aa96ae93aa378b17d95.tar.gz
Correct indentation: tab -> 4 spaces
Diffstat (limited to 'lib')
-rw-r--r--lib/Kolab/Conf.pm272
1 files changed, 135 insertions, 137 deletions
diff --git a/lib/Kolab/Conf.pm b/lib/Kolab/Conf.pm
index 7274bc4..424224c 100644
--- a/lib/Kolab/Conf.pm
+++ b/lib/Kolab/Conf.pm
@@ -69,13 +69,13 @@ sub fixup {
my $gid = (getgrnam($group))[2];
Kolab::log('T', sprintf("Changing permissions of %s to 0%o", $file, $perm ), KOLAB_DEBUG );
if( chmod($perm, $file) != 1 ) {
- Kolab::log('T', "Unable to change permissions of `$file' to ".sprintf("0%o",$perm) . ": $!", KOLAB_ERROR);
- exit(1);
+ Kolab::log('T', "Unable to change permissions of `$file' to ".sprintf("0%o",$perm) . ": $!", KOLAB_ERROR);
+ exit(1);
}
Kolab::log('T', "Changing owner of $file to $owner:$group ($uid:$gid)", KOLAB_DEBUG );
if( chown($uid,$gid,$file) != 1 ) {
- Kolab::log('T', "Unable to change ownership of `$file' to $uid:$gid: $!", KOLAB_ERROR);
- exit(1);
+ Kolab::log('T', "Unable to change ownership of `$file' to $uid:$gid: $!", KOLAB_ERROR);
+ exit(1);
}
}
@@ -145,7 +145,7 @@ sub build {
#Eat the meta data sections
if (/^KOLAB_META_START$/) {
my $found_end;
- while (!$found_end) {
+ while (!$found_end) {
$_ = <$template>;
$found_end = /^KOLAB_META_END$/;
}
@@ -304,13 +304,13 @@ sub getPostfixMap
$Kolab::config{'ldap_port'},
$Kolab::config{'bind_dn'},
$Kolab::config{'bind_pw'}
- );
+ );
my $mesg = $ldap->search(
base => 'k=kolab,'.$Kolab::config{'base_dn'},
scope => 'base',
filter => '(objectclass=*)'
- );
+ );
if ($mesg->code) {
Kolab::log('T', "Unable to locate Postfix $map map entries in LDAP", KOLAB_ERROR);
exit(1);
@@ -345,13 +345,13 @@ sub getCyrusGroups
$Kolab::config{'ldap_port'},
$Kolab::config{'bind_dn'},
$Kolab::config{'bind_pw'}
- );
+ );
my $mesg = $ldap->search(
base => $Kolab::config{'base_dn'},
scope => 'sub',
filter => '(&(mail=*)(objectclass=kolabgroupofnames))'
- );
+ );
if ($mesg->code) {
Kolab::log('T', 'Unable to locate Cyrus groups in LDAP', KOLAB_ERROR);
exit(1);
@@ -362,20 +362,20 @@ sub getCyrusGroups
if ($mesg->code <= 0) {
foreach $ldapobject ($mesg->entries) {
#my $group = $ldapobject->get_value('cn') . '@'.join('.',reverse(@dn)) . ":*:$count:";
- my $group = lc($ldapobject->get_value('mail')).":*:$count:";
+ my $group = lc($ldapobject->get_value('mail')).":*:$count:";
my $userlist = $ldapobject->get_value('member', asref => 1);
foreach (@$userlist) {
- my $uid = $_;
- my $umesg = $ldap->search( base => $uid,
- scope => 'base',
- filter => '(objectClass=*)' );
- if ( $umesg && $umesg->code() <= 0 && $umesg->count() == 1 ) {
- my $mail;
- ($mail = $umesg->entry(0)->get_value('mail')) or
- ($mail = $umesg->entry(0)->get_value('uid'));
- $group .= lc($mail).',';
- }
- }
+ my $uid = $_;
+ my $umesg = $ldap->search( base => $uid,
+ scope => 'base',
+ filter => '(objectClass=*)' );
+ if ( $umesg && $umesg->code() <= 0 && $umesg->count() == 1 ) {
+ my $mail;
+ ($mail = $umesg->entry(0)->get_value('mail')) or
+ ($mail = $umesg->entry(0)->get_value('uid'));
+ $group .= lc($mail).',';
+ }
+ }
$group =~ s/,$//;
$ret .= $group . "\n";
Kolab::log('T', "Adding cyrus group `$group'");
@@ -429,32 +429,32 @@ my $dom_acl3 = << 'EOS';
by * search stop
EOS
- my $str;
+ my $str;
my $domain;
my @domains;
if( ref($Kolab::config{'postfix-mydestination'}) eq 'ARRAY' ) {
- @domains = @{$Kolab::config{'postfix-mydestination'}};
+ @domains = @{$Kolab::config{'postfix-mydestination'}};
} else {
- @domains =( $Kolab::config{'postfix-mydestination'} );
+ @domains =( $Kolab::config{'postfix-mydestination'} );
}
($str = $dom_acl1) =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
$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;
- $ret .= $str;
+ ($str = $dom_acl2) =~ s/\@{3}domain\@{3}/$domain/g;
+ $str =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
+ $ret .= $str;
}
($str = $dom_acl3) =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
$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;
- $ret .= $str;
- Kolab::log('T', "Adding acl for domain '$str'");
+ ($str = $global_acl) =~ s/\@{3}domain\@{3}/$domain/g;
+ $str =~ s/\@{3}base_dn\@{3}/$Kolab::config{'base_dn'}/g;
+ $ret .= $str;
+ Kolab::log('T', "Adding acl for domain '$str'");
}
return $ret;
}
@@ -483,26 +483,26 @@ sub getLDAPReplicas
} else {
- if( $Kolab::config{'is_master'} eq "true" ) {
- # Master setup
- my @kh;
- if( ref $Kolab::config{'kolabhost'} eq 'ARRAY' ) {
- @kh = @{$Kolab::config{'kolabhost'}};
- } else {
- @kh = ( $Kolab::config{'kolabhost'} );
- }
- for my $h ( @kh ) {
- next if lc($h) eq lc($Kolab::config{'fqdnhostname'});
- $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
- $ret .= "updatedn ".$Kolab::config{'bind_dn'}."\n";
- $ret .= "updateref ".$Kolab::config{'ldap_master_uri'}."\n";
- }
+ if( $Kolab::config{'is_master'} eq "true" ) {
+ # Master setup
+ my @kh;
+ if( ref $Kolab::config{'kolabhost'} eq 'ARRAY' ) {
+ @kh = @{$Kolab::config{'kolabhost'}};
+ } else {
+ @kh = ( $Kolab::config{'kolabhost'} );
+ }
+ for my $h ( @kh ) {
+ next if lc($h) eq lc($Kolab::config{'fqdnhostname'});
+ $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
+ $ret .= "updatedn ".$Kolab::config{'bind_dn'}."\n";
+ $ret .= "updateref ".$Kolab::config{'ldap_master_uri'}."\n";
+ }
}
Kolab::log('T', 'Finished building LDAP replicas', KOLAB_DEBUG);
@@ -510,24 +510,24 @@ sub getLDAPReplicas
}
sub replaceMetaVar
-{
+{
my $var = shift;
while ($var =~ /\@{3}([^\s\@]+?)\@{3}/) {
- my $attr = $1;
- if ($Kolab::config{$attr}) {
- my $val = $Kolab::config{$attr};
- $var =~ s/\@{3}([^\s\@]+?)\@{3}/$val/;
- } else {
- Kolab::log('T', "No configuration variable corresponding to `$1' exists", KOLAB_WARN);
- }
+ my $attr = $1;
+ if ($Kolab::config{$attr}) {
+ my $val = $Kolab::config{$attr};
+ $var =~ s/\@{3}([^\s\@]+?)\@{3}/$val/;
+ } else {
+ Kolab::log('T', "No configuration variable corresponding to `$1' exists", KOLAB_WARN);
+ }
}
return $var;
}
sub loadMetaTemplates
-{
+{
my $templatedir = shift;
my ($tref, $pref, $oref, $cmdref, $ccharref) = @_;
@@ -537,59 +537,58 @@ sub loadMetaTemplates
closedir(DIR);
foreach my $template (@metatemplates) {
- my $runonchange = undef;
- my $commentchar = undef;
- #Open each file and check for the META
- if (open (TEMPLATE, "$templatedir/$template" )) {
- my $line = <TEMPLATE>;
- if ($line =~ /^KOLAB_META_START$/) {
- Kolab::log('T', 'Processing META template :'.$template, KOLAB_DEBUG );
- my ($found_end, $target, $permissions, $ownership);
- while (<TEMPLATE>) {
- $line = $_;
-
- if (!$found_end) {
- $found_end = $line =~ /^KOLAB_META_END$/;
- if (!$found_end && $line) {
- my ($key,$value) = split(/=/,$line);
- chomp($value);
- Kolab::log('T', 'META Key: '.$key.' Value: '.$value, KOLAB_DEBUG );
- if ($key =~ /^TARGET$/) {
- $target = replaceMetaVar($value);
- Kolab::log('T', 'META Target '.$target, KOLAB_DEBUG );
- } elsif ($key =~ /^PERMISSIONS$/) {
- $permissions = replaceMetaVar($value);
- Kolab::log('T', 'META Permissions '.$permissions, KOLAB_DEBUG );
- } elsif ($key =~ /^OWNERSHIP$/) {
- $ownership = replaceMetaVar($value);
- Kolab::log('T', 'META Ownership '.$ownership, KOLAB_DEBUG );
- } elsif ($key =~ /^RUNONCHANGE$/) {
- $runonchange = replaceMetaVar($value);
- Kolab::log('T', 'META Cmd to execute '.$runonchange, KOLAB_DEBUG );
- } elsif ($key =~ /^COMMENT_CHAR$/) {
- $commentchar = replaceMetaVar($value);
- Kolab::log('T', 'META CommentChar to use: '.$commentchar, KOLAB_DEBUG );
- } else {
- Kolab::log('T', 'incorrect META key "'.$key.'" in: '.$template, KOLAB_WARN );
- }
- }
- }
- }
- if ($found_end && $target && $permissions && $ownership) {
- Kolab::log('T', 'All mandatory fields populated in '.$template, KOLAB_DEBUG );
- $$tref{$templatedir . "/" . $template} = $target;
- $$oref{$target} = $ownership;
- $permissions = oct($permissions);
- $$pref{$target} = $permissions;
- my $runcmdtemplate = $templatedir."/".$template;
- $$cmdref{$runcmdtemplate} = $runonchange if (defined $runonchange);
- $$ccharref{$target} = $commentchar if (defined $commentchar);
- }
-
- }
- } else {
- Kolab::log('T', 'Could not open template file: '. $template, KOLAB_WARN);
- }
+ my $runonchange = undef;
+ my $commentchar = undef;
+ #Open each file and check for the META
+ if (open (TEMPLATE, "$templatedir/$template" )) {
+ my $line = <TEMPLATE>;
+ if ($line =~ /^KOLAB_META_START$/) {
+ Kolab::log('T', 'Processing META template :'.$template, KOLAB_DEBUG );
+ my ($found_end, $target, $permissions, $ownership);
+ while (<TEMPLATE>) {
+ $line = $_;
+
+ if (!$found_end) {
+ $found_end = $line =~ /^KOLAB_META_END$/;
+ if (!$found_end && $line) {
+ my ($key,$value) = split(/=/,$line);
+ chomp($value);
+ Kolab::log('T', 'META Key: '.$key.' Value: '.$value, KOLAB_DEBUG );
+ if ($key =~ /^TARGET$/) {
+ $target = replaceMetaVar($value);
+ Kolab::log('T', 'META Target '.$target, KOLAB_DEBUG );
+ } elsif ($key =~ /^PERMISSIONS$/) {
+ $permissions = replaceMetaVar($value);
+ Kolab::log('T', 'META Permissions '.$permissions, KOLAB_DEBUG );
+ } elsif ($key =~ /^OWNERSHIP$/) {
+ $ownership = replaceMetaVar($value);
+ Kolab::log('T', 'META Ownership '.$ownership, KOLAB_DEBUG );
+ } elsif ($key =~ /^RUNONCHANGE$/) {
+ $runonchange = replaceMetaVar($value);
+ Kolab::log('T', 'META Cmd to execute '.$runonchange, KOLAB_DEBUG );
+ } elsif ($key =~ /^COMMENT_CHAR$/) {
+ $commentchar = replaceMetaVar($value);
+ Kolab::log('T', 'META CommentChar to use: '.$commentchar, KOLAB_DEBUG );
+ } else {
+ Kolab::log('T', 'incorrect META key "'.$key.'" in: '.$template, KOLAB_WARN );
+ }
+ }
+ }
+ }
+ if ($found_end && $target && $permissions && $ownership) {
+ Kolab::log('T', 'All mandatory fields populated in '.$template, KOLAB_DEBUG );
+ $$tref{$templatedir . "/" . $template} = $target;
+ $$oref{$target} = $ownership;
+ $permissions = oct($permissions);
+ $$pref{$target} = $permissions;
+ my $runcmdtemplate = $templatedir."/".$template;
+ $$cmdref{$runcmdtemplate} = $runonchange if (defined $runonchange);
+ $$ccharref{$target} = $commentchar if (defined $commentchar);
+ }
+ }
+ } else {
+ Kolab::log('T', 'Could not open template file: '. $template, KOLAB_WARN);
+ }
}
}
@@ -622,11 +621,10 @@ sub rebuildTemplates
my %cmds = ();
foreach $key (keys %runonchange) {
- if (defined $confighaschanged{$key})
- {
- Kolab::log('T', 'Queueing RUNONCHANGE for '.$key, KOLAB_DEBUG );
- $cmds{$runonchange{$key}} = 1;
- }
+ if (defined $confighaschanged{$key}) {
+ Kolab::log('T', 'Queueing RUNONCHANGE for '.$key, KOLAB_DEBUG );
+ $cmds{$runonchange{$key}} = 1;
+ }
}
my $cmd;
foreach $cmd (keys %cmds) {
@@ -680,25 +678,25 @@ sub checkPermissions {
my $ok = 1;
foreach $key (keys %templates) {
- my $tpl = $templates{$key};
-
- if (-r $tpl) {
- my $st = stat($tpl);
- my $owner = getpwuid($st->uid).':'.getgrgid($st->gid);
- if( ( ($st->mode & 07777) != $permissions{$tpl}) ||
- ($owner ne $ownership{$tpl}) ) {
- my $str = 'File '.$tpl.' has the wrong persmissions/owner. Found '
- .sprintf("%lo", $st->mode&07777).' '.$owner.', expected '
- .sprintf("%lo",$permissions{$tpl}).' '.$ownership{$tpl};
- print( "$str\n" );
- Kolab::log('T', $str, KOLAB_ERROR );
- $ok = 0;
- }
- } else {
- my $str = "File $tpl does not exist";
- print "$str\n";
- Kolab::log('T', "$str", KOLAB_ERROR );
- }
+ my $tpl = $templates{$key};
+
+ if (-r $tpl) {
+ my $st = stat($tpl);
+ my $owner = getpwuid($st->uid).':'.getgrgid($st->gid);
+ if( ( ($st->mode & 07777) != $permissions{$tpl}) ||
+ ($owner ne $ownership{$tpl}) ) {
+ my $str = 'File '.$tpl.' has the wrong persmissions/owner. Found '
+ .sprintf("%lo", $st->mode&07777).' '.$owner.', expected '
+ .sprintf("%lo",$permissions{$tpl}).' '.$ownership{$tpl};
+ print( "$str\n" );
+ Kolab::log('T', $str, KOLAB_ERROR );
+ $ok = 0;
+ }
+ } else {
+ my $str = "File $tpl does not exist";
+ print "$str\n";
+ Kolab::log('T', "$str", KOLAB_ERROR );
+ }
}
return $ok;
}