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 byHOST.scheme => 'ldap' | 'ldaps' | 'ldapi'โ Connection scheme to use when not using an URI asHOST. (Default:ldap)keepalive => 1โ If given, set the socket'sSO_KEEPALIVEoption depending on the Boolean value of the option. (Default: use system default) Failures in changing the socket'sSO_KEEPALIVEoption are ignored.timeout => Nโ Timeout passed toIO::Socketwhen connecting the remote server. (Default:120)multihomed => Nโ Will be passed toIO::Socketas theMultiHomedparameter when connecting to the remote server.localaddr => HOSTโ Will be passed toIO::Socketas theLocalAddrparameter, which sets the client's IP address (as opposed to the server's IP address.)debug => Nโ Set the debug level. See thedebugmethod 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::LDAPwill croak whenever an error is detected.'warn'โNet::LDAPwill warn whenever an error is detected.'undef'โNet::LDAPwill warn whenever an error is detected and-wis in effect. The method that was called will returnundef. Note this value is the string'undef', not theundefvalue.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โ UseREGEXto denote the names of attributes that are to be considered binary in search results. When this option is given,Net::LDAPconverts all values of attributes not matching thisREGEXinto 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, ... ]โ SeeCONTROLSbelow.callback => CALLBACKโ SeeCALLBACKSbelow.
๐ซ 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, ... ]โVALUEshould 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 ifDNis aNet::LDAP::Entryobject.control => CONTROL/control => [ CONTROL, ... ]โ SeeCONTROLSbelow.callback => CALLBACKโ SeeCALLBACKSbelow.
๐ซ 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, ... ]โ SeeCONTROLSbelow.callback => CALLBACKโ SeeCALLBACKSbelow.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 ofAuthen::SASLor anAuthen::SASLclient connection by callingclient_newon anAuthen::SASLobject. If passed anAuthen::SASLobject thenclient_newwill be called to create a client connection object. The hostname passed byNet::LDAPtoclient_newcan be set using thesasl_hostoption below. If this is not correct for your environment, consider callingclient_newyourself and passing the client connection object asSASLOBJ.sasl_host => SASLHOSTโ When binding using SASL, allow the hostname used in the SASL communication to differ from the hostname connected to. IfSASLHOSTevaluates to TRUE, then it is used as the SASL hostname. If it evaluates to FALSE, then the value is determined by callingpeerhoston the socket. In older versions ofNet::LDAPthis 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 theHOSTparameter 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, ... ]โ SeeCONTROLSbelow.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=> CONTROLcontrol=> [ 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 is1.)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=> CONTROLcontrol=> [ 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 forLDAP_FEATURE_MODIFY_INCREMENT. Usesupported_featurein 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 toadd,delete,replaceandincrementwhere the whole operation can be given in a single argument. OP should beadd,delete,replaceorincrement. 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=> CONTROLcontrol=> [ 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 ascopeparameter 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.subsubtreeโ 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 aderefparameter 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 of0, 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 of0(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 aNet::LDAP::Filterobject.
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 => CONTROLcontrol => [ 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 certificaterequireโ server must provide a certificate, and it must be valid. no certificate, no vibes ๐
Heads up: if you setverifytooptionalorrequire, you also have to set eithercafileorcapath. The most secure option isrequire๐
sslversion => 'sslv2' | 'sslv3' | 'sslv23' | 'tlsv1' | 'tlsv1_1' | 'tlsv1_2'โ this picks which version of the SSL/TLS protocol to use. Default is whatever valueIO::Socket::SSLuses 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 theHOSTyou 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โ ifcapathhas 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 formhash.rnum, wherehashis the hash over the issuer's DN andnumis a number starting with0.
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 usingstart_tlsโ so you should always use theroot_dsemethod 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โcriticalis optional and should be a Boolean value; if it is not specified then it is assumed to befalse. ๐ฆ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::ConstantNet::LDAP::ControlNet::LDAP::EntryNet::LDAP::FilterNet::LDAP::MessageNet::LDAP::ReferenceNet::LDAP::SearchNet::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 ๐
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
- opensuse-leap 16.0: perl-ldap 0.68-160000.2.2 ยท Artistic-1.0 OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms