From: Michael C. <mjc...@xp...> - 2002-03-28 19:23:20
|
Hiya all, I am just starting out trying to do some perl-ldap coding. I am trying to piece together a program that will return all the dn and their attributes from a perticular branch of my ldap DIT and make a csv file from it. I have shamelessly borrowed a ton of code from the examples for perl-ldap but I still cant get it to return any results. Everything runs without errors but never outputs any data. (right now I am just trying to print something out). Any idea where I am going wrong? Thanks.. Mike ---------------------------------------- #!/usr/bin/perl -w use strict; use Net::LDAP::Util qw(ldap_error_name ldap_error_text); use Net::LDAP qw(:all); use vars qw( $LDAP_SERVER_NAME $LDAP_SERVER_PORT $LDAP_BASEDN $ldap $mesg ); $LDAP_SERVER_NAME = 'ldap-nj.xpedite.com'; $LDAP_SERVER_PORT = 389; $LDAP_BASEDN = 'ou=people, ou=usa, dc=xpedite, dc=com'; sub LDAPsearch { my ($ldap,$searchString,$attrs,$base) = @_ ; my $result = $ldap->search ( base => "$base", scope => "sub", filter => "$searchString", attrs => $attrs ); } $ldap = Net::LDAP->new($LDAP_SERVER_NAME) or die "$@"; $mesg = $ldap->bind( version => 3); if ($mesg->code) { my $ldap_code = ldap_error_name($mesg->code); print "$ldap_code"; exit; } my @Attrs = (); my $result = LDAPsearch($ldap,"*",\@Attrs,"$LDAP_BASEDN") or return 0; my $href = $result->as_struct; my @arrayOfDNs = keys %$href ; # use DN hashes foreach (@arrayOfDNs) { print "\n",$_,"\n"; my $valref = $$href{$_}; my @arrayOfAttrs = sort keys %$valref; #use Attr hashes my $attrName; foreach $attrName (@arrayOfAttrs) { next if ( $attrName =~ /;binary$/ ); my $attrVal = @$valref{$attrName} ; print "\t $attrName: @$attrVal \n"; } } |