Net::LDAP(3)

๐Ÿ’– Net::LDAP(3) ๐Ÿ’–

okay bestie, this is the Net::LDAP(3) page from User Contributed Perl Documentation, and it's giving LDAP but make it Perl. no cap, it's a whole collection of modules with main character energy. ๐Ÿ’…

โœจ NAME โœจ

Net::LDAP - Lightweight Directory Access Protocol

๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

Here's the whole vibe in one code block, fr fr โ€” every line exactly as the original serves it:

        use Net::LDAP;

        $ldap = Net::LDAP->new( 'ldap.example.com' )  or  die "$@";

        $mesg = $ldap->bind;                         # anonymous bind

        $mesg->code  and  die $mesg->error;          # check for errors

        $srch = $ldap->search( base   => "c=US",     # perform a search
                               filter => "(&(sn=Barr)(o=Texas Instruments))"
                             );

        $srch->code  and  die $srch->error;          # check for errors

        foreach $entry ($srch->entries) { $entry->dump; }

        $mesg = $ldap->unbind;                       # take down session

        $ldap = Net::LDAP->new( 'ldaps://ldap.example.com' )  or  die "$@";

        # simple bind with DN and password
        $mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
                             password => 'secret'
                           );

        $mesg->code  and  die $mesg->error;          # check for errors

        $result = $ldap->add( 'cn=Barbara Jensen, o=University of Michigan, c=US',
                              attrs => [
                                cn          => ['Barbara Jensen', 'Barbs Jensen'],
                                sn          => 'Jensen',
                                mail        => 'b.jensen@umich.edu',
                                objectclass => ['top', 'person',
                                                'organizationalPerson',
                                                'inetOrgPerson' ],
                              ]
                            );

        $result->code  and  warn "failed to add entry: ", $result->error;

        $mesg = $ldap->unbind;                       # take down session

๐ŸŒธ DESCRIPTION ๐ŸŒธ

So like, Net::LDAP is not one single module โ€” it's a collection of modules that implements a LDAP services API for Perl programs, periodt. The module may be used to search directories or perform maintenance functions such as adding, deleting or modifying entries.

This document assumes that the reader has some knowledge of the LDAP protocol, bestie. It's not starting from zero, iykyk.

๐Ÿ› ๏ธ CONSTRUCTOR ๐Ÿ› ๏ธ

๐Ÿช„ new ( HOST, OPTIONS )

Creates a new Net::LDAP object and opens a connection to the named host.

HOST may be a host name or an IP address. TCP port may be specified after the host name followed by a colon (such as localhost:10389). The default TCP port for LDAP is 389.

You can also specify a URI, such as 'ldaps://127.0.0.1:666' or 'ldapi://%2fvar%2flib%2fldap_sock'. Note that '%2f's in the LDAPI socket path will be translated into '/'. This is to support LDAP query options like base, search etc. although the query part of the URI will be ignored in this context. If port was not specified in the URI, the default is either 389 or 636 for 'LDAP' and 'LDAPS' schemes respectively.

