On 08/12/2008 01:07 PM, John Arends wrote:
> I am trying to write a script to do some work with Active Directory.
> Since my scripts need to run on a Linux machine, I have to use Net::LDAP.
>
Or try the new Net::LDAP::Class (your script rewritten below):
#!/usr/bin/perl
use strict;
use warnings;
use Net::LDAP;
my $uid = 'username';
my $bindPass = 'blah';
my $ldapServer = 'ldaps://ad.myorg.edu';
my $base = 'OU=SubOU,OU=myOU,dc=ad,dc=myorg,dc=edu';
{
package MyUser;
use base qw( Net::LDAP::Class::User::AD );
__PACKAGE__->meta->setup(
attributes => [ @{ __PACKAGE__->AD_attributes }, 'telephonenumber' ],
unique_attributes => __PACKAGE__->AD_attributes,
base_dn => $base,
);
sub init_group_class {'MyGroup'}
}
{
package MyGroup;
use base qw( Net::LDAP::Class::Group::AD );
__PACKAGE__->meta->setup(
attributes => __PACKAGE__->AD_attributes,
unique_attributes => __PACKAGE__->AD_attributes,
base_dn => $base,
);
sub init_user_class {'MyUser'}
}
my $ldap = Net::LDAP->new($ldapServer) or die "$@";
my $msg = $ldap->bind( $uid, password => $bindPass );
if ( $msg->code ) {
die Net::LDAP::Class->get_error_msg($msg);
}
my @users = MyUser->find( ldap => $ldap, filter => "&(sAMAccountName=*)" );
foreach my $user (@users) {
foreach my $attr (@{ $user->attributes }) {
printf( "%s : %s\n", $attr, $user->$attr || '' );
}
}
--
Peter Karman . [EMAIL PROTECTED] . http://peknet.com/