18 if (!defined(
'ADODB_DIR'))
die();
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);
30 # Connection information 34 # Used during searches 40 # Options configuration information 43 # error on binding, eg. "Binding: invalid credentials" 56 if ( !function_exists(
'ldap_connect' ) )
return null;
58 if (strpos(
$host,
'ldap://') === 0 || strpos(
$host,
'ldaps://') === 0) {
59 $this->_connectionID = @ldap_connect(
$host);
61 $conn_info = array(
$host,$this->port);
63 if ( strstr(
$host,
':' ) ) {
64 $conn_info = explode(
':',
$host );
67 $this->_connectionID = @ldap_connect( $conn_info[0], $conn_info[1] );
69 if (!$this->_connectionID) {
70 $e =
'Could not connect to ' . $conn_info[0];
71 $this->_errorMsg = $e;
72 if ($this->
debug) ADOConnection::outp($e);
75 if( count( $LDAP_CONNECT_OPTIONS ) > 0 ) {
80 $bind = @ldap_bind( $this->_connectionID, $username, $password );
82 $username =
'anonymous';
83 $bind = @ldap_bind( $this->_connectionID );
87 $e = sprintf($this->_bind_errmsg,ldap_error($this->_connectionID));
88 $this->_errorMsg = $e;
89 if ($this->
debug) ADOConnection::outp($e);
92 $this->_errorMsg =
'';
93 $this->database = $ldapbase;
94 return $this->_connectionID;
150 foreach( $options as $option ) {
151 ldap_set_option( $this->_connectionID, $option[
"OPTION_NAME"], $option[
"OPTION_VALUE"] )
152 or
die(
"Unable to set server option: " . $option[
"OPTION_NAME"] );
159 $rs = @ldap_search( $this->_connectionID, $this->database,
$sql );
160 $this->_errorMsg = (
$rs) ?
'' :
'Search error on '.
$sql.
': '.ldap_error($this->_connectionID);
166 return $this->_errorMsg;
171 return @ldap_errno($this->_connectionID);
177 @ldap_close( $this->_connectionID );
178 $this->_connectionID =
false;
182 $this->database = $db;
201 ldap_get_option( $this->_connectionID, LDAP_OPT_DEREF, $version[
'LDAP_OPT_DEREF'] ) ;
202 switch ( $version[
'LDAP_OPT_DEREF'] ) {
204 $version[
'LDAP_OPT_DEREF'] =
'LDAP_DEREF_NEVER';
206 $version[
'LDAP_OPT_DEREF'] =
'LDAP_DEREF_SEARCHING';
208 $version[
'LDAP_OPT_DEREF'] =
'LDAP_DEREF_FINDING';
210 $version[
'LDAP_OPT_DEREF'] =
'LDAP_DEREF_ALWAYS';
218 ldap_get_option( $this->_connectionID, LDAP_OPT_SIZELIMIT, $version[
'LDAP_OPT_SIZELIMIT'] );
219 if ( $version[
'LDAP_OPT_SIZELIMIT'] == 0 ) {
220 $version[
'LDAP_OPT_SIZELIMIT'] =
'LDAP_NO_LIMIT';
228 ldap_get_option( $this->_connectionID, LDAP_OPT_TIMELIMIT, $version[
'LDAP_OPT_TIMELIMIT'] );
229 if ( $version[
'LDAP_OPT_TIMELIMIT'] == 0 ) {
230 $version[
'LDAP_OPT_TIMELIMIT'] =
'LDAP_NO_LIMIT';
239 ldap_get_option( $this->_connectionID, LDAP_OPT_REFERRALS, $version[
'LDAP_OPT_REFERRALS'] );
240 if ( $version[
'LDAP_OPT_REFERRALS'] == 0 ) {
241 $version[
'LDAP_OPT_REFERRALS'] =
'LDAP_OPT_OFF';
243 $version[
'LDAP_OPT_REFERRALS'] =
'LDAP_OPT_ON';
252 ldap_get_option( $this->_connectionID, LDAP_OPT_RESTART, $version[
'LDAP_OPT_RESTART'] );
253 if ( $version[
'LDAP_OPT_RESTART'] == 0 ) {
254 $version[
'LDAP_OPT_RESTART'] =
'LDAP_OPT_OFF';
256 $version[
'LDAP_OPT_RESTART'] =
'LDAP_OPT_ON';
265 ldap_get_option( $this->_connectionID, LDAP_OPT_PROTOCOL_VERSION, $version[
'LDAP_OPT_PROTOCOL_VERSION'] );
266 if ( $version[
'LDAP_OPT_PROTOCOL_VERSION'] == 2 ) {
267 $version[
'LDAP_OPT_PROTOCOL_VERSION'] =
'LDAP_VERSION2';
269 $version[
'LDAP_OPT_PROTOCOL_VERSION'] =
'LDAP_VERSION3';
273 ldap_get_option( $this->_connectionID, LDAP_OPT_HOST_NAME, $version[
'LDAP_OPT_HOST_NAME'] );
274 ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_NUMBER, $version[
'LDAP_OPT_ERROR_NUMBER'] );
275 ldap_get_option( $this->_connectionID, LDAP_OPT_ERROR_STRING, $version[
'LDAP_OPT_ERROR_STRING'] );
276 ldap_get_option( $this->_connectionID, LDAP_OPT_MATCHED_DN, $version[
'LDAP_OPT_MATCHED_DN'] );
290 var $canSeek =
false;
295 if ($mode ===
false) {
296 global $ADODB_FETCH_MODE;
297 $mode = $ADODB_FETCH_MODE;
301 case ADODB_FETCH_NUM:
302 $this->fetchMode = LDAP_NUM;
304 case ADODB_FETCH_ASSOC:
305 $this->fetchMode = LDAP_ASSOC;
307 case ADODB_FETCH_DEFAULT:
308 case ADODB_FETCH_BOTH:
310 $this->fetchMode = LDAP_BOTH;
314 $this->ADORecordSet($queryID);
324 $this->_numOfRows = ldap_count_entries( $this->connection->_connectionID, $this->_queryID );
331 function GetAssoc($force_array =
false, $first2cols =
false)
333 $records = $this->_numOfRows;
335 for ( $i=0; $i < $records; $i++ ) {
336 foreach ( $this->fields as $k=>$v ) {
337 if ( is_array( $v ) ) {
338 if ( $v[
'count'] == 1 ) {
339 $results[$i][$k] = $v[0];
342 $results[$i][$k] = $v;
354 foreach ( $this->fields as $k=>$v ) {
355 if ( is_array( $v ) ) {
356 if ( $v[
'count'] == 1 ) {
357 $results[$k] = $v[0];
371 foreach ( $this->fields as $k=>$v ) {
373 if (is_array( $v )) {
374 if ( $v[
'count'] == 1 ) {
375 $results[$i] = $v[0];
388 if ( $this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0 )
391 if ( $this->_currentRow == 0 ) {
392 $this->_entryID = ldap_first_entry( $this->connection->_connectionID, $this->_queryID );
394 $this->_entryID = ldap_next_entry( $this->connection->_connectionID, $this->_entryID );
397 $this->fields = ldap_get_attributes( $this->connection->_connectionID, $this->_entryID );
398 $this->_numOfFields = $this->fields[
'count'];
399 switch ( $this->fetchMode ) {
402 $this->fields = $this->GetRowAssoc();
406 $this->fields = array_merge($this->GetRowNums(),$this->GetRowAssoc());
411 $this->fields = $this->GetRowNums();
414 return ( is_array( $this->fields ) );
418 @ldap_free_result( $this->_queryID );
419 $this->_queryID =
false;
if(isset($_REQUEST['nrows'])) else $rs
ADORecordSet_ldap($queryID, $mode=false)
GetAssoc($force_array=false, $first2cols=false)
_inject_bind_options( $options)
debug($variable='', $name=' *variable *', $line=' *line *', $file=' *file *', $recursiveDepth=3, $debugLevel=E_DEBUG)
_query($sql, $inputarr=false)
_connect( $host, $username, $password, $ldapbase)