HOST may also be a reference to an array of hosts, host-port pairs or URIs to try. Each will be tried in order until a connection is made. Only when all have failed will the result of undef be returned.

  • port => N โ€” Port to connect to on the remote server. May be overridden by HOST.
  • scheme => 'ldap' | 'ldaps' | 'ldapi' โ€” Connection scheme to use when not using an URI as HOST. (Default: ldap)
  • keepalive => 1 โ€” If given, set the socket's SO_KEEPALIVE option depending on the Boolean value of the option. (Default: use system default) Failures in changing the socket's SO_KEEPALIVE option are ignored.
  • timeout => N โ€” Timeout passed to IO::Socket when connecting the remote server. (Default: 120)
  • multihomed => N โ€” Will be passed to IO::Socket as the MultiHomed parameter when connecting to the remote server.
  • localaddr => HOST โ€” Will be passed to IO::Socket as the LocalAddr parameter, which sets the client's IP address (as opposed to the server's IP address.)
  • debug => N โ€” Set the debug level. See the debug method for details.
  • async => 1 โ€” Perform all operations asynchronously.
  • onerror => 'die' | 'warn' | 'undef' | sub { ... } โ€” In synchronous mode, change what happens when an error is detected.
    • 'die' โ€” Net::LDAP will croak whenever an error is detected.
    • 'warn' โ€” Net::LDAP will warn whenever an error is detected.
    • 'undef' โ€” Net::LDAP will warn whenever an error is detected and -w is in effect. The method that was called will return undef. Note this value is the string 'undef', not the undef value.
    • sub { ... } โ€” The given sub will be called in a scalar context with a single argument, the result message. The value returned will be the return value for the method that was called.
  • version => N โ€” Set the protocol version being used (default is LDAPv3). This is useful if you want to talk to an old server and therefore have to use LDAPv2.
  • raw => REGEX โ€” Use REGEX to denote the names of attributes that are to be considered binary in search results. When this option is given, Net::LDAP converts all values of attributes not matching this REGEX into Perl UTF-8 strings so that the regular Perl operators (pattern matching, ...) can operate as one expects even on strings with international characters. If this option is not given, attribute values are treated as byte strings. Example: raw => qr/(?i:^jpegPhoto|;binary)/
  • inet4 => N โ€” Try to connect to the server using the specified IP protocol only, i.e. either IPv4 or IPv6. If the protocol selected is not supported, connecting will fail. The default is to use any of the two protocols.
  • inet6 => N โ€” Try to connect to the server using the specified IP protocol only, i.e. either IPv4 or IPv6. If the protocol selected is not supported, connecting will fail. The default is to use any of the two protocols.

๐Ÿ’ซ Example

             $ldap = Net::LDAP->new( 'remote.host', async => 1 );

LDAPS connections have some extra valid options, see the start_tls method for details. Note the default port for LDAPS is 636, and the default value for 'sslversion' is the value used as default by IO::Socket::SSL.

For LDAPI connections, HOST is actually the location of a UNIX domain socket to connect to. The default location is '/var/run/ldapi'.

๐Ÿงš METHODS ๐Ÿงš

Each of the following methods take as arguments some number of fixed parameters followed by options, these options are passed in a named fashion, for example

         $mesg = $ldap->bind( "cn=me,o=example", password => "mypasswd");

The return value from these methods is an object derived from the Net::LDAP::Message class. The methods of this class allow you to examine the status of the request.

๐Ÿ—‘๏ธ abandon ( ID, OPTIONS )

Abandon a previously issued request. ID may be a number or an object which is a sub-class of Net::LDAP::Message, returned from a previous method call.

  • control => CONTROL / control => [ CONTROL, ... ] โ€” See CONTROLS below.
  • callback => CALLBACK โ€” See CALLBACKS below.

๐Ÿ’ซ Example

             $res = $ldap->search( @search_args );

             $mesg = $ldap->abandon( $res ); # This could be written as $res->abandon

โž• add ( DN, OPTIONS )

Add a new entry to the directory. DN can be either a Net::LDAP::Entry object or a string.

  • attrs => [ ATTR => VALUE, ... ] โ€” VALUE should be a string if only a single value is wanted, or a reference to an array of strings if multiple values are wanted. This argument is not used if DN is a Net::LDAP::Entry object.
  • control => CONTROL / control => [ CONTROL, ... ] โ€” See CONTROLS below.
  • callback => CALLBACK โ€” See CALLBACKS below.

๐Ÿ’ซ Example

             # $entry is an object of class Net::LDAP::Entry
             $mesg = $ldap->add( $entry );

             $mesg = $ldap->add( $dn,
                                 attrs => [
                                   name  => 'Graham Barr',
                                   attr  => 'value1',
                                   attr  => 'value2',
                                   multi => [qw(value1 value2)]
                                 ]
                               );

๐Ÿ” bind ( DN, OPTIONS )

Bind (log in) to the server. DN is the DN to bind with. An anonymous bind may be done by calling bind without any arguments.

  • control => CONTROL / control => [ CONTROL, ... ] โ€” See CONTROLS below.
  • callback => CALLBACK โ€” See CALLBACKS below.
  • noauth | anonymous => 1 โ€” Bind without any password. The value passed with this option is ignored.
  • password => PASSWORD โ€” Bind with the given password.
  • sasl => SASLOBJ โ€” Bind using a SASL mechanism. The argument given should be a sub-class of Authen::SASL or an Authen::SASL client connection by calling client_new on an Authen::SASL object. If passed an Authen::SASL object then client_new will be called to create a client connection object. The hostname passed by Net::LDAP to client_new can be set using the sasl_host option below. If this is not correct for your environment, consider calling client_new yourself and passing the client connection object as SASLOBJ.
  • sasl_host => SASLHOST โ€” When binding using SASL, allow the hostname used in the SASL communication to differ from the hostname connected to. If SASLHOST evaluates to TRUE, then it is used as the SASL hostname. If it evaluates to FALSE, then the value is determined by calling peerhost on the socket. In older versions of Net::LDAP this was the standard behaviour, but it turned out to cause more trouble than it fixed. When the option is not given, the SASL host name used defaults to the host name / IP address taken from the HOST parameter when connecting.

