aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-26 18:12:01 +0100
committerGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-26 18:12:01 +0100
commit28efba729bbd2687016cf122c1b01c2e8b09c202 (patch)
tree0200b014cbe33d6a583fc5002742fa204a0be7f2
parente6789ccf70a5d03a6533d626612e7a88686df0ae (diff)
Bugfix.
-rw-r--r--lib/Fripost/Schema/Domain.pm16
-rw-r--r--lib/Fripost/Schema/Util.pm20
2 files changed, 27 insertions, 9 deletions
diff --git a/lib/Fripost/Schema/Domain.pm b/lib/Fripost/Schema/Domain.pm
index ce7b900..44ad84e 100644
--- a/lib/Fripost/Schema/Domain.pm
+++ b/lib/Fripost/Schema/Domain.pm
@@ -17,8 +17,8 @@ use warnings;
use utf8;
use parent 'Fripost::Schema';
-use Fripost::Schema::Util qw/must_attrs softdie canonical_dn dn2mail email_valid
- ldap_explode_dn ldap_error ldap_and_filter/;
+use Fripost::Schema::Util qw/softdie dn2mail email_valid domain_valid
+ canonical_dn ldap_explode_dn ldap_error/;
use Fripost::Schema::Mail;
use Net::IDN::Encode qw/domain_to_ascii domain_to_unicode email_to_unicode/;
use URI::Escape::XS 'encodeURIComponent';
@@ -204,10 +204,11 @@ sub search {
: [ '1.1' ];
}
+ my $filter = Fripost::Schema::Util::ldap_and_filter(@filters);
my $domains = $self->ldap->search( base => canonical_dn(@{$self->suffix})
, scope => 'one'
, deref => 'never'
- , filter => ldap_and_filter(@filters)
+ , filter => $filter
, attrs => $attrs
);
ldap_error($domains, %options) // return;
@@ -679,7 +680,8 @@ sub replace {
# Nothing to do after an error.
return if $options{'-error'} && ${$options{'-error'}};
- &_is_valid($domain, %options);
+ # Check domain validity.
+ &_is_valid($domain, %options) // return;
return 1 if $options{'-dry-run'};
my %entry = $self->_domain_to_entry (%$domain);
@@ -695,10 +697,8 @@ sub _is_valid {
my $d = shift;
my %options = @_;
eval {
- must_attrs( $d, qw/name isActive/ );
- $d->{name} = email_valid( $d->{name}, -prefix => 'fake@',
- -error => 'Invalid domain',
- -exact => 1 );
+ Fripost::Schema::Util::must_attrs( $d, qw/name isActive/ );
+ $d->{name} = domain_valid( $d->{name} );
$d->{catchAlls} = [ map { email_valid($_, -prefix => 'fake') }
@{$d->{catchAlls}} ]
if $d->{catchAlls};
diff --git a/lib/Fripost/Schema/Util.pm b/lib/Fripost/Schema/Util.pm
index 32f0237..6fb84dc 100644
--- a/lib/Fripost/Schema/Util.pm
+++ b/lib/Fripost/Schema/Util.pm
@@ -13,7 +13,7 @@ use utf8;
use Exporter 'import';
our @EXPORT_OK = qw /concat get_perms explode
- must_attrs email_valid split_addr dn2mail
+ must_attrs domain_valid email_valid split_addr dn2mail
canonical_dn ldap_explode_dn ldap_error ldap_and_filter
clean_ldap_entry
assert softdie/;
@@ -125,6 +125,23 @@ sub email_valid {
return $addr;
}
+sub domain_valid {
+ my $domainname = shift;
+ Encode::_utf8_on($domainname);
+ my %options = @_;
+
+ my $in = 'fake@'.Net::IDN::Encode::domain_to_ascii($domainname);
+ my $addr = Email::Valid::->address( -address => $in
+ , -tldcheck => 1
+ , -fqdn => 1 );
+ unless (defined $addr and $addr eq $in) {
+ return if $options{'-nodie'};
+ my $mesg = $options{'-die'} // "Invalid domain";
+ die $mesg." ‘".$domainname."’\n";
+ }
+ return $domainname;
+}
+
sub canonical_dn {
Net::LDAP::Util::canonical_dn(\@_, casefold => 'lower'
, mbcescape => 1
@@ -196,6 +213,7 @@ sub softdie {
if (defined $options{'-error'}) {
${$options{'-error'}} = $mesg;
+ return;
}
elsif (exists $options{'-error'}) {
return; # Ignore the error