-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLDAPtest.pl
More file actions
executable file
·90 lines (72 loc) · 2.14 KB
/
Copy pathLDAPtest.pl
File metadata and controls
executable file
·90 lines (72 loc) · 2.14 KB
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
#!/usr/bin/perl -w
use strict;
use Carp;
use Net::LDAP;
use vars qw($ldap $SearchString @Attrs $base);
sub dumpargs {
my ($cmd,$s,$rh) = @_;
my @t;
push @t, "'$s'" if $s;
map {
my $value = $$rh{$_};
if (ref($value) eq 'ARRAY') {
push @t, "$_ => [" . join(", ", @$value) . "]";
} else {
push @t, "$_ => '$value'";
}
} keys(%$rh);
print "$cmd(", join(", ", @t), ")\n";
}
sub dump_entry {
my $entry = shift;
print "Dump:\n";
print "Entry = " . ref($entry) . "\n";
my $mailref = $entry->get_value("mail", asref => 1);
print "Mail: " . join (" ", @$mailref) . " \n";
print "Entry = " . ref($entry) . "\n";
my @entry_attr=$entry->attributes();
print "Attributes:\n";
for my $entry_attr (sort @entry_attr){
my $ref = $entry->get_value($entry_attr, asref => 1);
if (defined($ref)){
if ($entry_attr =~ /Certificate/){
printf " %-35s: %-10s\n", $entry_attr, " .. binary";
}
elsif ($entry_attr =~ /binary/){
printf " %-35s: %40s\n", $entry_attr, "Binary";
}
elsif ($#{@$ref} == 0){
printf " %-35s: %40s\n", $entry_attr, @$ref;
} else {
printf " %-35s: %40s\n", $entry_attr, "";
for my $value (sort @{$ref}){
printf " %-35s: %40s\n", " ", $value;
}
}
}
}
}
$ldap = Net::LDAP->new("ldap.hp.com") or die "$@";
#$ldap = Net::LDAP->new("isrvlx0.cv.hp.com") or die "$@";
if (!$base ) {
#$base = "dc=cv,dc=hp,dc=com";
$base = "ou=People,o=hp.com";
print "Base set to '$base'\n";
}
# if they don't pass an array of attributes...
# set up something for them
@Attrs = ["cn", "sn", "mail"];
my %searchargs;
$searchargs{base} = $base;
$searchargs{scope} = "sub";
$searchargs{filter} = "cn=floyd* moore";
#$searchargs{filter} = "uid=moore*";
$searchargs{attrs} = [];
dumpargs("search", undef, \%searchargs);
my $result = $ldap->search (%searchargs);
$result->code && die $result->error;
print "result = " . ref($result) . "\n";
my @entries = $result->entries;
my $entry = $entries[0];
print "DN: " . $entry->dn . "\n";
dump_entry($entry);