Jump to content

Archived

This topic is now archived and is closed to further replies.

anner

passing bound ldap connection?

Recommended Posts

I have a bunch of code (40+ scripts) for an admin interface, many of which perform ldap searches, adds, and/or modifies.  All need to bind to the same server with the same ID, so I tried putting the connection into and included file:

[code]function open_ldap_conn() {

$host = get_my_host();
if (strstr($host,"test")) { $ldapServer = "test.ldap.server";}
else { $ldapServer = "live.ldap.server"; }

//try and connect to ldap server
$ds = ldap_connect($ldapServer);
if (!$ds) {die('Cannot Connect to LDAP server');}

$domadlogin = "cn=admin";
$domadpw = "mypass";

//bind to ldap server
$ldapBind = ldap_bind($ds,$domadlogin,$domadpw);
if (!$ldapBind) {die('Cannot Bind to LDAP server');}

return($ds);
}[/code]

Now, it appears to be executing the included code without issue, but when I try and us the connection it fails:

[code]//Check for list existance
$ds = open_ldap_conn();
$Base = "ou=whitepages,o=my_o,c=us";
list($List, $dummy) = split("@",$ListName);
$Filter = "(cn=$List)";    # LDAP search filter
$sr = ldap_search($ds,$Base,$Filter);
if (!$sr) {log_error("List duplicate check failed<br>", 1); return(1);}
if (ldap_first_entry($ds, $sr))
        { ncmail_log_error("A list already exists with this name.  Please choose a new name for your list.<br>", 1);
        return(1);
        }
[/code]

With error:
warning: ldap_search(): supplied argument is not a valid ldap link resource
and my output: List duplicate check failed

Is it not possible to do this?  It seems silly to have to include the code for the connect in more than 40 different places when it's the exactly the same code over and over. 

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.