๐Ÿ’ซ Example

             $mesg = $ldap->bind; # Anonymous bind

             $mesg = $ldap->bind( $dn, password => $password );

             # $sasl is an object of class Authen::SASL
             $mesg = $ldap->bind( $dn, sasl => $sasl, version => 3 );

โš–๏ธ compare ( DN, OPTIONS )

Compare values in an attribute in the entry given by DN on the server. DN may be a string or a Net::LDAP::Entry object.

  • attr => ATTR โ€” The name of the attribute to compare.
  • value => VALUE โ€” The value to compare with.
  • control => CONTROL / control => [ CONTROL, ... ] โ€” See CONTROLS below.
  • callback => CALLBACK โ€” the thing that gets pinged when the compare comes back. See "CALLBACKS" below, bestie.

Example โ€” yes, Graham Barr is a whole recurring character in this manpage, we love a cameo:

  $mesg = $ldap->compare( $dn,
                          attr  => 'cn',
                          value => 'Graham Barr'
                        );

delete ( DN, OPTIONS ) ๐Ÿ—‘๏ธ

Okay so this one yeets the entry given by DN straight off the server. DN can be a plain string OR a Net::LDAP::Entry object โ€” either is fine, girl, we're flexible.

  • control => CONTROL
  • control => [ CONTROL, ... ] โ€” peep "CONTROLS" below for the whole deal.
  • callback => CALLBACK โ€” see "CALLBACKS" below.

Example:

 $mesg = $ldap->delete( $dn );

moddn ( DN, OPTIONS ) โœจ

Renames the entry given by DN on the server. Again, DN can be a string or a Net::LDAP::Entry object โ€” no gatekeeping here.

  • newrdn => RDN โ€” this value should be a new RDN to assign to DN. Like a glow-up name, lowkey.
  • deleteoldrdn => 1 โ€” pass this option if the existing RDN is to be deleted. (Yes, the literal value shown is 1.)
  • newsuperior => NEWDN โ€” if you give this, the value should be the DN of the new superior for DN. Moving out, getting a new manager, main character energy.
  • control => CONTROL
  • control => [ CONTROL, ... ] โ€” see "CONTROLS" below.
  • callback => CALLBACK โ€” see "CALLBACKS" below.

Example:

 $mesg = $ldap->moddn( $dn, newrdn => 'cn=Graham Barr' );

modify ( DN, OPTIONS ) ๐Ÿ’…

Modifies the contents of the entry given by DN on the server โ€” it's giving makeover, fr fr. DN may be a string or a Net::LDAP::Entry object.

  • add => { ATTR => VALUE, ... } โ€” adds more attributes or values to the entry. VALUE should be a string if only a single value is wanted in the attribute, or a reference to an array of strings if multiple values are wanted.
  $mesg = $ldap->modify( $dn,
    add => {
      description => 'List of members',    # Add description attribute
      member      => [
        'cn=member1,ou=people,dc=example,dc=com',    # Add to attribute
        'cn=member2,ou=people,dc=example,dc=com',
      ]
    }
  );
  • delete => [ ATTR, ... ] โ€” deletes complete attributes from the entry. Whole-attribute eviction notice. ๐Ÿชฆ
  $mesg = $ldap->modify( $dn,
    delete => ['member','description'] # Delete attributes
  );
  • delete => { ATTR => VALUE, ... } โ€” deletes individual values from an attribute. VALUE should be a string if only a single value is being deleted from the attribute, or a reference to an array of strings if multiple values are being deleted.

