[Date Prev][Date Next] [Chronological] [Thread] [Top]

Getting Passwords out of LDAP



I have an LDAP directory that is storeing user passwords in clear text and I
would like to be able to get a users password with a client program.

The problem is that I can't seem to get at the password attribute.  I've got
a small java app that should print perform a search and print out all the
attributes for the result but I don't get any mention of the password.

Do I need to do something special to retrieve the password?

Here is the java app.


import netscape.ldap.*;
import java.util.*;

class LDAPThingy {
	public static void main(String argz[]) {

		/* Create a new connection. */
		LDAPConnection ld = new LDAPConnection();
		PAProperties p = new PAProperties();


		try {
		   /* Connect to the LDAP server. */
		   ld.connect(p.getPAProperty("LDAP_Server"),
Integer.parseInt(p.getPAProperty("LDAP_Port")));

		   /* Get the root DSE by doing a search where:
      		   - The scope is SCOPE_BASE
		         - The base is ""
      		   - The search filter is "(objectclass=*)"
		   */
		   int MY_SCOPE = LDAPv2.SCOPE_BASE;
		   String MY_FILTER = "(objectclass=*)";
		   String MY_SEARCHBASE = "";

	   	LDAPSearchResults res = ld.search("o=primeadvantage.com",
LDAPConnection.SCOPE_SUB,
 
argz[0], null, false );


		   /* There should be only one entry in the results (the
root DSE). */
		   while ( res.hasMoreElements() ) {
		      LDAPEntry findEntry = (LDAPEntry)res.nextElement();

		      /* Get the attributes of the root DSE. */
      		LDAPAttributeSet findAttrs = findEntry.getAttributeSet();
		      Enumeration enumAttrs = findAttrs.getAttributes();

      		/* Iterate through each attribute. */
		      while ( enumAttrs.hasMoreElements() ) {
		         LDAPAttribute anAttr =
(LDAPAttribute)enumAttrs.nextElement();

      		   /* Get and print the attribute name. */
		         String attrName = anAttr.getName();
      		   System.out.println( attrName );

		         /* Get the values of the attribute. */
      		   Enumeration enumVals = anAttr.getStringValues();

		         /* Get and print each value. */
      		   if ( enumVals == null ) {
		            System.out.println( "\tNo values found." );
      		      continue;
		         }
      		   while ( enumVals.hasMoreElements() ) {
		            String aVal = ( String )enumVals.nextElement();
      		      System.out.println( "\t" + aVal );
		         }
		      }
		   }
		}
		catch( LDAPException e ) {
		   System.out.println( "Error: " + e.toString() );
		}
	}
}