| 
     
      
      
      From: Sheahan, J. (PCLN-NW) <Joh...@pr...> - 2003-03-17 14:25:48
       
   | 
I am using basic code (straight out of the O'Reilly book) to do a bind and
search on my LDAP directory. I get no error messages and it always returns
successfully but always shows 0 entries found. I am able to successfully
search the LDAP structure from a browser and also able to successfully
search it using the ldapsearch commands as follows:
##### This works fine
/usr/local/bin/ldapsearch -x -b 'dc=Priceline,dc=com' '(uid=jsheahan)'    
##### So does this, from a browser
ldap://172.21.81.101:389/o=People,dc=priceline,dc=com?cn,homephone,title,emp
loyeetype,mail,telephonenumber?sub?
##### Here is my basic code
use Net::LDAP;
use Net::LDAP::LDIF;
$server =  "172.21.81.101";
$port = "389";
$basedn = "o=People,dc=priceline,dc=com";
$scope = "sub";
$passwd = "secret";
$binddn = "cn=Manager,dc=priceline,dc=com";
$c = new Net::LDAP($server, port=>$port) or die "Unable to connect to
$server: $@\n";
#$c->bind() or die "Unable to bind: $@\n";
$c->bind($binddn, password => $passwd) or die "Unable to bind: $@\n";
$searchobj = $c->search(base => $basedn, scope => $scope, filter =>
"uid=jsheahan");
die "Bad Search, errorcode #".$searchobj->code() if $searchobj->code();
#process the return values from search()
if ($searchobj){
        $ldif = new Net::LDAP::LDIF("-");
        $ldif->write($searchobj->entries());
        $ldif->done();
}
 | 
| 
     
      
      
      From: Jason J. <jas...@ho...> - 2003-03-17 15:05:44
       
   | 
John,
I'm using the code below (minus variables, etc)......... the checkBindLDAP
subroutine is where I found problems with my binding, etc.
thnx,
~j
=================================
== BEGIN Code
use Net::LDAP qw(:all);
use Net::LDAP::Util qw(ldap_error_name ldap_error_text ldap_error_desc);
use CGI;
use CGI::Session qw/-ip-match/;
my $cgi = new CGI;
sub connectLDAP {
        local ($_IP_ADDRESS) = @_;
        $ldap = Net::LDAP->new("$_IP_ADDRESS") || die "$@\n";
}
sub bindLDAP {
        local ($_DN, $_PASSWORD) = @_;
        local $msg = $ldap->bind(dn=>"$_DN", password=>"$_PASSWORD") || die
"No Auth: " . "$@\n";
        &checkBindLDAP ($msg);
}
sub searchLDAP {
        local ($_BASE, $_BASE_SUFFIX, $_USERID, $_PASSWORD) = @_;
        $RS = $ldap->search     (
                                base => "dc=$_BASE,dc=$_BASE_SUFFIX",
                                filter => "sAMAccountName=$_USERID"
                                );
        if (1 == &checkSearchLDAP ($RS, $_PASSWORD)) {
                return 1;
        }else{
                return 0;
        }
}
sub checkBindLDAP {
        local ($_MSG) = @_;
        if ( $_MSG->code ) {
                ############################################################
                ## DEBUG INFORMATION
                print ("Message Error Code => " . $_MSG->code . "\n");
                print ("Message Error Name => " .
ldap_error_name($_MSG->code) . "\n");
                print ("Message Error Text => " .
ldap_error_text($_MSG->code) . "\n");
                print ("Message Error Desc => " .
ldap_error_desc($_MSG->code) . "\n");
                return 1;
        } else {
                return 0;
        }
}
sub unbindLDAP {
        $ldap->unbind();
}
&connectLDAP($LDAP_IP);
&bindLDAP($LDAP_DN,$LDAP_PASS);
&unbindLDAP();
----- Original Message -----
From: "Sheahan, John (PCLN-NW)" <Joh...@pr...>
To: <per...@li...>
Sent: Monday, March 17, 2003 8:25 AM
Subject: Basic search always returning 0 entries
> I am using basic code (straight out of the O'Reilly book) to do a bind and
> search on my LDAP directory. I get no error messages and it always returns
> successfully but always shows 0 entries found. I am able to successfully
> search the LDAP structure from a browser and also able to successfully
> search it using the ldapsearch commands as follows:
>
> ##### This works fine
> /usr/local/bin/ldapsearch -x -b 'dc=Priceline,dc=com' '(uid=jsheahan)'
>
> ##### So does this, from a browser
>
ldap://172.21.81.101:389/o=People,dc=priceline,dc=com?cn,homephone,title,emp
> loyeetype,mail,telephonenumber?sub?
>
> ##### Here is my basic code
>
> use Net::LDAP;
> use Net::LDAP::LDIF;
>
> $server =  "172.21.81.101";
> $port = "389";
> $basedn = "o=People,dc=priceline,dc=com";
> $scope = "sub";
> $passwd = "secret";
> $binddn = "cn=Manager,dc=priceline,dc=com";
>
>
> $c = new Net::LDAP($server, port=>$port) or die "Unable to connect to
> $server: $@\n";
>
> #$c->bind() or die "Unable to bind: $@\n";
>
> $c->bind($binddn, password => $passwd) or die "Unable to bind: $@\n";
> $searchobj = $c->search(base => $basedn, scope => $scope, filter =>
> "uid=jsheahan");
> die "Bad Search, errorcode #".$searchobj->code() if $searchobj->code();
>
>
> #process the return values from search()
> if ($searchobj){
>         $ldif = new Net::LDAP::LDIF("-");
>         $ldif->write($searchobj->entries());
>         $ldif->done();
> }
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by:Crypto Challenge is now open!
> Get cracking and register here for some mind boggling fun and
> the chance of winning an Apple iPod:
> http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
>
 | 
| 
     
      
      
      From: Chris R. <chr...@ma...> - 2003-03-17 15:39:47
       
   | 
On 17/3/03 2:25 pm, Sheahan, John (PCLN-NW) <Joh...@pr...>
wrote:
> I am using basic code (straight out of the O'Reilly book) to do a bind and
> search on my LDAP directory. I get no error messages and it always returns
> successfully but always shows 0 entries found. I am able to successfully
> search the LDAP structure from a browser and also able to successfully
> search it using the ldapsearch commands as follows:
> 
> ##### This works fine
> /usr/local/bin/ldapsearch -x -b 'dc=Priceline,dc=com' '(uid=jsheahan)'
> 
> ##### So does this, from a browser
> ldap://172.21.81.101:389/o=People,dc=priceline,dc=com?cn,homephone,title,emp
> loyeetype,mail,telephonenumber?sub?
> 
> ##### Here is my basic code
> 
> use Net::LDAP;
> use Net::LDAP::LDIF;
> 
> $server =  "172.21.81.101";
> $port = "389";
> $basedn = "o=People,dc=priceline,dc=com";
> $scope = "sub";
> $passwd = "secret";
> $binddn = "cn=Manager,dc=priceline,dc=com";
> 
> 
> $c = new Net::LDAP($server, port=>$port) or die "Unable to connect to
> $server: $@\n";
> 
> #$c->bind() or die "Unable to bind: $@\n";
> 
> $c->bind($binddn, password => $passwd) or die "Unable to bind: $@\n";
> $searchobj = $c->search(base => $basedn, scope => $scope, filter =>
> "uid=jsheahan");
Firstly these are three different search operations, so it is unreasonable
to expect them to behave identically.
Your "ldapsearch" search is like this (also make sure ldapsearch is talking
to the same server!):
    $c->search(base => 'dc=Priceline,dc=com',
               scope => 'sub',
               filter => '(uid=jsheahan)');
Your "ldap://" search is like this:
    $c->search(base => 'o=People,dc=priceline,dc=com',
               scope => 'sub',
               filter => '(objectclass=*)',
               attrs => [qw(cn homephone title employeetype
                            mail telephonenumber)]);
> die "Bad Search, errorcode #".$searchobj->code() if $searchobj->code();
> 
> 
> #process the return values from search()
> if ($searchobj){
>       $ldif = new Net::LDAP::LDIF("-");
>       $ldif->write($searchobj->entries());
$ldif->write is deprecated; use $ldif->write_entry instead.
What does $searchobj->count() return?
>       $ldif->done();
> }
Cheers,
Chris
 | 
| 
     
      
      
      From: Jim H. <ha...@us...> - 2003-03-17 16:07:44
       
   | 
The problem is in the LDIF code.  The following works:
if ($searchobj){
        $ldif = new Net::LDAP::LDIF("XX","a");
        $ldif->write_entry($searchobj->entries());
        $ldif->done();
}
but it puts the results in file XX.  Substituting - for XX doesn't send it to
stdout.  There is nothing in the docs to say that it should.  You shouldn't
need to use LDIF if you only want to display the results.  There are lots of
better ways.
  --Jim Harle
On Mon, 17 Mar 2003, Chris Ridd wrote:
> On 17/3/03 2:25 pm, Sheahan, John (PCLN-NW) <Joh...@pr...>
> wrote:
>
> > I am using basic code (straight out of the O'Reilly book) to do a bind and
> > search on my LDAP directory. I get no error messages and it always returns
> > successfully but always shows 0 entries found. I am able to successfully
> > search the LDAP structure from a browser and also able to successfully
> > search it using the ldapsearch commands as follows:
> >
> > ##### This works fine
> > /usr/local/bin/ldapsearch -x -b 'dc=Priceline,dc=com' '(uid=jsheahan)'
> >
> > ##### So does this, from a browser
> > ldap://172.21.81.101:389/o=People,dc=priceline,dc=com?cn,homephone,title,emp
> > loyeetype,mail,telephonenumber?sub?
> >
> > ##### Here is my basic code
> >
> > use Net::LDAP;
> > use Net::LDAP::LDIF;
> >
> > $server =  "172.21.81.101";
> > $port = "389";
> > $basedn = "o=People,dc=priceline,dc=com";
> > $scope = "sub";
> > $passwd = "secret";
> > $binddn = "cn=Manager,dc=priceline,dc=com";
> >
> >
> > $c = new Net::LDAP($server, port=>$port) or die "Unable to connect to
> > $server: $@\n";
> >
> > #$c->bind() or die "Unable to bind: $@\n";
> >
> > $c->bind($binddn, password => $passwd) or die "Unable to bind: $@\n";
> > $searchobj = $c->search(base => $basedn, scope => $scope, filter =>
> > "uid=jsheahan");
>
> Firstly these are three different search operations, so it is unreasonable
> to expect them to behave identically.
>
> Your "ldapsearch" search is like this (also make sure ldapsearch is talking
> to the same server!):
>
>     $c->search(base => 'dc=Priceline,dc=com',
>                scope => 'sub',
>                filter => '(uid=jsheahan)');
>
> Your "ldap://" search is like this:
>
>     $c->search(base => 'o=People,dc=priceline,dc=com',
>                scope => 'sub',
>                filter => '(objectclass=*)',
>                attrs => [qw(cn homephone title employeetype
>                             mail telephonenumber)]);
>
> > die "Bad Search, errorcode #".$searchobj->code() if $searchobj->code();
> >
> >
> > #process the return values from search()
> > if ($searchobj){
> >       $ldif = new Net::LDAP::LDIF("-");
> >       $ldif->write($searchobj->entries());
>
> $ldif->write is deprecated; use $ldif->write_entry instead.
>
> What does $searchobj->count() return?
>
> >       $ldif->done();
> > }
>
> Cheers,
>
> Chris
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by:Crypto Challenge is now open!
> Get cracking and register here for some mind boggling fun and
> the chance of winning an Apple iPod:
> http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
>
 | 
| 
     
      
      
      From: Graham B. <gb...@po...> - 2003-03-18 14:52:38
       
   | 
On Mon, Mar 17, 2003 at 11:07:08AM -0500, Jim Harle wrote:
> The problem is in the LDIF code.  The following works:
> if ($searchobj){
>         $ldif = new Net::LDAP::LDIF("XX","a");
>         $ldif->write_entry($searchobj->entries());
>         $ldif->done();
> }
> 
> but it puts the results in file XX.  Substituting - for XX doesn't send it to
> stdout.  There is nothing in the docs to say that it should.  You shouldn't
Maybe not, but as "-", "w" will send to stdout I don't see it as unreasonable
to expect "-","a" to also go to stdout.
> need to use LDIF if you only want to display the results.  There are lots of
> better ways.
Can you give examples ? Most people I know of use LDIF to display results,
certainly when in a debugging situation.
Graham.
 | 
| 
     
      
      
      From: Jim H. <ha...@us...> - 2003-03-18 14:59:26
       
   | 
On Tue, 18 Mar 2003, Graham Barr wrote: > > need to use LDIF if you only want to display the results. There are lots of > > better ways. > > Can you give examples ? Most people I know of use LDIF to display results, > certainly when in a debugging situation. $entry->dump is quick and easy. > > Graham. >  |