Commit 1004fdee authored by sikeda's avatar sikeda
Browse files

[-dev] Small refactoring: cookie_changed() was moved from tools to Conf.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12056 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 3a500004
......@@ -973,7 +973,7 @@ unless (Conf::data_structure_uptodate()) {
$log->syslog('err',
'WWSympa set to maintenance mode; you should run sympa.pl --upgrade'
);
} elsif (tools::cookie_changed($Conf::Conf{'cookie'})) {
} elsif (Conf::cookie_changed()) {
$maintenance_mode = 1;
$log->syslog('err',
'WWSympa set to maintenance mode; sympa.conf/cookie parameter has changed.');
......@@ -1057,7 +1057,7 @@ while ($query = new_loop()) {
## If in maintenance mode, check if the data structure is now uptodate
if ( $maintenance_mode
and Conf::data_structure_uptodate()
and not tools::cookie_changed($Conf::Conf{'cookie'})
and not Conf::cookie_changed()
and ($EUID eq (getpwnam(Sympa::Constants::USER))[2])) {
$maintenance_mode = undef;
$log->syslog('notice',
......
......@@ -737,6 +737,48 @@ sub data_structure_uptodate {
return 1;
}
# Check if cookie parameter was changed.
# Old name: tools::cookie_changed().
sub cookie_changed {
my $current = $Conf::Conf{'cookie'};
$current = '' unless defined $current;
my $changed = 1;
if (-f "$Conf::Conf{'etc'}/cookies.history") {
my $fh;
unless (open $fh, "$Conf::Conf{'etc'}/cookies.history") {
$log->syslog('err', 'Unable to read %s/cookies.history',
$Conf::Conf{'etc'});
return undef;
}
my $oldcook = <$fh>;
close $fh;
($oldcook) = reverse split /\s+/, $oldcook;
$oldcook = '' unless defined $oldcook;
if ($oldcook eq $current) {
$log->syslog('debug2', 'Cookie is stable');
$changed = 0;
}
return $changed;
} else {
my $umask = umask 037;
unless (open COOK, ">$Conf::Conf{'etc'}/cookies.history") {
umask $umask;
$log->syslog('err', 'Unable to create %s/cookies.history',
$Conf::Conf{'etc'});
return undef;
}
umask $umask;
chown [getpwnam(Sympa::Constants::USER)]->[2],
[getgrnam(Sympa::Constants::GROUP)]->[2],
"$Conf::Conf{'etc'}/cookies.history";
print COOK "$current ";
close COOK;
return (0);
}
}
## Check a few files
sub checkfiles {
my $config_err = 0;
......
......@@ -624,46 +624,8 @@ sub escape_quote {
# used for migrating old spool.
#sub sympa_checksum($rcpt);
# create a cipher
sub cookie_changed {
my $current = shift;
$current = '' unless defined $current;
my $changed = 1;
if (-f "$Conf::Conf{'etc'}/cookies.history") {
my $fh;
unless (open $fh, "$Conf::Conf{'etc'}/cookies.history") {
$log->syslog('err', 'Unable to read %s/cookies.history',
$Conf::Conf{'etc'});
return undef;
}
my $oldcook = <$fh>;
close $fh;
($oldcook) = reverse split /\s+/, $oldcook;
$oldcook = '' unless defined $oldcook;
if ($oldcook eq $current) {
$log->syslog('debug2', 'Cookie is stable');
$changed = 0;
}
return $changed;
} else {
my $umask = umask 037;
unless (open COOK, ">$Conf::Conf{'etc'}/cookies.history") {
umask $umask;
$log->syslog('err', 'Unable to create %s/cookies.history',
$Conf::Conf{'etc'});
return undef;
}
umask $umask;
chown [getpwnam(Sympa::Constants::USER)]->[2],
[getgrnam(Sympa::Constants::GROUP)]->[2],
"$Conf::Conf{'etc'}/cookies.history";
print COOK "$current ";
close COOK;
return (0);
}
}
# Moved to Conf::cookie_changed().
#sub cookie_changed;
# Moved to Sympa::Tools::WWW:_load_mime_types()
#sub load_mime_types();
......
......@@ -199,7 +199,7 @@ if ($main::options{'upgrade_config_location'}) {
);
}
if (tools::cookie_changed($Conf::Conf{'cookie'})) {
if (Conf::cookie_changed()) {
die sprintf
'sympa.conf/cookie parameter has changed. You may have severe inconsitencies into password storage. Restore previous cookie or write some tool to re-encrypt password in database and check spools contents (look at %s/cookies.history file).',
$Conf::Conf{'etc'};
......@@ -1041,7 +1041,7 @@ sub _load {
Sympa::Tools::Password::ciphersaber_installed();
if (tools::cookie_changed($Conf::Conf{'cookie'})) {
if (Conf::cookie_changed()) {
die sprintf
'sympa.conf/cookie parameter has changed. You may have severe inconsitencies into password storage. Restore previous cookie or write some tool to re-encrypt password in database and check spools contents (look at %s/cookies.history file).',
$Conf::Conf{'etc'};
......
......@@ -339,7 +339,7 @@ sub _load {
Sympa::Tools::Password::ciphersaber_installed();
if (tools::cookie_changed($Conf::Conf{'cookie'})) {
if (Conf::cookie_changed()) {
die sprintf
'sympa.conf/cookie parameter has changed. You may have severe inconsitencies into password storage. Restore previous cookie or write some tool to re-encrypt password in database and check spools contents (look at %s/cookies.history file).',
$Conf::Conf{'etc'};
......
......@@ -460,7 +460,7 @@ sub _load {
Sympa::Tools::Password::ciphersaber_installed();
if (tools::cookie_changed($Conf::Conf{'cookie'})) {
if (Conf::cookie_changed()) {
die sprintf
'sympa.conf/cookie parameter has changed. You may have severe inconsitencies into password storage. Restore previous cookie or write some tool to re-encrypt password in database and check spools contents (look at %s/cookies.history file).',
$Conf::Conf{'etc'};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment