import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPConnection;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPException;
import com.novell.ldap.LDAPDSConstants;
import java.util.Date;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.TimeZone;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.io.UnsupportedEncodingException;
public class OperationalAttrs implements LDAPDSConstants {
public static void main( String[] args )
{
if ( args.length != 5 ) {
System.err.println(
"Usage: java OperationalAttrs <host Name> <port number>"
+ " <login dn> <password>"
+ "\n <entryDN>");
System.err.println( "Example: java OperationalAttrs Acme.com 389 "
+ "\"cn=Admin,o=Acme\" secret\n"
+ " \"cn=James,o=Sales\"");
System.exit(1);
}
int ldapVersion = LDAPConnection.LDAP_V3;
int ldapPort = Integer.parseInt(args[1]);
String ldapHost = args[0];
String loginDN = args[2];
String password = args[3];
String entryDN = args[4];
LDAPConnection lc = new LDAPConnection();
try {
lc.connect( ldapHost, ldapPort );
lc.bind( ldapVersion, loginDN, password.getBytes("UTF8") );
printOperationalAttrs( lc, entryDN );
lc.disconnect();
}
catch( LDAPException e ) {
System.out.println( "\nError: " + e.toString() );
System.exit(1);
}
catch( UnsupportedEncodingException e ) {
System.out.println( "Error: " + e.toString() );
}
System.exit(0);
}
public static void printOperationalAttrs( LDAPConnection lc, String dn)
throws LDAPException
{
int flags;
Date date = null;
String attributeName, attrValue;
Iterator allAttributes;
Enumeration allValues;
LDAPAttribute attribute;
LDAPAttributeSet attributeSet;
String returnAttrs[] = { "createTimeStamp",
"creatorsName",
"entryFlags",
"federationBoundary",
"localEntryID",
"modifiersName",
"modifyTimeStamp",
"structuralObjectClass",
"subordinateCount",
"subschemaSubentry"
};
try {
LDAPEntry entry = lc.read( dn, returnAttrs );
System.out.println( " Entry: " + dn );
System.out.println( " LDAP Operational Attributes: ");
attributeSet = entry.getAttributeSet();
allAttributes = attributeSet.iterator();
while(allAttributes.hasNext()) {
attribute = (LDAPAttribute)allAttributes.next();
attributeName = attribute.getName();
if ( (allValues = attribute.getStringValues()) != null
&& (attrValue = (String) allValues.nextElement()) != null) {
if ( attributeName.equalsIgnoreCase( "modifyTimeStamp" )) {
System.out.println(" modifyTimeStamp: "
+ attrValue + " (UTC)");
PrintTime( attrValue );
}
else if (attributeName.equalsIgnoreCase("createTimeStamp")){
System.out.println(" createTimeStamp: "
+ attrValue + " (UTC)");
PrintTime( attrValue );
}
else if ( attributeName.equalsIgnoreCase( "entryFlags" )) {
if ( (flags = Integer.parseInt( attrValue )) != 0 )
EntryFlags( flags );
}
else
System.out.println(" " + attributeName +
": " + attrValue);
}
}
}
catch( LDAPException e ) {
System.err.println( "\nOperationalAttrs() failed.");
System.err.println( "\nError: " + e.toString() );
System.exit(1);
}
}
public static void PrintTime( String utc )
{
Date date = null;
DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
try {
date = formatter.parse( utc );
}
catch(ParseException pe) {
System.out.println( "Error: " + pe.toString() );
}
System.out.println(" " + date + " (UTC)");
}
public static void EntryFlags( int flags ) {
StringBuffer entryFlags = new StringBuffer();
if ( (flags & LDAP_DS_ALIAS_ENTRY) != 0 )
entryFlags.append("AliasEntry ");
if (( flags & LDAP_DS_PARTITION_ROOT) != 0 )
entryFlags.append("PartionRoot ");
if (( flags & LDAP_DS_CONTAINER_ENTRY) != 0 )
entryFlags.append("ContainerEntry ");
if (( flags & LDAP_DS_CONTAINER_ALIAS) != 0 )
entryFlags.append("ContainerAlias ");
if (( flags & LDAP_DS_MATCHES_LIST_FILTER) != 0 )
entryFlags.append("MatchesListFilter ");
if (( flags & LDAP_DS_REFERENCE_ENTRY) != 0 )
entryFlags.append("ReferenceEntry ");
if (( flags & LDAP_DS_40X_REFERENCE_ENTRY) != 0 )
entryFlags.append("40XReferenceEntry ");
if (( flags & LDAP_DS_BACKLINKED) != 0 )
entryFlags.append("Backlinked ");
if (( flags & LDAP_DS_NEW_ENTRY) != 0 )
entryFlags.append("NewEntry ");
if (( flags & LDAP_DS_AUDITED) != 0 )
entryFlags.append("TemporaryEntry ");
if (( flags & LDAP_DS_AUDITED) != 0 )
entryFlags.append("Audited ");
if (( flags & LDAP_DS_ENTRY_NOT_PRESENT) != 0 )
entryFlags.append("EntryNotPresent ");
if (( flags & LDAP_DS_ENTRY_VERIFY_CTS) != 0 )
entryFlags.append("EntryVerifyCTS ");
if (( flags & LDAP_DS_ENTRY_DAMAGED) != 0 )
entryFlags.append("EntryDamaged");
System.out.println(" entryFlags: " + entryFlags);
}
}