LFCS · 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 =>…
The correct answer is C. $mesg = $ldap->search( base => 'o=inc', scope => 'sub', filter => '(objectclass=*)'). The correct Perl LDAP search query utilizes a subtree scope and a universal filter to retrieve all entries under the specified base DN.
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
(23 responses)- A4% (1)
- B9% (2)
- C83% (19)
- D4% (1)
Why each option
The correct Perl LDAP search query utilizes a subtree scope and a universal filter to retrieve all entries under the specified base DN.
This search is incomplete as it lacks a filter, which is a mandatory component for a valid LDAP search operation.
A scope of 'one' would only search one level below the base DN, which is too restrictive for retrieving all entries that are typically written to an LDIF file representing a significant part of a directory.
The `search` method with `base => 'o=inc'` correctly defines the starting point for the search. `scope => 'sub'` ensures that the search includes the base DN and all entries within its subordinates, effectively covering the desired portion of the LDAP directory. The `filter => '(objectclass=*)'` is a standard LDAP filter that matches all entries, as every LDAP object possesses an `objectclass` attribute.
The `recursive => 'yes'` option is not a standard parameter for defining search scope in the `Net::LDAP` module; the correct parameter for a subtree search is `scope => 'sub'`.
Concept tested: Perl Net::LDAP search parameters
Topics
Community Discussion
No community discussion yet for this question.