/**
 * search ldap server
 *
 * Tries connect to specified ldap server.
 * Returns connection result or error.
 *
 * @return search result
 */
function cas_ldapSearch($uid)
{
    $config = elgg_get_plugin_from_id(PLUGIN_ID);
    // Connect to the ldap server now
    $ldap_connection = cas_ldapConnect();
    if (!$ldap_connection) {
        register_error(elgg_echo('au_cas_auth:ldap:connect:fail'));
        return null;
    }
    //@todo - make sure this is a setting
    $ldap_context = $config->ldap_context;
    $ldap_search_pattern = "(uid={$uid})";
    // NB: requesting textuid but getting back textUid
    // request textUid? (IOW, is ldap case insensitive?)
    $ldap_fields_wanted = array('uid', 'cn', 'mail', 'textuid');
    $ldap_result = @ldap_search($ldap_connection, $ldap_context, $ldap_search_pattern, $ldap_fields_wanted);
    /* check and push results */
    $records = ldap_get_entries($ldap_connection, $ldap_result);
    // NOTE: ldap_get_entries returns array indices in lowercase.
    if (!$records) {
        register_error(elgg_echo('au_cas_auth:ldap:no_records'));
        return null;
    }
    $record["dn"] = $records[0]["dn"];
    $record["cn"] = $records[0]["cn"][0];
    $record["uid"] = $records[0]["uid"][0];
    $record["mail"] = $records[0]["mail"][0];
    if (isset($records[0]["textuid"][0])) {
        $record["textUid"] = $records[0]["textuid"][0];
    }
    ldap_close($ldap_connection);
    return $record;
}
Esempio n. 2
0
/**
 * search ldap server
 *
 * Tries connect to specified ldap server.
 * Returns connection result or error.
 *
 * @return search result
 */
function cas_ldapSearch($uid)
{
    global $CONFIG, $messages;
    $config = elgg_get_plugin_from_id('cas_auth');
    // Connect to the ldap server now
    $ldap_connection = cas_ldapConnect();
    if (!$ldap_connection) {
        $messages[] = __gettext("Unable to connect to LDAP server");
        return null;
    }
    $ldap_context = $config->ldap_context;
    $ldap_search_pattern = "(uid={$uid})";
    $ldap_fields_wanted = array('uid', 'cn', 'mail', 'textuid');
    $ldap_context = 'ou=People,dc=athabascau,dc=ca';
    $ldap_result = @ldap_search($ldap_connection, $ldap_context, $ldap_search_pattern, $ldap_fields_wanted);
    /* check and push results */
    $records = ldap_get_entries($ldap_connection, $ldap_result);
    // NOTE: ldap_get_entries returns array indices in lowercase.
    if (!$records) {
        $messages[] = 'No records found.';
        return null;
    }
    $record["dn"] = $records[0]["dn"];
    $record["cn"] = $records[0]["cn"][0];
    $record["uid"] = $records[0]["uid"][0];
    $record["mail"] = $records[0]["mail"][0];
    if (isset($records[0]["textuid"][0])) {
        $record["textUid"] = $records[0]["textuid"][0];
    }
    ldap_close($ldap_connection);
    return $record;
}