LX0-104 · Question #162
The following excerpt is from a Perl script that reads a LDAP database and writes a LDIF file: $ldap =Net::LDAP->new( 'ldap.server.com' ); $mesg = $ldap->bind( 'cn=incadmin,o=inc', password => 'secret
The correct answer is C. $mesg = $ldap->search( base => 'o=inc', scope => 'sub', filter => '(objectclass=*)');. The correct code snippet for a comprehensive LDAP search to retrieve all entries from a specific base for LDIF export involves using a subtree scope and a general object class filter.
Question
Options
- A$mesg = $ldap->search(base => 'o=inc',);
- B$mesg = $ldap->search( base => 'cn=incadmin,o=inc', scope => 'one', filter => '(objectclass=*)' );
- C$mesg = $ldap->search( base => 'o=inc', scope => 'sub', filter => '(objectclass=*)');
- D$mesg = $ldap->search( base => 'o=inc', recursive => 'yes', filter => '(*)' );
How the community answered
(33 responses)- A6% (2)
- B3% (1)
- C85% (28)
- D6% (2)
Why each option
The correct code snippet for a comprehensive LDAP search to retrieve all entries from a specific base for LDIF export involves using a subtree scope and a general object class filter.
`$mesg = $ldap->search(base => 'o=inc',);` is incomplete as it lacks a scope and filter, making it an ineffective or potentially problematic search for a full export.
Using `scope => 'one'` limits the search to only the immediate children of the base DN, which would not retrieve the entire subtree required for a comprehensive LDIF export.
This snippet correctly specifies `base => 'o=inc'` as the starting point, `scope => 'sub'` to ensure the search includes the base DN and all its subordinates, and `filter => '(objectclass=*)'` to match and retrieve all entries that possess any object class, which is suitable for exporting an entire LDAP branch.
`recursive => 'yes'` is not a standard parameter for the `Net::LDAP` search method; the correct parameter for a recursive search of a subtree is `scope => 'sub'`.
Concept tested: Net::LDAP search parameters for data export
Source: https://metacpan.org/pod/Net::LDAP#search
Topics
Community Discussion
No community discussion yet for this question.