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.


In reply to Re: LDAP address lookup from Mutt by waxhead
in thread LDAP address lookup from Mutt by lachoy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.