Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-2007, 08:43 AM
Active Member
 
Posts: 32
Default ldap attributes different output with perl/php

This might not be a pure Zimbra question, but I'll toss it out here anyway hoping somebody has seen something like it.

The situation is this, we currently have an internal web page that displays all the mail aliases and such in the company, and their members, pulled out of LDAP. I want to duplicate this for when we finish rollout of Zimbra, especially since some aliases will change since we don't have the ACL control yet.

I decided that the easiest thing to do would be to query the LDAP directory in Zimbra, since that's essentially how the current system works. We have our aliases defined in openldap, with some custom attribs and object classes defined to classify and such, so to duplicate that I figured I'd just toss some type-value pairs into notes. (type=sitelist, expire=20071020, etc.)

Now here's the problem. Some of the fields aren't available in php, notably notes and description, the two I care about. I can do a ldapsearch from the CLI and I get all the data. I can do the equivilent search in perl and get the data, but I can't do the search in php. Here's some chunks of code:

Code:
[fgoserv:~]$ ldapsearch -D 'uid=zimbra,cn=admins,cn=zimbra' -x -W -h <hostname>-p 389 '(objectClass=zimbraDistributionList)'
Enter LDAP Password:
# extended LDIF
#
# LDAPv3
# base <> with scope subtree
# filter: (objectClass=zimbraDistributionList)
# requesting: ALL
#

# testdl, people, domain
dn: uid=testdl,ou=people,dc=domain,dc=com
zimbraId: aef1417f-a9dc-4ed3-beeb-fb71097c73cb
mail: testdl@domain.com
uid: testdl
objectClass: zimbraDistributionList
objectClass: zimbraMailRecipient
zimbraMailAlias: testdl@domain.com
zimbraMailForwardingAddress: pgienger@domain.com
cn: test list
zimbraNotes: blargh
description: just testing
zimbraMailStatus: enabled
displayName: test list
So that works, now perl:
Code:
#!/usr/bin/perl

use Net::LDAP;

my $ldap = Net::LDAP->new('server') or die "$@";
$ldap->bind ('uid=zimbra,cn=admins,cn=zimbra', password => 'password') or die "$@";

$result = $ldap->search(base => '',
                        scope => 'sub',
                        filter => '(objectClass=zimbraDistributionList)'
                       ) or die "$@";


print "Number of entires returned is ".$result->count."\n";
if ( $result->code )
{
  print $result->error."\n" if ( $DEBUG );
}
elsif ($result->count > 0)
{
  # now work through all of our defined dirs
  for ($i = 0 ; $i < $result->count ; $i++)
  {
    $entry = $result->entry($i);
    print $entry->get_value(zimbramailalias)." has notes: ".$entry->get_value(zimbranotes)."\n";
  }
}
$ldap->unbind;
result:
Code:
[fgoserv:zm]$ ./zmlist.pl
Number of entires returned is 6
testdl@domain.com has notes: blargh
<snip>
[fgoserv:zm]$
and the (relevant parts of the) broken php:
Code:
  $ldapConn=ldap_connect("server");  
  echo "connect result is " . $ldapConn . "<br />";

  if ($ldapConn)
  {
    echo "Binding ...";
    $result=ldap_bind($ldapConn,'uid=zimbra,cn=admins,cn=zimbra','password');    
    echo "Bind result is " . $result . "<br />";

    echo "Searching for (stuff) ...";
    $searchResult=ldap_search($ldapConn, "", "(objectClass=zimbraDistributionList)");

    echo "Number of entires returned is " . ldap_count_entries($ldapConn, $searchResult) . "<br />";
    echo "Getting entries ...<p>";

    $results = ldap_get_entries($ldapConn, $searchResult);
    echo "dumping results\n";
echo "<pre>\n";
    print_r($results);
echo "</pre>\n";
and the results
Code:
connect result is Resource id #2
Binding ...Bind result is
Searching for (stuff) ...Number of entires returned is 4
Getting entries ...
dumping results
Array
(
    [count] => 4
    [0] => Array
        (
            [zimbraid] => Array
                (
                    [count] => 1
                    [0] => aef1417f-a9dc-4ed3-beeb-fb71097c73cb
                )
            [0] => zimbraid
            [mail] => Array
                (
                    [count] => 1
                    [0] => testdl@ae-solutions.com
                )
            [1] => mail
            [uid] => Array
                (
                    [count] => 1
                    [0] => testdl
                )
            [2] => uid
            [objectclass] => Array
                (
                    [count] => 2
                    [0] => zimbraDistributionList
                    [1] => zimbraMailRecipient
                )
            [3] => objectclass
            [zimbramailalias] => Array
                (
                    [count] => 1
                    [0] => testdl@ae-solutions.com
                )
            [4] => zimbramailalias
            [zimbramailforwardingaddress] => Array
                (
                    [count] => 1
                    [0] => pgienger@ae-solutions.com
                )
            [5] => zimbramailforwardingaddress
            [cn] => Array
                (
                    [count] => 1
                    [0] => test list
                )
            [6] => cn
            [zimbramailstatus] => Array
                (
                    [count] => 1
                    [0] => enabled
                )
            [7] => zimbramailstatus
            [displayname] => Array
                (
                    [count] => 1
                    [0] => test list
                )
            [8] => displayname
            [count] => 9
            [dn] => uid=testdl,ou=people,dc=ae-solutions,dc=com
        )
Soooo, where did the other attribs go in php? I can develop the page in perl, but we'd rather do php, and I'm just boggled as to what could be wrong here.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.