Getting Squirrelmail 1.4.15 - 1.4.17 to work with Active Directory under windows 2003

Submitted by rmiddle on Wed, 02/04/2009 - 19:12

<a href="http://www.middleswarth.us/wp-content/uploads/2009/02/abook_ldap_server.php_.txt">abook_ldap_server.php.</a>Following the example at http://www.linuxmail.info/squirrelmail-active-directory-ldap-addressbook/ it worked in that I received no errors and some records would get listed but the search would give me an error and it would only list a few items when I did a list all.

After some digging I found out that http://us2.php.net/manual/en/function.ldap-search.php#45388 AD under 2003 requires and extra option set in order to work. So I edited the file.

squirrelmail/functions/abook_ldap_server.php

and added the following code.

<code>
if(!empty($this-&gt;protocol)) {
if(!@ldap_set_option($this-&gt;linkid, LDAP_OPT_PROTOCOL_VERSION, $this-&gt;protocol)) {
if(function_exists('ldap_error')) {
return $this-&gt;set_error(ldap_error($this-&gt;linkid));
} else {
return $this-&gt;set_error('ldap_set_option failed');
}
}
}</code>

// New Code. Import this is needed for AD under 2k3.
if(!@ldap_set_option($this-&gt;linkid, LDAP_OPT_REFERRALS, 0)) {
if(function_exists('ldap_error')) {
return $this-&gt;set_error(ldap_error($this-&gt;linkid));
} else {
return $this-&gt;set_error('ldap_set_option failed');
}
}
// End of new code.
if(!empty($this-&gt;binddn)) {
if(!@ldap_bind($this-&gt;linkid, $this-&gt;binddn, $this-&gt;bindpw)) {
if(function_exists('ldap_error')) {
return $this-&gt;set_error(ldap_error($this-&gt;linkid));
} else {
return $this-&gt;set_error('authenticated ldap_bind failed');
}
}
} else {
if(!@ldap_bind($this-&gt;linkid)) {
if(function_exists('ldap_error')) {
return $this-&gt;set_error(ldap_error($this-&gt;linkid));
} else {
return $this-&gt;set_error('anonymous ldap_bind failed');
}
}
}

See the attachment for the full file.

Thanks
Robert