head 1.1; access; symbols OPENPKG_E1_MP_HEAD:1.1 OPENPKG_E1_MP:1.1 OPENPKG_E1_MP_2_STABLE:1.1 OPENPKG_E1_FP:1.1 OPENPKG_2_STABLE_20061018:1.1 OPENPKG_2_STABLE:1.1.0.14 OPENPKG_2_STABLE_BP:1.1 OPENPKG_2_5_SOLID:1.1.0.12 OPENPKG_2_5_SOLID_BP:1.1 OPENPKG_2_4_RELEASE:1.1 OPENPKG_2_4_SOLID:1.1.0.10 OPENPKG_2_4_SOLID_BP:1.1 OPENPKG_2_3_RELEASE:1.1 OPENPKG_2_3_SOLID:1.1.0.8 OPENPKG_2_3_SOLID_BP:1.1 OPENPKG_2_2_RELEASE:1.1 OPENPKG_2_2_SOLID:1.1.0.6 OPENPKG_2_2_SOLID_BP:1.1 OPENPKG_2_1_RELEASE:1.1 OPENPKG_2_1_SOLID:1.1.0.4 OPENPKG_2_1_SOLID_BP:1.1 OPENPKG_2_0_SOLID:1.1.0.2; locks; strict; comment @# @; 1.1 date 2004.05.05.13.05.03; author rse; state dead; branches 1.1.2.1; next ; 1.1.2.1 date 2004.05.05.13.05.03; author rse; state Exp; branches; next ; desc @@ 1.1 log @file perl-kolab.patch was initially added on branch OPENPKG_2_0_SOLID. @ text @@ 1.1.2.1 log @MFC: fix chown; SA-2004.019-kolab @ text @a0 163 --- Conf.pm 2004-05-03 14:27:12.000000000 +0200 +++ Conf.pm 2004-05-03 14:27:41.000000000 +0200 @@@@ -56,72 +56,94 @@@@ our $VERSION = '0.9'; -sub build { - my $tmpl = shift; - my $cfg = shift; - my $oldcfg = $cfg . '.old'; - my $prefix = $Kolab::config{'prefix'}; - - my $tmpfile = $prefix . '/etc/kolab/.tmp'; - copy($cfg, $oldcfg); - chown($Kolab::config{'kolab_uid'}, $Kolab::config{'kolab_gid'}, $oldcfg); - - Kolab::log('T', "Creating new configuration file `$cfg' from template `$tmpl'"); - - my $template; - if (!($template = IO::File->new($tmpl, 'r'))) { - Kolab::log('T', "Unable to open template file `$tmpl'", KOLAB_ERROR); - exit(1); - } - my $config; - if (!($config = IO::File->new($tmpfile, 'w+'))) { - Kolab::log('T', "Unable to open configuration file `$cfg'", KOLAB_ERROR); - exit(1); - } - - while (<$template>) { - if (/\@@{3}(\S+)\@@{3}/) { - if ($Kolab::config{$1}) { - s/\@@{3}(\S+)\@@{3}/$Kolab::config{$1}/g; - } else { - Kolab::log('T', "No configuration variable corresponding to `$1' exists", KOLAB_WARN); - s/\@@{3}(\S+)\@@{3}//g; - } - } - print $config $_; - } - - $template->close; - $config->close; - - move($tmpfile, $cfg); - chown($Kolab::config{'kolab_uid'}, $Kolab::config{'kolab_gid'}, $cfg); - - if (-f $oldcfg) { - my $rc = `diff -q $cfg $oldcfg`; - chomp($rc); - if ($rc) { - if ($cfg =~ /postfix/) { - $Kolab::haschanged{'postfix'} = 1; - } elsif ($cfg =~ /saslauthd/) { - $Kolab::haschanged{'saslauthd'} = 1; - } elsif ($cfg =~ /apache/) { - $Kolab::haschanged{'apache'} = 1; - } elsif ($cfg =~ /proftpd/) { - $Kolab::haschanged{'proftpd'} = 1; - } elsif ($cfg =~ /openldap/) { - $Kolab::haschanged{'slapd'} = 1; - } elsif ($cfg =~ /imapd/) { - $Kolab::haschanged{'imapd'} = 1; - } - - Kolab::log('T', "`$cfg' change detected: $rc", KOLAB_DEBUG); - } - } - - Kolab::log('T', "Finished creating configuration file `$cfg'"); -} - +sub build { + my $tmpl = shift; + my $cfg = shift; + my $prefix = $Kolab::config{'prefix'}; + + my $TEMPLATE; + if (!($TEMPLATE = IO::File->new($tmpl, 'r'))) { + Kolab::log('T', "Unable to open template file `$tmpl'", KOLAB_ERROR); + exit(1); + } + my @@tempfile = (); + + while (<$TEMPLATE>) { + if (/\@@{3}(\S+)\@@{3}/) { + if ($Kolab::config{$1}) { + s/\@@{3}(\S+)\@@{3}/$Kolab::config{$1}/g; + } else { + Kolab::log('T', "No configuration variable corresponding to `$1' exists", KOLAB_WARN); + s/\@@{3}(\S+)\@@{3}//g; + } + } + push (@@tempfile, $_); + } + $TEMPLATE->close; + + my $CONFIGFILE; + if (!($CONFIGFILE = IO::File->new($cfg, 'r'))) { + Kolab::log('T', "Unable to open config file `$cfg'", KOLAB_ERROR); + exit(1); + } + + my $configchanged = 0; + + foreach my $line (@@tempfile) { + my $configline = <$CONFIGFILE>; + $configchanged = 1 if ($configline ne $line) + } + $CONFIGFILE->close; + undef $CONFIGFILE; + + return 0 if ($configchanged ne 1); + + if ($configchanged) { + Kolab::log('T', "`$cfg' change detected.", KOLAB_DEBUG); + + if ($cfg =~ /postfix/) { + $Kolab::haschanged{'postfix'} = 1; + } elsif ($cfg =~ /saslauthd/) { + $Kolab::haschanged{'saslauthd'} = 1; + } elsif ($cfg =~ /apache/) { + $Kolab::haschanged{'apache'} = 1; + } elsif ($cfg =~ /proftpd/) { + $Kolab::haschanged{'proftpd'} = 1; + } elsif ($cfg =~ /openldap/) { + $Kolab::haschanged{'slapd'} = 1; + } elsif ($cfg =~ /imapd/) { + $Kolab::haschanged{'imapd'} = 1; + } + } + Kolab::log('T', "Creating new configuration file `$cfg' from template `$tmpl'"); + + my $tmpfile = $prefix . '/etc/kolab/.tmp'; + unlink($tmpfile); + my $NEWFILE; + if ($cfg =~ /openldap/) { + if (!($NEWFILE = IO::File->new($tmpfile, O_RDWR|O_CREAT|O_EXCL, 0600))) { + Kolab::log('T', "Unable to open configuration file `$tmpfile'", KOLAB_ERROR); + exit(1); + } + } else { + if (!($NEWFILE = IO::File->new($tmpfile, O_RDWR|O_CREAT|O_EXCL, 0644))) { + Kolab::log('T', "Unable to open configuration file `$tmpfile'", KOLAB_ERROR); + exit(1); + } + } + + foreach my $line (@@tempfile) { + print $NEWFILE $line; + } + $NEWFILE->close; + unlink($cfg); + link($tmpfile,$cfg); + unlink($tmpfile); + chown($Kolab::config{'kolab_uid'}, $Kolab::config{'kolab_gid'}, $cfg); + + Kolab::log('T', "Finished creating configuration file `$cfg'"); +} + sub buildPostfixTransportMap { Kolab::log('T', 'Building Postfix transport map'); @