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

View File

@ -29,11 +29,18 @@ foreach ($attrs as $key => $values) {
if ($key == 'dn')
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>';
$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>',
$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 '<tr class="list_item"><td class="blank">&nbsp;</td><td class="value">';

View File

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

View File

@ -361,18 +361,20 @@ class ldap extends DS {
if ($debug)
debug_dump(array('query'=>$query,'server'=>$this->getIndex(),'con'=>$this->connect($method)));
$resource = $this->connect($method,$debug);
switch ($query['scope']) {
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;
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;
case 'sub':
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;
}
@ -389,70 +391,47 @@ class ldap extends DS {
$return = array();
# Get the first entry identifier
if ($entry_id = ldap_first_entry($this->connect($method,$debug),$search)) {
if ($debug)
debug_dump(array('entry_id'=>$entry_id));
if ($entries = ldap_get_entries($resource,$search)) {
# Remove the count
if (isset($entries['count']))
unset($entries['count']);
# 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
$dn = ldap_get_dn($this->connect($method,$debug),$entry_id);
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);
# Remove the none entry references.
if (! is_array($entry)) {
unset($entries[$a]);
continue;
}
if ($this->isAttrBinary($attr))
$values = ldap_get_values_len($this->connect($method,$debug),$entry_id,$attr);
else
$values = ldap_get_values($this->connect($method,$debug),$entry_id,$attr);
$dn = $entry['dn'];
unset($entry['dn']);
# Get the number of values for this attribute
$count = $values['count'];
unset($values['count']);
if ($count == 1)
$return[$dn][$attr] = $values[0];
else
$return[$dn][$attr] = $values;
$attr = ldap_next_attribute($this->connect($method,$debug),$entry_id,$attrs);
} # end while attr
# Iterate over the attributes
foreach ($entry as $b => $attrs) {
# Remove the none entry references.
if (! is_array($attrs)) {
unset($entry[$b]);
continue;
}
$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
foreach ($return as $key=> $values)
ksort($return[$key]);
}
if (DEBUG_ENABLED)
debug_log('Returning (%s)',17,__FILE__,__LINE__,__METHOD__,$return);
@ -763,9 +742,6 @@ class ldap extends DS {
$results = $this->getDNAttrValues('',$method);
if (isset($results['namingcontexts'])) {
if (! is_array($results['namingcontexts']))
$results['namingcontexts'] = array($results['namingcontexts']);
if (DEBUG_ENABLED)
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);
if (isset($results['dn'][0]))
return $results['dn'][0];
if ($results)
return $results;
else
return false;
}