Net::LDAP::Entry(3) | User Contributed Perl Documentation | Net::LDAP::Entry(3) |
Net::LDAP::Entry - An LDAP entry object
use Net::LDAP; $ldap = Net::LDAP->new ( $host ); $mesg = $ldap->search ( @search_args ); my $max = $mesg->count; for ( $i = 0 ; $i < $max ; $i++ ) { my $entry = $mesg->entry ( $i ); foreach my $attr ( $entry->attributes ) { print join( "\n ", $attr, $entry->get_value( $attr ) ), "\n"; } } # or use Net::LDAP::Entry; $entry = Net::LDAP::Entry->new; $entry->dn($dn); $entry->add ( attr1 => 'value1', attr2 => [ qw(value1 value2) ] ); $entry->delete ( 'unwanted' ); $entry->replace ( attr1 => 'newvalue', attr2 => [ qw(new values) ] ); $entry->update ( $ldap ); # update directory server $entry2 = $entry->clone; # copies entry # new alternate syntax $entry = Net::LDAP::Entry->new ( $dn, attr1 => 'value1', attr2 => [ qw(value1 value2) ] )->add( attr3 => 'value' )->update( $ldap );
The Net::LDAP::Entry object represents a single entry in the directory. It is a container for attribute-value pairs.
A Net::LDAP::Entry object can be used in two situations. The first and probably most common use is in the result of a search to the directory server.
The other is where a new object is created locally and then a single command is sent to the directory server to add, modify or replace an entry. Entries for this purpose can also be created by reading an LDIF file with the Net::LDAP::LDIF module.
Net::LDAP::Entry->new() # or Net::LDAP::Entry->new( $dn ) # or Net::LDAP::Entry->new( $dn , objectClass => [qw( top posixAccount )] , uid => 'admin' )
$entry->add ( 'sn' => 'Barr' ); $entry->add ( 'street' => [ '1 some road','nowhere' ] );
NOTE: these changes are local to the client and will not appear on the directory server until the "update" method is called. As "add" returns the entry, you can write something like.
$entry->add ( 'sn' => 'Barr' )->update( $ldap );
name: Graham Barr name;en-us: Bob jpeg;binary: **binary data**
then
@values = $entry->attributes; print "default: @values\n"; @values = $entry->attributes ( nooptions => 1 ); print "nooptions: @values\n";
will output
default: name name;en-us jpeg;binary nooptions: name jpeg
Possible values for "TYPE" are
$entry->delete->update( $ldap )
$entry->delete ( 'mail' => [ 'foo.bar@example.com' ] ); $entry->delete ( 'description' => [ ], 'streetAddress' => [ ] );
NOTE: these changes are local to the client and will not appear on the directory server until the "update" method is called.
NOTE: these changes are local to the client and will not appear on the directory server until the "update" method is called.
This method is intended for debugging purposes and does not treat binary attributes specially. It also does not deal properly with entries resulting from LDIF change records.
See Net::LDAP::LDIF on how to generate LDIF output.
If "FILEHANDLE" is omitted "STDOUT" is used by default.
name: Graham Barr name;en-us: Bob
Then a get for attribute "name" with alloptions set to a true value
$ref = $entry->get_value ( 'name', alloptions => 1 );
will return a hash reference that would be like
{ '' => [ 'Graham Barr' ], ';en-us' => [ 'Bob' ] }
If alloptions is not set or is set to false only the attribute values for the exactly matching name are returned.
$scalar = $entry->get_value ( 'name' );
$scalar will be the first value for the "name" attribute, or "undef" if the entry does not contain a "name" attribute.
$ref = $entry->get_value ( 'name', asref => 1 );
$ref will be a reference to an array, which will have all the values for the "name" attribute. If the entry does not have an attribute called "name" then $ref will be "undef".
NOTE: In the interest of performance the array references returned by "get_value" are references to structures held inside the entry object. These values and their contents should NOT be modified directly.
NOTE: these changes are local to the client and will not appear on the directory server until the "update" method is called.
This method can also be used to modify the DN of the entry on the server, by specifying moddn or modrdn as the changetype, and setting the entry attributes newrdn, deleteoldrdn, and (optionally) newsuperior.
"CLIENT" is a "Net::LDAP" object where the update will be sent to.
"OPTIONS" may be options to the "Net::LDAP" actions on CLIENT corresponding to the entry's changetype.
The result will be an object of type Net::LDAP::Message as returned by the add, modify or delete method called on CLIENT.
Alternatively "CLIENT" can also be a "Net::LDAP::LDIF" object, that must be an LDIF file opened for writing.
In this case, the entry, together with any "OPTIONS" is passed as arguments to the "write_entry" method of the "CLIENT" object.
Here too, the result is an object class "Net::LDAP::Message". On error, the error code is "LDAP_OTHER" with the LDIF error message in the error text.
Net::LDAP, Net::LDAP::LDIF
Graham Barr <gbarr@pobox.com>.
Please report any bugs, or post any suggestions, to the perl-ldap mailing list <perl-ldap@perl.org>.
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.
2019-04-16 | perl v5.34.0 |