home *** CD-ROM | disk | FTP | other *** search
- package netscape.ldap;
-
- import java.lang.reflect.Method;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import netscape.ldap.client.JDAPAVA;
- import netscape.ldap.client.JDAPMessage;
- import netscape.ldap.client.opers.JDAPAbandonRequest;
- import netscape.ldap.client.opers.JDAPAddRequest;
- import netscape.ldap.client.opers.JDAPBindRequest;
- import netscape.ldap.client.opers.JDAPCompareRequest;
- import netscape.ldap.client.opers.JDAPDeleteRequest;
- import netscape.ldap.client.opers.JDAPExtendedRequest;
- import netscape.ldap.client.opers.JDAPExtendedResponse;
- import netscape.ldap.client.opers.JDAPModifyRDNRequest;
- import netscape.ldap.client.opers.JDAPModifyRequest;
- import netscape.ldap.client.opers.JDAPProtocolOp;
- import netscape.ldap.client.opers.JDAPResult;
- import netscape.ldap.client.opers.JDAPSearchRequest;
-
- public class LDAPConnection implements LDAPv3, Cloneable {
- public static final int LDAP_VERSION = 2;
- public static final String LDAP_PROPERTY_SDK = "version.sdk";
- public static final String LDAP_PROPERTY_PROTOCOL = "version.protocol";
- public static final String LDAP_PROPERTY_SECURITY = "version.security";
- private static final String defaultFilter = "(objectClass=*)";
- private static final LDAPSearchConstraints readConstraints = new LDAPSearchConstraints();
- private transient LDAPSearchConstraints defaultConstraints = new LDAPSearchConstraints();
- private transient Vector responseListeners;
- private transient Vector searchListeners;
- private transient boolean bound;
- private transient String host;
- private transient String[] m_hostList;
- private transient int port = -1;
- private transient int[] m_portList;
- private transient int m_defaultPort;
- private transient String prevBoundDN;
- private transient String prevBoundPasswd;
- private transient String boundDN;
- private transient String boundPasswd;
- private transient int protocolVersion = 2;
- private transient LDAPSocketFactory m_factory;
- // $FF: renamed from: th netscape.ldap.LDAPConnThread
- private transient LDAPConnThread field_0;
- private transient Vector m_attachedList = new Vector();
- private transient Hashtable m_responseControlTable = new Hashtable();
- private transient LDAPCache m_cache;
- private transient boolean needAuthenticate = false;
- static Hashtable m_threadConnTable = new Hashtable();
- private static final Float SdkVersion = new Float(3.01F);
- private static final Float ProtocolVersion = new Float(3.0F);
- private static final String SecurityVersion = new String("none,simple");
- private static final Float MajorVersion = new Float(0.9F);
- private static final Float MinorVersion = new Float(0.1F);
- private static final String DELIM = "#";
- private static final String PersistSearchPackageName = "netscape.ldap.controls.LDAPPersistSearchControl";
- private static boolean isCommunicator = checkCommunicator();
- private static final boolean debug = false;
-
- public LDAPConnection() {
- this.m_factory = null;
- }
-
- public LDAPConnection(LDAPSocketFactory var1) {
- this.m_factory = var1;
- }
-
- public void finalize() throws LDAPException {
- if (this.field_0 != null) {
- this.disconnect();
- }
-
- }
-
- public void setCache(LDAPCache var1) {
- this.m_cache = var1;
- }
-
- public LDAPCache getCache() {
- return this.m_cache;
- }
-
- public Object getProperty(String var1) throws LDAPException {
- if (var1.equals("version.sdk")) {
- return SdkVersion;
- } else if (var1.equals("version.protocol")) {
- return ProtocolVersion;
- } else if (var1.equals("version.security")) {
- return SecurityVersion;
- } else if (var1.equals("version.major")) {
- return MajorVersion;
- } else {
- return var1.equals("version.minor") ? MinorVersion : null;
- }
- }
-
- public void setProperty(String var1, Object var2) throws LDAPException {
- }
-
- private void setProtocolVersion(int var1) {
- this.protocolVersion = var1;
- }
-
- public String getHost() {
- return this.host;
- }
-
- public int getPort() {
- return this.port;
- }
-
- public String getAuthenticationDN() {
- return this.boundDN;
- }
-
- public String getAuthenticationPassword() {
- return this.boundPasswd;
- }
-
- public LDAPSocketFactory getSocketFactory() {
- return this.m_factory;
- }
-
- public void setSocketFactory(LDAPSocketFactory var1) {
- this.m_factory = var1;
- }
-
- public boolean isConnected() {
- return this.field_0 != null;
- }
-
- public boolean isAuthenticated() {
- return this.bound;
- }
-
- public void connect(String var1, int var2) throws LDAPException {
- this.connect(var1, var2, (String)null, (String)null);
- }
-
- public void connect(String var1, int var2, String var3, String var4) throws LDAPException {
- if (this.field_0 != null) {
- this.disconnect();
- }
-
- if (var1 == null) {
- throw new LDAPException("no host for connection", 89);
- } else {
- this.m_defaultPort = var2;
- StringTokenizer var5 = new StringTokenizer(var1);
- this.m_hostList = new String[var5.countTokens()];
- this.m_portList = new int[var5.countTokens()];
-
- for(int var6 = 0; var5.hasMoreTokens(); ++var6) {
- String var7 = var5.nextToken();
- int var8 = var7.indexOf(58);
- if (var8 > 0) {
- this.m_hostList[var6] = var7.substring(0, var8);
- this.m_portList[var6] = Integer.parseInt(var7.substring(var8 + 1));
- } else {
- this.m_hostList[var6] = var7;
- this.m_portList[var6] = this.m_defaultPort;
- }
- }
-
- LDAPException var11 = null;
-
- for(int var10 = 0; var10 < this.m_hostList.length; ++var10) {
- try {
- this.host = this.m_hostList[var10];
- this.port = this.m_portList[var10];
- this.connect();
- var11 = null;
- break;
- } catch (LDAPException var9) {
- var11 = var9;
- }
- }
-
- if (var11 != null) {
- this.host = this.m_hostList[0];
- this.port = this.m_defaultPort;
- throw var11;
- } else {
- if (var3 != null && var4 != null) {
- this.authenticate(var3, var4);
- }
-
- }
- }
- }
-
- public void connect(int var1, String var2, int var3, String var4, String var5) throws LDAPException {
- this.setProtocolVersion(var1);
- this.connect(var2, var3, var4, var5);
- }
-
- private synchronized void connect() throws LDAPException {
- if (this.field_0 == null) {
- if (this.host != null && this.port >= 0) {
- this.field_0 = this.getNewThread(this.host, this.port, this.m_factory, this.m_cache);
- } else {
- throw new LDAPException("no connection parameters", 89);
- }
- }
- }
-
- private synchronized LDAPConnThread getNewThread(String var1, int var2, LDAPSocketFactory var3, LDAPCache var4) throws LDAPException {
- LDAPConnThread var5 = null;
- Vector var6 = null;
- Hashtable var7 = m_threadConnTable;
- synchronized(var7){}
-
- try {
- Enumeration var9 = m_threadConnTable.keys();
- boolean var10 = false;
-
- while(var9.hasMoreElements()) {
- LDAPConnThread var11 = (LDAPConnThread)var9.nextElement();
- Vector var12 = (Vector)m_threadConnTable.get(var11);
- Enumeration var13 = var12.elements();
-
- while(var13.hasMoreElements()) {
- LDAPConnection var14 = (LDAPConnection)var13.nextElement();
- if (var14.equals(this)) {
- var10 = true;
- if (!((Thread)var11).isAlive()) {
- try {
- var5 = new LDAPConnThread(var1, var2, var3, var4);
- var6 = (Vector)m_threadConnTable.remove(var11);
- } catch (Exception var19) {
- throw new LDAPException("unable to establish connection", 52);
- }
- }
- break;
- }
- }
-
- if (var10) {
- break;
- }
- }
-
- if (!var10) {
- try {
- var5 = new LDAPConnThread(var1, var2, var3, var4);
- var6 = new Vector();
- var6.addElement(this);
- } catch (Exception var18) {
- throw new LDAPException("unable to establish connection", 52);
- }
- }
-
- if (var5 != null) {
- m_threadConnTable.put(var5, var6);
- int var21 = 0;
-
- for(int var22 = var6.size(); var21 < var22; ++var21) {
- LDAPConnection var23 = (LDAPConnection)var6.elementAt(var21);
- var5.register(var23);
- var23.field_0 = var5;
- }
- }
- } catch (Throwable var20) {
- throw var20;
- }
-
- return var5;
- }
-
- public void abandon(LDAPSearchResults var1) throws LDAPException {
- if (this.field_0 != null && var1 != null) {
- var1.abandon();
- int var2 = var1.getID();
-
- for(int var3 = 0; var3 < 3; ++var3) {
- try {
- this.field_0.abandon(var2);
- this.field_0.sendRequest(new JDAPAbandonRequest(var2), (LDAPResponseListener)null, this.defaultConstraints);
- break;
- }
- }
-
- if (this.field_0 == null) {
- throw new LDAPException("Failed to send abandon request to the server.", 80);
- }
- }
- }
-
- public void authenticate(String var1, String var2) throws LDAPException {
- this.authenticate(this.protocolVersion, var1, var2);
- }
-
- public void authenticate(int var1, String var2, String var3) throws LDAPException {
- this.prevBoundDN = this.boundDN;
- this.prevBoundPasswd = this.boundPasswd;
- this.boundDN = var2;
- this.boundPasswd = var3;
- this.needAuthenticate = true;
- this.bind(var1);
- this.needAuthenticate = false;
- }
-
- private void bind(int var1) throws LDAPException {
- if (this.field_0 == null) {
- this.connect();
- }
-
- if (this.bound && this.needAuthenticate) {
- if (this.protocolVersion == var1) {
- if (this.field_0.getClientCount() == 1 && this.boundDN == null) {
- LDAPResponseListener var22 = this.getResponseListener();
-
- try {
- this.sendRequest(new JDAPBindRequest(this.protocolVersion, this.boundDN, this.boundPasswd), var22, this.defaultConstraints);
- JDAPMessage var23 = var22.getResponse();
- this.checkMsg(var23);
- this.bound = false;
- } finally {
- this.releaseResponseListener(var22);
- }
-
- return;
- }
-
- if (this.boundDN != null && this.boundPasswd != null && this.boundDN.equals(this.prevBoundDN) && this.boundPasswd.equals(this.prevBoundPasswd)) {
- return;
- }
- }
-
- if (this.field_0.getClientCount() > 1) {
- this.disconnect();
- this.connect();
- }
- }
-
- if (!this.bound) {
- this.protocolVersion = var1;
- if (this.boundDN == null) {
- this.bound = false;
- } else {
- LDAPResponseListener var2 = this.getResponseListener();
-
- try {
- this.sendRequest(new JDAPBindRequest(this.protocolVersion, this.boundDN, this.boundPasswd), var2, this.defaultConstraints);
- JDAPMessage var3 = var2.getResponse();
- this.checkMsg(var3);
- } finally {
- this.releaseResponseListener(var2);
- }
-
- Hashtable var4 = m_threadConnTable;
- synchronized(var4){}
-
- try {
- if (m_threadConnTable.containsKey(this.field_0)) {
- Vector var6 = (Vector)m_threadConnTable.get(this.field_0);
- int var7 = 0;
-
- for(int var8 = var6.size(); var7 < var8; ++var7) {
- LDAPConnection var9 = (LDAPConnection)var6.elementAt(var7);
- var9.bound = true;
- }
- } else {
- printDebug("Thread table does not contain the specified thread");
- }
- } catch (Throwable var21) {
- throw var21;
- }
-
- }
- }
- }
-
- private void sendRequest(JDAPProtocolOp var1, LDAPResponseListener var2, LDAPSearchConstraints var3) throws LDAPException {
- for(int var4 = 0; var4 < 3; ++var4) {
- try {
- this.field_0.sendRequest(var1, var2, var3);
- break;
- }
- }
-
- if (this.field_0 == null) {
- throw new LDAPException("The connection is not available", 80);
- }
- }
-
- private void bind() throws LDAPException {
- this.bind(this.protocolVersion);
- }
-
- public synchronized void disconnect() throws LDAPException {
- if (this.field_0 == null) {
- throw new LDAPException("unable to disconnect() without connecting", 80);
- } else {
- if (this.m_cache != null) {
- this.m_cache.cleanup();
- this.m_cache = null;
- }
-
- this.deleteThreadConnEntry();
- this.deregisterConnection();
- }
- }
-
- private void deleteThreadConnEntry() {
- Hashtable var1 = m_threadConnTable;
- synchronized(var1){}
-
- try {
- Enumeration var3 = m_threadConnTable.keys();
-
- while(var3.hasMoreElements()) {
- LDAPConnThread var4 = (LDAPConnThread)var3.nextElement();
- Vector var5 = (Vector)m_threadConnTable.get(var4);
- Enumeration var6 = var5.elements();
-
- while(var6.hasMoreElements()) {
- LDAPConnection var7 = (LDAPConnection)var6.nextElement();
- if (var7.equals(this)) {
- var5.removeElement(var7);
- return;
- }
- }
- }
-
- } catch (Throwable var9) {
- throw var9;
- }
- }
-
- synchronized void deregisterConnection() {
- this.field_0.deregister(this);
- this.field_0 = null;
- this.bound = false;
- }
-
- public LDAPEntry read(String var1) throws LDAPException {
- return this.read(var1, (String[])null);
- }
-
- public LDAPEntry read(String var1, String[] var2) throws LDAPException {
- return this.read(var1, var2, this.defaultConstraints);
- }
-
- private LDAPEntry read(String var1, String[] var2, LDAPSearchConstraints var3) throws LDAPException {
- LDAPSearchResults var4 = this.search(var1, 0, "(objectClass=*)", var2, false, var3);
- return var4 == null ? null : var4.next();
- }
-
- public static LDAPEntry read(LDAPUrl var0) throws LDAPException {
- String var1 = var0.getHost();
- int var2 = var0.getPort();
- if (var1 == null) {
- throw new LDAPException("no host for connection", 89);
- } else {
- String[] var3 = var0.getAttributeArray();
- String var4 = var0.getDN();
- LDAPConnection var6 = new LDAPConnection();
- var6.connect(var1, var2);
- LDAPEntry var5 = var6.read(var4, var3);
- var6.disconnect();
- return var5;
- }
- }
-
- public static LDAPSearchResults search(LDAPUrl var0) throws LDAPException {
- return search(var0, (LDAPSearchConstraints)null);
- }
-
- public static LDAPSearchResults search(LDAPUrl var0, LDAPSearchConstraints var1) throws LDAPException {
- String var2 = var0.getHost();
- int var3 = var0.getPort();
- if (var2 == null) {
- throw new LDAPException("no host for connection", 89);
- } else {
- String[] var4 = var0.getAttributeArray();
- String var5 = var0.getDN();
- String var6 = var0.getFilter();
- if (var6 == null) {
- var6 = "(objectClass=*)";
- }
-
- int var7 = var0.getScope();
- LDAPConnection var8 = new LDAPConnection();
- var8.connect(var2, var3);
- LDAPSearchResults var9;
- if (var1 != null) {
- var9 = var8.search(var5, var7, var6, var4, false, var1);
- } else {
- var9 = var8.search(var5, var7, var6, var4, false);
- }
-
- var9.closeOnCompletion(var8);
- return var9;
- }
- }
-
- public LDAPSearchResults search(String var1, int var2, String var3, String[] var4, boolean var5) throws LDAPException {
- return this.search(var1, var2, var3, var4, var5, this.defaultConstraints);
- }
-
- public LDAPSearchResults search(String var1, int var2, String var3, String[] var4, boolean var5, LDAPSearchConstraints var6) throws LDAPException {
- LDAPSearchResults var7 = new LDAPSearchResults();
- Object var8 = null;
- Long var9 = null;
- boolean var10 = true;
-
- try {
- if (this.m_cache != null) {
- var9 = this.m_cache.createKey(this.host, this.port, var1, var3, var2, var4, this.boundDN, var6);
- Vector var65 = (Vector)this.m_cache.getEntry(var9);
- if (var65 != null) {
- return new LDAPSearchResults(var65);
- }
- }
- } catch (LDAPException var56) {
- var10 = false;
- System.out.println("Exception: " + var56);
- }
-
- this.bind();
- LDAPSearchListener var11 = this.getSearchListener();
- int var12 = var6.getDereference();
- JDAPSearchRequest var13 = new JDAPSearchRequest(var1, var2, var12, var6.getMaxResults(), var6.getTimeLimit(), var5, var3, var4);
- synchronized(var11){}
-
- try {
- boolean var16 = false;
-
- try {
- this.sendRequest(var13, var11, var6);
- var16 = true;
- } finally {
- if (!var16) {
- this.releaseSearchListener(var11);
- }
-
- }
-
- if (this.m_cache != null && var10) {
- var11.setKey(var9);
- }
- } catch (Throwable var58) {
- throw var58;
- }
-
- if (var6.getBatchSize() == 0) {
- LDAPSearchResults var67;
- try {
- LDAPSearchResults[] var18;
- try {
- JDAPMessage var17 = ((LDAPResponseListener)var11).getResponse();
- Enumeration var70 = var11.getSearchResults();
- if (!var70.hasMoreElements()) {
- this.checkMsg(var17);
- }
-
- while(var70.hasMoreElements()) {
- var7.add(((JDAPMessage)var70.nextElement()).getProtocolOp());
- }
-
- return var7;
- } catch (LDAPReferralException var59) {
- var18 = new LDAPSearchResults[1];
- this.performReferrals(var59, var6, 3, var1, var2, var3, var4, var5, (LDAPModification[])null, (LDAPEntry)null, (LDAPAttribute)null, var18, (boolean[])null);
- if (var18[0] == null) {
- var18[0] = new LDAPSearchResults();
- }
- } catch (LDAPException var60) {
- throw var60;
- }
-
- var67 = var18[0];
- } finally {
- this.releaseSearchListener(var11);
- }
-
- return var67;
- } else {
- JDAPMessage var14 = var11.nextResult();
- if (var14 == null) {
- var14 = ((LDAPResponseListener)var11).getResponse();
-
- LDAPSearchResults var68;
- try {
- LDAPSearchResults[] var19;
- try {
- this.checkMsg(var14);
- return var7;
- } catch (LDAPReferralException var62) {
- var19 = new LDAPSearchResults[1];
- this.performReferrals(var62, var6, 3, var1, var2, var3, var4, var5, (LDAPModification[])null, (LDAPEntry)null, (LDAPAttribute)null, var19, (boolean[])null);
- if (var19[0] == null) {
- var19[0] = new LDAPSearchResults();
- }
- } catch (LDAPException var63) {
- throw var63;
- }
-
- var68 = var19[0];
- } finally {
- this.releaseSearchListener(var11);
- }
-
- return var68;
- } else {
- var7.add(var14.getProtocolOp());
- LDAPControl[] var15 = (LDAPControl[])getOption(12, var6);
- if (var15 != null && var15.length > 0) {
- for(int var69 = 0; var69 < var15.length; ++var69) {
- if (var15[var69].getClass().getName().equals("netscape.ldap.controls.LDAPPersistSearchControl")) {
- var7.associatePersistentSearch(var11);
- return var7;
- }
- }
- }
-
- var7.associate(var11);
- return var7;
- }
- }
- }
-
- public boolean compare(String var1, LDAPAttribute var2) throws LDAPException {
- return this.compare(var1, var2, this.defaultConstraints);
- }
-
- private boolean compare(String var1, LDAPAttribute var2, LDAPSearchConstraints var3) throws LDAPException {
- this.bind();
- LDAPResponseListener var4 = this.getResponseListener();
- Enumeration var5 = var2.getByteValues();
- byte[] var6 = (byte[])var5.nextElement();
- String var7 = "";
-
- try {
- var7 = new String(var6, "UTF8");
- } catch (Throwable var18) {
- }
-
- JDAPAVA var8 = new JDAPAVA(var2.getName(), var7);
-
- boolean var21;
- try {
- this.sendRequest(new JDAPCompareRequest(var1, var8), var4, var3);
- JDAPMessage var9 = var4.getResponse();
- int var13 = ((JDAPResult)var9.getProtocolOp()).getResultCode();
- if (var13 != 5) {
- if (var13 == 6) {
- var21 = true;
- return var21;
- }
-
- this.checkMsg(var9);
- return false;
- }
-
- var21 = false;
- } catch (LDAPReferralException var19) {
- boolean[] var14 = new boolean[1];
- this.performReferrals(var19, var3, 14, var1, 0, (String)null, (String[])null, false, (LDAPModification[])null, (LDAPEntry)null, var2, (LDAPSearchResults[])null, var14);
- var21 = var14[0];
- return var21;
- } finally {
- this.releaseResponseListener(var4);
- }
-
- return var21;
- }
-
- public void add(LDAPEntry var1) throws LDAPException {
- this.add(var1, this.defaultConstraints);
- }
-
- private void add(LDAPEntry var1, LDAPSearchConstraints var2) throws LDAPException {
- this.bind();
- LDAPResponseListener var3 = this.getResponseListener();
- LDAPAttributeSet var4 = var1.getAttributeSet();
- LDAPAttribute[] var5 = new LDAPAttribute[var4.size()];
-
- for(int var6 = 0; var6 < var4.size(); ++var6) {
- var5[var6] = var4.elementAt(var6);
- }
-
- try {
- this.sendRequest(new JDAPAddRequest(var1.getDN(), var5), var3, var2);
- JDAPMessage var7 = var3.getResponse();
- this.checkMsg(var7);
- } catch (LDAPReferralException var13) {
- this.performReferrals(var13, var2, 8, (String)null, 0, (String)null, (String[])null, false, (LDAPModification[])null, var1, (LDAPAttribute)null, (LDAPSearchResults[])null, (boolean[])null);
- } finally {
- this.releaseResponseListener(var3);
- }
-
- }
-
- public LDAPExtendedOperation extendedOperation(LDAPExtendedOperation var1) throws LDAPException {
- this.bind();
- LDAPResponseListener var2 = this.getResponseListener();
- Object var3 = null;
- Object var4 = null;
- LDAPSearchConstraints var6 = this.defaultConstraints;
-
- LDAPExtendedOperation var7;
- try {
- this.sendRequest(new JDAPExtendedRequest(var1.getID(), var1.getValue()), var2, var6);
- JDAPMessage var15 = var2.getResponse();
- this.checkMsg(var15);
- JDAPExtendedResponse var10 = (JDAPExtendedResponse)var15.getProtocolOp();
- byte[] var16 = var10.getValue();
- String var5 = var10.getID();
- return new LDAPExtendedOperation(var5, var16);
- } catch (LDAPReferralException var13) {
- var7 = this.performExtendedReferrals(var13, var6, var1);
- } finally {
- this.releaseResponseListener(var2);
- }
-
- return var7;
- }
-
- public void modify(String var1, LDAPModification var2) throws LDAPException {
- this.modify(var1, var2, this.defaultConstraints);
- }
-
- private void modify(String var1, LDAPModification var2, LDAPSearchConstraints var3) throws LDAPException {
- LDAPModification[] var4 = new LDAPModification[]{var2};
- this.modify(var1, var4, var3);
- }
-
- public void modify(String var1, LDAPModificationSet var2) throws LDAPException {
- this.modify(var1, var2, this.defaultConstraints);
- }
-
- private void modify(String var1, LDAPModificationSet var2, LDAPSearchConstraints var3) throws LDAPException {
- LDAPModification[] var4 = new LDAPModification[var2.size()];
-
- for(int var5 = 0; var5 < var2.size(); ++var5) {
- var4[var5] = var2.elementAt(var5);
- }
-
- this.modify(var1, var4, var3);
- }
-
- private void modify(String var1, LDAPModification[] var2) throws LDAPException {
- this.modify(var1, var2, this.defaultConstraints);
- }
-
- private void modify(String var1, LDAPModification[] var2, LDAPSearchConstraints var3) throws LDAPException {
- this.bind();
- LDAPResponseListener var4 = this.getResponseListener();
- Object var5 = null;
-
- try {
- this.sendRequest(new JDAPModifyRequest(var1, var2), var4, var3);
- JDAPMessage var13 = var4.getResponse();
- this.checkMsg(var13);
- } catch (LDAPReferralException var11) {
- this.performReferrals(var11, var3, 6, var1, 0, (String)null, (String[])null, false, var2, (LDAPEntry)null, (LDAPAttribute)null, (LDAPSearchResults[])null, (boolean[])null);
- } finally {
- this.releaseResponseListener(var4);
- }
-
- }
-
- public void delete(String var1) throws LDAPException {
- this.delete(var1, this.defaultConstraints);
- }
-
- private void delete(String var1, LDAPSearchConstraints var2) throws LDAPException {
- this.bind();
- LDAPResponseListener var3 = this.getResponseListener();
-
- try {
- this.sendRequest(new JDAPDeleteRequest(var1), var3, var2);
- JDAPMessage var4 = var3.getResponse();
- this.checkMsg(var4);
- } catch (LDAPReferralException var10) {
- this.performReferrals(var10, var2, 10, var1, 0, (String)null, (String[])null, false, (LDAPModification[])null, (LDAPEntry)null, (LDAPAttribute)null, (LDAPSearchResults[])null, (boolean[])null);
- } finally {
- this.releaseResponseListener(var3);
- }
-
- }
-
- public void rename(String var1, String var2, boolean var3) throws LDAPException {
- this.rename(var1, var2, (String)null, var3);
- }
-
- public void rename(String var1, String var2, String var3, boolean var4) throws LDAPException {
- this.rename(var1, var2, var3, var4, this.defaultConstraints);
- }
-
- private void rename(String var1, String var2, String var3, boolean var4, LDAPSearchConstraints var5) throws LDAPException {
- this.bind();
- LDAPResponseListener var6 = this.getResponseListener();
-
- try {
- Object var10 = null;
- JDAPModifyRDNRequest var15;
- if (var3 != null) {
- var15 = new JDAPModifyRDNRequest(var1, var2, var4, var3);
- } else {
- var15 = new JDAPModifyRDNRequest(var1, var2, var4);
- }
-
- this.sendRequest(var15, var6, var5);
- JDAPMessage var7 = var6.getResponse();
- this.checkMsg(var7);
- } catch (LDAPReferralException var13) {
- this.performReferrals(var13, var5, 12, var1, 0, var2, (String[])null, var4, (LDAPModification[])null, (LDAPEntry)null, (LDAPAttribute)null, (LDAPSearchResults[])null, (boolean[])null);
- } finally {
- this.releaseResponseListener(var6);
- }
-
- }
-
- public Object getOption(int var1) throws LDAPException {
- return var1 == 17 ? new Integer(this.protocolVersion) : getOption(var1, this.defaultConstraints);
- }
-
- private static Object getOption(int var0, LDAPSearchConstraints var1) throws LDAPException {
- switch (var0) {
- case 2:
- return new Integer(var1.getDereference());
- case 3:
- return new Integer(var1.getMaxResults());
- case 4:
- return new Integer(var1.getTimeLimit());
- case 8:
- return new Boolean(var1.getReferrals());
- case 9:
- return var1.getRebindProc();
- case 10:
- return new Integer(var1.getHopLimit());
- case 11:
- return var1.getClientControls();
- case 12:
- return var1.getServerControls();
- case 20:
- return new Integer(var1.getBatchSize());
- default:
- throw new LDAPException("invalid option", 89);
- }
- }
-
- public void setOption(int var1, Object var2) throws LDAPException {
- if (var1 == 17) {
- this.setProtocolVersion((Integer)var2);
- } else {
- setOption(var1, var2, this.defaultConstraints);
- }
- }
-
- private static void setOption(int var0, Object var1, LDAPSearchConstraints var2) throws LDAPException {
- try {
- switch (var0) {
- case 2:
- var2.setDereference((Integer)var1);
- return;
- case 3:
- var2.setMaxResults((Integer)var1);
- return;
- case 4:
- var2.setTimeLimit((Integer)var1);
- return;
- case 8:
- var2.setReferrals((Boolean)var1);
- return;
- case 9:
- var2.setRebindProc((LDAPRebind)var1);
- return;
- case 10:
- var2.setHopLimit((Integer)var1);
- return;
- case 11:
- if (var1 == null) {
- var2.setClientControls((LDAPControl[])null);
- return;
- } else if (var1 instanceof LDAPControl) {
- var2.setClientControls((LDAPControl)var1);
- return;
- } else {
- if (var1 instanceof LDAPControl[]) {
- var2.setClientControls((LDAPControl[])var1);
- return;
- }
-
- throw new LDAPException("invalid LDAPControl", 89);
- }
- case 12:
- if (var1 == null) {
- var2.setServerControls((LDAPControl[])null);
- return;
- } else if (var1 instanceof LDAPControl) {
- var2.setServerControls((LDAPControl)var1);
- return;
- } else {
- if (var1 instanceof LDAPControl[]) {
- var2.setServerControls((LDAPControl[])var1);
- return;
- }
-
- throw new LDAPException("invalid LDAPControl", 89);
- }
- case 20:
- var2.setBatchSize((Integer)var1);
- return;
- default:
- throw new LDAPException("invalid option", 89);
- }
- } catch (ClassCastException var3) {
- throw new LDAPException("invalid option value", 89);
- }
- }
-
- public LDAPControl[] getResponseControls() {
- LDAPControl[] var1 = null;
- Hashtable var3 = this.m_responseControlTable;
- synchronized(var3){}
-
- LDAPControl[] var2;
- try {
- var2 = (LDAPControl[])this.m_responseControlTable.get(Thread.currentThread());
- } catch (Throwable var5) {
- throw var5;
- }
-
- if (var2 != null && var2.length > 0) {
- var1 = new LDAPControl[var2.length];
-
- for(int var6 = 0; var6 < var2.length; ++var6) {
- var1[var6] = (LDAPControl)var2[var6].clone();
- }
- }
-
- return var1;
- }
-
- public LDAPSearchConstraints getSearchConstraints() {
- return this.defaultConstraints;
- }
-
- private synchronized LDAPResponseListener getResponseListener() {
- if (this.responseListeners == null) {
- this.responseListeners = new Vector(5);
- }
-
- LDAPResponseListener var1;
- if (this.responseListeners.size() < 1) {
- var1 = new LDAPResponseListener(this);
- } else {
- var1 = (LDAPResponseListener)this.responseListeners.elementAt(0);
- this.responseListeners.removeElementAt(0);
- }
-
- var1.setThread();
- return var1;
- }
-
- private synchronized LDAPSearchListener getSearchListener() {
- if (this.searchListeners == null) {
- this.searchListeners = new Vector(5);
- }
-
- LDAPSearchListener var1;
- if (this.searchListeners.size() < 1) {
- var1 = new LDAPSearchListener(this);
- } else {
- var1 = (LDAPSearchListener)this.searchListeners.elementAt(0);
- this.searchListeners.removeElementAt(0);
- }
-
- ((LDAPResponseListener)var1).setThread();
- return var1;
- }
-
- private synchronized void releaseResponseListener(LDAPResponseListener var1) {
- if (this.responseListeners == null) {
- this.responseListeners = new Vector(5);
- }
-
- var1.reset();
- this.responseListeners.addElement(var1);
- }
-
- private synchronized void releaseSearchListener(LDAPSearchListener var1) {
- if (this.searchListeners == null) {
- this.searchListeners = new Vector(5);
- }
-
- var1.reset();
- this.searchListeners.addElement(var1);
- }
-
- private void checkMsg(JDAPMessage var1) throws LDAPException {
- if (var1.getProtocolOp() instanceof JDAPResult) {
- JDAPResult var2 = (JDAPResult)var1.getProtocolOp();
- int var3 = var2.getResultCode();
- if (var3 != 0) {
- if (var3 == 10) {
- throw new LDAPReferralException("referral", var2.getResultCode(), var2.getReferrals());
- } else if (var3 == 9) {
- throw new LDAPReferralException("referral", var2.getResultCode(), var2.getErrorMessage());
- } else {
- throw new LDAPException("error result", var2.getResultCode(), var2.getErrorMessage(), var2.getMatchedDN());
- }
- }
- }
- }
-
- void setResponseControls(Thread var1, LDAPControl[] var2) {
- Hashtable var3 = this.m_responseControlTable;
- synchronized(var3){}
-
- try {
- if (var2 != null) {
- this.m_responseControlTable.put(var1, var2);
- } else {
- this.m_responseControlTable.remove(var1);
- }
-
- Enumeration var5 = this.m_attachedList.elements();
-
- while(var5.hasMoreElements()) {
- Thread var6 = (Thread)var5.nextElement();
- if (!var6.isAlive()) {
- this.m_responseControlTable.remove(var6);
- this.m_attachedList.removeElement(var6);
- }
- }
- } catch (Throwable var8) {
- throw var8;
- }
-
- if (this.m_attachedList.indexOf(var1) < 0) {
- this.m_attachedList.addElement(var1);
- }
-
- }
-
- private LDAPConnection prepareReferral(LDAPUrl var1, LDAPSearchConstraints var2) throws LDAPException {
- LDAPConnection var3 = new LDAPConnection(this.getSocketFactory());
- var3.setOption(8, new Boolean(true));
- var3.setOption(9, var2.getRebindProc());
- var3.setOption(10, new Integer(var2.getHopLimit() - 1));
- var3.connect(var1.getHost(), var1.getPort());
- if (var2.getRebindProc() == null) {
- var3.authenticate((String)null, (String)null);
- } else {
- LDAPRebindAuth var4 = var2.getRebindProc().getRebindAuthentication(var1.getHost(), var1.getPort());
- var3.authenticate(var4.getDN(), var4.getPassword());
- }
-
- return var3;
- }
-
- private void performReferrals(LDAPReferralException var1, LDAPSearchConstraints var2, int var3, String var4, int var5, String var6, String[] var7, boolean var8, LDAPModification[] var9, LDAPEntry var10, LDAPAttribute var11, LDAPSearchResults[] var12, boolean[] var13) throws LDAPException {
- if (var2.getHopLimit() < 0) {
- throw new LDAPReferralException("exceed hop limit", ((LDAPException)var1).getLDAPResultCode(), ((LDAPException)var1).getLDAPErrorMessage());
- } else if (!var2.getReferrals()) {
- throw var1;
- } else {
- LDAPUrl[] var14 = var1.getURLs();
- if (var14 != null) {
- for(int var15 = 0; var15 < var14.length; ++var15) {
- try {
- LDAPConnection var16 = this.prepareReferral(var14[var15], var2);
- switch (var3) {
- case 3:
- LDAPSearchConstraints var17 = (LDAPSearchConstraints)var2.clone();
- var17.setHopLimit(var2.getHopLimit() - 1);
- var12[0] = var16.search(var4, var5, var6, var7, var8, var17);
- if (var12[0] != null) {
- var12[0].closeOnCompletion(var16);
- }
-
- return;
- case 6:
- var16.modify(var4, var9);
- break;
- case 8:
- var16.add(var10);
- break;
- case 10:
- var16.delete(var4);
- break;
- case 12:
- var16.rename(var4, var6, var8);
- break;
- case 14:
- var13[0] = var16.compare(var4, var11);
- }
-
- var16.disconnect();
- return;
- }
- }
-
- }
- }
- }
-
- private LDAPExtendedOperation performExtendedReferrals(LDAPReferralException var1, LDAPSearchConstraints var2, LDAPExtendedOperation var3) throws LDAPException {
- if (var2.getHopLimit() < 0) {
- throw new LDAPReferralException("exceed hop limit", ((LDAPException)var1).getLDAPResultCode(), ((LDAPException)var1).getLDAPErrorMessage());
- } else if (!var2.getReferrals()) {
- throw var1;
- } else {
- LDAPUrl[] var4 = var1.getURLs();
- if (var4 == null) {
- return null;
- } else {
- for(int var5 = 0; var5 < var4.length; ++var5) {
- try {
- LDAPConnection var6 = this.prepareReferral(var4[var5], var2);
- LDAPExtendedOperation var7 = var6.extendedOperation(var3);
- var6.disconnect();
- return var7;
- }
- }
-
- return null;
- }
- }
- }
-
- public synchronized Object clone() {
- try {
- LDAPConnection var1 = (LDAPConnection)super.clone();
- var1.defaultConstraints = (LDAPSearchConstraints)this.defaultConstraints.clone();
- var1.responseListeners = null;
- var1.searchListeners = null;
- var1.bound = this.bound;
- var1.host = this.host;
- var1.port = this.port;
- var1.boundDN = this.boundDN;
- var1.boundPasswd = this.boundPasswd;
- var1.m_factory = this.m_factory;
- var1.field_0 = this.field_0;
- Hashtable var3 = m_threadConnTable;
- synchronized(var3){}
-
- label47: {
- Object var2;
- try {
- Vector var5 = (Vector)m_threadConnTable.get(this.field_0);
- if (var5 != null) {
- var5.addElement(var1);
- break label47;
- }
-
- printDebug("Failed to clone");
- var2 = null;
- } catch (Throwable var8) {
- throw var8;
- }
-
- return var2;
- }
-
- var1.field_0.register(var1);
- return var1;
- } catch (Exception var9) {
- return null;
- }
- }
-
- private static boolean checkCommunicator() {
- try {
- Method var0 = LDAPCheckComm.getMethod("netscape.security.PrivilegeManager", "enablePrivilege");
- if (var0 == null) {
- printDebug("Method is null");
- return false;
- }
-
- Object[] var1 = new Object[]{new String("UniversalConnect")};
- var0.invoke((Object)null, var1);
- printDebug("UniversalConnect enabled");
- return true;
- } catch (LDAPException var2) {
- printDebug("Exception: " + var2.toString());
- } catch (Exception var3) {
- printDebug("Exception on invoking enablePrivilege: " + ((Throwable)var3).toString());
- }
-
- return false;
- }
-
- public static boolean isNetscape() {
- return isCommunicator;
- }
-
- private static void printDebug(String var0) {
- }
-
- public static void main(String[] var0) {
- System.out.println("LDAP SDK Version is " + SdkVersion);
- System.out.println("LDAP Protocol Version is " + ProtocolVersion);
- }
- }
-