I started on something for CPAN that I never got around to finishing. I started this because I wanted to create a mutt alias file that contained everyone in the company by accessing Exchange via LDAP. Here are the basics.

A sample calling program:

#!/usr/bin/perl -w use strict; use Net::LDAP::Exchange; use Data::Dumper; use constant SERVER => 'Exchange Server Here'; use constant DOMAIN => 'Domain Here'; # If you need to login... use constant LOGIN => 'Exchange Login Here'; use constant PASSWORD => 'Password Here'; my $ex = Net::LDAP::Exchange->new(SERVER,DOMAIN,LOGIN,PASSWORD); my $result_set = $ex->search_lastname('Bisbee'); print Dumper($result_set);
 

Here is the skelton of my module to search by last name:

package Net::LDAP::Exchange; use strict; use Net::LDAP; use Data::Dumper; sub new { my ($class, $server, $domain, $name, $password) = @_; die 'server and domain are required' unless $server and $domain; die 'missing password' if $name and !$password; die 'missing name' if $password and !$name; my $self = bless {}, $class; $self->{ldap} = Net::LDAP->new($server); $self->{server} = $server; $self->{domain} = $domain; $self->{name} = $name if $name; $self->{password} = $password if $password; return $self; } sub search_lastname { my ($self,$search) = @_; my $query = _build_query($search,qw(CN)); my $result_set = $self->search($query); return $result_set; } sub search { my ($self,$query) = @_; if ($self->{name} and $self->{password}) { $self->{ldap}->bind('cn='.$self->{name}, password=>$self->{password}, version=>3); } else { $self->{ldap}->bind; } my $results = $self->{ldap}->search(base => 'o=' . $self->{domain}, filter => "(|$query)"); $results->code && die $results->error; my @result_set = (); foreach my $entry ($results->all_entries) { my @attributes = $entry->attributes; my $result = {}; for my $att (@attributes) { my $return_att = uc $att; $result->{$return_att} = $entry->get_value($att); } push @result_set, $result; } $self->{ldap}->unbind; return \@result_set; } sub _build_query { my ($search,@fields) = @_; my $query = join '', map { "($_=$search*) " } @fields; return $query; }
If you have any comments or suggestions, send them to jbisbee at yahoo dot com.

-biz-


In reply to Re: Phone lookup on Exchange server by jbisbee
in thread Phone lookup on Exchange server by jlf

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.