nerdexam
CompTIA

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.

Shells, Scripting and Data Management

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

(33 responses)
  • A
    6% (2)
  • B
    3% (1)
  • C
    85% (28)
  • D
    6% (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.

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

`$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.

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

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.

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

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.

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

`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

#Perl scripting#LDAP search queries#Net::LDAP#LDAP filters

Community Discussion

No community discussion yet for this question.

Full LX0-104 Practice