Using COM & ADSI - Bracket Problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am working on a script using ADSI via COM in PHP.  The script works
for the most part when I query a user using the following function:

function passwordExpires($userDN) {
    $comLDAP = new COM('LDAP:');
    $getUser = $comLDAP->OpenDSObject('LDAP://' . $this->server . '/' .
$userDN, $this->domain . "\" . $this->user, $this->pass, 1);
    $dateParse = date_parse($getUser->passwordLastChanged);
    $today = time();
    $expDate = mktime($dateParse[hour],$dateParse[minute],
    $days = floor(($expDate-$today)/(60*60*24));
    $hours = floor(((($expDate-$today)/(60*60*24))- $days)*24);
    $dayText = ($days != 1)  ? " Days "  : " Day ";
    $hrsText = ($hours != 1) ? " Hours " : " Hour ";
    return ($days.$dayText.$hours.$hrsText);

This script works fine querying most distinguishedName values.  Where
I keep running into a problem is with a specific OU that has braces
'( )' in the name.  This has also occurred when the CN has a braces in
it. (eg "CN=Joe Smith (Department),OU=...")

I receive the following error in my php.log file:

PHP Fatal error:  Uncaught exception 'com_exception' with message
'<b>Source:</b> Unknown<br/><b>Description:</b> Unknown' in C:
Stack trace:
#0 C:\development\class.easyADSI.php(190): com->OpenDSObject('LDAP://
server....', 'DOMAIN\admin', 'password', 1)
#1 C:\development\class.easyADSI.php(271): EasyADSI-
Quoted text here. Click to load it
  thrown in C:\development\class.easyADSI.php on line 190

I know that the script is dying on:
$getUser = $comLDAP->OpenDSObject('LDAP://' . $this->server . '/' .
$userDN, $this->domain . "\" . $this->user, $this->pass, 1);

I know that the LDAP functions in PHP may be able to help but the
server does not have the LDAP function turned on in PHP so I must use

MSDN has helped out a little bit in explaining that I may need to
escape these characters (
aa366101(VS.85).aspx) but when I have tried the suggestions it still
errors out.

Can anyone give me a hand with this?

Re: Using COM & ADSI - Bracket Problem wrote:
Quoted text here. Click to load it

Answered in alt.php.  If you must post to multiple newsgroups, please
crosspost - don't multipost.  Thanks.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline