I figured it out. When I run the script from my workstation which a member
of xxx.com domain, The script automatically assumes my security context and
runs flawlessly. Now when I move the same script to an isolated host that is
in my network but not a member of any domain, I get 0x80040e37 "Table does
not exist' error. I know this is perl-ldap mailing list but I thought you
guys are hella cool ;)
This workaround works from managed/unmanaged server:
#setup ADO connection
my $connObj = Win32::OLE->new('ADODB.Connection');
$connObj->{Provider} = "ADsDSOObject";
# Set these next two if you need to authenticate # This is the workaround if
# The server this script is running from is not in a domain. Need a default
account
$connObj->Properties->{'User ID'} = '[EMAIL PROTECTED]';
$connObj->Properties->{'Password'} = '[EMAIL PROTECTED]/()|2|)';
$connObj->Open;
my $commObj = Win32::OLE->new('ADODB.Command');
$commObj->{ActiveConnection} = $connObj;
$commObj->Properties->{'Page Size'} = 1000;
# Grab the default domain name.
my $rootDSE = Win32::OLE->GetObject("LDAP://$domain/RootDSE");
my $rootNC = $rootDSE->Get("defaultNamingContext");
# Run ADO query and print results.
my $query = "<LDAP://$domain/$cont$rootNC>;"; #$domain = xxx.com
$query .= "((sn=$searchterm));";
$query .= "distinguishedName,cn;";
$query .= "subtree";
$commObj->{CommandText} = $query;
my $resObj = $commObj->Execute($query); die "Could not query $domain:
",$Win32::OLE::LastError,"\n" unless ref $resObj;
my $total = 0;
while (!($resObj->EOF)) {
$strUserDN = $resObj->Fields("distinguishedName")->value;
$total++; $resObj->MoveNext;
print $strUserDN;
}
From: Yang C <[EMAIL PROTECTED]>
To: Julius Squeezer <[EMAIL PROTECTED]>
Subject: RE: Run an Acive Directory query from a server that is not in a
domain
Date: Tue, 18 Sep 2007 22:06:46 -0400
You may need to import lmhosts file to make domain's ntebios name available
to your alone server.> From: [EMAIL PROTECTED]> To: perl-ldap@perl.org>
Subject: Run an Acive Directory query from a server that is not in a
domain> Date: Wed, 19 Sep 2007 01:50:40 +0600> > Hello> > The code works
fine running from my workstation, which is in a domain. > Whenever I move
it to the server that is not in any domain I get error. So, > how do I run
an Acive Directory query from a server that is not in a domain? > Tried NET
USE to authenticate to active directory before running the code, > NETUSE
command was successful but the code couldn't contact the domain ("the >
specified domain either does not exist or could not be contacted"). Any
help > is appreciated> > The following binds ok: But what if I need to do
an anonymous search without > using> any DN or username or pass?> > use
Win32::OLE;> my $DSO = Win32::OLE->GetObject('LDAP:');> >
$DSO->OpenDSObject('LDAP://DOMAINCONTROLLER/cn=username,OU=Users,DC=MYCORP,DC=COM',>
'[EMAIL PROTECTED]',> 'pass',> 0) )> How does the search function change
for anonymous search from a detached> host? If I put
LDAP://DOMAINCONTROLLER/ in the search string base it> generates error> >
sub SearchUser {> > my $searchterm = shift;> > my $strFilter =
"((sn=$searchterm));";> my $strAttrs = "distinguishedName;";> my $strScope
= "subtree";> my $strBase = "<LDAP://" . $strDomainDN . ">;";> > my
$objConn = Win32::OLE->CreateObject("ADODB.Connection");>
$objConn->{Provider} = "ADsDSOObject";> $objConn->Open;> my $objRS =
$objConn->Execute($strBase . $strFilter . $strAttrs .> $strScope);>
$objRS->MoveFirst;> > while (not $objRS->EOF) {> > $strUserDN =
$objRS->Fields(0)->Value;> $objRS->MoveNext;> }> > Sincerely> >
_________________________________________________________________> Don't
just search. Find. Check out the new MSN Search! > http://search.msn.com/>
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/