SF Bug #2820854 - ldap_first_attribute error

This commit is contained in:
Deon George 2009-07-14 19:07:43 +10:00
parent 45ca83411f
commit bbe87c6e2f
4 changed files with 105 additions and 126 deletions

View File

@ -16,7 +16,7 @@ require './common.php';
$attrs = $app['server']->getRootDSE(); $attrs = $app['server']->getRootDSE();
$query = array(); $query = array();
$query['base'] = $attrs['monitorcontext']; $query['base'] = $attrs['monitorcontext'][0];
$query['scope'] = 'sub'; $query['scope'] = 'sub';
$query['attrs'] = array('+','*'); $query['attrs'] = array('+','*');
$results = $app['server']->query($query,null); $results = $app['server']->query($query,null);
@ -37,7 +37,7 @@ printf('<tr class="list_item"><td class="heading" rowspan=2>%s</td></tr>',_('LDA
printf('<tr class="list_item"><td class="value">'); printf('<tr class="list_item"><td class="value">');
echo '<table class="result" border=0>'; echo '<table class="result" border=0>';
printf('<tr><td>%s</td></tr>',$results['cn=Monitor']['monitoredInfo']); printf('<tr><td>%s</td></tr>',$results[$attrs['monitorcontext'][0]]['monitoredinfo'][0]);
echo '</table>'; echo '</table>';
echo '</td></tr>'; echo '</td></tr>';
@ -47,10 +47,7 @@ foreach (array(
'cn=Overlays,cn=Monitor' => 'cn=Overlay %s,%s' 'cn=Overlays,cn=Monitor' => 'cn=Overlay %s,%s'
) as $dn => $child) { ) as $dn => $child) {
if (is_array($results[$dn]['description']))
$description = implode(' ',$results[$dn]['description']); $description = implode(' ',$results[$dn]['description']);
else
$description = $results[$dn]['description'];
$description = preg_replace('/"/','\'',$description); $description = preg_replace('/"/','\'',$description);
printf('<tr class="list_item"><td class="heading" rowspan=2><acronym title="%s">%s</acronym></td></tr>',$description,$dn); printf('<tr class="list_item"><td class="heading" rowspan=2><acronym title="%s">%s</acronym></td></tr>',$description,$dn);
@ -59,8 +56,8 @@ foreach (array(
echo '<table class="result_table" border=0 width="100%">'; echo '<table class="result_table" border=0 width="100%">';
$attrs = array( $attrs = array(
'monitorRuntimeConfig', 'monitorruntimeconfig',
'supportedControl' 'supportedcontrol'
); );
echo '<tr class="highlight">'; echo '<tr class="highlight">';
@ -72,21 +69,23 @@ foreach (array(
echo '</tr>'; echo '</tr>';
$counter = 0; $counter = 0;
foreach ($results[$dn]['monitoredInfo'] as $index => $backend) { foreach ($results[$dn]['monitoredinfo'] as $index => $backend) {
printf('<tr class="%s">',$counter++%2==0?'even':'odd'); printf('<tr class="%s">',$counter++%2==0?'even':'odd');
printf('<td>%s</td>',$backend); printf('<td>%s</td>',$backend);
$key = sprintf($child,$index,$dn); $key = sprintf($child,$index,$dn);
echo '<td>'; echo '<td>';
if (isset($results[$key]['seeAlso'])) { if (isset($results[$key]['seealso'])) {
$seealso = is_array($results[$key]['seeAlso']) ? $results[$key]['seeAlso'] : array($results[$key]['seeAlso']); $seealso = is_array($results[$key]['seealso']) ? $results[$key]['seealso'] : array($results[$key]['seealso']);
foreach ($seealso as $db) foreach ($seealso as $db)
if (isset($results[$db]['namingContexts'])) if (isset($results[$db]['namingcontexts']))
printf('<acronym title="%s">%s</acronym><br/>',isset($results[$db]['labeledURI']) ? $results[$db]['labeledURI'] : _('Internal'),$results[$db]['namingContexts']); printf('<acronym title="%s">%s</acronym><br/>',
isset($results[$db]['labeleduri']) ? implode(' ',$results[$db]['labeleduri']) : _('Internal'),
implode(' ',$results[$db]['namingcontexts']));
else else
printf('%s ',$results[$db]['monitoredInfo']); printf('%s ',implode(' ',$results[$db]['monitoredinfo']));
} else { } else {
echo '&nbsp;'; echo '&nbsp;';
@ -101,7 +100,7 @@ foreach (array(
else else
$sc = $results[$key][$attr]; $sc = $results[$key][$attr];
if (strcasecmp('supportedControl',$attr) == 0) if (strcasecmp('supportedcontrol',$attr) == 0)
foreach ($sc as $control) { foreach ($sc as $control) {
$oidtotext = support_oid_to_text($control); $oidtotext = support_oid_to_text($control);
@ -133,44 +132,44 @@ echo '<table class="result"><tr><td>';
echo '<table class="result_table" border=0 width="100%">'; echo '<table class="result_table" border=0 width="100%">';
printf('<tr class="highlight"><td class="20%%">%s</td><td class="value" width="80%%">%s</td></tr>', printf('<tr class="highlight"><td class="20%%">%s</td><td class="value" width="80%%">%s</td></tr>',
_('Total Connections'),$results['cn=Total,cn=Connections,cn=Monitor']['monitorCounter']); _('Total Connections'),$results['cn=Total,cn=Connections,cn=Monitor']['monitorcounter']);
printf('<tr class="highlight"><td class="20%%">%s</td><td class="value" width="80%%">%s</td></tr>', printf('<tr class="highlight"><td class="20%%">%s</td><td class="value" width="80%%">%s</td></tr>',
_('Current Connections'),$results['cn=Current,cn=Connections,cn=Monitor']['monitorCounter']); _('Current Connections'),$results['cn=Current,cn=Connections,cn=Monitor']['monitorcounter']);
# Look for some connections # Look for some connections
foreach ($results as $key => $value) { foreach ($results as $key => $value) {
if (preg_match('/^cn=Connection.*,cn=Connections,cn=Monitor$/',$key)) { if (preg_match('/^cn=Connection.*,cn=Connections,cn=Monitor$/',$key)) {
echo '<tr class="highlight">'; echo '<tr class="highlight">';
printf('<td>%s</td>',$results[$key]['cn']); printf('<td>%s</td>',$results[$key]['cn'][0]);
echo '<td class="value">'; echo '<td class="value">';
echo '<table class="result_table" border=0 width="100%">'; echo '<table class="result_table" border=0 width="100%">';
$counter = 0; $counter = 0;
foreach (array( foreach (array(
'monitorConnectionActivityTime', 'monitorconnectionactivitytime',
'monitorConnectionAuthzDN', 'monitorconnectionauthzdn',
'monitorConnectionGet', 'monitorconnectionget',
'monitorConnectionListener', 'monitorconnectionlistener',
'monitorConnectionLocalAddress', 'monitorconnectionlocaladdress',
'monitorConnectionMask', 'monitorconnectionmask',
'monitorConnectionNumber', 'monitorconnectionnumber',
'monitorConnectionOpsCompleted', 'monitorconnectionopscompleted',
'monitorConnectionOpsExecuting', 'monitorconnectionopsexecuting',
'monitorConnectionOpsPending', 'monitorconnectionopspending',
'monitorConnectionOpsReceived', 'monitorconnectionopsreceived',
'monitorConnectionPeerAddress', 'monitorconnectionpeeraddress',
'monitorConnectionPeerDomain', 'monitorconnectionpeerdomain',
'monitorConnectionProtocol', 'monitorconnectionprotocol',
'monitorConnectionRead', 'monitorconnectionread',
'monitorConnectionStartTime', 'monitorconnectionstarttime',
'monitorConnectionWrite' 'monitorconnectionwrite'
) as $metric) { ) as $metric) {
printf('<tr class="%s">',$counter++%2==0?'even':'odd'); printf('<tr class="%s">',$counter++%2==0?'even':'odd');
printf('<td class="title" width="35%%">%s</td><td width="65%%">%s</td>', printf('<td class="title" width="35%%">%s</td><td width="65%%">%s</td>',
$metric,isset($results[$key][$metric]) ? $results[$key][$metric] : '&nbsp;'); $metric,isset($results[$key][$metric]) ? $results[$key][$metric][0] : '&nbsp;');
echo '</tr>'; echo '</tr>';
} }
@ -196,51 +195,48 @@ foreach (array(
'cn=Waiters,cn=Monitor' 'cn=Waiters,cn=Monitor'
) as $dn ) { ) as $dn ) {
if (is_array($results[$dn]['description']))
$description = implode(' ',$results[$dn]['description']); $description = implode(' ',$results[$dn]['description']);
else
$description = $results[$dn]['description'];
$description = preg_replace('/"/','\'',$description); $description = preg_replace('/"/','\'',$description);
printf('<tr class="list_item"><td class="heading" rowspan=2><acronym title="%s">%s</acronym></td></tr>',$description,$dn); printf('<tr class="list_item"><td class="heading" rowspan=2><acronym title="%s">%s</acronym></td></tr>',$description,$dn);
echo '<tr class="list_item"><td class="value">'; echo '<tr class="list_item"><td class="value">';
echo '<table class="result"><tr><td>'; echo '<table class="result"><tr><td>';
echo '<table class="result_table" border=0 width="100%">'; echo '<table class="result_table" border=0 width="100%">';
if (isset($results[$dn]['monitorOpInitiated'])) if (isset($results[$dn]['monitoropinitiated']))
printf('<tr class="highlight"><td width="20%%">%s</td><td class="value" width="80%%">%s</td></tr>', printf('<tr class="highlight"><td width="20%%">%s</td><td class="value" width="80%%">%s</td></tr>',
'monitorOpInitiated',$results[$dn]['monitorOpInitiated']); 'monitorOpInitiated',$results[$dn]['monitoropinitiated'][0]);
if (isset($results[$dn]['monitorOpCompleted'])) if (isset($results[$dn]['monitoropcompleted']))
printf('<tr class="highlight"><td width="20%%">%s</td><td class="value" width="80%%">%s</td></tr>', printf('<tr class="highlight"><td width="20%%">%s</td><td class="value" width="80%%">%s</td></tr>',
'monitorOpCompleted',$results[$dn]['monitorOpCompleted']); 'monitorOpCompleted',$results[$dn]['monitoropcompleted'][0]);
if (isset($results[$dn]['monitoredInfo'])) if (isset($results[$dn]['monitoredinfo']))
printf('<tr class="highlight"><td width="20%%">%s</td><td class="value" width="80%%">%s</td></tr>', printf('<tr class="highlight"><td width="20%%">%s</td><td class="value" width="80%%">%s</td></tr>',
'monitoredInfo',$results[$dn]['monitoredInfo']); 'monitoredInfo',$results[$dn]['monitoredinfo'][0]);
# Look for some connecitons # Look for some connecitons
foreach ($results as $key => $value) { foreach ($results as $key => $value) {
if (preg_match('/^.*,'.$dn.'$/',$key)) { if (preg_match('/^.*,'.$dn.'$/',$key)) {
echo '<tr class="highlight">'; echo '<tr class="highlight">';
printf('<td width="20%%">%s</td>',$results[$key]['cn']); printf('<td width="20%%">%s</td>',$results[$key]['cn'][0]);
echo '<td class="value" width="80%">'; echo '<td class="value" width="80%">';
echo '<table class="result_table" border=0 width="100%">'; echo '<table class="result_table" border=0 width="100%">';
foreach (array( foreach (array(
'labeledURI', 'labeleduri',
'monitorConnectionLocalAddress', 'monitorconnectionlocaladdress',
'monitoredInfo', 'monitoredinfo',
'monitorCounter', 'monitorcounter',
'monitorOpInitiated', 'monitoropinitiated',
'monitorOpCompleted', 'monitoropcompleted',
'monitorTimestamp' 'monitortimestamp'
) as $metric) { ) as $metric) {
if (isset($results[$key][$metric])) { if (isset($results[$key][$metric])) {
printf('<tr class="%s">',$counter++%2==0?'even':'odd'); printf('<tr class="%s">',$counter++%2==0?'even':'odd');
printf('<td class="title" width="35%%">%s</td><td width="65%%">%s</td>', printf('<td class="title" width="35%%">%s</td><td width="65%%">%s</td>',
$metric,$results[$key][$metric]); $metric,$results[$key][$metric][0]);
echo '</tr>'; echo '</tr>';
} }

View File

@ -29,11 +29,18 @@ foreach ($attrs as $key => $values) {
if ($key == 'dn') if ($key == 'dn')
continue; continue;
$href = sprintf('cmd.php?cmd=schema&amp;server_id=%s&amp;view=attributes&amp;viewvalue=%s',$app['server']->getIndex(),$key);
echo '<tr class="list_item"><td class="heading" rowspan=2>'; echo '<tr class="list_item"><td class="heading" rowspan=2>';
$sattr = $app['server']->getSchemaAttribute($key);
if ($sattr) {
$href = sprintf('cmd.php?cmd=schema&amp;server_id=%s&amp;view=attributes&amp;viewvalue=%s',$app['server']->getIndex(),$sattr->getName());
printf('<a href="%s" title="%s: %s" >%s</a>', printf('<a href="%s" title="%s: %s" >%s</a>',
$href,_('Click to view the schema definition for attribute type'),$key,$key); $href,_('Click to view the schema definition for attribute type'),$sattr->getName(false),$sattr->getName(false));
} else
echo $key;
echo '</td></tr>'; echo '</td></tr>';
echo '<tr class="list_item"><td class="blank">&nbsp;</td><td class="value">'; echo '<tr class="list_item"><td class="blank">&nbsp;</td><td class="value">';

View File

@ -146,7 +146,7 @@ abstract class Tree {
$server = $this->getServer(); $server = $this->getServer();
$dnlower = $this->indexDN($dn); $dnlower = $this->indexDN($dn);
if (! ($dn = $server->dnExists($dn))) if (! ($server->dnExists($dn)))
return; return;
if (isset($this->entries[$dnlower])) if (isset($this->entries[$dnlower]))

View File

@ -361,18 +361,20 @@ class ldap extends DS {
if ($debug) if ($debug)
debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method))); debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method)));
$resource = $this->connect($method,$debug);
switch ($query['scope']) { switch ($query['scope']) {
case 'base': case 'base':
$search = @ldap_read($this->connect($method,$debug),$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$time_limit,$query['deref']); $search = @ldap_read($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$time_limit,$query['deref']);
break; break;
case 'one': case 'one':
$search = @ldap_list($this->connect($method,$debug),$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$time_limit,$query['deref']); $search = @ldap_list($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$time_limit,$query['deref']);
break; break;
case 'sub': case 'sub':
default: default:
$search = @ldap_search($this->connect($method,$debug),$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$time_limit,$query['deref']); $search = @ldap_search($resource,$query['base'],$query['filter'],$query['attrs'],$attrs_only,$query['size_limit'],$time_limit,$query['deref']);
break; break;
} }
@ -389,70 +391,47 @@ class ldap extends DS {
$return = array(); $return = array();
# Get the first entry identifier # Get the first entry identifier
if ($entry_id = ldap_first_entry($this->connect($method,$debug),$search)) { if ($entries = ldap_get_entries($resource,$search)) {
# Remove the count
if ($debug) if (isset($entries['count']))
debug_dump(array('entry_id'=>$entry_id)); unset($entries['count']);
# Iterate over the entries # Iterate over the entries
while ($entry_id) { foreach ($entries as $a => $entry) {
if (! isset($entry['dn']))
debug_dump_backtrace('No DN?',1);
# Get the distinguished name of the entry # Remove the none entry references.
$dn = ldap_get_dn($this->connect($method,$debug),$entry_id); if (! is_array($entry)) {
unset($entries[$a]);
if (DEBUG_ENABLED)
debug_log('Got DN [%s].',64,__FILE__,__LINE__,__METHOD__,$dn);
$return[$dn]['dn'] = $dn;
# Get the attributes of the entry
$attrs = ldap_get_attributes($this->connect($method,$debug),$entry_id);
if (DEBUG_ENABLED)
debug_log('Got ATTRS [%s].',64,__FILE__,__LINE__,__METHOD__,$attrs);
# Get the first attribute of the entry
if ($attr = ldap_first_attribute($this->connect($method,$debug),$entry_id,$attrs)) {
if (DEBUG_ENABLED)
debug_log('Processing ATTR [%s].',64,__FILE__,__LINE__,__METHOD__,$attr);
# Iterate over the attributes
while ($attr) {
# It seems that OpenDS complains when you do a ldap_get_values on these attributes - we'll skip them as a workaround
# This is probably the bug https://opends.dev.java.net/issues/show_bug.cgi?id=3446
#@todo we probably shouldnt completely ignore the isMemberOf ?
if (in_array($attr,array('isMemberOf'))) {
$attr = ldap_next_attribute($this->connect($method,$debug),$entry_id,$attrs);
continue; continue;
} }
if ($this->isAttrBinary($attr)) $dn = $entry['dn'];
$values = ldap_get_values_len($this->connect($method,$debug),$entry_id,$attr); unset($entry['dn']);
else
$values = ldap_get_values($this->connect($method,$debug),$entry_id,$attr);
# Get the number of values for this attribute # Iterate over the attributes
$count = $values['count']; foreach ($entry as $b => $attrs) {
unset($values['count']); # Remove the none entry references.
if (! is_array($attrs)) {
if ($count == 1) unset($entry[$b]);
$return[$dn][$attr] = $values[0]; continue;
else
$return[$dn][$attr] = $values;
$attr = ldap_next_attribute($this->connect($method,$debug),$entry_id,$attrs);
} # end while attr
} }
$entry_id = ldap_next_entry($this->connect($method,$debug),$entry_id); # Remove the count
if (isset($entry[$b]['count']))
unset($entry[$b]['count']);
}
} # End while entry_id # Our queries always include the DN (the only value not an array).
$entry['dn'] = $dn;
$return[$dn] = $entry;
} }
# Sort our results # Sort our results
foreach ($return as $key=> $values) foreach ($return as $key=> $values)
ksort($return[$key]); ksort($return[$key]);
}
if (DEBUG_ENABLED) if (DEBUG_ENABLED)
debug_log('Returning (%s)',17,__FILE__,__LINE__,__METHOD__,$return); debug_log('Returning (%s)',17,__FILE__,__LINE__,__METHOD__,$return);
@ -763,9 +742,6 @@ class ldap extends DS {
$results = $this->getDNAttrValues('',$method); $results = $this->getDNAttrValues('',$method);
if (isset($results['namingcontexts'])) { if (isset($results['namingcontexts'])) {
if (! is_array($results['namingcontexts']))
$results['namingcontexts'] = array($results['namingcontexts']);
if (DEBUG_ENABLED) if (DEBUG_ENABLED)
debug_log('LDAP Entries:%s',80,__FILE__,__LINE__,__METHOD__,implode('|',$results['namingcontexts'])); debug_log('LDAP Entries:%s',80,__FILE__,__LINE__,__METHOD__,implode('|',$results['namingcontexts']));
@ -792,8 +768,8 @@ class ldap extends DS {
$results = $this->getDNAttrValues($dn,$method); $results = $this->getDNAttrValues($dn,$method);
if (isset($results['dn'][0])) if ($results)
return $results['dn'][0]; return $results;
else else
return false; return false;
} }