K
K
Koal Koalich2018-09-19 09:39:53
LDAP
Koal Koalich, 2018-09-19 09:39:53

How to get all addresses from Kerio using ldap?

I'm trying to programmatically get all addresses by ldap from Kerio. This code only returned 200 contacts from some Public Folders:

<?php
error_reporting(E_ERROR);
$info = loginToLDAPInfo549post();
var_dump($info);
function loginToLDAPInfo549post($login="")
{
  $ds = ldap_connect("myserver", 389);
  if ($ds === false)
  {
    echo 'Возможно, используется некорректный синтаксис ldap_connect<br />';
    return;
  }
  ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
  $ldapbind = ldap_bind($ds, 'login', 'pass');
  if ($ldapbind === false)
  {
    echo "LDAP bind failed...<br />";
    return;
  }

  $dn='';
  $pageSize = 1000;
        $cookie = '';
  $info = array();
  $attributes = array("displayname", "samaccountname", "userprincipalname", "mail");
  //$attributes = array("mail");
  do {
    ldap_control_paged_result($ds, $pageSize, true, $cookie);
    $sr = ldap_search(
      $ds,
      $dn,
      '(|(objectClass=*))',
      $attributes,
      0,          // not attrsonly 
      $pageSize   //sizelimit
    );

    if ($sr === false)
    {
      //echo ldap_error($ds);
      ldap_unbind($ds);
      return false;
        }
    $rawinfo = ldap_get_entries($ds, $sr);
    $info = array_merge($info, $rawinfo);
    ldap_control_paged_result_response($ds, $sr, $cookie);
  }while($cookie !== null && $cookie != '');
  ldap_unbind($ds);
  return $info;
}
?>

But I have an address book attached to Outlook, which clearly has more than these 200 addresses, but it is not clear what settings are used when connecting. The login and password in the code is the same as in Outlook.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Koal Koalich, 2018-09-19
@tmman

In general, apparently, 200 is some kind of default setting on the server side. Like, for example, 1000 records at a time in AD. I changed the $filter parameter (in the code above there is '(|(objectClass=*))') to, for example, cn=desired_value and so far I got what I wanted. Well, that is, not all records, but received an email by full name. The issue with the complete list has not yet been resolved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question