Changeset 34 for trunk/phpgwapi/inc/adodb/drivers/adodb-ldap.inc.php
- Timestamp:
- 06/29/07 15:17:46 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpgwapi/inc/adodb/drivers/adodb-ldap.inc.php
r2 r34 1 1 <?php 2 2 /* 3 V4. 51 29 July 2004 (c) 2000-2004John 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. 4 4 Released under both BSD license and Lesser GPL library license. 5 5 Whenever there is any discrepancy between the two licenses, … … 7 7 Set tabs to 8. 8 8 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. 9 13 10 14 Joshua Eldridge (joshuae74#hotmail.com) … … 13 17 // security - hide paths 14 18 if (!defined('ADODB_DIR')) die(); 19 20 if (!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 } 15 25 16 26 class ADODB_ldap extends ADOConnection { … … 25 35 var $filter; 26 36 var $dn; 27 37 var $version; 38 var $port = 389; 39 40 # Options configuration information 41 var $LDAP_CONNECT_OPTIONS; 28 42 29 43 function ADODB_ldap() 30 44 { 31 32 45 } 33 46 34 47 // returns true or false 35 48 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 } 58 89 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 } 59 148 60 149 /* returns _queryID or false */ 61 150 function _query($sql,$inputarr) 62 151 { 63 64 return $rs; 65 152 $rs = ldap_search( $this->_connectionID, $this->database, $sql ); 153 $this->_errorMsg = ($rs) ? '' : 'Search error on '.$sql; 154 return $rs; 66 155 } 67 156 … … 73 162 } 74 163 164 function SelectDB($db) { 165 $this->database = $db; 166 return true; 167 } // SelectDB 168 75 169 function ServerInfo() 76 170 { 77 if( is_array( $this->version ) ) return $this->version;171 if( !empty( $this->version ) ) return $this->version; 78 172 $version = array(); 79 173 /* … … 161 255 /* The host name (or list of hosts) for the primary LDAP server. */ 162 256 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'] ); 165 259 ldap_get_option( $this->_connectionID, LDAP_OPT_MATCHED_DN, $version['LDAP_OPT_MATCHED_DN'] ); 166 260 … … 194 288 $this->fetchMode = LDAP_ASSOC; 195 289 break; 196 default:197 290 case ADODB_FETCH_DEFAULT: 198 291 case ADODB_FETCH_BOTH: 292 default: 199 293 $this->fetchMode = LDAP_BOTH; 200 294 break; … … 293 387 294 388 case LDAP_NUM: 295 $this->fields = $this->GetRowNums();389 $this->fields = array_merge($this->GetRowNums(),$this->GetRowAssoc()); 296 390 break; 297 391 298 392 case LDAP_BOTH: 299 393 default: 394 $this->fields = $this->GetRowNums(); 300 395 break; 301 396 }
Note: See TracChangeset
for help on using the changeset viewer.