diff options
author | Guilhem Moulin <guilhem.moulin@fripost.org> | 2013-01-26 18:12:01 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem.moulin@fripost.org> | 2013-01-26 18:12:01 +0100 |
commit | 28efba729bbd2687016cf122c1b01c2e8b09c202 (patch) | |
tree | 0200b014cbe33d6a583fc5002742fa204a0be7f2 /lib/Fripost/Schema/Util.pm | |
parent | e6789ccf70a5d03a6533d626612e7a88686df0ae (diff) |
Bugfix.
Diffstat (limited to 'lib/Fripost/Schema/Util.pm')
-rw-r--r-- | lib/Fripost/Schema/Util.pm | 20 |
1 files changed, 19 insertions, 1 deletions
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 |