25 |
our $user = 'unconfigured-user'; |
our $user = 'unconfigured-user'; |
26 |
our $passwd = 'unconfigured-password'; |
our $passwd = 'unconfigured-password'; |
27 |
|
|
28 |
our $max_results = 15; # 100; # FIXME |
our $max_results = 3000; # FIXME must be enough for all users |
29 |
|
our $objectclass_default = 'hrEduPerson'; |
30 |
|
|
31 |
our $objectclass = 'HrEduPerson'; |
our $objectclass; |
32 |
|
|
33 |
$SIG{__DIE__} = sub { |
$SIG{__DIE__} = sub { |
34 |
warn "!!! DIE ", @_; |
warn "!!! DIE ", @_; |
157 |
|
|
158 |
my $sql_where = ''; |
my $sql_where = ''; |
159 |
@values = (); |
@values = (); |
160 |
|
$objectclass = ''; |
161 |
|
|
162 |
foreach my $filter ( keys %{ $reqData->{'filter'} } ) { |
foreach my $filter ( keys %{ $reqData->{'filter'} } ) { |
163 |
|
|
179 |
} |
} |
180 |
} |
} |
181 |
|
|
|
$sql_where .= ' ' . join( " $filter ", @limits ); |
|
|
|
|
182 |
} else { |
} else { |
183 |
__ldap_search_to_sql( $filter, $reqData->{'filter'}->{$filter} ); |
__ldap_search_to_sql( $filter, $reqData->{'filter'}->{$filter} ); |
184 |
} |
} |
185 |
|
|
186 |
|
$sql_where .= ' ' . join( " $filter ", @limits ) if @limits; |
187 |
|
|
188 |
} |
} |
189 |
|
|
190 |
|
$objectclass ||= $objectclass_default; |
191 |
|
|
192 |
|
my $sql_select = read_file( lc "sql/$objectclass.sql" ); |
193 |
if ( $sql_where ) { |
if ( $sql_where ) { |
194 |
$sql_where = " where $sql_where"; |
if ( $sql_select !~ m{where}i ) { |
195 |
|
$sql_where = " where $sql_where"; |
196 |
|
} else { |
197 |
|
$sql_where = " and $sql_where"; |
198 |
|
} |
199 |
} |
} |
200 |
|
|
|
my $sql_select = read_file( lc "sql/$objectclass.sql" ); |
|
201 |
|
|
202 |
warn "# SQL:\n$sql_select\n", $sql_where ? $sql_where : '-- no where', "\n# DATA: ",dump( @values ); |
warn "# SQL:\n$sql_select\n", $sql_where ? $sql_where : '-- no where', "\n# DATA: ",dump( @values ); |
203 |
my $sth = $dbh->prepare( $sql_select . $sql_where . " LIMIT $max_results" ); # XXX remove limit? |
my $sth = $dbh->prepare( $sql_select . $sql_where . " LIMIT $max_results" ); # XXX remove limit? |
205 |
|
|
206 |
warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} ); |
warn "# ", $sth->rows, " results for ",dump( $reqData->{'filter'} ); |
207 |
|
|
208 |
|
my $last_dn = '?'; |
209 |
|
my $entry; |
210 |
|
|
211 |
while (my $row = $sth->fetchrow_hashref) { |
while (my $row = $sth->fetchrow_hashref) { |
212 |
|
|
213 |
my ( $dn, $attributes ) = _dn_attributes( $row, $base ); |
my ( $dn, $attributes ) = _dn_attributes( $row, $base ); |
214 |
|
|
215 |
my $entry = Net::LDAP::Entry->new; |
warn "# dn $last_dn ... $dn\n"; |
216 |
$entry->dn( $dn ); |
|
217 |
$entry->add( %$attributes ); |
if ( $dn ne $last_dn ) { |
218 |
|
|
219 |
#$entry->changetype( 'modify' ); |
if ( $entry ) { |
220 |
|
#$entry->changetype( 'modify' ); |
221 |
|
warn "### entry ",$entry->dump( \*STDERR ); |
222 |
|
push @entries, $entry; |
223 |
|
undef $entry; |
224 |
|
} |
225 |
|
|
226 |
|
$entry = Net::LDAP::Entry->new; |
227 |
|
$entry->dn( $dn ); |
228 |
|
|
229 |
warn "### entry ",$entry->dump( \*STDERR ); |
$entry->add( %$attributes ); |
230 |
|
|
231 |
|
} else { |
232 |
|
foreach my $n ( keys %$attributes ) { |
233 |
|
my $v = $attributes->{$n}; |
234 |
|
warn "# attr $n = $v\n"; |
235 |
|
$entry->add( $n, $v ) if $entry->get_value( $n ) ne $v; |
236 |
|
} |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
|
$last_dn = $dn; |
241 |
|
|
|
push @entries, $entry; |
|
242 |
} |
} |
243 |
|
|
244 |
|
warn "### last entry ",$entry->dump( \*STDERR ); |
245 |
|
push @entries, $entry; |
246 |
|
|
247 |
} else { |
} else { |
248 |
warn "UNKNOWN request: ",dump( $reqData ); |
warn "UNKNOWN request: ",dump( $reqData ); |
249 |
} |
} |