|
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
>
|