/usr/share/perl5/Net/LDAP.pod is in libnet-ldap-perl 1:0.6500+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 | =head1 NAME
Net::LDAP - Lightweight Directory Access Protocol
=head1 SYNOPSIS
use Net::LDAP;
$ldap = Net::LDAP->new( 'ldap.bigfoot.com' ) or die "$@";
$mesg = $ldap->bind ; # an anonymous bind
$mesg = $ldap->search( # perform a search
base => "c=US",
filter => "(&(sn=Barr)(o=Texas Instruments))"
);
$mesg->code && die $mesg->error;
foreach $entry ($mesg->entries) { $entry->dump; }
$mesg = $ldap->unbind; # take down session
$ldap = Net::LDAP->new( 'ldap.umich.edu' );
# bind to a directory with dn and password
$mesg = $ldap->bind( 'cn=root, o=University of Michigan, c=us',
password => 'secret'
);
$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 && warn "failed to add entry: ", $result->error ;
$mesg = $ldap->unbind; # take down session
=head1 DESCRIPTION
B<Net::LDAP> is a collection of modules that implements a LDAP
services API for Perl programs. 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.
=head1 CONSTRUCTOR
=over 4
=item new ( HOST, OPTIONS )
Creates a new B<Net::LDAP> object and opens a connection to the named host.
C<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.
C<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 C<undef> be
returned.
=over 4
=item port =E<gt> N
Port to connect to on the remote server. May be overridden by C<HOST>.
=item scheme =E<gt> 'ldap' | 'ldaps' | 'ldapi'
Connection scheme to use when not using an URI as C<HOST>.
(Default: ldap)
=item keepalive =E<gt> 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.
=item timeout =E<gt> N
Timeout passed to L<IO::Socket> when connecting the remote server.
(Default: 120)
=item multihomed =E<gt> N
Will be passed to L<IO::Socket> as the C<MultiHomed> parameter
when connecting to the remote server
=item localaddr =E<gt> HOST
Will be passed to L<IO::Socket> as the C<LocalAddr> parameter, which
sets the client's IP address (as opposed to the server's IP address.)
=item debug =E<gt> N
Set the debug level. See the L<debug|/debug> method for details.
=item async =E<gt> 1
Perform all operations asynchronously.
=item onerror =E<gt> 'die' | 'warn' | undef | sub { ... }
In synchronous mode, change what happens when an error is detected.
=over 4
=item 'die'
Net::LDAP will croak whenever an error is detected.
=item 'warn'
Net::LDAP will warn whenever an error is detected.
=item undef
Net::LDAP will warn whenever an error is detected and C<-w> is in
effect. The method that was called will return C<undef>.
=item 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.
=back
=item version =E<gt> 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.
=item raw =E<gt> 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 =E<gt> qr/(?i:^jpegPhoto|;binary)/
=item inet4 =E<gt> N
=item inet6 =E<gt> 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.
=back
B<Example>
$ldap = Net::LDAP->new( 'remote.host', async => 1 );
LDAPS connections have some extra valid options, see the
L<start_tls|/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 L<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'.
=back
=head1 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
L<Net::LDAP::Message> class. The methods of this class allow
you to examine the status of the request.
=over 4
=item abandon ( ID, OPTIONS )
Abandon a previously issued request. C<ID> may be a number or an
object which is a sub-class of L<Net::LDAP::Message>, returned from a
previous method call.
=over 4
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below
=back
B<Example>
$res = $ldap->search( @search_args );
$mesg = $ldap->abandon( $res ); # This could be written as $res->abandon
=item add ( DN, OPTIONS )
Add a new entry to the directory. C<DN> can be either a
L<Net::LDAP::Entry> object or a string.
=over 4
=item attrs =E<gt> [ ATTR =E<gt> VALUE, ... ]
C<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 C<DN> is a L<Net::LDAP::Entry> object.
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below
=back
B<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)]
]
);
=item bind ( DN, OPTIONS )
Bind (log in) to the server. C<DN> is the DN to bind with. An
anonymous bind may be done by calling bind without any arguments.
=over 4
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below
=item noauth | anonymous =E<gt> 1
Bind without any password. The value passed with this option is ignored.
=item password =E<gt> PASSWORD
Bind with the given password.
=item sasl =E<gt> SASLOBJ
Bind using a SASL mechanism. The argument given should be a sub-class
of L<Authen::SASL> or an L<Authen::SASL> client connection by calling
C<client_new> on an L<Authen::SASL> object.
If passed an L<Authen::SASL> object then C<client_new> will be
called to create a client connection object.
The hostname passed by C<Net::LDAP> to C<client_new> can be set using
the C<sasl_host> option below.
If this is not correct for your environment, consider calling C<client_new>
yourself and passing the client connection object as C<SASLOBJ>.
=item sasl_host =E<gt> SASLHOST
When binding using SASL, allow the hostname used in the SASL
communication to differ from the hostname connected to.
If C<SASLHOST> evaluates to TRUE, then it is used as the SASL hostname.
If it evaluates to FALSE, then the value is determined by
calling C<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 C<HOST> parameter when connecting.
=back
B<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 );
=item compare ( DN, OPTIONS )
Compare values in an attribute in the entry given by C<DN> on the
server. C<DN> may be a string or a L<Net::LDAP::Entry> object.
=over 4
=item attr =E<gt> ATTR
The name of the attribute to compare.
=item value =E<gt> VALUE
The value to compare with.
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below.
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below.
=back
B<Example>
$mesg = $ldap->compare( $dn,
attr => 'cn',
value => 'Graham Barr'
);
=item delete ( DN, OPTIONS )
Delete the entry given by C<DN> from the server. C<DN> may be a string
or a L<Net::LDAP::Entry> object.
=over 4
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below.
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below.
=back
B<Example>
$mesg = $ldap->delete( $dn );
=item moddn ( DN, OPTIONS )
Rename the entry given by C<DN> on the server. C<DN> may be a string
or a L<Net::LDAP::Entry> object.
=over 4
=item newrdn =E<gt> RDN
This value should be a new RDN to assign to C<DN>.
=item deleteoldrdn =E<gt> 1
This option should be passed if the existing RDN is to be deleted.
=item newsuperior =E<gt> NEWDN
If given this value should be the DN of the new superior for C<DN>.
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below.
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below.
=back
B<Example>
$mesg = $ldap->moddn( $dn, newrdn => 'cn=Graham Barr' );
=item modify ( DN, OPTIONS )
Modify the contents of the entry given by C<DN> on the server. C<DN>
may be a string or a L<Net::LDAP::Entry> object.
=over 4
=item add =E<gt> { ATTR =E<gt> VALUE, ... }
Add more attributes or values to the entry. C<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',
]
}
);
=item delete =E<gt> [ ATTR, ... ]
Delete complete attributes from the entry.
$mesg = $ldap->modify( $dn,
delete => ['member','description'] # Delete attributes
);
=item delete =E<gt> { ATTR =E<gt> VALUE, ... }
Delete individual values from an attribute. C<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.
If C<VALUE> is a reference to an empty array or all existing values
of the attribute are being deleted, then the attribute will be
deleted from the entry.
$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
}
);
=item replace =E<gt> { ATTR =E<gt> VALUE, ... }
Replace any existing values in each given attribute with
C<VALUE>. C<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.
$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
}
);
=item increment =E<gt> { ATTR =E<gt> VALUE, ... }
Atomically increment the existing value in each given attribute by the
provided C<VALUE>. The attributes need to have integer syntax, or be
otherwise "incrementable". Note this will only work if the server
advertises support for LDAP_FEATURE_MODIFY_INCREMENT. Use
L<Net::LDAP::RootDSE/supported_feature> to check this.
$mesg = $ldap->modify( $dn,
increment => {
uidNumber => 1 # increment uidNumber by 1
}
);
=item changes =E<gt> [ OP =E<gt> [ ATTR =E<gt> VALUE ], ... ]
This is an alternative to B<add>, B<delete>, B<replace> and B<increment>
where the whole operation can be given in a single argument. C<OP>
should be B<add>, B<delete>, B<replace> or B<increment>. C<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.
$mesg = $ldap->modify( $dn,
changes => [
add => [
description => 'A description',
member => $newMember,
],
delete => [
seeAlso => [],
],
add => [
anotherAttribute => $value,
],
]
);
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below.
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below.
=back
B<Example>
$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']
]
);
=item search ( OPTIONS )
Search 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.
The result is an object of class L<Net::LDAP::Search>.
=over 4
=item base =E<gt> DN
The DN that is the base object entry relative to which the search is
to be performed.
=item scope =E<gt> '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 C<scope>
parameter with one of the following values:
=over 4
=item base
Search only the base object.
=item one
Search the entries immediately below the base object.
=item sub
=item subtree
Search the whole tree below (and including) the base object. This is
the default.
=item children
Search the whole subtree below the base object, excluding the base object itself.
Note: I<children> scope requires LDAPv3 subordinate feature extension.
=back
=item deref =E<gt> '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 C<deref> parameter with one of the
following values:
=over 4
=item never
Do not dereference aliases in searching or in locating the base object
of the search.
=item search
Dereference aliases in subordinates of the base object in searching,
but not in locating the base object of the search.
=item find
Dereference aliases in locating the base object of the search, but not
when searching subordinates of the base object. This is the default.
=item always
Dereference aliases both in searching and in locating the base object
of the search.
=back
=item sizelimit =E<gt> 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.
=item timelimit =E<gt> 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.
=item typesonly =E<gt> 1
Only attribute types (no values) should be returned. Normally
attribute types and values are returned.
=item filter =E<gt> 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
L<Net::LDAP::Filter> object. Values inside filters may need to be escaped
to avoid security problems; see L<Net::LDAP::Filter> for a definition of
the filter format, including the escaping rules.
=item attrs =E<gt> [ 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']
);
=item control =E<gt> CONTROL
=item control =E<gt> [ CONTROL, ... ]
See L</CONTROLS> below.
=item callback =E<gt> CALLBACK
See L</CALLBACKS> below.
=item raw =E<gt> 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.
The value provided here overwrites the value inherited from the constructor.
Example: raw =E<gt> qr/(?i:^jpegPhoto|;binary)/
=back
B<Example>
$mesg = $ldap->search(
base => $base_dn,
scope => 'sub',
filter => '(|(objectclass=rfc822mailgroup)(sn=jones))'
);
Net::LDAP::LDIF->new( \*STDOUT,"w" )->write( $mesg->entries );
=item start_tls ( OPTIONS )
Calling this method will convert the existing connection to using
Transport Layer Security (TLS), which provides an encrypted
connection. This is I<only> possible if the connection uses LDAPv3,
and requires that the server advertises support for
LDAP_EXTENSION_START_TLS. Use
L<Net::LDAP::RootDSE/supported_extension> to check this.
=over 4
=item verify =E<gt> 'none' | 'optional' | 'require'
How to verify the server's certificate:
=over 4
=item none
The server may provide a certificate but it will not be checked - this
may mean you are be connected to the wrong server
=item optional
Verify only when the server offers a certificate
=item require
The server must provide a certificate, and it must be valid.
=back
If you set verify to optional or require, you must also set either
cafile or capath. The most secure option is B<require>.
=item sslversion =E<gt> 'sslv2' | 'sslv3' | 'sslv23' | 'tlsv1' | 'tlsv1_1' | 'tlsv1_2'
This defines the version of the SSL/TLS protocol to use.
Default is to use the value that L<IO::Socket::SSL> uses as default.
See L<IO::Socket::SSL/SSL_version> for more details.
=item ciphers =E<gt> CIPHERS
Specify which subset of cipher suites are permissible for this
connection, using the standard OpenSSL string format. The default
behavior is to keep the decision on the underlying cryptographic
library.
=item clientcert =E<gt> '/path/to/cert.pem'
=item clientkey =E<gt> '/path/to/key.pem'
=item keydecrypt =E<gt> sub { ... }
If you want to use the client to offer a certificate to the server for
SSL authentication (which is not the same as for the LDAP Bind
operation) then set clientcert to the user's certificate file, and
clientkey to the user's private key file. These files must be in PEM
format.
If the private key is encrypted (highly recommended) then keydecrypt
should be a subroutine that returns the decrypting key. For example:
$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/'
);
=item capath =E<gt> '/path/to/servercerts/'
=item cafile =E<gt> '/path/to/servercert.pem'
When verifying the server's certificate, either set capath to the
pathname of the directory containing CA certificates, or set cafile to
the filename containing the certificate of the CA who signed the
server's certificate. These certificates must all be in PEM format.
The directory in 'capath' must contain certificates named using the
hash value of the certificates' subject names. To generate these
names, use OpenSSL like this in Unix:
ln -s cacert.pem `openssl x509 -hash -noout < cacert.pem`.0
(assuming that the certificate of the CA is in cacert.pem.)
=item checkcrl =E<gt> 1
If capath has been configured, then it will also be searched for
certificate revocation lists (CRLs) when verifying the server's
certificate.
The CRLs' names must follow the form B<hash>.rB<num> where B<hash>
is the hash over the issuer's DN and B<num> is a number starting with 0.
See L<IO::Socket::SSL/SSL_check_crl> for further information.
=back
=item unbind ( )
The unbind method does not take any parameters and will unbind you
from the server. Some servers may allow you to re-bind or perform
other operations after unbinding. If you wish to switch to another set
of credentials while continuing to use the same connection, re-binding
with another DN and password, without unbind-ing, will generally work.
B<Example>
$mesg = $ldap->unbind;
=item done ( )
Convenience alias for C<unbind()>, named after the clean-up method
of L<Net::LDAP::LDIF>.
=back
The following methods are for convenience, and do not return
C<Net::LDAP::Message> objects.
=over 4
=item async ( VALUE )
If C<VALUE> is given the async mode will be set. The previous value
will be returned. The value is I<true> if LDAP operations are being
performed asynchronously.
=item certificate ( )
Returns an X509_Certificate object containing the server's
certificate. See the IO::Socket::SSL documentation for information
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";
=item cipher ( )
Returns the cipher mode being used by the connection, in the string
format used by OpenSSL.
=item debug ( VALUE )
If C<VALUE> is given the debug bit-value will be set. The previous
value will be returned. Debug output will be sent to C<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.
=item disconnect ( )
Disconnect from the server
=item root_dse ( OPTIONS )
The root_dse method retrieves cached information from the server's
rootDSE.
=over 4
=item attrs =E<gt> [ ATTR, ... ]
A reference to a list of attributes to be returned.
If not specified, then the following attributes will be requested
subschemaSubentry
namingContexts
altServer
supportedExtension
supportedFeatures
supportedControl
supportedSASLMechanisms
supportedLDAPVersion
=back
The result is an object of class L<Net::LDAP::RootDSE>.
B<Example>
my $root = $ldap->root_dse;
# get naming Context
$root->get_value( 'namingContexts', asref => 1 );
# get supported LDAP versions
$root->supported_version;
As the root DSE may change in certain circumstances - for instance
when you change the connection using start_tls - you should always use
the root_dse method to return the most up-to-date copy of the root
DSE.
=item schema ( OPTIONS )
Read schema information from the server.
The result is an object of class L<Net::LDAP::Schema>.
Read this documentation for further information about methods that
can be performed with this object.
=over 4
=item dn =E<gt> DN
If a DN is supplied, it will become the base object entry from
which the search for schema information will be conducted. If
no DN is supplied the base object entry will be determined from
the rootDSE entry.
=back
B<Example>
my $schema = $ldap->schema;
# get objectClasses
@ocs = $schema->all_objectclasses;
# Get the attributes
@atts = $schema->all_attributes;
=item sasl ( )
Returns the C<Authen::SASL> object associated with the LDAP object,
or C<undef> if there isn't.
=item 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 C<IO::Socket> object;
with SASL layers the outcome depends on the options given:
=over 4
=item sasl_layer =E<gt> FLAG
This option is only relevant if SASL layers are established.
If it it missing or if is 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 C<IO::Socket> object.
If it exists, but is set to a value evaluating to FALSE, then the
base C<IO::Socket> object underneath the SASL layer is returned.
=back
=item host ( )
Returns the host to which the connection was established.
For LDAPI connections the socket path is returned.
=item port ( )
Returns the port connected to or C<undef> in case of LDAPI connections.
=item uri ( )
Returns the URI connected to.
As 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.
=item scheme ( )
Returns the scheme of the connection. One of I<ldap>, I<ldaps> or I<ldapi>.
=item sync ( MESG )
Wait for a given C<MESG> request to be completed by the server. If no
C<MESG> is given, then wait for all outstanding requests to be completed.
Returns an error code defined in L<Net::LDAP::Constant>.
=item process ( MESG )
Process any messages that the server has sent, but do not block. If C<MESG>
is specified then return as soon as C<MESG> has been processed.
Returns an error code defined in L<Net::LDAP::Constant>.
=item version ( )
Returns the version of the LDAP protocol that is being used.
=back
=head1 CONTROLS
Many of the methods described above accept a control option.
This allows the user to pass controls to the server as described
in LDAPv3.
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 C<to_asn> will be called which should return a reference
to a HASH containing the three elements described below.
For most purposes L<Net::LDAP::Control> objects are the easiest
way to generate controls.
=over 4
=item type =E<gt> OID
This element must be present and is the name of the type of control
being requested.
=item critical =E<gt> FLAG
critical is optional and should be a Boolean value, if it is not specified
then it is assumed to be I<false>.
=item value =E<gt> VALUE
If the control being requested requires a value then this element should
hold the value for the server.
=back
=head1 CALLBACKS
Most of the above commands accept a callback option. This option
should be a reference to a subroutine. This subroutine will be called
for each packet received from the server as a response to the request
sent.
When the subroutine is called the first argument will be the
L<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 L<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
L<Net::LDAP::Reference> object as the second argument.
=head1 LDAP ERROR CODES
B<Net::LDAP> also exports constants for the error codes that can be received
from the server, see L<Net::LDAP::Constant>.
=head1 SEE ALSO
L<Net::LDAP::Constant>,
L<Net::LDAP::Control>,
L<Net::LDAP::Entry>,
L<Net::LDAP::Filter>,
L<Net::LDAP::Message>,
L<Net::LDAP::Reference>,
L<Net::LDAP::Search>,
L<Net::LDAP::RFC>
The homepage for the perl-ldap modules can be found at
http://ldap.perl.org/.
=head1 ACKNOWLEDGEMENTS
This document is based on a document originally written by Russell Fulton
E<lt>r.fulton@auckland.ac.nzE<gt>.
Chris Ridd E<lt>chris.ridd@isode.comE<gt> for the many hours spent
testing and contribution of the ldap* command line utilities.
=head1 MAILING LIST
A discussion mailing list is hosted by the Perl Foundation at
E<lt>perl-ldap@perl.orgE<gt> No subscription is necessary!
=head1 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.
=head1 AUTHOR
Graham Barr E<lt>gbarr@pobox.comE<gt>
=head1 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.
=cut
|