<commit_before><?php


function get_ldap_array($host,$port,$bind_pwd,$bind_dn,$basedn,$ldap_filter_attr,$ldap_search_attr,$toolkits_username,$password,$xerte_toolkits_site){

    $ldap_search_attr = array('firstname' => 'givenname', 'lastname' => 'sn');

    $ldapbind = null;

    $ds = @ldap_connect($host, (int)$port);
    if(!$ds) {
        _debug("Failed to connect to LDAP server - something is probably slightly wrong - " . ldap_error());
        return false;
    }

    if($bind_pwd!=""){

        @ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);


        if ($bind_dn != '') {

            $ldapbind = @ldap_bind($ds, $bind_dn, $bind_pwd);

            $sr = @ldap_search($ds, $basedn, "cn=" . $toolkits_username, array_values($ldap_search_attr));

            if(!$sr){

                /*
                 * login has failed
                 */

                ldap_close($ds);

                return false;

            }




            $entry = ldap_get_entries($ds, $sr);



            if(! $entry or ! $entry[0]) {

                ldap_close($ds);

                return false;

            }else{

                if(@ldap_bind($ds, $entry[0]['dn'], $password) ) {

                    /*
                     * valid login, so return true
                     */

                    ldap_close($ds);

                    return $entry;

                }

            }

        }


    }else{

        $filter   = $xerte_toolkits_site->LDAP_filter . $toolkits_username;

        $ldapConnection = ldap_connect($host, (int)$port);

        $ldapSearchResult = @ldap_search($ldapConnection, $basedn, $filter );

        $ldapSearchArray = @ldap_get_entries($ldapConnection, $ldapSearchResult);

        $userBaseDn = $ldapSearchArray[0]["dn"];

        /*
         * Bind with password & baseDN
         */

        @ldap_set_option($ds, LDAP_OPT_REFERRALS,0);

        if ($ldapConnection){

            if (@ldap_bind($ldapConnection, $userBaseDn, $password)){

                $entry = ldap_get_entries($ldapConnection, $ldapSearchResult);

                if(!$entry or !$entry[0]){

                    ldap_close($ds);

                    return false;

                }else{

                    return $entry;

                }

            }else{

                return false;

            }

        }

        ldap_close($ldapConnection);


    }	

}

//////////////////////////

function get_user_ldap($host,$port,$bind_pwd,$bind_dn,$basedn,$ldap_filter,$ldap_filter_attr,$eureka_username,$password,$eureka_site){

    if($bind_pwd!=""){

        $ldap_search_attr = array('firstname' => 'givenname', 'lastname' => 'sn');

        $ldapbind = null;

        $ds = @ldap_connect($host, (int)$port);

        @ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);

        if ($ds) {

            if ($bind_dn != '') {

                $ldapbind = @ldap_bind($ds, $bind_dn, $bind_pwd);
<commit_msg>do not try and set ldap option unless we have connected (login_library.php; see r207 in trunk)<commit_after><?php


function get_ldap_array($host,$port,$bind_pwd,$bind_dn,$basedn,$ldap_filter_attr,$ldap_search_attr,$toolkits_username,$password,$xerte_toolkits_site){

    $ldap_search_attr = array('firstname' => 'givenname', 'lastname' => 'sn');

    $ldapbind = null;

    $ds = @ldap_connect($host, (int)$port);
    if(!$ds) {
        _debug("Failed to connect to LDAP server - something is probably slightly wrong - " . ldap_error());
        return false;
    }

    if($bind_pwd!=""){

        @ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);


        if ($bind_dn != '') {

            $ldapbind = @ldap_bind($ds, $bind_dn, $bind_pwd);

            $sr = @ldap_search($ds, $basedn, "cn=" . $toolkits_username, array_values($ldap_search_attr));

            if(!$sr){

                /*
                 * login has failed
                 */

                ldap_close($ds);

                return false;

            }




            $entry = ldap_get_entries($ds, $sr);



            if(! $entry or ! $entry[0]) {

                ldap_close($ds);

                return false;

            }else{

                if(@ldap_bind($ds, $entry[0]['dn'], $password) ) {

                    /*
                     * valid login, so return true
                     */

                    ldap_close($ds);

                    return $entry;

                }

            }

        }


    }else{

        $filter   = $xerte_toolkits_site->LDAP_filter . $toolkits_username;

        $ldapConnection = ldap_connect($host, (int)$port);

        $ldapSearchResult = @ldap_search($ldapConnection, $basedn, $filter );

        $ldapSearchArray = @ldap_get_entries($ldapConnection, $ldapSearchResult);

        $userBaseDn = $ldapSearchArray[0]["dn"];

        /*
         * Bind with password & baseDN
         */

        @ldap_set_option($ds, LDAP_OPT_REFERRALS,0);

        if ($ldapConnection){

            if (@ldap_bind($ldapConnection, $userBaseDn, $password)){

                $entry = ldap_get_entries($ldapConnection, $ldapSearchResult);

                if(!$entry or !$entry[0]){

                    ldap_close($ds);

                    return false;

                }else{

                    return $entry;

                }

            }else{

                return false;

            }

        }

        ldap_close($ldapConnection);


    }	

}

//////////////////////////

function get_user_ldap($host,$port,$bind_pwd,$bind_dn,$basedn,$ldap_filter,$ldap_filter_attr,$eureka_username,$password,$eureka_site){

    if($bind_pwd!=""){

        $ldap_search_attr = array('firstname' => 'givenname', 'lastname' => 'sn');

        $ldapbind = null;

        $ds = @ldap_connect($host, (int)$port);

        if ($ds) {
            @ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
            if ($bind_dn != '') {
                $ldapbind = @ldap_bind($ds, $bind_dn, $bind_pwd);

{'fraction_non_alphanumeric': 0.14664429530201342, 'fraction_numerical': 0.0028523489932885905, 'mean_word_length': 1.7546210720887245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '801886', 'n_tokens_mistral': 2012, 'n_tokens_neox': 1831, 'n_words': 297}