our $user = 'unconfigured-user';
our $passwd = 'unconfigured-password';
-our $max_results = 15; # 100; # FIXME
+our $max_results = $ENV{MAX_RESULTS} || 3000; # FIXME must be enough for all users
+our $objectclass_default = 'hrEduPerson';
-our $objectclass = 'HrEduPerson';
+our $objectclass;
$SIG{__DIE__} = sub {
warn "!!! DIE ", @_;
my $sql_where = '';
@values = ();
+ $objectclass = '';
foreach my $filter ( keys %{ $reqData->{'filter'} } ) {
}
}
- $sql_where .= ' ' . join( " $filter ", @limits );
-
} else {
__ldap_search_to_sql( $filter, $reqData->{'filter'}->{$filter} );
}
+ $sql_where .= ' ' . join( " $filter ", @limits ) if @limits;
+
}
+ $objectclass ||= $objectclass_default;
+
+ my $sql_select = read_file( lc "sql/$objectclass.sql" );
if ( $sql_where ) {
- $sql_where = " where $sql_where";
+ if ( $sql_select !~ m{where}i ) {
+ $sql_where = " where $sql_where";
+ } else {
+ $sql_where = " and $sql_where";
+ }
}
- my $sql_select = read_file( lc "sql/$objectclass.sql" );
- warn "# SQL:\n$sql_select\n", $sql_where ? $sql_where : '-- no where', "\n# DATA: ",dump( @values );
- my $sth = $dbh->prepare( $sql_select . $sql_where . " LIMIT $max_results" ); # XXX remove limit?
+ my $sql
+ = $sql_select
+ . $sql_where
+ . ( $objectclass =~ m{person}i ? " LIMIT $max_results" : '' ) # add limit just for persons
+ ;
+
+ warn "# SQL:\n$sql\n# DATA: ",dump( @values );
+ my $sth = $dbh->prepare( $sql );
$sth->execute( @values );
warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} );
+ my $last_dn = '?';
+ my $entry;
+
while (my $row = $sth->fetchrow_hashref) {
my ( $dn, $attributes ) = _dn_attributes( $row, $base );
- my $entry = Net::LDAP::Entry->new;
- $entry->dn( $dn );
- $entry->add( %$attributes );
+ warn "# dn $last_dn ... $dn\n";
+
+ if ( $dn ne $last_dn ) {
+
+ if ( $entry ) {
+ #$entry->changetype( 'modify' );
+ warn "### entry ",$entry->dump( \*STDERR );
+ push @entries, $entry;
+ undef $entry;
+ }
+
+ $entry = Net::LDAP::Entry->new;
+ $entry->dn( $dn );
+
+ $entry->add( %$attributes );
+
+ } else {
+ foreach my $n ( keys %$attributes ) {
+ my $v = $attributes->{$n};
+ warn "# attr $n = $v\n";
+ $entry->add( $n, $v ) if $entry->get_value( $n ) ne $v;
+ }
+ }
- #$entry->changetype( 'modify' );
- warn "### entry ",$entry->dump( \*STDERR );
+ $last_dn = $dn;
+
+ }
+ if ( $entry ) {
+ warn "### last entry ",$entry->dump( \*STDERR );
push @entries, $entry;
}