function get_userid($username)
{
    global $config, $ds;
    $user_id = auth_ldap_session_cache_get('userid');
    if (isset($user_id)) {
        return $user_id;
    } else {
        $user_id = -1;
    }
    $filter = '(' . $config['auth_ldap_prefix'] . $username . ')';
    $search = ldap_search($ds, trim($config['auth_ldap_suffix'], ','), $filter);
    $entries = ldap_get_entries($ds, $search);
    if ($entries['count']) {
        $user_id = $entries[0]['uidnumber'][0];
    }
    auth_ldap_session_cache_set('userid', $user_id);
    return $user_id;
}
Example #2
0
function get_userid($username)
{
    global $config, $ldap_connection;
    $user_id = auth_ldap_session_cache_get('userid');
    if (isset($user_id)) {
        return $user_id;
    } else {
        $user_id = -1;
    }
    $attributes = array('objectsid');
    $search = ldap_search($ldap_connection, $config['auth_ad_base_dn'], get_auth_ad_user_filter($username), $attributes);
    $entries = ldap_get_entries($ldap_connection, $search);
    if ($entries['count']) {
        $user_id = preg_replace('/.*-(\\d+)$/', '$1', sid_from_ldap($entries[0]['objectsid'][0]));
    }
    auth_ldap_session_cache_set('userid', $user_id);
    return $user_id;
}