โš ๏ธ Heads up: if VALUE is a reference to an empty array, or if all existing values of the attribute are being deleted, then the attribute will be deleted from the entry. So like, careful โ€” that's the whole attribute gone, not just the values.

  $mesg = $ldap->modify( $dn,
    delete => {
      description => 'List of members',
      member      => [
        'cn=member1,ou=people,dc=example,dc=com',    # Remove members
        'cn=member2,ou=people,dc=example,dc=com',
      ],
      seeAlso => [],   # Remove attribute
    }
  );
  • replace => { ATTR => VALUE, ... } โ€” replaces any existing values in each given attribute with VALUE. VALUE should be a string if only a single value is wanted in the attribute, or a reference to an array of strings if multiple values are wanted. A reference to an empty array will remove the entire attribute. If the attribute does not already exist in the entry, it will be created. Out with the old, in with the new, periodt. ๐Ÿ”ฅ
  $mesg = $ldap->modify( $dn,
    replace => {
      description => 'New List of members', # Change the description
      member      => [ # Replace whole list with these
        'cn=member1,ou=people,dc=example,dc=com',
        'cn=member2,ou=people,dc=example,dc=com',
      ],
      seeAlso => [],   # Remove attribute
    }
  );
  • increment => { ATTR => VALUE, ... } โ€” atomically increments the existing value in each given attribute by the provided VALUE. The attributes need to have integer syntax, or be otherwise "incrementable". ๐Ÿงฎ
Real talk though: this will only work if the server advertises support for LDAP_FEATURE_MODIFY_INCREMENT. Use supported_feature in Net::LDAP::RootDSE to check this โ€” vibe check your server first, bestie.
  $mesg = $ldap->modify( $dn,
    increment => {
      uidNumber => 1 # increment uidNumber by 1
    }
  );
  • changes => [ OP => [ ATTR => VALUE ], ... ] โ€” this is the alternative to add, delete, replace and increment where the whole operation can be given in a single argument. OP should be add, delete, replace or increment. VALUE should be either a string or a reference to an array of strings, as before.

Use this form if you want to control the order in which the operations will be performed. Very much the "I want it done my way" option. ๐Ÿ‘‘

  $mesg = $ldap->modify( $dn,
    changes => [
      add => [
        description => 'A description',
        member      => $newMember,
      ],
      delete => [
        seeAlso => [],
      ],
      add => [
        anotherAttribute => $value,
      ],
    ]
  );
  • control => CONTROL
  • control => [ CONTROL, ... ] โ€” see "CONTROLS" below.
  • callback => CALLBACK โ€” see "CALLBACKS" below.

Examples (a whole lil buffet of them, enjoy ๐Ÿ“):

 $mesg = $ldap->modify( $dn, add => { sn => 'Barr' } );

 $mesg = $ldap->modify( $dn, delete => [qw(faxNumber)] );

 $mesg = $ldap->modify( $dn, delete => { 'telephoneNumber' => '911' } );

 $mesg = $ldap->modify( $dn, replace => { 'mail' => 'gbarr@pobox.com' } );

 $mesg = $ldap->modify( $dn,
                        changes => [
                            # add sn=Barr
                          add     => [ sn => 'Barr' ],
                            # delete all fax numbers
                          delete  => [ faxNumber => []],
                            # delete phone number 911
                          delete  => [ telephoneNumber => ['911']],
                            # change email address
                          replace => [ mail => 'gbarr@pobox.com']
                        ]
                      );

search ( OPTIONS ) ๐Ÿ”

Searches the directory using a given filter. This can be used to read attributes from a single entry, from entries immediately below a particular entry, or a whole subtree of entries. It's giving "I contain multitudes" energy.

The result is an object of class Net::LDAP::Search. That's your prize. ๐ŸŽ€

  • base => DN โ€” the DN that is the base object entry relative to which the search is to be performed. Your starting point, your home base, your main character location.
  • scope => 'base' | 'one' | 'sub' | 'subtree' | 'children' โ€” by default the search is performed on the whole tree below the specified base object. This maybe changed by specifying a scope parameter with one of the following values:
    • base โ€” search only the base object. Just the one. Solo.
    • one โ€” search the entries immediately below the base object. The direct children only, no plus-ones.
    • sub
    • subtree โ€” search the whole tree below (and including) the base object. This is the default. Big sweep energy.
    • children โ€” search the whole subtree below the base object, excluding the base object itself.
