aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Fripost/Schema/Type/User.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Fripost/Schema/Type/User.pm')
-rw-r--r--lib/Fripost/Schema/Type/User.pm45
1 files changed, 30 insertions, 15 deletions
diff --git a/lib/Fripost/Schema/Type/User.pm b/lib/Fripost/Schema/Type/User.pm
index 794f5e5..a9eb293 100644
--- a/lib/Fripost/Schema/Type/User.pm
+++ b/lib/Fripost/Schema/Type/User.pm
@@ -6,6 +6,7 @@ use strict;
use base qw/Net::LDAP/;
use Fripost::Schema::Utils;
+use Fripost::Schema::Type::Domain;
our $VERSION = '0.01';
@@ -15,7 +16,9 @@ our $VERSION = '0.01';
# Search a user, and return the corresponding entries if found. If no
# user is given, returns all users.
# If the user has no domain part, returns matching users for any
-# domains.
+# domains. Otherwise, we first search for matching domains (we may
+# have multiple matches as wildcards are allowed), and then for each of
+# them, search for the matching users.
sub search {
my $self = shift;
my $user = shift;
@@ -25,26 +28,38 @@ sub search {
if defined $user->{username};
my $base = $self->{_options}->{base_dn};
- $base = join ',', ( 'dc='.$domain, $base )
- if defined $domain;
+ my @bases;
+ if (defined $domain) {
+ my $dres = Fripost::Schema::Type::Domain::search ( $self, {domain => $domain} );
+ foreach ($dres->entries) {
+ push @bases, join ',', ( 'dc='.$_->get_value('dc'), $base );
+ }
+ }
+ else {
+ push @bases, $base;
+ }
my $filter = "(ObjectClass=virtualMailbox)";
$filter = "(&" .$filter. "(uid=" .$username. ")" .")"
if defined $username;
- if ($self->{_options}->{debug}) {
- say STDERR "DEBUG: Search base: " .$base;
- say STDERR "DEBUG: Search filter: " .$filter;
+ my @res;
+ foreach my $b (@bases) {
+ if ($self->{_options}->{debug}) {
+ say STDERR "DEBUG: Search base: " .$b;
+ say STDERR "DEBUG: Search filter: " .$filter;
+ }
+
+ my $res = $self->{_ldap}->search(
+ base => $b,
+ scope => 'sub',
+ attrs => [ 'uid', 'gn' , 'sn', 'isActive' ],
+ filter => $filter
+ );
+ die "Error: " .$res->error. "\n" if $res->code;
+ push @res, $res;
}
-
- my $res = $self->{_ldap}->search(
- base => $base,
- scope => 'sub',
- attrs => [ 'uid', 'gn' , 'sn', 'isActive' ],
- filter => $filter
- );
- die "Error: " .$res->error. "\n" if $res->code;
- return $res;
+ return \@res;
}