aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Schema
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-22 02:58:23 +0100
committerGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-22 02:58:23 +0100
commitf674299b721d26ea97fc36e7e6818a84f3d311d3 (patch)
tree75c23d231e57296357d27b1ec78686c06a895980 /lib/Fripost/Schema
parent9f75efbed94052726c64284bad49d37ce905172f (diff)
Better check for domain existence.
Diffstat (limited to 'lib/Fripost/Schema')
-rw-r--r--lib/Fripost/Schema/Domain.pm9
-rw-r--r--lib/Fripost/Schema/Local.pm2
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/Fripost/Schema/Domain.pm b/lib/Fripost/Schema/Domain.pm
index 56e9737..8c3586f 100644
--- a/lib/Fripost/Schema/Domain.pm
+++ b/lib/Fripost/Schema/Domain.pm
@@ -17,7 +17,7 @@ use warnings;
use utf8;
use parent 'Fripost::Schema';
-use Net::LDAP qw/LDAP_SUCCESS LDAP_COMPARE_TRUE/;
+use Net::LDAP qw/LDAP_SUCCESS LDAP_COMPARE_TRUE LDAP_NO_SUCH_OBJECT/;
use Fripost::Schema::Util qw/concat get_perms explode must_attrs
email_valid canonical_dn/;
use Net::IDN::Encode qw/domain_to_ascii domain_to_unicode
@@ -113,6 +113,8 @@ sub get {
fripostOwner
fripostPostmaster/ ];
+ $attrs = [ '1.1' ] if $options{'-assert_exist'};
+
my $domains = $self->ldap->search(
base => canonical_dn({fvd => $d}, @{$self->suffix}),
scope => 'base',
@@ -133,6 +135,7 @@ sub get {
die $options{'-die'}."\n" if defined $options{'-die'};
die "No such such domain: ā€˜$dā€™\n";
}
+ return if $options{'-assert_exist'};
return ( domain => domain_to_unicode($domain->get_value('fvd'))
, isactive => $domain->get_value('fripostIsStatusActive') eq 'TRUE'
@@ -237,11 +240,11 @@ sub add {
scope => 'base',
deref => 'never',
filter => 'objectClass=FripostVirtualDomain',
- attrs => [] );
+ attrs => [ '1.1' ] );
if ($mesg->code == LDAP_SUCCESS) {
die "Domain ā€˜".$domain."ā€™ already exists.\n";
}
- elsif ($mesg->code != 32) {
+ elsif ($mesg->code != LDAP_NO_SUCH_OBJECT) {
die $mesg->error."\n";
}
diff --git a/lib/Fripost/Schema/Local.pm b/lib/Fripost/Schema/Local.pm
index 51cac34..7a1ae22 100644
--- a/lib/Fripost/Schema/Local.pm
+++ b/lib/Fripost/Schema/Local.pm
@@ -144,7 +144,7 @@ sub exists {
, scope => 'base'
, deref => 'never'
, filter => 'objectClass=*'
- , attrs => []
+ , attrs => [ '1.1' ]
);
return 1 unless $mesg->code; # 0 Success
unless ($mesg->code == 32) { # 32 No such object