ldapjdk-4.18/ 0000775 0010033 0010033 00000000000 10667357302 012440 5 ustar vivekl vivekl ldapjdk-4.18/mozilla/ 0000775 0010033 0010033 00000000000 10667357302 014107 5 ustar vivekl vivekl ldapjdk-4.18/mozilla/directory/ 0000775 0010033 0010033 00000000000 10667357303 016114 5 ustar vivekl vivekl ldapjdk-4.18/mozilla/directory/java-sdk/ 0000775 0010033 0010033 00000000000 10667357333 017617 5 ustar vivekl vivekl ldapjdk-4.18/mozilla/directory/java-sdk/build.properties 0000664 0010033 0010033 00000000615 10315014722 023014 0 ustar vivekl vivekl # ----------------------------------------------------------------------------- # build.properties.sample # # This is an example "build.properties" file, used to customize building # Mozilla Java LDAP SDK for your local environment. # # $Id: build.properties,v 1.2 2005/09/23 15:05:54 richm%stanfordalumni.org Exp $ # ----------------------------------------------------------------------------- ldapjdk-4.18/mozilla/directory/java-sdk/ldapsp.mk 0000664 0010033 0010033 00000010405 10602743265 021423 0 ustar vivekl vivekl # -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- # # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # # The contents of this file are subject to the Mozilla Public License Version # 1.1 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the # License. # # The Original Code is mozilla.org code. # # The Initial Developer of the Original Code is # Netscape Communications Corporation. # Portions created by the Initial Developer are Copyright (C) 1999 # the Initial Developer. All Rights Reserved. # # Contributor(s): # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK ***** # # Makefile for the LDAPSP classes # # A debug compile (java -g) is done by default. You can specify "DEBUG=0" on # the make line to compile with '-O' option. # ARCH := $(shell uname -s) MCOM_ROOT=. ifeq ($(ARCH), WINNT) MOZ_DIR:=$(subst \,/,$(MOZ_SRC)) BASEDIR:=$(MOZ_DIR)/mozilla/directory/java-sdk else ifeq ($(ARCH), WIN95) MOZ_DIR:=$(subst \,/,$(MOZ_SRC)) BASEDIR:=$(MOZ_DIR)/mozilla/directory/java-sdk else BASEDIR := $(shell cd $(MCOM_ROOT); pwd) endif endif # Destination for class files and packages CLASS_DEST=$(BASEDIR)/dist/classes ifeq ($(ARCH), WINNT) JDK := $(subst \,/,$(JAVA_HOME)) SEP=; else ifeq ($(ARCH), WIN95) JDK := $(subst \,/,$(JAVA_HOME)) SEP=; else JDK := $(JAVA_HOME) SEP=: endif endif JNDILIB:=$(BASEDIR)/ldapsp/lib/jndi.jar JAVACLASSPATH:=$(CLASS_DEST)$(SEP)$(BASEDIR)/ldapsp$(SEP)$(JDK)/lib/classes.zip$(SEP)$(JNDILIB)$(SEP)$(CLASSPATH) SRCDIR=com/netscape/jndi/ldap DISTDIR=$(MCOM_ROOT)/dist CLASSDIR=$(MCOM_ROOT)/dist/classes CLASSPACKAGEDIR=$(DISTDIR)/packages DOCDIR=$(DISTDIR)/doc/ldapsp BASEPACKAGENAME=ldapsp.jar CLASSPACKAGE=$(CLASSPACKAGEDIR)/$(PACKAGENAME) DOCCLASSES=com.netscape.jndi.ldap.controls ifdef JAVA_HOME JDKBIN=$(JDK)/bin/ endif ifndef JAVAC ifndef DEBUG #defualt mode is debug (-g) JAVAC=$(JDKBIN)javac -g -classpath "$(JAVACLASSPATH)" else ifeq ($(DEBUG), 1) JAVAC=$(JDKBIN)javac -g -classpath "$(JAVACLASSPATH)" else JAVAC=$(JDKBIN)javac -O -classpath "$(JAVACLASSPATH)" endif endif endif ifndef JAR JAR:=$(JDKBIN)jar endif ifndef JAVADOC JAVADOC=$(JDKBIN)javadoc -classpath "$(JAVACLASSPATH)" endif all: classes doc: $(DISTDIR) $(DOCDIR) $(JAVADOC) -d $(DOCDIR) $(DOCCLASSES) basics: $(DISTDIR) $(CLASSDIR) classes: JNDICLASSES package: basepackage basepackage: $(CLASSPACKAGEDIR) cd $(DISTDIR)/classes; rm -f ../packages/$(BASEPACKAGENAME); $(JAR) cvf ../packages/$(BASEPACKAGENAME) com/netscape/jndi/ldap/*.class com/netscape/jndi/ldap/common/*.class com/netscape/jndi/ldap/schema/*.class com/netscape/jndi/ldap/controls/*.class MAIN: basics cd ldapsp/$(SRCDIR); $(JAVAC) -d $(CLASS_DEST) *.java SCHEMA: basics cd ldapsp/$(SRCDIR)/schema; $(JAVAC) -d $(CLASS_DEST) *.java COMMON: basics cd ldapsp/$(SRCDIR)/common; $(JAVAC) -d $(CLASS_DEST) *.java CONTROLS: basics cd ldapsp/$(SRCDIR)/controls; $(JAVAC) -d $(CLASS_DEST) *.java JNDICLASSES: COMMON CONTROLS SCHEMA MAIN clean: rm -rf $(DISTDIR)/classes/com/netscape/jndi/ldap $(CLASSPACKAGEDIR): mkdir -p $@ $(DOCDIR): mkdir -p $@ $(DISTDIR): mkdir -p $@ $(CLASSDIR): mkdir -p $@ ldapjdk-4.18/mozilla/directory/java-sdk/tools/ 0000775 0010033 0010033 00000000000 10667357333 020757 5 ustar vivekl vivekl ldapjdk-4.18/mozilla/directory/java-sdk/tools/LDAPTool.java 0000664 0010033 0010033 00000011646 10602743274 023200 0 ustar vivekl vivekl /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1999 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ import netscape.ldap.*; import netscape.ldap.util.*; import netscape.ldap.controls.*; /** * LDAPTool * Base class for LDAP command-line tools * * @version 1.0 * @author Rob Weltman **/ class LDAPTool { /** * This function is to extract specified parameters from the * arguments list. * @param args list of args */ protected static GetOpt extractParameters(String privateOpts, String args[]) { GetOpt options = new GetOpt("vnRMD:h:O:p:w:d:V:y:" + privateOpts, args); if (options.hasOption('n')) m_justShow = true; if (options.hasOption('v')) m_verbose = true; if (options.hasOption('R')) m_referrals = false; /* -D bind DN */ if (options.hasOption('D')) m_binddn = options.getOptionParam('D'); /* -h ldap host */ if (options.hasOption('h')) m_ldaphost = options.getOptionParam('h'); /* -p ldap port */ if (options.hasOption('p')) { /* if the option is -p */ try { m_ldapport = Integer.parseInt(options.getOptionParam('p')); } catch (NumberFormatException e) { m_ldapport = 389; } } /* if the option is -p */ /* -O hop limit */ if (options.hasOption('O')) { /* if the option is -O */ try { m_hopLimit = Integer.parseInt(options.getOptionParam('O')); } catch (NumberFormatException e) { m_hopLimit = 10; } } /* if the option is -O */ /* -d debug level */ if (options.hasOption('d')) { /* if the option is -d */ try { m_debugLevel = Integer.parseInt(options.getOptionParam('d')); } catch (NumberFormatException e) { m_debugLevel = 0; } } /* if the option is -d */ /* -V ldap protocol version */ if (options.hasOption('V')) { /* if the option is -V */ try { m_version = Integer.parseInt(options.getOptionParam('V')); } catch (NumberFormatException e) { m_version = 3; } } /* if the option is -V */ /* -w bind password */ if (options.hasOption('w')) m_passwd = options.getOptionParam('w'); /* -y proxy DN */ if (options.hasOption('y')) m_proxyControl = new LDAPProxiedAuthControl( options.getOptionParam('y'), true ); /* -M treat ref attribute as ordinary entry */ if (options.hasOption('M')) m_ordinary = true; return options; } protected static void setDefaultReferralCredentials( LDAPConstraints cons ) { LDAPRebind rebind = new LDAPRebind() { public LDAPRebindAuth getRebindAuthentication( String host, int port ) { return new LDAPRebindAuth( m_client.getAuthenticationDN(), m_client.getAuthenticationPassword() ); } }; cons.setReferrals( true ); cons.setRebindProc( rebind ); } protected static int m_ldapport = 389; protected static String m_binddn = null; protected static String m_ldaphost = "localhost"; protected static String m_passwd = null; protected static int m_version = 3; protected static int m_debugLevel = 0; protected static int m_hopLimit = 10; protected static boolean m_referrals = true; protected static LDAPConnection m_client = null; protected static boolean m_justShow = false; protected static boolean m_verbose = false; protected static boolean m_ordinary = false; protected static LDAPControl m_proxyControl = null; } ldapjdk-4.18/mozilla/directory/java-sdk/tools/LDAPModify.java 0000664 0010033 0010033 00000050544 10602743274 023512 0 ustar vivekl vivekl /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1999 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ /* * @(#) LDAPModify.java * */ import java.io.*; import java.net.*; import java.util.*; import netscape.ldap.*; import netscape.ldap.util.*; /** * Executes modify, delete, add, and modRDN. * This class is implemented based on the java LDAP classes. * *
* usage : java LDAPModify [options] * example : java LDAPModify -D "uid=johnj,ou=People,o=Airius.com" * -w "password" -h ldap.netscape.com -p 389 * -f modify.cfg * * options: {np = no parameters, p = requires parameters} * 'D' bind DN --------------------------------------------- p * 'w' bind password --------------------------------------- p * 'f' input file ------------------------------------------ p * 'h' LDAP host ------------------------------------------- p * 'p' LDAP port ------------------------------------------- p * 'e' record rejected records in a text file -------------- p * 'c' continuous, do not stop on error ------------------- np * 'a' add, if no operation is specified ------------------ np * 'r' replace, if no operation is specified -------------- np * 'b' binary, read values starting with / from a file ---- np * 'd' debugging level ------------------------------------- p * 'V' version, specify LDAP protocol version (2 or 3) ----- p * 'R' do not follow referrals ---------------------------- np * 'O' hop limit ------------------------------------------- p * 'H' help, display usage--------------------------------- np * 'M' manage referrals, do not follow them --------------- np * 'n' show what would be done but do not do it ----------- np * 'v' verbose mode --------------------------------------- np * 'e' reject file, where to list rejected records --------- p * 'y' proxy DN, DN to use for access control -------------- p * * note: '-' or '/' is used to mark an option field. * e.g. -a -b /c /d parameter -e parameter * ** * @version 1.0 */ public class LDAPModify extends LDAPTool { /* LDAPModify */ public static void main(String args[]) { /* main */ /* extract parameters from the arguments list */ extractParameters(args); /* perform an LDAP client connection operation */ try { if (!m_justShow) { m_client = new LDAPConnection(); m_client.connect( m_ldaphost, m_ldapport ); } } catch(Exception e) { System.err.println("Error: client connection failed!"); System.exit(0); } /* perform an LDAP bind operation */ try { if (!m_justShow) m_client.authenticate( m_version, m_binddn, m_passwd ); } catch (Exception e) { System.err.println( e.toString() ); System.exit(0); } try { if ( m_file != null ) m_ldif = new LDIF(m_file); else { m_ldif = new LDIF(); } } catch (Exception e) { if ( m_file == null ) m_file = "stdin"; System.err.println("Failed to read LDIF file " + m_file + ", " + e.toString()); System.exit(0); } /* performs a JDAP Modify operation */ try { doModify(); } catch (Exception e) { System.err.println( e.toString() ); } /* disconnect */ try { if (!m_justShow) m_client.disconnect(); } catch (Exception e) { System.err.println( e.toString() ); } System.exit(0); } /* main */ /** * Prints usage. */ private static void doUsage() { System.err.println( "usage: LDAPModify [options]" ); System.err.println("options"); System.err.println(" -h host LDAP server name or IP address"); System.err.println(" -p port LDAP server TCP port number"); System.err.println(" -V version LDAP protocol version " + "number (default is 3)"); System.err.println(" -D binddn bind dn"); System.err.println(" -w password bind passwd (for simple " + "authentication)"); System.err.println(" -d level set LDAP debugging level " + "to \'level\'"); System.err.println(" -R do not automatically follow " + "referrals"); System.err.println(" -O hop limit maximum number of referral " + "hops to traverse"); System.err.println(" -H display usage information"); System.err.println(" -c continuous mode (do not " + "stop on errors)"); System.err.println(" -M manage references (treat them " + "as regular entries)"); System.err.println(" -f file read modifications from " + "file instead of standard input"); System.err.println(" -a add entries"); System.err.println(" -b read values that start with " + "/ from files (for bin attrs)"); System.err.println(" -n show what would be done but " + "don\'t actually do it"); System.err.println(" -v run in verbose mode"); System.err.println(" -r replace existing values by " + "default"); System.err.println(" -e rejectfile save rejected entries in " + "\'rejfile\'"); System.err.println(" -y proxy-DN DN to use for access control"); } /** * This class-method is used to extract specified parameters from the * arguments list. */ /* extract parameters */ protected static void extractParameters(String args[]) { String privateOpts = "abcHFre:f:"; GetOpt options = LDAPTool.extractParameters( privateOpts, args ); /* -H Help */ if (options.hasOption('H')) { doUsage(); System.exit(0); } /* Help */ if (options.hasOption('F')) m_force = true; if (options.hasOption('a')) m_add = true; if (options.hasOption('c')) m_continuous = true; if (options.hasOption('r')) m_add = false; if (options.hasOption('b')) m_binaryFiles = true; /* -f input file */ if(options.hasOption('f')) { /* Is input file */ m_file = (String)options.getOptionParam('f'); } /* End Is input file */ /* -e rejects file */ if(options.hasOption('e')) { /* rejects file */ m_rejectsFile = (String)options.getOptionParam('e'); } /* End rejects file */ } /* extract parameters */ /** * Call the LDAPConnection modify operation with the * specified options, and/or parameters. */ private static void doModify() throws IOException { /* doModify */ PrintWriter reject = null; LDAPConstraints baseCons = null; if (!m_justShow) { baseCons = m_client.getConstraints(); Vector controlVector = new Vector(); if (m_proxyControl != null) controlVector.addElement(m_proxyControl); if (m_ordinary) { controlVector.addElement( new LDAPControl( LDAPControl.MANAGEDSAIT, true, null) ); } if (controlVector.size() > 0) { LDAPControl[] controls = new LDAPControl[controlVector.size()]; controlVector.copyInto(controls); baseCons.setServerControls(controls); } baseCons.setReferrals( m_referrals ); if ( m_referrals ) { setDefaultReferralCredentials( baseCons ); } baseCons.setHopLimit( m_hopLimit ); } LDIFRecord rec = m_ldif.nextRecord(); for (; rec != null; rec = m_ldif.nextRecord() ) { LDAPConstraints cons = baseCons; if (!m_justShow) { // Were there any controls specified in the LDIF // record? LDAPControl[] newControls = rec.getControls(); if ( newControls != null ) { LDAPControl[] controls = newControls; LDAPControl[] oldControls = baseCons.getServerControls(); if ( oldControls != null ) { // If there were already controls defined, merge in // the new ones controls = new LDAPControl[oldControls.length + newControls.length]; for( int i = 0; i < oldControls.length; i++ ) { controls[i] = oldControls[i]; } for( int i = 0; i < newControls.length; i++ ) { controls[i+oldControls.length] = newControls[i]; } } // Assign the merged controls to a copy of the constraints cons = (LDAPSearchConstraints)baseCons.clone(); cons.setServerControls( controls ); } } LDIFContent content = rec.getContent(); LDAPModification mods[] = null; LDAPAttribute addAttrs[] = null; boolean doDelete = false; boolean doModDN = false; LDAPEntry newEntry = null; /* What type of record is this? */ if ( content instanceof LDIFModifyContent ) { mods = ((LDIFModifyContent)content).getModifications(); } else if ( content instanceof LDIFAddContent ) { addAttrs = ((LDIFAddContent)content).getAttributes(); } else if ( content instanceof LDIFAttributeContent ) { /* No change type; decide what to do based on options */ if ( m_add ) { addAttrs = ((LDIFAttributeContent)content).getAttributes(); } else { LDAPAttribute[] tmpAttrs = ((LDIFAttributeContent)content).getAttributes(); mods = new LDAPModification[tmpAttrs.length]; for( int ta = 0; ta < tmpAttrs.length; ta++ ) { mods[ta] = new LDAPModification( LDAPModification.REPLACE, tmpAttrs[ta] ); } } } else if ( content instanceof LDIFDeleteContent ) { doDelete = true; } else if (content instanceof LDIFModDNContent ) { doModDN = true; } else { } /* Prepare for adding */ if ( addAttrs != null ) { LDAPAttributeSet newAttrSet = new LDAPAttributeSet(); for( int a = 0; a < addAttrs.length; a++ ) newAttrSet.add( addAttrs[a] ); newEntry = new LDAPEntry( rec.getDN(), newAttrSet ); } /* Get values from files? */ boolean skip = false; if ( m_binaryFiles ) { /* Check each value of each attribute, to see if it needs replacing with the contents of a file */ if ( mods != null ) { for( int m = 0; m < mods.length; m++ ) { LDAPModification mod = mods[m]; LDAPAttribute attr = mods[m].getAttribute(); LDAPAttribute newAttr = checkFiles( attr ); if ( newAttr == null ) skip = true; else mods[m] = new LDAPModification( mod.getOp(), newAttr ); } } else if ( addAttrs != null ) { LDAPAttributeSet newAttrSet = new LDAPAttributeSet(); for( int a = 0; a < addAttrs.length; a++ ) { LDAPAttribute attr = addAttrs[a]; LDAPAttribute newAttr = checkFiles( attr ); if ( newAttr == null ) { skip = true; break; } else { newAttrSet.add( newAttr ); } } if ( !skip ) { newEntry = new LDAPEntry( rec.getDN(), newAttrSet ); } } } /* Do the directory operation */ int errCode = 0; if ( !skip ) { try { if ( mods != null ) { LDAPModificationSet modSet = new LDAPModificationSet(); System.out.println("\nmodifying entry "+rec.getDN() ); for( int m = 0; m < mods.length; m++ ) { if (m_verbose) System.out.println("\t"+mods[m] ); modSet.add( mods[m].getOp(), mods[m].getAttribute() ); } if (!m_justShow) { m_client.modify( rec.getDN(), modSet, cons ); } } else if ( newEntry != null ) { System.out.println( "\nadding new entry " + newEntry.getDN() ); if ( m_verbose ) { LDAPAttributeSet set = newEntry.getAttributeSet(); for( int a = 0; a < set.size(); a++ ) { System.out.println("\t"+set.elementAt(a) ); } } if (!m_justShow) { m_client.add( newEntry, cons ); } } else if ( doDelete ) { System.out.println( "\ndeleting entry " + rec.getDN() ); if (!m_justShow) m_client.delete( rec.getDN(), cons ); } else if ( doModDN) { System.out.println( "\nmodifying RDN of entry " + rec.getDN()+" and/or moving it beneath a new parent"); if ( m_verbose ) { System.out.println( "\t"+content.toString()); } if (!m_justShow) { LDIFModDNContent moddnContent = (LDIFModDNContent)content; m_client.rename( rec.getDN(), moddnContent.getRDN(), moddnContent.getNewParent(), moddnContent.getDeleteOldRDN(), cons ); System.out.println( "rename completed"); } } } catch (LDAPException e) { System.err.println( rec.getDN() + ": " + e.errorCodeToString() ); if (e.getLDAPErrorMessage() != null) System.err.println( "additional info: " + e.getLDAPErrorMessage() ); if ( !m_continuous ) { System.exit(1); } skip = true; errCode = e.getLDAPResultCode(); } } /* Write to rejects file? */ if ( skip && (m_rejectsFile != null) ) { try { if ( reject == null ) { reject = new PrintWriter( new FileOutputStream( m_rejectsFile ) ); } } catch ( Exception e ) { } if ( reject != null ) { reject.println( "dn: "+rec.getDN()+ " # Error: " + errCode ); if ( mods != null ) { for( int m = 0; m < mods.length; m++ ) { reject.println( mods[m].toString() ); } } else if ( newEntry != null ) { reject.println( "Add " + newEntry.toString() ); } else if ( doDelete ) { reject.println( "Delete " + rec.getDN() ); } else if (doModDN) { reject.println( "ModDN "+ ((LDIFModDNContent)content).toString() ); } reject.flush(); } } } System.exit(0); } /* doModify */ /** * Read in binary data for values specified with a leading / * @param attr Source attribute. * @return Updated attribute. **/ private static LDAPAttribute checkFiles ( LDAPAttribute attr ) { LDAPAttribute newAttr = new LDAPAttribute( attr.getName() ); /* Check each value and see if it is a file name */ Enumeration e = attr.getStringValues(); if (e != null) { while ( e.hasMoreElements() ) { String val = (String)e.nextElement(); if ( (val != null) && (val.length() > 1)) { try { File file = new File( val ); FileInputStream fi = new FileInputStream( file ); byte[] bval = new byte[(int)file.length()]; fi.read( bval, 0, (int)file.length() ); newAttr.addValue( bval ); } catch (FileNotFoundException ex) { newAttr.addValue(val) ; } catch ( IOException ex ) { System.err.println( "Unable to read value " + "from file " + val ); if ( !m_continuous ) System.exit(1); newAttr = null; } } else { newAttr.addValue( val ); } } } else System.err.println("Failed to do string conversion for "+attr.getName()); return newAttr; } private static boolean m_continuous = false; private static boolean m_force = false; private static boolean m_add = false; private static boolean m_binaryFiles = false; private static String m_rejectsFile = null; private static LDIF m_ldif = null; private static String m_file = null; } /* LDAPModify */ ldapjdk-4.18/mozilla/directory/java-sdk/tools/LDAPSearch.java 0000664 0010033 0010033 00000044603 10602743274 023467 0 ustar vivekl vivekl /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1999 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ import java.io.*; import java.net.*; import java.util.*; import netscape.ldap.*; import netscape.ldap.util.*; import netscape.ldap.controls.*; /** * Execute Search operations through the LDAP client interface. * This class is implemented based on the LDAP class library. * *
* usage : java LDAPSearch -b baseDN [options] filter [attributes...] * for example : java LDAPSearch -b "c=us" -h ds.internic.net -p 389 * "(objectClass=*)" * * note: '-' or '/' is used to distinct the option field. * e.g. -a -b /c /d parameter -e parameter * * filter: * Any string in RFC1558 specification. * e.g. "(objectClass=*)" * * attributes: {0..n} * All the string parameters follows with the filter. * e.g. filter attrsA attrsB attrsC ** * @version 1.0 */ public class LDAPSearch extends LDAPTool { /** * This is the main function. * @param args list of arguments */ public static void main(String args[]) { /* extract parameters from the arguments list */ extractParameters(args); if (!m_justShow) { /* perform an LDAP client connection operation */ try { m_client = new LDAPConnection(); m_client.connect( m_ldaphost, m_ldapport ); } catch(Exception e) { System.err.println("Error: client connection failed!"); System.exit(0); } /* perform an LDAP bind operation */ try { m_client.authenticate( m_version, m_binddn, m_passwd ); } catch (Exception e) { System.err.println( e.toString() ); System.exit(0); } /* perform a search operation */ dosearch(); m_pw.flush(); m_pw.close(); /* disconnect */ try { m_client.disconnect(); } catch (Exception e) { System.err.println( e.toString() ); } } System.exit(0); } /** * Prints usage. */ private static void doUsage() { System.err.println("usage: LDAPSearch -b basedn [options] " + "filter [attributes...]"); System.err.println("options"); System.err.println(" -h host LDAP server name or IP address"); System.err.println(" -p port LDAP server TCP port number"); System.err.println(" -V version LDAP protocol version " + "number (default is 3)"); System.err.println(" -D binddn bind dn"); System.err.println(" -w password bind passwd (for simple " + "authentication)"); System.err.println(" -v run in verbose mode"); System.err.println(" -n show what would be done but "+ "don't actually do it"); System.err.println(" -d level set LDAP debugging level " + "to \'level\'"); System.err.println(" -R do not automatically follow " + "referrals"); System.err.println(" -O hop limit maximum number of referral " + "hops to traverse"); System.err.println(" -H display usage information"); System.err.println(" -t write values to files"); System.err.println(" -A retrieve attribute names only"); System.err.println(" -F sep print \'sep\' instead of " + "\'=\' between attribute names and values"); System.err.println(" -S attr sort the results by attribute " + "\'attr\'"); System.err.println(" -s scope one of base, one, or sub " + "(search scope)"); System.err.println(" -a deref one of never, always, search, " + "or find (alias dereferencing)"); System.err.println(" -l timelimit time limit (in seconds) for " + "search"); System.err.println(" -T do not fold (wrap) long lines "+ "(default is to fold)"); System.err.println(" -x perform sorting on server"); System.err.println(" -M manage references (treat them "+ "as regular entries)"); System.err.println(" -z sizelimit size limit (in entries) for " + "search"); System.err.println(" -G before:after:index:count | before:after:value "+ "where 'before' and 'after' are the number of "+ "entries surrounding 'index'. 'count' is the "+ "content count, 'value' is the search value."); System.err.println(" -y proxy-DN DN to use for access control"); System.err.println(" -X output DSML instead of LDIF"); } /** * This function is to extract specified parameters from the * arguments list. * @param args list of args */ protected static void extractParameters(String args[]) { String privateOpts = "HATtxvnXa:b:F:l:s:S:z:G:"; GetOpt options = LDAPTool.extractParameters( privateOpts, args ); /* -H Help */ if (options.hasOption('H')) { doUsage(); System.exit(0); } /* Help */ /* -A retrieve attribute name only == no values */ if (options.hasOption('A')) m_attrsonly = true; if (options.hasOption('x')) m_sortOnServer = true; if (options.hasOption('t')) m_tempFiles = true; /* -F separator */ if (options.hasOption('F')) m_sep = options.getOptionParam('F'); /* -a set alias deref option */ if (options.hasOption('a')) { /* has option a */ String param = options.getOptionParam('a'); if (param.equalsIgnoreCase("never")) m_deref = 0; else if (param.equalsIgnoreCase("search")) m_deref = 1; else if (param.equalsIgnoreCase("find")) m_deref = 2; else if (param.equalsIgnoreCase("always")) m_deref = 3; else System.err.println("Error: alias deref option " + "should be never, search, find, " + "or always."); } /* has option a */ /* -b searchbase */ if (options.hasOption('b')) m_base = options.getOptionParam('b'); /* -S sort attribute */ if (options.hasOption('S')) m_sort.addElement( options.getOptionParam('S') ); /* -l time limit */ if (options.hasOption('l')) { /* if the option is -l */ try { m_timelimit = Integer.parseInt(options.getOptionParam('l')); } catch (NumberFormatException e) { m_timelimit = 0; } } /* if the option is -l */ /* -s search scope */ if (options.hasOption('s')) { /* has option s */ String param = options.getOptionParam('s'); if (param.equalsIgnoreCase("base")) m_scope = 0; else if (param.equalsIgnoreCase("one")) m_scope = 1; else if (param.equalsIgnoreCase("sub")) m_scope = 2; else System.err.println("Error: scope should be base, " + "one or sub."); } /* has option s */ /* -z size limit */ if (options.hasOption('z')) { /* if the option is -z */ try { m_sizelimit = Integer.parseInt(options.getOptionParam('z')); } catch (NumberFormatException e) { m_sizelimit = 0; } } /* if the option is -z */ /* -T fold line */ if (options.hasOption('T')) { /* if the option is -T */ m_foldLine = false; } if (options.hasOption('X')) m_printDSML = true; parseVlv(options); /* extract the filter string and attributes */ Enumeration pa = options.getParameters().elements(); Vector vec = new Vector(); while (pa.hasMoreElements()) { /* while */ vec.addElement(pa.nextElement()); } /* while */ int counter = vec.size(); if (counter <= 0) { /* No filter */ System.err.println("Error: must supply filter string!"); doUsage(); System.exit(0); } /* No filter */ if (counter == 1) { /* Has filter but no attributes */ /* gets filter string */ m_filter = (String)vec.elementAt(0); if (m_verbose) System.err.println("filter pattern: "+m_filter); /* no attributes */ m_attrs = null; if (m_verbose) { System.err.println("returning: ALL"); System.err.println("filter is: ("+m_filter+")"); } } /* Has filter but no attributes */ if (counter > 1) { /* Has filter and attributes */ /* gets filter string */ m_filter = (String)vec.elementAt(0); if (m_verbose) { System.err.println("filter pattern: "+m_filter); System.err.print("returning:"); } /* gets attributes */ m_attrs = new String[counter]; for (int j = 1; j < counter; j++) { m_attrs[j-1] = (String)vec.elementAt(j); if (m_verbose) System.err.print(" "+m_attrs[j-1]); } if (m_verbose) { System.err.println(); System.err.println("filter is: ("+m_filter+")"); } } /* Has filter and attributes */ } private static void parseVlv(GetOpt options) { /* -G virtual list */ if (options.hasOption('G')) { /* if the option is -G */ String val = options.getOptionParam('G'); StringTokenizer tokenizer = new StringTokenizer(val, ":"); m_vlvTokens = tokenizer.countTokens(); if (m_vlvTokens < 3) { doUsage(); System.exit(0); } try { m_beforeCount = Integer.parseInt((String)tokenizer.nextElement()); } catch (NumberFormatException e) { m_beforeCount = 0; } try { m_afterCount = Integer.parseInt((String)tokenizer.nextElement()); } catch (NumberFormatException e) { m_afterCount = 0; } if (m_vlvTokens == 3) { m_searchVal = (String)tokenizer.nextElement(); } else if (m_vlvTokens > 3) { try { m_index = Integer.parseInt((String)tokenizer.nextElement()); } catch (NumberFormatException e) { m_index = 0; } try { m_count = Integer.parseInt((String)tokenizer.nextElement()); } catch (NumberFormatException e) { m_count = 0; } } } /* if the option is -G */ } /** * This class-method is used to call the LDAP Search Operation with the * specified options, parameters, filters and/or attributes. */ private static void dosearch() { LDAPControl[] controls = null; try { Vector cons = new Vector(); LDAPSortControl sort = null; if ( m_sortOnServer && (m_sort.size() > 0) ) { LDAPSortKey[] keys = new LDAPSortKey[m_sort.size()]; for( int i = 0; i < keys.length; i++ ) { keys[i] = new LDAPSortKey( (String)m_sort.elementAt(i) ); } sort = new LDAPSortControl( keys, true ); cons.addElement(sort); } if ((sort == null) && (m_vlvTokens >= 3)) { System.err.println("Server-side sorting is required for "+ "virtual list option"); doUsage(); System.exit(0); } LDAPVirtualListControl vControl = null; if (m_vlvTokens == 3) { vControl = new LDAPVirtualListControl(m_searchVal, m_beforeCount, m_afterCount); } else if (m_vlvTokens > 3) { vControl = new LDAPVirtualListControl(m_index, m_beforeCount, m_afterCount, m_count); } if (vControl != null) cons.addElement(vControl); if (m_proxyControl != null) cons.addElement(m_proxyControl); if (m_ordinary) { LDAPControl manageDSAITControl = new LDAPControl( LDAPControl.MANAGEDSAIT, true, null); cons.addElement(manageDSAITControl); } if (cons.size() > 0) { controls = new LDAPControl[cons.size()]; cons.copyInto(controls); } } catch (Exception e) { System.err.println( e.toString() ); System.exit(0); } /* perform an LDAP Search Operation */ LDAPSearchResults res = null; try { LDAPSearchConstraints cons = m_client.getSearchConstraints(); cons.setServerControls(controls); cons.setDereference( m_deref ); cons.setMaxResults( m_sizelimit ); cons.setServerTimeLimit( m_timelimit ); cons.setReferrals( m_referrals ); if ( m_referrals ) { setDefaultReferralCredentials( cons ); } cons.setHopLimit( m_hopLimit ); res = m_client.search( m_base, m_scope, m_filter, m_attrs, m_attrsonly, cons ); } catch (Exception e) { System.err.println( e.toString() ); System.exit(1); } /* Sort? */ if ( (m_sort.size() > 0) && !m_sortOnServer ) { String[] sortAttrs = new String[m_sort.size()]; for( int i = 0; i < sortAttrs.length; i++ ) sortAttrs[i] = (String)m_sort.elementAt( i ); res.sort( new LDAPCompareAttrNames( sortAttrs ) ); } /* print out the values of the entries */ printResults( res ); /* Any sort control responses? */ showControls( m_client.getResponseControls() ); } /** * Print the result entries. * @param res Search results */ private static void printResults( LDAPSearchResults res ) { boolean isSchema = false; boolean didEntryIntro = false; LDAPWriter writer; if ( m_printDSML ) { printString( DSML_INTRO ); writer = new DSMLWriter( m_pw ); } else { writer = new LDIFWriter( m_pw, m_attrsonly, m_sep, m_foldLine, m_tempFiles ); } /* print out the retrieved entries */ try { /* Loop on results until finished */ while ( res.hasMoreElements() ) { LDAPEntry entry = null; try { /* Next directory entry */ entry = (LDAPEntry)res.next(); } catch (LDAPReferralException ee) { LDAPUrl[] urls= ee.getURLs(); System.err.println("Referral entries: "); for (int i=0; i
* usage : java LDAPDelete [options] DN * for example : java -D "dn" -w password -h ds.internic.net -p 389 * "cn=Johnny James,o=Ace Industry" * * options: {np = no parameters, p = requires parameters} * 'D' bind DN --------------------------------------------- p * 'h' LDAP host ------------------------------------------- p * 'p' LDAP port ------------------------------------------- p * 'w' bind password --------------------------------------- p * * note: '-' or '/' is used to distinct the option field. * e.g. -a -b /c /d parameter -e parameter * ** * @version 1.0 */ public class LDAPDelete extends LDAPTool { /* LDAPDelete */ public static void main(String args[]) { /* main */ if ( args.length < 1 ) { doUsage(); System.exit(1); } /* extract parameters from the arguments list */ extractParameters(args); if (!m_justShow) { /* perform an LDAP client connection operation */ try { m_client = new LDAPConnection(); m_client.connect( m_ldaphost, m_ldapport ); } catch(Exception e) { System.err.println("Error: client connection failed!"); System.exit(1); } /* perform an LDAP bind operation */ try { m_client.authenticate( m_version, m_binddn, m_passwd ); } catch (Exception e) { System.err.println( e.toString() ); System.exit(1); } /* perform a delete operation */ dodelete(); /* disconnect */ try { m_client.disconnect(); } catch (Exception e) { System.err.println( e.toString() ); } } else dodelete(null); System.exit(0); } /* main */ /** * Prints usage. */ private static void doUsage() { System.err.println( "usage: LDAPDelete [options] dn" ); System.err.println("options"); System.err.println(" -h host LDAP server name or IP address"); System.err.println(" -p port LDAP server TCP port number"); System.err.println(" -V version LDAP protocol version " + "number (default is 3)"); System.err.println(" -D binddn bind dn"); System.err.println(" -w password bind passwd (for simple " + "authentication)"); System.err.println(" -d level set LDAP debugging level " + "to \'level\'"); System.err.println(" -f file read DNs to delete from file"); System.err.println(" -R do not automatically follow " + "referrals"); System.err.println(" -O hop limit maximum number of referral " + "hops to traverse"); System.err.println(" -H display usage information"); System.err.println(" -c continuous mode (do not "+ "stop on errors)"); System.err.println(" -M manage references (treat them "+ "as regular entries)"); System.err.println(" -y proxy-DN DN to use for access control"); } /** * This class-method is used to extract specified parameters from the * arguments list. */ protected static void extractParameters(String args[]) { GetOpt options = LDAPTool.extractParameters( "Hcf:", args ); /* -H Help */ if (options.hasOption('H')) { doUsage(); System.exit(0); } /* Help */ /* -c continuous mode */ if (options.hasOption('c')) { m_cont = true; } /* continous mode */ /* -f file */ if (options.hasOption('f')) { String filename = options.getOptionParam('f'); if (filename == null) { doUsage(); System.exit(0); } try { FileInputStream fs = new FileInputStream(filename); DataInputStream ds = new DataInputStream(fs); m_reader = new BufferedReader(new InputStreamReader(ds)); } catch (FileNotFoundException e) { System.err.println("File "+filename+" not found"); } catch (IOException e) { System.err.println("Error in opening the file "+filename); } } /* input file */ if (m_reader == null) { Enumeration pa = options.getParameters().elements(); Vector vec = new Vector(); while (pa.hasMoreElements()) { /* while */ vec.addElement(pa.nextElement()); } if (vec.size() <= 0) { doUsage(); System.exit(0); } m_delete_dn = new String[vec.size()]; vec.copyInto(m_delete_dn); } } /* extract parameters */ /** * This class-method is used to call the LDAP Delete Operation with the * specified options, and/or parameters. */ private static void dodelete() { /* dodelete */ int msgid = 0; LDAPConstraints cons = m_client.getConstraints(); Vector controlVector = new Vector(); if (m_proxyControl != null) controlVector.addElement(m_proxyControl); if (m_ordinary) { controlVector.addElement( new LDAPControl( LDAPControl.MANAGEDSAIT, true, null) ); } if (controlVector.size() > 0) { LDAPControl[] controls = new LDAPControl[controlVector.size()]; controlVector.copyInto(controls); cons.setServerControls(controls); } cons.setReferrals( m_referrals ); if ( m_referrals ) { setDefaultReferralCredentials( cons ); } cons.setHopLimit( m_hopLimit ); dodelete(cons); } /* dodelete */ private static void dodelete(LDAPConstraints cons) { try { if (m_reader == null) { for (int i=0; i