Note: children scope requires the LDAPv3 subordinate feature extension. Don't come for it if your server doesn't support it. ๐Ÿ˜ญ
  • deref => 'never' | 'search' | 'find' | 'always' โ€” by default aliases are dereferenced to locate the base object for the search, but not when searching subordinates of the base object. This may be changed by specifying a deref parameter with one of the following values:
    • never โ€” do not dereference aliases in searching or in locating the base object of the search. Absolutely not, we don't know her.
    • search โ€” dereference aliases in subordinates of the base object in searching, but not in locating the base object of the search.
    • find โ€” dereference aliases in locating the base object of the search, but not when searching subordinates of the base object. This is the default.
    • always โ€” dereference aliases both in searching and in locating the base object of the search. All of it. Every alias. Greedy in a slay way.
  • sizelimit => N โ€” a sizelimit that restricts the maximum number of entries to be returned as a result of the search. A value of 0, and the default, means that no restriction is requested. Servers may enforce a maximum number of entries to return โ€” so like, don't assume you're getting everything.
  • timelimit => N โ€” a timelimit that restricts the maximum time (in seconds) allowed for a search. A value of 0 (the default), means that no timelimit will be requested.
  • typesonly => 1 โ€” only attribute types (no values) should be returned. Normally attribute types and values are returned. Mystery mode, values redacted. ๐Ÿ™ˆ
  • filter => FILTER โ€” a filter that defines the conditions an entry in the directory must meet in order for it to be returned by the search. This may be a string or a Net::LDAP::Filter object.
Security moment, bestie: values inside filters may need to be escaped to avoid security problems; see Net::LDAP::Filter for a definition of the filter format, including the escaping rules. Do not skip this. Fr fr.
  • attrs => [ ATTR, ... ] โ€” a list of attributes to be returned for each entry that matches the search filter.

If not specified, then the server will return the attributes that are specified as accessible by default given your bind credentials.

Certain additional attributes such as createTimestamp and other operational attributes may also be available for the asking:

  $mesg = $ldap->search( ... ,
                         attrs => ['createTimestamp']
                       );

To retrieve the default attributes and additional ones, use '*'.

  $mesg = $ldap->search( ... ,
                         attrs => ['*', 'createTimestamp']
                       );

To retrieve no attributes (the server only returns the DNs of matching entries), use '1.1':

  $mesg = $ldap->search( ... ,
                         attrs => ['1.1']
                       );

okay that's the tea so far โ€” there's more coming, obviously, we're not even done. keep reading, bestie ๐Ÿฆ‹

  • control => CONTROL
  • control => [ CONTROL, ... ] โ€” peep the "CONTROLS" section down below bestie ๐Ÿ’…
  • callback => CALLBACK โ€” and this one's explained in "CALLBACKS", keep scrolling โœจ
  • raw => REGEX โ€” okay so this REGEX is how you tell Net::LDAP which attribute names should be treated as binary when your search results come back ๐ŸŽ€

When you pass this, Net::LDAP takes every attribute value whose name does not match the REGEX and converts it into a Perl UTF-8 string, so that normal Perl operators (pattern matching, that whole crew) behave like you'd expect, even when the strings are full of international characters ๐ŸŒโœจ

If you don't pass it, attribute values get treated as byte strings. no conversion, no nothing ๐Ÿซถ

Whatever value you give here overwrites the value inherited from the constructor. it wins, periodt ๐Ÿ‘‘

Example: raw => qr/(?i:^jpegPhoto|;binary)/

Example

 $mesg = $ldap->search(
                        base   => $base_dn,
                        scope  => 'sub',
                        filter => '(|(objectclass=rfc822mailgroup)(sn=jones))'
                      );

 Net::LDAP::LDIF->new( \*STDOUT,"w" )->write( $mesg->entries );

๐Ÿ’– start_tls ( OPTIONS ) ๐Ÿ’–

Calling this method upgrades your existing connection to Transport Layer Security (TLS), which is the encrypted-connection glow-up ๐Ÿ”โœจ It's only possible if your connection is using LDAPv3, and the server has to actually advertise support for LDAP_EXTENSION_START_TLS. Wanna check first? Use "supported_extension" in Net::LDAP::RootDSE, iykyk ๐ŸŒธ

  • verify => 'none' | 'optional' | 'require' โ€” how you wanna verify the server's certificate, bestie:
    • none โ€” server may hand over a certificate but it will not be checked, which lowkey means you could be connected to the totally wrong server ๐Ÿ˜ญ
    • optional โ€” verify only when the server actually offers a certificate
    • require โ€” server must provide a certificate, and it must be valid. no certificate, no vibes ๐Ÿ’…
