LDAPCompare.java revision 266c5071a91fda6a5159b08ea8d45261228d03d5
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying * information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2006 Sun Microsystems, Inc.
*/
/**
* This class provides a tool that can be used to issue compare requests to the
* Directory Server.
*/
public class LDAPCompare
{
/**
* The fully-qualified name of this class for debugging purposes.
*/
private static final String CLASS_NAME =
"org.opends.server.tools.LDAPCompare";
// The message ID counter to use for requests.
private AtomicInteger nextMessageID;
// The print stream to use for standard error.
private PrintStream err;
// The print stream to use for standard output.
private PrintStream out;
/**
* Constructor for the LDAPCompare object.
*
* @param nextMessageID The message ID counter to use for requests.
* @param out The print stream to use for standard output.
* @param err The print stream to use for standard error.
*/
{
this.nextMessageID = nextMessageID;
}
/**
* Execute the compare request in the specified list of DNs.
*
* @param connection The connection to execute the request on.
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param lines The list of DNs to compare the attribute in.
* @param compareOptions The constraints for the compare request.
*
* @throws IOException If a problem occurs while communicating with the
* Directory Server.
*
* @throws LDAPException If the server returns an error response.
*/
throws IOException, LDAPException
{
{
}
}
/**
* Read the specified DNs from the given reader
* (file or stdin) and execute the given compare request.
*
* @param connection The connection to execute the request on.
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param reader The reader to read the list of DNs from.
* @param compareOptions The constraints for the compare request.
*
* @throws IOException If a problem occurs while communicating with the
* Directory Server.
*
* @throws LDAPException If the server returns an error response.
*/
throws IOException, LDAPException
{
{
}
}
/**
* Execute the compare request for the specified DN entry.
*
* @param connection The connection to execute the request on.
* @param attributeType The attribute type to compare.
* @param attributeVal The attribute value to compare.
* @param line The DN to compare attribute in.
* @param compareOptions The constraints for the compare request.
*
* @throws IOException If a problem occurs while communicating with the
* Directory Server.
*
* @throws LDAPException If the server returns an error response.
*/
throws IOException, LDAPException
{
if(!compareOptions.showOperations())
{
try
{
} catch(ASN1Exception ae)
{
if(!compareOptions.continueOnError())
{
} else
{
return;
}
}
&& !compareOptions.continueOnError())
{
} else
{
if(resultCode == COMPARE_FALSE)
{
} else if(resultCode == COMPARE_TRUE)
{
} else
{
}
}
}
}
/**
* The main method for LDAPCompare tool.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Parses the provided command-line arguments and uses that information to
* run the ldapcompare tool.
*
* @param args The command-line arguments provided to this program.
*
* @return The error code.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to
* run the ldapcompare tool.
*
* @param args The command-line arguments provided to this
* program.
* @param initializeServer Indicates whether to initialize the server.
* @param outStream The output stream to use for standard output, or
* <CODE>null</CODE> if standard output is not
* needed.
* @param errStream The output stream to use for standard error, or
* <CODE>null</CODE> if standard error is not
* needed.
*
* @return The error code.
*/
{
{
}
else
{
}
{
}
else
{
}
byte[] attributeVal = null;
// Create the command-line argument parser for use with this program.
false, true, 1, 0,
" \'attribute:value\' \"DN\" ...");
try
{
false, false, true, "{bindPassword}",
false, false, "{bindPasswordFilename}", null,
"useSASLExternal",
false, false, true, "{keyStorePath}",
"keyStorePassword", false, false,
"keyStorePasswordFile", false, false, "{path}",
"trustStorePath", false, false, true,
false, false, true, "{trustStorePassword}", null,
"trustStorePasswordFile", false, false,
"assertionFilter", false, false, true,
"{controloid[:criticality[:value|::b64value|:<filePath]]}",
false, false,
"continueOnError",
"noop",
} catch (ArgumentException ae)
{
return 1;
}
// Parse the command-line arguments provided to this program.
try
{
}
catch (ArgumentException ae)
{
return 1;
}
// If we should just display usage information, then print it and exit.
{
return 0;
}
{
int msgID = MSGID_TOOL_CONFLICTING_ARGS;
return 1;
}
if(attrAndDNStrings.isEmpty())
{
int msgID = MSGID_LDAPCOMPARE_NO_ATTR;
return 1;
}
// First element should be an attribute string.
// Rest are DN strings
for(String s : attrAndDNStrings)
{
}
// If no DNs were provided, then exit with an error.
{
int msgID = MSGID_LDAPCOMPARE_NO_DNS;
return 1;
}
// parse the attribute string
if(idx == -1)
{
return 1;
}
{
if(nextChar == ':')
{
try
{
}
catch (ParseException e)
{
return 1;
}
} else if(nextChar == '<')
{
try
{
}
catch (Exception e)
{
return 1;
}
} else
{
}
}
else
{
}
int portNumber = 389;
try
{
} catch (ArgumentException ae)
{
return 1;
}
try
{
{
return 1;
}
} catch(ArgumentException ae)
{
return 1;
}
{
// read the password from the stdin.
try
{
{
return 1;
}
} else if(bindPasswordValue == null)
{
// Read from file if it exists.
}
if (keyStorePassword.isPresent())
{
}
else if (keyStorePasswordFile.isPresent())
{
}
if (trustStorePassword.isPresent())
{
}
else if (trustStorePasswordFile.isPresent())
{
}
if(controlStr.hasValue())
{
{
return 1;
}
}
if (assertionFilter.isPresent())
{
try
{
new LDAPControl(OID_LDAP_ASSERTION, true,
}
catch (LDAPException le)
{
return 1;
}
}
// Set the connection options.
// Parse the SASL properties.
if(saslOptions.isPresent())
{
{
{
if(val == false)
{
return 1;
}
} else
{
if(val == false)
{
return 1;
}
}
}
}
{
{
return 1;
}
if(keyStorePathValue == null)
{
return 1;
}
}
try
{
if (initializeServer)
{
// Bootstrap and initialize directory data structures.
}
// Connect to the specified host with the supplied userDN and password.
{
sslConnectionFactory = new SSLConnectionFactory();
}
{
// Read from stdin.
} else if(fileNameValue != null)
{
}
{
} else
{
}
} catch(LDAPException le)
{
return code;
} catch(LDAPConnectionException lce)
{
return code;
} catch(Exception e)
{
return 1;
} finally
{
if(connection != null)
{
connection.close();
}
}
return 0;
}
}