Jump to content


Photo

passing bound ldap connection?


  • Please log in to reply
No replies to this topic

#1 anner

anner
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 25 October 2006 - 01:36 PM

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:

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);
}

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

//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);
        }

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. 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users