Thursday, September 24, 2009

LDAP Change log number


I was inactive on this blog for quite some time but I will try to post on this once again.

In this blog I am trying to put some light on the LDAP change log numbers and how they work.

until now I was under impression that LDAP change log number always start with 1 and increase in sequence. It does increase in sequence but if an LDAP environment has a limit to keep change log only for last N number of days then LDAP first changelog number is not 1 but something else.

Now if you have to check what is the first and last change log number in your directory then how would you do it programatically?

Below is the code which can be used to get the lastchangelognumber. Similarly one can get the firstchangelognumber from the directory.

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;

public class ReadingLDAPChangeLog {

* @param args

static String RETURN_ATTRIBUTES[] = { "changes"};
static String RETURN_ATTRIBUTES_CHANGELOG[] = { "lastchangenumber"};

public static DirContext makeLDAPConnection (String Hostname, String Port, String BaseDN, String BindDN, String Password)
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://" + Hostname + ":" + Port + "/" + BaseDN);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, BindDN);
env.put(Context.SECURITY_CREDENTIALS, Password);
env.put(Context.BATCHSIZE, "100");
DirContext ctx = new InitialDirContext(env);
return ctx;
catch (Exception e)
System.out.println("Unable to connect to LDAP server.");
System.out.println("Please check connection parameters set in");
return null;

public static void main(String[] args) throws Exception {
//String SEARCH_FILTER = "(&(changenumber >= 550)(changenumber <= 580))";

String SEARCH_FILTER = "(objectclass = top)";

DirContext ctx_changelog = makeLDAPConnection("localhost","389","","cn=admin","*******");

SearchControls constraints_changelog = new SearchControls();

NamingEnumeration results_changelog ="", SEARCH_FILTER, constraints_changelog);

while ( results_changelog != null && results_changelog.hasMore() )

SearchResult sr = (SearchResult);
String DN = sr.getName();

Attributes attrs = ctx_changelog.getAttributes(DN, RETURN_ATTRIBUTES_CHANGELOG);

Attribute attr = attrs.get("lastchangenumber");
String lastchangenumber = (String)attr.get();





Anonymous said...

Keystar have been successfully training on all aspects of IT since 1991. The Managing Director Bobbie Lee's desire is to give value for excellence using the experience she has gained over many years in a rapidly moving industry.


Anonymous said...

IS VERY GOOD..............................

Hub and Switch and Router

I was doing a udemy course to learn more about the networking concepts and wanted to clarify the confusion between Hub, Switch and Router. ...