Jamroom to XMPIE uStore Bridge
Jamroom Developers
I got a little way towards LDAP authentication before I hit other problems with doing that.
This might help with making a connection and running a search
function ujLDAPauth_db_get_item_listener($_data, $_user, $_conf, $_args, $event)
{
global $_post;
if (isset($_post['module']) && $_post['module'] == 'jrUser' && $_post['option'] == 'login_save') {
$ip_address = 'xxxxxxxxx'; // ip address
$port = 'xxxxx'; // port
$ldappass = 'xxxxxxxx'; // your ldap password
$ldaprdn = 'CN=svc-lookup,OU=Services,DC=subdomain,DC=domain,DC=com'; // your domain name
// LDAP lookup
$ds = ldap_connect($ip_address,$port); // must be a valid LDAP server!
//fdebug("ds",$ds);// OK
if ($ds) {
//$r = ldap_bind($ds); // this is an "anonymous" bind, typically bind to ldap server with user / pass
$ldapbind = ldap_bind($ds, $ldaprdn, $ldappass);
// verify binding
if ($ldapbind) {
fdebug("LDAP bind successful...");// OK
} else {
fdebug("LDAP bind failed...");// OK
}
// Searching for username a34-jones
// echo "Searching for (sn=S*) ...";
// Search surname entry
//$sr = ldap_search($ds, "DC=subdomain,DC=domain,DC=com", "cn=a34-jones");
// echo "Searching for (sn=C*) ...";
// Search surname entry
// $sr=ldap_search($ds, "DC=subdomain,DC=domain,DC=com", "(uid=a34*)");
// //echo "Search result is " . $sr . "<br />";
// fdebug("search result (uid=a34*)",$sr);// OK
//
// fdebug( "Number of entries returned is " . ldap_count_entries($ds, $sr) . "<br />", $sr);// OK
//
// $sr=ldap_search($ds, "DC=subdomain,DC=domain,DC=com", "(sn=jo*)");
//
// fdebug("search result for sn=jo*",$sr);// OK
//
// $sr=ldap_search($ds, "DC=subdomain,DC=domain,DC=com", "(sn=a34*)");
//
// fdebug("search result (sn=a34*)",$sr);// OK
// ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$sr=ldap_search($ds, "DC=subdomain,DC=domain,DC=com", "cn=a34-jones");
if (!$sr) {
$err_number = ldap_errno($ds);
$err_txt = ldap_err2str($err_number);
}
fdebug("error", $err_txt, "search result sn=J*",$sr);
$info = ldap_get_entries($ds, $sr);
fdebug( "Data for " . $info["count"] . " items returned:<p>",$info);
// for ($i=0; $i<$info["count"]; $i++) {
// echo "dn is: " . $info[$i]["dn"] . "<br />";
// echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />";
// echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />";
// }
// Closing connection
ldap_close($ds);
}
} else {
return $_data;
}
return $_data;
}