From: Jeffery H. <je...@uv...> - 2002-11-03 03:26:51
|
Dear all, I tried to write a simple program to query microsoft active directory data use Net::LDAP. I have binded it successful, but I cannot query it! I use the same command from ldap browser, it can query my data. my query string like that: $querystring = "cn=HuangJeffery,cn=Users,dc=mydomain,dc=com"; What's problem here! does anyone success to access AD use perl module? How to use it! Thank you! Regard, Jeffery |
From: Chris R. <chr...@ma...> - 2002-11-03 06:32:34
|
On 3/11/02 3:23 am, Jeffery Huang <je...@uv...> wrote: > Dear all, > I tried to write a simple program to query microsoft active > directory data use Net::LDAP. > I have binded it successful, but I cannot query it! I use the same > command from ldap browser, > it can query my data. my query string like that: > > $querystring = "cn=HuangJeffery,cn=Users,dc=mydomain,dc=com"; > > What's problem here! does anyone success to access AD use perl module? > How to use it! I don't know what you mean by a query string. LDAP searches have search bases and search filters (and a few other things) but no query strings. Can you send us the exact parameters that you send to $ldap->search()? Cheers, Chris |
From: Jeffery H. <je...@uv...> - 2002-11-04 02:27:39
|
Hello! Chris, This is my code: #!/usr/bin/perl use Net::LDAP; use Net::LDAP::Util qw(ldap_error_text ldap_error_name ldap_error_desc ); $ldap = Net::LDAP->new("localhost") or die "Initial LDAP error"; $mesg = $ldap->bind( 'CN=HuangJeffery,CN=Users,DC=mydomain,DC=com', password => '1234' ); if ( $mesg->is_error ) { print "bind failed\n"; print ldap_error_name( $mesg->code ); print "\n"; } else { print "bind successful\n"; print ldap_error_name( $mesg->code ); print "\n"; } # if they don't pass an array of attributes... # set up something for them $searchString = "cn=HuangJeffery,cn=Users,dc=mydomain,dc=com"; if (!$attrs ) { $attrs = ['mobile' ]; } $result = $ldap->search ( scope => "sub", filter => "$searchString", attrs => $attrs ); if ( $result->code ) { print ldap_error_name($result->code); print "\n"; } else { my $href = $result->as_struct; # get an array of the DN names my @arrayOfDNs = keys %$href ; # use DN hashes # process each DN using it as a key foreach (@arrayOfDNs) { print $_,"\n"; my $valref = $$href{$_}; # get an array of the attribute names # passed for this one DN. my @arrayOfAttrs = sort keys %$valref; #use Attr hashes my $attrName; foreach $attrName (@arrayOfAttrs) { # skip any binary data: yuck! next if ( $attrName =~ /;binary$/ ); # get the attribute value (pointer) using the # attribute name as the hash my $attrVal = @$valref{$attrName} ; print "\t $attrName: @$attrVal \n"; } print "#-------------------------------\n"; # End of that DN } # # end of as_struct method # #-------- #------------ # # handle each of the results independently # ... i.e. using the walk through method my @entries = $result->entries; my $entr ; foreach $entr ( @entries ) { print "DN: ",$entr->dn,"\n"; #my @attrs = sort $entr->attributes; my $attr; foreach $attr ( sort $entr->attributes ){ #skip binary we can't handle next if ( $attr =~ /;binary$/ ); print " $attr : ",$entr->get_value($attr),"\n"; } #print "@attrs\n"; print "#-------------------------------\n"; } } $ldap->unbind; 1; Chris Ridd wrote: >On 3/11/02 3:23 am, Jeffery Huang <je...@uv...> wrote: > > > >>Dear all, >> I tried to write a simple program to query microsoft active >>directory data use Net::LDAP. >>I have binded it successful, but I cannot query it! I use the same >>command from ldap browser, >>it can query my data. my query string like that: >> >> $querystring = "cn=HuangJeffery,cn=Users,dc=mydomain,dc=com"; >> >>What's problem here! does anyone success to access AD use perl module? >>How to use it! >> >> > >I don't know what you mean by a query string. LDAP searches have search >bases and search filters (and a few other things) but no query strings. Can >you send us the exact parameters that you send to $ldap->search()? > >Cheers, > >Chris > > > |
From: <pau...@cp...> - 2002-11-04 09:10:56
|
Jeffery- You need to examine the arguments you pass to the search method - see perldoc net::ldap for full details. You might try something like: $result =3D $ldap->search ( base =3D> $searchString, filter =3D> "(objectclass=3D*)", attrs =3D> $attrs ); Regards, Paul. >-- Original Message -- >From: Jeffery Huang <je...@uv...> >To: Chris Ridd <chr...@ma...>, > perl-ldap-dev <per...@li...> >Subject: Re: Ldap module and active directory >Date: Mon, 04 Nov 2002 10:23:52 +0800 > > >Hello! Chris, > This is my code: > >#!/usr/bin/perl > >use Net::LDAP; > use Net::LDAP::Util qw(ldap_error_text > ldap_error_name > ldap_error_desc > ); > >$ldap =3D Net::LDAP->new("localhost") or die "Initial LDAP error"; > >$mesg =3D $ldap->bind( 'CN=3DHuangJeffery,CN=3DUsers,DC=3Dmydomain,DC=3D= com', >password =3D> '1234' ); > > >if ( $mesg->is_error ) >{ > print "bind failed\n"; > print ldap_error_name( $mesg->code ); > print "\n"; >} >else >{ > print "bind successful\n"; > print ldap_error_name( $mesg->code ); > print "\n"; >} > ># if they don't pass an array of attributes... ># set up something for them > >$searchString =3D "cn=3DHuangJeffery,cn=3DUsers,dc=3Dmydomain,dc=3Dcom";= >if (!$attrs ) { $attrs =3D ['mobile' ]; } > > >$result =3D $ldap->search ( > scope =3D> "sub", > filter =3D> "$searchString", > attrs =3D> $attrs ); > >if ( $result->code ) >{ >print ldap_error_name($result->code); >print "\n"; >} >else >{ >my $href =3D $result->as_struct; > ># get an array of the DN names > >my @arrayOfDNs =3D keys %$href ; # use DN hashes > ># process each DN using it as a key > >foreach (@arrayOfDNs) { > print $_,"\n"; > my $valref =3D $$href{$_}; > > # get an array of the attribute names > # passed for this one DN. > my @arrayOfAttrs =3D sort keys %$valref; #use Attr hashes > my $attrName; > foreach $attrName (@arrayOfAttrs) { > > # skip any binary data: yuck! > next if ( $attrName =3D~ /;binary$/ ); > > # get the attribute value (pointer) using the > # attribute name as the hash > my $attrVal =3D @$valref{$attrName} ; > print "\t $attrName: @$attrVal \n"; > } > print "#-------------------------------\n"; > # End of that DN >} ># ># end of as_struct method ># >#-------- > >#------------ ># ># handle each of the results independently ># ... i.e. using the walk through method > >my @entries =3D $result->entries; > >my $entr ; >foreach $entr ( @entries ) >{ > print "DN: ",$entr->dn,"\n"; > #my @attrs =3D sort $entr->attributes; > > my $attr; > foreach $attr ( sort $entr->attributes ){ > #skip binary we can't handle > next if ( $attr =3D~ /;binary$/ ); > print " $attr : ",$entr->get_value($attr),"\n"; > } > > #print "@attrs\n"; > print "#-------------------------------\n"; >} >} >$ldap->unbind; >1; >Chris Ridd wrote: > >>On 3/11/02 3:23 am, Jeffery Huang <je...@uv...> wrote: >> >> >> >>>Dear all, >>> I tried to write a simple program to query microsoft active >>>directory data use Net::LDAP. >>>I have binded it successful, but I cannot query it! I use the same >>>command from ldap browser, >>>it can query my data. my query string like that: >>> >>> $querystring =3D "cn=3DHuangJeffery,cn=3DUsers,dc=3Dmydomain,dc=3D= com"; >>> >>>What's problem here! does anyone success to access AD use perl module?= >>>How to use it! >>> >>> >> >>I don't know what you mean by a query string. LDAP searches have search= >>bases and search filters (and a few other things) but no query strings.= >Can >>you send us the exact parameters that you send to $ldap->search()? >> >>Cheers, >> >>Chris >> >> >> > > > > > >------------------------------------------------------- >This SF.net email is sponsored by: ApacheCon, November 18-21 in >Las Vegas (supported by COMDEX), the only Apache event to be >fully supported by the ASF. http://www.apachecon.com |
From: Chris R. <chr...@ma...> - 2002-11-04 13:09:41
|
On 4/11/02 9:10 am, pau...@cp... <pau...@cp...> wrote: > Jeffery- > You need to examine the arguments you pass to the search method - see > perldoc net::ldap for full details. You might try something like: > > $result = $ldap->search ( > base => $searchString, > filter => "(objectclass=*)", > attrs => $attrs ); > > Regards, > > Paul. Jeffery was actually binding as $searchString as well, so it probably isn't the right base to use for the search. I don't know enough about Active Directory to know what a good search base for it might be :-( Cheers, Chris |