blob: f6d99604d6586d9cc003146a7e2ec0ff78b3da6a (
plain)
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
|
#!/usr/bin/perl -w
#
# testwrite.pl - Test of LDAP URL Operations in Perl5
# Author: Clayton Donley <donley@cig.mot.com>
#
# This script tests some of the basic LDAP URL functions.
# Call the script with an LDAP URL to perform a search.
use strict;
use Net::LDAPapi;
my $urlhref;
my $url = $ARGV[0] || "ldap://ldap.four11.com/??sub?(cn=Clayton Donley)";
if (ldap_is_ldap_url($url))
{
$urlhref = ldap_url_parse($url);
} else {
die "$url: Not an LDAP Url.";
}
if ($urlhref)
{
print "host: " . $urlhref->{'host'} . "\n";
print "port: " . $urlhref->{'port'} . "\n";
print "base: " . $urlhref->{'dn'} . "\n";
my $attr;
foreach $attr (@{$urlhref->{'attr'}})
{
print "attr: " . $attr . "\n";
}
print "filter: " . $urlhref->{'filter'} . "\n";
print "scope: " . $urlhref->{'scope'} . "\n";
# If using Netscape, there is an options key specifying the use of SSL, etc...
if ($urlhref->{'options'})
{
print "options: " . $urlhref->{'options'} . "\n"
}
print "Connecting...\n";
my $port = $urlhref->{"port"} || 389;
my $ld = new Net::LDAPapi(-host=>$urlhref->{"host"},-port=>$port);
if ($ld == -1)
{
die "Connection failed...";
}
$ld->bind_s;
$ld->url_search_s($url,0);
my %record = %{$ld->get_all_entries};
$ld->unbind;
my @dns = (sort keys %record);
print $#dns+1 . " entries returned.\n";
foreach my $dn (@dns)
{
print "dn: $dn\n";
foreach my $attr (keys %{$record{$dn}})
{
foreach my $item (@{$record{$dn}{$attr}})
{
if ($attr =~ /binary/)
{
print "$attr: binary - length=" . length($item) . "\n";
} else {
print "$attr: $item\n";
}
}
}
}
} else {
print "Invalid LDAP URL: $url\n";
}
|