示例#1
0
function get_admins()
{
    global $error, $ds, $cached_admins;
    global $ldap_admin_group_name, $ldap_admin_group_attr, $ldap_admin_group_type;
    if (!empty($cached_admins)) {
        return $cached_admins;
    }
    $cached_admins = array();
    if ($r = connect_and_bind()) {
        $search_filter = "({$ldap_admin_group_attr}=*)";
        $sr = @ldap_search($ds, $ldap_admin_group_name, $search_filter, array($ldap_admin_group_attr));
        if (!$sr) {
            $error = 'Error searching LDAP server: ' . ldap_error($ds);
        } else {
            $admins = ldap_get_entries($ds, $sr);
            for ($x = 0; $x < $admins[0][$ldap_admin_group_attr]['count']; $x++) {
                if ($ldap_admin_group_type != 'posixgroup') {
                    $cached_admins[] = stripdn($admins[0][$ldap_admin_group_attr][$x]);
                } else {
                    $cached_admins[] = $admins[0][$ldap_admin_group_attr][$x];
                }
            }
            @ldap_free_result($sr);
        }
        @ldap_close($ds);
    }
    return $cached_admins;
}
function get_admins()
{
    global $error, $ldap_server, $ldap_port;
    global $ldap_admin_dn, $ldap_admin_pwd;
    global $ldap_admin_group_name, $ldap_admin_group_attr;
    global $cached_admins;
    if (!empty($cached_admins)) {
        return $cached_admins;
    }
    $cached_admins = array();
    $ds = @ldap_connect($ldap_server, $ldap_port);
    if (!$ds) {
        $error = "Error connecting to LDAP server";
    } else {
        if ($ds) {
            if ($ldap_admin_dn != "") {
                // bind as administrator
                $r = @ldap_bind($ds, $ldap_admin_dn, $ldap_admin_pwd);
            } else {
                $r = @ldap_bind($ds);
                // bind as anonymous
            }
            if (!$r) {
                $error = "Invalid Admin's login for LDAP Server";
            } else {
                $search_filter = "({$ldap_admin_group_attr}=*)";
                $sr = @ldap_search($ds, $ldap_admin_group_name, $search_filter);
                $admins = ldap_get_entries($ds, $sr);
                for ($x = 0; $x <= $admins[0][$ldap_admin_group_attr]["count"]; $x++) {
                    $cached_admins[] = stripdn($admins[0][$ldap_admin_group_attr][$x]);
                }
                @ldap_free_result($sr);
            }
            @ldap_close($ds);
        }
    }
    $cached_admins_found = true;
    return $cached_admins;
}