Ignore:
Timestamp:
06/29/07 15:17:46 (17 years ago)
Author:
niltonneto
Message:

Versão nova do ADODB (4.5 para 4.95)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpgwapi/inc/adodb/drivers/adodb-ldap.inc.php

    r2 r34  
    11<?php 
    22/* 
    3   V4.51 29 July 2004  (c) 2000-2004 John Lim (jlim#natsoft.com.my). All rights reserved. 
     3  V4.94 23 Jan 2007  (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved. 
    44   Released under both BSD license and Lesser GPL library license.  
    55  Whenever there is any discrepancy between the two licenses,  
     
    77  Set tabs to 8. 
    88   
     9  Revision 1: (02/25/2005) Updated codebase to include the _inject_bind_options function. This allows 
     10  users to access the options in the ldap_set_option function appropriately. Most importantly 
     11  LDAP Version 3 is now supported. See the examples for more information. Also fixed some minor 
     12  bugs that surfaced when PHP error levels were set high. 
    913   
    1014  Joshua Eldridge (joshuae74#hotmail.com) 
     
    1317// security - hide paths 
    1418if (!defined('ADODB_DIR')) die(); 
     19 
     20if (!defined('LDAP_ASSOC')) { 
     21         define('LDAP_ASSOC',ADODB_FETCH_ASSOC); 
     22         define('LDAP_NUM',ADODB_FETCH_NUM); 
     23         define('LDAP_BOTH',ADODB_FETCH_BOTH); 
     24} 
    1525 
    1626class ADODB_ldap extends ADOConnection { 
     
    2535    var $filter; 
    2636    var $dn; 
    27  
     37        var $version; 
     38        var $port = 389; 
     39 
     40        # Options configuration information 
     41        var $LDAP_CONNECT_OPTIONS; 
    2842 
    2943        function ADODB_ldap()  
    3044        {                
    31  
    3245        } 
    3346                 
    3447        // returns true or false 
    3548         
    36         function _connect( $host, $username, $password, $ldapbase ) 
    37         { 
    38  
    39            if ( !function_exists( 'ldap_connect' ) ) return null; 
    40             
    41            $conn_info = array( $host ); 
    42             
    43            if ( strstr( $host, ':' ) ) { 
    44                $conn_info = split( ':', $host ); 
    45            }  
    46  
    47            $this->_connectionID = ldap_connect( $conn_info[0], $conn_info[1] )  
    48                or die( 'Could not connect to ' . $this->_connectionID ); 
    49            if ($username && $password) { 
    50                $bind = ldap_bind( $this->_connectionID, $username, $password )  
    51                    or die( 'Could not bind to ' . $this->_connectionID . ' with $username & $password'); 
    52            } else { 
    53                $bind = ldap_bind( $this->_connectionID )  
    54                    or die( 'Could not bind anonymously to ' . $this->_connectionID ); 
    55            } 
    56            return $this->_connectionID; 
    57     } 
     49        function _connect( $host, $username, $password, $ldapbase) 
     50        { 
     51        global $LDAP_CONNECT_OPTIONS; 
     52                 
     53                if ( !function_exists( 'ldap_connect' ) ) return null; 
     54                 
     55                $conn_info = array( $host,$this->port); 
     56                 
     57                if ( strstr( $host, ':' ) ) { 
     58                    $conn_info = split( ':', $host ); 
     59                }  
     60                 
     61                $this->_connectionID = ldap_connect( $conn_info[0], $conn_info[1] ); 
     62                if (!$this->_connectionID) { 
     63                        $e = 'Could not connect to ' . $conn_info[0]; 
     64                        $this->_errorMsg = $e; 
     65                        if ($this->debug) ADOConnection::outp($e); 
     66                        return false; 
     67                } 
     68                if( count( $LDAP_CONNECT_OPTIONS ) > 0 ) { 
     69                        $this->_inject_bind_options( $LDAP_CONNECT_OPTIONS ); 
     70                } 
     71                 
     72                if ($username) { 
     73                    $bind = ldap_bind( $this->_connectionID, $username, $password ); 
     74                } else { 
     75                        $username = 'anonymous'; 
     76                    $bind = ldap_bind( $this->_connectionID );           
     77                } 
     78                 
     79                if (!$bind) { 
     80                        $e = 'Could not bind to ' . $conn_info[0] . " as ".$username; 
     81                        $this->_errorMsg = $e; 
     82                        if ($this->debug) ADOConnection::outp($e); 
     83                        return false; 
     84                } 
     85                $this->_errorMsg = ''; 
     86                $this->database = $ldapbase; 
     87                return $this->_connectionID; 
     88        } 
    5889     
     90/* 
     91        Valid Domain Values for LDAP Options: 
     92 
     93        LDAP_OPT_DEREF (integer) 
     94        LDAP_OPT_SIZELIMIT (integer) 
     95        LDAP_OPT_TIMELIMIT (integer) 
     96        LDAP_OPT_PROTOCOL_VERSION (integer) 
     97        LDAP_OPT_ERROR_NUMBER (integer) 
     98        LDAP_OPT_REFERRALS (boolean) 
     99        LDAP_OPT_RESTART (boolean) 
     100        LDAP_OPT_HOST_NAME (string) 
     101        LDAP_OPT_ERROR_STRING (string) 
     102        LDAP_OPT_MATCHED_DN (string) 
     103        LDAP_OPT_SERVER_CONTROLS (array) 
     104        LDAP_OPT_CLIENT_CONTROLS (array) 
     105 
     106        Make sure to set this BEFORE calling Connect() 
     107 
     108        Example: 
     109 
     110        $LDAP_CONNECT_OPTIONS = Array( 
     111                Array ( 
     112                        "OPTION_NAME"=>LDAP_OPT_DEREF, 
     113                        "OPTION_VALUE"=>2 
     114                ), 
     115                Array ( 
     116                        "OPTION_NAME"=>LDAP_OPT_SIZELIMIT, 
     117                        "OPTION_VALUE"=>100 
     118                ), 
     119                Array ( 
     120                        "OPTION_NAME"=>LDAP_OPT_TIMELIMIT, 
     121                        "OPTION_VALUE"=>30 
     122                ), 
     123                Array ( 
     124                        "OPTION_NAME"=>LDAP_OPT_PROTOCOL_VERSION, 
     125                        "OPTION_VALUE"=>3 
     126                ), 
     127                Array ( 
     128                        "OPTION_NAME"=>LDAP_OPT_ERROR_NUMBER, 
     129                        "OPTION_VALUE"=>13 
     130                ), 
     131                Array ( 
     132                        "OPTION_NAME"=>LDAP_OPT_REFERRALS, 
     133                        "OPTION_VALUE"=>FALSE 
     134                ), 
     135                Array ( 
     136                        "OPTION_NAME"=>LDAP_OPT_RESTART, 
     137                        "OPTION_VALUE"=>FALSE 
     138                ) 
     139        ); 
     140*/ 
     141 
     142        function _inject_bind_options( $options ) { 
     143                foreach( $options as $option ) { 
     144                        ldap_set_option( $this->_connectionID, $option["OPTION_NAME"], $option["OPTION_VALUE"] ) 
     145                                or die( "Unable to set server option: " . $option["OPTION_NAME"] ); 
     146                } 
     147        } 
    59148         
    60149        /* returns _queryID or false */ 
    61150        function _query($sql,$inputarr) 
    62151        { 
    63            $rs = ldap_search( $this->_connectionID, $this->database, $sql ); 
    64        return $rs;  
    65                  
     152                $rs = ldap_search( $this->_connectionID, $this->database, $sql ); 
     153                $this->_errorMsg = ($rs) ? '' : 'Search error on '.$sql; 
     154                return $rs;  
    66155        } 
    67156 
     
    73162        } 
    74163     
     164        function SelectDB($db) { 
     165                $this->database = $db; 
     166                return true; 
     167        } // SelectDB 
     168 
    75169    function ServerInfo() 
    76170    { 
    77         if( is_array( $this->version ) ) return $this->version; 
     171        if( !empty( $this->version ) ) return $this->version; 
    78172        $version = array(); 
    79173        /* 
     
    161255        /* The host name (or list of hosts) for the primary LDAP server. */ 
    162256        ldap_get_option( $this->_connectionID, LDAP_OPT_HOST_NAME, $version['LDAP_OPT_HOST_NAME'] );  
    163         ldap_get_option( $this->_connectionID, OPT_ERROR_NUMBER, $version['OPT_ERROR_NUMBER'] );  
    164         ldap_get_option( $this->_connectionID, OPT_ERROR_STRING, $version['OPT_ERROR_STRING'] );  
     257        ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_NUMBER, $version['LDAP_OPT_ERROR_NUMBER'] );  
     258        ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_STRING, $version['LDAP_OPT_ERROR_STRING'] );  
    165259        ldap_get_option( $this->_connectionID, LDAP_OPT_MATCHED_DN, $version['LDAP_OPT_MATCHED_DN'] );  
    166260         
     
    194288                  $this->fetchMode = LDAP_ASSOC;  
    195289                break; 
    196                 default: 
    197290                case ADODB_FETCH_DEFAULT: 
    198291                case ADODB_FETCH_BOTH:  
     292                default: 
    199293                  $this->fetchMode = LDAP_BOTH;  
    200294                break; 
     
    293387             
    294388            case LDAP_NUM: 
    295             $this->fields = $this->GetRowNums(); 
     389                        $this->fields = array_merge($this->GetRowNums(),$this->GetRowAssoc()); 
    296390            break; 
    297391             
    298392            case LDAP_BOTH: 
    299393            default: 
     394                        $this->fields = $this->GetRowNums(); 
    300395            break; 
    301396        } 
Note: See TracChangeset for help on using the changeset viewer.