This is my first comment...
I grabbed this script to give me ldap access to my server, naturally. However my mail attribute is multivalued for a number of entries, so I have made some modifications to the script to handle the multivalued attribute.
Make sure you change all entries as required.
#!/usr/bin/perl
use strict;
use Net::LDAP;
use constant HOST => 'ldap.your.domain';
use constant BASE => 'ou=People, dc=your, dc=domain';
use constant VERSION => 3;
use constant SCOPE => 'sub';
my $name;
my @attributes = qw( dn givenName sn mail );
my $filter = "(|(sn=$name*)(givenName=$name*))";
{
print "Searching directory... ";
$name = shift || die "Usage: $0 filter\n";
my $ldap = Net::LDAP->new( HOST, onerror => 'die' )
|| die "Cannot connect: $@";
$ldap->bind(version => VERSION) or die "Cannot bind: $@";
my $result = $ldap->search( base => BASE,
scope => SCOPE,
attrs => \@attributes,
filter => $filter
);
my @entries = $result->entries;
$ldap->unbind();
print scalar @entries, " entries found.\n";
foreach my $entry ( @entries ) {
my @emailAddr = $entry->get_value('mail');
foreach my $addr (@emailAddr) {
print $addr , "\t";
print $entry->get_value('givenName'), " ";
print $entry->get_value('sn'), "\n";
}
}
}
Make sure you have the Net::LDAP module installed.
Hope someone finds it of use, and thanks to the original author... I just hacked on what was already provided.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.