Unverified Commit 6bb7170a authored by Luc Didry's avatar Luc Didry
Browse files

Tidy up src/ t/ xt/ files

parent ec8d60e4
......@@ -53,7 +53,7 @@ my $openssl;
foreach my $path (
split(/:/, $ENV{PATH} || ''),
qw(/usr/local/bin /usr/local/ssl/bin /opt/local/bin /usr/sfw/bin /usr/bin)
) {
) {
my $file = $path . '/openssl';
if (-x $file) {
$openssl = $file;
......@@ -79,7 +79,7 @@ my ($cert, $privatekey, $inpass, $key);
if ( ($main::options{'help'} ne '')
|| !(-r $main::options{'pkcs12'})
|| (($main::options{'listname'} ne '') && ($main::options{'robot'} ne ''))
) {
) {
print_usage();
} else {
......
......@@ -76,7 +76,7 @@ unless (
'proxy_vars=s', 'service_parameters=s',
'session_id=s'
)
) {
) {
printf "";
}
......
......@@ -48,7 +48,7 @@ unless (
qw(suffix:s attrs:s),
qw(help version)
)
) {
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($options{'help'}) {
......
......@@ -227,7 +227,7 @@ foreach my $tpl (@templates) {
group => Sympa::Constants::GROUP,
mode => 0755,
)
) {
) {
$log->syslog('err', 'Unable to set rights on %s',
$Conf::Conf{'db_name'});
next;
......@@ -283,7 +283,7 @@ sub convert {
user => Sympa::Constants::USER,
group => Sympa::Constants::GROUP
)
) {
) {
$log->syslog('err', 'Unable to set rights on %s',
$Conf::Conf{'db_name'});
return undef;
......
......@@ -106,8 +106,7 @@ sub process {
}
}
if ($found == 0) {
$log->syslog(
'notice',
$log->syslog('notice',
'bulkmailer table not found in database, bulk spool of your Sympa is probably up-to-date'
);
exit 0;
......
......@@ -47,7 +47,7 @@ unless (
\%options, 'help|h', 'version|v', 'robot=s',
'list=s', 'all_lists', 'fix_qencode'
)
) {
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($options{'help'}) {
......
......@@ -38,31 +38,35 @@ use Digest::MD5;
use Getopt::Long;
use Time::HiRes qw(gettimeofday tv_interval);
my $usage = "Usage: $0 [--dry_run|n] [--debug|d] [--verbose|v] [--config file] [--cache file] [--nosavecache] [--noupdateuser] [--limit|l]\n";
my $dry_run = 0;
my $debug = 0;
my $verbose = 0;
my $interval = 100; # frequency at which we notify how things are going
my $cache; # cache of previously encountered hashes (default undef)
my $updateuser = 1; # update user database (default yes)
my $savecache = 1; # save hash DB if specified (default yes)
my $limit = 0; # number of users to update (default all)
my $config = Conf::get_sympa_conf(); # config file to use
my $usage =
"Usage: $0 [--dry_run|n] [--debug|d] [--verbose|v] [--config file] [--cache file] [--nosavecache] [--noupdateuser] [--limit|l]\n";
my $dry_run = 0;
my $debug = 0;
my $verbose = 0;
my $interval = 100; # frequency at which we notify how things are going
my $cache; # cache of previously encountered hashes (default undef)
my $updateuser = 1; # update user database (default yes)
my $savecache = 1; # save hash DB if specified (default yes)
my $limit = 0; # number of users to update (default all)
my $config = Conf::get_sympa_conf(); # config file to use
my %options;
GetOptions(\%main::options, 'cache|c=s', 'nosavecache', 'noupdateuser',
'limit|l=i', 'config=s', 'dry_run|n', 'debug|d', 'verbose|v');
GetOptions(
\%main::options, 'cache|c=s', 'nosavecache', 'noupdateuser',
'limit|l=i', 'config=s', 'dry_run|n', 'debug|d',
'verbose|v'
);
$cache = $main::options{'cache'};
$config = $main::options{'config'} if defined($main::options{'config'});
$debug = defined($main::options{'debug'});
$verbose = defined($main::options{'verbose'});
$dry_run = defined($main::options{'dry_run'});
$debug = defined($main::options{'debug'});
$verbose = defined($main::options{'verbose'});
$dry_run = defined($main::options{'dry_run'});
$savecache = !defined($main::options{'nosavecache'});
$updateuser = !defined($main::options{'noupdateuser'});
$limit = $main::options{'limit'} || 0;
$limit = $main::options{'limit'} || 0;
STDOUT->autoflush(1);
......@@ -79,12 +83,12 @@ die 'Error in configuration'
unless Conf::load($config, 'no_db');
my $password_hash = Conf::get_robot_conf('*', 'password_hash');
my $bcrypt_cost = Conf::get_robot_conf('*', 'bcrypt_cost');
my $bcrypt_cost = Conf::get_robot_conf('*', 'bcrypt_cost');
#
# Handle the cache if specfied
#
my $hashes = {};
my $hashes = {};
my $hashes_changed = 0;
if (defined($cache) && (-e $cache)) {
......@@ -144,12 +148,12 @@ while (my $user = $sth->fetchrow_hashref('NAME_lc')) {
## do we have a precalculated hash for this user/password/hashtype?
my $checksum = checksum($clear_password);
my $checksum = checksum($clear_password);
my $email_user = $user->{'email_user'};
my $prehash = $hashes->{$email_user};
my $prehash = $hashes->{$email_user};
my $newhash;
if (defined($hashes->{$email_user})
if ( defined($hashes->{$email_user})
&& ($hashes->{$email_user}->{'type'} eq $password_hash)
&& ($hashes->{$email_user}->{'checksum'} eq $checksum)) {
......@@ -161,16 +165,18 @@ while (my $user = $sth->fetchrow_hashref('NAME_lc')) {
$hashes_changed = 1;
# track how long it takes (cheap with MD5, expensive with Bcrypt)
my $starttime = [gettimeofday];
$newhash = Sympa::User::password_fingerprint($clear_password, undef);
$newhash = Sympa::User::password_fingerprint($clear_password, undef);
my $elapsed = tv_interval($starttime, [gettimeofday]);
$total->{'newhash_time'} += $elapsed;
$total->{'newhashes'}++;
$hashes->{$email_user} = { 'email_user' => $email_user,
'checksum' => $checksum,
'type' => $password_hash,
'hash' => $newhash };
$hashes->{$email_user} = {
'email_user' => $email_user,
'checksum' => $checksum,
'type' => $password_hash,
'hash' => $newhash
};
printf "new hash $email_user $newhash\n" if ($debug);
}
......@@ -179,7 +185,7 @@ while (my $user = $sth->fetchrow_hashref('NAME_lc')) {
# notify along the way if in verbose mode. most useful for larger sites
if ($verbose && (($total->{'updated'} % $interval) == 0)) {
printf 'Processed %d users', $total->{'updated'};
if ($total->{'newhashes'}) {
if ($total->{'newhashes'}) {
printf
", %d new hashes in %.3f sec, %.4f sec/hash %.2f hash/sec",
$total->{'newhashes'}, $total->{'newhash_time'},
......@@ -201,7 +207,7 @@ while (my $user = $sth->fetchrow_hashref('NAME_lc')) {
$newhash,
$user->{'email_user'}
)
) {
) {
die 'Unable to execute SQL statement';
}
}
......@@ -229,7 +235,7 @@ printf
if ($total->{'newhashes'}) {
my $elapsed = $total->{'newhash_time'};
my $new = $total->{'newhashes'};
my $new = $total->{'newhashes'};
printf
"Time required to calculate new %s hashes: %.2f seconds %.5f sec/hash\n",
$password_hash, $total->{'newhash_time'},
......@@ -244,7 +250,7 @@ if ($total->{'prehashes'}) {
"Used %d precalculated hashes to reduce compute time.\n",
$total->{'prehashes'};
}
exit 0;
#
......@@ -267,8 +273,8 @@ sub read_hashes {
my $h = {};
open(HASHES, "<$f") || die "$0: read_hashes: open $f: $!\n";
while(<HASHES>) {
next if (/^$/ || /^\#/); # ignore blank lines/comments
while (<HASHES>) {
next if (/^$/ || /^\#/); # ignore blank lines/comments
chomp;
my ($email, $checksum, $type, $hash) = split(/ /, $_, 4);
......@@ -276,13 +282,13 @@ sub read_hashes {
unless ($email && $checksum && $type && $hash);
die "$0: $email: unsupported hash type $type\n"
unless ($type =~ /^(md5|bcrypt)$/);
$h->{$email} = {
'email_user' => $email,
'checksum' => $checksum,
'type' => $type,
'hash' => $hash
}
'email_user' => $email,
'checksum' => $checksum,
'type' => $type,
'hash' => $hash
};
}
close(HASHES);
......@@ -303,15 +309,14 @@ sub save_hashes {
my $u = $h->{$email_user};
printf HASHES "%s %s %s %s\n",
$u->{'email_user'}, $u->{'checksum'},
$u->{'type'}, $u->{'hash'};
$u->{'type'}, $u->{'hash'};
}
close(HASHES);
rename($f, "$f.old");
rename($f, "$f.old");
rename($tmpfile, $f);
}
__END__
=encoding utf-8
......
......@@ -81,7 +81,8 @@ my $all_lists = Sympa::List::get_lists('*');
# Soap part
##############################################################################
Sympa::WWW::SOAP::Transport->new(cookie_expire => $Conf::Conf{'cookie_expire'})
Sympa::WWW::SOAP::Transport->new(
cookie_expire => $Conf::Conf{'cookie_expire'})
->dispatch_with({'urn:sympasoap' => 'Sympa::WWW::SOAP'})->handle;
__END__
......
This diff is collapsed.
......@@ -1866,11 +1866,10 @@ our @params = (
},
{ 'name' => 'arc_srvid',
'gettext_id' => 'SRV ID for Authentication-Results used in ARC seal',
'gettext_comment' =>
'Typically the domain of the mail server',
'vhost' => '1',
'optional' => '1',
'file' => 'sympa.conf',
'gettext_comment' => 'Typically the domain of the mail server',
'vhost' => '1',
'optional' => '1',
'file' => 'sympa.conf',
},
{ 'name' => 'arc_signer_domain',
'vhost' => '1',
......
......@@ -53,7 +53,7 @@ sub translate_type {
# ODBC
$type =~ s/^double/real/g;
$type =~ s/^enum.*/varchar(20)/g;
$type =~ s/^text.*/varchar(4000)/g; # varchar(500) on <= 6.2.36
$type =~ s/^text.*/varchar(4000)/g; # varchar(500) on <= 6.2.36
$type =~ s/^longtext.*/text/g;
$type =~ s/^datetime/timestamp/g;
$type =~ s/^mediumblob/longvarbinary/g;
......
......@@ -639,7 +639,7 @@ sub translate_type {
$type =~ s/^tinyint\(.*\)/int2/g;
$type =~ s/^bigint.*/int8/g;
$type =~ s/^double/float8/g;
$type =~ s/^text.*/text/g; # varchar(500) on <= 6.2.36
$type =~ s/^text.*/text/g; # varchar(500) on <= 6.2.36
$type =~ s/^longtext.*/text/g;
$type =~ s/^datetime.*/timestamptz/g;
$type =~ s/^enum.*/varchar(15)/g;
......
......@@ -8056,7 +8056,9 @@ sub get_robots {
}
my $use_default_robot = 1;
foreach $r (sort readdir(DIR)) {
next unless (($r !~ /^\./o) && (-r "$Conf::Conf{'etc'}/$r/robot.conf"));
next
unless (($r !~ /^\./o)
&& (-r "$Conf::Conf{'etc'}/$r/robot.conf"));
push @robots, $r;
undef $use_default_robot if ($r eq $Conf::Conf{'domain'});
}
......
......@@ -559,7 +559,7 @@ sub arc_seal {
unless ($arc_cv =~ m{^(none|pass|fail)$}) {
$log->syslog('err',
"ARC chain value %s is invalid, could not seal message", $arc_cv);
"ARC chain value %s is invalid, could not seal message", $arc_cv);
return undef;
}
......@@ -612,7 +612,7 @@ sub arc_seal {
# Seal is done. Add new headers for the seal
my @seal = $arc->as_strings();
foreach my $ahdr (@seal) {
my ($ah, $av) = split /:\s*/,$ahdr,2;
my ($ah, $av) = split /:\s*/, $ahdr, 2;
$self->add_header($ah, $av, 0);
}
#$self->{_body} = $new_body;
......@@ -621,8 +621,9 @@ sub arc_seal {
return $self;
}
BEGIN { eval 'use Mail::DKIM::Verifier';
eval 'use Mail::DKIM::ARC::Verifier';
BEGIN {
eval 'use Mail::DKIM::Verifier';
eval 'use Mail::DKIM::ARC::Verifier';
}
sub check_dkim_signature {
......@@ -675,7 +676,7 @@ sub check_arc_chain {
? $self->{context}->{'domain'}
: $self->{context};
my $srvid;
unless($srvid = Conf::get_robot_conf($robot_id || '*', 'arc_srvid')) {
unless ($srvid = Conf::get_robot_conf($robot_id || '*', 'arc_srvid')) {
$log->syslog('debug2', 'ARC library installed, but no arc_srvid set');
return;
}
......@@ -683,15 +684,17 @@ sub check_arc_chain {
# if there is no authentication-results, not much point in checking ARC
# since we can't add a new seal
my @ars = grep { m{^\s*\Q$srvid\E;} } $self->get_header('Authentication-Results');
my @ars =
grep {m{^\s*\Q$srvid\E;}} $self->get_header('Authentication-Results');
unless(@ars) {
$log->syslog('debug2', 'ARC enabled but no Authentication-Results: %s;', $srvid);
unless (@ars) {
$log->syslog('debug2',
'ARC enabled but no Authentication-Results: %s;', $srvid);
return;
}
# already checked?
foreach my $ar (@ars) {
if($ar =~ m{\barc=(pass|fail|none)\b}i) {
if ($ar =~ m{\barc=(pass|fail|none)\b}i) {
$log->syslog('debug2', "ARC already $1");
$self->{shelved}->{arc_cv} = $1;
return;
......
......@@ -221,7 +221,7 @@ sub _twist {
# -6 remove existing signature if altered
# -7 DKIM signing
# -8 ARC seal
if ($message->{shelved}{dmarc_protect}) {
$message->dmarc_protect;
}
......@@ -229,8 +229,8 @@ sub _twist {
my ($dkim, $arc);
if ($message->{shelved}{dkim_sign}) {
$dkim = Sympa::Tools::DKIM::get_dkim_parameters($message->{context});
$arc = Sympa::Tools::DKIM::get_arc_parameters($message->{context})
if $message->{shelved}->{arc_cv};
$arc = Sympa::Tools::DKIM::get_arc_parameters($message->{context})
if $message->{shelved}->{arc_cv};
}
if ( $message->{shelved}{merge}
......@@ -343,7 +343,7 @@ sub _twist {
'arc_srvid' => $arc->{'srvid'},
'arc_privatekey' => $arc->{'private_key'},
'arc_cv' => $message->{shelved}->{arc_cv}
) if $arc;
delete $new_message->{shelved}{dkim_sign};
......
......@@ -106,33 +106,43 @@ sub get_arc_parameters {
my ($data, $keyfile);
if ($list) {
# check if enabled for the list
$log->syslog('debug2', 'list arc feature %s', $list->{'admin'}{'arc_feature'});
$log->syslog(
'debug2',
'list arc feature %s',
$list->{'admin'}{'arc_feature'}
);
return undef unless $list->{'admin'}{'arc_feature'} eq 'on';
# fetch arc parameter in list context
$data->{'d'} = $list->{'admin'}{'arc_parameters'}{'arc_signer_domain'}
|| $list->{'admin'}{'dkim_parameters'}{'signer_domain'};
$data->{'selector'} = $list->{'admin'}{'arc_parameters'}{'arc_selector'}
|| $list->{'admin'}{'dkim_parameters'}{'selector'};
|| $list->{'admin'}{'dkim_parameters'}{'signer_domain'};
$data->{'selector'} =
$list->{'admin'}{'arc_parameters'}{'arc_selector'}
|| $list->{'admin'}{'dkim_parameters'}{'selector'};
$keyfile = $list->{'admin'}{'arc_parameters'}{'arc_private_key_path'}
|| $list->{'admin'}{'dkim_parameters'}{'private_key_path'};
|| $list->{'admin'}{'dkim_parameters'}{'private_key_path'};
} else {
# in robot context
$log->syslog('debug2', 'robot arc feature %s',Conf::get_robot_conf($robot_id, 'arc_feature'));
return undef unless Conf::get_robot_conf($robot_id, 'arc_feature') eq 'on';
$log->syslog(
'debug2',
'robot arc feature %s',
Conf::get_robot_conf($robot_id, 'arc_feature')
);
return undef
unless Conf::get_robot_conf($robot_id, 'arc_feature') eq 'on';
$data->{'d'} = Conf::get_robot_conf($robot_id, 'arc_signer_domain')
|| Conf::get_robot_conf($robot_id, 'dkim_signer_domain');
$data->{'selector'} =
Conf::get_robot_conf($robot_id, 'arc_selector') ||
Conf::get_robot_conf($robot_id, 'dkim_selector');
$keyfile = Conf::get_robot_conf($robot_id, ' arc_private_key_path')
|| Conf::get_robot_conf($robot_id, 'dkim_private_key_path');
|| Conf::get_robot_conf($robot_id, 'dkim_signer_domain');
$data->{'selector'} = Conf::get_robot_conf($robot_id, 'arc_selector')
|| Conf::get_robot_conf($robot_id, 'dkim_selector');
$keyfile =
Conf::get_robot_conf($robot_id, ' arc_private_key_path')
|| Conf::get_robot_conf($robot_id, 'dkim_private_key_path');
}
$data->{'srvid'} = Conf::get_robot_conf($robot_id, 'arc_srvid')
|| $data->{'d'};
|| $data->{'d'};
return undef
unless defined $data->{'d'}
and defined $data->{'selector'}
......
......@@ -343,7 +343,7 @@ sub initialize_ldap {
sslversion => $ldap_ssl_version,
($ldap_cachain ? (cafile => $ldap_cachain) : ())
)
) {
) {
printf STDERR
"Can't connect to LDAP server using SSL or unable to verify Server certificate for %s: %s\n",
$ldap_host, $EVAL_ERROR;
......
......@@ -187,7 +187,7 @@ sub initialize_mysql {
"DBI:mysql:dbname=$mysql_base;host=$mysql_host", $mysql_user,
$mysql_pass
)
) {
) {
print "Can't connect to Database :", $DBI::errstr;
return 0;
}
......
......@@ -54,7 +54,7 @@ unless (
\%main::options, 'config|f=s', 'debug|d', 'help|h',
'foreground|F', 'log_level=s', 'version|v'
)
) {
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
......
......@@ -59,7 +59,7 @@ unless (
\%main::options, 'config|f=s', 'debug|d', 'help|h',
'log_level=s', 'foreground|F', 'version|v',
)
) {
) {
pod2usage(-exitval => 1, -output => \*STDERR);
}
if ($main::options{'help'}) {
......
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