nerdexam
Linux_Foundation

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.

Submitted by yuki_2020· Apr 18, 2026Operation of Running Systems

Question

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'); [YOUR ANSWER GOES HERE] Net::LDAP::LDIF->new( *STDOUT,"w" )- >write( $mesg->entries ); $mesg=$ldap->unbind; Which code snippet contains the correct query?

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)
  • A
    4% (1)
  • B
    9% (2)
  • C
    83% (19)
  • D
    4% (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.

A$mesg = $ldap->search(base => 'o=inc',);

This search is incomplete as it lacks a filter, which is a mandatory component for a valid LDAP search operation.

B$mesg = $ldap->search( base => 'cn=incadmin,o=inc', scope => 'one', filter => '(objectclass=*)' );

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.

C$mesg = $ldap->search( base => 'o=inc', scope => 'sub', filter => '(objectclass=*)');Correct

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.

D$mesg = $ldap->search( base => 'o=inc', recursive => 'yes', filter => '(*)' );

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

#LDAP#LDAP Search#Perl Scripting#Directory Services

Community Discussion

No community discussion yet for this question.

Full LFCS Practice