aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Schema
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Fripost/Schema')
-rw-r--r--lib/Fripost/Schema/Search.pm7
-rw-r--r--lib/Fripost/Schema/Type/Alias.pm20
-rw-r--r--lib/Fripost/Schema/Type/User.pm4
3 files changed, 17 insertions, 14 deletions
diff --git a/lib/Fripost/Schema/Search.pm b/lib/Fripost/Schema/Search.pm
index 30d92d6..7c0ece6 100644
--- a/lib/Fripost/Schema/Search.pm
+++ b/lib/Fripost/Schema/Search.pm
@@ -51,11 +51,8 @@ sub _domainEntry {
my $entry = shift;
my %domain;
&_get_values( $entry, \%domain, 'domain', 'dc');
- &_get_values( $entry, \%domain, 'isActive');
- my $parent = &_get_dn($entry)->[1];
- unless ($parent eq 'ou=domains') {
- $domain{owner} = (split /=/, $parent, 2)[1];
- }
+ map { &_get_values($entry, \%domain, $_) }
+ qw /isActive owner/;
return \%domain;
}
diff --git a/lib/Fripost/Schema/Type/Alias.pm b/lib/Fripost/Schema/Type/Alias.pm
index fa78d6f..7949b4b 100644
--- a/lib/Fripost/Schema/Type/Alias.pm
+++ b/lib/Fripost/Schema/Type/Alias.pm
@@ -14,10 +14,15 @@ our $VERSION = '0.01';
# alias is given, returns all aliases.
# Filters on values of both keys `address' and `goto' (unless they are
# undefined).
+# An extra key `domain' can be given to scope the search on aliases for
+# this domain only.
sub search {
my $self = shift;
- my $base = $self->{_options}->{base_dn};
+ my $base = join ',', ( 'ou=domains'
+ , $self->{_options}->{base_dn} );
+ $base = 'dc='.$_[0]->{domain} .','. $base
+ if defined $_[0]->{domain};
my @filters = ('(ObjectClass=virtualAliases)');
push @filters, '(mailLocalAddress=' .$_[0]->{address}. ')'
@@ -54,15 +59,15 @@ sub add {
"' targetting to itself.\n"
if $alias->{address} eq $alias->{goto};
+ my $domain = (split /\@/, $alias->{address}, 2)[1];
my $base = join ',', ( 'mailTarget='.$alias->{goto}
- , 'dc='. (split /\@/, $alias->{address}, 2)[1]
+ , 'dc='. $domain
, 'ou=domains'
, $self->{_options}->{base_dn} );
- my @attrs = ( mailLocalAddress => $alias->{address}
- , isActive => $alias->{isActive} );
+ my @attrs = ( mailLocalAddress => $alias->{address} );
my $res;
- if ($self->search($alias)->count) {
+ if ($self->search({ goto => $alias->{goto}, domain => $domain })->count) {
$res = $self->{_ldap}->modify( $base, add => [ @attrs ] );
}
else {
@@ -70,8 +75,9 @@ sub add {
attrs => [ mailTarget => $alias->{goto}
, objectClass => [ 'top',
'inetLocalMailRecipient',
- 'virtualAliases' ],
- @attrs
+ 'virtualAliases' ]
+ , @attrs
+ , isActive => $alias->{isActive}
]
);
}
diff --git a/lib/Fripost/Schema/Type/User.pm b/lib/Fripost/Schema/Type/User.pm
index 09c3aa0..544687c 100644
--- a/lib/Fripost/Schema/Type/User.pm
+++ b/lib/Fripost/Schema/Type/User.pm
@@ -19,8 +19,8 @@ sub search {
my $base = join ',', ('ou=mailboxes',$self->{_options}->{base_dn});
my $filter = "(ObjectClass=virtualMailbox)";
- $filter = "(&" .$filter. "(uid=" .$_[0]. ")" .")"
- if defined $_[0];
+ $filter = "(&" .$filter. "(uid=" .$_[0]->{username}. ")" .")"
+ if defined $_[0]->{username};
my $res = $self->{_ldap}->search(
base => $base,