aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Fripost/Schema/Search.pm28
-rw-r--r--lib/Fripost/Schema/Type/User.pm45
2 files changed, 55 insertions, 18 deletions
diff --git a/lib/Fripost/Schema/Search.pm b/lib/Fripost/Schema/Search.pm
index a9eb2ea..1051a21 100644
--- a/lib/Fripost/Schema/Search.pm
+++ b/lib/Fripost/Schema/Search.pm
@@ -11,7 +11,20 @@ use base qw/Net::LDAP::Search/;
our $VERSION = '0.01';
# Count the entries got out from the query.
-sub count { $_[0]->{_res}->count }
+sub count {
+ my $self = shift;
+
+ if (ref $self->{_res} eq 'ARRAY') {
+ my $count;
+ foreach (@{$self->{_res}}) {
+ $count += $_->count;
+ }
+ return $count;
+ }
+ else {
+ return $self->{_res}->count;
+ }
+}
# Create a hash out of the LDAP entry. Keys depend on the context
# of the object.
@@ -31,11 +44,20 @@ sub entries {
$dumpEntry = "_aliasEntry";
}
else {
- die "Something weird happened. Please report."
+ die "Something weird happened. Please report.";
}
+ my @entries;
+ if (ref $self->{_res} eq 'ARRAY') {
+ foreach (@{$self->{_res}}) {
+ push @entries, $_->entries;
+ }
+ }
+ else {
+ @entries = ($self->{_res}->entries);
+ }
no strict "refs";
- return (map {&$dumpEntry($_)} $self->{_res}->entries);
+ return (map {&$dumpEntry($_)} @entries);
}
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;
}