Heads up: if you set verify to optional or require, you also have to set either cafile or capath. The most secure option is require ๐Ÿ‘‘
  • sslversion => 'sslv2' | 'sslv3' | 'sslv23' | 'tlsv1' | 'tlsv1_1' | 'tlsv1_2' โ€” this picks which version of the SSL/TLS protocol to use. Default is whatever value IO::Socket::SSL uses as its default ๐ŸŒˆ

See "SSL_version" in IO::Socket::SSL for the full tea ๐Ÿซ–

  • sslserver => SSLHOST โ€” lets you change the server name used for certificate hostname verification, for when the target hostname doesn't match the LDAP server's certificate. Not given? It defaults to the name of the HOST you connected to ๐Ÿฆ‹

See "SSL_verifycn_name" in IO::Socket::SSL for more details.

  • ciphers => CIPHERS โ€” specify which subset of cipher suites are permissible for this connection, using the standard OpenSSL string format โœจ Default behavior is to just let the underlying cryptographic library make the decision, main character energy, it's got this ๐Ÿ’œ
  • clientcert => '/path/to/cert.pem'
  • clientkey => '/path/to/key.pem'
  • keydecrypt => sub { ... }

So if you want the client to offer a certificate to the server for SSL authentication (which is not the same thing as the LDAP Bind operation, don't get it twisted ๐Ÿ™ˆ), set clientcert to the user's certificate file and clientkey to the user's private key file. Both files must be in PEM format ๐ŸŽ€

If that private key is encrypted (highly recommended, fr fr), then keydecrypt should be a subroutine that returns the decrypting key. Like this:

 $ldap = Net::LDAP->new( 'myhost.example.com', version => 3 );
 $mesg = $ldap->start_tls(
                           verify => 'require',
                           clientcert => 'mycert.pem',
                           clientkey => 'mykey.pem',
                           keydecrypt => sub { 'secret'; },
                           capath => '/usr/local/cacerts/'
                         );
  • capath => '/path/to/servercerts/'
  • cafile => '/path/to/servercert.pem'

When you're verifying the server's certificate, set capath to the pathname of the directory containing the CA certificates, or set cafile to the filename containing the certificate of the CA who signed the server's certificate. All these certificates must be in PEM format ๐Ÿงš

That capath directory has to contain certificates named using the hash value of the certificates' subject names. To generate those names, use OpenSSL like this on Unix:

 ln -s cacert.pem `openssl x509 -hash -noout < cacert.pem`.0

(assuming the certificate of the CA lives in cacert.pem, obviously ๐Ÿ’…)

  • checkcrl => 1 โ€” if capath has been configured, then it'll also be searched for certificate revocation lists (CRLs) when verifying the server's certificate ๐Ÿ‘€ The CRLs' names must follow the form hash.rnum, where hash is the hash over the issuer's DN and num is a number starting with 0.

See "SSL_check_crl" in IO::Socket::SSL for further information ๐ŸŒŸ


โœจ unbind ( ) โœจ

unbind takes zero parameters and unbinds you from the server, bye bestie ๐Ÿ‘‹ Some servers may let you re-bind or do other stuff after unbinding. And if you just wanna switch to a different set of credentials while keeping the same connection โ€” re-binding with another DN and password without unbinding โ€” that generally works too ๐ŸŒธ

Example

 $mesg = $ldap->unbind;

๐ŸŽ€ done ( ) ๐ŸŽ€

A convenience alias for unbind(), named after the clean-up method of Net::LDAP::LDIF. cute little callback name, love that for us ๐Ÿซถ


The following methods are for convenience, and do not return Net::LDAP::Message objects. so like, don't go looking for a $mesg okay? ๐Ÿ˜Œ

๐Ÿ’œ async ( VALUE ) ๐Ÿ’œ

If VALUE is given, the async mode gets set. The previous value is returned. The value is true if LDAP operations are being performed asynchronously โœจ

๐ŸŒˆ certificate ( ) ๐ŸŒˆ

Returns an X509_Certificate object containing the server's certificate. Peep the IO::Socket::SSL documentation for info about this class ๐Ÿฆ‹

For example, to get the subject name (in a peculiar OpenSSL-specific format, different from RFC 1779 and RFC 4514) from the server's certificate, do this:

 print "Subject DN: " . $ldaps->certificate->subject_name . "\n";

โญ cipher ( ) โญ

Returns the cipher mode being used by the connection, in the string format used by OpenSSL. encrypted and slaying ๐Ÿ”

๐Ÿ”ฅ debug ( VALUE ) ๐Ÿ”ฅ

If VALUE is given, the debug bit-value gets set. The previous value is returned. Debug output goes to STDERR. The bits of this value are:

1   Show outgoing packets (using asn_hexdump).
2   Show incoming packets (using asn_hexdump).
4   Show outgoing packets (using asn_dump).
8   Show incoming packets (using asn_dump).

The default value is 0. quiet and mysterious, we respect it ๐Ÿ™ˆ

๐Ÿ“ disconnect ( ) ๐Ÿ“

Disconnect from the server. that's it, that's the method ๐Ÿ’€

๐Ÿ‘‘ root_dse ( OPTIONS ) ๐Ÿ‘‘

The root_dse method retrieves cached information from the server's rootDSE ๐ŸŒธ

  • attrs => [ ATTR, ... ] โ€” a reference to a list of attributes to be returned. If you don't specify it, then these attributes get requested by default:
 subschemaSubentry
 namingContexts
 altServer
 supportedExtension
 supportedFeatures
 supportedControl
 supportedSASLMechanisms
 supportedLDAPVersion

The result is an object of class Net::LDAP::RootDSE โœจ

Example

 my $root = $ldap->root_dse;
 # get naming Context
 $root->get_value( 'namingContexts', asref => 1 );
 # get supported LDAP versions
 $root->supported_version;
Real talk: the root DSE can change in certain circumstances โ€” for instance when you change the connection using start_tls โ€” so you should always use the root_dse method to get the most up-to-date copy of the root DSE. no stale copies, bestie ๐Ÿ’…

๐Ÿงš schema ( OPTIONS ) ๐Ÿงš

Read schema information from the server ๐Ÿ“–

The result is an object of class Net::LDAP::Schema. Go read that documentation for more info about the methods you can run on this object ๐Ÿ’œ

  • dn => DN โ€” if a DN is supplied, it becomes the base object entry from which the search for schema information is conducted. If no DN is supplied, the base object entry gets determined from the rootDSE entry ๐ŸŒŸ

Example

 my $schema = $ldap->schema;
 # get objectClasses
 @ocs = $schema->all_objectclasses;
 # Get the attributes
 @atts = $schema->all_attributes;

๐Ÿ’… sasl ( ) ๐Ÿ’…

Returns the Authen::SASL object associated with the LDAP object, or undef if there isn't one. sometimes the answer is just nothing, and that's okay ๐Ÿ˜ญ

๐ŸŒธ socket ( OPTIONS ) ๐ŸŒธ

Returns the underlying socket object being used ๐Ÿ”Œ

The exact object type returned depends on whether SASL layers are established. Without SASL layers, the result is always an IO::Socket object; with SASL layers, the outcome depends on the options you give:

  • sasl_layer => FLAG โ€” this option is only relevant if SASL layers are established ๐Ÿ‘€

If it's missing or set to a TRUE value, then the SASL layer handle is returned. Depending on the SASL library used, the object returned is not necessarily an IO::Socket object ๐Ÿฆ‹

If it exists but is set to a value evaluating to FALSE, then the base IO::Socket object underneath the SASL layer is returned. the real one, the one underneath ๐Ÿซถ

๐ŸŽ€ host ( ) ๐ŸŽ€

Returns the host to which the connection was established. For LDAPI connections, the socket path is returned โœจ

๐ŸŒˆ port ( ) ๐ŸŒˆ

Returns the port connected to, or undef in case of LDAPI connections ๐Ÿ’œ

โญ uri ( ) โญ

Returns the URI connected to ๐ŸŒŸ

Since the value returned is that element of the constructor's HOST argument with which the connection was established, this may or may not be a legal URI. so like, don't come for her if it's weird ๐Ÿ’…

๐Ÿ”ฅ scheme ( ) ๐Ÿ”ฅ

Returns the scheme of the connection. One of ldap, ldaps or ldapi. pick your fighter ๐Ÿ‘‘

๐Ÿฆ‹ sync ( MESG ) ๐Ÿฆ‹

Wait for a given MESG request to be completed by the server โณ If no MESG is given, then wait for all outstanding requests to be completed. patience is a virtue bestie โœจ

Returns an error code defined in Net::LDAP::Constant.

๐Ÿ’œ process ( MESG ) ๐Ÿ’œ

Process any messages that the server has sent, but do not block ๐Ÿšซโณ If MESG is specified, then return as soon as MESG has been processed.

Returns an error code defined in Net::LDAP::Constant ๐ŸŒธ

Okay bestie, final method snack before we move on:

  • version ( ) โ€” returns the version of the LDAP protocol that is being used. ๐Ÿ’…

๐ŸŽ›๏ธ CONTROLS ๐ŸŽ›๏ธ

Many of the methods described above accept a control option โ€” it's literally how you pass controls to the server as described in LDAPv3. Slay. โœจ

A control is a reference to a HASH and should contain the three elements below. If any of the controls are blessed then the method to_asn will be called, and it should return a reference to a HASH containing the three elements described below. ๐Ÿซถ

For most purposes Net::LDAP::Control objects are the easiest way to generate controls. Iconic. ๐Ÿ‘‘

  • type => OID โ€” this element must be present, and it's the name of the type of control being requested. ๐ŸŽ€
  • critical => FLAG โ€” critical is optional and should be a Boolean value; if it is not specified then it is assumed to be false. ๐Ÿฆ‹
  • value => VALUE โ€” if the control being requested requires a value, then this element should hold the value for the server. ๐Ÿ’–

๐Ÿ“ฌ CALLBACKS ๐Ÿ“ฌ

Most of the above commands accept a callback option. This option should be a reference to a subroutine, and that subroutine will be called for each packet received from the server as a response to the request sent. Group-chat ping energy. ๐Ÿ˜ญ

When the subroutine is called, the first argument will be the Net::LDAP::Message object which was returned from the method.

If the request is a search then multiple packets can be received from the server. Each entry is received as a separate packet. For each of these the subroutine will be called with a Net::LDAP::Entry object as the second argument. ๐ŸŒธ

During a search the server may also send a list of references. When such a list is received then the subroutine will be called with a Net::LDAP::Reference object as the second argument. ๐Ÿฆ‹

๐Ÿšจ LDAP ERROR CODES ๐Ÿšจ

Net::LDAP also exports constants for the error codes that can be received from the server, see Net::LDAP::Constant. Errors but make it organized. ๐Ÿ’€

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

  • Net::LDAP::Constant
  • Net::LDAP::Control
  • Net::LDAP::Entry
  • Net::LDAP::Filter
  • Net::LDAP::Message
  • Net::LDAP::Reference
  • Net::LDAP::Search
  • Net::LDAP::RFC

The homepage for the perl-ldap modules can be found at http://ldap.perl.org/. ๐Ÿซถ

๐Ÿ‘‘ ACKNOWLEDGEMENTS ๐Ÿ‘‘

This document is based on a document originally written by Russell Fulton (r.fulton@auckland.ac.nz). ๐Ÿ’–

Chris Ridd (chris.ridd@isode.com) for the many hours spent testing and contribution of the ldap* command line utilities. ๐ŸŒŸ

๐Ÿซถ MAILING LIST ๐Ÿซถ

A discussion mailing list is hosted by the Perl Foundation at perl-ldap@perl.org. No subscription is necessary! ๐ŸŽ€

๐Ÿ˜ญ BUGS ๐Ÿ˜ญ

We hope you do not find any, but if you do please report them to the mailing list.

If you have a patch, please send it as an attachment to the mailing list. ๐Ÿซถ

๐Ÿ’œ AUTHOR ๐Ÿ’œ

Graham Barr (gbarr@pobox.com)

Copyright (c) 1997-2004 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


That's the whole page, bestie! ๐ŸŽ€ This one is perl v5.42.0, dated 2024-01-02, and it's Net::LDAP(3) โ€” mwah ๐Ÿ’‹โœจ

๐Ÿ“ฆ where this page comes from